| 1 | package net.minecraft.client.player;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import com.mojang.logging.LogUtils;
|
| 5 | import java.util.Iterator;
|
| 6 | import java.util.List;
|
| 7 | import java.util.Objects;
|
| 8 | import java.util.stream.StreamSupport;
|
| 9 | import net.fabricmc.api.EnvType;
|
| 10 | import net.fabricmc.api.Environment;
|
| 11 | import net.fabricmc.fabric.api.networking.v1.context.PacketContextProvider;
|
| 12 | import net.minecraft.client.ClientRecipeBook;
|
| 13 | import net.minecraft.client.KeyMapping;
|
| 14 | import net.minecraft.client.Minecraft;
|
| 15 | import net.minecraft.client.gui.screens.LevelLoadingScreen;
|
| 16 | import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
| 17 | import net.minecraft.client.gui.screens.inventory.BookEditScreen;
|
| 18 | import net.minecraft.client.gui.screens.inventory.CommandBlockEditScreen;
|
| 19 | import net.minecraft.client.gui.screens.inventory.HangingSignEditScreen;
|
| 20 | import net.minecraft.client.gui.screens.inventory.JigsawBlockEditScreen;
|
| 21 | import net.minecraft.client.gui.screens.inventory.MinecartCommandBlockEditScreen;
|
| 22 | import net.minecraft.client.gui.screens.inventory.SignEditScreen;
|
| 23 | import net.minecraft.client.gui.screens.inventory.StructureBlockEditScreen;
|
| 24 | import net.minecraft.client.gui.screens.inventory.TestBlockEditScreen;
|
| 25 | import net.minecraft.client.gui.screens.inventory.TestInstanceBlockEditScreen;
|
| 26 | import net.minecraft.client.gui.screens.options.HasGamemasterPermissionReaction;
|
| 27 | import net.minecraft.client.multiplayer.ClientLevel;
|
| 28 | import net.minecraft.client.multiplayer.ClientPacketListener;
|
| 29 | import net.minecraft.client.multiplayer.chat.ChatAbilities;
|
| 30 | import net.minecraft.client.resources.sounds.AmbientSoundHandler;
|
| 31 | import net.minecraft.client.resources.sounds.BiomeAmbientSoundsHandler;
|
| 32 | import net.minecraft.client.resources.sounds.BubbleColumnAmbientSoundHandler;
|
| 33 | import net.minecraft.client.resources.sounds.ElytraOnPlayerSoundInstance;
|
| 34 | import net.minecraft.client.resources.sounds.RidingEntitySoundInstance;
|
| 35 | import net.minecraft.client.resources.sounds.RidingMinecartSoundInstance;
|
| 36 | import net.minecraft.client.resources.sounds.SimpleSoundInstance;
|
| 37 | import net.minecraft.client.resources.sounds.UnderLiquidAmbientSoundInstance;
|
| 38 | import net.minecraft.client.resources.sounds.UnderwaterAmbientSoundHandler;
|
| 39 | import net.minecraft.core.BlockPos;
|
| 40 | import net.minecraft.core.Direction;
|
| 41 | import net.minecraft.core.Holder;
|
| 42 | import net.minecraft.core.Direction.Axis;
|
| 43 | import net.minecraft.core.Direction.AxisDirection;
|
| 44 | import net.minecraft.core.component.DataComponents;
|
| 45 | import net.minecraft.core.particles.ParticleTypes;
|
| 46 | import net.minecraft.network.chat.Component;
|
| 47 | import net.minecraft.network.protocol.game.ServerboundClientCommandPacket;
|
| 48 | import net.minecraft.network.protocol.game.ServerboundContainerClosePacket;
|
| 49 | import net.minecraft.network.protocol.game.ServerboundMoveVehiclePacket;
|
| 50 | import net.minecraft.network.protocol.game.ServerboundPlayerAbilitiesPacket;
|
| 51 | import net.minecraft.network.protocol.game.ServerboundPlayerCommandPacket;
|
| 52 | import net.minecraft.network.protocol.game.ServerboundPlayerInputPacket;
|
| 53 | import net.minecraft.network.protocol.game.ServerboundRecipeBookSeenRecipePacket;
|
| 54 | import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket.Pos;
|
| 55 | import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket.PosRot;
|
| 56 | import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket.Rot;
|
| 57 | import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket.StatusOnly;
|
| 58 | import net.minecraft.network.protocol.game.ServerboundPlayerCommandPacket.Action;
|
| 59 | import net.minecraft.network.syncher.EntityDataAccessor;
|
| 60 | import net.minecraft.resources.Identifier;
|
| 61 | import net.minecraft.server.dialog.Dialog;
|
| 62 | import net.minecraft.server.permissions.LevelBasedPermissionSet;
|
| 63 | import net.minecraft.server.permissions.PermissionSet;
|
| 64 | import net.minecraft.server.permissions.Permissions;
|
| 65 | import net.minecraft.sounds.SoundEvent;
|
| 66 | import net.minecraft.sounds.SoundEvents;
|
| 67 | import net.minecraft.sounds.SoundSource;
|
| 68 | import net.minecraft.stats.StatsCounter;
|
| 69 | import net.minecraft.tags.FluidTags;
|
| 70 | import net.minecraft.util.Mth;
|
| 71 | import net.minecraft.util.TickThrottler;
|
| 72 | import net.minecraft.world.InteractionHand;
|
| 73 | import net.minecraft.world.effect.MobEffects;
|
| 74 | import net.minecraft.world.entity.Entity;
|
| 75 | import net.minecraft.world.entity.EntitySelector;
|
| 76 | import net.minecraft.world.entity.HumanoidArm;
|
| 77 | import net.minecraft.world.entity.MoverType;
|
| 78 | import net.minecraft.world.entity.PlayerRideableJumping;
|
| 79 | import net.minecraft.world.entity.Pose;
|
| 80 | import net.minecraft.world.entity.Entity.RemovalReason;
|
| 81 | import net.minecraft.world.entity.EntityEvent.Value;
|
| 82 | import net.minecraft.world.entity.ai.attributes.Attributes;
|
| 83 | import net.minecraft.world.entity.animal.happyghast.HappyGhast;
|
| 84 | import net.minecraft.world.entity.animal.nautilus.AbstractNautilus;
|
| 85 | import net.minecraft.world.entity.player.Abilities;
|
| 86 | import net.minecraft.world.entity.player.Input;
|
| 87 | import net.minecraft.world.entity.projectile.ProjectileUtil;
|
| 88 | import net.minecraft.world.entity.vehicle.boat.AbstractBoat;
|
| 89 | import net.minecraft.world.entity.vehicle.minecart.AbstractMinecart;
|
| 90 | import net.minecraft.world.entity.vehicle.minecart.MinecartCommandBlock;
|
| 91 | import net.minecraft.world.inventory.ClickAction;
|
| 92 | import net.minecraft.world.item.ItemStack;
|
| 93 | import net.minecraft.world.item.component.AttackRange;
|
| 94 | import net.minecraft.world.item.component.UseEffects;
|
| 95 | import net.minecraft.world.item.component.WritableBookContent;
|
| 96 | import net.minecraft.world.item.crafting.display.RecipeDisplayId;
|
| 97 | import net.minecraft.world.level.GameType;
|
| 98 | import net.minecraft.world.level.block.Portal.Transition;
|
| 99 | import net.minecraft.world.level.block.entity.CommandBlockEntity;
|
| 100 | import net.minecraft.world.level.block.entity.HangingSignBlockEntity;
|
| 101 | import net.minecraft.world.level.block.entity.JigsawBlockEntity;
|
| 102 | import net.minecraft.world.level.block.entity.SignBlockEntity;
|
| 103 | import net.minecraft.world.level.block.entity.SignTextSlot;
|
| 104 | import net.minecraft.world.level.block.entity.StructureBlockEntity;
|
| 105 | import net.minecraft.world.level.block.entity.TestBlockEntity;
|
| 106 | import net.minecraft.world.level.block.entity.TestInstanceBlockEntity;
|
| 107 | import net.minecraft.world.level.block.state.BlockState;
|
| 108 | import net.minecraft.world.phys.AABB;
|
| 109 | import net.minecraft.world.phys.BlockHitResult;
|
| 110 | import net.minecraft.world.phys.EntityHitResult;
|
| 111 | import net.minecraft.world.phys.HitResult;
|
| 112 | import net.minecraft.world.phys.Vec2;
|
| 113 | import net.minecraft.world.phys.Vec3;
|
| 114 | import net.minecraft.world.phys.HitResult.Type;
|
| 115 | import net.minecraft.world.phys.shapes.CollisionContext;
|
| 116 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 117 | import org.jspecify.annotations.Nullable;
|
| 118 | import org.slf4j.Logger;
|
| 119 |
|
| 120 | @Environment(EnvType.CLIENT)
|
| 121 | public class LocalPlayer extends AbstractClientPlayer implements PacketContextProvider {
|
| 122 | public static final Logger LOGGER = LogUtils.getLogger();
|
| 123 | private static final int POSITION_REMINDER_INTERVAL = 20;
|
| 124 | private static final int WATER_VISION_MAX_TIME = 600;
|
| 125 | private static final int WATER_VISION_QUICK_TIME = 100;
|
| 126 | private static final float WATER_VISION_QUICK_PERCENT = 0.6F;
|
| 127 | private static final double SUFFOCATING_COLLISION_CHECK_SCALE = 0.35;
|
| 128 | private static final double MINOR_COLLISION_ANGLE_THRESHOLD_RADIAN = 0.13962634F;
|
| 129 | private static final float PORTAL_SPINNING_SPEED = 20.0F;
|
| 130 | private static final float NAUSEA_SPINNING_SPEED = 7.0F;
|
| 131 | public final ClientPacketListener connection;
|
| 132 | private final StatsCounter stats;
|
| 133 | private final ClientRecipeBook recipeBook;
|
| 134 | private final TickThrottler dropSpamThrottler = new TickThrottler(20, 1280);
|
| 135 | private final List<AmbientSoundHandler> ambientSoundHandlers = Lists.newArrayList();
|
| 136 | private PermissionSet permissions = PermissionSet.NO_PERMISSIONS;
|
| 137 | private ChatAbilities chatAbilities;
|
| 138 | private double xLast;
|
| 139 | private double yLast;
|
| 140 | private double zLast;
|
| 141 | private float yRotLast;
|
| 142 | private float xRotLast;
|
| 143 | private boolean lastOnGround;
|
| 144 | private boolean lastHorizontalCollision;
|
| 145 | private boolean crouching;
|
| 146 | private boolean wasSprinting;
|
| 147 | private int positionReminder;
|
| 148 | private boolean flashOnSetHealth;
|
| 149 | public ClientInput input = new ClientInput();
|
| 150 | private Input lastSentInput;
|
| 151 | protected final Minecraft minecraft;
|
| 152 | protected int sprintTriggerTime;
|
| 153 | private static final int EXPERIENCE_DISPLAY_UNREADY_TO_SET = Integer.MIN_VALUE;
|
| 154 | private static final int EXPERIENCE_DISPLAY_READY_TO_SET = -2147483647;
|
| 155 | public int experienceDisplayStartTick = Integer.MIN_VALUE;
|
| 156 | public float yBob;
|
| 157 | public float xBob;
|
| 158 | public float yBobO;
|
| 159 | public float xBobO;
|
| 160 | private int jumpRidingTicks;
|
| 161 | private float jumpRidingScale;
|
| 162 | public float portalEffectIntensity;
|
| 163 | public float oPortalEffectIntensity;
|
| 164 | private float spinningEffectTime;
|
| 165 | private float spinningEffectSpeed;
|
| 166 | private final ItemActivation itemActivation;
|
| 167 | private final FirstPersonHandsAndItems firstPersonHandsAndItems = new FirstPersonHandsAndItems();
|
| 168 | private boolean startedUsingItem;
|
| 169 | private @Nullable InteractionHand usingItemHand;
|
| 170 | private boolean handsBusy;
|
| 171 | private boolean autoJumpEnabled = true;
|
| 172 | private int autoJumpTime;
|
| 173 | private boolean wasFallFlying;
|
| 174 | private int waterVisionTime;
|
| 175 | private boolean showDeathScreen = true;
|
| 176 | private boolean doLimitedCrafting = false;
|
| 177 |
|
| 178 | public LocalPlayer(
|
| 179 | final Minecraft minecraft,
|
| 180 | final ClientLevel level,
|
| 181 | final ClientPacketListener connection,
|
| 182 | final StatsCounter stats,
|
| 183 | final ClientRecipeBook recipeBook,
|
| 184 | final Input lastSentInput,
|
| 185 | final boolean wasSprinting,
|
| 186 | final ChatAbilities chatAbilities,
|
| 187 | final ItemActivation itemActivation
|
| 188 | ) {
|
| 189 | super(level, connection.getLocalGameProfile());
|
| 190 | this.minecraft = minecraft;
|
| 191 | this.connection = connection;
|
| 192 | this.stats = stats;
|
| 193 | this.recipeBook = recipeBook;
|
| 194 | this.lastSentInput = lastSentInput;
|
| 195 | this.wasSprinting = wasSprinting;
|
| 196 | this.ambientSoundHandlers.add(new UnderwaterAmbientSoundHandler(this, minecraft.getSoundManager()));
|
| 197 | this.ambientSoundHandlers.add(new BubbleColumnAmbientSoundHandler(this));
|
| 198 | this.ambientSoundHandlers.add(new BiomeAmbientSoundsHandler(this, minecraft.getSoundManager()));
|
| 199 | this.chatAbilities = chatAbilities;
|
| 200 | this.itemActivation = itemActivation;
|
| 201 | }
|
| 202 |
|
| 203 | @Override
|
| 204 | public void heal(final float heal) {
|
| 205 | }
|
| 206 |
|
| 207 | @Override
|
| 208 | public boolean startRiding(final Entity entity, final boolean force, final boolean sendEventAndTriggers) {
|
| 209 | if (!super.startRiding(entity, force, sendEventAndTriggers)) {
|
| 210 | return false;
|
| 211 | }
|
| 212 |
|
| 213 | if (entity instanceof AbstractMinecart minecart) {
|
| 214 | this.minecraft.getSoundManager().play(new RidingMinecartSoundInstance(this, minecart, true, SoundEvents.MINECART_INSIDE_UNDERWATER, 0.0F, 0.75F, 1.0F));
|
| 215 | this.minecraft.getSoundManager().play(new RidingMinecartSoundInstance(this, minecart, false, SoundEvents.MINECART_INSIDE, 0.0F, 0.75F, 1.0F));
|
| 216 | } else if (entity instanceof HappyGhast happyGhast) {
|
| 217 | this.minecraft
|
| 218 | .getSoundManager()
|
| 219 | .play(new RidingEntitySoundInstance(this, happyGhast, false, SoundEvents.HAPPY_GHAST_RIDING, happyGhast.getSoundSource(), 0.0F, 1.0F, 5.0F));
|
| 220 | } else if (entity instanceof AbstractNautilus nautilus) {
|
| 221 | this.minecraft
|
| 222 | .getSoundManager()
|
| 223 | .play(new RidingEntitySoundInstance(this, nautilus, true, SoundEvents.NAUTILUS_RIDING, nautilus.getSoundSource(), 0.0F, 1.0F, 5.0F));
|
| 224 | }
|
| 225 |
|
| 226 | return true;
|
| 227 | }
|
| 228 |
|
| 229 | @Override
|
| 230 | public void removeVehicle() {
|
| 231 | super.removeVehicle();
|
| 232 | this.handsBusy = false;
|
| 233 | }
|
| 234 |
|
| 235 | @Override
|
| 236 | public float getViewYRot(final float a) {
|
| 237 | return this.getYRot(a);
|
| 238 | }
|
| 239 |
|
| 240 | @Override
|
| 241 | public void tick() {
|
| 242 | if (this.connection.hasClientLoaded()) {
|
| 243 | this.dropSpamThrottler.tick();
|
| 244 | super.tick();
|
| 245 | this.firstPersonHandsAndItems.tick(this);
|
| 246 |
|
| 247 | for (AmbientSoundHandler soundHandler : this.ambientSoundHandlers) {
|
| 248 | soundHandler.tick();
|
| 249 | }
|
| 250 | }
|
| 251 | }
|
| 252 |
|
| 253 | public void displayItemActivation(final ItemStack itemStack) {
|
| 254 | this.itemActivation.activate(itemStack, this.random);
|
| 255 | }
|
| 256 |
|
| 257 | public void resetItemActivation() {
|
| 258 | this.itemActivation.reset();
|
| 259 | }
|
| 260 |
|
| 261 | public ItemActivation itemActivation() {
|
| 262 | return this.itemActivation;
|
| 263 | }
|
| 264 |
|
| 265 | public void itemUsed(final InteractionHand hand) {
|
| 266 | this.firstPersonHandsAndItems.itemUsed(hand);
|
| 267 | }
|
| 268 |
|
| 269 | public FirstPersonHandsAndItems firstPersonHandsAndItems() {
|
| 270 | return this.firstPersonHandsAndItems;
|
| 271 | }
|
| 272 |
|
| 273 | public void sendChanges() {
|
| 274 | if (this.connection.hasClientLoaded()) {
|
| 275 | if (!this.lastSentInput.equals(this.input.keyPresses)) {
|
| 276 | this.connection.send(new ServerboundPlayerInputPacket(this.input.keyPresses));
|
| 277 | this.lastSentInput = this.input.keyPresses;
|
| 278 | }
|
| 279 |
|
| 280 | if (this.isPassenger()) {
|
| 281 | this.connection.send(new Rot(this.getYRot(), this.getXRot(), this.onGround(), this.horizontalCollision));
|
| 282 | Entity vehicle = this.getRootVehicle();
|
| 283 | if (vehicle != this && vehicle.isLocalInstanceAuthoritative()) {
|
| 284 | this.connection.send(ServerboundMoveVehiclePacket.fromEntity(vehicle));
|
| 285 | this.sendIsSprintingIfNeeded();
|
| 286 | }
|
| 287 | } else {
|
| 288 | this.sendPosition();
|
| 289 | }
|
| 290 | }
|
| 291 | }
|
| 292 |
|
| 293 | public float getCurrentMood() {
|
| 294 | for (AmbientSoundHandler ambientSoundHandler : this.ambientSoundHandlers) {
|
| 295 | if (ambientSoundHandler instanceof BiomeAmbientSoundsHandler biomeAmbientSoundsHandler) {
|
| 296 | return biomeAmbientSoundsHandler.getMoodiness();
|
| 297 | }
|
| 298 | }
|
| 299 |
|
| 300 | return 0.0F;
|
| 301 | }
|
| 302 |
|
| 303 | private void sendPosition() {
|
| 304 | this.sendIsSprintingIfNeeded();
|
| 305 | if (this.isControlledCamera()) {
|
| 306 | double deltaX = this.getX() - this.xLast;
|
| 307 | double deltaY = this.getY() - this.yLast;
|
| 308 | double deltaZ = this.getZ() - this.zLast;
|
| 309 | double deltaYRot = this.getYRot() - this.yRotLast;
|
| 310 | double deltaXRot = this.getXRot() - this.xRotLast;
|
| 311 | this.positionReminder++;
|
| 312 | boolean move = Mth.lengthSquared(deltaX, deltaY, deltaZ) > Mth.square(2.0E-4) || this.positionReminder >= 20;
|
| 313 | boolean rot = deltaYRot != 0.0 || deltaXRot != 0.0;
|
| 314 | if (move && rot) {
|
| 315 | this.connection.send(new PosRot(this.position(), this.getYRot(), this.getXRot(), this.onGround(), this.horizontalCollision));
|
| 316 | } else if (move) {
|
| 317 | this.connection.send(new Pos(this.position(), this.onGround(), this.horizontalCollision));
|
| 318 | } else if (rot) {
|
| 319 | this.connection.send(new Rot(this.getYRot(), this.getXRot(), this.onGround(), this.horizontalCollision));
|
| 320 | } else if (this.lastOnGround != this.onGround() || this.lastHorizontalCollision != this.horizontalCollision) {
|
| 321 | this.connection.send(new StatusOnly(this.onGround(), this.horizontalCollision));
|
| 322 | }
|
| 323 |
|
| 324 | if (move) {
|
| 325 | this.xLast = this.getX();
|
| 326 | this.yLast = this.getY();
|
| 327 | this.zLast = this.getZ();
|
| 328 | this.positionReminder = 0;
|
| 329 | }
|
| 330 |
|
| 331 | if (rot) {
|
| 332 | this.yRotLast = this.getYRot();
|
| 333 | this.xRotLast = this.getXRot();
|
| 334 | }
|
| 335 |
|
| 336 | this.lastOnGround = this.onGround();
|
| 337 | this.lastHorizontalCollision = this.horizontalCollision;
|
| 338 | this.autoJumpEnabled = this.minecraft.options.autoJump().get();
|
| 339 | }
|
| 340 | }
|
| 341 |
|
| 342 | private void sendIsSprintingIfNeeded() {
|
| 343 | boolean isSprinting = this.isSprinting();
|
| 344 | if (isSprinting != this.wasSprinting) {
|
| 345 | Action action = isSprinting ? Action.START_SPRINTING : Action.STOP_SPRINTING;
|
| 346 | this.connection.send(new ServerboundPlayerCommandPacket(this, action));
|
| 347 | this.wasSprinting = isSprinting;
|
| 348 | }
|
| 349 | }
|
| 350 |
|
| 351 | public void respawn() {
|
| 352 | this.connection.send(new ServerboundClientCommandPacket(net.minecraft.network.protocol.game.ServerboundClientCommandPacket.Action.PERFORM_RESPAWN));
|
| 353 | KeyMapping.resetToggleKeys();
|
| 354 | }
|
| 355 |
|
| 356 | @Override
|
| 357 | public void closeContainer() {
|
| 358 | this.connection.send(new ServerboundContainerClosePacket(this.containerMenu.containerId));
|
| 359 | this.clientSideCloseContainer();
|
| 360 | }
|
| 361 |
|
| 362 | public void clientSideCloseContainer() {
|
| 363 | super.closeContainer();
|
| 364 | this.minecraft.gui.setScreen(null);
|
| 365 | }
|
| 366 |
|
| 367 | public void hurtTo(final float newHealth) {
|
| 368 | if (this.flashOnSetHealth) {
|
| 369 | float dmg = this.getHealth() - newHealth;
|
| 370 | if (dmg <= 0.0F) {
|
| 371 | this.setHealth(newHealth);
|
| 372 | if (dmg < 0.0F) {
|
| 373 | this.damageCooldownTime = 10;
|
| 374 | }
|
| 375 | } else {
|
| 376 | this.lastHurt = dmg;
|
| 377 | this.damageCooldownTime = 20;
|
| 378 | this.setHealth(newHealth);
|
| 379 | this.hurtDuration = 10;
|
| 380 | this.hurtTime = this.hurtDuration;
|
| 381 | }
|
| 382 | } else {
|
| 383 | this.setHealth(newHealth);
|
| 384 | this.flashOnSetHealth = true;
|
| 385 | }
|
| 386 | }
|
| 387 |
|
| 388 | @Override
|
| 389 | public void onUpdateAbilities() {
|
| 390 | this.connection.send(new ServerboundPlayerAbilitiesPacket(this.getAbilities()));
|
| 391 | }
|
| 392 |
|
| 393 | @Override
|
| 394 | public void setReducedDebugInfo(final boolean reducedDebugInfo) {
|
| 395 | super.setReducedDebugInfo(reducedDebugInfo);
|
| 396 | this.minecraft.debugEntries.rebuildCurrentList();
|
| 397 | }
|
| 398 |
|
| 399 | @Override
|
| 400 | public boolean isLocalPlayer() {
|
| 401 | return true;
|
| 402 | }
|
| 403 |
|
| 404 | @Override
|
| 405 | public boolean isSuppressingSlidingDownLadder() {
|
| 406 | return !this.getAbilities().flying && super.isSuppressingSlidingDownLadder();
|
| 407 | }
|
| 408 |
|
| 409 | @Override
|
| 410 | public boolean canSpawnSprintParticle() {
|
| 411 | return !this.getAbilities().flying && super.canSpawnSprintParticle();
|
| 412 | }
|
| 413 |
|
| 414 | protected void sendRidingJump() {
|
| 415 | this.connection.send(new ServerboundPlayerCommandPacket(this, Action.START_RIDING_JUMP, Mth.floor(this.getJumpRidingScale() * 100.0F)));
|
| 416 | }
|
| 417 |
|
| 418 | public void sendOpenInventory() {
|
| 419 | this.connection.send(new ServerboundPlayerCommandPacket(this, Action.OPEN_INVENTORY));
|
| 420 | }
|
| 421 |
|
| 422 | public StatsCounter getStats() {
|
| 423 | return this.stats;
|
| 424 | }
|
| 425 |
|
| 426 | public ClientRecipeBook getRecipeBook() {
|
| 427 | return this.recipeBook;
|
| 428 | }
|
| 429 |
|
| 430 | public void removeRecipeHighlight(final RecipeDisplayId recipe) {
|
| 431 | if (this.recipeBook.willHighlight(recipe)) {
|
| 432 | this.recipeBook.removeHighlight(recipe);
|
| 433 | this.connection.send(new ServerboundRecipeBookSeenRecipePacket(recipe));
|
| 434 | }
|
| 435 | }
|
| 436 |
|
| 437 | @Override
|
| 438 | public PermissionSet permissions() {
|
| 439 | return this.permissions;
|
| 440 | }
|
| 441 |
|
| 442 | public void setPermissions(final PermissionSet newPermissions) {
|
| 443 | boolean previousGamemasterPermission = this.permissions.hasPermission(Permissions.COMMANDS_GAMEMASTER);
|
| 444 | boolean newGamemasterPermission = newPermissions.hasPermission(Permissions.COMMANDS_GAMEMASTER);
|
| 445 | this.permissions = newPermissions;
|
| 446 | if (previousGamemasterPermission != newGamemasterPermission && this.minecraft.gui.screen() instanceof HasGamemasterPermissionReaction screen) {
|
| 447 | screen.onGamemasterPermissionChanged(newGamemasterPermission);
|
| 448 | }
|
| 449 | }
|
| 450 |
|
| 451 | public ChatAbilities chatAbilities() {
|
| 452 | return this.chatAbilities;
|
| 453 | }
|
| 454 |
|
| 455 | public void refreshChatAbilities() {
|
| 456 | this.chatAbilities = this.minecraft.computeChatAbilities();
|
| 457 | this.minecraft.gui.hud.getChat().setVisibleMessageFilter(this.chatAbilities.visibleMessagesFilter());
|
| 458 | }
|
| 459 |
|
| 460 | @Override
|
| 461 | public void sendSystemMessage(final Component message) {
|
| 462 | this.minecraft.gui.chatListener().handleSystemMessage(message, true);
|
| 463 | }
|
| 464 |
|
| 465 | @Override
|
| 466 | public void sendOverlayMessage(final Component message) {
|
| 467 | this.minecraft.gui.chatListener().handleOverlay(message);
|
| 468 | }
|
| 469 |
|
| 470 | private void moveTowardsClosestSpace(final double x, final double z) {
|
| 471 | BlockPos pos = BlockPos.containing(x, this.getY(), z);
|
| 472 | if (this.suffocatesAt(pos)) {
|
| 473 | double xd = x - pos.getX();
|
| 474 | double zd = z - pos.getZ();
|
| 475 | Direction dir = null;
|
| 476 | double closest = Double.MAX_VALUE;
|
| 477 | Direction[] directions = new Direction[]{Direction.WEST, Direction.EAST, Direction.NORTH, Direction.SOUTH};
|
| 478 |
|
| 479 | for (Direction direction : directions) {
|
| 480 | double axisDistance = direction.getAxis().choose(xd, 0.0, zd);
|
| 481 | double distanceToEdge = direction.getAxisDirection() == AxisDirection.POSITIVE ? 1.0 - axisDistance : axisDistance;
|
| 482 | if (distanceToEdge < closest && !this.suffocatesAt(pos.relative(direction))) {
|
| 483 | closest = distanceToEdge;
|
| 484 | dir = direction;
|
| 485 | }
|
| 486 | }
|
| 487 |
|
| 488 | if (dir != null) {
|
| 489 | Vec3 oldMovement = this.getDeltaMovement();
|
| 490 | if (dir.getAxis() == Axis.X) {
|
| 491 | this.setDeltaMovement(0.1 * dir.getStepX(), oldMovement.y, oldMovement.z);
|
| 492 | } else {
|
| 493 | this.setDeltaMovement(oldMovement.x, oldMovement.y, 0.1 * dir.getStepZ());
|
| 494 | }
|
| 495 | }
|
| 496 | }
|
| 497 | }
|
| 498 |
|
| 499 | private boolean suffocatesAt(final BlockPos pos) {
|
| 500 | AABB boundingBox = this.getBoundingBox();
|
| 501 | AABB testArea = new AABB(pos.getX(), boundingBox.minY, pos.getZ(), pos.getX() + 1.0, boundingBox.maxY, pos.getZ() + 1.0).deflate(1.0E-7);
|
| 502 | return this.level().collidesWithSuffocatingBlock(this, testArea);
|
| 503 | }
|
| 504 |
|
| 505 | public void setExperienceValues(final float experienceProgress, final int totalExp, final int experienceLevel) {
|
| 506 | if (experienceProgress != this.experienceProgress) {
|
| 507 | this.setExperienceDisplayStartTickToTickCount();
|
| 508 | }
|
| 509 |
|
| 510 | this.experienceProgress = experienceProgress;
|
| 511 | this.totalExperience = totalExp;
|
| 512 | this.experienceLevel = experienceLevel;
|
| 513 | }
|
| 514 |
|
| 515 | private void setExperienceDisplayStartTickToTickCount() {
|
| 516 | if (this.experienceDisplayStartTick == Integer.MIN_VALUE) {
|
| 517 | this.experienceDisplayStartTick = -2147483647;
|
| 518 | } else {
|
| 519 | this.experienceDisplayStartTick = this.tickCount;
|
| 520 | }
|
| 521 | }
|
| 522 |
|
| 523 | @Override
|
| 524 | public void handleEntityEvent(final @Value byte id) {
|
| 525 | switch (id) {
|
| 526 | case 24:
|
| 527 | this.setPermissions(PermissionSet.NO_PERMISSIONS);
|
| 528 | break;
|
| 529 | case 25:
|
| 530 | this.setPermissions(LevelBasedPermissionSet.MODERATOR);
|
| 531 | break;
|
| 532 | case 26:
|
| 533 | this.setPermissions(LevelBasedPermissionSet.GAMEMASTER);
|
| 534 | break;
|
| 535 | case 27:
|
| 536 | this.setPermissions(LevelBasedPermissionSet.ADMIN);
|
| 537 | break;
|
| 538 | case 28:
|
| 539 | this.setPermissions(LevelBasedPermissionSet.OWNER);
|
| 540 | break;
|
| 541 | default:
|
| 542 | super.handleEntityEvent(id);
|
| 543 | }
|
| 544 | }
|
| 545 |
|
| 546 | public void setShowDeathScreen(final boolean show) {
|
| 547 | this.showDeathScreen = show;
|
| 548 | }
|
| 549 |
|
| 550 | public boolean shouldShowDeathScreen() {
|
| 551 | return this.showDeathScreen;
|
| 552 | }
|
| 553 |
|
| 554 | public void setDoLimitedCrafting(final boolean value) {
|
| 555 | this.doLimitedCrafting = value;
|
| 556 | }
|
| 557 |
|
| 558 | public boolean getDoLimitedCrafting() {
|
| 559 | return this.doLimitedCrafting;
|
| 560 | }
|
| 561 |
|
| 562 | @Override
|
| 563 | public void playSound(final SoundEvent sound, final float volume, final float pitch) {
|
| 564 | this.level().playLocalSound(this.getX(), this.getY(), this.getZ(), sound, this.getSoundSource(), volume, pitch, false);
|
| 565 | }
|
| 566 |
|
| 567 | @Override
|
| 568 | public void startUsingItem(final InteractionHand hand) {
|
| 569 | ItemStack itemStack = this.getItemInHand(hand);
|
| 570 | if (!itemStack.isEmpty() && !this.isUsingItem()) {
|
| 571 | super.startUsingItem(hand);
|
| 572 | this.startedUsingItem = true;
|
| 573 | this.usingItemHand = hand;
|
| 574 | }
|
| 575 | }
|
| 576 |
|
| 577 | @Override
|
| 578 | public boolean isUsingItem() {
|
| 579 | return this.startedUsingItem;
|
| 580 | }
|
| 581 |
|
| 582 | private boolean isSlowDueToUsingItem() {
|
| 583 | return this.isUsingItem() && !this.useItem.getOrDefault(DataComponents.USE_EFFECTS, UseEffects.DEFAULT).canSprint();
|
| 584 | }
|
| 585 |
|
| 586 | private float itemUseSpeedMultiplier() {
|
| 587 | return this.useItem.getOrDefault(DataComponents.USE_EFFECTS, UseEffects.DEFAULT).speedMultiplier();
|
| 588 | }
|
| 589 |
|
| 590 | @Override
|
| 591 | public void stopUsingItem() {
|
| 592 | super.stopUsingItem();
|
| 593 | this.startedUsingItem = false;
|
| 594 | }
|
| 595 |
|
| 596 | @Override
|
| 597 | public InteractionHand getUsedItemHand() {
|
| 598 | return Objects.requireNonNullElse(this.usingItemHand, InteractionHand.MAIN_HAND);
|
| 599 | }
|
| 600 |
|
| 601 | @Override
|
| 602 | public void onSyncedDataUpdated(final EntityDataAccessor<?> accessor) {
|
| 603 | super.onSyncedDataUpdated(accessor);
|
| 604 | if (DATA_LIVING_ENTITY_FLAGS.equals(accessor)) {
|
| 605 | boolean serverUsingItem = (this.entityData.get(DATA_LIVING_ENTITY_FLAGS) & 1) > 0;
|
| 606 | InteractionHand serverUsingHand = (this.entityData.get(DATA_LIVING_ENTITY_FLAGS) & 2) > 0 ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND;
|
| 607 | if (serverUsingItem && !this.startedUsingItem) {
|
| 608 | this.startUsingItem(serverUsingHand);
|
| 609 | } else if (!serverUsingItem && this.startedUsingItem) {
|
| 610 | this.stopUsingItem();
|
| 611 | }
|
| 612 | }
|
| 613 |
|
| 614 | if (DATA_SHARED_FLAGS_ID.equals(accessor) && this.isFallFlying() && !this.wasFallFlying) {
|
| 615 | this.minecraft.getSoundManager().play(new ElytraOnPlayerSoundInstance(this));
|
| 616 | }
|
| 617 | }
|
| 618 |
|
| 619 | public @Nullable PlayerRideableJumping jumpableVehicle() {
|
| 620 | return this.getControlledVehicle() instanceof PlayerRideableJumping playerRideableJumping && playerRideableJumping.canJump() ? playerRideableJumping : null;
|
| 621 | }
|
| 622 |
|
| 623 | public float getJumpRidingScale() {
|
| 624 | return this.jumpRidingScale;
|
| 625 | }
|
| 626 |
|
| 627 | @Override
|
| 628 | public boolean isTextFilteringEnabled() {
|
| 629 | return this.minecraft.isTextFilteringEnabled();
|
| 630 | }
|
| 631 |
|
| 632 | @Override
|
| 633 | public void openTextEdit(final SignBlockEntity sign, final SignTextSlot slot) {
|
| 634 | if (sign instanceof HangingSignBlockEntity hangingSign) {
|
| 635 | this.minecraft.gui.setScreen(new HangingSignEditScreen(hangingSign, slot, this.minecraft.isTextFilteringEnabled()));
|
| 636 | } else {
|
| 637 | this.minecraft.gui.setScreen(new SignEditScreen(sign, slot, this.minecraft.isTextFilteringEnabled()));
|
| 638 | }
|
| 639 | }
|
| 640 |
|
| 641 | @Override
|
| 642 | public void openMinecartCommandBlock(final MinecartCommandBlock commandBlock) {
|
| 643 | this.minecraft.gui.setScreen(new MinecartCommandBlockEditScreen(commandBlock));
|
| 644 | }
|
| 645 |
|
| 646 | @Override
|
| 647 | public void openCommandBlock(final CommandBlockEntity commandBlock) {
|
| 648 | this.minecraft.gui.setScreen(new CommandBlockEditScreen(commandBlock));
|
| 649 | }
|
| 650 |
|
| 651 | @Override
|
| 652 | public void openStructureBlock(final StructureBlockEntity structureBlock) {
|
| 653 | this.minecraft.gui.setScreen(new StructureBlockEditScreen(structureBlock));
|
| 654 | }
|
| 655 |
|
| 656 | @Override
|
| 657 | public void openTestBlock(final TestBlockEntity testBlock) {
|
| 658 | this.minecraft.gui.setScreen(new TestBlockEditScreen(testBlock));
|
| 659 | }
|
| 660 |
|
| 661 | @Override
|
| 662 | public void openTestInstanceBlock(final TestInstanceBlockEntity testInstanceBlock) {
|
| 663 | this.minecraft.gui.setScreen(new TestInstanceBlockEditScreen(testInstanceBlock));
|
| 664 | }
|
| 665 |
|
| 666 | @Override
|
| 667 | public void openJigsawBlock(final JigsawBlockEntity jigsawBlock) {
|
| 668 | this.minecraft.gui.setScreen(new JigsawBlockEditScreen(jigsawBlock));
|
| 669 | }
|
| 670 |
|
| 671 | @Override
|
| 672 | public void openDialog(final Holder<Dialog> dialog) {
|
| 673 | this.connection.showDialog(dialog, this.minecraft.gui.screen());
|
| 674 | }
|
| 675 |
|
| 676 | @Override
|
| 677 | public void openItemGui(final ItemStack itemStack, final InteractionHand hand) {
|
| 678 | WritableBookContent content = itemStack.get(DataComponents.WRITABLE_BOOK_CONTENT);
|
| 679 | if (content != null) {
|
| 680 | this.minecraft.gui.setScreen(new BookEditScreen(this, itemStack, hand, content));
|
| 681 | }
|
| 682 | }
|
| 683 |
|
| 684 | @Override
|
| 685 | public void crit(final Entity entity) {
|
| 686 | this.minecraft.particleEngine.createTrackingEmitter(entity, ParticleTypes.CRIT);
|
| 687 | }
|
| 688 |
|
| 689 | @Override
|
| 690 | public void magicCrit(final Entity entity) {
|
| 691 | this.minecraft.particleEngine.createTrackingEmitter(entity, ParticleTypes.ENCHANTED_HIT);
|
| 692 | }
|
| 693 |
|
| 694 | @Override
|
| 695 | public boolean isShiftKeyDown() {
|
| 696 | return this.input.keyPresses.shift();
|
| 697 | }
|
| 698 |
|
| 699 | @Override
|
| 700 | public boolean isCrouching() {
|
| 701 | return this.crouching;
|
| 702 | }
|
| 703 |
|
| 704 | public boolean isMovingSlowly() {
|
| 705 | return this.isCrouching() || this.isVisuallyCrawling();
|
| 706 | }
|
| 707 |
|
| 708 | @Override
|
| 709 | public void applyInput() {
|
| 710 | if (this.isControlledCamera()) {
|
| 711 | Vec2 modifiedInput = this.modifyInput(this.input.getMoveVector());
|
| 712 | this.xxa = modifiedInput.x;
|
| 713 | this.zza = modifiedInput.y;
|
| 714 | this.jumping = this.input.keyPresses.jump();
|
| 715 | this.yBobO = this.yBob;
|
| 716 | this.xBobO = this.xBob;
|
| 717 | this.xBob = this.xBob + (this.getXRot() - this.xBob) * 0.5F;
|
| 718 | this.yBob = this.yBob + (this.getYRot() - this.yBob) * 0.5F;
|
| 719 | } else {
|
| 720 | super.applyInput();
|
| 721 | }
|
| 722 | }
|
| 723 |
|
| 724 | private Vec2 modifyInput(final Vec2 input) {
|
| 725 | if (input.lengthSquared() == 0.0F) {
|
| 726 | return input;
|
| 727 | }
|
| 728 |
|
| 729 | Vec2 newInput = input.scale(0.98F);
|
| 730 | if (this.isUsingItem() && !this.isPassenger()) {
|
| 731 | newInput = newInput.scale(this.itemUseSpeedMultiplier());
|
| 732 | }
|
| 733 |
|
| 734 | if (this.isMovingSlowly()) {
|
| 735 | float sneakingMovementFactor = (float)this.getAttributeValue(Attributes.SNEAKING_SPEED);
|
| 736 | newInput = newInput.scale(sneakingMovementFactor);
|
| 737 | }
|
| 738 |
|
| 739 | return modifyInputSpeedForSquareMovement(newInput);
|
| 740 | }
|
| 741 |
|
| 742 | private static Vec2 modifyInputSpeedForSquareMovement(final Vec2 input) {
|
| 743 | float length = input.length();
|
| 744 | if (length <= 0.0F) {
|
| 745 | return input;
|
| 746 | }
|
| 747 |
|
| 748 | Vec2 direction = input.scale(1.0F / length);
|
| 749 | float distanceToUnitSquare = distanceToUnitSquare(direction);
|
| 750 | float modifiedLength = Math.min(length * distanceToUnitSquare, 1.0F);
|
| 751 | return direction.scale(modifiedLength);
|
| 752 | }
|
| 753 |
|
| 754 | private static float distanceToUnitSquare(final Vec2 direction) {
|
| 755 | float directionX = Math.abs(direction.x);
|
| 756 | float directionY = Math.abs(direction.y);
|
| 757 | float tan = directionY > directionX ? directionX / directionY : directionY / directionX;
|
| 758 | return Mth.sqrt(1.0F + Mth.square(tan));
|
| 759 | }
|
| 760 |
|
| 761 | protected boolean isControlledCamera() {
|
| 762 | return this.minecraft.getCameraEntity() == this;
|
| 763 | }
|
| 764 |
|
| 765 | public void resetPos() {
|
| 766 | this.setPose(Pose.STANDING);
|
| 767 | if (this.level() != null) {
|
| 768 | for (double testY = this.getY(); testY > this.level().getMinY() && testY <= this.level().getMaxY(); testY++) {
|
| 769 | this.setPos(this.getX(), testY, this.getZ());
|
| 770 | if (this.level().noCollision(this)) {
|
| 771 | break;
|
| 772 | }
|
| 773 | }
|
| 774 |
|
| 775 | this.setDeltaMovement(Vec3.ZERO);
|
| 776 | this.setXRot(0.0F);
|
| 777 | }
|
| 778 |
|
| 779 | this.setHealth(this.getMaxHealth());
|
| 780 | this.deathTime = 0;
|
| 781 | }
|
| 782 |
|
| 783 | @Override
|
| 784 | public void aiStep() {
|
| 785 | if (this.sprintTriggerTime > 0) {
|
| 786 | this.sprintTriggerTime--;
|
| 787 | }
|
| 788 |
|
| 789 | if (!(this.minecraft.gui.screen() instanceof LevelLoadingScreen)) {
|
| 790 | this.handlePortalTransitionEffect(this.getActivePortalLocalTransition() == Transition.CONFUSION);
|
| 791 | this.processPortalCooldown();
|
| 792 | }
|
| 793 |
|
| 794 | this.tickSpinningEffect();
|
| 795 | boolean wasJumping = this.input.keyPresses.jump();
|
| 796 | boolean wasShiftKeyDown = this.input.keyPresses.shift();
|
| 797 | boolean hasForwardImpulse = this.input.hasForwardImpulse();
|
| 798 | Abilities abilities = this.getAbilities();
|
| 799 | this.crouching = !abilities.flying
|
| 800 | && !this.isSwimming()
|
| 801 | && !this.isPassenger()
|
| 802 | && this.canPlayerFitWithinBlocksAndEntitiesWhen(Pose.CROUCHING)
|
| 803 | && (this.isShiftKeyDown() || !this.isSleeping() && !this.canPlayerFitWithinBlocksAndEntitiesWhen(Pose.STANDING));
|
| 804 | this.input.tick();
|
| 805 | this.minecraft.getTutorial().onInput(this.input);
|
| 806 | boolean wasAutoJump = false;
|
| 807 | if (this.autoJumpTime > 0) {
|
| 808 | this.autoJumpTime--;
|
| 809 | wasAutoJump = true;
|
| 810 | this.input.makeJump();
|
| 811 | }
|
| 812 |
|
| 813 | if (!this.noPhysics && !this.isPassenger()) {
|
| 814 | this.moveTowardsClosestSpace(this.getX() - this.getBbWidth() * 0.35, this.getZ() + this.getBbWidth() * 0.35);
|
| 815 | this.moveTowardsClosestSpace(this.getX() - this.getBbWidth() * 0.35, this.getZ() - this.getBbWidth() * 0.35);
|
| 816 | this.moveTowardsClosestSpace(this.getX() + this.getBbWidth() * 0.35, this.getZ() - this.getBbWidth() * 0.35);
|
| 817 | this.moveTowardsClosestSpace(this.getX() + this.getBbWidth() * 0.35, this.getZ() + this.getBbWidth() * 0.35);
|
| 818 | }
|
| 819 |
|
| 820 | if (wasShiftKeyDown || this.isSlowDueToUsingItem() && !this.isPassenger() || this.input.keyPresses.backward()) {
|
| 821 | this.sprintTriggerTime = 0;
|
| 822 | }
|
| 823 |
|
| 824 | if (this.canStartSprinting()) {
|
| 825 | if (!hasForwardImpulse) {
|
| 826 | if (this.sprintTriggerTime > 0) {
|
| 827 | this.setSprinting(true);
|
| 828 | } else {
|
| 829 | this.sprintTriggerTime = this.minecraft.options.sprintWindow().get();
|
| 830 | }
|
| 831 | }
|
| 832 |
|
| 833 | if (this.input.keyPresses.sprint()) {
|
| 834 | this.setSprinting(true);
|
| 835 | }
|
| 836 | }
|
| 837 |
|
| 838 | if (this.isSprinting()) {
|
| 839 | if (this.isSwimming()) {
|
| 840 | if (this.shouldStopSwimSprinting()) {
|
| 841 | this.setSprinting(false);
|
| 842 | }
|
| 843 | } else if (this.shouldStopRunSprinting()) {
|
| 844 | this.setSprinting(false);
|
| 845 | }
|
| 846 | }
|
| 847 |
|
| 848 | boolean justToggledCreativeFlight = false;
|
| 849 | if (abilities.mayfly) {
|
| 850 | if (this.minecraft.gameMode.isSpectator()) {
|
| 851 | if (!abilities.flying) {
|
| 852 | abilities.flying = true;
|
| 853 | justToggledCreativeFlight = true;
|
| 854 | this.onUpdateAbilities();
|
| 855 | }
|
| 856 | } else if (!wasJumping && this.input.keyPresses.jump() && !wasAutoJump) {
|
| 857 | if (this.jumpTriggerTime == 0) {
|
| 858 | this.jumpTriggerTime = 7;
|
| 859 | } else if (!this.isSwimming() && (this.getVehicle() == null || this.jumpableVehicle() != null)) {
|
| 860 | abilities.flying = !abilities.flying;
|
| 861 | if (abilities.flying && this.onGround()) {
|
| 862 | this.jumpFromGround();
|
| 863 | }
|
| 864 |
|
| 865 | justToggledCreativeFlight = true;
|
| 866 | this.onUpdateAbilities();
|
| 867 | this.jumpTriggerTime = 0;
|
| 868 | }
|
| 869 | }
|
| 870 | }
|
| 871 |
|
| 872 | if (this.input.keyPresses.jump() && !justToggledCreativeFlight && !wasJumping && !this.onClimbable() && this.tryToStartFallFlying()) {
|
| 873 | this.connection.send(new ServerboundPlayerCommandPacket(this, Action.START_FALL_FLYING));
|
| 874 | }
|
| 875 |
|
| 876 | this.wasFallFlying = this.isFallFlying();
|
| 877 | if (this.isInWater() && this.input.keyPresses.shift() && this.isAffectedByFluids()) {
|
| 878 | this.goDownInWater();
|
| 879 | }
|
| 880 |
|
| 881 | if (this.isEyeInFluid(FluidTags.WATER)) {
|
| 882 | int speed = this.isSpectator() ? 10 : 1;
|
| 883 | this.waterVisionTime = Mth.clamp(this.waterVisionTime + speed, 0, 600);
|
| 884 | } else if (this.waterVisionTime > 0) {
|
| 885 | this.isEyeInFluid(FluidTags.WATER);
|
| 886 | this.waterVisionTime = Mth.clamp(this.waterVisionTime - 10, 0, 600);
|
| 887 | }
|
| 888 |
|
| 889 | if (abilities.flying && this.isControlledCamera()) {
|
| 890 | int inputYa = 0;
|
| 891 | if (this.input.keyPresses.shift()) {
|
| 892 | inputYa--;
|
| 893 | }
|
| 894 |
|
| 895 | if (this.input.keyPresses.jump()) {
|
| 896 | inputYa++;
|
| 897 | }
|
| 898 |
|
| 899 | if (inputYa != 0) {
|
| 900 | this.setDeltaMovement(this.getDeltaMovement().add(0.0, inputYa * abilities.getFlyingSpeed() * 3.0F, 0.0));
|
| 901 | }
|
| 902 | }
|
| 903 |
|
| 904 | PlayerRideableJumping jumpableVehicle = this.jumpableVehicle();
|
| 905 | if (jumpableVehicle != null && jumpableVehicle.getJumpCooldown() == 0) {
|
| 906 | if (this.jumpRidingTicks < 0) {
|
| 907 | this.jumpRidingTicks++;
|
| 908 | if (this.jumpRidingTicks == 0) {
|
| 909 | this.jumpRidingScale = 0.0F;
|
| 910 | }
|
| 911 | }
|
| 912 |
|
| 913 | if (wasJumping && !this.input.keyPresses.jump()) {
|
| 914 | this.jumpRidingTicks = -10;
|
| 915 | jumpableVehicle.onPlayerJump(Mth.floor(this.getJumpRidingScale() * 100.0F));
|
| 916 | this.sendRidingJump();
|
| 917 | } else if (!wasJumping && this.input.keyPresses.jump()) {
|
| 918 | this.jumpRidingTicks = 0;
|
| 919 | this.jumpRidingScale = 0.0F;
|
| 920 | } else if (wasJumping) {
|
| 921 | this.jumpRidingTicks++;
|
| 922 | if (this.jumpRidingTicks < 10) {
|
| 923 | this.jumpRidingScale = this.jumpRidingTicks * 0.1F;
|
| 924 | } else {
|
| 925 | this.jumpRidingScale = 0.8F + 2.0F / (this.jumpRidingTicks - 9) * 0.1F;
|
| 926 | }
|
| 927 | }
|
| 928 | } else {
|
| 929 | this.jumpRidingScale = 0.0F;
|
| 930 | }
|
| 931 |
|
| 932 | super.aiStep();
|
| 933 | if (this.onGround() && abilities.flying && !this.minecraft.gameMode.isSpectator()) {
|
| 934 | abilities.flying = false;
|
| 935 | this.onUpdateAbilities();
|
| 936 | }
|
| 937 | }
|
| 938 |
|
| 939 | private boolean shouldStopRunSprinting() {
|
| 940 | return !this.isSprintingPossible(this.getAbilities().flying) || !this.input.hasForwardImpulse() || this.horizontalCollision && !this.minorHorizontalCollision;
|
| 941 | }
|
| 942 |
|
| 943 | private boolean shouldStopSwimSprinting() {
|
| 944 | return !this.isSprintingPossible(true) || !this.isInWater() || !this.input.hasForwardImpulse() && !this.onGround() && !this.input.keyPresses.shift();
|
| 945 | }
|
| 946 |
|
| 947 | public Transition getActivePortalLocalTransition() {
|
| 948 | return this.portalProcess == null ? Transition.NONE : this.portalProcess.getPortalLocalTransition();
|
| 949 | }
|
| 950 |
|
| 951 | @Override
|
| 952 | protected void tickDeath() {
|
| 953 | this.deathTime++;
|
| 954 | if (this.deathTime == 20) {
|
| 955 | this.remove(RemovalReason.KILLED);
|
| 956 | }
|
| 957 | }
|
| 958 |
|
| 959 | private void handlePortalTransitionEffect(final boolean active) {
|
| 960 | this.oPortalEffectIntensity = this.portalEffectIntensity;
|
| 961 | float step = 0.0F;
|
| 962 | if (active && this.portalProcess != null && this.portalProcess.isInsidePortalThisTick()) {
|
| 963 | if (this.minecraft.gui.screen() != null && !this.minecraft.gui.screen().isAllowedInPortal()) {
|
| 964 | if (this.minecraft.gui.screen() instanceof AbstractContainerScreen) {
|
| 965 | this.closeContainer();
|
| 966 | }
|
| 967 |
|
| 968 | this.minecraft.gui.setScreen(null);
|
| 969 | }
|
| 970 |
|
| 971 | if (this.portalEffectIntensity == 0.0F) {
|
| 972 | this.minecraft.getSoundManager().play(SimpleSoundInstance.forLocalAmbience(SoundEvents.PORTAL_TRIGGER, this.random.nextFloat() * 0.4F + 0.8F, 0.25F));
|
| 973 | }
|
| 974 |
|
| 975 | step = 0.0125F;
|
| 976 | this.portalProcess.setAsInsidePortalThisTick(false);
|
| 977 | } else if (this.portalEffectIntensity > 0.0F) {
|
| 978 | step = -0.05F;
|
| 979 | }
|
| 980 |
|
| 981 | this.portalEffectIntensity = Mth.clamp(this.portalEffectIntensity + step, 0.0F, 1.0F);
|
| 982 | }
|
| 983 |
|
| 984 | private void tickSpinningEffect() {
|
| 985 | float portalIntensity = this.portalEffectIntensity;
|
| 986 | float nauseaIntensity = this.getEffectBlendFactor(MobEffects.NAUSEA, 1.0F);
|
| 987 | if (!(portalIntensity > 0.0F) && !(nauseaIntensity > 0.0F)) {
|
| 988 | this.spinningEffectSpeed = 0.0F;
|
| 989 | } else {
|
| 990 | this.spinningEffectSpeed = (portalIntensity * 20.0F + nauseaIntensity * 7.0F) / (portalIntensity + nauseaIntensity);
|
| 991 | this.spinningEffectTime = this.spinningEffectTime + this.spinningEffectSpeed;
|
| 992 | }
|
| 993 | }
|
| 994 |
|
| 995 | public float getSpinningEffectAngle(final float partialTick) {
|
| 996 | return this.spinningEffectTime + partialTick * this.spinningEffectSpeed;
|
| 997 | }
|
| 998 |
|
| 999 | @Override
|
| 1000 | public void rideTick() {
|
| 1001 | super.rideTick();
|
| 1002 | this.handsBusy = false;
|
| 1003 | if (this.getControlledVehicle() instanceof AbstractBoat boat) {
|
| 1004 | boat.setInput(this.input.keyPresses.left(), this.input.keyPresses.right(), this.input.keyPresses.forward(), this.input.keyPresses.backward());
|
| 1005 | this.handsBusy = this.handsBusy
|
| 1006 | | (this.input.keyPresses.left() || this.input.keyPresses.right() || this.input.keyPresses.forward() || this.input.keyPresses.backward());
|
| 1007 | }
|
| 1008 | }
|
| 1009 |
|
| 1010 | public boolean isHandsBusy() {
|
| 1011 | return this.handsBusy;
|
| 1012 | }
|
| 1013 |
|
| 1014 | @Override
|
| 1015 | public void move(final MoverType moverType, final Vec3 delta) {
|
| 1016 | double prevX = this.getX();
|
| 1017 | double prevZ = this.getZ();
|
| 1018 | super.move(moverType, delta);
|
| 1019 | float deltaX = (float)(this.getX() - prevX);
|
| 1020 | float deltaZ = (float)(this.getZ() - prevZ);
|
| 1021 | this.updateAutoJump(deltaX, deltaZ);
|
| 1022 | this.addWalkedDistance(Mth.length(deltaX, deltaZ) * 0.6F);
|
| 1023 | }
|
| 1024 |
|
| 1025 | public boolean isAutoJumpEnabled() {
|
| 1026 | return this.autoJumpEnabled;
|
| 1027 | }
|
| 1028 |
|
| 1029 | @Override
|
| 1030 | public boolean shouldRotateWithMinecart() {
|
| 1031 | return this.minecraft.options.rotateWithMinecart().get();
|
| 1032 | }
|
| 1033 |
|
| 1034 | protected void updateAutoJump(final float xa, final float za) {
|
| 1035 | if (this.canAutoJump()) {
|
| 1036 | Vec3 moveBegin = this.position();
|
| 1037 | Vec3 moveEnd = moveBegin.add(xa, 0.0, za);
|
| 1038 | Vec3 moveDiff = new Vec3(xa, 0.0, za);
|
| 1039 | float currentSpeed = this.getSpeed();
|
| 1040 | float moveDistSq = (float)moveDiff.lengthSqr();
|
| 1041 | if (moveDistSq <= 0.001F) {
|
| 1042 | Vec2 move = this.input.getMoveVector();
|
| 1043 | float inputXa = currentSpeed * move.x;
|
| 1044 | float inputZa = currentSpeed * move.y;
|
| 1045 | float sin = Mth.sin(this.getYRot() * (float) (Math.PI / 180.0));
|
| 1046 | float cos = Mth.cos(this.getYRot() * (float) (Math.PI / 180.0));
|
| 1047 | moveDiff = new Vec3(inputXa * cos - inputZa * sin, moveDiff.y, inputZa * cos + inputXa * sin);
|
| 1048 | moveDistSq = (float)moveDiff.lengthSqr();
|
| 1049 | if (moveDistSq <= 0.001F) {
|
| 1050 | return;
|
| 1051 | }
|
| 1052 | }
|
| 1053 |
|
| 1054 | float moveDistInverted = Mth.invSqrt(moveDistSq);
|
| 1055 | Vec3 moveDir = moveDiff.scale(moveDistInverted);
|
| 1056 | Vec3 facingDir3 = this.getForward();
|
| 1057 | float facingVsMovingDotProduct2 = (float)(facingDir3.x * moveDir.x + facingDir3.z * moveDir.z);
|
| 1058 | if (!(facingVsMovingDotProduct2 < -0.15F)) {
|
| 1059 | CollisionContext context = CollisionContext.of(this);
|
| 1060 | BlockPos ceilingPos = BlockPos.containing(this.getX(), this.getBoundingBox().maxY, this.getZ());
|
| 1061 | BlockState aboveBlock1 = this.level().getBlockState(ceilingPos);
|
| 1062 | if (aboveBlock1.getCollisionShape(this.level(), ceilingPos, context).isEmpty()) {
|
| 1063 | ceilingPos = ceilingPos.above();
|
| 1064 | BlockState aboveBlock2 = this.level().getBlockState(ceilingPos);
|
| 1065 | if (aboveBlock2.getCollisionShape(this.level(), ceilingPos, context).isEmpty()) {
|
| 1066 | float lookAheadSteps = 7.0F;
|
| 1067 | float jumpHeight = 1.2F;
|
| 1068 | if (this.hasEffect(MobEffects.JUMP_BOOST)) {
|
| 1069 | jumpHeight += (this.getEffect(MobEffects.JUMP_BOOST).getAmplifier() + 1) * 0.75F;
|
| 1070 | }
|
| 1071 |
|
| 1072 | float lookAheadDist = Math.max(currentSpeed * 7.0F, 1.0F / moveDistInverted);
|
| 1073 | Vec3 segBegin = moveBegin;
|
| 1074 | Vec3 segEnd = moveEnd.add(moveDir.scale(lookAheadDist));
|
| 1075 | float playerWidth = this.getBbWidth();
|
| 1076 | float playerHeight = this.getBbHeight();
|
| 1077 | AABB testBox = new AABB(segBegin, segEnd.add(0.0, playerHeight, 0.0)).inflate(playerWidth, 0.0, playerWidth);
|
| 1078 | segBegin = segBegin.add(0.0, 0.51F, 0.0);
|
| 1079 | segEnd = segEnd.add(0.0, 0.51F, 0.0);
|
| 1080 | Vec3 rightDir = moveDir.cross(new Vec3(0.0, 1.0, 0.0));
|
| 1081 | Vec3 rightOffset = rightDir.scale(playerWidth * 0.5F);
|
| 1082 | Vec3 leftSegBegin = segBegin.subtract(rightOffset);
|
| 1083 | Vec3 leftSegEnd = segEnd.subtract(rightOffset);
|
| 1084 | Vec3 rightSegBegin = segBegin.add(rightOffset);
|
| 1085 | Vec3 rightSegEnd = segEnd.add(rightOffset);
|
| 1086 | Iterable<VoxelShape> collisions = this.level().getCollisions(this, testBox);
|
| 1087 | Iterator<AABB> shape = StreamSupport.stream(collisions.spliterator(), false).flatMap(s -> s.toAabbs().stream()).iterator();
|
| 1088 | float obstacleHeight = Float.MIN_VALUE;
|
| 1089 |
|
| 1090 | while (shape.hasNext()) {
|
| 1091 | AABB box = shape.next();
|
| 1092 | if (box.intersects(leftSegBegin, leftSegEnd) || box.intersects(rightSegBegin, rightSegEnd)) {
|
| 1093 | obstacleHeight = (float)box.maxY;
|
| 1094 | Vec3 obstacleShapeCenter = box.getCenter();
|
| 1095 | BlockPos obstacleBlockPos = BlockPos.containing(obstacleShapeCenter);
|
| 1096 |
|
| 1097 | for (int steps = 1; steps < jumpHeight; steps++) {
|
| 1098 | BlockPos abovePos1 = obstacleBlockPos.above(steps);
|
| 1099 | BlockState aboveBlock = this.level().getBlockState(abovePos1);
|
| 1100 | VoxelShape blockShape;
|
| 1101 | if (!(blockShape = aboveBlock.getCollisionShape(this.level(), abovePos1, context)).isEmpty()) {
|
| 1102 | obstacleHeight = (float)blockShape.max(Axis.Y) + abovePos1.getY();
|
| 1103 | if (obstacleHeight - this.getY() > jumpHeight) {
|
| 1104 | return;
|
| 1105 | }
|
| 1106 | }
|
| 1107 |
|
| 1108 | if (steps > 1) {
|
| 1109 | ceilingPos = ceilingPos.above();
|
| 1110 | BlockState aboveBlock3 = this.level().getBlockState(ceilingPos);
|
| 1111 | if (!aboveBlock3.getCollisionShape(this.level(), ceilingPos, context).isEmpty()) {
|
| 1112 | return;
|
| 1113 | }
|
| 1114 | }
|
| 1115 | }
|
| 1116 | break;
|
| 1117 | }
|
| 1118 | }
|
| 1119 |
|
| 1120 | if (obstacleHeight != Float.MIN_VALUE) {
|
| 1121 | float ydelta = (float)(obstacleHeight - this.getY());
|
| 1122 | if (!(ydelta <= 0.5F) && !(ydelta > jumpHeight)) {
|
| 1123 | this.autoJumpTime = 1;
|
| 1124 | }
|
| 1125 | }
|
| 1126 | }
|
| 1127 | }
|
| 1128 | }
|
| 1129 | }
|
| 1130 | }
|
| 1131 |
|
| 1132 | @Override
|
| 1133 | protected boolean isHorizontalCollisionMinor(final Vec3 movement) {
|
| 1134 | float yRotInRadians = this.getYRot() * (float) (Math.PI / 180.0);
|
| 1135 | double yRotSin = Mth.sin(yRotInRadians);
|
| 1136 | double yRotCos = Mth.cos(yRotInRadians);
|
| 1137 | double globalXA = this.xxa * yRotCos - this.zza * yRotSin;
|
| 1138 | double globalZA = this.zza * yRotCos + this.xxa * yRotSin;
|
| 1139 | double aLengthSquared = Mth.square(globalXA) + Mth.square(globalZA);
|
| 1140 | double movementLengthSquared = Mth.square(movement.x) + Mth.square(movement.z);
|
| 1141 | if (!(aLengthSquared < 1.0E-5F) && !(movementLengthSquared < 1.0E-5F)) {
|
| 1142 | double dotProduct = globalXA * movement.x + globalZA * movement.z;
|
| 1143 | double angleBetweenDesiredAndActualMovement = Math.acos(dotProduct / Math.sqrt(aLengthSquared * movementLengthSquared));
|
| 1144 | return angleBetweenDesiredAndActualMovement < 0.13962634F;
|
| 1145 | } else {
|
| 1146 | return false;
|
| 1147 | }
|
| 1148 | }
|
| 1149 |
|
| 1150 | private boolean canAutoJump() {
|
| 1151 | return this.isAutoJumpEnabled()
|
| 1152 | && this.autoJumpTime <= 0
|
| 1153 | && this.onGround()
|
| 1154 | && !this.isStayingOnGroundSurface()
|
| 1155 | && !this.isPassenger()
|
| 1156 | && this.isMoving()
|
| 1157 | && this.getBlockJumpFactor() >= 1.0;
|
| 1158 | }
|
| 1159 |
|
| 1160 | private boolean isMoving() {
|
| 1161 | return this.input.getMoveVector().lengthSquared() > 0.0F;
|
| 1162 | }
|
| 1163 |
|
| 1164 | private boolean isSprintingPossible(final boolean allowedInShallowWater) {
|
| 1165 | return !this.isMobilityRestricted()
|
| 1166 | && (this.isPassenger() ? this.vehicleCanSprint(this.getVehicle()) : this.hasEnoughFoodToDoExhaustiveManoeuvres())
|
| 1167 | && (allowedInShallowWater || !this.isInShallowWater());
|
| 1168 | }
|
| 1169 |
|
| 1170 | private boolean canStartSprinting() {
|
| 1171 | return !this.isSprinting()
|
| 1172 | && this.input.hasForwardImpulse()
|
| 1173 | && this.isSprintingPossible(this.getAbilities().flying)
|
| 1174 | && !this.isSlowDueToUsingItem()
|
| 1175 | && (!this.isFallFlying() || this.isUnderWater())
|
| 1176 | && (!this.isMovingSlowly() || this.isUnderWater());
|
| 1177 | }
|
| 1178 |
|
| 1179 | private boolean vehicleCanSprint(final Entity vehicle) {
|
| 1180 | return vehicle.canSprint() && vehicle.isLocalInstanceAuthoritative();
|
| 1181 | }
|
| 1182 |
|
| 1183 | public float getWaterVision() {
|
| 1184 | if (!this.isEyeInFluid(FluidTags.WATER)) {
|
| 1185 | return 0.0F;
|
| 1186 | }
|
| 1187 |
|
| 1188 | float max = 600.0F;
|
| 1189 | float mid = 100.0F;
|
| 1190 | if (this.waterVisionTime >= 600.0F) {
|
| 1191 | return 1.0F;
|
| 1192 | }
|
| 1193 |
|
| 1194 | float a = Mth.clamp(this.waterVisionTime / 100.0F, 0.0F, 1.0F);
|
| 1195 | float b = this.waterVisionTime < 100.0F ? 0.0F : Mth.clamp((this.waterVisionTime - 100.0F) / 500.0F, 0.0F, 1.0F);
|
| 1196 | return a * 0.6F + b * 0.39999998F;
|
| 1197 | }
|
| 1198 |
|
| 1199 | public void onGameModeChanged(final GameType gameType) {
|
| 1200 | if (gameType == GameType.SPECTATOR) {
|
| 1201 | this.setDeltaMovement(this.getDeltaMovement().with(Axis.Y, 0.0));
|
| 1202 | }
|
| 1203 | }
|
| 1204 |
|
| 1205 | @Override
|
| 1206 | public boolean isUnderWater() {
|
| 1207 | return this.wasUnderwater;
|
| 1208 | }
|
| 1209 |
|
| 1210 | @Override
|
| 1211 | protected boolean updateIsUnderwater() {
|
| 1212 | boolean oldIsUnderwater = this.wasUnderwater;
|
| 1213 | boolean newIsUnderwater = super.updateIsUnderwater();
|
| 1214 | if (this.isSpectator()) {
|
| 1215 | return this.wasUnderwater;
|
| 1216 | }
|
| 1217 |
|
| 1218 | if (!oldIsUnderwater && newIsUnderwater) {
|
| 1219 | this.level().playLocalSound(this.getX(), this.getY(), this.getZ(), SoundEvents.AMBIENT_UNDERWATER_ENTER, SoundSource.AMBIENT, 1.0F, 1.0F, false);
|
| 1220 | this.minecraft.getSoundManager().play(UnderLiquidAmbientSoundInstance.underwater(this));
|
| 1221 | }
|
| 1222 |
|
| 1223 | if (oldIsUnderwater && !newIsUnderwater) {
|
| 1224 | this.level().playLocalSound(this.getX(), this.getY(), this.getZ(), SoundEvents.AMBIENT_UNDERWATER_EXIT, SoundSource.AMBIENT, 1.0F, 1.0F, false);
|
| 1225 | }
|
| 1226 |
|
| 1227 | return this.wasUnderwater;
|
| 1228 | }
|
| 1229 |
|
| 1230 | @Override
|
| 1231 | public Vec3 getRopeHoldPosition(final float partialTickTime) {
|
| 1232 | if (this.minecraft.options.getCameraType().isFirstPerson()) {
|
| 1233 | float yRot = Mth.lerp(partialTickTime * 0.5F, this.getYRot(), this.yRotO) * (float) (Math.PI / 180.0);
|
| 1234 | float xRot = Mth.lerp(partialTickTime * 0.5F, this.getXRot(), this.xRotO) * (float) (Math.PI / 180.0);
|
| 1235 | double handDir = this.getMainArm() == HumanoidArm.RIGHT ? -1.0 : 1.0;
|
| 1236 | Vec3 offset = new Vec3(0.39 * handDir, -0.6, 0.3);
|
| 1237 | return offset.xRot(-xRot).yRot(-yRot).add(this.getEyePosition(partialTickTime));
|
| 1238 | } else {
|
| 1239 | return super.getRopeHoldPosition(partialTickTime);
|
| 1240 | }
|
| 1241 | }
|
| 1242 |
|
| 1243 | @Override
|
| 1244 | public void updateTutorialInventoryAction(final ItemStack itemCarried, final ItemStack itemInSlot, final ClickAction clickAction) {
|
| 1245 | this.minecraft.getTutorial().onInventoryAction(itemCarried, itemInSlot, clickAction);
|
| 1246 | }
|
| 1247 |
|
| 1248 | @Override
|
| 1249 | public float getVisualRotationYInDegrees() {
|
| 1250 | return this.getYRot();
|
| 1251 | }
|
| 1252 |
|
| 1253 | @Override
|
| 1254 | public void handleCreativeModeItemDrop(final ItemStack stack) {
|
| 1255 | this.minecraft.gameMode.handleCreativeModeItemDrop(stack);
|
| 1256 | }
|
| 1257 |
|
| 1258 | @Override
|
| 1259 | public boolean canDropItems() {
|
| 1260 | return this.dropSpamThrottler.isUnderThreshold();
|
| 1261 | }
|
| 1262 |
|
| 1263 | public TickThrottler getDropSpamThrottler() {
|
| 1264 | return this.dropSpamThrottler;
|
| 1265 | }
|
| 1266 |
|
| 1267 | public Input getLastSentInput() {
|
| 1268 | return this.lastSentInput;
|
| 1269 | }
|
| 1270 |
|
| 1271 | public HitResult raycastHitResult(final float a, final Entity cameraEntity) {
|
| 1272 | ItemStack itemStack = this.getActiveItem();
|
| 1273 | AttackRange itemAttackRange = itemStack.get(DataComponents.ATTACK_RANGE);
|
| 1274 | double blockInteractionRange = this.blockInteractionRange();
|
| 1275 | HitResult hitResult = null;
|
| 1276 | if (itemAttackRange != null) {
|
| 1277 | hitResult = itemAttackRange.getClosesetHit(cameraEntity, a, EntitySelector.CAN_BE_PICKED);
|
| 1278 | if (hitResult instanceof BlockHitResult) {
|
| 1279 | hitResult = filterHitResult(hitResult, cameraEntity.getEyePosition(a), blockInteractionRange);
|
| 1280 | }
|
| 1281 | }
|
| 1282 |
|
| 1283 | if (hitResult == null || hitResult.getType() == Type.MISS) {
|
| 1284 | double entityInteractionRange = this.entityInteractionRange();
|
| 1285 | hitResult = pick(cameraEntity, blockInteractionRange, entityInteractionRange, a);
|
| 1286 | }
|
| 1287 |
|
| 1288 | return hitResult;
|
| 1289 | }
|
| 1290 |
|
| 1291 | private static HitResult pick(final Entity cameraEntity, final double blockInteractionRange, final double entityInteractionRange, final float partialTicks) {
|
| 1292 | double maxDistance = Math.max(blockInteractionRange, entityInteractionRange);
|
| 1293 | double maxDistanceSq = Mth.square(maxDistance);
|
| 1294 | Vec3 from = cameraEntity.getEyePosition(partialTicks);
|
| 1295 | HitResult blockHitResult = cameraEntity.pick(maxDistance, partialTicks, false);
|
| 1296 | double blockDistanceSq = blockHitResult.getLocation().distanceToSqr(from);
|
| 1297 | if (blockHitResult.getType() != Type.MISS) {
|
| 1298 | maxDistanceSq = blockDistanceSq;
|
| 1299 | maxDistance = Math.sqrt(maxDistanceSq);
|
| 1300 | }
|
| 1301 |
|
| 1302 | Vec3 direction = cameraEntity.getViewVector(partialTicks);
|
| 1303 | Vec3 to = from.add(direction.x * maxDistance, direction.y * maxDistance, direction.z * maxDistance);
|
| 1304 | float overlap = 1.0F;
|
| 1305 | AABB box = cameraEntity.getBoundingBox().expandTowards(direction.scale(maxDistance)).inflate(1.0, 1.0, 1.0);
|
| 1306 | EntityHitResult entityHitResult = ProjectileUtil.getEntityHitResult(cameraEntity, from, to, box, EntitySelector.CAN_BE_PICKED, maxDistanceSq);
|
| 1307 | return entityHitResult != null && entityHitResult.getLocation().distanceToSqr(from) < blockDistanceSq
|
| 1308 | ? filterHitResult(entityHitResult, from, entityInteractionRange)
|
| 1309 | : filterHitResult(blockHitResult, from, blockInteractionRange);
|
| 1310 | }
|
| 1311 |
|
| 1312 | private static HitResult filterHitResult(final HitResult hitResult, final Vec3 from, final double maxRange) {
|
| 1313 | Vec3 hitLocation = hitResult.getLocation();
|
| 1314 | if (!hitLocation.closerThan(from, maxRange)) {
|
| 1315 | Vec3 location = hitResult.getLocation();
|
| 1316 | Direction direction = Direction.getApproximateNearest(location.x - from.x, location.y - from.y, location.z - from.z);
|
| 1317 | return BlockHitResult.miss(location, direction, BlockPos.containing(location));
|
| 1318 | } else {
|
| 1319 | return hitResult;
|
| 1320 | }
|
| 1321 | }
|
| 1322 |
|
| 1323 | public void setActivePostEffects(final List<Identifier> postEffects) {
|
| 1324 | this.postEffects.clear();
|
| 1325 | this.postEffects.addAll(postEffects);
|
| 1326 | }
|
| 1327 |
|
| 1328 | public List<Identifier> getActivePostEffects() {
|
| 1329 | return this.postEffects;
|
| 1330 | }
|
| 1331 | }
|
| 1332 |
|