| 1 | package net.minecraft.world.entity;
|
| 2 |
|
| 3 | import com.google.common.collect.ImmutableList;
|
| 4 | import com.google.common.collect.Lists;
|
| 5 | import com.google.common.collect.Sets;
|
| 6 | import com.google.common.collect.ImmutableList.Builder;
|
| 7 | import com.mojang.logging.LogUtils;
|
| 8 | import com.mojang.serialization.Codec;
|
| 9 | import it.unimi.dsi.fastutil.floats.FloatArraySet;
|
| 10 | import it.unimi.dsi.fastutil.floats.FloatArrays;
|
| 11 | import it.unimi.dsi.fastutil.floats.FloatSet;
|
| 12 | import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
| 13 | import it.unimi.dsi.fastutil.longs.LongSet;
|
| 14 | import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
| 15 | import java.lang.annotation.ElementType;
|
| 16 | import java.lang.annotation.Retention;
|
| 17 | import java.lang.annotation.RetentionPolicy;
|
| 18 | import java.lang.annotation.Target;
|
| 19 | import java.util.ArrayDeque;
|
| 20 | import java.util.ArrayList;
|
| 21 | import java.util.Arrays;
|
| 22 | import java.util.List;
|
| 23 | import java.util.Locale;
|
| 24 | import java.util.Objects;
|
| 25 | import java.util.Optional;
|
| 26 | import java.util.Set;
|
| 27 | import java.util.UUID;
|
| 28 | import java.util.concurrent.atomic.AtomicInteger;
|
| 29 | import java.util.function.BiConsumer;
|
| 30 | import java.util.function.Predicate;
|
| 31 | import java.util.stream.Stream;
|
| 32 | import net.fabricmc.fabric.api.attachment.v1.AttachmentTarget;
|
| 33 | import net.fabricmc.fabric.api.event.lifecycle.v1.EntityLoadData;
|
| 34 | import net.fabricmc.fabric.api.permission.v1.PermissionContextOwner;
|
| 35 | import net.minecraft.CrashReport;
|
| 36 | import net.minecraft.CrashReportCategory;
|
| 37 | import net.minecraft.ReportedException;
|
| 38 | import net.minecraft.SharedConstants;
|
| 39 | import net.minecraft.advancements.triggers.CriteriaTriggers;
|
| 40 | import net.minecraft.commands.CommandSource;
|
| 41 | import net.minecraft.commands.CommandSourceStack;
|
| 42 | import net.minecraft.commands.arguments.EntityAnchorArgument;
|
| 43 | import net.minecraft.core.BlockPos;
|
| 44 | import net.minecraft.core.Direction;
|
| 45 | import net.minecraft.core.Holder;
|
| 46 | import net.minecraft.core.PositionAndRotation;
|
| 47 | import net.minecraft.core.RegistryAccess;
|
| 48 | import net.minecraft.core.SectionPos;
|
| 49 | import net.minecraft.core.TypedInstance;
|
| 50 | import net.minecraft.core.UUIDUtil;
|
| 51 | import net.minecraft.core.component.DataComponentGetter;
|
| 52 | import net.minecraft.core.component.DataComponentType;
|
| 53 | import net.minecraft.core.component.DataComponents;
|
| 54 | import net.minecraft.core.particles.BlockParticleOption;
|
| 55 | import net.minecraft.core.particles.ParticleTypes;
|
| 56 | import net.minecraft.network.chat.CommonComponents;
|
| 57 | import net.minecraft.network.chat.Component;
|
| 58 | import net.minecraft.network.chat.ComponentSerialization;
|
| 59 | import net.minecraft.network.chat.HoverEvent;
|
| 60 | import net.minecraft.network.chat.MutableComponent;
|
| 61 | import net.minecraft.network.chat.numbers.StyledFormat;
|
| 62 | import net.minecraft.network.protocol.Packet;
|
| 63 | import net.minecraft.network.protocol.game.ClientGamePacketListener;
|
| 64 | import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
|
| 65 | import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
|
| 66 | import net.minecraft.network.protocol.game.VecDeltaCodec;
|
| 67 | import net.minecraft.network.syncher.EntityDataAccessor;
|
| 68 | import net.minecraft.network.syncher.EntityDataSerializers;
|
| 69 | import net.minecraft.network.syncher.SyncedDataHolder;
|
| 70 | import net.minecraft.network.syncher.SynchedEntityData;
|
| 71 | import net.minecraft.resources.ResourceKey;
|
| 72 | import net.minecraft.server.level.ServerEntity;
|
| 73 | import net.minecraft.server.level.ServerLevel;
|
| 74 | import net.minecraft.server.level.ServerPlayer;
|
| 75 | import net.minecraft.server.level.TicketType;
|
| 76 | import net.minecraft.server.permissions.PermissionSet;
|
| 77 | import net.minecraft.sounds.SoundEvent;
|
| 78 | import net.minecraft.sounds.SoundEvents;
|
| 79 | import net.minecraft.sounds.SoundSource;
|
| 80 | import net.minecraft.tags.BlockTags;
|
| 81 | import net.minecraft.tags.DamageTypeTags;
|
| 82 | import net.minecraft.tags.EntityTypeTags;
|
| 83 | import net.minecraft.tags.FluidTags;
|
| 84 | import net.minecraft.tags.TagKey;
|
| 85 | import net.minecraft.util.BlockUtil;
|
| 86 | import net.minecraft.util.Mth;
|
| 87 | import net.minecraft.util.ProblemReporter;
|
| 88 | import net.minecraft.util.RandomSource;
|
| 89 | import net.minecraft.util.Util;
|
| 90 | import net.minecraft.util.debug.DebugEntityBlockIntersection;
|
| 91 | import net.minecraft.util.debug.DebugSubscriptions;
|
| 92 | import net.minecraft.util.debug.DebugValueSource;
|
| 93 | import net.minecraft.util.profiling.Profiler;
|
| 94 | import net.minecraft.util.profiling.ProfilerFiller;
|
| 95 | import net.minecraft.world.InteractionHand;
|
| 96 | import net.minecraft.world.InteractionResult;
|
| 97 | import net.minecraft.world.Nameable;
|
| 98 | import net.minecraft.world.attribute.EnvironmentAttributes;
|
| 99 | import net.minecraft.world.damagesource.DamageSource;
|
| 100 | import net.minecraft.world.damagesource.DamageSources;
|
| 101 | import net.minecraft.world.entity.item.ItemEntity;
|
| 102 | import net.minecraft.world.entity.player.Player;
|
| 103 | import net.minecraft.world.entity.projectile.Projectile;
|
| 104 | import net.minecraft.world.entity.projectile.ProjectileDeflection;
|
| 105 | import net.minecraft.world.item.Item;
|
| 106 | import net.minecraft.world.item.ItemStack;
|
| 107 | import net.minecraft.world.item.Items;
|
| 108 | import net.minecraft.world.item.component.CustomData;
|
| 109 | import net.minecraft.world.level.BlockGetter;
|
| 110 | import net.minecraft.world.level.ChunkPos;
|
| 111 | import net.minecraft.world.level.ClipContext;
|
| 112 | import net.minecraft.world.level.Explosion;
|
| 113 | import net.minecraft.world.level.ItemLike;
|
| 114 | import net.minecraft.world.level.Level;
|
| 115 | import net.minecraft.world.level.block.Block;
|
| 116 | import net.minecraft.world.level.block.Blocks;
|
| 117 | import net.minecraft.world.level.block.FenceGateBlock;
|
| 118 | import net.minecraft.world.level.block.HoneyBlock;
|
| 119 | import net.minecraft.world.level.block.Mirror;
|
| 120 | import net.minecraft.world.level.block.Portal;
|
| 121 | import net.minecraft.world.level.block.RenderShape;
|
| 122 | import net.minecraft.world.level.block.Rotation;
|
| 123 | import net.minecraft.world.level.block.SoundType;
|
| 124 | import net.minecraft.world.level.block.state.BlockState;
|
| 125 | import net.minecraft.world.level.border.WorldBorder;
|
| 126 | import net.minecraft.world.level.entity.EntityAccess;
|
| 127 | import net.minecraft.world.level.entity.EntityInLevelCallback;
|
| 128 | import net.minecraft.world.level.gameevent.DynamicGameEventListener;
|
| 129 | import net.minecraft.world.level.gameevent.GameEvent;
|
| 130 | import net.minecraft.world.level.levelgen.Heightmap;
|
| 131 | import net.minecraft.world.level.material.Fluid;
|
| 132 | import net.minecraft.world.level.material.FluidState;
|
| 133 | import net.minecraft.world.level.material.PushReaction;
|
| 134 | import net.minecraft.world.level.portal.PortalShape;
|
| 135 | import net.minecraft.world.level.portal.TeleportTransition;
|
| 136 | import net.minecraft.world.level.storage.TagValueInput;
|
| 137 | import net.minecraft.world.level.storage.TagValueOutput;
|
| 138 | import net.minecraft.world.level.storage.ValueInput;
|
| 139 | import net.minecraft.world.level.storage.ValueOutput;
|
| 140 | import net.minecraft.world.level.storage.loot.LootTable;
|
| 141 | import net.minecraft.world.phys.AABB;
|
| 142 | import net.minecraft.world.phys.BlockHitResult;
|
| 143 | import net.minecraft.world.phys.HitResult;
|
| 144 | import net.minecraft.world.phys.Vec2;
|
| 145 | import net.minecraft.world.phys.Vec3;
|
| 146 | import net.minecraft.world.phys.shapes.BooleanOp;
|
| 147 | import net.minecraft.world.phys.shapes.CollisionContext;
|
| 148 | import net.minecraft.world.phys.shapes.Shapes;
|
| 149 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 150 | import net.minecraft.world.scores.DisplaySlot;
|
| 151 | import net.minecraft.world.scores.Objective;
|
| 152 | import net.minecraft.world.scores.PlayerTeam;
|
| 153 | import net.minecraft.world.scores.ReadOnlyScoreInfo;
|
| 154 | import net.minecraft.world.scores.ScoreHolder;
|
| 155 | import net.minecraft.world.scores.Scoreboard;
|
| 156 | import net.minecraft.world.scores.Team;
|
| 157 | import net.minecraft.world.waypoints.WaypointTransmitter;
|
| 158 | import org.jetbrains.annotations.Contract;
|
| 159 | import org.joml.Quaternionf;
|
| 160 | import org.jspecify.annotations.Nullable;
|
| 161 | import org.slf4j.Logger;
|
| 162 |
|
| 163 | public abstract class Entity
|
| 164 | implements Nameable,
|
| 165 | EntityAccess,
|
| 166 | ScoreHolder,
|
| 167 | SyncedDataHolder,
|
| 168 | DataComponentGetter,
|
| 169 | ItemOwner,
|
| 170 | SlotProvider,
|
| 171 | DebugValueSource,
|
| 172 | TypedInstance<EntityType<?>>,
|
| 173 | AttachmentTarget,
|
| 174 | EntityLoadData,
|
| 175 | PermissionContextOwner {
|
| 176 | private static final Logger LOGGER = LogUtils.getLogger();
|
| 177 | public static final String TAG_ID = "id";
|
| 178 | public static final String TAG_UUID = "UUID";
|
| 179 | public static final String TAG_PASSENGERS = "Passengers";
|
| 180 | public static final String TAG_DATA = "data";
|
| 181 | public static final String TAG_POS = "Pos";
|
| 182 | public static final String TAG_MOTION = "Motion";
|
| 183 | public static final String TAG_ROTATION = "Rotation";
|
| 184 | public static final String TAG_PORTAL_COOLDOWN = "PortalCooldown";
|
| 185 | public static final String TAG_NO_GRAVITY = "NoGravity";
|
| 186 | public static final String TAG_AIR = "Air";
|
| 187 | public static final String TAG_ON_GROUND = "OnGround";
|
| 188 | public static final String TAG_FALL_DISTANCE = "fall_distance";
|
| 189 | public static final String TAG_FIRE = "Fire";
|
| 190 | public static final String TAG_SILENT = "Silent";
|
| 191 | public static final String TAG_GLOWING = "Glowing";
|
| 192 | public static final String TAG_INVULNERABLE = "Invulnerable";
|
| 193 | public static final String TAG_INVULNERABLE_TIME = "invulnerable_time";
|
| 194 | public static final String TAG_CUSTOM_NAME = "CustomName";
|
| 195 | public static final int INVALID_ENTITY_ID = 0;
|
| 196 | public static final int CONTENTS_SLOT_INDEX = 0;
|
| 197 | public static final int BOARDING_COOLDOWN = 60;
|
| 198 | public static final int TOTAL_AIR_SUPPLY = 300;
|
| 199 | public static final int MAX_ENTITY_TAG_COUNT = 1024;
|
| 200 | private static final Codec<List<String>> TAG_LIST_CODEC = Codec.STRING.sizeLimitedListOf(1024);
|
| 201 | public static final double DEFAULT_NAME_TAG_DISTANCE = 64.0;
|
| 202 | public static final double DEFAULT_BELOW_NAME_DISTANCE = 10.0;
|
| 203 | public static final double MAX_NAME_TAG_DISTANCE = 512.0;
|
| 204 | public static final float DELTA_AFFECTED_BY_BLOCKS_BELOW_0_2 = 0.2F;
|
| 205 | public static final double DELTA_AFFECTED_BY_BLOCKS_BELOW_0_5 = 0.500001;
|
| 206 | public static final double DELTA_AFFECTED_BY_BLOCKS_BELOW_1_0 = 0.999999;
|
| 207 | public static final int BASE_TICKS_REQUIRED_TO_FREEZE = 140;
|
| 208 | public static final int FREEZE_HURT_FREQUENCY = 40;
|
| 209 | public static final int BASE_SAFE_FALL_DISTANCE = 3;
|
| 210 | private static final AABB INITIAL_AABB = new AABB(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
|
| 211 | private static final double WATER_FLOW_SCALE = 0.014;
|
| 212 | private static final double LAVA_FAST_FLOW_SCALE = 0.007;
|
| 213 | private static final double LAVA_SLOW_FLOW_SCALE = 0.0023333333333333335;
|
| 214 | private static final int MAX_BLOCK_ITERATIONS_ALONG_TRAVEL_PER_TICK = 16;
|
| 215 | private static final double MAX_MOVEMENT_RESETTING_TRACE_DISTANCE = 8.0;
|
| 216 | private static final Set<TagKey<Fluid>> FLUIDS_WITH_CURRENT = Set.of(FluidTags.WATER, FluidTags.LAVA);
|
| 217 | private static double viewScale = 1.0;
|
| 218 | private final EntityType<?> type;
|
| 219 | private boolean requiresPrecisePosition;
|
| 220 | private int id = 0;
|
| 221 | public boolean blocksBuilding;
|
| 222 | private ImmutableList<Entity> passengers = ImmutableList.of();
|
| 223 | protected int boardingCooldown;
|
| 224 | private @Nullable Entity vehicle;
|
| 225 | private Level level;
|
| 226 | public double xo;
|
| 227 | public double yo;
|
| 228 | public double zo;
|
| 229 | private Vec3 position;
|
| 230 | private BlockPos blockPosition;
|
| 231 | private ChunkPos chunkPosition;
|
| 232 | private Vec3 deltaMovement = Vec3.ZERO;
|
| 233 | private float yRot;
|
| 234 | private float xRot;
|
| 235 | public float yRotO;
|
| 236 | public float xRotO;
|
| 237 | private AABB bb = INITIAL_AABB;
|
| 238 | private boolean onGround;
|
| 239 | public boolean horizontalCollision;
|
| 240 | public boolean verticalCollision;
|
| 241 | public boolean verticalCollisionBelow;
|
| 242 | public boolean minorHorizontalCollision;
|
| 243 | protected Vec3 stuckSpeedMultiplier = Vec3.ZERO;
|
| 244 | private Entity.@Nullable RemovalReason removalReason;
|
| 245 | public static final float DEFAULT_BB_WIDTH = 0.6F;
|
| 246 | public static final float DEFAULT_BB_HEIGHT = 1.8F;
|
| 247 | public float moveDist;
|
| 248 | public float flyDist;
|
| 249 | public double fallDistance;
|
| 250 | private float nextStep = 1.0F;
|
| 251 | public double xOld;
|
| 252 | public double yOld;
|
| 253 | public double zOld;
|
| 254 | public boolean noPhysics;
|
| 255 | protected final RandomSource random = RandomSource.create();
|
| 256 | public int tickCount;
|
| 257 | private int remainingFireTicks;
|
| 258 | private final EntityFluidInteraction fluidInteraction = new EntityFluidInteraction(FLUIDS_WITH_CURRENT);
|
| 259 | protected boolean wasTouchingWater;
|
| 260 | protected boolean wasEyeInWater;
|
| 261 | private int invulnerableTime;
|
| 262 | protected boolean firstTick = true;
|
| 263 | protected final SynchedEntityData entityData;
|
| 264 | protected static final EntityDataAccessor<Byte> DATA_SHARED_FLAGS_ID = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BYTE);
|
| 265 | protected static final int FLAG_ONFIRE = 0;
|
| 266 | private static final int FLAG_SHIFT_KEY_DOWN = 1;
|
| 267 | private static final int FLAG_SPRINTING = 3;
|
| 268 | private static final int FLAG_SWIMMING = 4;
|
| 269 | private static final int FLAG_INVISIBLE = 5;
|
| 270 | protected static final int FLAG_GLOWING = 6;
|
| 271 | protected static final int FLAG_FALL_FLYING = 7;
|
| 272 | private static final EntityDataAccessor<Integer> DATA_AIR_SUPPLY_ID = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.INT);
|
| 273 | private static final EntityDataAccessor<Optional<Component>> DATA_CUSTOM_NAME = SynchedEntityData.defineId(
|
| 274 | Entity.class, EntityDataSerializers.OPTIONAL_COMPONENT
|
| 275 | );
|
| 276 | private static final EntityDataAccessor<Boolean> DATA_CUSTOM_NAME_VISIBLE = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN);
|
| 277 | private static final EntityDataAccessor<Boolean> DATA_SILENT = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN);
|
| 278 | private static final EntityDataAccessor<Boolean> DATA_NO_GRAVITY = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN);
|
| 279 | protected static final EntityDataAccessor<Pose> DATA_POSE = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.POSE);
|
| 280 | private static final EntityDataAccessor<Integer> DATA_TICKS_FROZEN = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.INT);
|
| 281 | private EntityInLevelCallback levelCallback = EntityInLevelCallback.NULL;
|
| 282 | private final VecDeltaCodec packetPositionCodec = new VecDeltaCodec();
|
| 283 | public boolean needsSync;
|
| 284 | public boolean syncPosition;
|
| 285 | public boolean syncVelocity;
|
| 286 | public @Nullable PortalProcessor portalProcess;
|
| 287 | private int portalCooldown;
|
| 288 | private boolean permanentlyInvulnerable;
|
| 289 | protected UUID uuid = Mth.createInsecureUUID(this.random);
|
| 290 | protected String stringUUID = this.uuid.toString();
|
| 291 | private boolean hasGlowingTag;
|
| 292 | private final Set<String> tags = Sets.newHashSet();
|
| 293 | private final double[] pistonDeltas = new double[]{0.0, 0.0, 0.0};
|
| 294 | private long pistonDeltasGameTime;
|
| 295 | private EntityDimensions dimensions;
|
| 296 | private float eyeHeight;
|
| 297 | public boolean isInPowderSnow;
|
| 298 | public boolean wasInPowderSnow;
|
| 299 | public Optional<BlockPos> mainSupportingBlockPos = Optional.empty();
|
| 300 | private boolean onGroundNoBlocks = false;
|
| 301 | private float crystalSoundIntensity;
|
| 302 | private int lastCrystalSoundPlayTick;
|
| 303 | private boolean hasVisualFire;
|
| 304 | private Vec3 lastKnownSpeed = Vec3.ZERO;
|
| 305 | private @Nullable Vec3 lastKnownPosition;
|
| 306 | private @Nullable BlockState inBlockState = null;
|
| 307 | public static final int MAX_MOVEMENTS_HANDELED_PER_TICK = 100;
|
| 308 | private final ArrayDeque<Entity.Movement> movementThisTick = new ArrayDeque<>(100);
|
| 309 | private final List<Entity.Movement> finalMovementsThisTick = new ObjectArrayList<>();
|
| 310 | private final LongSet visitedBlocks = new LongOpenHashSet();
|
| 311 | protected final InsideBlockEffectApplier.StepBasedCollector insideEffectCollector = new InsideBlockEffectApplier.StepBasedCollector();
|
| 312 | protected final InterpolationHandler interpolationHandler;
|
| 313 | private CustomData customData = CustomData.EMPTY;
|
| 314 |
|
| 315 | public Entity(final EntityType<?> type, final Level level) {
|
| 316 | this.type = type;
|
| 317 | this.level = level;
|
| 318 | this.id = level.getNextEntityId();
|
| 319 | this.dimensions = type.getDimensions();
|
| 320 | this.position = Vec3.ZERO;
|
| 321 | this.blockPosition = BlockPos.ZERO;
|
| 322 | this.chunkPosition = ChunkPos.ZERO;
|
| 323 | SynchedEntityData.Builder entityDataBuilder = new SynchedEntityData.Builder(this);
|
| 324 | entityDataBuilder.define(DATA_SHARED_FLAGS_ID, (byte)0);
|
| 325 | entityDataBuilder.define(DATA_AIR_SUPPLY_ID, this.getMaxAirSupply());
|
| 326 | entityDataBuilder.define(DATA_CUSTOM_NAME_VISIBLE, false);
|
| 327 | entityDataBuilder.define(DATA_CUSTOM_NAME, Optional.empty());
|
| 328 | entityDataBuilder.define(DATA_SILENT, false);
|
| 329 | entityDataBuilder.define(DATA_NO_GRAVITY, false);
|
| 330 | entityDataBuilder.define(DATA_POSE, Pose.STANDING);
|
| 331 | entityDataBuilder.define(DATA_TICKS_FROZEN, 0);
|
| 332 | this.defineSynchedData(entityDataBuilder);
|
| 333 | this.entityData = entityDataBuilder.build();
|
| 334 | this.interpolationHandler = this.createInterpolationHandler();
|
| 335 | this.setPos(0.0, 0.0, 0.0);
|
| 336 | this.eyeHeight = this.dimensions.eyeHeight();
|
| 337 | }
|
| 338 |
|
| 339 | public boolean isColliding(final BlockPos pos, final BlockState state) {
|
| 340 | VoxelShape movedBlockShape = state.getCollisionShape(this.level(), pos, CollisionContext.of(this)).move(pos);
|
| 341 | return Shapes.joinIsNotEmpty(movedBlockShape, Shapes.create(this.getBoundingBox()), BooleanOp.AND);
|
| 342 | }
|
| 343 |
|
| 344 | public int getTeamColor() {
|
| 345 | Team team = this.getTeam();
|
| 346 | return team != null && team.getColor().isPresent() ? team.getColor().get().rgb() : 16777215;
|
| 347 | }
|
| 348 |
|
| 349 | public boolean isSpectator() {
|
| 350 | return false;
|
| 351 | }
|
| 352 |
|
| 353 | public boolean canInteractWithLevel() {
|
| 354 | return this.isAlive() && !this.isRemoved() && !this.isSpectator();
|
| 355 | }
|
| 356 |
|
| 357 | public final void unRide() {
|
| 358 | if (this.isVehicle()) {
|
| 359 | this.ejectPassengers();
|
| 360 | }
|
| 361 |
|
| 362 | if (this.isPassenger()) {
|
| 363 | this.stopRiding();
|
| 364 | }
|
| 365 | }
|
| 366 |
|
| 367 | public void syncPacketPositionCodec(final double x, final double y, final double z) {
|
| 368 | this.packetPositionCodec.setBase(new Vec3(x, y, z));
|
| 369 | }
|
| 370 |
|
| 371 | public VecDeltaCodec getPositionCodec() {
|
| 372 | return this.packetPositionCodec;
|
| 373 | }
|
| 374 |
|
| 375 | public EntityType<?> getType() {
|
| 376 | return this.type;
|
| 377 | }
|
| 378 |
|
| 379 | @Override
|
| 380 | public Holder<EntityType<?>> typeHolder() {
|
| 381 | return this.type.builtInRegistryHolder();
|
| 382 | }
|
| 383 |
|
| 384 | public boolean getRequiresPrecisePosition() {
|
| 385 | return this.requiresPrecisePosition;
|
| 386 | }
|
| 387 |
|
| 388 | public void setRequiresPrecisePosition(final boolean requiresPrecisePosition) {
|
| 389 | this.requiresPrecisePosition = requiresPrecisePosition;
|
| 390 | }
|
| 391 |
|
| 392 | @Override
|
| 393 | public int getId() {
|
| 394 | if (this.id == 0) {
|
| 395 | throw new IllegalStateException("Tried to access entity ID before ID assignment");
|
| 396 | } else {
|
| 397 | return this.id;
|
| 398 | }
|
| 399 | }
|
| 400 |
|
| 401 | public void setId(final int id) {
|
| 402 | this.id = id;
|
| 403 | }
|
| 404 |
|
| 405 | public Set<String> entityTags() {
|
| 406 | return this.tags;
|
| 407 | }
|
| 408 |
|
| 409 | public boolean addTag(final String tag) {
|
| 410 | return this.tags.size() >= 1024 ? false : this.tags.add(tag);
|
| 411 | }
|
| 412 |
|
| 413 | public boolean removeTag(final String tag) {
|
| 414 | return this.tags.remove(tag);
|
| 415 | }
|
| 416 |
|
| 417 | public void kill(final ServerLevel level) {
|
| 418 | this.remove(Entity.RemovalReason.KILLED);
|
| 419 | this.gameEvent(GameEvent.ENTITY_DIE);
|
| 420 | }
|
| 421 |
|
| 422 | public final void discard() {
|
| 423 | this.remove(Entity.RemovalReason.DISCARDED);
|
| 424 | }
|
| 425 |
|
| 426 | protected abstract void defineSynchedData(SynchedEntityData.Builder entityData);
|
| 427 |
|
| 428 | public SynchedEntityData getEntityData() {
|
| 429 | return this.entityData;
|
| 430 | }
|
| 431 |
|
| 432 | @Override
|
| 433 | public boolean equals(final Object obj) {
|
| 434 | return obj instanceof Entity entity ? entity.getId() == this.getId() : false;
|
| 435 | }
|
| 436 |
|
| 437 | @Override
|
| 438 | public int hashCode() {
|
| 439 | return this.getId();
|
| 440 | }
|
| 441 |
|
| 442 | public void remove(final Entity.RemovalReason reason) {
|
| 443 | this.setRemoved(reason);
|
| 444 | }
|
| 445 |
|
| 446 | public void onClientRemoval() {
|
| 447 | }
|
| 448 |
|
| 449 | public void onRemoval(final Entity.RemovalReason reason) {
|
| 450 | }
|
| 451 |
|
| 452 | public void setPose(final Pose pose) {
|
| 453 | this.entityData.set(DATA_POSE, pose);
|
| 454 | }
|
| 455 |
|
| 456 | public Pose getPose() {
|
| 457 | return this.entityData.get(DATA_POSE);
|
| 458 | }
|
| 459 |
|
| 460 | public boolean hasPose(final Pose pose) {
|
| 461 | return this.getPose() == pose;
|
| 462 | }
|
| 463 |
|
| 464 | public boolean closerThan(final Entity other, final double distance) {
|
| 465 | return this.position().closerThan(other.position(), distance);
|
| 466 | }
|
| 467 |
|
| 468 | public boolean closerThan(final Entity other, final double distanceXZ, final double distanceY) {
|
| 469 | double dx = other.getX() - this.getX();
|
| 470 | double dy = other.getY() - this.getY();
|
| 471 | double dz = other.getZ() - this.getZ();
|
| 472 | return Mth.lengthSquared(dx, dz) < Mth.square(distanceXZ) && Mth.square(dy) < Mth.square(distanceY);
|
| 473 | }
|
| 474 |
|
| 475 | protected void setRot(final float yRot, final float xRot) {
|
| 476 | this.setYRot(yRot % 360.0F);
|
| 477 | this.setXRot(xRot % 360.0F);
|
| 478 | }
|
| 479 |
|
| 480 | public final void setPos(final Vec3 pos) {
|
| 481 | this.setPos(pos.x(), pos.y(), pos.z());
|
| 482 | }
|
| 483 |
|
| 484 | public void setPos(final double x, final double y, final double z) {
|
| 485 | this.setPosRaw(x, y, z);
|
| 486 | this.setBoundingBox(this.makeBoundingBox());
|
| 487 | }
|
| 488 |
|
| 489 | protected final AABB makeBoundingBox() {
|
| 490 | return this.makeBoundingBox(this.position);
|
| 491 | }
|
| 492 |
|
| 493 | protected AABB makeBoundingBox(final Vec3 position) {
|
| 494 | return this.dimensions.makeBoundingBox(position);
|
| 495 | }
|
| 496 |
|
| 497 | protected void reapplyPosition() {
|
| 498 | this.lastKnownPosition = null;
|
| 499 | this.setPos(this.position.x, this.position.y, this.position.z);
|
| 500 | }
|
| 501 |
|
| 502 | public void turn(final double xo, final double yo) {
|
| 503 | float xDelta = (float)yo * 0.15F;
|
| 504 | float yDelta = (float)xo * 0.15F;
|
| 505 | this.setXRot(this.getXRot() + xDelta);
|
| 506 | this.setYRot(this.getYRot() + yDelta);
|
| 507 | this.setXRot(Mth.clamp(this.getXRot(), -90.0F, 90.0F));
|
| 508 | this.xRotO += xDelta;
|
| 509 | this.yRotO += yDelta;
|
| 510 | this.xRotO = Mth.clamp(this.xRotO, -90.0F, 90.0F);
|
| 511 | if (this.vehicle != null) {
|
| 512 | this.vehicle.onPassengerTurned(this);
|
| 513 | }
|
| 514 | }
|
| 515 |
|
| 516 | public void updateDataBeforeSync() {
|
| 517 | }
|
| 518 |
|
| 519 | public void tick() {
|
| 520 | this.baseTick();
|
| 521 | }
|
| 522 |
|
| 523 | public final void commonTick() {
|
| 524 | if (this.invulnerableTime > 0) {
|
| 525 | this.invulnerableTime--;
|
| 526 | }
|
| 527 |
|
| 528 | this.setOldPosAndRot();
|
| 529 | if (this.level().isClientSide()) {
|
| 530 | this.getInterpolation().interpolate();
|
| 531 | }
|
| 532 |
|
| 533 | this.tickCount++;
|
| 534 | }
|
| 535 |
|
| 536 | public void baseTick() {
|
| 537 | ProfilerFiller profiler = Profiler.get();
|
| 538 | profiler.push("entityBaseTick");
|
| 539 | this.computeSpeed();
|
| 540 | this.inBlockState = null;
|
| 541 | if (this.isPassenger() && this.getVehicle().isRemoved()) {
|
| 542 | this.stopRiding();
|
| 543 | }
|
| 544 |
|
| 545 | if (this.boardingCooldown > 0) {
|
| 546 | this.boardingCooldown--;
|
| 547 | }
|
| 548 |
|
| 549 | this.handlePortal();
|
| 550 | if (this.canSpawnSprintParticle()) {
|
| 551 | this.spawnSprintParticle();
|
| 552 | }
|
| 553 |
|
| 554 | this.wasInPowderSnow = this.isInPowderSnow;
|
| 555 | this.isInPowderSnow = false;
|
| 556 | this.wasEyeInWater = this.isEyeInFluid(FluidTags.WATER);
|
| 557 | this.updateFluidInteraction();
|
| 558 | this.updateSwimming();
|
| 559 | if (this.level() instanceof ServerLevel serverLevel) {
|
| 560 | if (this.remainingFireTicks > 0) {
|
| 561 | if (this.fireImmune()) {
|
| 562 | this.clearFire();
|
| 563 | } else {
|
| 564 | if (this.remainingFireTicks % 20 == 0 && !this.isInLava()) {
|
| 565 | this.hurtServer(serverLevel, this.damageSources().onFire(), 1.0F);
|
| 566 | }
|
| 567 |
|
| 568 | this.setRemainingFireTicks(this.remainingFireTicks - 1);
|
| 569 | }
|
| 570 | }
|
| 571 | } else {
|
| 572 | this.clearFire();
|
| 573 | }
|
| 574 |
|
| 575 | if (this.isInLava()) {
|
| 576 | this.fallDistance *= 0.5;
|
| 577 | }
|
| 578 |
|
| 579 | this.checkBelowWorld();
|
| 580 | if (!this.level().isClientSide()) {
|
| 581 | this.setSharedFlagOnFire(this.remainingFireTicks > 0);
|
| 582 | }
|
| 583 |
|
| 584 | this.firstTick = false;
|
| 585 | if (this.level() instanceof ServerLevel serverLevel && this instanceof Leashable) {
|
| 586 | Leashable.tickLeash(serverLevel, (Entity & Leashable)this);
|
| 587 | }
|
| 588 |
|
| 589 | profiler.pop();
|
| 590 | }
|
| 591 |
|
| 592 | protected void computeSpeed() {
|
| 593 | if (this.lastKnownPosition == null) {
|
| 594 | this.lastKnownPosition = this.position();
|
| 595 | }
|
| 596 |
|
| 597 | this.lastKnownSpeed = this.position().subtract(this.lastKnownPosition);
|
| 598 | this.lastKnownPosition = this.position();
|
| 599 | }
|
| 600 |
|
| 601 | public void setSharedFlagOnFire(final boolean value) {
|
| 602 | this.setSharedFlag(0, value || this.hasVisualFire);
|
| 603 | }
|
| 604 |
|
| 605 | public void checkBelowWorld() {
|
| 606 | if (this.getY() < this.level().getMinY() - 64) {
|
| 607 | this.onBelowWorld();
|
| 608 | }
|
| 609 | }
|
| 610 |
|
| 611 | public void setPortalCooldown() {
|
| 612 | this.portalCooldown = this.getDimensionChangingDelay();
|
| 613 | }
|
| 614 |
|
| 615 | public void setPortalCooldown(final int portalCooldown) {
|
| 616 | this.portalCooldown = portalCooldown;
|
| 617 | }
|
| 618 |
|
| 619 | public int getPortalCooldown() {
|
| 620 | return this.portalCooldown;
|
| 621 | }
|
| 622 |
|
| 623 | public boolean isOnPortalCooldown() {
|
| 624 | return this.portalCooldown > 0;
|
| 625 | }
|
| 626 |
|
| 627 | protected void processPortalCooldown() {
|
| 628 | if (this.isOnPortalCooldown()) {
|
| 629 | this.portalCooldown--;
|
| 630 | }
|
| 631 | }
|
| 632 |
|
| 633 | public void lavaIgnite() {
|
| 634 | if (!this.fireImmune()) {
|
| 635 | this.igniteForSeconds(15.0F);
|
| 636 | }
|
| 637 | }
|
| 638 |
|
| 639 | public void lavaHurt() {
|
| 640 | if (!this.fireImmune()) {
|
| 641 | if (this.level() instanceof ServerLevel serverLevel
|
| 642 | && this.hurtServer(serverLevel, this.damageSources().lava(), 4.0F)
|
| 643 | && this.shouldPlayLavaHurtSound()
|
| 644 | && !this.isSilent()) {
|
| 645 | serverLevel.playSound(
|
| 646 | null, this.getX(), this.getY(), this.getZ(), SoundEvents.GENERIC_BURN, this.getSoundSource(), 0.4F, 2.0F + this.random.nextFloat() * 0.4F
|
| 647 | );
|
| 648 | }
|
| 649 | }
|
| 650 | }
|
| 651 |
|
| 652 | protected boolean shouldPlayLavaHurtSound() {
|
| 653 | return true;
|
| 654 | }
|
| 655 |
|
| 656 | public final void igniteForSeconds(final float numberOfSeconds) {
|
| 657 | this.igniteForTicks(Mth.floor(numberOfSeconds * 20.0F));
|
| 658 | }
|
| 659 |
|
| 660 | public void igniteForTicks(final int numberOfTicks) {
|
| 661 | if (this.remainingFireTicks < numberOfTicks) {
|
| 662 | this.setRemainingFireTicks(numberOfTicks);
|
| 663 | }
|
| 664 |
|
| 665 | this.clearFreeze();
|
| 666 | }
|
| 667 |
|
| 668 | public void setRemainingFireTicks(final int remainingTicks) {
|
| 669 | this.remainingFireTicks = remainingTicks;
|
| 670 | }
|
| 671 |
|
| 672 | public int getRemainingFireTicks() {
|
| 673 | return this.remainingFireTicks;
|
| 674 | }
|
| 675 |
|
| 676 | public void clearFire() {
|
| 677 | this.setRemainingFireTicks(Math.min(0, this.getRemainingFireTicks()));
|
| 678 | }
|
| 679 |
|
| 680 | protected void onBelowWorld() {
|
| 681 | this.discard();
|
| 682 | }
|
| 683 |
|
| 684 | public boolean isFree(final double xa, final double ya, final double za) {
|
| 685 | return this.isFree(this.getBoundingBox().move(xa, ya, za));
|
| 686 | }
|
| 687 |
|
| 688 | private boolean isFree(final AABB box) {
|
| 689 | return this.level().noCollision(this, box) && !this.level().containsAnyLiquid(box);
|
| 690 | }
|
| 691 |
|
| 692 | public void setOnGround(final boolean onGround) {
|
| 693 | this.onGround = onGround;
|
| 694 | this.checkSupportingBlock(onGround, null);
|
| 695 | }
|
| 696 |
|
| 697 | public void setOnGroundWithMovement(final boolean onGround, final Vec3 movement) {
|
| 698 | this.setOnGroundWithMovement(onGround, this.horizontalCollision, movement);
|
| 699 | }
|
| 700 |
|
| 701 | public void setOnGroundWithMovement(final boolean onGround, final boolean horizontalCollision, final Vec3 movement) {
|
| 702 | this.onGround = onGround;
|
| 703 | this.horizontalCollision = horizontalCollision;
|
| 704 | this.checkSupportingBlock(onGround, movement);
|
| 705 | }
|
| 706 |
|
| 707 | public boolean isSupportedBy(final BlockPos pos) {
|
| 708 | return this.mainSupportingBlockPos.isPresent() && this.mainSupportingBlockPos.get().equals(pos);
|
| 709 | }
|
| 710 |
|
| 711 | protected void checkSupportingBlock(final boolean onGround, final @Nullable Vec3 movement) {
|
| 712 | if (onGround) {
|
| 713 | AABB boundingBox = this.getBoundingBox();
|
| 714 | AABB testArea = new AABB(boundingBox.minX, boundingBox.minY - 1.0E-6, boundingBox.minZ, boundingBox.maxX, boundingBox.minY, boundingBox.maxZ);
|
| 715 | Optional<BlockPos> supportingBlock = this.level.findSupportingBlock(this, testArea);
|
| 716 | if (supportingBlock.isPresent() || this.onGroundNoBlocks) {
|
| 717 | this.mainSupportingBlockPos = supportingBlock;
|
| 718 | } else if (movement != null) {
|
| 719 | AABB onGroundCollisionTestArea = testArea.move(-movement.x, 0.0, -movement.z);
|
| 720 | supportingBlock = this.level.findSupportingBlock(this, onGroundCollisionTestArea);
|
| 721 | this.mainSupportingBlockPos = supportingBlock;
|
| 722 | }
|
| 723 |
|
| 724 | this.onGroundNoBlocks = supportingBlock.isEmpty();
|
| 725 | } else {
|
| 726 | this.onGroundNoBlocks = false;
|
| 727 | if (this.mainSupportingBlockPos.isPresent()) {
|
| 728 | this.mainSupportingBlockPos = Optional.empty();
|
| 729 | }
|
| 730 | }
|
| 731 | }
|
| 732 |
|
| 733 | public boolean onGround() {
|
| 734 | return this.onGround;
|
| 735 | }
|
| 736 |
|
| 737 | public void move(final MoverType moverType, Vec3 delta) {
|
| 738 | if (SharedConstants.IS_RUNNING_IN_IDE && !moverType.isServerAndClientSimulated() && !this.canSimulateMovement()) {
|
| 739 | throw (IllegalStateException)Util.pauseInIde(new IllegalStateException("Attempted to move entity on a logical side not permitted to simulate movement"));
|
| 740 | }
|
| 741 |
|
| 742 | if (this.noPhysics) {
|
| 743 | this.setPos(this.getX() + delta.x, this.getY() + delta.y, this.getZ() + delta.z);
|
| 744 | this.recordMovement(moverType, delta);
|
| 745 | this.horizontalCollision = false;
|
| 746 | this.verticalCollision = false;
|
| 747 | this.verticalCollisionBelow = false;
|
| 748 | this.minorHorizontalCollision = false;
|
| 749 | } else {
|
| 750 | if (moverType == MoverType.PISTON) {
|
| 751 | delta = this.limitPistonMovement(delta);
|
| 752 | if (delta.equals(Vec3.ZERO)) {
|
| 753 | return;
|
| 754 | }
|
| 755 | }
|
| 756 |
|
| 757 | ProfilerFiller profiler = Profiler.get();
|
| 758 | profiler.push("move");
|
| 759 | if (this.stuckSpeedMultiplier.lengthSqr() > 1.0E-7) {
|
| 760 | if (moverType != MoverType.PISTON) {
|
| 761 | delta = delta.multiply(this.stuckSpeedMultiplier);
|
| 762 | }
|
| 763 |
|
| 764 | this.stuckSpeedMultiplier = Vec3.ZERO;
|
| 765 | this.setDeltaMovement(Vec3.ZERO);
|
| 766 | }
|
| 767 |
|
| 768 | delta = this.maybeBackOffFromEdge(delta, moverType);
|
| 769 | Vec3 movement = this.collide(delta);
|
| 770 | double movementLength = movement.lengthSqr();
|
| 771 | if (movementLength > 1.0E-7 || delta.lengthSqr() - movementLength < 1.0E-7) {
|
| 772 | if (this.fallDistance != 0.0 && movementLength >= 1.0) {
|
| 773 | double checkDistance = Math.min(movement.length(), 8.0);
|
| 774 | Vec3 checkTo = this.position().add(movement.normalize().scale(checkDistance));
|
| 775 | BlockHitResult hitResult = this.level()
|
| 776 | .clip(new ClipContext(this.position(), checkTo, ClipContext.Block.FALLDAMAGE_RESETTING, ClipContext.Fluid.WATER, this));
|
| 777 | if (hitResult.getType() != HitResult.Type.MISS) {
|
| 778 | this.resetFallDistance();
|
| 779 | }
|
| 780 | }
|
| 781 |
|
| 782 | Vec3 pos = this.position();
|
| 783 | Vec3 newPosition = pos.add(movement);
|
| 784 | this.addMovementThisTick(new Entity.Movement(pos, newPosition, delta));
|
| 785 | this.setPos(newPosition);
|
| 786 | this.recordMovement(moverType, movement);
|
| 787 | }
|
| 788 |
|
| 789 | profiler.pop();
|
| 790 | profiler.push("rest");
|
| 791 | boolean xCollision = !Mth.equal(delta.x, movement.x);
|
| 792 | boolean zCollision = !Mth.equal(delta.z, movement.z);
|
| 793 | this.horizontalCollision = xCollision || zCollision;
|
| 794 | boolean movedVertically = Math.abs(delta.y) > 0.0;
|
| 795 | if (movedVertically || this.isLocalInstanceAuthoritative()) {
|
| 796 | this.verticalCollision = delta.y != movement.y;
|
| 797 | this.verticalCollisionBelow = this.verticalCollision && delta.y < 0.0;
|
| 798 | this.setOnGroundWithMovement(this.verticalCollisionBelow, this.horizontalCollision, movement);
|
| 799 | }
|
| 800 |
|
| 801 | if (this.horizontalCollision) {
|
| 802 | this.minorHorizontalCollision = this.isHorizontalCollisionMinor(movement);
|
| 803 | } else {
|
| 804 | this.minorHorizontalCollision = false;
|
| 805 | }
|
| 806 |
|
| 807 | BlockPos effectPos = this.getOnPosLegacy();
|
| 808 | BlockState effectState = this.level().getBlockState(effectPos);
|
| 809 | if (this.isLocalInstanceAuthoritative()) {
|
| 810 | this.checkFallDamage(movement.y, this.onGround(), effectState, effectPos);
|
| 811 | }
|
| 812 |
|
| 813 | if (this.isRemoved()) {
|
| 814 | profiler.pop();
|
| 815 | } else {
|
| 816 | if (this.canSimulateMovement() && (movedVertically && this.verticalCollision || this.horizontalCollision)) {
|
| 817 | this.restituteMovementAfterCollisions(effectState, xCollision, zCollision, movement);
|
| 818 | }
|
| 819 |
|
| 820 | if (!this.level().isClientSide() || this.isLocalInstanceAuthoritative()) {
|
| 821 | Entity.MovementEmission emission = this.getMovementEmission();
|
| 822 | if (emission.emitsAnything() && !this.isPassenger()) {
|
| 823 | this.applyMovementEmissionAndPlaySound(emission, movement, effectPos, effectState);
|
| 824 | }
|
| 825 | }
|
| 826 |
|
| 827 | float blockSpeedFactor = this.getBlockSpeedFactor();
|
| 828 | this.setDeltaMovement(this.getDeltaMovement().multiply(blockSpeedFactor, 1.0, blockSpeedFactor));
|
| 829 | profiler.pop();
|
| 830 | }
|
| 831 | }
|
| 832 | }
|
| 833 |
|
| 834 | public void recordMovement(final MoverType moverType, final Vec3 movement) {
|
| 835 | if (moverType.isServerAndClientSimulated() || this.getMoveSimulationType() == MoveSimulationType.SERVER_AND_CLIENT) {
|
| 836 | this.interpolationHandler.applyPredictedMovement(movement);
|
| 837 | }
|
| 838 | }
|
| 839 |
|
| 840 | private void restituteMovementAfterCollisions(final BlockState effectState, final boolean xCollision, final boolean zCollision, final Vec3 movement) {
|
| 841 | double restitution = this.isSuppressingBounce() ? 0.0 : this.getEntityBounciness();
|
| 842 | Vec3 currentMovement = this.getDeltaMovement();
|
| 843 | Vec3 movementAfterBounce = currentMovement;
|
| 844 | if (xCollision) {
|
| 845 | movementAfterBounce = movementAfterBounce.with(Direction.Axis.X, -currentMovement.x * restitution);
|
| 846 | }
|
| 847 |
|
| 848 | if (zCollision) {
|
| 849 | movementAfterBounce = movementAfterBounce.with(Direction.Axis.Z, -currentMovement.z * restitution);
|
| 850 | }
|
| 851 |
|
| 852 | boolean bounced = restitution > 0.0 && (xCollision || zCollision);
|
| 853 | if (this.verticalCollision) {
|
| 854 | if (this.verticalCollisionBelow) {
|
| 855 | restitution = !(-currentMovement.y <= this.getEffectiveGravity()) && !this.isSuppressingBounce() && !effectState.is(BlockTags.SUPPRESSES_BOUNCE)
|
| 856 | ? Math.max(restitution, this.getBlockBounciness(effectState.getBlock()))
|
| 857 | : 0.0;
|
| 858 | }
|
| 859 |
|
| 860 | double gravityCompensation;
|
| 861 | double effectiveDrag;
|
| 862 | if (restitution > 0.0) {
|
| 863 | double portionWithMovement = movement.y / currentMovement.y;
|
| 864 | gravityCompensation = portionWithMovement * this.getEffectiveGravity();
|
| 865 | effectiveDrag = Mth.lerp(portionWithMovement, 1.0, this.getAirDrag());
|
| 866 | bounced = true;
|
| 867 | } else {
|
| 868 | gravityCompensation = 0.0;
|
| 869 | effectiveDrag = 1.0;
|
| 870 | }
|
| 871 |
|
| 872 | movementAfterBounce = movementAfterBounce.with(Direction.Axis.Y, (gravityCompensation - currentMovement.y) * effectiveDrag * restitution);
|
| 873 | }
|
| 874 |
|
| 875 | if (bounced) {
|
| 876 | effectState.getBlock().bounceOn(this.level, effectState, this.getBlockPosBelowThatAffectsMyMovement(), this, this.fallDistance);
|
| 877 | this.gameEvent(GameEvent.BOUNCE);
|
| 878 | this.syncPosition = true;
|
| 879 | }
|
| 880 |
|
| 881 | this.setDeltaMovement(movementAfterBounce);
|
| 882 | }
|
| 883 |
|
| 884 | private double getBlockBounciness(final Block onBlock) {
|
| 885 | float blockBounciness = onBlock.getBounceRestitution();
|
| 886 | if (!(this instanceof LivingEntity)) {
|
| 887 | blockBounciness *= 0.8F;
|
| 888 | }
|
| 889 |
|
| 890 | return blockBounciness;
|
| 891 | }
|
| 892 |
|
| 893 | protected double getEntityBounciness() {
|
| 894 | return 0.0;
|
| 895 | }
|
| 896 |
|
| 897 | protected double getEffectiveGravity() {
|
| 898 | return this.getGravity();
|
| 899 | }
|
| 900 |
|
| 901 | protected boolean omnidirectionalAirMover() {
|
| 902 | return false;
|
| 903 | }
|
| 904 |
|
| 905 | private void applyMovementEmissionAndPlaySound(
|
| 906 | final Entity.MovementEmission emission, final Vec3 clippedMovement, final BlockPos effectPos, final BlockState effectState
|
| 907 | ) {
|
| 908 | float moveDistScale = 0.6F;
|
| 909 | float movedDistance = (float)(clippedMovement.length() * 0.6F);
|
| 910 | float horizontalMovedDistance = (float)(clippedMovement.horizontalDistance() * 0.6F);
|
| 911 | BlockPos supportingPos = this.getOnPos();
|
| 912 | BlockState supportingState = this.level().getBlockState(supportingPos);
|
| 913 | boolean climbing = this.isStateClimbable(supportingState);
|
| 914 | this.moveDist += climbing ? movedDistance : horizontalMovedDistance;
|
| 915 | this.flyDist += movedDistance;
|
| 916 | if (this.moveDist > this.nextStep && !supportingState.isAir()) {
|
| 917 | boolean onlyEffectStateEmittions = supportingPos.equals(effectPos);
|
| 918 | boolean producedSideEffects = this.vibrationAndSoundEffectsFromBlock(
|
| 919 | effectPos, effectState, emission.emitsSounds(), onlyEffectStateEmittions, clippedMovement
|
| 920 | );
|
| 921 | if (!onlyEffectStateEmittions) {
|
| 922 | producedSideEffects |= this.vibrationAndSoundEffectsFromBlock(supportingPos, supportingState, false, emission.emitsEvents(), clippedMovement);
|
| 923 | }
|
| 924 |
|
| 925 | if (producedSideEffects) {
|
| 926 | this.nextStep = this.nextStep();
|
| 927 | } else if (this.isInWater()) {
|
| 928 | this.nextStep = this.nextStep();
|
| 929 | if (emission.emitsSounds()) {
|
| 930 | this.waterSwimSound();
|
| 931 | }
|
| 932 |
|
| 933 | if (emission.emitsEvents()) {
|
| 934 | this.gameEvent(GameEvent.SWIM);
|
| 935 | }
|
| 936 | }
|
| 937 | } else if (supportingState.isAir()) {
|
| 938 | this.processFlappingMovement();
|
| 939 | }
|
| 940 | }
|
| 941 |
|
| 942 | protected void applyEffectsFromBlocks() {
|
| 943 | this.finalMovementsThisTick.clear();
|
| 944 | this.finalMovementsThisTick.addAll(this.movementThisTick);
|
| 945 | this.movementThisTick.clear();
|
| 946 | if (this.finalMovementsThisTick.isEmpty()) {
|
| 947 | this.finalMovementsThisTick.add(new Entity.Movement(this.oldPosition(), this.position()));
|
| 948 | } else if (this.finalMovementsThisTick.getLast().to.distanceToSqr(this.position()) > 9.9999994E-11F) {
|
| 949 | this.finalMovementsThisTick.add(new Entity.Movement(this.finalMovementsThisTick.getLast().to, this.position()));
|
| 950 | }
|
| 951 |
|
| 952 | this.applyEffectsFromBlocks(this.finalMovementsThisTick);
|
| 953 | }
|
| 954 |
|
| 955 | protected void applyEffectsFromBlocksForLastMovements() {
|
| 956 | this.applyEffectsFromBlocks(this.finalMovementsThisTick);
|
| 957 | }
|
| 958 |
|
| 959 | private void addMovementThisTick(final Entity.Movement movement) {
|
| 960 | if (this.movementThisTick.size() >= 100) {
|
| 961 | Entity.Movement first = this.movementThisTick.removeFirst();
|
| 962 | Entity.Movement second = this.movementThisTick.removeFirst();
|
| 963 | Entity.Movement combined = new Entity.Movement(first.from(), second.to());
|
| 964 | this.movementThisTick.addFirst(combined);
|
| 965 | }
|
| 966 |
|
| 967 | this.movementThisTick.add(movement);
|
| 968 | }
|
| 969 |
|
| 970 | public void removeLatestMovementRecording() {
|
| 971 | if (!this.movementThisTick.isEmpty()) {
|
| 972 | this.movementThisTick.removeLast();
|
| 973 | }
|
| 974 | }
|
| 975 |
|
| 976 | protected void clearMovementThisTick() {
|
| 977 | this.movementThisTick.clear();
|
| 978 | }
|
| 979 |
|
| 980 | public boolean hasMovedHorizontallyRecently() {
|
| 981 | return Math.abs(this.lastKnownSpeed.horizontalDistance()) > 1.0E-5F;
|
| 982 | }
|
| 983 |
|
| 984 | public void applyEffectsFromBlocks(final Vec3 from, final Vec3 to) {
|
| 985 | this.applyEffectsFromBlocks(List.of(new Entity.Movement(from, to)));
|
| 986 | }
|
| 987 |
|
| 988 | private void applyEffectsFromBlocks(final List<Entity.Movement> movements) {
|
| 989 | if (this.isAffectedByBlocks()) {
|
| 990 | if (this.onGround()) {
|
| 991 | BlockPos effectPos = this.getOnPosLegacy();
|
| 992 | BlockState effectState = this.level().getBlockState(effectPos);
|
| 993 | effectState.getBlock().stepOn(this.level(), effectPos, effectState, this);
|
| 994 | }
|
| 995 |
|
| 996 | boolean wasOnFire = this.isOnFire();
|
| 997 | boolean wasFreezing = this.isFreezing();
|
| 998 | int previousRemainingFireTicks = this.getRemainingFireTicks();
|
| 999 | this.checkInsideBlocks(movements, this.insideEffectCollector);
|
| 1000 | this.insideEffectCollector.applyAndClear(this);
|
| 1001 | if (this.isInRain()) {
|
| 1002 | this.clearFire();
|
| 1003 | }
|
| 1004 |
|
| 1005 | if (wasOnFire && !this.isOnFire() || wasFreezing && !this.isFreezing()) {
|
| 1006 | this.playEntityOnFireExtinguishedSound();
|
| 1007 | }
|
| 1008 |
|
| 1009 | boolean wasIgnitedThisTick = this.getRemainingFireTicks() > previousRemainingFireTicks;
|
| 1010 | if (!this.level().isClientSide() && !this.isOnFire() && !wasIgnitedThisTick) {
|
| 1011 | this.setRemainingFireTicks(-this.getFireImmuneTicks());
|
| 1012 | }
|
| 1013 | }
|
| 1014 | }
|
| 1015 |
|
| 1016 | protected boolean isAffectedByBlocks() {
|
| 1017 | return !this.isRemoved() && !this.noPhysics;
|
| 1018 | }
|
| 1019 |
|
| 1020 | private boolean isStateClimbable(final BlockState state) {
|
| 1021 | return state.is(BlockTags.CLIMBABLE) || state.is(Blocks.POWDER_SNOW);
|
| 1022 | }
|
| 1023 |
|
| 1024 | private boolean vibrationAndSoundEffectsFromBlock(
|
| 1025 | final BlockPos pos, final BlockState blockState, final boolean shouldSound, final boolean shouldVibrate, final Vec3 clippedMovement
|
| 1026 | ) {
|
| 1027 | if (blockState.isAir()) {
|
| 1028 | return false;
|
| 1029 | }
|
| 1030 |
|
| 1031 | boolean isClimbable = this.isStateClimbable(blockState);
|
| 1032 | if ((this.onGround() || isClimbable || this.isCrouching() && clippedMovement.y == 0.0 || this.isOnRails()) && !this.isSwimming()) {
|
| 1033 | if (shouldSound) {
|
| 1034 | this.walkingStepSound(pos, blockState);
|
| 1035 | }
|
| 1036 |
|
| 1037 | if (shouldVibrate) {
|
| 1038 | this.level().gameEvent(GameEvent.STEP, this.position(), GameEvent.Context.of(this, blockState));
|
| 1039 | }
|
| 1040 |
|
| 1041 | return true;
|
| 1042 | } else {
|
| 1043 | return false;
|
| 1044 | }
|
| 1045 | }
|
| 1046 |
|
| 1047 | protected boolean isHorizontalCollisionMinor(final Vec3 movement) {
|
| 1048 | return false;
|
| 1049 | }
|
| 1050 |
|
| 1051 | protected void playEntityOnFireExtinguishedSound() {
|
| 1052 | if (!this.level.isClientSide()) {
|
| 1053 | this.level()
|
| 1054 | .playSound(
|
| 1055 | null,
|
| 1056 | this.getX(),
|
| 1057 | this.getY(),
|
| 1058 | this.getZ(),
|
| 1059 | SoundEvents.GENERIC_EXTINGUISH_FIRE,
|
| 1060 | this.getSoundSource(),
|
| 1061 | 0.7F,
|
| 1062 | 1.6F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F
|
| 1063 | );
|
| 1064 | }
|
| 1065 | }
|
| 1066 |
|
| 1067 | public void extinguishFire() {
|
| 1068 | if (this.isOnFire()) {
|
| 1069 | this.playEntityOnFireExtinguishedSound();
|
| 1070 | }
|
| 1071 |
|
| 1072 | this.clearFire();
|
| 1073 | }
|
| 1074 |
|
| 1075 | protected void processFlappingMovement() {
|
| 1076 | if (this.isFlapping()) {
|
| 1077 | this.onFlap();
|
| 1078 | if (this.getMovementEmission().emitsEvents()) {
|
| 1079 | this.gameEvent(GameEvent.FLAP);
|
| 1080 | }
|
| 1081 | }
|
| 1082 | }
|
| 1083 |
|
| 1084 | @Deprecated
|
| 1085 | public BlockPos getOnPosLegacy() {
|
| 1086 | return this.getOnPos(0.2F);
|
| 1087 | }
|
| 1088 |
|
| 1089 | public BlockPos getBlockPosBelowThatAffectsMyMovement() {
|
| 1090 | return this.getOnPos(0.500001F);
|
| 1091 | }
|
| 1092 |
|
| 1093 | public BlockPos getOnPos() {
|
| 1094 | return this.getOnPos(1.0E-5F);
|
| 1095 | }
|
| 1096 |
|
| 1097 | protected BlockPos getOnPos(final float offset) {
|
| 1098 | if (this.mainSupportingBlockPos.isPresent()) {
|
| 1099 | BlockPos getOnPos = this.mainSupportingBlockPos.get();
|
| 1100 | if (!(offset > 1.0E-5F)) {
|
| 1101 | return getOnPos;
|
| 1102 | }
|
| 1103 |
|
| 1104 | BlockState belowState = this.level().getBlockState(getOnPos);
|
| 1105 | return (!(offset <= 0.5) || !belowState.is(BlockTags.FENCES)) && !belowState.is(BlockTags.WALLS) && !(belowState.getBlock() instanceof FenceGateBlock)
|
| 1106 | ? getOnPos.atY(Mth.floor(this.position.y - offset))
|
| 1107 | : getOnPos;
|
| 1108 | } else {
|
| 1109 | int xTruncated = Mth.floor(this.position.x);
|
| 1110 | int yTruncatedBelow = Mth.floor(this.position.y - offset);
|
| 1111 | int zTruncated = Mth.floor(this.position.z);
|
| 1112 | return new BlockPos(xTruncated, yTruncatedBelow, zTruncated);
|
| 1113 | }
|
| 1114 | }
|
| 1115 |
|
| 1116 | protected float getBlockJumpFactor() {
|
| 1117 | float jumpFactorHere = this.level().getBlockState(this.blockPosition()).getBlock().getJumpFactor();
|
| 1118 | float jumpFactorBelow = this.level().getBlockState(this.getBlockPosBelowThatAffectsMyMovement()).getBlock().getJumpFactor();
|
| 1119 | return jumpFactorHere == 1.0 ? jumpFactorBelow : jumpFactorHere;
|
| 1120 | }
|
| 1121 |
|
| 1122 | protected float getBlockSpeedFactor() {
|
| 1123 | BlockState state = this.level().getBlockState(this.blockPosition());
|
| 1124 | float speedFactorHere = state.getBlock().getSpeedFactor();
|
| 1125 | if (!state.is(Blocks.WATER) && !state.is(Blocks.BUBBLE_COLUMN)) {
|
| 1126 | return speedFactorHere == 1.0 ? this.level().getBlockState(this.getBlockPosBelowThatAffectsMyMovement()).getBlock().getSpeedFactor() : speedFactorHere;
|
| 1127 | } else {
|
| 1128 | return speedFactorHere;
|
| 1129 | }
|
| 1130 | }
|
| 1131 |
|
| 1132 | protected Vec3 maybeBackOffFromEdge(final Vec3 delta, final MoverType moverType) {
|
| 1133 | return delta;
|
| 1134 | }
|
| 1135 |
|
| 1136 | protected Vec3 limitPistonMovement(final Vec3 vec) {
|
| 1137 | if (vec.lengthSqr() <= 1.0E-7) {
|
| 1138 | return vec;
|
| 1139 | }
|
| 1140 |
|
| 1141 | long currentGameTime = this.level().getGameTime();
|
| 1142 | if (currentGameTime != this.pistonDeltasGameTime) {
|
| 1143 | Arrays.fill(this.pistonDeltas, 0.0);
|
| 1144 | this.pistonDeltasGameTime = currentGameTime;
|
| 1145 | }
|
| 1146 |
|
| 1147 | if (vec.x != 0.0) {
|
| 1148 | double xa = this.applyPistonMovementRestriction(Direction.Axis.X, vec.x);
|
| 1149 | return Math.abs(xa) <= 1.0E-5F ? Vec3.ZERO : new Vec3(xa, 0.0, 0.0);
|
| 1150 | } else if (vec.y != 0.0) {
|
| 1151 | double ya = this.applyPistonMovementRestriction(Direction.Axis.Y, vec.y);
|
| 1152 | return Math.abs(ya) <= 1.0E-5F ? Vec3.ZERO : new Vec3(0.0, ya, 0.0);
|
| 1153 | } else if (vec.z != 0.0) {
|
| 1154 | double za = this.applyPistonMovementRestriction(Direction.Axis.Z, vec.z);
|
| 1155 | return Math.abs(za) <= 1.0E-5F ? Vec3.ZERO : new Vec3(0.0, 0.0, za);
|
| 1156 | } else {
|
| 1157 | return Vec3.ZERO;
|
| 1158 | }
|
| 1159 | }
|
| 1160 |
|
| 1161 | private double applyPistonMovementRestriction(final Direction.Axis axis, double amount) {
|
| 1162 | int ordinal = axis.ordinal();
|
| 1163 | double min = Mth.clamp(amount + this.pistonDeltas[ordinal], -0.51, 0.51);
|
| 1164 | amount = min - this.pistonDeltas[ordinal];
|
| 1165 | this.pistonDeltas[ordinal] = min;
|
| 1166 | return amount;
|
| 1167 | }
|
| 1168 |
|
| 1169 | public double getAvailableSpaceBelow(final double maxDistance) {
|
| 1170 | AABB aabb = this.getBoundingBox();
|
| 1171 | AABB below = aabb.setMinY(aabb.minY - maxDistance).setMaxY(aabb.minY);
|
| 1172 | List<VoxelShape> colliders = collectAllColliders(this, this.level, below);
|
| 1173 | return colliders.isEmpty() ? maxDistance : -Shapes.collide(Direction.Axis.Y, aabb, colliders, -maxDistance);
|
| 1174 | }
|
| 1175 |
|
| 1176 | private Vec3 collide(final Vec3 movement) {
|
| 1177 | AABB aabb = this.getBoundingBox();
|
| 1178 | List<VoxelShape> entityColliders = this.level().getEntityCollisions(this, aabb.expandTowards(movement).expandTowards(0.0, this.maxUpStep(), 0.0));
|
| 1179 | Vec3 movementStep = movement.lengthSqr() == 0.0 ? movement : collideBoundingBox(this, movement, aabb, this.level(), entityColliders);
|
| 1180 | boolean xCollision = movement.x != movementStep.x;
|
| 1181 | boolean yCollision = movement.y != movementStep.y;
|
| 1182 | boolean zCollision = movement.z != movementStep.z;
|
| 1183 | boolean onGroundAfterCollision = yCollision && movement.y < 0.0;
|
| 1184 | if (this.maxUpStep() > 0.0F && (onGroundAfterCollision || this.onGround()) && (xCollision || zCollision)) {
|
| 1185 | AABB groundedAABB = onGroundAfterCollision ? aabb.move(0.0, movementStep.y, 0.0) : aabb;
|
| 1186 | AABB stepUpAABB = groundedAABB.expandTowards(movement.x, this.maxUpStep(), movement.z);
|
| 1187 | if (!onGroundAfterCollision) {
|
| 1188 | stepUpAABB = stepUpAABB.expandTowards(0.0, -1.0E-5F, 0.0);
|
| 1189 | }
|
| 1190 |
|
| 1191 | List<VoxelShape> colliders = collectCollidersIgnoringWorldBorder(this, this.level, entityColliders, stepUpAABB);
|
| 1192 | float stepHeightToSkip = (float)movementStep.y;
|
| 1193 | float[] candidateStepUpHeights = collectCandidateStepUpHeights(groundedAABB, colliders, this.maxUpStep(), stepHeightToSkip);
|
| 1194 |
|
| 1195 | for (float candidateStepUpHeight : candidateStepUpHeights) {
|
| 1196 | Vec3 stepFromGround = collideWithShapes(new Vec3(movement.x, candidateStepUpHeight, movement.z), groundedAABB, colliders);
|
| 1197 | if (stepFromGround.horizontalDistanceSqr() > movementStep.horizontalDistanceSqr()) {
|
| 1198 | double distanceToGround = aabb.minY - groundedAABB.minY;
|
| 1199 | return stepFromGround.subtract(0.0, distanceToGround, 0.0);
|
| 1200 | }
|
| 1201 | }
|
| 1202 | }
|
| 1203 |
|
| 1204 | return movementStep;
|
| 1205 | }
|
| 1206 |
|
| 1207 | private static float[] collectCandidateStepUpHeights(
|
| 1208 | final AABB boundingBox, final List<VoxelShape> colliders, final float maxStepHeight, final float stepHeightToSkip
|
| 1209 | ) {
|
| 1210 | FloatSet candidates = new FloatArraySet(4);
|
| 1211 |
|
| 1212 | for (VoxelShape collider : colliders) {
|
| 1213 | for (double coord : collider.getCoords(Direction.Axis.Y)) {
|
| 1214 | float relativeCoord = (float)(coord - boundingBox.minY);
|
| 1215 | if (!(relativeCoord < 0.0F) && relativeCoord != stepHeightToSkip) {
|
| 1216 | if (relativeCoord > maxStepHeight) {
|
| 1217 | break;
|
| 1218 | }
|
| 1219 |
|
| 1220 | candidates.add(relativeCoord);
|
| 1221 | }
|
| 1222 | }
|
| 1223 | }
|
| 1224 |
|
| 1225 | float[] sortedCandidates = candidates.toFloatArray();
|
| 1226 | FloatArrays.unstableSort(sortedCandidates);
|
| 1227 | return sortedCandidates;
|
| 1228 | }
|
| 1229 |
|
| 1230 | public static Vec3 collideBoundingBox(
|
| 1231 | final Entity source, final Vec3 movement, final AABB boundingBox, final Level level, final List<VoxelShape> entityColliders
|
| 1232 | ) {
|
| 1233 | List<VoxelShape> colliders = collectCollidersIgnoringWorldBorder(source, level, entityColliders, boundingBox.expandTowards(movement));
|
| 1234 | return collideWithShapes(movement, boundingBox, colliders);
|
| 1235 | }
|
| 1236 |
|
| 1237 | public static Vec3 collideBoundingBox(
|
| 1238 | final CollisionContext source, final Vec3 movement, final AABB boundingBox, final Level level, final List<VoxelShape> entityColliders
|
| 1239 | ) {
|
| 1240 | List<VoxelShape> colliders = collectCollidersIgnoringWorldBorder(source, level, entityColliders, boundingBox.expandTowards(movement));
|
| 1241 | return collideWithShapes(movement, boundingBox, colliders);
|
| 1242 | }
|
| 1243 |
|
| 1244 | public static List<VoxelShape> collectAllColliders(final @Nullable Entity source, final Level level, final AABB boundingBox) {
|
| 1245 | List<VoxelShape> entityColliders = level.getEntityCollisions(source, boundingBox);
|
| 1246 | return collectCollidersIgnoringWorldBorder(source, level, entityColliders, boundingBox);
|
| 1247 | }
|
| 1248 |
|
| 1249 | private static List<VoxelShape> collectCollidersIgnoringWorldBorder(
|
| 1250 | final @Nullable Entity source, final Level level, final List<VoxelShape> entityColliders, final AABB boundingBox
|
| 1251 | ) {
|
| 1252 | Builder<VoxelShape> colliders = ImmutableList.builderWithExpectedSize(entityColliders.size() + 1);
|
| 1253 | if (!entityColliders.isEmpty()) {
|
| 1254 | colliders.addAll(entityColliders);
|
| 1255 | }
|
| 1256 |
|
| 1257 | WorldBorder worldBorder = level.getWorldBorder();
|
| 1258 | boolean isEntityInsideCloseToBorder = source != null && worldBorder.isInsideCloseToBorder(source, boundingBox);
|
| 1259 | if (isEntityInsideCloseToBorder) {
|
| 1260 | colliders.add(worldBorder.getCollisionShape());
|
| 1261 | }
|
| 1262 |
|
| 1263 | colliders.addAll(level.getBlockCollisions(source, boundingBox));
|
| 1264 | return colliders.build();
|
| 1265 | }
|
| 1266 |
|
| 1267 | private static List<VoxelShape> collectCollidersIgnoringWorldBorder(
|
| 1268 | final CollisionContext source, final Level level, final List<VoxelShape> entityColliders, final AABB boundingBox
|
| 1269 | ) {
|
| 1270 | Builder<VoxelShape> colliders = ImmutableList.builderWithExpectedSize(entityColliders.size() + 1);
|
| 1271 | if (!entityColliders.isEmpty()) {
|
| 1272 | colliders.addAll(entityColliders);
|
| 1273 | }
|
| 1274 |
|
| 1275 | colliders.addAll(level.getBlockCollisionsFromContext(source, boundingBox));
|
| 1276 | return colliders.build();
|
| 1277 | }
|
| 1278 |
|
| 1279 | private static Vec3 collideWithShapes(final Vec3 movement, final AABB boundingBox, final List<VoxelShape> shapes) {
|
| 1280 | if (shapes.isEmpty()) {
|
| 1281 | return movement;
|
| 1282 | }
|
| 1283 |
|
| 1284 | Vec3 resolvedMovement = Vec3.ZERO;
|
| 1285 |
|
| 1286 | for (Direction.Axis axis : Direction.axisStepOrder(movement)) {
|
| 1287 | double axisMovement = movement.get(axis);
|
| 1288 | if (axisMovement != 0.0) {
|
| 1289 | double collision = Shapes.collide(axis, boundingBox.move(resolvedMovement), shapes, axisMovement);
|
| 1290 | resolvedMovement = resolvedMovement.with(axis, collision);
|
| 1291 | }
|
| 1292 | }
|
| 1293 |
|
| 1294 | return resolvedMovement;
|
| 1295 | }
|
| 1296 |
|
| 1297 | protected float nextStep() {
|
| 1298 | return (int)this.moveDist + 1;
|
| 1299 | }
|
| 1300 |
|
| 1301 | protected SoundEvent getSwimSound() {
|
| 1302 | return SoundEvents.GENERIC_SWIM;
|
| 1303 | }
|
| 1304 |
|
| 1305 | protected SoundEvent getSwimSplashSound() {
|
| 1306 | return SoundEvents.GENERIC_SPLASH;
|
| 1307 | }
|
| 1308 |
|
| 1309 | protected SoundEvent getSwimHighSpeedSplashSound() {
|
| 1310 | return SoundEvents.GENERIC_SPLASH;
|
| 1311 | }
|
| 1312 |
|
| 1313 | private void checkInsideBlocks(final List<Entity.Movement> movements, final InsideBlockEffectApplier.StepBasedCollector effectCollector) {
|
| 1314 | if (this.isAffectedByBlocks()) {
|
| 1315 | LongSet visitedBlocks = this.visitedBlocks;
|
| 1316 |
|
| 1317 | for (Entity.Movement movement : movements) {
|
| 1318 | Vec3 pos = movement.from;
|
| 1319 | Vec3 delta = movement.to().subtract(movement.from());
|
| 1320 | int maxMovementIterations = 16;
|
| 1321 | if (movement.axisDependentOriginalMovement().isPresent() && delta.lengthSqr() > 0.0) {
|
| 1322 | for (Direction.Axis axis : Direction.axisStepOrder(movement.axisDependentOriginalMovement().get())) {
|
| 1323 | double axisMove = delta.get(axis);
|
| 1324 | if (axisMove != 0.0) {
|
| 1325 | Vec3 to = pos.relative(axis.getPositive(), axisMove);
|
| 1326 | maxMovementIterations -= this.checkInsideBlocks(pos, to, effectCollector, visitedBlocks, maxMovementIterations);
|
| 1327 | pos = to;
|
| 1328 | }
|
| 1329 | }
|
| 1330 | } else {
|
| 1331 | maxMovementIterations -= this.checkInsideBlocks(movement.from(), movement.to(), effectCollector, visitedBlocks, 16);
|
| 1332 | }
|
| 1333 |
|
| 1334 | if (maxMovementIterations <= 0) {
|
| 1335 | this.checkInsideBlocks(movement.to(), movement.to(), effectCollector, visitedBlocks, 1);
|
| 1336 | }
|
| 1337 | }
|
| 1338 |
|
| 1339 | visitedBlocks.clear();
|
| 1340 | }
|
| 1341 | }
|
| 1342 |
|
| 1343 | private int checkInsideBlocks(
|
| 1344 | final Vec3 from,
|
| 1345 | final Vec3 to,
|
| 1346 | final InsideBlockEffectApplier.StepBasedCollector effectCollector,
|
| 1347 | final LongSet visitedBlocks,
|
| 1348 | final int maxMovementIterations
|
| 1349 | ) {
|
| 1350 | AABB deflatedBoundingBoxAtTarget = this.makeBoundingBox(to).deflate(1.0E-5F);
|
| 1351 | boolean movedFar = from.distanceToSqr(to) > Mth.square(0.9999900000002526);
|
| 1352 | boolean debugEntityBlockIntersections = this.level instanceof ServerLevel serverLevel
|
| 1353 | && serverLevel.getServer().debugSubscribers().hasAnySubscriberFor(DebugSubscriptions.ENTITY_BLOCK_INTERSECTIONS);
|
| 1354 | AtomicInteger iterations = new AtomicInteger();
|
| 1355 | BlockGetter.forEachBlockIntersectedBetween(
|
| 1356 | from,
|
| 1357 | to,
|
| 1358 | deflatedBoundingBoxAtTarget,
|
| 1359 | (blockIntersection, iteration) -> {
|
| 1360 | if (!this.isAlive()) {
|
| 1361 | return false;
|
| 1362 | }
|
| 1363 |
|
| 1364 | if (iteration >= maxMovementIterations) {
|
| 1365 | return false;
|
| 1366 | }
|
| 1367 |
|
| 1368 | iterations.set(iteration);
|
| 1369 | BlockState state = this.level().getBlockState(blockIntersection);
|
| 1370 | if (state.isAir()) {
|
| 1371 | if (debugEntityBlockIntersections) {
|
| 1372 | this.debugBlockIntersection((ServerLevel)this.level(), blockIntersection.immutable(), false, false);
|
| 1373 | }
|
| 1374 |
|
| 1375 | return true;
|
| 1376 | } else {
|
| 1377 | VoxelShape intersectShape = state.getEntityInsideCollisionShape(this.level(), blockIntersection, this);
|
| 1378 | boolean insideBlock = intersectShape == Shapes.block()
|
| 1379 | || this.collidedWithShapeMovingFrom(from, to, intersectShape.move(new Vec3(blockIntersection)).toAabbs());
|
| 1380 | boolean insideFluid = this.collidedWithFluid(state.getFluidState(), blockIntersection, from, to);
|
| 1381 | if ((insideBlock || insideFluid) && visitedBlocks.add(blockIntersection.asLong())) {
|
| 1382 | if (insideBlock) {
|
| 1383 | try {
|
| 1384 | boolean isPrecise = movedFar || deflatedBoundingBoxAtTarget.intersects(blockIntersection);
|
| 1385 | effectCollector.advanceStep(iteration);
|
| 1386 | state.entityInside(this.level(), blockIntersection, this, effectCollector, isPrecise);
|
| 1387 | this.onInsideBlock(state);
|
| 1388 | } catch (Throwable t) {
|
| 1389 | CrashReport report = CrashReport.forThrowable(t, "Colliding entity with block");
|
| 1390 | CrashReportCategory category = report.addCategory("Block being collided with");
|
| 1391 | CrashReportCategory.populateBlockDetails(category, this.level(), blockIntersection, state);
|
| 1392 | CrashReportCategory entityCategory = report.addCategory("Entity being checked for collision");
|
| 1393 | this.fillCrashReportCategory(entityCategory);
|
| 1394 | throw new ReportedException(report);
|
| 1395 | }
|
| 1396 | }
|
| 1397 |
|
| 1398 | if (insideFluid) {
|
| 1399 | effectCollector.advanceStep(iteration);
|
| 1400 | state.getFluidState().entityInside(this.level(), blockIntersection, this, effectCollector);
|
| 1401 | }
|
| 1402 |
|
| 1403 | if (debugEntityBlockIntersections) {
|
| 1404 | this.debugBlockIntersection((ServerLevel)this.level(), blockIntersection.immutable(), insideBlock, insideFluid);
|
| 1405 | }
|
| 1406 |
|
| 1407 | return true;
|
| 1408 | } else {
|
| 1409 | return true;
|
| 1410 | }
|
| 1411 | }
|
| 1412 | }
|
| 1413 | );
|
| 1414 | return iterations.get() + 1;
|
| 1415 | }
|
| 1416 |
|
| 1417 | private void debugBlockIntersection(final ServerLevel level, final BlockPos pos, final boolean insideBlock, final boolean insideFluid) {
|
| 1418 | DebugEntityBlockIntersection type;
|
| 1419 | if (insideFluid) {
|
| 1420 | type = DebugEntityBlockIntersection.IN_FLUID;
|
| 1421 | } else if (insideBlock) {
|
| 1422 | type = DebugEntityBlockIntersection.IN_BLOCK;
|
| 1423 | } else {
|
| 1424 | type = DebugEntityBlockIntersection.IN_AIR;
|
| 1425 | }
|
| 1426 |
|
| 1427 | level.debugSynchronizers().sendBlockValue(pos, DebugSubscriptions.ENTITY_BLOCK_INTERSECTIONS, type);
|
| 1428 | }
|
| 1429 |
|
| 1430 | public boolean collidedWithFluid(final FluidState fluidState, final BlockPos blockPos, final Vec3 from, final Vec3 to) {
|
| 1431 | AABB fluidAABB = fluidState.getAABB(this.level(), blockPos);
|
| 1432 | return fluidAABB != null && this.collidedWithShapeMovingFrom(from, to, List.of(fluidAABB));
|
| 1433 | }
|
| 1434 |
|
| 1435 | public boolean collidedWithShapeMovingFrom(final Vec3 from, final Vec3 to, final List<AABB> aabbs) {
|
| 1436 | AABB boundingBoxAtFrom = this.makeBoundingBox(from);
|
| 1437 | Vec3 travelVector = to.subtract(from);
|
| 1438 | return boundingBoxAtFrom.collidedAlongVector(travelVector, aabbs);
|
| 1439 | }
|
| 1440 |
|
| 1441 | protected void onInsideBlock(final BlockState state) {
|
| 1442 | }
|
| 1443 |
|
| 1444 | public BlockPos adjustSpawnLocation(final ServerLevel level, final BlockPos spawnSuggestion) {
|
| 1445 | BlockPos spawnBlockPos = level.getRespawnData().pos();
|
| 1446 | Vec3 spawnPos = Vec3.atCenterOf(spawnBlockPos);
|
| 1447 | int spawnHeight = level.getChunkAt(spawnBlockPos).getHeight(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, spawnBlockPos.getX(), spawnBlockPos.getZ()) + 1;
|
| 1448 | return BlockPos.containing(spawnPos.x, spawnHeight, spawnPos.z);
|
| 1449 | }
|
| 1450 |
|
| 1451 | public void gameEvent(final Holder<GameEvent> event, final @Nullable Entity sourceEntity) {
|
| 1452 | this.level().gameEvent(sourceEntity, event, this.position);
|
| 1453 | }
|
| 1454 |
|
| 1455 | public void gameEvent(final Holder<GameEvent> event) {
|
| 1456 | this.gameEvent(event, this);
|
| 1457 | }
|
| 1458 |
|
| 1459 | private void walkingStepSound(final BlockPos onPos, final BlockState onState) {
|
| 1460 | this.playStepSound(onPos, onState);
|
| 1461 | if (this.shouldPlayAmethystStepSound(onState)) {
|
| 1462 | this.playAmethystStepSound();
|
| 1463 | }
|
| 1464 | }
|
| 1465 |
|
| 1466 | protected void waterSwimSound() {
|
| 1467 | Entity entity = Objects.requireNonNullElse(this.getControllingPassenger(), this);
|
| 1468 | float volumeModifier = entity == this ? 0.35F : 0.4F;
|
| 1469 | Vec3 deltaMovement = entity.getDeltaMovement();
|
| 1470 | float speed = Math.min(
|
| 1471 | 1.0F,
|
| 1472 | (float)Math.sqrt(deltaMovement.x * deltaMovement.x * 0.2F + deltaMovement.y * deltaMovement.y + deltaMovement.z * deltaMovement.z * 0.2F) * volumeModifier
|
| 1473 | );
|
| 1474 | this.playSwimSound(speed);
|
| 1475 | }
|
| 1476 |
|
| 1477 | protected BlockPos getPrimaryStepSoundBlockPos(final BlockPos affectingPos) {
|
| 1478 | BlockPos abovePos = affectingPos.above();
|
| 1479 | BlockState aboveState = this.level().getBlockState(abovePos);
|
| 1480 | return !aboveState.is(BlockTags.INSIDE_STEP_SOUND_BLOCKS) && !aboveState.is(BlockTags.COMBINATION_STEP_SOUND_BLOCKS) ? affectingPos : abovePos;
|
| 1481 | }
|
| 1482 |
|
| 1483 | protected void playCombinationStepSounds(final BlockState primaryStepSound, final BlockState secondaryStepSound) {
|
| 1484 | SoundType primaryStepSoundType = primaryStepSound.getSoundType();
|
| 1485 | this.playSound(primaryStepSoundType.getStepSound(), primaryStepSoundType.getVolume() * 0.15F, primaryStepSoundType.getPitch());
|
| 1486 | this.playMuffledStepSound(secondaryStepSound);
|
| 1487 | }
|
| 1488 |
|
| 1489 | protected void playMuffledStepSound(final BlockState blockState) {
|
| 1490 | SoundType secondaryStepSoundType = blockState.getSoundType();
|
| 1491 | this.playSound(secondaryStepSoundType.getStepSound(), secondaryStepSoundType.getVolume() * 0.05F, secondaryStepSoundType.getPitch() * 0.8F);
|
| 1492 | }
|
| 1493 |
|
| 1494 | protected void playStepSound(final BlockPos pos, final BlockState blockState) {
|
| 1495 | SoundType soundType = blockState.getSoundType();
|
| 1496 | this.playSound(soundType.getStepSound(), soundType.getVolume() * 0.15F, soundType.getPitch());
|
| 1497 | }
|
| 1498 |
|
| 1499 | private boolean shouldPlayAmethystStepSound(final BlockState affectingState) {
|
| 1500 | return affectingState.is(BlockTags.CRYSTAL_SOUND_BLOCKS) && this.tickCount >= this.lastCrystalSoundPlayTick + 20;
|
| 1501 | }
|
| 1502 |
|
| 1503 | private void playAmethystStepSound() {
|
| 1504 | this.crystalSoundIntensity = this.crystalSoundIntensity * (float)Math.pow(0.997, this.tickCount - this.lastCrystalSoundPlayTick);
|
| 1505 | this.crystalSoundIntensity = Math.min(1.0F, this.crystalSoundIntensity + 0.07F);
|
| 1506 | float pitch = 0.5F + this.crystalSoundIntensity * this.random.nextFloat() * 1.2F;
|
| 1507 | float volume = 0.1F + this.crystalSoundIntensity * 1.2F;
|
| 1508 | this.playSound(SoundEvents.AMETHYST_BLOCK_CHIME, volume, pitch);
|
| 1509 | this.lastCrystalSoundPlayTick = this.tickCount;
|
| 1510 | }
|
| 1511 |
|
| 1512 | protected void playSwimSound(final float volume) {
|
| 1513 | this.playSound(this.getSwimSound(), volume, 1.0F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F);
|
| 1514 | }
|
| 1515 |
|
| 1516 | protected void onFlap() {
|
| 1517 | }
|
| 1518 |
|
| 1519 | protected boolean isFlapping() {
|
| 1520 | return false;
|
| 1521 | }
|
| 1522 |
|
| 1523 | public void playSound(final SoundEvent sound, final float volume, final float pitch) {
|
| 1524 | if (!this.isSilent()) {
|
| 1525 | this.level().playSound(null, this.getX(), this.getY(), this.getZ(), sound, this.getSoundSource(), volume, pitch);
|
| 1526 | }
|
| 1527 | }
|
| 1528 |
|
| 1529 | public void playSound(final SoundEvent sound) {
|
| 1530 | if (!this.isSilent()) {
|
| 1531 | this.playSound(sound, 1.0F, 1.0F);
|
| 1532 | }
|
| 1533 | }
|
| 1534 |
|
| 1535 | public boolean isSilent() {
|
| 1536 | return this.entityData.get(DATA_SILENT);
|
| 1537 | }
|
| 1538 |
|
| 1539 | public void setSilent(final boolean silent) {
|
| 1540 | this.entityData.set(DATA_SILENT, silent);
|
| 1541 | }
|
| 1542 |
|
| 1543 | public boolean isNoGravity() {
|
| 1544 | return this.entityData.get(DATA_NO_GRAVITY);
|
| 1545 | }
|
| 1546 |
|
| 1547 | public void setNoGravity(final boolean noGravity) {
|
| 1548 | this.entityData.set(DATA_NO_GRAVITY, noGravity);
|
| 1549 | }
|
| 1550 |
|
| 1551 | protected double getDefaultGravity() {
|
| 1552 | return 0.0;
|
| 1553 | }
|
| 1554 |
|
| 1555 | public final double getGravity() {
|
| 1556 | return this.isNoGravity() ? 0.0 : this.getDefaultGravity();
|
| 1557 | }
|
| 1558 |
|
| 1559 | protected void applyGravity() {
|
| 1560 | double gravity = this.getGravity();
|
| 1561 | if (gravity != 0.0) {
|
| 1562 | this.setDeltaMovement(this.getDeltaMovement().add(0.0, -gravity, 0.0));
|
| 1563 | }
|
| 1564 | }
|
| 1565 |
|
| 1566 | protected float getAirDrag() {
|
| 1567 | return 0.98F;
|
| 1568 | }
|
| 1569 |
|
| 1570 | protected Entity.MovementEmission getMovementEmission() {
|
| 1571 | return Entity.MovementEmission.ALL;
|
| 1572 | }
|
| 1573 |
|
| 1574 | public boolean dampensVibrations() {
|
| 1575 | return false;
|
| 1576 | }
|
| 1577 |
|
| 1578 | public final void doCheckFallDamage(final double xa, final double ya, final double za, final boolean onGround) {
|
| 1579 | if (!this.touchingUnloadedChunk()) {
|
| 1580 | this.checkSupportingBlock(onGround, new Vec3(xa, ya, za));
|
| 1581 | BlockPos pos = this.getOnPosLegacy();
|
| 1582 | BlockState state = this.level().getBlockState(pos);
|
| 1583 | this.checkFallDamage(ya, onGround, state, pos);
|
| 1584 | }
|
| 1585 | }
|
| 1586 |
|
| 1587 | protected void checkFallDamage(final double ya, final boolean onGround, final BlockState onState, final BlockPos pos) {
|
| 1588 | if (!this.isInWater() && ya < 0.0) {
|
| 1589 | this.fallDistance -= (float)ya;
|
| 1590 | }
|
| 1591 |
|
| 1592 | if (onGround) {
|
| 1593 | if (this.fallDistance > 0.0) {
|
| 1594 | onState.getBlock().fallOn(this.level(), onState, pos, this, this.fallDistance);
|
| 1595 | this.level()
|
| 1596 | .gameEvent(
|
| 1597 | GameEvent.HIT_GROUND,
|
| 1598 | this.position,
|
| 1599 | GameEvent.Context.of(this, this.mainSupportingBlockPos.<BlockState>map(blockPos -> this.level().getBlockState(blockPos)).orElse(onState))
|
| 1600 | );
|
| 1601 | }
|
| 1602 |
|
| 1603 | this.resetFallDistance();
|
| 1604 | }
|
| 1605 | }
|
| 1606 |
|
| 1607 | public boolean fireImmune() {
|
| 1608 | return this.getType().fireImmune();
|
| 1609 | }
|
| 1610 |
|
| 1611 | public boolean causeFallDamage(final double fallDistance, final float damageModifier, final DamageSource damageSource) {
|
| 1612 | if (this.is(EntityTypeTags.FALL_DAMAGE_IMMUNE)) {
|
| 1613 | return false;
|
| 1614 | }
|
| 1615 |
|
| 1616 | this.propagateFallToPassengers(fallDistance, damageModifier, damageSource);
|
| 1617 | return false;
|
| 1618 | }
|
| 1619 |
|
| 1620 | protected void propagateFallToPassengers(final double fallDistance, final float damageModifier, final DamageSource damageSource) {
|
| 1621 | if (this.isVehicle()) {
|
| 1622 | for (Entity passenger : this.getPassengers()) {
|
| 1623 | passenger.causeFallDamage(fallDistance, damageModifier, damageSource);
|
| 1624 | }
|
| 1625 | }
|
| 1626 | }
|
| 1627 |
|
| 1628 | public boolean isInWater() {
|
| 1629 | return this.wasTouchingWater;
|
| 1630 | }
|
| 1631 |
|
| 1632 | private boolean isInRain() {
|
| 1633 | BlockPos pos = this.blockPosition();
|
| 1634 | return this.level().isRainingAt(pos) || this.level().isRainingAt(BlockPos.containing(pos.getX(), this.getBoundingBox().maxY, pos.getZ()));
|
| 1635 | }
|
| 1636 |
|
| 1637 | public boolean isInWaterOrRain() {
|
| 1638 | return this.isInWater() || this.isInRain();
|
| 1639 | }
|
| 1640 |
|
| 1641 | public boolean isInLiquid() {
|
| 1642 | return this.isInWater() || this.isInLava();
|
| 1643 | }
|
| 1644 |
|
| 1645 | public boolean isInFloatableFluid() {
|
| 1646 | return this.fluidInteraction.isInFluid(FluidTags.ENTITY_FLOATABLE);
|
| 1647 | }
|
| 1648 |
|
| 1649 | public boolean isUnderWater() {
|
| 1650 | return this.wasEyeInWater && this.isInWater();
|
| 1651 | }
|
| 1652 |
|
| 1653 | public boolean isInShallowWater() {
|
| 1654 | return this.isInWater() && !this.isUnderWater();
|
| 1655 | }
|
| 1656 |
|
| 1657 | public boolean isInClouds() {
|
| 1658 | if (this.level.environmentAttributes().getValue(EnvironmentAttributes.CLOUD_COLOR, this.position()).w() == 0.0F) {
|
| 1659 | return false;
|
| 1660 | }
|
| 1661 |
|
| 1662 | float cloudBottom = this.level.environmentAttributes().getValue(EnvironmentAttributes.CLOUD_HEIGHT, this.position());
|
| 1663 | if (this.getY() + this.getBbHeight() < cloudBottom) {
|
| 1664 | return false;
|
| 1665 | }
|
| 1666 |
|
| 1667 | float cloudTop = cloudBottom + 4.0F;
|
| 1668 | return this.getY() <= cloudTop;
|
| 1669 | }
|
| 1670 |
|
| 1671 | public void updateSwimming() {
|
| 1672 | if (this.isSwimming()) {
|
| 1673 | this.setSwimming(this.isSprinting() && this.isInWater() && !this.isPassenger());
|
| 1674 | } else {
|
| 1675 | this.setSwimming(this.isSprinting() && this.isUnderWater() && !this.isPassenger() && this.level().getFluidState(this.blockPosition).is(FluidTags.WATER));
|
| 1676 | }
|
| 1677 | }
|
| 1678 |
|
| 1679 | protected boolean updateFluidInteraction() {
|
| 1680 | boolean inAnyFluid = this.fluidInteraction.update(this, !this.isPushedByFluid());
|
| 1681 | boolean inWater = this.fluidInteraction.isInFluid(FluidTags.WATER);
|
| 1682 | boolean inLava = this.fluidInteraction.isInFluid(FluidTags.LAVA);
|
| 1683 | if (inWater) {
|
| 1684 | this.resetFallDistance();
|
| 1685 | if (!this.wasTouchingWater && !this.firstTick) {
|
| 1686 | this.doWaterSplashEffect();
|
| 1687 | }
|
| 1688 | }
|
| 1689 |
|
| 1690 | this.wasTouchingWater = inWater;
|
| 1691 | if (this.isPushedByFluid()) {
|
| 1692 | if (inWater) {
|
| 1693 | this.fluidInteraction.applyCurrentTo(FluidTags.WATER, this, 0.014);
|
| 1694 | }
|
| 1695 |
|
| 1696 | if (inLava) {
|
| 1697 | double lavaFlowScale = this.level.environmentAttributes().getDimensionValue(EnvironmentAttributes.FAST_LAVA) ? 0.007 : 0.0023333333333333335;
|
| 1698 | this.fluidInteraction.applyCurrentTo(FluidTags.LAVA, this, lavaFlowScale);
|
| 1699 | }
|
| 1700 | }
|
| 1701 |
|
| 1702 | return inAnyFluid;
|
| 1703 | }
|
| 1704 |
|
| 1705 | protected void doWaterSplashEffect() {
|
| 1706 | Entity entity = Objects.requireNonNullElse(this.getControllingPassenger(), this);
|
| 1707 | float volumeModifier = entity == this ? 0.2F : 0.9F;
|
| 1708 | Vec3 movement = entity.getDeltaMovement();
|
| 1709 | float speed = Math.min(1.0F, (float)Math.sqrt(movement.x * movement.x * 0.2F + movement.y * movement.y + movement.z * movement.z * 0.2F) * volumeModifier);
|
| 1710 | if (speed < 0.25F) {
|
| 1711 | this.playSound(this.getSwimSplashSound(), speed, 1.0F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F);
|
| 1712 | } else {
|
| 1713 | this.playSound(this.getSwimHighSpeedSplashSound(), speed, 1.0F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F);
|
| 1714 | }
|
| 1715 |
|
| 1716 | float yt = Mth.floor(this.getY());
|
| 1717 |
|
| 1718 | for (int i = 0; i < 1.0F + this.dimensions.width() * 20.0F; i++) {
|
| 1719 | double xo = (this.random.nextDouble() * 2.0 - 1.0) * this.dimensions.width();
|
| 1720 | double zo = (this.random.nextDouble() * 2.0 - 1.0) * this.dimensions.width();
|
| 1721 | this.level()
|
| 1722 | .addParticle(ParticleTypes.BUBBLE, this.getX() + xo, yt + 1.0F, this.getZ() + zo, movement.x, movement.y - this.random.nextDouble() * 0.2F, movement.z);
|
| 1723 | }
|
| 1724 |
|
| 1725 | for (int i = 0; i < 1.0F + this.dimensions.width() * 20.0F; i++) {
|
| 1726 | double xo = (this.random.nextDouble() * 2.0 - 1.0) * this.dimensions.width();
|
| 1727 | double zo = (this.random.nextDouble() * 2.0 - 1.0) * this.dimensions.width();
|
| 1728 | this.level().addParticle(ParticleTypes.SPLASH, this.getX() + xo, yt + 1.0F, this.getZ() + zo, movement.x, movement.y, movement.z);
|
| 1729 | }
|
| 1730 |
|
| 1731 | this.gameEvent(GameEvent.SPLASH);
|
| 1732 | }
|
| 1733 |
|
| 1734 | @Deprecated
|
| 1735 | protected BlockState getBlockStateOnLegacy() {
|
| 1736 | return this.level().getBlockState(this.getOnPosLegacy());
|
| 1737 | }
|
| 1738 |
|
| 1739 | public BlockState getBlockStateOn() {
|
| 1740 | return this.level().getBlockState(this.getOnPos());
|
| 1741 | }
|
| 1742 |
|
| 1743 | public boolean canSpawnSprintParticle() {
|
| 1744 | return this.isSprinting() && !this.isInWater() && !this.isSpectator() && !this.isCrouching() && !this.isInLava() && this.isAlive();
|
| 1745 | }
|
| 1746 |
|
| 1747 | protected void spawnSprintParticle() {
|
| 1748 | BlockPos pos = this.getOnPosLegacy();
|
| 1749 | BlockState blockState = this.level().getBlockState(pos);
|
| 1750 | if (blockState.getRenderShape() != RenderShape.INVISIBLE) {
|
| 1751 | Vec3 movement = this.getDeltaMovement();
|
| 1752 | BlockPos entityPosition = this.blockPosition();
|
| 1753 | double x = this.getX() + (this.random.nextDouble() - 0.5) * this.dimensions.width();
|
| 1754 | double z = this.getZ() + (this.random.nextDouble() - 0.5) * this.dimensions.width();
|
| 1755 | if (entityPosition.getX() != pos.getX()) {
|
| 1756 | x = Mth.clamp(x, pos.getX(), pos.getX() + 1.0);
|
| 1757 | }
|
| 1758 |
|
| 1759 | if (entityPosition.getZ() != pos.getZ()) {
|
| 1760 | z = Mth.clamp(z, pos.getZ(), pos.getZ() + 1.0);
|
| 1761 | }
|
| 1762 |
|
| 1763 | this.level().addParticle(new BlockParticleOption(ParticleTypes.BLOCK, blockState), x, this.getY() + 0.1, z, movement.x * -4.0, 1.5, movement.z * -4.0);
|
| 1764 | }
|
| 1765 | }
|
| 1766 |
|
| 1767 | public boolean isEyeInFluid(final TagKey<Fluid> type) {
|
| 1768 | return this.fluidInteraction.isEyeInFluid(type);
|
| 1769 | }
|
| 1770 |
|
| 1771 | public boolean isInLava() {
|
| 1772 | return !this.firstTick && this.fluidInteraction.isInFluid(FluidTags.LAVA);
|
| 1773 | }
|
| 1774 |
|
| 1775 | public void moveRelative(final float speed, final Vec3 input) {
|
| 1776 | Vec3 delta = getInputVector(input, speed, this.getYRot());
|
| 1777 | this.setDeltaMovement(this.getDeltaMovement().add(delta));
|
| 1778 | }
|
| 1779 |
|
| 1780 | protected static Vec3 getInputVector(final Vec3 input, final float speed, final float yRot) {
|
| 1781 | double length = input.lengthSqr();
|
| 1782 | if (length < 1.0E-7) {
|
| 1783 | return Vec3.ZERO;
|
| 1784 | }
|
| 1785 |
|
| 1786 | Vec3 movement = (length > 1.0 ? input.normalize() : input).scale(speed);
|
| 1787 | float sin = Mth.sin(yRot * (float) (Math.PI / 180.0));
|
| 1788 | float cos = Mth.cos(yRot * (float) (Math.PI / 180.0));
|
| 1789 | return new Vec3(movement.x * cos - movement.z * sin, movement.y, movement.z * cos + movement.x * sin);
|
| 1790 | }
|
| 1791 |
|
| 1792 | @Deprecated
|
| 1793 | public float getLightLevelDependentMagicValue() {
|
| 1794 | return this.level().hasChunkAt(this.getBlockX(), this.getBlockZ())
|
| 1795 | ? this.level().getLightLevelDependentMagicValue(BlockPos.containing(this.getX(), this.getEyeY(), this.getZ()))
|
| 1796 | : 0.0F;
|
| 1797 | }
|
| 1798 |
|
| 1799 | public void absSnapTo(final double x, final double y, final double z, final float yRot, final float xRot) {
|
| 1800 | this.absSnapTo(x, y, z);
|
| 1801 | this.absSnapRotationTo(yRot, xRot);
|
| 1802 | }
|
| 1803 |
|
| 1804 | public void absSnapRotationTo(final float yRot, final float xRot) {
|
| 1805 | this.setYRot(yRot % 360.0F);
|
| 1806 | this.setXRot(Mth.clamp(xRot, -90.0F, 90.0F) % 360.0F);
|
| 1807 | this.yRotO = this.getYRot();
|
| 1808 | this.xRotO = this.getXRot();
|
| 1809 | }
|
| 1810 |
|
| 1811 | public void absSnapTo(final double x, final double y, final double z) {
|
| 1812 | double cx = Mth.clamp(x, -3.0E7, 3.0E7);
|
| 1813 | double cz = Mth.clamp(z, -3.0E7, 3.0E7);
|
| 1814 | this.xo = cx;
|
| 1815 | this.yo = y;
|
| 1816 | this.zo = cz;
|
| 1817 | this.setPos(cx, y, cz);
|
| 1818 | }
|
| 1819 |
|
| 1820 | public void snapTo(final Vec3 pos) {
|
| 1821 | this.snapTo(pos.x, pos.y, pos.z);
|
| 1822 | }
|
| 1823 |
|
| 1824 | public void snapTo(final double x, final double y, final double z) {
|
| 1825 | this.snapTo(x, y, z, this.getYRot(), this.getXRot());
|
| 1826 | }
|
| 1827 |
|
| 1828 | public void snapTo(final BlockPos spawnPos, final float yRot, final float xRot) {
|
| 1829 | this.snapTo(Vec3.atBottomCenterOf(spawnPos), yRot, xRot);
|
| 1830 | }
|
| 1831 |
|
| 1832 | public void snapTo(final Vec3 spawnPos, final float yRot, final float xRot) {
|
| 1833 | this.snapTo(spawnPos.x, spawnPos.y, spawnPos.z, yRot, xRot);
|
| 1834 | }
|
| 1835 |
|
| 1836 | public void snapTo(final double x, final double y, final double z, final float yRot, final float xRot) {
|
| 1837 | this.setPosRaw(x, y, z);
|
| 1838 | this.setYRot(yRot);
|
| 1839 | this.setXRot(xRot);
|
| 1840 | this.setOldPosAndRot();
|
| 1841 | this.reapplyPosition();
|
| 1842 | }
|
| 1843 |
|
| 1844 | public final void setOldPosAndRot() {
|
| 1845 | this.setOldPos();
|
| 1846 | this.setOldRot();
|
| 1847 | }
|
| 1848 |
|
| 1849 | public final void setOldPosAndRot(final Vec3 position, final float yRot, final float xRot) {
|
| 1850 | this.setOldPos(position);
|
| 1851 | this.setOldRot(yRot, xRot);
|
| 1852 | }
|
| 1853 |
|
| 1854 | protected void setOldPos() {
|
| 1855 | this.setOldPos(this.position);
|
| 1856 | }
|
| 1857 |
|
| 1858 | public void setOldRot() {
|
| 1859 | this.setOldRot(this.getYRot(), this.getXRot());
|
| 1860 | }
|
| 1861 |
|
| 1862 | private void setOldPos(final Vec3 position) {
|
| 1863 | this.xo = this.xOld = position.x;
|
| 1864 | this.yo = this.yOld = position.y;
|
| 1865 | this.zo = this.zOld = position.z;
|
| 1866 | }
|
| 1867 |
|
| 1868 | private void setOldRot(final float yRot, final float xRot) {
|
| 1869 | this.yRotO = yRot;
|
| 1870 | this.xRotO = xRot;
|
| 1871 | }
|
| 1872 |
|
| 1873 | public final Vec3 oldPosition() {
|
| 1874 | return new Vec3(this.xOld, this.yOld, this.zOld);
|
| 1875 | }
|
| 1876 |
|
| 1877 | public float distanceTo(final Entity entity) {
|
| 1878 | float xd = (float)(this.getX() - entity.getX());
|
| 1879 | float yd = (float)(this.getY() - entity.getY());
|
| 1880 | float zd = (float)(this.getZ() - entity.getZ());
|
| 1881 | return Mth.sqrt(xd * xd + yd * yd + zd * zd);
|
| 1882 | }
|
| 1883 |
|
| 1884 | public double distanceToSqr(final double x2, final double y2, final double z2) {
|
| 1885 | double xd = this.getX() - x2;
|
| 1886 | double yd = this.getY() - y2;
|
| 1887 | double zd = this.getZ() - z2;
|
| 1888 | return xd * xd + yd * yd + zd * zd;
|
| 1889 | }
|
| 1890 |
|
| 1891 | public double distanceToSqr(final Entity entity) {
|
| 1892 | return this.distanceToSqr(entity.position());
|
| 1893 | }
|
| 1894 |
|
| 1895 | public double distanceToSqr(final Vec3 pos) {
|
| 1896 | double xd = this.getX() - pos.x;
|
| 1897 | double yd = this.getY() - pos.y;
|
| 1898 | double zd = this.getZ() - pos.z;
|
| 1899 | return xd * xd + yd * yd + zd * zd;
|
| 1900 | }
|
| 1901 |
|
| 1902 | public void playerTouch(final Player player) {
|
| 1903 | }
|
| 1904 |
|
| 1905 | public void push(final Entity entity) {
|
| 1906 | if (!this.isPassengerOfSameVehicle(entity)) {
|
| 1907 | if (!entity.noPhysics && !this.noPhysics) {
|
| 1908 | double xa = entity.getX() - this.getX();
|
| 1909 | double za = entity.getZ() - this.getZ();
|
| 1910 | double dd = Mth.absMax(xa, za);
|
| 1911 | if (dd >= 0.01F) {
|
| 1912 | dd = Math.sqrt(dd);
|
| 1913 | xa /= dd;
|
| 1914 | za /= dd;
|
| 1915 | double pow = 1.0 / dd;
|
| 1916 | if (pow > 1.0) {
|
| 1917 | pow = 1.0;
|
| 1918 | }
|
| 1919 |
|
| 1920 | xa *= pow;
|
| 1921 | za *= pow;
|
| 1922 | xa *= 0.05F;
|
| 1923 | za *= 0.05F;
|
| 1924 | if (!this.isVehicle() && this.isPushable()) {
|
| 1925 | this.push(-xa, 0.0, -za);
|
| 1926 | }
|
| 1927 |
|
| 1928 | if (!entity.isVehicle() && entity.isPushable()) {
|
| 1929 | entity.push(xa, 0.0, za);
|
| 1930 | }
|
| 1931 | }
|
| 1932 | }
|
| 1933 | }
|
| 1934 | }
|
| 1935 |
|
| 1936 | public void push(final Vec3 impulse) {
|
| 1937 | if (impulse.isFinite()) {
|
| 1938 | this.push(impulse.x, impulse.y, impulse.z);
|
| 1939 | }
|
| 1940 | }
|
| 1941 |
|
| 1942 | public void pushFromExplosion(final Vec3 impulse) {
|
| 1943 | this.push(impulse);
|
| 1944 | }
|
| 1945 |
|
| 1946 | public void push(final double xa, final double ya, final double za) {
|
| 1947 | if (Double.isFinite(xa) && Double.isFinite(ya) && Double.isFinite(za)) {
|
| 1948 | this.setDeltaMovement(this.getDeltaMovement().add(xa, ya, za));
|
| 1949 | this.needsSync = true;
|
| 1950 | }
|
| 1951 | }
|
| 1952 |
|
| 1953 | protected void markHurt() {
|
| 1954 | this.syncVelocity = true;
|
| 1955 | }
|
| 1956 |
|
| 1957 | @Deprecated
|
| 1958 | public final void hurt(final DamageSource source, final float damage) {
|
| 1959 | if (this.level instanceof ServerLevel serverLevel) {
|
| 1960 | this.hurtServer(serverLevel, source, damage);
|
| 1961 | }
|
| 1962 | }
|
| 1963 |
|
| 1964 | @Deprecated
|
| 1965 | public final boolean hurtOrSimulate(final DamageSource source, final float damage) {
|
| 1966 | return this.level instanceof ServerLevel serverLevel ? this.hurtServer(serverLevel, source, damage) : this.hurtClient(source);
|
| 1967 | }
|
| 1968 |
|
| 1969 | public abstract boolean hurtServer(ServerLevel level, DamageSource source, float damage);
|
| 1970 |
|
| 1971 | public boolean hurtClient(final DamageSource source) {
|
| 1972 | return false;
|
| 1973 | }
|
| 1974 |
|
| 1975 | public final Vec3 getViewVector(final float a) {
|
| 1976 | return calculateViewVector(this.getViewXRot(a), this.getViewYRot(a));
|
| 1977 | }
|
| 1978 |
|
| 1979 | public Direction getNearestViewDirection() {
|
| 1980 | return Direction.getApproximateNearest(this.getViewVector(1.0F));
|
| 1981 | }
|
| 1982 |
|
| 1983 | public float getViewXRot(final float a) {
|
| 1984 | return this.getXRot(a);
|
| 1985 | }
|
| 1986 |
|
| 1987 | public float getViewYRot(final float a) {
|
| 1988 | return this.getYRot(a);
|
| 1989 | }
|
| 1990 |
|
| 1991 | public float getXRot(final float partialTicks) {
|
| 1992 | return partialTicks == 1.0F ? this.getXRot() : Mth.lerp(partialTicks, this.xRotO, this.getXRot());
|
| 1993 | }
|
| 1994 |
|
| 1995 | public float getYRot(final float partialTicks) {
|
| 1996 | return partialTicks == 1.0F ? this.getYRot() : Mth.rotLerp(partialTicks, this.yRotO, this.getYRot());
|
| 1997 | }
|
| 1998 |
|
| 1999 | public static Vec3 calculateViewVector(final float xRot, final float yRot) {
|
| 2000 | float realXRot = xRot * (float) (Math.PI / 180.0);
|
| 2001 | float realYRot = -yRot * (float) (Math.PI / 180.0);
|
| 2002 | float yCos = Mth.cos(realYRot);
|
| 2003 | float ySin = Mth.sin(realYRot);
|
| 2004 | float xCos = Mth.cos(realXRot);
|
| 2005 | float xSin = Mth.sin(realXRot);
|
| 2006 | return new Vec3(ySin * xCos, -xSin, yCos * xCos);
|
| 2007 | }
|
| 2008 |
|
| 2009 | public static Quaternionf calculateViewQuaternion(final float xRot, final float yRot) {
|
| 2010 | return new Quaternionf().rotationY(-yRot * (float) (Math.PI / 180.0)).rotateX(xRot * (float) (Math.PI / 180.0));
|
| 2011 | }
|
| 2012 |
|
| 2013 | public final Vec3 getUpVector(final float a) {
|
| 2014 | return calculateUpVector(this.getViewXRot(a), this.getViewYRot(a));
|
| 2015 | }
|
| 2016 |
|
| 2017 | protected static Vec3 calculateUpVector(final float xRot, final float yRot) {
|
| 2018 | return calculateViewVector(xRot - 90.0F, yRot);
|
| 2019 | }
|
| 2020 |
|
| 2021 | public final Vec3 getEyePosition() {
|
| 2022 | return new Vec3(this.getX(), this.getEyeY(), this.getZ());
|
| 2023 | }
|
| 2024 |
|
| 2025 | public final Vec3 getEyePosition(final float partialTickTime) {
|
| 2026 | double x = Mth.lerp(partialTickTime, this.xo, this.getX());
|
| 2027 | double y = Mth.lerp(partialTickTime, this.yo, this.getY()) + this.getEyeHeight();
|
| 2028 | double z = Mth.lerp(partialTickTime, this.zo, this.getZ());
|
| 2029 | return new Vec3(x, y, z);
|
| 2030 | }
|
| 2031 |
|
| 2032 | public Vec3 getLightProbePosition(final float partialTickTime) {
|
| 2033 | return this.getEyePosition(partialTickTime);
|
| 2034 | }
|
| 2035 |
|
| 2036 | public final Vec3 getPosition(final float partialTickTime) {
|
| 2037 | double endX = Mth.lerp(partialTickTime, this.xo, this.getX());
|
| 2038 | double endY = Mth.lerp(partialTickTime, this.yo, this.getY());
|
| 2039 | double endZ = Mth.lerp(partialTickTime, this.zo, this.getZ());
|
| 2040 | return new Vec3(endX, endY, endZ);
|
| 2041 | }
|
| 2042 |
|
| 2043 | public HitResult pick(final double range, final float a, final boolean withLiquids) {
|
| 2044 | Vec3 from = this.getEyePosition(a);
|
| 2045 | Vec3 viewVector = this.getViewVector(a);
|
| 2046 | Vec3 to = from.add(viewVector.x * range, viewVector.y * range, viewVector.z * range);
|
| 2047 | return this.level().clip(new ClipContext(from, to, ClipContext.Block.OUTLINE, withLiquids ? ClipContext.Fluid.ANY : ClipContext.Fluid.NONE, this));
|
| 2048 | }
|
| 2049 |
|
| 2050 | public boolean canBeHitByProjectile() {
|
| 2051 | return this.isAlive() && this.isPickable();
|
| 2052 | }
|
| 2053 |
|
| 2054 | public boolean isPickable() {
|
| 2055 | return false;
|
| 2056 | }
|
| 2057 |
|
| 2058 | public boolean canBePickedFromInside() {
|
| 2059 | return true;
|
| 2060 | }
|
| 2061 |
|
| 2062 | public boolean isPushable() {
|
| 2063 | return false;
|
| 2064 | }
|
| 2065 |
|
| 2066 | public void awardKillScore(final Entity victim, final DamageSource killingBlow) {
|
| 2067 | if (victim instanceof ServerPlayer serverPlayer) {
|
| 2068 | CriteriaTriggers.ENTITY_KILLED_PLAYER.trigger(serverPlayer, this, killingBlow);
|
| 2069 | }
|
| 2070 | }
|
| 2071 |
|
| 2072 | public boolean shouldRender(final double camX, final double camY, final double camZ) {
|
| 2073 | double xd = this.getX() - camX;
|
| 2074 | double yd = this.getY() - camY;
|
| 2075 | double zd = this.getZ() - camZ;
|
| 2076 | double distance = xd * xd + yd * yd + zd * zd;
|
| 2077 | return this.shouldRenderAtSqrDistance(distance);
|
| 2078 | }
|
| 2079 |
|
| 2080 | public boolean shouldRenderAtSqrDistance(final double distance) {
|
| 2081 | double size = this.getBoundingBox().getSize();
|
| 2082 | if (Double.isNaN(size)) {
|
| 2083 | size = 1.0;
|
| 2084 | }
|
| 2085 |
|
| 2086 | size *= 64.0 * viewScale;
|
| 2087 | return distance < size * size;
|
| 2088 | }
|
| 2089 |
|
| 2090 | public boolean saveAsPassenger(final ValueOutput output) {
|
| 2091 | if (this.removalReason != null && !this.removalReason.shouldSave()) {
|
| 2092 | return false;
|
| 2093 | }
|
| 2094 |
|
| 2095 | String id = this.getEncodeId();
|
| 2096 | if (id == null) {
|
| 2097 | return false;
|
| 2098 | }
|
| 2099 |
|
| 2100 | output.putString("id", id);
|
| 2101 | this.saveWithoutId(output);
|
| 2102 | return true;
|
| 2103 | }
|
| 2104 |
|
| 2105 | public boolean save(final ValueOutput output) {
|
| 2106 | return this.isPassenger() ? false : this.saveAsPassenger(output);
|
| 2107 | }
|
| 2108 |
|
| 2109 | public void saveWithoutId(final ValueOutput output) {
|
| 2110 | try {
|
| 2111 | if (this.vehicle != null) {
|
| 2112 | output.store("Pos", Vec3.CODEC, new Vec3(this.vehicle.getX(), this.getY(), this.vehicle.getZ()));
|
| 2113 | } else {
|
| 2114 | output.store("Pos", Vec3.CODEC, this.position());
|
| 2115 | }
|
| 2116 |
|
| 2117 | output.store("Motion", Vec3.CODEC, this.getDeltaMovement());
|
| 2118 | output.store("Rotation", Vec2.CODEC, new Vec2(this.getYRot(), this.getXRot()));
|
| 2119 | output.putDouble("fall_distance", this.fallDistance);
|
| 2120 | output.putShort("Fire", (short)this.remainingFireTicks);
|
| 2121 | output.putShort("Air", (short)this.getAirSupply());
|
| 2122 | output.putBoolean("OnGround", this.onGround());
|
| 2123 | output.putBoolean("Invulnerable", this.permanentlyInvulnerable);
|
| 2124 | output.putInt("PortalCooldown", this.portalCooldown);
|
| 2125 | if (this.invulnerableTime > 0) {
|
| 2126 | output.putInt("invulnerable_time", this.invulnerableTime);
|
| 2127 | }
|
| 2128 |
|
| 2129 | output.store("UUID", UUIDUtil.CODEC, this.getUUID());
|
| 2130 | output.storeNullable("CustomName", ComponentSerialization.CODEC, this.getCustomName());
|
| 2131 | if (this.isCustomNameVisible()) {
|
| 2132 | output.putBoolean("CustomNameVisible", this.isCustomNameVisible());
|
| 2133 | }
|
| 2134 |
|
| 2135 | if (this.isSilent()) {
|
| 2136 | output.putBoolean("Silent", this.isSilent());
|
| 2137 | }
|
| 2138 |
|
| 2139 | if (this.isNoGravity()) {
|
| 2140 | output.putBoolean("NoGravity", this.isNoGravity());
|
| 2141 | }
|
| 2142 |
|
| 2143 | if (this.hasGlowingTag) {
|
| 2144 | output.putBoolean("Glowing", true);
|
| 2145 | }
|
| 2146 |
|
| 2147 | int ticksFrozen = this.getTicksFrozen();
|
| 2148 | if (ticksFrozen > 0) {
|
| 2149 | output.putInt("TicksFrozen", this.getTicksFrozen());
|
| 2150 | }
|
| 2151 |
|
| 2152 | if (this.hasVisualFire) {
|
| 2153 | output.putBoolean("HasVisualFire", this.hasVisualFire);
|
| 2154 | }
|
| 2155 |
|
| 2156 | if (!this.tags.isEmpty()) {
|
| 2157 | output.store("Tags", TAG_LIST_CODEC, List.copyOf(this.tags));
|
| 2158 | }
|
| 2159 |
|
| 2160 | if (!this.customData.isEmpty()) {
|
| 2161 | output.store("data", CustomData.CODEC, this.customData);
|
| 2162 | }
|
| 2163 |
|
| 2164 | this.addAdditionalSaveData(output);
|
| 2165 | if (this.isVehicle()) {
|
| 2166 | ValueOutput.ValueOutputList passengersList = output.childrenList("Passengers");
|
| 2167 |
|
| 2168 | for (Entity passenger : this.getPassengers()) {
|
| 2169 | ValueOutput passengerOutput = passengersList.addChild();
|
| 2170 | if (!passenger.saveAsPassenger(passengerOutput)) {
|
| 2171 | passengersList.discardLast();
|
| 2172 | }
|
| 2173 | }
|
| 2174 |
|
| 2175 | if (passengersList.isEmpty()) {
|
| 2176 | output.discard("Passengers");
|
| 2177 | }
|
| 2178 | }
|
| 2179 | } catch (Throwable t) {
|
| 2180 | CrashReport report = CrashReport.forThrowable(t, "Saving entity NBT");
|
| 2181 | CrashReportCategory category = report.addCategory("Entity being saved");
|
| 2182 | this.fillCrashReportCategory(category);
|
| 2183 | throw new ReportedException(report);
|
| 2184 | }
|
| 2185 | }
|
| 2186 |
|
| 2187 | public void load(final ValueInput input) {
|
| 2188 | try {
|
| 2189 | Vec3 pos = input.read("Pos", Vec3.CODEC).orElse(Vec3.ZERO);
|
| 2190 | Vec3 motion = input.read("Motion", Vec3.CODEC).orElse(Vec3.ZERO);
|
| 2191 | Vec2 rotation = input.read("Rotation", Vec2.CODEC).orElse(Vec2.ZERO);
|
| 2192 | this.setDeltaMovement(Math.abs(motion.x) > 10.0 ? 0.0 : motion.x, Math.abs(motion.y) > 10.0 ? 0.0 : motion.y, Math.abs(motion.z) > 10.0 ? 0.0 : motion.z);
|
| 2193 | this.needsSync = true;
|
| 2194 | double maxHorizontalPosition = 3.0000512E7;
|
| 2195 | this.setPosRaw(Mth.clamp(pos.x, -3.0000512E7, 3.0000512E7), Mth.clamp(pos.y, -2.0E7, 2.0E7), Mth.clamp(pos.z, -3.0000512E7, 3.0000512E7));
|
| 2196 | this.setYRot(rotation.x);
|
| 2197 | this.setXRot(rotation.y);
|
| 2198 | this.setOldPosAndRot();
|
| 2199 | this.setYHeadRot(this.getYRot());
|
| 2200 | this.setYBodyRot(this.getYRot());
|
| 2201 | this.fallDistance = input.getDoubleOr("fall_distance", 0.0);
|
| 2202 | this.remainingFireTicks = input.getShortOr("Fire", (short)0);
|
| 2203 | this.setAirSupply(input.getIntOr("Air", this.getMaxAirSupply()));
|
| 2204 | this.onGround = input.getBooleanOr("OnGround", false);
|
| 2205 | this.permanentlyInvulnerable = input.getBooleanOr("Invulnerable", false);
|
| 2206 | this.invulnerableTime = input.getIntOr("invulnerable_time", 0);
|
| 2207 | this.portalCooldown = input.getIntOr("PortalCooldown", 0);
|
| 2208 | input.read("UUID", UUIDUtil.CODEC).ifPresent(id -> {
|
| 2209 | this.uuid = id;
|
| 2210 | this.stringUUID = this.uuid.toString();
|
| 2211 | });
|
| 2212 | if (!Double.isFinite(this.getX()) || !Double.isFinite(this.getY()) || !Double.isFinite(this.getZ())) {
|
| 2213 | throw new IllegalStateException("Entity has invalid position");
|
| 2214 | }
|
| 2215 |
|
| 2216 | if (Double.isFinite(this.getYRot()) && Double.isFinite(this.getXRot())) {
|
| 2217 | this.reapplyPosition();
|
| 2218 | this.setRot(this.getYRot(), this.getXRot());
|
| 2219 | this.setCustomName(input.read("CustomName", ComponentSerialization.CODEC).orElse(null));
|
| 2220 | this.setCustomNameVisible(input.getBooleanOr("CustomNameVisible", false));
|
| 2221 | this.setSilent(input.getBooleanOr("Silent", false));
|
| 2222 | this.setNoGravity(input.getBooleanOr("NoGravity", false));
|
| 2223 | this.setGlowingTag(input.getBooleanOr("Glowing", false));
|
| 2224 | this.setTicksFrozen(input.getIntOr("TicksFrozen", 0));
|
| 2225 | this.hasVisualFire = input.getBooleanOr("HasVisualFire", false);
|
| 2226 | this.customData = input.read("data", CustomData.CODEC).orElse(CustomData.EMPTY);
|
| 2227 | this.tags.clear();
|
| 2228 | input.read("Tags", TAG_LIST_CODEC).ifPresent(this.tags::addAll);
|
| 2229 | input.getString("Team").ifPresent(teamName -> {
|
| 2230 | Scoreboard scoreboard = this.level().getScoreboard();
|
| 2231 | PlayerTeam team = scoreboard.getPlayerTeam(teamName);
|
| 2232 | boolean success = team != null && scoreboard.addPlayerToTeam(this.getStringUUID(), team);
|
| 2233 | if (!success) {
|
| 2234 | LOGGER.warn("Unable to add entity to team \"{}\" (that team probably doesn't exist)", teamName);
|
| 2235 | }
|
| 2236 | });
|
| 2237 | this.readAdditionalSaveData(input);
|
| 2238 | if (this.repositionEntityAfterLoad()) {
|
| 2239 | this.reapplyPosition();
|
| 2240 | }
|
| 2241 | } else {
|
| 2242 | throw new IllegalStateException("Entity has invalid rotation");
|
| 2243 | }
|
| 2244 | } catch (Throwable t) {
|
| 2245 | CrashReport report = CrashReport.forThrowable(t, "Loading entity NBT");
|
| 2246 | CrashReportCategory category = report.addCategory("Entity being loaded");
|
| 2247 | this.fillCrashReportCategory(category);
|
| 2248 | throw new ReportedException(report);
|
| 2249 | }
|
| 2250 | }
|
| 2251 |
|
| 2252 | public void postDataManipulated() {
|
| 2253 | }
|
| 2254 |
|
| 2255 | protected boolean repositionEntityAfterLoad() {
|
| 2256 | return true;
|
| 2257 | }
|
| 2258 |
|
| 2259 | protected final @Nullable String getEncodeId() {
|
| 2260 | if (!this.getType().canSerialize()) {
|
| 2261 | return null;
|
| 2262 | }
|
| 2263 |
|
| 2264 | ResourceKey<EntityType<?>> typeId = this.typeHolder().unwrapKey().orElseThrow(() -> new IllegalStateException("Unregistered entity"));
|
| 2265 | return typeId.identifier().toString();
|
| 2266 | }
|
| 2267 |
|
| 2268 | protected abstract void readAdditionalSaveData(ValueInput input);
|
| 2269 |
|
| 2270 | protected abstract void addAdditionalSaveData(ValueOutput output);
|
| 2271 |
|
| 2272 | public @Nullable ItemEntity spawnAtLocation(final ServerLevel level, final ItemLike resource) {
|
| 2273 | return this.spawnAtLocation(level, new ItemStack(resource), 0.0F);
|
| 2274 | }
|
| 2275 |
|
| 2276 | public @Nullable ItemEntity spawnAtLocation(final ServerLevel level, final ItemStack itemStack) {
|
| 2277 | return this.spawnAtLocation(level, itemStack, 0.0F);
|
| 2278 | }
|
| 2279 |
|
| 2280 | public @Nullable ItemEntity spawnAtLocation(final ServerLevel level, final ItemStack itemStack, final Vec3 offset) {
|
| 2281 | if (itemStack.isEmpty()) {
|
| 2282 | return null;
|
| 2283 | }
|
| 2284 |
|
| 2285 | ItemEntity entity = new ItemEntity(level, this.getX() + offset.x, this.getY() + offset.y, this.getZ() + offset.z, itemStack);
|
| 2286 | entity.setDefaultPickUpDelay();
|
| 2287 | level.addFreshEntity(entity);
|
| 2288 | return entity;
|
| 2289 | }
|
| 2290 |
|
| 2291 | public @Nullable ItemEntity spawnAtLocation(final ServerLevel level, final ItemStack itemStack, final float offset) {
|
| 2292 | return this.spawnAtLocation(level, itemStack, new Vec3(0.0, offset, 0.0));
|
| 2293 | }
|
| 2294 |
|
| 2295 | public boolean isAlive() {
|
| 2296 | return !this.isRemoved();
|
| 2297 | }
|
| 2298 |
|
| 2299 | public boolean isInWall() {
|
| 2300 | if (this.noPhysics) {
|
| 2301 | return false;
|
| 2302 | }
|
| 2303 |
|
| 2304 | float checkWidth = this.dimensions.width() * 0.8F;
|
| 2305 | AABB eyeBb = AABB.ofSize(this.getEyePosition(), checkWidth, 1.0E-6, checkWidth);
|
| 2306 | return BlockPos.betweenClosedStream(eyeBb)
|
| 2307 | .anyMatch(
|
| 2308 | pos -> {
|
| 2309 | BlockState state = this.level().getBlockState(pos);
|
| 2310 | return !state.isAir()
|
| 2311 | && state.isSuffocating(this.level(), pos)
|
| 2312 | && Shapes.joinIsNotEmpty(state.getCollisionShape(this.level(), pos).move(pos), Shapes.create(eyeBb), BooleanOp.AND);
|
| 2313 | }
|
| 2314 | );
|
| 2315 | }
|
| 2316 |
|
| 2317 | public InteractionResult interact(final Player player, final InteractionHand hand, final Vec3 location) {
|
| 2318 | if (!this.level().isClientSide()
|
| 2319 | && player.isSecondaryUseActive()
|
| 2320 | && this instanceof Leashable leashable
|
| 2321 | && leashable.canBeLeashed()
|
| 2322 | && this.isAlive()
|
| 2323 | && !(this instanceof LivingEntity le && le.isBaby())) {
|
| 2324 | List<Leashable> mobsToLeash = Leashable.leashableInArea(this, l -> l.getLeashHolder() == player);
|
| 2325 | if (!mobsToLeash.isEmpty()) {
|
| 2326 | boolean anyLeashed = false;
|
| 2327 |
|
| 2328 | for (Leashable mob : mobsToLeash) {
|
| 2329 | if (mob.canHaveALeashAttachedTo(this)) {
|
| 2330 | mob.setLeashedTo(this, true);
|
| 2331 | anyLeashed = true;
|
| 2332 | }
|
| 2333 | }
|
| 2334 |
|
| 2335 | if (anyLeashed) {
|
| 2336 | this.level().gameEvent(GameEvent.ENTITY_ACTION, this.blockPosition(), GameEvent.Context.of(player));
|
| 2337 | this.playSound(SoundEvents.LEAD_TIED);
|
| 2338 | return InteractionResult.SUCCESS_SERVER.withoutItem();
|
| 2339 | }
|
| 2340 | }
|
| 2341 | }
|
| 2342 |
|
| 2343 | ItemStack heldItem = player.getItemInHand(hand);
|
| 2344 | if (heldItem.is(Items.SHEARS) && this.shearOffAllLeashConnections(player)) {
|
| 2345 | heldItem.hurtAndBreak(1, player, hand);
|
| 2346 | return InteractionResult.SUCCESS;
|
| 2347 | } else if (this instanceof Mob target
|
| 2348 | && heldItem.is(Items.SHEARS)
|
| 2349 | && target.canShearEquipment(player)
|
| 2350 | && !player.isSecondaryUseActive()
|
| 2351 | && target.attemptToShearEquipment(player, hand, heldItem)) {
|
| 2352 | return InteractionResult.SUCCESS;
|
| 2353 | } else {
|
| 2354 | if (this.isAlive() && this instanceof Leashable leashable) {
|
| 2355 | if (leashable.getLeashHolder() == player) {
|
| 2356 | if (!this.level().isClientSide()) {
|
| 2357 | if (player.hasInfiniteMaterials()) {
|
| 2358 | leashable.removeLeash();
|
| 2359 | } else {
|
| 2360 | leashable.dropLeash();
|
| 2361 | }
|
| 2362 |
|
| 2363 | this.gameEvent(GameEvent.ENTITY_INTERACT, player);
|
| 2364 | this.playSound(SoundEvents.LEAD_UNTIED);
|
| 2365 | }
|
| 2366 |
|
| 2367 | return InteractionResult.SUCCESS.withoutItem();
|
| 2368 | }
|
| 2369 |
|
| 2370 | ItemStack itemStack = player.getItemInHand(hand);
|
| 2371 | if (itemStack.is(Items.LEAD) && !(leashable.getLeashHolder() instanceof Player)) {
|
| 2372 | if (this.level().isClientSide()) {
|
| 2373 | return InteractionResult.CONSUME;
|
| 2374 | }
|
| 2375 |
|
| 2376 | if (leashable.canHaveALeashAttachedTo(player)) {
|
| 2377 | if (leashable.isLeashed()) {
|
| 2378 | leashable.dropLeash();
|
| 2379 | }
|
| 2380 |
|
| 2381 | leashable.setLeashedTo(player, true);
|
| 2382 | this.playSound(SoundEvents.LEAD_TIED);
|
| 2383 | itemStack.shrink(1);
|
| 2384 | return InteractionResult.SUCCESS_SERVER;
|
| 2385 | }
|
| 2386 | }
|
| 2387 | }
|
| 2388 |
|
| 2389 | return InteractionResult.PASS;
|
| 2390 | }
|
| 2391 | }
|
| 2392 |
|
| 2393 | public boolean shearOffAllLeashConnections(final @Nullable Player player) {
|
| 2394 | boolean dropped = this.dropAllLeashConnections(player);
|
| 2395 | if (dropped && this.level() instanceof ServerLevel serverLevel) {
|
| 2396 | serverLevel.playSound(null, this.blockPosition(), SoundEvents.SHEARS_SNIP, player != null ? player.getSoundSource() : this.getSoundSource());
|
| 2397 | }
|
| 2398 |
|
| 2399 | return dropped;
|
| 2400 | }
|
| 2401 |
|
| 2402 | public boolean dropAllLeashConnections(final @Nullable Player player) {
|
| 2403 | List<Leashable> leashables = Leashable.leashableLeashedTo(this);
|
| 2404 | boolean dropped = !leashables.isEmpty();
|
| 2405 | if (this instanceof Leashable leashableThis && leashableThis.isLeashed()) {
|
| 2406 | leashableThis.dropLeash();
|
| 2407 | dropped = true;
|
| 2408 | }
|
| 2409 |
|
| 2410 | for (Leashable leashable : leashables) {
|
| 2411 | leashable.dropLeash();
|
| 2412 | }
|
| 2413 |
|
| 2414 | if (dropped) {
|
| 2415 | this.gameEvent(GameEvent.SHEAR, player);
|
| 2416 | return true;
|
| 2417 | } else {
|
| 2418 | return false;
|
| 2419 | }
|
| 2420 | }
|
| 2421 |
|
| 2422 | public boolean canCollideWith(final Entity entity) {
|
| 2423 | return entity.canBeCollidedWith(this) && !this.isPassengerOfSameVehicle(entity);
|
| 2424 | }
|
| 2425 |
|
| 2426 | public boolean canBeCollidedWith(final @Nullable Entity other) {
|
| 2427 | return false;
|
| 2428 | }
|
| 2429 |
|
| 2430 | public void rideTick() {
|
| 2431 | this.setDeltaMovement(Vec3.ZERO);
|
| 2432 | this.tick();
|
| 2433 | if (this.isPassenger()) {
|
| 2434 | this.getVehicle().positionRider(this);
|
| 2435 | }
|
| 2436 | }
|
| 2437 |
|
| 2438 | public final void positionRider(final Entity passenger) {
|
| 2439 | if (this.hasPassenger(passenger)) {
|
| 2440 | this.positionRider(passenger, Entity::setPos);
|
| 2441 | }
|
| 2442 | }
|
| 2443 |
|
| 2444 | protected void positionRider(final Entity passenger, final Entity.MoveFunction moveFunction) {
|
| 2445 | Vec3 position = this.getPassengerRidingPosition(passenger);
|
| 2446 | Vec3 offset = passenger.getVehicleAttachmentPoint(this);
|
| 2447 | moveFunction.accept(passenger, position.x - offset.x, position.y - offset.y, position.z - offset.z);
|
| 2448 | }
|
| 2449 |
|
| 2450 | public void onPassengerTurned(final Entity passenger) {
|
| 2451 | }
|
| 2452 |
|
| 2453 | public Vec3 getVehicleAttachmentPoint(final Entity vehicle) {
|
| 2454 | return this.getAttachments().get(EntityAttachment.VEHICLE, 0, this.yRot);
|
| 2455 | }
|
| 2456 |
|
| 2457 | public Vec3 getPassengerRidingPosition(final Entity passenger) {
|
| 2458 | return this.position().add(this.getPassengerAttachmentPoint(passenger, this.dimensions, 1.0F));
|
| 2459 | }
|
| 2460 |
|
| 2461 | protected Vec3 getPassengerAttachmentPoint(final Entity passenger, final EntityDimensions dimensions, final float scale) {
|
| 2462 | return getDefaultPassengerAttachmentPoint(this, passenger, dimensions.attachments());
|
| 2463 | }
|
| 2464 |
|
| 2465 | protected static Vec3 getDefaultPassengerAttachmentPoint(final Entity vehicle, final Entity passenger, final EntityAttachments attachments) {
|
| 2466 | int passengerIndex = vehicle.getPassengers().indexOf(passenger);
|
| 2467 | return attachments.getClamped(EntityAttachment.PASSENGER, passengerIndex, vehicle.yRot);
|
| 2468 | }
|
| 2469 |
|
| 2470 | public final boolean startRiding(final Entity entity) {
|
| 2471 | return this.startRiding(entity, false, true);
|
| 2472 | }
|
| 2473 |
|
| 2474 | public boolean showVehicleHealth() {
|
| 2475 | return this instanceof LivingEntity;
|
| 2476 | }
|
| 2477 |
|
| 2478 | public boolean startRiding(final Entity entityToRide, final boolean force, final boolean sendEventAndTriggers) {
|
| 2479 | if (entityToRide == this.vehicle) {
|
| 2480 | return false;
|
| 2481 | }
|
| 2482 |
|
| 2483 | if (!entityToRide.couldAcceptPassenger()) {
|
| 2484 | return false;
|
| 2485 | }
|
| 2486 |
|
| 2487 | if (!this.level().isClientSide() && !entityToRide.type.canSerialize()) {
|
| 2488 | return false;
|
| 2489 | }
|
| 2490 |
|
| 2491 | for (Entity vehicleEntity = entityToRide; vehicleEntity.vehicle != null; vehicleEntity = vehicleEntity.vehicle) {
|
| 2492 | if (vehicleEntity.vehicle == this) {
|
| 2493 | return false;
|
| 2494 | }
|
| 2495 | }
|
| 2496 |
|
| 2497 | if (force || this.canRide(entityToRide) && entityToRide.canAddPassenger(this)) {
|
| 2498 | if (this.isPassenger()) {
|
| 2499 | this.stopRiding();
|
| 2500 | }
|
| 2501 |
|
| 2502 | this.setPose(Pose.STANDING);
|
| 2503 | this.vehicle = entityToRide;
|
| 2504 | this.vehicle.addPassenger(this);
|
| 2505 | if (sendEventAndTriggers) {
|
| 2506 | this.level().gameEvent(this, GameEvent.ENTITY_MOUNT, this.vehicle.position);
|
| 2507 | entityToRide.getIndirectPassengersStream()
|
| 2508 | .filter(e -> e instanceof ServerPlayer)
|
| 2509 | .forEach(player -> CriteriaTriggers.START_RIDING_TRIGGER.trigger((ServerPlayer)player));
|
| 2510 | }
|
| 2511 |
|
| 2512 | return true;
|
| 2513 | } else {
|
| 2514 | return false;
|
| 2515 | }
|
| 2516 | }
|
| 2517 |
|
| 2518 | protected boolean canRide(final Entity vehicle) {
|
| 2519 | return !this.isShiftKeyDown() && this.boardingCooldown <= 0;
|
| 2520 | }
|
| 2521 |
|
| 2522 | public void ejectPassengers() {
|
| 2523 | for (int i = this.passengers.size() - 1; i >= 0; i--) {
|
| 2524 | this.passengers.get(i).stopRiding();
|
| 2525 | }
|
| 2526 | }
|
| 2527 |
|
| 2528 | public final boolean doTeamsAllowDamage(final Entity other) {
|
| 2529 | Team team = this.getTeam();
|
| 2530 | Team otherTeam = other.getTeam();
|
| 2531 | if (team == null) {
|
| 2532 | return true;
|
| 2533 | } else {
|
| 2534 | return !team.isAlliedTo(otherTeam) ? true : team.isAllowFriendlyFire();
|
| 2535 | }
|
| 2536 | }
|
| 2537 |
|
| 2538 | public void removeVehicle() {
|
| 2539 | if (this.vehicle != null) {
|
| 2540 | Entity oldVehicle = this.vehicle;
|
| 2541 | this.vehicle = null;
|
| 2542 | oldVehicle.removePassenger(this);
|
| 2543 | Entity.RemovalReason removalReason = this.getRemovalReason();
|
| 2544 | if (removalReason == null || removalReason.shouldDestroy()) {
|
| 2545 | this.level().gameEvent(this, GameEvent.ENTITY_DISMOUNT, oldVehicle.position);
|
| 2546 | }
|
| 2547 | }
|
| 2548 | }
|
| 2549 |
|
| 2550 | public void stopRiding() {
|
| 2551 | this.removeVehicle();
|
| 2552 | }
|
| 2553 |
|
| 2554 | protected void addPassenger(final Entity passenger) {
|
| 2555 | if (passenger.getVehicle() != this) {
|
| 2556 | throw new IllegalStateException("Use x.startRiding(y), not y.addPassenger(x)");
|
| 2557 | }
|
| 2558 |
|
| 2559 | if (this.passengers.isEmpty()) {
|
| 2560 | this.passengers = ImmutableList.of(passenger);
|
| 2561 | } else {
|
| 2562 | List<Entity> newPassengers = Lists.newArrayList(this.passengers);
|
| 2563 | if (!this.level().isClientSide() && passenger instanceof Player && !(this.getFirstPassenger() instanceof Player)) {
|
| 2564 | newPassengers.add(0, passenger);
|
| 2565 | } else {
|
| 2566 | newPassengers.add(passenger);
|
| 2567 | }
|
| 2568 |
|
| 2569 | this.passengers = ImmutableList.copyOf(newPassengers);
|
| 2570 | }
|
| 2571 | }
|
| 2572 |
|
| 2573 | protected void removePassenger(final Entity passenger) {
|
| 2574 | if (passenger.getVehicle() == this) {
|
| 2575 | throw new IllegalStateException("Use x.stopRiding(y), not y.removePassenger(x)");
|
| 2576 | }
|
| 2577 |
|
| 2578 | if (this.passengers.size() == 1 && this.passengers.get(0) == passenger) {
|
| 2579 | this.passengers = ImmutableList.of();
|
| 2580 | } else {
|
| 2581 | this.passengers = this.passengers.stream().filter(p -> p != passenger).collect(ImmutableList.toImmutableList());
|
| 2582 | }
|
| 2583 |
|
| 2584 | passenger.boardingCooldown = 60;
|
| 2585 | }
|
| 2586 |
|
| 2587 | protected boolean canAddPassenger(final Entity passenger) {
|
| 2588 | return this.passengers.isEmpty();
|
| 2589 | }
|
| 2590 |
|
| 2591 | protected boolean couldAcceptPassenger() {
|
| 2592 | return true;
|
| 2593 | }
|
| 2594 |
|
| 2595 | public final boolean isInterpolating() {
|
| 2596 | return this.interpolationHandler.hasActiveInterpolation();
|
| 2597 | }
|
| 2598 |
|
| 2599 | public final void moveOrInterpolateTo(final PositionPath position, final float yRot, final float xRot) {
|
| 2600 | this.moveOrInterpolateTo(position, yRot, xRot, true);
|
| 2601 | }
|
| 2602 |
|
| 2603 | public final void moveOrInterpolateTo(final Vec3 position, final float yRot, final float xRot) {
|
| 2604 | this.moveOrInterpolateTo(PositionPath.of(position), yRot, xRot, true);
|
| 2605 | }
|
| 2606 |
|
| 2607 | public final void moveOrInterpolateTo(final float yRot, final float xRot) {
|
| 2608 | this.moveOrInterpolateTo(null, yRot, xRot, true);
|
| 2609 | }
|
| 2610 |
|
| 2611 | public final void moveOrInterpolateTo(final PositionPath position) {
|
| 2612 | this.moveOrInterpolateTo(position, 0.0F, 0.0F, false);
|
| 2613 | }
|
| 2614 |
|
| 2615 | public final void moveOrInterpolateTo(final @Nullable PositionPath position, final float yRot, final float xRot, final boolean hasRotation) {
|
| 2616 | if (!this.interpolationHandler.interpolateTo(position, yRot, xRot, hasRotation)) {
|
| 2617 | if (position != null) {
|
| 2618 | this.setPos(position.endPosition());
|
| 2619 | }
|
| 2620 |
|
| 2621 | if (hasRotation) {
|
| 2622 | this.setRot(yRot, xRot);
|
| 2623 | }
|
| 2624 | }
|
| 2625 | }
|
| 2626 |
|
| 2627 | public void onInterpolationStart(final InterpolationHandler interpolation) {
|
| 2628 | }
|
| 2629 |
|
| 2630 | protected InterpolationHandler createInterpolationHandler() {
|
| 2631 | return InterpolationHandler.NO_OP;
|
| 2632 | }
|
| 2633 |
|
| 2634 | public final InterpolationHandler getInterpolation() {
|
| 2635 | return this.interpolationHandler;
|
| 2636 | }
|
| 2637 |
|
| 2638 | public void lerpHeadTo(final float yRot, final int steps) {
|
| 2639 | this.setYHeadRot(yRot);
|
| 2640 | }
|
| 2641 |
|
| 2642 | public float getPickRadius() {
|
| 2643 | return 0.0F;
|
| 2644 | }
|
| 2645 |
|
| 2646 | public Vec3 getLookAngle() {
|
| 2647 | return calculateViewVector(this.getXRot(), this.getYRot());
|
| 2648 | }
|
| 2649 |
|
| 2650 | public Quaternionf getLookQuaternion() {
|
| 2651 | return calculateViewQuaternion(this.getXRot(), this.getYRot());
|
| 2652 | }
|
| 2653 |
|
| 2654 | public Vec3 getHeadLookAngle() {
|
| 2655 | return calculateViewVector(this.getXRot(), this.getYHeadRot());
|
| 2656 | }
|
| 2657 |
|
| 2658 | public Vec3 getHandHoldingItemAngle(final Item item) {
|
| 2659 | if (!(this instanceof Player player)) {
|
| 2660 | return Vec3.ZERO;
|
| 2661 | } else {
|
| 2662 | boolean itemOnlyInOffhand = player.getOffhandItem().is(item) && !player.getMainHandItem().is(item);
|
| 2663 | HumanoidArm itemArm = itemOnlyInOffhand ? player.getMainArm().getOpposite() : player.getMainArm();
|
| 2664 | return calculateViewVector(0.0F, this.getYRot() + (itemArm == HumanoidArm.RIGHT ? 80 : -80)).scale(0.5);
|
| 2665 | }
|
| 2666 | }
|
| 2667 |
|
| 2668 | public Vec2 getRotationVector() {
|
| 2669 | return new Vec2(this.getXRot(), this.getYRot());
|
| 2670 | }
|
| 2671 |
|
| 2672 | public Vec3 getForward() {
|
| 2673 | return Vec3.directionFromRotation(this.getRotationVector());
|
| 2674 | }
|
| 2675 |
|
| 2676 | public void setAsInsidePortal(final Portal portal, final BlockPos pos) {
|
| 2677 | if (this.isOnPortalCooldown()) {
|
| 2678 | this.setPortalCooldown();
|
| 2679 | } else {
|
| 2680 | if (this.portalProcess == null || !this.portalProcess.isSamePortal(portal)) {
|
| 2681 | this.portalProcess = new PortalProcessor(portal, pos.immutable());
|
| 2682 | } else if (!this.portalProcess.isInsidePortalThisTick()) {
|
| 2683 | this.portalProcess.updateEntryPosition(pos.immutable());
|
| 2684 | this.portalProcess.setAsInsidePortalThisTick(true);
|
| 2685 | }
|
| 2686 | }
|
| 2687 | }
|
| 2688 |
|
| 2689 | protected void handlePortal() {
|
| 2690 | if (this.level() instanceof ServerLevel level) {
|
| 2691 | this.processPortalCooldown();
|
| 2692 | if (this.portalProcess != null) {
|
| 2693 | if (this.portalProcess.processPortalTeleportation(level, this, this.canUsePortal(false))) {
|
| 2694 | ProfilerFiller profiler = Profiler.get();
|
| 2695 | profiler.push("portal");
|
| 2696 | this.setPortalCooldown();
|
| 2697 | TeleportTransition teleportTransition = this.portalProcess.getPortalDestination(level, this);
|
| 2698 | if (teleportTransition != null) {
|
| 2699 | this.teleportToPortalDestination(level, teleportTransition);
|
| 2700 | }
|
| 2701 |
|
| 2702 | profiler.pop();
|
| 2703 | } else if (this.portalProcess.hasExpired()) {
|
| 2704 | this.portalProcess = null;
|
| 2705 | }
|
| 2706 | }
|
| 2707 | }
|
| 2708 | }
|
| 2709 |
|
| 2710 | public void teleportToPortalDestination(final ServerLevel level, final TeleportTransition teleportTransition) {
|
| 2711 | ServerLevel newLevel = teleportTransition.newLevel();
|
| 2712 | if (level.isAllowedToEnterPortal(newLevel) && (newLevel.dimension() == level.dimension() || this.canTeleport(level, newLevel))) {
|
| 2713 | this.teleport(teleportTransition);
|
| 2714 | }
|
| 2715 | }
|
| 2716 |
|
| 2717 | public int getDimensionChangingDelay() {
|
| 2718 | Entity firstPassenger = this.getFirstPassenger();
|
| 2719 | return firstPassenger instanceof ServerPlayer ? firstPassenger.getDimensionChangingDelay() : 300;
|
| 2720 | }
|
| 2721 |
|
| 2722 | public void lerpMotion(final Vec3 movement) {
|
| 2723 | this.setDeltaMovement(movement);
|
| 2724 | }
|
| 2725 |
|
| 2726 | public void handleDamageEvent(final DamageSource source) {
|
| 2727 | }
|
| 2728 |
|
| 2729 | public void handleEntityEvent(final @EntityEvent.Value byte id) {
|
| 2730 | switch (id) {
|
| 2731 | case 53:
|
| 2732 | HoneyBlock.showSlideParticles(this);
|
| 2733 | }
|
| 2734 | }
|
| 2735 |
|
| 2736 | public void animateHurt(final float direction) {
|
| 2737 | }
|
| 2738 |
|
| 2739 | public boolean isOnFire() {
|
| 2740 | boolean isClientSide = this.level() != null && this.level().isClientSide();
|
| 2741 | return !this.fireImmune() && (this.remainingFireTicks > 0 || isClientSide && this.getSharedFlag(0));
|
| 2742 | }
|
| 2743 |
|
| 2744 | public boolean isPassenger() {
|
| 2745 | return this.getVehicle() != null;
|
| 2746 | }
|
| 2747 |
|
| 2748 | public boolean isVehicle() {
|
| 2749 | return !this.passengers.isEmpty();
|
| 2750 | }
|
| 2751 |
|
| 2752 | public boolean dismountsUnderwater() {
|
| 2753 | return this.is(EntityTypeTags.DISMOUNTS_UNDERWATER);
|
| 2754 | }
|
| 2755 |
|
| 2756 | public boolean canControlVehicle() {
|
| 2757 | return !this.is(EntityTypeTags.NON_CONTROLLING_RIDER);
|
| 2758 | }
|
| 2759 |
|
| 2760 | public void setShiftKeyDown(final boolean shiftKeyDown) {
|
| 2761 | this.setSharedFlag(1, shiftKeyDown);
|
| 2762 | }
|
| 2763 |
|
| 2764 | public boolean isShiftKeyDown() {
|
| 2765 | return this.getSharedFlag(1);
|
| 2766 | }
|
| 2767 |
|
| 2768 | public boolean isSteppingCarefully() {
|
| 2769 | return this.isShiftKeyDown();
|
| 2770 | }
|
| 2771 |
|
| 2772 | public boolean isSuppressingBounce() {
|
| 2773 | return this.isShiftKeyDown();
|
| 2774 | }
|
| 2775 |
|
| 2776 | public boolean isDiscrete() {
|
| 2777 | return this.isShiftKeyDown();
|
| 2778 | }
|
| 2779 |
|
| 2780 | public boolean isDescending() {
|
| 2781 | return this.isShiftKeyDown();
|
| 2782 | }
|
| 2783 |
|
| 2784 | public boolean isCrouching() {
|
| 2785 | return this.hasPose(Pose.CROUCHING);
|
| 2786 | }
|
| 2787 |
|
| 2788 | public boolean isSprinting() {
|
| 2789 | return this.getSharedFlag(3);
|
| 2790 | }
|
| 2791 |
|
| 2792 | public void setSprinting(final boolean isSprinting) {
|
| 2793 | this.setSharedFlag(3, isSprinting);
|
| 2794 | }
|
| 2795 |
|
| 2796 | public boolean isSwimming() {
|
| 2797 | return this.getSharedFlag(4);
|
| 2798 | }
|
| 2799 |
|
| 2800 | public boolean isVisuallySwimming() {
|
| 2801 | return this.hasPose(Pose.SWIMMING);
|
| 2802 | }
|
| 2803 |
|
| 2804 | public boolean isVisuallyCrawling() {
|
| 2805 | return this.isVisuallySwimming() && !this.isInWater();
|
| 2806 | }
|
| 2807 |
|
| 2808 | public void setSwimming(final boolean swimming) {
|
| 2809 | this.setSharedFlag(4, swimming);
|
| 2810 | }
|
| 2811 |
|
| 2812 | public final boolean hasGlowingTag() {
|
| 2813 | return this.hasGlowingTag;
|
| 2814 | }
|
| 2815 |
|
| 2816 | public final void setGlowingTag(final boolean value) {
|
| 2817 | this.hasGlowingTag = value;
|
| 2818 | this.setSharedFlag(6, this.isCurrentlyGlowing());
|
| 2819 | }
|
| 2820 |
|
| 2821 | public boolean isCurrentlyGlowing() {
|
| 2822 | return this.level().isClientSide() ? this.getSharedFlag(6) : this.hasGlowingTag;
|
| 2823 | }
|
| 2824 |
|
| 2825 | public boolean isInvisible() {
|
| 2826 | return this.getSharedFlag(5);
|
| 2827 | }
|
| 2828 |
|
| 2829 | public boolean isInvisibleTo(final Player player) {
|
| 2830 | if (player.isSpectator()) {
|
| 2831 | return false;
|
| 2832 | }
|
| 2833 |
|
| 2834 | Team team = this.getTeam();
|
| 2835 | return team != null && player != null && player.getTeam() == team && team.canSeeFriendlyInvisibles() ? false : this.isInvisible();
|
| 2836 | }
|
| 2837 |
|
| 2838 | public boolean isOnRails() {
|
| 2839 | return false;
|
| 2840 | }
|
| 2841 |
|
| 2842 | public void updateDynamicGameEventListener(final BiConsumer<DynamicGameEventListener<?>, ServerLevel> action) {
|
| 2843 | }
|
| 2844 |
|
| 2845 | public @Nullable PlayerTeam getTeam() {
|
| 2846 | return this.level().getScoreboard().getPlayersTeam(this.getScoreboardName());
|
| 2847 | }
|
| 2848 |
|
| 2849 | public final boolean isAlliedTo(final @Nullable Entity other) {
|
| 2850 | return other == null ? false : this == other || this.considersEntityAsAlly(other) || other.considersEntityAsAlly(this);
|
| 2851 | }
|
| 2852 |
|
| 2853 | protected boolean considersEntityAsAlly(final Entity other) {
|
| 2854 | return this.isAlliedTo(other.getTeam());
|
| 2855 | }
|
| 2856 |
|
| 2857 | public boolean isAlliedTo(final @Nullable Team other) {
|
| 2858 | return this.getTeam() != null ? this.getTeam().isAlliedTo(other) : false;
|
| 2859 | }
|
| 2860 |
|
| 2861 | public void setInvisible(final boolean invisible) {
|
| 2862 | this.setSharedFlag(5, invisible);
|
| 2863 | }
|
| 2864 |
|
| 2865 | protected boolean getSharedFlag(final @Entity.Flags int flag) {
|
| 2866 | return (this.entityData.get(DATA_SHARED_FLAGS_ID) & 1 << flag) != 0;
|
| 2867 | }
|
| 2868 |
|
| 2869 | protected void setSharedFlag(final @Entity.Flags int flag, final boolean value) {
|
| 2870 | byte currentValue = this.entityData.get(DATA_SHARED_FLAGS_ID);
|
| 2871 | if (value) {
|
| 2872 | this.entityData.set(DATA_SHARED_FLAGS_ID, (byte)(currentValue | 1 << flag));
|
| 2873 | } else {
|
| 2874 | this.entityData.set(DATA_SHARED_FLAGS_ID, (byte)(currentValue & ~(1 << flag)));
|
| 2875 | }
|
| 2876 | }
|
| 2877 |
|
| 2878 | public int getMaxAirSupply() {
|
| 2879 | return 300;
|
| 2880 | }
|
| 2881 |
|
| 2882 | public int getAirSupply() {
|
| 2883 | return this.entityData.get(DATA_AIR_SUPPLY_ID);
|
| 2884 | }
|
| 2885 |
|
| 2886 | public void setAirSupply(final int supply) {
|
| 2887 | this.entityData.set(DATA_AIR_SUPPLY_ID, supply);
|
| 2888 | }
|
| 2889 |
|
| 2890 | public void clearFreeze() {
|
| 2891 | this.setTicksFrozen(0);
|
| 2892 | }
|
| 2893 |
|
| 2894 | public int getTicksFrozen() {
|
| 2895 | return this.entityData.get(DATA_TICKS_FROZEN);
|
| 2896 | }
|
| 2897 |
|
| 2898 | public void setTicksFrozen(final int ticks) {
|
| 2899 | this.entityData.set(DATA_TICKS_FROZEN, ticks);
|
| 2900 | }
|
| 2901 |
|
| 2902 | public float getPercentFrozen() {
|
| 2903 | int ticksToFreeze = this.getTicksRequiredToFreeze();
|
| 2904 | return (float)Math.min(this.getTicksFrozen(), ticksToFreeze) / ticksToFreeze;
|
| 2905 | }
|
| 2906 |
|
| 2907 | public boolean isFullyFrozen() {
|
| 2908 | return this.getTicksFrozen() >= this.getTicksRequiredToFreeze();
|
| 2909 | }
|
| 2910 |
|
| 2911 | public int getTicksRequiredToFreeze() {
|
| 2912 | return 140;
|
| 2913 | }
|
| 2914 |
|
| 2915 | public void thunderHit(final ServerLevel level, final LightningBolt lightningBolt) {
|
| 2916 | this.setRemainingFireTicks(this.remainingFireTicks + 1);
|
| 2917 | if (this.remainingFireTicks == 0) {
|
| 2918 | this.igniteForSeconds(8.0F);
|
| 2919 | }
|
| 2920 |
|
| 2921 | this.hurtServer(level, this.damageSources().lightningBolt(), 5.0F);
|
| 2922 | }
|
| 2923 |
|
| 2924 | public void onAboveBubbleColumn(final boolean dragDown, final BlockPos pos) {
|
| 2925 | handleOnAboveBubbleColumn(this, dragDown, pos);
|
| 2926 | }
|
| 2927 |
|
| 2928 | protected static void handleOnAboveBubbleColumn(final Entity entity, final boolean dragDown, final BlockPos pos) {
|
| 2929 | if (entity.canSimulateMovement()) {
|
| 2930 | Vec3 movement = entity.getDeltaMovement();
|
| 2931 | double yd;
|
| 2932 | if (dragDown) {
|
| 2933 | yd = Math.max(-0.9, movement.y - 0.03);
|
| 2934 | } else {
|
| 2935 | yd = Math.min(1.8, movement.y + 0.1);
|
| 2936 | }
|
| 2937 |
|
| 2938 | entity.setDeltaMovement(movement.x, yd, movement.z);
|
| 2939 | }
|
| 2940 |
|
| 2941 | sendBubbleColumnParticles(entity.level, pos);
|
| 2942 | }
|
| 2943 |
|
| 2944 | protected static void sendBubbleColumnParticles(final Level level, final BlockPos pos) {
|
| 2945 | if (level instanceof ServerLevel serverLevel) {
|
| 2946 | RandomSource random = level.getRandom();
|
| 2947 |
|
| 2948 | for (int i = 0; i < 2; i++) {
|
| 2949 | serverLevel.sendParticles(ParticleTypes.SPLASH, pos.getX() + random.nextDouble(), pos.getY() + 1, pos.getZ() + random.nextDouble(), 1, 0.0, 0.0, 0.0, 1.0);
|
| 2950 | serverLevel.sendParticles(ParticleTypes.BUBBLE, pos.getX() + random.nextDouble(), pos.getY() + 1, pos.getZ() + random.nextDouble(), 1, 0.0, 0.01, 0.0, 0.2);
|
| 2951 | }
|
| 2952 | }
|
| 2953 | }
|
| 2954 |
|
| 2955 | public void onInsideBubbleColumn(final boolean dragDown) {
|
| 2956 | handleOnInsideBubbleColumn(this, dragDown);
|
| 2957 | }
|
| 2958 |
|
| 2959 | protected static void handleOnInsideBubbleColumn(final Entity entity, final boolean dragDown) {
|
| 2960 | if (entity.canSimulateMovement()) {
|
| 2961 | Vec3 movement = entity.getDeltaMovement();
|
| 2962 | double yd;
|
| 2963 | if (dragDown) {
|
| 2964 | yd = Math.max(-0.3, movement.y - 0.03);
|
| 2965 | } else {
|
| 2966 | yd = Math.min(0.7, movement.y + 0.06);
|
| 2967 | }
|
| 2968 |
|
| 2969 | entity.setDeltaMovement(movement.x, yd, movement.z);
|
| 2970 | }
|
| 2971 |
|
| 2972 | entity.resetFallDistance();
|
| 2973 | }
|
| 2974 |
|
| 2975 | public boolean killedEntity(final ServerLevel level, final LivingEntity entity, final DamageSource source) {
|
| 2976 | return true;
|
| 2977 | }
|
| 2978 |
|
| 2979 | public boolean projectileReceivesSideEffectsOnHit(final boolean wasHurt) {
|
| 2980 | return true;
|
| 2981 | }
|
| 2982 |
|
| 2983 | public void checkFallDistanceAccumulation() {
|
| 2984 | if (this.getDeltaMovement().y() > -0.5 && this.fallDistance > 1.0) {
|
| 2985 | this.fallDistance = 1.0;
|
| 2986 | }
|
| 2987 | }
|
| 2988 |
|
| 2989 | public void resetFallDistance() {
|
| 2990 | this.fallDistance = 0.0;
|
| 2991 | }
|
| 2992 |
|
| 2993 | protected void moveTowardsClosestSpace(final double x, final double y, final double z) {
|
| 2994 | BlockPos pos = BlockPos.containing(x, y, z);
|
| 2995 | Vec3 delta = new Vec3(x - pos.getX(), y - pos.getY(), z - pos.getZ());
|
| 2996 | BlockPos.MutableBlockPos neighborPos = new BlockPos.MutableBlockPos();
|
| 2997 | Direction closestDirection = Direction.UP;
|
| 2998 | double closest = Double.MAX_VALUE;
|
| 2999 |
|
| 3000 | for (Direction direction : new Direction[]{Direction.NORTH, Direction.SOUTH, Direction.WEST, Direction.EAST, Direction.UP}) {
|
| 3001 | neighborPos.setWithOffset(pos, direction);
|
| 3002 | if (!this.level().getBlockState(neighborPos).isCollisionShapeFullBlock(this.level(), neighborPos)) {
|
| 3003 | double d = delta.get(direction.getAxis());
|
| 3004 | double orientedDelta = direction.getAxisDirection() == Direction.AxisDirection.POSITIVE ? 1.0 - d : d;
|
| 3005 | if (orientedDelta < closest) {
|
| 3006 | closest = orientedDelta;
|
| 3007 | closestDirection = direction;
|
| 3008 | }
|
| 3009 | }
|
| 3010 | }
|
| 3011 |
|
| 3012 | float speed = this.random.nextFloat() * 0.2F + 0.1F;
|
| 3013 | float step = closestDirection.getAxisDirection().getStep();
|
| 3014 | Vec3 scaledMovement = this.getDeltaMovement().scale(0.75);
|
| 3015 | if (closestDirection.getAxis() == Direction.Axis.X) {
|
| 3016 | this.setDeltaMovement(step * speed, scaledMovement.y, scaledMovement.z);
|
| 3017 | } else if (closestDirection.getAxis() == Direction.Axis.Y) {
|
| 3018 | this.setDeltaMovement(scaledMovement.x, step * speed, scaledMovement.z);
|
| 3019 | } else if (closestDirection.getAxis() == Direction.Axis.Z) {
|
| 3020 | this.setDeltaMovement(scaledMovement.x, scaledMovement.y, step * speed);
|
| 3021 | }
|
| 3022 | }
|
| 3023 |
|
| 3024 | public void makeStuckInBlock(final BlockState blockState, final Vec3 speedMultiplier) {
|
| 3025 | this.resetFallDistance();
|
| 3026 | this.stuckSpeedMultiplier = speedMultiplier;
|
| 3027 | }
|
| 3028 |
|
| 3029 | private static Component removeAction(final Component component) {
|
| 3030 | MutableComponent result = component.plainCopy().setStyle(component.getStyle().withClickEvent(null));
|
| 3031 |
|
| 3032 | for (Component s : component.getSiblings()) {
|
| 3033 | result.append(removeAction(s));
|
| 3034 | }
|
| 3035 |
|
| 3036 | return result;
|
| 3037 | }
|
| 3038 |
|
| 3039 | @Override
|
| 3040 | public Component getName() {
|
| 3041 | Component customName = this.getCustomName();
|
| 3042 | return customName != null ? removeAction(customName) : this.getTypeName();
|
| 3043 | }
|
| 3044 |
|
| 3045 | protected Component getTypeName() {
|
| 3046 | return this.type.getDescription();
|
| 3047 | }
|
| 3048 |
|
| 3049 | public boolean is(final Entity other) {
|
| 3050 | return this == other;
|
| 3051 | }
|
| 3052 |
|
| 3053 | public float getYHeadRot() {
|
| 3054 | return 0.0F;
|
| 3055 | }
|
| 3056 |
|
| 3057 | public void setYHeadRot(final float yHeadRot) {
|
| 3058 | }
|
| 3059 |
|
| 3060 | public void setYBodyRot(final float yBodyRot) {
|
| 3061 | }
|
| 3062 |
|
| 3063 | public boolean isAttackable() {
|
| 3064 | return true;
|
| 3065 | }
|
| 3066 |
|
| 3067 | public boolean skipAttackInteraction(final Entity source) {
|
| 3068 | return false;
|
| 3069 | }
|
| 3070 |
|
| 3071 | @Override
|
| 3072 | public String toString() {
|
| 3073 | String levelId = this.level() == null ? "~NULL~" : this.level().toString();
|
| 3074 | return this.removalReason != null
|
| 3075 | ? String.format(
|
| 3076 | Locale.ROOT,
|
| 3077 | "%s['%s'/%d, l='%s', x=%.2f, y=%.2f, z=%.2f, removed=%s]",
|
| 3078 | this.getClass().getSimpleName(),
|
| 3079 | this.getPlainTextName(),
|
| 3080 | this.id,
|
| 3081 | levelId,
|
| 3082 | this.getX(),
|
| 3083 | this.getY(),
|
| 3084 | this.getZ(),
|
| 3085 | this.removalReason
|
| 3086 | )
|
| 3087 | : String.format(
|
| 3088 | Locale.ROOT,
|
| 3089 | "%s['%s'/%d, l='%s', x=%.2f, y=%.2f, z=%.2f]",
|
| 3090 | this.getClass().getSimpleName(),
|
| 3091 | this.getPlainTextName(),
|
| 3092 | this.id,
|
| 3093 | levelId,
|
| 3094 | this.getX(),
|
| 3095 | this.getY(),
|
| 3096 | this.getZ()
|
| 3097 | );
|
| 3098 | }
|
| 3099 |
|
| 3100 | protected final boolean isInvulnerableToBase(final DamageSource source) {
|
| 3101 | return this.isRemoved()
|
| 3102 | || this.isInvulnerable() && !source.is(DamageTypeTags.BYPASSES_INVULNERABILITY) && !source.isCreativePlayer()
|
| 3103 | || source.is(DamageTypeTags.IS_FIRE) && this.fireImmune()
|
| 3104 | || source.is(DamageTypeTags.IS_FALL) && this.is(EntityTypeTags.FALL_DAMAGE_IMMUNE);
|
| 3105 | }
|
| 3106 |
|
| 3107 | public boolean isInvulnerable() {
|
| 3108 | return this.isPermanentlyInvulnerable() || this.isTemporarilyInvulnerable();
|
| 3109 | }
|
| 3110 |
|
| 3111 | public boolean isPermanentlyInvulnerable() {
|
| 3112 | return this.permanentlyInvulnerable;
|
| 3113 | }
|
| 3114 |
|
| 3115 | public boolean isTemporarilyInvulnerable() {
|
| 3116 | return this.invulnerableTime > 0;
|
| 3117 | }
|
| 3118 |
|
| 3119 | public boolean isInvulnerableToPiercingWeapon() {
|
| 3120 | return this.isInvulnerable();
|
| 3121 | }
|
| 3122 |
|
| 3123 | public void setPermanentlyInvulnerable(final boolean permanentlyInvulnerable) {
|
| 3124 | this.permanentlyInvulnerable = permanentlyInvulnerable;
|
| 3125 | }
|
| 3126 |
|
| 3127 | public void copyPosition(final Entity target) {
|
| 3128 | this.snapTo(target.getX(), target.getY(), target.getZ(), target.getYRot(), target.getXRot());
|
| 3129 | }
|
| 3130 |
|
| 3131 | public void restoreFrom(final Entity oldEntity) {
|
| 3132 | try (ProblemReporter.ScopedCollector reporter = new ProblemReporter.ScopedCollector(this.problemPath(), LOGGER)) {
|
| 3133 | TagValueOutput entityData = TagValueOutput.createWithContext(reporter, oldEntity.registryAccess());
|
| 3134 | oldEntity.saveWithoutId(entityData);
|
| 3135 | this.load(TagValueInput.create(reporter, this.registryAccess(), entityData.buildResult()));
|
| 3136 | }
|
| 3137 |
|
| 3138 | this.portalCooldown = oldEntity.portalCooldown;
|
| 3139 | this.portalProcess = oldEntity.portalProcess;
|
| 3140 | }
|
| 3141 |
|
| 3142 | public @Nullable Entity teleport(final TeleportTransition transition) {
|
| 3143 | if (this.level() instanceof ServerLevel serverLevel && !this.isRemoved()) {
|
| 3144 | ServerLevel newLevel = transition.newLevel();
|
| 3145 | boolean otherDimension = newLevel.dimension() != serverLevel.dimension();
|
| 3146 | if (!transition.asPassenger()) {
|
| 3147 | this.stopRiding();
|
| 3148 | }
|
| 3149 |
|
| 3150 | return otherDimension ? this.teleportCrossDimension(serverLevel, newLevel, transition) : this.teleportSameDimension(serverLevel, transition);
|
| 3151 | } else {
|
| 3152 | return null;
|
| 3153 | }
|
| 3154 | }
|
| 3155 |
|
| 3156 | private Entity teleportSameDimension(final ServerLevel level, final TeleportTransition transition) {
|
| 3157 | for (Entity passenger : this.getPassengers()) {
|
| 3158 | passenger.teleport(this.calculatePassengerTransition(transition, passenger));
|
| 3159 | }
|
| 3160 |
|
| 3161 | ProfilerFiller profiler = Profiler.get();
|
| 3162 | profiler.push("teleportSameDimension");
|
| 3163 | this.teleportSetPosition(PositionMoveRotation.of(transition), transition.relatives());
|
| 3164 | if (!transition.asPassenger()) {
|
| 3165 | this.sendTeleportTransitionToPlayers(level, transition);
|
| 3166 | }
|
| 3167 |
|
| 3168 | transition.postTeleportTransition().onTransition(this);
|
| 3169 | profiler.pop();
|
| 3170 | return this;
|
| 3171 | }
|
| 3172 |
|
| 3173 | private @Nullable Entity teleportCrossDimension(final ServerLevel oldLevel, final ServerLevel newLevel, final TeleportTransition transition) {
|
| 3174 | List<Entity> oldPassengers = this.getPassengers();
|
| 3175 | List<Entity> newPassengers = new ArrayList<>(oldPassengers.size());
|
| 3176 | this.ejectPassengers();
|
| 3177 |
|
| 3178 | for (Entity passenger : oldPassengers) {
|
| 3179 | Entity newPassenger = passenger.teleport(this.calculatePassengerTransition(transition, passenger));
|
| 3180 | if (newPassenger != null) {
|
| 3181 | newPassengers.add(newPassenger);
|
| 3182 | }
|
| 3183 | }
|
| 3184 |
|
| 3185 | ProfilerFiller profiler = Profiler.get();
|
| 3186 | profiler.push("teleportCrossDimension");
|
| 3187 | Entity newEntity = this.getType().create(newLevel, EntitySpawnReason.DIMENSION_TRAVEL);
|
| 3188 | if (newEntity == null) {
|
| 3189 | profiler.pop();
|
| 3190 | return null;
|
| 3191 | }
|
| 3192 |
|
| 3193 | newEntity.restoreFrom(this);
|
| 3194 | this.removeAfterChangingDimensions();
|
| 3195 | newEntity.teleportSetPosition(PositionMoveRotation.of(this), PositionMoveRotation.of(transition), transition.relatives());
|
| 3196 | newLevel.addDuringTeleport(newEntity);
|
| 3197 |
|
| 3198 | for (Entity newPassenger : newPassengers) {
|
| 3199 | newPassenger.startRiding(newEntity, true, false);
|
| 3200 | }
|
| 3201 |
|
| 3202 | newLevel.resetEmptyTime();
|
| 3203 | transition.postTeleportTransition().onTransition(newEntity);
|
| 3204 | this.teleportSpectators(transition, oldLevel);
|
| 3205 | profiler.pop();
|
| 3206 | return newEntity;
|
| 3207 | }
|
| 3208 |
|
| 3209 | protected void teleportSpectators(final TeleportTransition transition, final ServerLevel oldLevel) {
|
| 3210 | for (ServerPlayer serverPlayer : List.copyOf(oldLevel.players())) {
|
| 3211 | if (serverPlayer.getCamera() == this) {
|
| 3212 | serverPlayer.teleport(transition);
|
| 3213 | serverPlayer.setCamera(null);
|
| 3214 | }
|
| 3215 | }
|
| 3216 | }
|
| 3217 |
|
| 3218 | private TeleportTransition calculatePassengerTransition(final TeleportTransition transition, final Entity passenger) {
|
| 3219 | float passengerYRot = transition.yRot() + (transition.relatives().contains(Relative.Y_ROT) ? 0.0F : passenger.getYRot() - this.getYRot());
|
| 3220 | float passengerXRot = transition.xRot() + (transition.relatives().contains(Relative.X_ROT) ? 0.0F : passenger.getXRot() - this.getXRot());
|
| 3221 | Vec3 passengerOffset = passenger.position().subtract(this.position());
|
| 3222 | Vec3 passengerPos = transition.position()
|
| 3223 | .add(
|
| 3224 | transition.relatives().contains(Relative.X) ? 0.0 : passengerOffset.x(),
|
| 3225 | transition.relatives().contains(Relative.Y) ? 0.0 : passengerOffset.y(),
|
| 3226 | transition.relatives().contains(Relative.Z) ? 0.0 : passengerOffset.z()
|
| 3227 | );
|
| 3228 | return transition.withPosition(passengerPos).withRotation(passengerYRot, passengerXRot).transitionAsPassenger();
|
| 3229 | }
|
| 3230 |
|
| 3231 | private void sendTeleportTransitionToPlayers(final ServerLevel serverLevel, final TeleportTransition transition) {
|
| 3232 | Entity controller = this.getControllingPassenger();
|
| 3233 | List<Entity> passengers = this.getIndirectPassengersStream().toList();
|
| 3234 |
|
| 3235 | for (Entity passenger : passengers) {
|
| 3236 | if (passenger instanceof ServerPlayer player) {
|
| 3237 | if (controller != null && player.getId() == controller.getId()) {
|
| 3238 | player.connection.send(ClientboundTeleportEntityPacket.teleport(this.getId(), PositionMoveRotation.of(transition), transition.relatives(), this.onGround));
|
| 3239 | } else {
|
| 3240 | player.connection.send(ClientboundTeleportEntityPacket.teleport(this.getId(), PositionMoveRotation.of(this), Set.of(), this.onGround));
|
| 3241 | }
|
| 3242 | }
|
| 3243 | }
|
| 3244 |
|
| 3245 | if (!this.type.hasUpdateInterval() || this.getMoveSimulationType() == MoveSimulationType.SERVER_AND_CLIENT) {
|
| 3246 | serverLevel.getChunkSource()
|
| 3247 | .sendToTrackingPlayersFiltered(
|
| 3248 | this,
|
| 3249 | ClientboundTeleportEntityPacket.teleport(this.getId(), PositionMoveRotation.of(this), Set.of(), this.onGround),
|
| 3250 | playerx -> !passengers.contains(playerx)
|
| 3251 | );
|
| 3252 | }
|
| 3253 | }
|
| 3254 |
|
| 3255 | public void teleportSetPosition(final PositionMoveRotation destination, final Set<Relative> relatives) {
|
| 3256 | this.teleportSetPosition(PositionMoveRotation.of(this), destination, relatives);
|
| 3257 | }
|
| 3258 |
|
| 3259 | public void teleportSetPosition(final PositionMoveRotation currentValues, final PositionMoveRotation destination, final Set<Relative> relatives) {
|
| 3260 | PositionMoveRotation absoluteDestination = PositionMoveRotation.calculateAbsolute(currentValues, destination, relatives);
|
| 3261 | this.setPosRaw(absoluteDestination.position().x, absoluteDestination.position().y, absoluteDestination.position().z);
|
| 3262 | this.setYRot(absoluteDestination.yRot());
|
| 3263 | this.setYHeadRot(absoluteDestination.yRot());
|
| 3264 | this.setXRot(absoluteDestination.xRot());
|
| 3265 | this.reapplyPosition();
|
| 3266 | this.setOldPosAndRot();
|
| 3267 | this.setDeltaMovement(absoluteDestination.deltaMovement());
|
| 3268 | this.clearMovementThisTick();
|
| 3269 | }
|
| 3270 |
|
| 3271 | public void forceSetRotation(final float yRot, final boolean relativeY, final float xRot, final boolean relativeX) {
|
| 3272 | Set<Relative> relatives = Relative.rotation(relativeY, relativeX);
|
| 3273 | PositionMoveRotation currentValues = PositionMoveRotation.of(this);
|
| 3274 | PositionMoveRotation destination = currentValues.withRotation(yRot, xRot);
|
| 3275 | PositionMoveRotation absoluteDestination = PositionMoveRotation.calculateAbsolute(currentValues, destination, relatives);
|
| 3276 | this.setYRot(absoluteDestination.yRot());
|
| 3277 | this.setYHeadRot(absoluteDestination.yRot());
|
| 3278 | this.setXRot(absoluteDestination.xRot());
|
| 3279 | this.setOldRot();
|
| 3280 | }
|
| 3281 |
|
| 3282 | public void placePortalTicket(final BlockPos ticketPosition) {
|
| 3283 | if (this.level() instanceof ServerLevel serverLevel) {
|
| 3284 | serverLevel.getChunkSource().addTicketWithRadius(TicketType.PORTAL, ChunkPos.containing(ticketPosition), 3);
|
| 3285 | }
|
| 3286 | }
|
| 3287 |
|
| 3288 | protected void removeAfterChangingDimensions() {
|
| 3289 | this.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION);
|
| 3290 | if (this instanceof Leashable leashable) {
|
| 3291 | leashable.removeLeash();
|
| 3292 | }
|
| 3293 |
|
| 3294 | if (this instanceof WaypointTransmitter waypoint && this.level instanceof ServerLevel serverLevel) {
|
| 3295 | serverLevel.getWaypointManager().untrackWaypoint(waypoint);
|
| 3296 | }
|
| 3297 | }
|
| 3298 |
|
| 3299 | public Vec3 getRelativePortalPosition(final Direction.Axis axis, final BlockUtil.FoundRectangle portalArea) {
|
| 3300 | return PortalShape.getRelativePosition(portalArea, axis, this.position(), this.getDimensions(this.getPose()));
|
| 3301 | }
|
| 3302 |
|
| 3303 | public boolean canUsePortal(final boolean ignorePassenger) {
|
| 3304 | return (ignorePassenger || !this.isPassenger()) && this.isAlive();
|
| 3305 | }
|
| 3306 |
|
| 3307 | public boolean canTeleport(final Level from, final Level to) {
|
| 3308 | if (from.dimension() == Level.END && to.dimension() == Level.OVERWORLD) {
|
| 3309 | for (Entity passenger : this.getPassengers()) {
|
| 3310 | if (passenger instanceof ServerPlayer player && !player.seenCredits) {
|
| 3311 | return false;
|
| 3312 | }
|
| 3313 | }
|
| 3314 | }
|
| 3315 |
|
| 3316 | return true;
|
| 3317 | }
|
| 3318 |
|
| 3319 | public float getBlockExplosionResistance(
|
| 3320 | final Explosion explosion, final BlockGetter level, final BlockPos pos, final BlockState block, final FluidState fluid, final float resistance
|
| 3321 | ) {
|
| 3322 | return resistance;
|
| 3323 | }
|
| 3324 |
|
| 3325 | public boolean shouldBlockExplode(final Explosion explosion, final BlockGetter level, final BlockPos pos, final BlockState state, final float power) {
|
| 3326 | return true;
|
| 3327 | }
|
| 3328 |
|
| 3329 | public int getMaxFallDistance() {
|
| 3330 | return 3;
|
| 3331 | }
|
| 3332 |
|
| 3333 | public boolean isIgnoringBlockTriggers() {
|
| 3334 | return false;
|
| 3335 | }
|
| 3336 |
|
| 3337 | public void fillCrashReportCategory(final CrashReportCategory category) {
|
| 3338 | category.setDetail("Entity Type", () -> this.typeHolder().getRegisteredName() + " (" + this.getClass().getCanonicalName() + ")");
|
| 3339 | category.setDetail("Entity ID", this.id);
|
| 3340 | category.setDetail("Entity Name", () -> this.getPlainTextName());
|
| 3341 | category.setDetail("Entity's Exact location", String.format(Locale.ROOT, "%.2f, %.2f, %.2f", this.getX(), this.getY(), this.getZ()));
|
| 3342 | category.setDetail(
|
| 3343 | "Entity's Block location", CrashReportCategory.formatLocation(this.level(), Mth.floor(this.getX()), Mth.floor(this.getY()), Mth.floor(this.getZ()))
|
| 3344 | );
|
| 3345 | Vec3 movement = this.getDeltaMovement();
|
| 3346 | category.setDetail("Entity's Momentum", String.format(Locale.ROOT, "%.2f, %.2f, %.2f", movement.x, movement.y, movement.z));
|
| 3347 | category.setDetail("Entity's Passengers", () -> this.getPassengers().toString());
|
| 3348 | category.setDetail("Entity's Vehicle", () -> String.valueOf(this.getVehicle()));
|
| 3349 | }
|
| 3350 |
|
| 3351 | public boolean displayFireAnimation() {
|
| 3352 | return this.isOnFire() && !this.isSpectator();
|
| 3353 | }
|
| 3354 |
|
| 3355 | public void setUUID(final UUID uuid) {
|
| 3356 | this.uuid = uuid;
|
| 3357 | this.stringUUID = this.uuid.toString();
|
| 3358 | }
|
| 3359 |
|
| 3360 | @Override
|
| 3361 | public UUID getUUID() {
|
| 3362 | return this.uuid;
|
| 3363 | }
|
| 3364 |
|
| 3365 | public String getStringUUID() {
|
| 3366 | return this.stringUUID;
|
| 3367 | }
|
| 3368 |
|
| 3369 | @Override
|
| 3370 | public String getScoreboardName() {
|
| 3371 | return this.stringUUID;
|
| 3372 | }
|
| 3373 |
|
| 3374 | public boolean isPushedByFluid() {
|
| 3375 | return true;
|
| 3376 | }
|
| 3377 |
|
| 3378 | public static double getViewScale() {
|
| 3379 | return viewScale;
|
| 3380 | }
|
| 3381 |
|
| 3382 | public static void setViewScale(final double viewScale) {
|
| 3383 | Entity.viewScale = viewScale;
|
| 3384 | }
|
| 3385 |
|
| 3386 | @Override
|
| 3387 | public Component getDisplayName() {
|
| 3388 | return PlayerTeam.formatNameForTeam(this.getTeam(), this.getName())
|
| 3389 | .withStyle(s -> s.withHoverEvent(this.createHoverEvent()).withInsertion(this.getStringUUID()));
|
| 3390 | }
|
| 3391 |
|
| 3392 | public void setCustomName(final @Nullable Component name) {
|
| 3393 | this.entityData.set(DATA_CUSTOM_NAME, Optional.ofNullable(name));
|
| 3394 | }
|
| 3395 |
|
| 3396 | @Override
|
| 3397 | public @Nullable Component getCustomName() {
|
| 3398 | return this.entityData.get(DATA_CUSTOM_NAME).orElse(null);
|
| 3399 | }
|
| 3400 |
|
| 3401 | @Override
|
| 3402 | public boolean hasCustomName() {
|
| 3403 | return this.entityData.get(DATA_CUSTOM_NAME).isPresent();
|
| 3404 | }
|
| 3405 |
|
| 3406 | public void setCustomNameVisible(final boolean visible) {
|
| 3407 | this.entityData.set(DATA_CUSTOM_NAME_VISIBLE, visible);
|
| 3408 | }
|
| 3409 |
|
| 3410 | public boolean isCustomNameVisible() {
|
| 3411 | return this.entityData.get(DATA_CUSTOM_NAME_VISIBLE);
|
| 3412 | }
|
| 3413 |
|
| 3414 | public @Nullable Component belowNameDisplay() {
|
| 3415 | Scoreboard scoreboard = this.level().getScoreboard();
|
| 3416 | Objective objective = scoreboard.getDisplayObjective(DisplaySlot.BELOW_NAME);
|
| 3417 | if (objective != null) {
|
| 3418 | ReadOnlyScoreInfo score = scoreboard.getPlayerScoreInfo(this, objective);
|
| 3419 | if (score != null) {
|
| 3420 | Component formattedValue = score.formatValue(objective.numberFormatOrDefault(StyledFormat.NO_STYLE));
|
| 3421 | return Component.empty().append(formattedValue).append(CommonComponents.SPACE).append(objective.getDisplayName());
|
| 3422 | }
|
| 3423 | }
|
| 3424 |
|
| 3425 | return null;
|
| 3426 | }
|
| 3427 |
|
| 3428 | public boolean teleportTo(
|
| 3429 | final ServerLevel level,
|
| 3430 | final double x,
|
| 3431 | final double y,
|
| 3432 | final double z,
|
| 3433 | final Set<Relative> relatives,
|
| 3434 | final float newYRot,
|
| 3435 | final float newXRot,
|
| 3436 | final boolean resetCamera
|
| 3437 | ) {
|
| 3438 | Entity newEntity = this.teleport(new TeleportTransition(level, new Vec3(x, y, z), Vec3.ZERO, newYRot, newXRot, relatives, TeleportTransition.DO_NOTHING));
|
| 3439 | return newEntity != null;
|
| 3440 | }
|
| 3441 |
|
| 3442 | public void dismountTo(final double x, final double y, final double z) {
|
| 3443 | this.teleportTo(x, y, z);
|
| 3444 | }
|
| 3445 |
|
| 3446 | public void teleportTo(final double x, final double y, final double z) {
|
| 3447 | if (this.level() instanceof ServerLevel) {
|
| 3448 | this.snapTo(x, y, z, this.getYRot(), this.getXRot());
|
| 3449 | this.teleportPassengers();
|
| 3450 | }
|
| 3451 | }
|
| 3452 |
|
| 3453 | private void teleportPassengers() {
|
| 3454 | this.getSelfAndPassengers().forEach(entity -> {
|
| 3455 | for (Entity passenger : entity.passengers) {
|
| 3456 | entity.positionRider(passenger, Entity::snapTo);
|
| 3457 | }
|
| 3458 | });
|
| 3459 | }
|
| 3460 |
|
| 3461 | public void teleportRelative(final double dx, final double dy, final double dz) {
|
| 3462 | this.teleportTo(this.getX() + dx, this.getY() + dy, this.getZ() + dz);
|
| 3463 | }
|
| 3464 |
|
| 3465 | public boolean shouldShowName() {
|
| 3466 | return this.isCustomNameVisible();
|
| 3467 | }
|
| 3468 |
|
| 3469 | @Override
|
| 3470 | public void onSyncedDataUpdated(final List<SynchedEntityData.DataValue<?>> updatedItems) {
|
| 3471 | }
|
| 3472 |
|
| 3473 | @Override
|
| 3474 | public void onSyncedDataUpdated(final EntityDataAccessor<?> accessor) {
|
| 3475 | if (DATA_POSE.equals(accessor)) {
|
| 3476 | this.refreshDimensions();
|
| 3477 | }
|
| 3478 | }
|
| 3479 |
|
| 3480 | @Deprecated
|
| 3481 | protected void fixupDimensions() {
|
| 3482 | Pose pose = this.getPose();
|
| 3483 | EntityDimensions newDim = this.getDimensions(pose);
|
| 3484 | this.dimensions = newDim;
|
| 3485 | this.eyeHeight = newDim.eyeHeight();
|
| 3486 | }
|
| 3487 |
|
| 3488 | public void refreshDimensions() {
|
| 3489 | EntityDimensions oldDim = this.dimensions;
|
| 3490 | Pose pose = this.getPose();
|
| 3491 | EntityDimensions newDim = this.getDimensions(pose);
|
| 3492 | this.dimensions = newDim;
|
| 3493 | this.eyeHeight = newDim.eyeHeight();
|
| 3494 | this.reapplyPosition();
|
| 3495 | boolean isSmall = newDim.width() <= 4.0F && newDim.height() <= 4.0F;
|
| 3496 | if (!this.level.isClientSide()
|
| 3497 | && !this.firstTick
|
| 3498 | && !this.noPhysics
|
| 3499 | && isSmall
|
| 3500 | && (newDim.width() > oldDim.width() || newDim.height() > oldDim.height())
|
| 3501 | && !(this instanceof Player)) {
|
| 3502 | this.fudgePositionAfterSizeChange(oldDim);
|
| 3503 | }
|
| 3504 | }
|
| 3505 |
|
| 3506 | public boolean fudgePositionAfterSizeChange(final EntityDimensions previousDimensions) {
|
| 3507 | EntityDimensions newDimensions = this.getDimensions(this.getPose());
|
| 3508 | Vec3 oldCenter = this.position().add(0.0, previousDimensions.height() / 2.0, 0.0);
|
| 3509 | double widthDelta = Math.max(0.0F, newDimensions.width() - previousDimensions.width()) + 1.0E-6;
|
| 3510 | double heightDelta = Math.max(0.0F, newDimensions.height() - previousDimensions.height()) + 1.0E-6;
|
| 3511 | VoxelShape allowedCenters = Shapes.create(AABB.ofSize(oldCenter, widthDelta, heightDelta, widthDelta));
|
| 3512 | Optional<Vec3> freePosition = this.level
|
| 3513 | .findFreePosition(this, allowedCenters, oldCenter, newDimensions.width(), newDimensions.height(), newDimensions.width());
|
| 3514 | if (freePosition.isPresent()) {
|
| 3515 | this.setPos(freePosition.get().add(0.0, -newDimensions.height() / 2.0, 0.0));
|
| 3516 | return true;
|
| 3517 | }
|
| 3518 |
|
| 3519 | if (newDimensions.width() > previousDimensions.width() && newDimensions.height() > previousDimensions.height()) {
|
| 3520 | VoxelShape allowedCentersIgnoringY = Shapes.create(AABB.ofSize(oldCenter, widthDelta, 1.0E-6, widthDelta));
|
| 3521 | Optional<Vec3> freePositionIgnoreVertical = this.level
|
| 3522 | .findFreePosition(this, allowedCentersIgnoringY, oldCenter, newDimensions.width(), previousDimensions.height(), newDimensions.width());
|
| 3523 | if (freePositionIgnoreVertical.isPresent()) {
|
| 3524 | this.setPos(freePositionIgnoreVertical.get().add(0.0, -previousDimensions.height() / 2.0 + 1.0E-6, 0.0));
|
| 3525 | return true;
|
| 3526 | }
|
| 3527 | }
|
| 3528 |
|
| 3529 | return false;
|
| 3530 | }
|
| 3531 |
|
| 3532 | public Direction getDirection() {
|
| 3533 | return Direction.fromYRot(this.getYRot());
|
| 3534 | }
|
| 3535 |
|
| 3536 | public Direction getMotionDirection() {
|
| 3537 | return this.getDirection();
|
| 3538 | }
|
| 3539 |
|
| 3540 | protected HoverEvent createHoverEvent() {
|
| 3541 | return new HoverEvent.ShowEntity(new HoverEvent.EntityTooltipInfo(this.getType(), this.getUUID(), this.getName()));
|
| 3542 | }
|
| 3543 |
|
| 3544 | public boolean broadcastToPlayer(final ServerPlayer player) {
|
| 3545 | return true;
|
| 3546 | }
|
| 3547 |
|
| 3548 | @Override
|
| 3549 | public final AABB getBoundingBox() {
|
| 3550 | return this.bb;
|
| 3551 | }
|
| 3552 |
|
| 3553 | public AABB getInterpolatedBoundingBox(final float partialTicks) {
|
| 3554 | return this.xOld == this.getX() && this.yOld == this.getY() && this.zOld == this.getZ()
|
| 3555 | ? this.bb
|
| 3556 | : this.bb
|
| 3557 | .move(
|
| 3558 | Mth.lerp(partialTicks, this.xOld, this.getX()) - this.getX(),
|
| 3559 | Mth.lerp(partialTicks, this.yOld, this.getY()) - this.getY(),
|
| 3560 | Mth.lerp(partialTicks, this.zOld, this.getZ()) - this.getZ()
|
| 3561 | );
|
| 3562 | }
|
| 3563 |
|
| 3564 | public final void setBoundingBox(final AABB bb) {
|
| 3565 | this.bb = bb;
|
| 3566 | }
|
| 3567 |
|
| 3568 | public final float getEyeHeight(final Pose pose) {
|
| 3569 | return this.getDimensions(pose).eyeHeight();
|
| 3570 | }
|
| 3571 |
|
| 3572 | public final float getEyeHeight() {
|
| 3573 | return this.eyeHeight;
|
| 3574 | }
|
| 3575 |
|
| 3576 | @Override
|
| 3577 | public @Nullable SlotAccess getSlot(final int slot) {
|
| 3578 | return null;
|
| 3579 | }
|
| 3580 |
|
| 3581 | public boolean ignoreExplosion(final Explosion explosion) {
|
| 3582 | return false;
|
| 3583 | }
|
| 3584 |
|
| 3585 | public void startSeenByPlayer(final ServerPlayer player) {
|
| 3586 | }
|
| 3587 |
|
| 3588 | public void stopSeenByPlayer(final ServerPlayer player) {
|
| 3589 | }
|
| 3590 |
|
| 3591 | public float rotate(final Rotation rotation) {
|
| 3592 | float angle = Mth.wrapDegrees(this.getYRot());
|
| 3593 |
|
| 3594 | return switch (rotation) {
|
| 3595 | case CLOCKWISE_180 -> angle + 180.0F;
|
| 3596 | case COUNTERCLOCKWISE_90 -> angle + 270.0F;
|
| 3597 | case CLOCKWISE_90 -> angle + 90.0F;
|
| 3598 | default -> angle;
|
| 3599 | };
|
| 3600 | }
|
| 3601 |
|
| 3602 | public float mirror(final Mirror mirror) {
|
| 3603 | float angle = Mth.wrapDegrees(this.getYRot());
|
| 3604 |
|
| 3605 | return switch (mirror) {
|
| 3606 | case FRONT_BACK -> -angle;
|
| 3607 | case LEFT_RIGHT -> 180.0F - angle;
|
| 3608 | default -> angle;
|
| 3609 | };
|
| 3610 | }
|
| 3611 |
|
| 3612 | public ProjectileDeflection deflection(final Projectile projectile) {
|
| 3613 | return this.is(EntityTypeTags.DEFLECTS_PROJECTILES) ? ProjectileDeflection.REVERSE : ProjectileDeflection.NONE;
|
| 3614 | }
|
| 3615 |
|
| 3616 | public @Nullable LivingEntity getControllingPassenger() {
|
| 3617 | return null;
|
| 3618 | }
|
| 3619 |
|
| 3620 | public final boolean hasControllingPassenger() {
|
| 3621 | return this.getControllingPassenger() != null;
|
| 3622 | }
|
| 3623 |
|
| 3624 | public final List<Entity> getPassengers() {
|
| 3625 | return this.passengers;
|
| 3626 | }
|
| 3627 |
|
| 3628 | public @Nullable Entity getFirstPassenger() {
|
| 3629 | return this.passengers.isEmpty() ? null : this.passengers.get(0);
|
| 3630 | }
|
| 3631 |
|
| 3632 | public boolean hasPassenger(final Entity entity) {
|
| 3633 | return this.passengers.contains(entity);
|
| 3634 | }
|
| 3635 |
|
| 3636 | public boolean hasPassenger(final Predicate<Entity> test) {
|
| 3637 | for (Entity passenger : this.passengers) {
|
| 3638 | if (test.test(passenger)) {
|
| 3639 | return true;
|
| 3640 | }
|
| 3641 | }
|
| 3642 |
|
| 3643 | return false;
|
| 3644 | }
|
| 3645 |
|
| 3646 | private Stream<Entity> getIndirectPassengersStream() {
|
| 3647 | return this.passengers.stream().flatMap(Entity::getSelfAndPassengers);
|
| 3648 | }
|
| 3649 |
|
| 3650 | @Override
|
| 3651 | public Stream<Entity> getSelfAndPassengers() {
|
| 3652 | return Stream.concat(Stream.of(this), this.getIndirectPassengersStream());
|
| 3653 | }
|
| 3654 |
|
| 3655 | @Override
|
| 3656 | public Stream<Entity> getPassengersAndSelf() {
|
| 3657 | return Stream.concat(this.passengers.stream().flatMap(Entity::getPassengersAndSelf), Stream.of(this));
|
| 3658 | }
|
| 3659 |
|
| 3660 | public Iterable<Entity> getIndirectPassengers() {
|
| 3661 | return () -> this.getIndirectPassengersStream().iterator();
|
| 3662 | }
|
| 3663 |
|
| 3664 | public int countPlayerPassengers() {
|
| 3665 | return (int)this.getIndirectPassengersStream().filter(e -> e instanceof Player).count();
|
| 3666 | }
|
| 3667 |
|
| 3668 | public boolean hasExactlyOnePlayerPassenger() {
|
| 3669 | return this.countPlayerPassengers() == 1;
|
| 3670 | }
|
| 3671 |
|
| 3672 | public Entity getRootVehicle() {
|
| 3673 | Entity result = this;
|
| 3674 |
|
| 3675 | while (result.isPassenger()) {
|
| 3676 | result = result.getVehicle();
|
| 3677 | }
|
| 3678 |
|
| 3679 | return result;
|
| 3680 | }
|
| 3681 |
|
| 3682 | public boolean isPassengerOfSameVehicle(final Entity other) {
|
| 3683 | return this.getRootVehicle() == other.getRootVehicle();
|
| 3684 | }
|
| 3685 |
|
| 3686 | public boolean hasIndirectPassenger(final Entity entity) {
|
| 3687 | if (!entity.isPassenger()) {
|
| 3688 | return false;
|
| 3689 | }
|
| 3690 |
|
| 3691 | Entity ridden = entity.getVehicle();
|
| 3692 | return ridden == this ? true : this.hasIndirectPassenger(ridden);
|
| 3693 | }
|
| 3694 |
|
| 3695 | public final boolean isLocalInstanceAuthoritative() {
|
| 3696 | return this.level.isClientSide() ? this.isLocalClientAuthoritative() : !this.isClientAuthoritative();
|
| 3697 | }
|
| 3698 |
|
| 3699 | protected boolean isLocalClientAuthoritative() {
|
| 3700 | LivingEntity passenger = this.getControllingPassenger();
|
| 3701 | return passenger != null && passenger.isLocalClientAuthoritative();
|
| 3702 | }
|
| 3703 |
|
| 3704 | public boolean isClientAuthoritative() {
|
| 3705 | LivingEntity passenger = this.getControllingPassenger();
|
| 3706 | return passenger != null && passenger.isClientAuthoritative();
|
| 3707 | }
|
| 3708 |
|
| 3709 | public MoveSimulationType getMoveSimulationType() {
|
| 3710 | return MoveSimulationType.AUTHORITATIVE_SIDE;
|
| 3711 | }
|
| 3712 |
|
| 3713 | public final boolean canSimulateMovement() {
|
| 3714 | return switch (this.getMoveSimulationType()) {
|
| 3715 | case SERVER_AND_CLIENT -> true;
|
| 3716 | case AUTHORITATIVE_SIDE -> this.isLocalInstanceAuthoritative();
|
| 3717 | case AUTHORITATIVE_SIDE_AND_SERVER -> !this.level().isClientSide() || this.isLocalClientAuthoritative();
|
| 3718 | };
|
| 3719 | }
|
| 3720 |
|
| 3721 | public boolean isEffectiveAi() {
|
| 3722 | return this.isLocalInstanceAuthoritative();
|
| 3723 | }
|
| 3724 |
|
| 3725 | protected static Vec3 getCollisionHorizontalEscapeVector(final double colliderWidth, final double collidingWidth, final float directionDegrees) {
|
| 3726 | double distance = (colliderWidth + collidingWidth + 1.0E-5F) / 2.0;
|
| 3727 | float directionX = -Mth.sin(directionDegrees * (float) (Math.PI / 180.0));
|
| 3728 | float directionZ = Mth.cos(directionDegrees * (float) (Math.PI / 180.0));
|
| 3729 | float scale = Math.max(Math.abs(directionX), Math.abs(directionZ));
|
| 3730 | return new Vec3(directionX * distance / scale, 0.0, directionZ * distance / scale);
|
| 3731 | }
|
| 3732 |
|
| 3733 | public Vec3 getDismountLocationForPassenger(final LivingEntity passenger) {
|
| 3734 | return new Vec3(this.getX(), this.getBoundingBox().maxY, this.getZ());
|
| 3735 | }
|
| 3736 |
|
| 3737 | public @Nullable Entity getVehicle() {
|
| 3738 | return this.vehicle;
|
| 3739 | }
|
| 3740 |
|
| 3741 | public @Nullable Entity getControlledVehicle() {
|
| 3742 | return this.vehicle != null && this.vehicle.getControllingPassenger() == this ? this.vehicle : null;
|
| 3743 | }
|
| 3744 |
|
| 3745 | public PushReaction getPistonPushReaction() {
|
| 3746 | return PushReaction.PUSH_PULL;
|
| 3747 | }
|
| 3748 |
|
| 3749 | public SoundSource getSoundSource() {
|
| 3750 | return SoundSource.NEUTRAL;
|
| 3751 | }
|
| 3752 |
|
| 3753 | protected int getFireImmuneTicks() {
|
| 3754 | return 0;
|
| 3755 | }
|
| 3756 |
|
| 3757 | public CommandSourceStack createCommandSourceStackForNameResolution(final ServerLevel level) {
|
| 3758 | return new CommandSourceStack(CommandSource.NULL, this.position(), this.getRotationVector(), level, PermissionSet.NO_PERMISSIONS, level.getServer(), this);
|
| 3759 | }
|
| 3760 |
|
| 3761 | public void lookAt(final EntityAnchorArgument.Anchor anchor, final Vec3 pos) {
|
| 3762 | Vec3 from = anchor.apply(this);
|
| 3763 | double xd = pos.x - from.x;
|
| 3764 | double yd = pos.y - from.y;
|
| 3765 | double zd = pos.z - from.z;
|
| 3766 | double sd = Math.sqrt(xd * xd + zd * zd);
|
| 3767 | this.setXRot(Mth.wrapDegrees((float)(-(Mth.atan2(yd, sd) * 180.0F / (float)Math.PI))));
|
| 3768 | this.setYRot(Mth.wrapDegrees((float)(Mth.atan2(zd, xd) * 180.0F / (float)Math.PI) - 90.0F));
|
| 3769 | this.setYHeadRot(this.getYRot());
|
| 3770 | this.xRotO = this.getXRot();
|
| 3771 | this.yRotO = this.getYRot();
|
| 3772 | }
|
| 3773 |
|
| 3774 | public float getPreciseBodyRotation(final float partial) {
|
| 3775 | return Mth.lerp(partial, this.yRotO, this.yRot);
|
| 3776 | }
|
| 3777 |
|
| 3778 | public boolean touchingUnloadedChunk() {
|
| 3779 | AABB box = this.getBoundingBox().inflate(1.0);
|
| 3780 | int x0 = Mth.floor(box.minX);
|
| 3781 | int x1 = Mth.ceil(box.maxX);
|
| 3782 | int z0 = Mth.floor(box.minZ);
|
| 3783 | int z1 = Mth.ceil(box.maxZ);
|
| 3784 | return !this.level().hasChunksAt(x0, z0, x1, z1);
|
| 3785 | }
|
| 3786 |
|
| 3787 | public double getFluidHeight(final TagKey<Fluid> type) {
|
| 3788 | return this.fluidInteraction.getFluidHeight(type);
|
| 3789 | }
|
| 3790 |
|
| 3791 | public double getFluidJumpThreshold() {
|
| 3792 | return this.getEyeHeight() < 0.4 ? 0.0 : 0.4;
|
| 3793 | }
|
| 3794 |
|
| 3795 | public final float getBbWidth() {
|
| 3796 | return this.dimensions.width();
|
| 3797 | }
|
| 3798 |
|
| 3799 | public final float getBbHeight() {
|
| 3800 | return this.dimensions.height();
|
| 3801 | }
|
| 3802 |
|
| 3803 | public Packet<ClientGamePacketListener> getAddEntityPacket(final ServerEntity serverEntity) {
|
| 3804 | return new ClientboundAddEntityPacket(this, serverEntity);
|
| 3805 | }
|
| 3806 |
|
| 3807 | public EntityDimensions getDimensions(final Pose pose) {
|
| 3808 | return this.type.getDimensions();
|
| 3809 | }
|
| 3810 |
|
| 3811 | public final EntityAttachments getAttachments() {
|
| 3812 | return this.dimensions.attachments();
|
| 3813 | }
|
| 3814 |
|
| 3815 | @Override
|
| 3816 | public Vec3 position() {
|
| 3817 | return this.position;
|
| 3818 | }
|
| 3819 |
|
| 3820 | public Vec3 trackingPosition() {
|
| 3821 | return this.position();
|
| 3822 | }
|
| 3823 |
|
| 3824 | @Override
|
| 3825 | public BlockPos blockPosition() {
|
| 3826 | return this.blockPosition;
|
| 3827 | }
|
| 3828 |
|
| 3829 | public BlockState getInBlockState() {
|
| 3830 | if (this.inBlockState == null) {
|
| 3831 | this.inBlockState = this.level().getBlockState(this.blockPosition());
|
| 3832 | }
|
| 3833 |
|
| 3834 | return this.inBlockState;
|
| 3835 | }
|
| 3836 |
|
| 3837 | public ChunkPos chunkPosition() {
|
| 3838 | return this.chunkPosition;
|
| 3839 | }
|
| 3840 |
|
| 3841 | public Vec3 getDeltaMovement() {
|
| 3842 | return this.deltaMovement;
|
| 3843 | }
|
| 3844 |
|
| 3845 | public void setDeltaMovement(final Vec3 deltaMovement) {
|
| 3846 | if (deltaMovement.isFinite()) {
|
| 3847 | this.deltaMovement = deltaMovement;
|
| 3848 | }
|
| 3849 | }
|
| 3850 |
|
| 3851 | public void addDeltaMovement(final Vec3 momentum) {
|
| 3852 | if (momentum.isFinite()) {
|
| 3853 | this.setDeltaMovement(this.getDeltaMovement().add(momentum));
|
| 3854 | }
|
| 3855 | }
|
| 3856 |
|
| 3857 | public void setDeltaMovement(final double xd, final double yd, final double zd) {
|
| 3858 | this.setDeltaMovement(new Vec3(xd, yd, zd));
|
| 3859 | }
|
| 3860 |
|
| 3861 | public final int getBlockX() {
|
| 3862 | return this.blockPosition.getX();
|
| 3863 | }
|
| 3864 |
|
| 3865 | public final double getX() {
|
| 3866 | return this.position.x;
|
| 3867 | }
|
| 3868 |
|
| 3869 | public double getX(final double progress) {
|
| 3870 | return this.position.x + this.getBbWidth() * progress;
|
| 3871 | }
|
| 3872 |
|
| 3873 | public double getRandomX(final double spread) {
|
| 3874 | return this.getX((2.0 * this.random.nextDouble() - 1.0) * spread);
|
| 3875 | }
|
| 3876 |
|
| 3877 | public final int getBlockY() {
|
| 3878 | return this.blockPosition.getY();
|
| 3879 | }
|
| 3880 |
|
| 3881 | public final double getY() {
|
| 3882 | return this.position.y;
|
| 3883 | }
|
| 3884 |
|
| 3885 | public double getY(final double progress) {
|
| 3886 | return this.position.y + this.getBbHeight() * progress;
|
| 3887 | }
|
| 3888 |
|
| 3889 | public double getRandomY(final double spread) {
|
| 3890 | return this.getY((2.0 * this.random.nextDouble() - 1.0) * spread);
|
| 3891 | }
|
| 3892 |
|
| 3893 | public double getRandomY() {
|
| 3894 | return this.getY(this.random.nextDouble());
|
| 3895 | }
|
| 3896 |
|
| 3897 | public double getEyeY() {
|
| 3898 | return this.position.y + this.eyeHeight;
|
| 3899 | }
|
| 3900 |
|
| 3901 | public final int getBlockZ() {
|
| 3902 | return this.blockPosition.getZ();
|
| 3903 | }
|
| 3904 |
|
| 3905 | public final double getZ() {
|
| 3906 | return this.position.z;
|
| 3907 | }
|
| 3908 |
|
| 3909 | public double getZ(final double progress) {
|
| 3910 | return this.position.z + this.getBbWidth() * progress;
|
| 3911 | }
|
| 3912 |
|
| 3913 | public double getRandomZ(final double spread) {
|
| 3914 | return this.getZ((2.0 * this.random.nextDouble() - 1.0) * spread);
|
| 3915 | }
|
| 3916 |
|
| 3917 | public final void setPosRaw(final double x, final double y, final double z) {
|
| 3918 | if (this.position.x != x || this.position.y != y || this.position.z != z) {
|
| 3919 | this.position = new Vec3(x, y, z);
|
| 3920 | int fx = Mth.floor(x);
|
| 3921 | int fy = Mth.floor(y);
|
| 3922 | int fz = Mth.floor(z);
|
| 3923 | if (fx != this.blockPosition.getX() || fy != this.blockPosition.getY() || fz != this.blockPosition.getZ()) {
|
| 3924 | this.blockPosition = new BlockPos(fx, fy, fz);
|
| 3925 | this.inBlockState = null;
|
| 3926 | if (SectionPos.blockToSectionCoord(fx) != this.chunkPosition.x() || SectionPos.blockToSectionCoord(fz) != this.chunkPosition.z()) {
|
| 3927 | this.chunkPosition = ChunkPos.containing(this.blockPosition);
|
| 3928 | }
|
| 3929 | }
|
| 3930 |
|
| 3931 | this.levelCallback.onMove();
|
| 3932 | if (!this.firstTick && this.level instanceof ServerLevel serverLevel && !this.isRemoved()) {
|
| 3933 | if (this instanceof WaypointTransmitter waypoint && waypoint.isTransmittingWaypoint()) {
|
| 3934 | serverLevel.getWaypointManager().updateWaypoint(waypoint);
|
| 3935 | }
|
| 3936 |
|
| 3937 | if (this instanceof ServerPlayer player && player.isReceivingWaypoints() && player.connection != null) {
|
| 3938 | serverLevel.getWaypointManager().updatePlayer(player);
|
| 3939 | }
|
| 3940 | }
|
| 3941 | }
|
| 3942 | }
|
| 3943 |
|
| 3944 | public void checkDespawn() {
|
| 3945 | }
|
| 3946 |
|
| 3947 | public Vec3[] getQuadLeashHolderOffsets() {
|
| 3948 | return Leashable.createQuadLeashOffsets(this, 0.0, 0.5, 0.5, 0.0);
|
| 3949 | }
|
| 3950 |
|
| 3951 | public boolean supportQuadLeashAsHolder() {
|
| 3952 | return false;
|
| 3953 | }
|
| 3954 |
|
| 3955 | public void notifyLeashHolder(final Leashable entity) {
|
| 3956 | }
|
| 3957 |
|
| 3958 | public void notifyLeasheeRemoved(final Leashable entity) {
|
| 3959 | }
|
| 3960 |
|
| 3961 | public Vec3 getRopeHoldPosition(final float partialTickTime) {
|
| 3962 | return this.getPosition(partialTickTime).add(0.0, this.eyeHeight * 0.7, 0.0);
|
| 3963 | }
|
| 3964 |
|
| 3965 | public void recreateFromPacket(final ClientboundAddEntityPacket packet) {
|
| 3966 | int entityId = packet.getId();
|
| 3967 | double x = packet.getX();
|
| 3968 | double y = packet.getY();
|
| 3969 | double z = packet.getZ();
|
| 3970 | this.syncPacketPositionCodec(x, y, z);
|
| 3971 | this.snapTo(x, y, z, packet.getYRot(), packet.getXRot());
|
| 3972 | this.setId(entityId);
|
| 3973 | this.setUUID(packet.getUUID());
|
| 3974 | this.setDeltaMovement(packet.getMovement());
|
| 3975 | }
|
| 3976 |
|
| 3977 | public @Nullable ItemStack getPickResult() {
|
| 3978 | return null;
|
| 3979 | }
|
| 3980 |
|
| 3981 | public void setIsInPowderSnow(final boolean isInPowderSnow) {
|
| 3982 | this.isInPowderSnow = isInPowderSnow;
|
| 3983 | }
|
| 3984 |
|
| 3985 | public boolean canFreeze() {
|
| 3986 | return !this.is(EntityTypeTags.FREEZE_IMMUNE_ENTITY_TYPES);
|
| 3987 | }
|
| 3988 |
|
| 3989 | public boolean isFreezing() {
|
| 3990 | return this.getTicksFrozen() > 0;
|
| 3991 | }
|
| 3992 |
|
| 3993 | public float getYRot() {
|
| 3994 | return this.yRot;
|
| 3995 | }
|
| 3996 |
|
| 3997 | @Override
|
| 3998 | public float getVisualRotationYInDegrees() {
|
| 3999 | return this.getYRot();
|
| 4000 | }
|
| 4001 |
|
| 4002 | public void setYRot(final float yRot) {
|
| 4003 | if (!Float.isFinite(yRot)) {
|
| 4004 | Util.logAndPauseIfInIde("Invalid entity rotation: " + yRot + ", discarding.");
|
| 4005 | } else {
|
| 4006 | this.yRot = yRot;
|
| 4007 | }
|
| 4008 | }
|
| 4009 |
|
| 4010 | public float getXRot() {
|
| 4011 | return this.xRot;
|
| 4012 | }
|
| 4013 |
|
| 4014 | public void setXRot(final float xRot) {
|
| 4015 | if (!Float.isFinite(xRot)) {
|
| 4016 | Util.logAndPauseIfInIde("Invalid entity rotation: " + xRot + ", discarding.");
|
| 4017 | } else {
|
| 4018 | this.xRot = Math.clamp(xRot % 360.0F, -90.0F, 90.0F);
|
| 4019 | }
|
| 4020 | }
|
| 4021 |
|
| 4022 | public PositionAndRotation storePositionAndRotation() {
|
| 4023 | return PositionAndRotation.of(this.position, this.yRot, this.xRot);
|
| 4024 | }
|
| 4025 |
|
| 4026 | public PositionAndRotation getClientPositionAndRotation() {
|
| 4027 | return Objects.requireNonNullElseGet(this.interpolationHandler.target(), this::storePositionAndRotation);
|
| 4028 | }
|
| 4029 |
|
| 4030 | public Vec3 getClientPosition() {
|
| 4031 | PositionAndRotation target = this.interpolationHandler.target();
|
| 4032 | return target != null ? target.position() : this.position;
|
| 4033 | }
|
| 4034 |
|
| 4035 | public boolean canSprint() {
|
| 4036 | return false;
|
| 4037 | }
|
| 4038 |
|
| 4039 | public float maxUpStep() {
|
| 4040 | return 0.0F;
|
| 4041 | }
|
| 4042 |
|
| 4043 | public void onExplosionHit(final @Nullable Entity explosionCausedBy) {
|
| 4044 | }
|
| 4045 |
|
| 4046 | @Override
|
| 4047 | public final boolean isRemoved() {
|
| 4048 | return this.removalReason != null;
|
| 4049 | }
|
| 4050 |
|
| 4051 | public Entity.@Nullable RemovalReason getRemovalReason() {
|
| 4052 | return this.removalReason;
|
| 4053 | }
|
| 4054 |
|
| 4055 | @Override
|
| 4056 | public final void setRemoved(final Entity.RemovalReason reason) {
|
| 4057 | if (this.removalReason == null) {
|
| 4058 | this.removalReason = reason;
|
| 4059 | }
|
| 4060 |
|
| 4061 | if (this.removalReason.shouldDestroy()) {
|
| 4062 | this.stopRiding();
|
| 4063 | }
|
| 4064 |
|
| 4065 | this.getPassengers().forEach(Entity::stopRiding);
|
| 4066 | this.levelCallback.onRemove(reason);
|
| 4067 | this.onRemoval(reason);
|
| 4068 | }
|
| 4069 |
|
| 4070 | protected void unsetRemoved() {
|
| 4071 | this.removalReason = null;
|
| 4072 | }
|
| 4073 |
|
| 4074 | @Override
|
| 4075 | public void setLevelCallback(final EntityInLevelCallback levelCallback) {
|
| 4076 | this.levelCallback = levelCallback;
|
| 4077 | }
|
| 4078 |
|
| 4079 | @Override
|
| 4080 | public boolean shouldBeSaved() {
|
| 4081 | if (this.removalReason != null && !this.removalReason.shouldSave()) {
|
| 4082 | return false;
|
| 4083 | } else {
|
| 4084 | return this.isPassenger() ? false : !this.isVehicle() || !this.hasExactlyOnePlayerPassenger();
|
| 4085 | }
|
| 4086 | }
|
| 4087 |
|
| 4088 | @Override
|
| 4089 | public boolean isAlwaysTicking() {
|
| 4090 | return false;
|
| 4091 | }
|
| 4092 |
|
| 4093 | public boolean mayInteract(final ServerLevel level, final BlockPos pos) {
|
| 4094 | return true;
|
| 4095 | }
|
| 4096 |
|
| 4097 | public boolean isFlyingVehicle() {
|
| 4098 | return false;
|
| 4099 | }
|
| 4100 |
|
| 4101 | @Override
|
| 4102 | public Level level() {
|
| 4103 | return this.level;
|
| 4104 | }
|
| 4105 |
|
| 4106 | protected void setLevel(final Level level) {
|
| 4107 | this.level = level;
|
| 4108 | }
|
| 4109 |
|
| 4110 | public DamageSources damageSources() {
|
| 4111 | return this.level().damageSources();
|
| 4112 | }
|
| 4113 |
|
| 4114 | public RegistryAccess registryAccess() {
|
| 4115 | return this.level().registryAccess();
|
| 4116 | }
|
| 4117 |
|
| 4118 | protected void lerpPositionAndRotationStep(
|
| 4119 | final int stepsToTarget, final double targetX, final double targetY, final double targetZ, final double targetYRot, final double targetXRot
|
| 4120 | ) {
|
| 4121 | double alpha = 1.0 / stepsToTarget;
|
| 4122 | double x = Mth.lerp(alpha, this.getX(), targetX);
|
| 4123 | double y = Mth.lerp(alpha, this.getY(), targetY);
|
| 4124 | double z = Mth.lerp(alpha, this.getZ(), targetZ);
|
| 4125 | float yRot = (float)Mth.rotLerp(alpha, this.getYRot(), targetYRot);
|
| 4126 | float xRot = (float)Mth.lerp(alpha, this.getXRot(), targetXRot);
|
| 4127 | this.setPos(x, y, z);
|
| 4128 | this.setRot(yRot, xRot);
|
| 4129 | }
|
| 4130 |
|
| 4131 | public RandomSource getRandom() {
|
| 4132 | return this.random;
|
| 4133 | }
|
| 4134 |
|
| 4135 | public Vec3 getKnownMovement() {
|
| 4136 | return this.getControllingPassenger() instanceof Player controller && this.isAlive() ? controller.getKnownMovement() : this.getDeltaMovement();
|
| 4137 | }
|
| 4138 |
|
| 4139 | public Vec3 getKnownSpeed() {
|
| 4140 | return this.getControllingPassenger() instanceof Player controller && this.isAlive() ? controller.getKnownSpeed() : this.lastKnownSpeed;
|
| 4141 | }
|
| 4142 |
|
| 4143 | public @Nullable ItemStack getWeaponItem() {
|
| 4144 | return null;
|
| 4145 | }
|
| 4146 |
|
| 4147 | public Optional<ResourceKey<LootTable>> getLootTable() {
|
| 4148 | return this.type.getDefaultLootTable();
|
| 4149 | }
|
| 4150 |
|
| 4151 | protected void applyImplicitComponents(final DataComponentGetter components) {
|
| 4152 | this.applyImplicitComponentIfPresent(components, DataComponents.CUSTOM_NAME);
|
| 4153 | this.applyImplicitComponentIfPresent(components, DataComponents.CUSTOM_DATA);
|
| 4154 | }
|
| 4155 |
|
| 4156 | public final void applyComponentsFromItemStack(final ItemStack stack) {
|
| 4157 | this.applyImplicitComponents(stack.getComponents());
|
| 4158 | }
|
| 4159 |
|
| 4160 | @Override
|
| 4161 | public <T> @Nullable T get(final DataComponentType<? extends T> type) {
|
| 4162 | if (type == DataComponents.CUSTOM_NAME) {
|
| 4163 | return castComponentValue((DataComponentType<T>)type, this.getCustomName());
|
| 4164 | } else {
|
| 4165 | return type == DataComponents.CUSTOM_DATA ? castComponentValue((DataComponentType<T>)type, this.customData) : this.typeHolder().components().get(type);
|
| 4166 | }
|
| 4167 | }
|
| 4168 |
|
| 4169 | @Contract("_,!null->!null;_,_->_")
|
| 4170 | protected static <T> @Nullable T castComponentValue(final DataComponentType<T> type, final @Nullable Object value) {
|
| 4171 | return (T)value;
|
| 4172 | }
|
| 4173 |
|
| 4174 | public <T> void setComponent(final DataComponentType<T> type, final T value) {
|
| 4175 | this.applyImplicitComponent(type, value);
|
| 4176 | }
|
| 4177 |
|
| 4178 | protected <T> boolean applyImplicitComponent(final DataComponentType<T> type, final T value) {
|
| 4179 | if (type == DataComponents.CUSTOM_NAME) {
|
| 4180 | this.setCustomName(castComponentValue(DataComponents.CUSTOM_NAME, value));
|
| 4181 | return true;
|
| 4182 | } else if (type == DataComponents.CUSTOM_DATA) {
|
| 4183 | this.customData = castComponentValue(DataComponents.CUSTOM_DATA, value);
|
| 4184 | return true;
|
| 4185 | } else {
|
| 4186 | return false;
|
| 4187 | }
|
| 4188 | }
|
| 4189 |
|
| 4190 | protected <T> boolean applyImplicitComponentIfPresent(final DataComponentGetter components, final DataComponentType<T> type) {
|
| 4191 | T value = components.get(type);
|
| 4192 | return value != null ? this.applyImplicitComponent(type, value) : false;
|
| 4193 | }
|
| 4194 |
|
| 4195 | public ProblemReporter.PathElement problemPath() {
|
| 4196 | return new Entity.EntityPathElement(this);
|
| 4197 | }
|
| 4198 |
|
| 4199 | @Override
|
| 4200 | public void registerDebugValues(final ServerLevel level, final DebugValueSource.Registration registration) {
|
| 4201 | }
|
| 4202 |
|
| 4203 | public @Nullable AABB getFluidInteractionBox() {
|
| 4204 | double margin = 0.001;
|
| 4205 | AABB box = this.getBoundingBox().deflate(0.001);
|
| 4206 | Entity vehicle = this.getVehicle();
|
| 4207 | if (vehicle != null) {
|
| 4208 | box = vehicle.modifyPassengerFluidInteractionBox(box);
|
| 4209 | }
|
| 4210 |
|
| 4211 | return box;
|
| 4212 | }
|
| 4213 |
|
| 4214 | public void setInvulnerableTime(final int invulnerableTime) {
|
| 4215 | this.invulnerableTime = invulnerableTime;
|
| 4216 | }
|
| 4217 |
|
| 4218 | public int getInvulnerableTime() {
|
| 4219 | return this.invulnerableTime;
|
| 4220 | }
|
| 4221 |
|
| 4222 | protected @Nullable AABB modifyPassengerFluidInteractionBox(final AABB passengerBox) {
|
| 4223 | return passengerBox;
|
| 4224 | }
|
| 4225 |
|
| 4226 | private record EntityPathElement(Entity entity) implements ProblemReporter.PathElement {
|
| 4227 | @Override
|
| 4228 | public String get() {
|
| 4229 | return this.entity.toString();
|
| 4230 | }
|
| 4231 | }
|
| 4232 |
|
| 4233 | @Retention(RetentionPolicy.CLASS)
|
| 4234 | @Target(ElementType.TYPE_USE)
|
| 4235 | public @interface Flags {
|
| 4236 | }
|
| 4237 |
|
| 4238 | @FunctionalInterface
|
| 4239 | public interface MoveFunction {
|
| 4240 | void accept(Entity target, double x, double y, double z);
|
| 4241 | }
|
| 4242 |
|
| 4243 | private record Movement(Vec3 from, Vec3 to, Optional<Vec3> axisDependentOriginalMovement) {
|
| 4244 | public Movement(final Vec3 from, final Vec3 to, final Vec3 axisDependentOriginalMovement) {
|
| 4245 | this(from, to, Optional.of(axisDependentOriginalMovement));
|
| 4246 | }
|
| 4247 |
|
| 4248 | public Movement(final Vec3 from, final Vec3 to) {
|
| 4249 | this(from, to, Optional.empty());
|
| 4250 | }
|
| 4251 | }
|
| 4252 |
|
| 4253 | public enum MovementEmission {
|
| 4254 | NONE(false, false),
|
| 4255 | SOUNDS(true, false),
|
| 4256 | EVENTS(false, true),
|
| 4257 | ALL(true, true);
|
| 4258 |
|
| 4259 | private final boolean sounds;
|
| 4260 | private final boolean events;
|
| 4261 |
|
| 4262 | MovementEmission(final boolean sounds, final boolean events) {
|
| 4263 | this.sounds = sounds;
|
| 4264 | this.events = events;
|
| 4265 | }
|
| 4266 |
|
| 4267 | public boolean emitsAnything() {
|
| 4268 | return this.events || this.sounds;
|
| 4269 | }
|
| 4270 |
|
| 4271 | public boolean emitsEvents() {
|
| 4272 | return this.events;
|
| 4273 | }
|
| 4274 |
|
| 4275 | public boolean emitsSounds() {
|
| 4276 | return this.sounds;
|
| 4277 | }
|
| 4278 | }
|
| 4279 |
|
| 4280 | public enum RemovalReason {
|
| 4281 | KILLED(true, false),
|
| 4282 | DISCARDED(true, false),
|
| 4283 | UNLOADED_TO_CHUNK(false, true),
|
| 4284 | UNLOADED_WITH_PLAYER(false, false),
|
| 4285 | CHANGED_DIMENSION(false, false);
|
| 4286 |
|
| 4287 | private final boolean destroy;
|
| 4288 | private final boolean save;
|
| 4289 |
|
| 4290 | RemovalReason(final boolean destroy, final boolean save) {
|
| 4291 | this.destroy = destroy;
|
| 4292 | this.save = save;
|
| 4293 | }
|
| 4294 |
|
| 4295 | public boolean shouldDestroy() {
|
| 4296 | return this.destroy;
|
| 4297 | }
|
| 4298 |
|
| 4299 | public boolean shouldSave() {
|
| 4300 | return this.save;
|
| 4301 | }
|
| 4302 | }
|
| 4303 | }
|
| 4304 |
|