Use a Shared Random for Entities

Reduces memory usage and provides ensures more randomness, Especially since a lot of garbage entity objects get created.
This commit is contained in:
Aikar 2016-03-22 00:33:47 -04:00
parent becb30e9e6
commit d989bc5d17
2 changed files with 196 additions and 104 deletions

View File

@ -18,7 +18,7 @@
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.FenceGateBlock; import net.minecraft.world.level.block.FenceGateBlock;
@@ -138,9 +138,67 @@ @@ -138,9 +138,140 @@
import net.minecraft.world.scores.ScoreHolder; import net.minecraft.world.scores.ScoreHolder;
import net.minecraft.world.scores.Team; import net.minecraft.world.scores.Team;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -61,13 +61,86 @@
+// CraftBukkit end +// CraftBukkit end
public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess, ScoreHolder { public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess, ScoreHolder {
+
+ // CraftBukkit start + // CraftBukkit start
+ private static final int CURRENT_LEVEL = 2; + private static final int CURRENT_LEVEL = 2;
+ static boolean isLevelAtLeast(CompoundTag tag, int level) { + static boolean isLevelAtLeast(CompoundTag tag, int level) {
+ return tag.contains("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level; + return tag.contains("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level;
+ } + }
+ +
+ // Paper start - Share random for entities to make them more random
+ public static RandomSource SHARED_RANDOM = new RandomRandomSource();
+ private static final class RandomRandomSource extends java.util.Random implements net.minecraft.world.level.levelgen.BitRandomSource {
+ private boolean locked = false;
+
+ @Override
+ public synchronized void setSeed(long seed) {
+ if (locked) {
+ LOGGER.error("Ignoring setSeed on Entity.SHARED_RANDOM", new Throwable());
+ } else {
+ super.setSeed(seed);
+ locked = true;
+ }
+ }
+
+ @Override
+ public RandomSource fork() {
+ return new net.minecraft.world.level.levelgen.LegacyRandomSource(this.nextLong());
+ }
+
+ @Override
+ public net.minecraft.world.level.levelgen.PositionalRandomFactory forkPositional() {
+ return new net.minecraft.world.level.levelgen.LegacyRandomSource.LegacyPositionalRandomFactory(this.nextLong());
+ }
+
+ // these below are added to fix reobf issues that I don't wanna deal with right now
+ @Override
+ public int next(int bits) {
+ return super.next(bits);
+ }
+
+ @Override
+ public int nextInt(int origin, int bound) {
+ return net.minecraft.world.level.levelgen.BitRandomSource.super.nextInt(origin, bound);
+ }
+
+ @Override
+ public long nextLong() {
+ return net.minecraft.world.level.levelgen.BitRandomSource.super.nextLong();
+ }
+
+ @Override
+ public int nextInt() {
+ return net.minecraft.world.level.levelgen.BitRandomSource.super.nextInt();
+ }
+
+ @Override
+ public int nextInt(int bound) {
+ return net.minecraft.world.level.levelgen.BitRandomSource.super.nextInt(bound);
+ }
+
+ @Override
+ public boolean nextBoolean() {
+ return net.minecraft.world.level.levelgen.BitRandomSource.super.nextBoolean();
+ }
+
+ @Override
+ public float nextFloat() {
+ return net.minecraft.world.level.levelgen.BitRandomSource.super.nextFloat();
+ }
+
+ @Override
+ public double nextDouble() {
+ return net.minecraft.world.level.levelgen.BitRandomSource.super.nextDouble();
+ }
+
+ @Override
+ public double nextGaussian() {
+ return super.nextGaussian();
+ }
+ }
+ // Paper end - Share random for entities to make them more random
+
+ private CraftEntity bukkitEntity; + private CraftEntity bukkitEntity;
+ +
+ public CraftEntity getBukkitEntity() { + public CraftEntity getBukkitEntity() {
@ -76,7 +149,7 @@
+ } + }
+ return this.bukkitEntity; + return this.bukkitEntity;
+ } + }
+
+ // CraftBukkit - SPIGOT-6907: re-implement LivingEntity#setMaximumAir() + // CraftBukkit - SPIGOT-6907: re-implement LivingEntity#setMaximumAir()
+ public int getDefaultMaxAirSupply() { + public int getDefaultMaxAirSupply() {
+ return Entity.TOTAL_AIR_SUPPLY; + return Entity.TOTAL_AIR_SUPPLY;
@ -86,7 +159,7 @@
private static final Logger LOGGER = LogUtils.getLogger(); private static final Logger LOGGER = LogUtils.getLogger();
public static final String ID_TAG = "id"; public static final String ID_TAG = "id";
public static final String PASSENGERS_TAG = "Passengers"; public static final String PASSENGERS_TAG = "Passengers";
@@ -224,7 +282,7 @@ @@ -224,7 +355,7 @@
private static final EntityDataAccessor<Boolean> DATA_CUSTOM_NAME_VISIBLE = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN); private static final EntityDataAccessor<Boolean> DATA_CUSTOM_NAME_VISIBLE = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN);
private static final EntityDataAccessor<Boolean> DATA_SILENT = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN); private static final EntityDataAccessor<Boolean> DATA_SILENT = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN);
private static final EntityDataAccessor<Boolean> DATA_NO_GRAVITY = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN); private static final EntityDataAccessor<Boolean> DATA_NO_GRAVITY = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN);
@ -95,7 +168,7 @@
private static final EntityDataAccessor<Integer> DATA_TICKS_FROZEN = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.INT); private static final EntityDataAccessor<Integer> DATA_TICKS_FROZEN = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.INT);
private EntityInLevelCallback levelCallback; private EntityInLevelCallback levelCallback;
private final VecDeltaCodec packetPositionCodec; private final VecDeltaCodec packetPositionCodec;
@@ -253,7 +311,62 @@ @@ -253,7 +384,62 @@
private final List<Entity.Movement> movementThisTick; private final List<Entity.Movement> movementThisTick;
private final Set<BlockState> blocksInside; private final Set<BlockState> blocksInside;
private final LongSet visitedBlocks; private final LongSet visitedBlocks;
@ -130,7 +203,7 @@
+ this.origin = location.toVector(); + this.origin = location.toVector();
+ this.originWorld = location.getWorld().getUID(); + this.originWorld = location.getWorld().getUID();
+ } + }
+
+ @javax.annotation.Nullable + @javax.annotation.Nullable
+ public org.bukkit.util.Vector getOriginVector() { + public org.bukkit.util.Vector getOriginVector() {
+ return this.origin != null ? this.origin.clone() : null; + return this.origin != null ? this.origin.clone() : null;
@ -144,7 +217,7 @@
+ public float getBukkitYaw() { + public float getBukkitYaw() {
+ return this.yRot; + return this.yRot;
+ } + }
+
+ public boolean isChunkLoaded() { + public boolean isChunkLoaded() {
+ return this.level.hasChunk((int) Math.floor(this.getX()) >> 4, (int) Math.floor(this.getZ()) >> 4); + return this.level.hasChunk((int) Math.floor(this.getX()) >> 4, (int) Math.floor(this.getZ()) >> 4);
+ } + }
@ -158,7 +231,16 @@
public Entity(EntityType<?> type, Level world) { public Entity(EntityType<?> type, Level world) {
this.id = Entity.ENTITY_COUNTER.incrementAndGet(); this.id = Entity.ENTITY_COUNTER.incrementAndGet();
this.passengers = ImmutableList.of(); this.passengers = ImmutableList.of();
@@ -284,6 +397,13 @@ @@ -261,7 +447,7 @@
this.bb = Entity.INITIAL_AABB;
this.stuckSpeedMultiplier = Vec3.ZERO;
this.nextStep = 1.0F;
- this.random = RandomSource.create();
+ this.random = SHARED_RANDOM; // Paper - Share random for entities to make them more random
this.remainingFireTicks = -this.getFireImmuneTicks();
this.fluidHeight = new Object2DoubleArrayMap(2);
this.fluidOnEyes = new HashSet();
@@ -284,6 +470,13 @@
this.position = Vec3.ZERO; this.position = Vec3.ZERO;
this.blockPosition = BlockPos.ZERO; this.blockPosition = BlockPos.ZERO;
this.chunkPosition = ChunkPos.ZERO; this.chunkPosition = ChunkPos.ZERO;
@ -172,7 +254,7 @@
SynchedEntityData.Builder datawatcher_a = new SynchedEntityData.Builder(this); SynchedEntityData.Builder datawatcher_a = new SynchedEntityData.Builder(this);
datawatcher_a.define(Entity.DATA_SHARED_FLAGS_ID, (byte) 0); datawatcher_a.define(Entity.DATA_SHARED_FLAGS_ID, (byte) 0);
@@ -292,7 +412,7 @@ @@ -292,7 +485,7 @@
datawatcher_a.define(Entity.DATA_CUSTOM_NAME, Optional.empty()); datawatcher_a.define(Entity.DATA_CUSTOM_NAME, Optional.empty());
datawatcher_a.define(Entity.DATA_SILENT, false); datawatcher_a.define(Entity.DATA_SILENT, false);
datawatcher_a.define(Entity.DATA_NO_GRAVITY, false); datawatcher_a.define(Entity.DATA_NO_GRAVITY, false);
@ -181,7 +263,7 @@
datawatcher_a.define(Entity.DATA_TICKS_FROZEN, 0); datawatcher_a.define(Entity.DATA_TICKS_FROZEN, 0);
this.defineSynchedData(datawatcher_a); this.defineSynchedData(datawatcher_a);
this.entityData = datawatcher_a.build(); this.entityData = datawatcher_a.build();
@@ -362,20 +482,36 @@ @@ -362,19 +555,35 @@
} }
public void kill(ServerLevel world) { public void kill(ServerLevel world) {
@ -205,8 +287,8 @@
public SynchedEntityData getEntityData() { public SynchedEntityData getEntityData() {
return this.entityData; return this.entityData;
} + }
+
+ // CraftBukkit start + // CraftBukkit start
+ public void refreshEntityData(ServerPlayer to) { + public void refreshEntityData(ServerPlayer to) {
+ List<SynchedEntityData.DataValue<?>> list = this.getEntityData().getNonDefaultValues(); + List<SynchedEntityData.DataValue<?>> list = this.getEntityData().getNonDefaultValues();
@ -214,13 +296,12 @@
+ if (list != null) { + if (list != null) {
+ to.connection.send(new ClientboundSetEntityDataPacket(this.getId(), list)); + to.connection.send(new ClientboundSetEntityDataPacket(this.getId(), list));
+ } + }
+ } }
+ // CraftBukkit end + // CraftBukkit end
+
public boolean equals(Object object) { public boolean equals(Object object) {
return object instanceof Entity ? ((Entity) object).id == this.id : false; return object instanceof Entity ? ((Entity) object).id == this.id : false;
} @@ -385,22 +594,34 @@
@@ -385,22 +521,34 @@
} }
public void remove(Entity.RemovalReason reason) { public void remove(Entity.RemovalReason reason) {
@ -260,7 +341,7 @@
return this.getPose() == pose; return this.getPose() == pose;
} }
@@ -417,6 +565,33 @@ @@ -417,6 +638,33 @@
} }
public void setRot(float yaw, float pitch) { public void setRot(float yaw, float pitch) {
@ -294,23 +375,24 @@
this.setYRot(yaw % 360.0F); this.setYRot(yaw % 360.0F);
this.setXRot(pitch % 360.0F); this.setXRot(pitch % 360.0F);
} }
@@ -462,6 +637,15 @@ @@ -460,7 +708,16 @@
this.baseTick();
}
public void tick() {
this.baseTick();
+ }
+
+ // CraftBukkit start + // CraftBukkit start
+ public void postTick() { + public void postTick() {
+ // No clean way to break out of ticking once the entity has been copied to a new world, so instead we move the portalling later in the tick cycle + // No clean way to break out of ticking once the entity has been copied to a new world, so instead we move the portalling later in the tick cycle
+ if (!(this instanceof ServerPlayer)) { + if (!(this instanceof ServerPlayer)) {
+ this.handlePortal(); + this.handlePortal();
+ } + }
+ } }
+ // CraftBukkit end + // CraftBukkit end
+
public void baseTick() { public void baseTick() {
ProfilerFiller gameprofilerfiller = Profiler.get(); ProfilerFiller gameprofilerfiller = Profiler.get();
@@ -475,7 +732,7 @@
@@ -475,7 +659,7 @@
--this.boardingCooldown; --this.boardingCooldown;
} }
@ -319,7 +401,7 @@
if (this.canSpawnSprintParticle()) { if (this.canSpawnSprintParticle()) {
this.spawnSprintParticle(); this.spawnSprintParticle();
} }
@@ -514,6 +698,10 @@ @@ -514,6 +771,10 @@
if (this.isInLava()) { if (this.isInLava()) {
this.lavaHurt(); this.lavaHurt();
this.fallDistance *= 0.5F; this.fallDistance *= 0.5F;
@ -330,7 +412,7 @@
} }
this.checkBelowWorld(); this.checkBelowWorld();
@@ -525,7 +713,7 @@ @@ -525,7 +786,7 @@
world = this.level(); world = this.level();
if (world instanceof ServerLevel worldserver) { if (world instanceof ServerLevel worldserver) {
if (this instanceof Leashable) { if (this instanceof Leashable) {
@ -339,7 +421,7 @@
} }
} }
@@ -537,7 +725,11 @@ @@ -537,7 +798,11 @@
} }
public void checkBelowWorld() { public void checkBelowWorld() {
@ -352,7 +434,7 @@
this.onBelowWorld(); this.onBelowWorld();
} }
@@ -568,15 +760,32 @@ @@ -568,15 +833,32 @@
public void lavaHurt() { public void lavaHurt() {
if (!this.fireImmune()) { if (!this.fireImmune()) {
@ -387,7 +469,7 @@
} }
} }
@@ -587,7 +796,23 @@ @@ -587,7 +869,23 @@
} }
public final void igniteForSeconds(float seconds) { public final void igniteForSeconds(float seconds) {
@ -412,7 +494,7 @@
} }
public void igniteForTicks(int ticks) { public void igniteForTicks(int ticks) {
@@ -610,7 +835,7 @@ @@ -610,7 +908,7 @@
} }
protected void onBelowWorld() { protected void onBelowWorld() {
@ -421,13 +503,10 @@
} }
public boolean isFree(double offsetX, double offsetY, double offsetZ) { public boolean isFree(double offsetX, double offsetY, double offsetZ) {
@@ -747,8 +972,30 @@ @@ -750,6 +1048,28 @@
}
}
if (movement.y != vec3d1.y) {
block.updateEntityMovementAfterFallOn(this.level(), this);
+ }
+ }
+
+ // CraftBukkit start + // CraftBukkit start
+ if (this.horizontalCollision && this.getBukkitEntity() instanceof Vehicle) { + if (this.horizontalCollision && this.getBukkitEntity() instanceof Vehicle) {
+ Vehicle vehicle = (Vehicle) this.getBukkitEntity(); + Vehicle vehicle = (Vehicle) this.getBukkitEntity();
@ -446,13 +525,14 @@
+ if (!bl.getType().isAir()) { + if (!bl.getType().isAir()) {
+ VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, bl); + VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, bl);
+ this.level.getCraftServer().getPluginManager().callEvent(event); + this.level.getCraftServer().getPluginManager().callEvent(event);
} + }
} + }
+ // CraftBukkit end + // CraftBukkit end
+
if (!this.level().isClientSide() || this.isControlledByLocalInstance()) { if (!this.level().isClientSide() || this.isControlledByLocalInstance()) {
Entity.MovementEmission entity_movementemission = this.getMovementEmission(); Entity.MovementEmission entity_movementemission = this.getMovementEmission();
@@ -1131,8 +1378,22 @@
@@ -1131,8 +1451,22 @@
protected SoundEvent getSwimHighSpeedSplashSound() { protected SoundEvent getSwimHighSpeedSplashSound() {
return SoundEvents.GENERIC_SPLASH; return SoundEvents.GENERIC_SPLASH;
@ -461,12 +541,12 @@
+ // CraftBukkit start - Add delegate methods + // CraftBukkit start - Add delegate methods
+ public SoundEvent getSwimSound0() { + public SoundEvent getSwimSound0() {
+ return this.getSwimSound(); + return this.getSwimSound();
+ }
+
+ public SoundEvent getSwimSplashSound0() {
+ return this.getSwimSplashSound();
} }
+ public SoundEvent getSwimSplashSound0() {
+ return this.getSwimSplashSound();
+ }
+
+ public SoundEvent getSwimHighSpeedSplashSound0() { + public SoundEvent getSwimHighSpeedSplashSound0() {
+ return this.getSwimHighSpeedSplashSound(); + return this.getSwimHighSpeedSplashSound();
+ } + }
@ -475,7 +555,7 @@
public void recordMovementThroughBlocks(Vec3 oldPos, Vec3 newPos) { public void recordMovementThroughBlocks(Vec3 oldPos, Vec3 newPos) {
this.movementThisTick.add(new Entity.Movement(oldPos, newPos)); this.movementThisTick.add(new Entity.Movement(oldPos, newPos));
} }
@@ -1609,6 +1870,7 @@ @@ -1609,6 +1943,7 @@
this.yo = y; this.yo = y;
this.zo = d4; this.zo = d4;
this.setPos(d3, y, d4); this.setPos(d3, y, d4);
@ -483,7 +563,7 @@
} }
public void moveTo(Vec3 pos) { public void moveTo(Vec3 pos) {
@@ -1859,7 +2121,13 @@ @@ -1859,7 +2194,13 @@
public boolean isPushable() { public boolean isPushable() {
return false; return false;
@ -497,7 +577,7 @@
public void awardKillScore(Entity entityKilled, DamageSource damageSource) { public void awardKillScore(Entity entityKilled, DamageSource damageSource) {
if (entityKilled instanceof ServerPlayer) { if (entityKilled instanceof ServerPlayer) {
@@ -1889,16 +2157,22 @@ @@ -1889,16 +2230,22 @@
} }
public boolean saveAsPassenger(CompoundTag nbt) { public boolean saveAsPassenger(CompoundTag nbt) {
@ -523,7 +603,7 @@
return true; return true;
} }
} }
@@ -1909,54 +2183,98 @@ @@ -1909,54 +2256,98 @@
} }
public CompoundTag saveWithoutId(CompoundTag nbt) { public CompoundTag saveWithoutId(CompoundTag nbt) {
@ -642,7 +722,7 @@
} }
ListTag nbttaglist; ListTag nbttaglist;
@@ -1972,10 +2290,10 @@ @@ -1972,10 +2363,10 @@
nbttaglist.add(StringTag.valueOf(s)); nbttaglist.add(StringTag.valueOf(s));
} }
@ -655,7 +735,7 @@
if (this.isVehicle()) { if (this.isVehicle()) {
nbttaglist = new ListTag(); nbttaglist = new ListTag();
iterator = this.getPassengers().iterator(); iterator = this.getPassengers().iterator();
@@ -1984,17 +2302,31 @@ @@ -1984,17 +2375,31 @@
Entity entity = (Entity) iterator.next(); Entity entity = (Entity) iterator.next();
CompoundTag nbttagcompound1 = new CompoundTag(); CompoundTag nbttagcompound1 = new CompoundTag();
@ -690,11 +770,10 @@
} catch (Throwable throwable) { } catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT"); CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being saved"); CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being saved");
@@ -2079,7 +2411,65 @@ @@ -2080,6 +2485,64 @@
}
} else { } else {
throw new IllegalStateException("Entity has invalid position"); throw new IllegalStateException("Entity has invalid position");
+ } }
+ +
+ // CraftBukkit start + // CraftBukkit start
+ // Spigot start + // Spigot start
@ -730,7 +809,7 @@
+ } + }
+ +
+ ((ServerPlayer) this).setLevel(bworld == null ? null : ((CraftWorld) bworld).getHandle()); + ((ServerPlayer) this).setLevel(bworld == null ? null : ((CraftWorld) bworld).getHandle());
} + }
+ this.getBukkitEntity().readBukkitValues(nbt); + this.getBukkitEntity().readBukkitValues(nbt);
+ if (nbt.contains("Bukkit.invisible")) { + if (nbt.contains("Bukkit.invisible")) {
+ boolean bukkitInvisible = nbt.getBoolean("Bukkit.invisible"); + boolean bukkitInvisible = nbt.getBoolean("Bukkit.invisible");
@ -756,7 +835,7 @@
} catch (Throwable throwable) { } catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT"); CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being loaded"); CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being loaded");
@@ -2101,6 +2491,12 @@ @@ -2101,6 +2564,12 @@
return entitytypes.canSerialize() && minecraftkey != null ? minecraftkey.toString() : null; return entitytypes.canSerialize() && minecraftkey != null ? minecraftkey.toString() : null;
} }
@ -769,7 +848,7 @@
protected abstract void readAdditionalSaveData(CompoundTag nbt); protected abstract void readAdditionalSaveData(CompoundTag nbt);
protected abstract void addAdditionalSaveData(CompoundTag nbt); protected abstract void addAdditionalSaveData(CompoundTag nbt);
@@ -2153,9 +2549,22 @@ @@ -2153,9 +2622,22 @@
if (stack.isEmpty()) { if (stack.isEmpty()) {
return null; return null;
} else { } else {
@ -792,7 +871,7 @@
world.addFreshEntity(entityitem); world.addFreshEntity(entityitem);
return entityitem; return entityitem;
} }
@@ -2184,6 +2593,12 @@ @@ -2184,6 +2666,12 @@
if (this.isAlive() && this instanceof Leashable leashable) { if (this.isAlive() && this instanceof Leashable leashable) {
if (leashable.getLeashHolder() == player) { if (leashable.getLeashHolder() == player) {
if (!this.level().isClientSide()) { if (!this.level().isClientSide()) {
@ -805,7 +884,7 @@
if (player.hasInfiniteMaterials()) { if (player.hasInfiniteMaterials()) {
leashable.removeLeash(); leashable.removeLeash();
} else { } else {
@@ -2200,6 +2615,13 @@ @@ -2200,6 +2688,13 @@
if (itemstack.is(Items.LEAD) && leashable.canHaveALeashAttachedToIt()) { if (itemstack.is(Items.LEAD) && leashable.canHaveALeashAttachedToIt()) {
if (!this.level().isClientSide()) { if (!this.level().isClientSide()) {
@ -819,7 +898,7 @@
leashable.setLeashedTo(player, true); leashable.setLeashedTo(player, true);
} }
@@ -2265,7 +2687,7 @@ @@ -2265,7 +2760,7 @@
} }
public boolean showVehicleHealth() { public boolean showVehicleHealth() {
@ -828,7 +907,7 @@
} }
public boolean startRiding(Entity entity, boolean force) { public boolean startRiding(Entity entity, boolean force) {
@@ -2273,7 +2695,7 @@ @@ -2273,7 +2768,7 @@
return false; return false;
} else if (!entity.couldAcceptPassenger()) { } else if (!entity.couldAcceptPassenger()) {
return false; return false;
@ -837,7 +916,7 @@
return false; return false;
} else { } else {
for (Entity entity1 = entity; entity1.vehicle != null; entity1 = entity1.vehicle) { for (Entity entity1 = entity; entity1.vehicle != null; entity1 = entity1.vehicle) {
@@ -2285,11 +2707,32 @@ @@ -2285,11 +2780,32 @@
if (!force && (!this.canRide(entity) || !entity.canAddPassenger(this))) { if (!force && (!this.canRide(entity) || !entity.canAddPassenger(this))) {
return false; return false;
} else { } else {
@ -871,7 +950,7 @@
this.vehicle = entity; this.vehicle = entity;
this.vehicle.addPassenger(this); this.vehicle.addPassenger(this);
entity.getIndirectPassengersStream().filter((entity2) -> { entity.getIndirectPassengersStream().filter((entity2) -> {
@@ -2318,7 +2761,7 @@ @@ -2318,7 +2834,7 @@
Entity entity = this.vehicle; Entity entity = this.vehicle;
this.vehicle = null; this.vehicle = null;
@ -880,7 +959,7 @@
} }
} }
@@ -2349,21 +2792,50 @@ @@ -2349,21 +2865,50 @@
} }
} }
@ -937,7 +1016,7 @@
} }
protected boolean canAddPassenger(Entity passenger) { protected boolean canAddPassenger(Entity passenger) {
@@ -2464,7 +2936,7 @@ @@ -2464,7 +3009,7 @@
if (teleporttransition != null) { if (teleporttransition != null) {
ServerLevel worldserver1 = teleporttransition.newLevel(); ServerLevel worldserver1 = teleporttransition.newLevel();
@ -946,7 +1025,7 @@
this.teleport(teleporttransition); this.teleport(teleporttransition);
} }
} }
@@ -2547,7 +3019,7 @@ @@ -2547,7 +3092,7 @@
} }
public boolean isCrouching() { public boolean isCrouching() {
@ -955,7 +1034,7 @@
} }
public boolean isSprinting() { public boolean isSprinting() {
@@ -2563,7 +3035,7 @@ @@ -2563,7 +3108,7 @@
} }
public boolean isVisuallySwimming() { public boolean isVisuallySwimming() {
@ -964,7 +1043,7 @@
} }
public boolean isVisuallyCrawling() { public boolean isVisuallyCrawling() {
@@ -2571,6 +3043,13 @@ @@ -2571,6 +3116,13 @@
} }
public void setSwimming(boolean swimming) { public void setSwimming(boolean swimming) {
@ -978,7 +1057,7 @@
this.setSharedFlag(4, swimming); this.setSharedFlag(4, swimming);
} }
@@ -2609,6 +3088,7 @@ @@ -2609,6 +3161,7 @@
@Nullable @Nullable
public PlayerTeam getTeam() { public PlayerTeam getTeam() {
@ -986,7 +1065,7 @@
return this.level().getScoreboard().getPlayersTeam(this.getScoreboardName()); return this.level().getScoreboard().getPlayersTeam(this.getScoreboardName());
} }
@@ -2624,8 +3104,12 @@ @@ -2624,8 +3177,12 @@
return this.getTeam() != null ? this.getTeam().isAlliedTo(team) : false; return this.getTeam() != null ? this.getTeam().isAlliedTo(team) : false;
} }
@ -1000,7 +1079,7 @@
} }
public boolean getSharedFlag(int index) { public boolean getSharedFlag(int index) {
@@ -2644,7 +3128,7 @@ @@ -2644,7 +3201,7 @@
} }
public int getMaxAirSupply() { public int getMaxAirSupply() {
@ -1009,7 +1088,7 @@
} }
public int getAirSupply() { public int getAirSupply() {
@@ -2652,7 +3136,18 @@ @@ -2652,7 +3209,18 @@
} }
public void setAirSupply(int air) { public void setAirSupply(int air) {
@ -1029,7 +1108,7 @@
} }
public int getTicksFrozen() { public int getTicksFrozen() {
@@ -2679,11 +3174,40 @@ @@ -2679,11 +3247,40 @@
public void thunderHit(ServerLevel world, LightningBolt lightning) { public void thunderHit(ServerLevel world, LightningBolt lightning) {
this.setRemainingFireTicks(this.remainingFireTicks + 1); this.setRemainingFireTicks(this.remainingFireTicks + 1);
@ -1072,7 +1151,7 @@
} }
public void onAboveBubbleCol(boolean drag) { public void onAboveBubbleCol(boolean drag) {
@@ -2713,7 +3237,7 @@ @@ -2713,7 +3310,7 @@
this.resetFallDistance(); this.resetFallDistance();
} }
@ -1081,7 +1160,7 @@
return true; return true;
} }
@@ -2852,6 +3376,18 @@ @@ -2852,6 +3449,18 @@
if (world instanceof ServerLevel worldserver) { if (world instanceof ServerLevel worldserver) {
if (!this.isRemoved()) { if (!this.isRemoved()) {
@ -1100,7 +1179,7 @@
ServerLevel worldserver1 = teleportTarget.newLevel(); ServerLevel worldserver1 = teleportTarget.newLevel();
boolean flag = worldserver1.dimension() != worldserver.dimension(); boolean flag = worldserver1.dimension() != worldserver.dimension();
@@ -2920,8 +3456,12 @@ @@ -2920,8 +3529,12 @@
} else { } else {
entity.restoreFrom(this); entity.restoreFrom(this);
this.removeAfterChangingDimensions(); this.removeAfterChangingDimensions();
@ -1114,7 +1193,7 @@
Iterator iterator1 = list1.iterator(); Iterator iterator1 = list1.iterator();
while (iterator1.hasNext()) { while (iterator1.hasNext()) {
@@ -2947,7 +3487,7 @@ @@ -2947,7 +3560,7 @@
} }
private void sendTeleportTransitionToRidingPlayers(TeleportTransition teleportTarget) { private void sendTeleportTransitionToRidingPlayers(TeleportTransition teleportTarget) {
@ -1123,7 +1202,7 @@
Iterator iterator = this.getIndirectPassengers().iterator(); Iterator iterator = this.getIndirectPassengers().iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
@@ -2995,8 +3535,9 @@ @@ -2995,8 +3608,9 @@
} }
protected void removeAfterChangingDimensions() { protected void removeAfterChangingDimensions() {
@ -1134,10 +1213,12 @@
leashable.removeLeash(); leashable.removeLeash();
} }
@@ -3006,6 +3547,20 @@ @@ -3004,7 +3618,21 @@
return PortalShape.getRelativePosition(portalRect, portalAxis, this.position(), this.getDimensions(this.getPose()));
}
public Vec3 getRelativePortalPosition(Direction.Axis portalAxis, BlockUtil.FoundRectangle portalRect) {
return PortalShape.getRelativePosition(portalRect, portalAxis, this.position(), this.getDimensions(this.getPose()));
+ }
+
+ // CraftBukkit start + // CraftBukkit start
+ public CraftPortalEvent callPortalEvent(Entity entity, Location exit, PlayerTeleportEvent.TeleportCause cause, int searchRadius, int creationRadius) { + public CraftPortalEvent callPortalEvent(Entity entity, Location exit, PlayerTeleportEvent.TeleportCause cause, int searchRadius, int creationRadius) {
+ org.bukkit.entity.Entity bukkitEntity = entity.getBukkitEntity(); + org.bukkit.entity.Entity bukkitEntity = entity.getBukkitEntity();
@ -1149,13 +1230,12 @@
+ return null; + return null;
+ } + }
+ return new CraftPortalEvent(event); + return new CraftPortalEvent(event);
+ } }
+ // CraftBukkit end + // CraftBukkit end
+
public boolean canUsePortal(boolean allowVehicles) { public boolean canUsePortal(boolean allowVehicles) {
return (allowVehicles || !this.isPassenger()) && this.isAlive(); return (allowVehicles || !this.isPassenger()) && this.isAlive();
} @@ -3134,9 +3762,15 @@
@@ -3134,10 +3689,16 @@
return (Boolean) this.entityData.get(Entity.DATA_CUSTOM_NAME_VISIBLE); return (Boolean) this.entityData.get(Entity.DATA_CUSTOM_NAME_VISIBLE);
} }
@ -1166,16 +1246,15 @@
+ public final boolean teleportTo(ServerLevel world, double destX, double destY, double destZ, Set<Relative> flags, float yaw, float pitch, boolean resetCamera) { + public final boolean teleportTo(ServerLevel world, double destX, double destY, double destZ, Set<Relative> flags, float yaw, float pitch, boolean resetCamera) {
+ return this.teleportTo(world, destX, destY, destZ, flags, yaw, pitch, resetCamera, PlayerTeleportEvent.TeleportCause.UNKNOWN); + return this.teleportTo(world, destX, destY, destZ, flags, yaw, pitch, resetCamera, PlayerTeleportEvent.TeleportCause.UNKNOWN);
+ } + }
+
+ public boolean teleportTo(ServerLevel worldserver, double d0, double d1, double d2, Set<Relative> set, float f, float f1, boolean flag, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) { + public boolean teleportTo(ServerLevel worldserver, double d0, double d1, double d2, Set<Relative> set, float f, float f1, boolean flag, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) {
+ float f2 = Mth.clamp(f1, -90.0F, 90.0F); + float f2 = Mth.clamp(f1, -90.0F, 90.0F);
+ Entity entity = this.teleport(new TeleportTransition(worldserver, new Vec3(d0, d1, d2), Vec3.ZERO, f, f2, set, TeleportTransition.DO_NOTHING, cause)); + Entity entity = this.teleport(new TeleportTransition(worldserver, new Vec3(d0, d1, d2), Vec3.ZERO, f, f2, set, TeleportTransition.DO_NOTHING, cause));
+ // CraftBukkit end + // CraftBukkit end
+
return entity != null; return entity != null;
} }
@@ -3187,7 +3821,7 @@
@@ -3187,7 +3748,7 @@
/** @deprecated */ /** @deprecated */
@Deprecated @Deprecated
protected void fixupDimensions() { protected void fixupDimensions() {
@ -1184,7 +1263,7 @@
EntityDimensions entitysize = this.getDimensions(entitypose); EntityDimensions entitysize = this.getDimensions(entitypose);
this.dimensions = entitysize; this.dimensions = entitysize;
@@ -3196,7 +3757,7 @@ @@ -3196,7 +3830,7 @@
public void refreshDimensions() { public void refreshDimensions() {
EntityDimensions entitysize = this.dimensions; EntityDimensions entitysize = this.dimensions;
@ -1193,7 +1272,7 @@
EntityDimensions entitysize1 = this.getDimensions(entitypose); EntityDimensions entitysize1 = this.getDimensions(entitypose);
this.dimensions = entitysize1; this.dimensions = entitysize1;
@@ -3258,10 +3819,29 @@ @@ -3258,10 +3892,29 @@
} }
public final void setBoundingBox(AABB boundingBox) { public final void setBoundingBox(AABB boundingBox) {
@ -1225,7 +1304,7 @@
return this.getDimensions(pose).eyeHeight(); return this.getDimensions(pose).eyeHeight();
} }
@@ -3335,7 +3915,7 @@ @@ -3335,7 +3988,7 @@
} }
@Nullable @Nullable
@ -1234,7 +1313,7 @@
return null; return null;
} }
@@ -3435,7 +4015,7 @@ @@ -3435,7 +4088,7 @@
} }
public boolean isControlledByLocalInstance() { public boolean isControlledByLocalInstance() {
@ -1243,7 +1322,7 @@
if (entityliving instanceof Player entityhuman) { if (entityliving instanceof Player entityhuman) {
return entityhuman.isLocalPlayer(); return entityhuman.isLocalPlayer();
@@ -3445,7 +4025,7 @@ @@ -3445,7 +4098,7 @@
} }
public boolean isControlledByClient() { public boolean isControlledByClient() {
@ -1252,7 +1331,7 @@
return entityliving != null && entityliving.isControlledByClient(); return entityliving != null && entityliving.isControlledByClient();
} }
@@ -3463,7 +4043,7 @@ @@ -3463,7 +4116,7 @@
return new Vec3((double) f1 * d2 / (double) f3, 0.0D, (double) f2 * d2 / (double) f3); return new Vec3((double) f1 * d2 / (double) f3, 0.0D, (double) f2 * d2 / (double) f3);
} }
@ -1261,13 +1340,14 @@
return new Vec3(this.getX(), this.getBoundingBox().maxY, this.getZ()); return new Vec3(this.getX(), this.getBoundingBox().maxY, this.getZ());
} }
@@ -3489,8 +4069,37 @@ @@ -3488,9 +4141,38 @@
public int getFireImmuneTicks() {
return 1; return 1;
} }
+
+ // CraftBukkit start + // CraftBukkit start
+ private final CommandSource commandSource = new CommandSource() { + private final CommandSource commandSource = new CommandSource() {
+
+ @Override + @Override
+ public void sendSystemMessage(Component message) { + public void sendSystemMessage(Component message) {
+ } + }
@ -1300,19 +1380,20 @@
} }
public void lookAt(EntityAnchorArgument.Anchor anchorPoint, Vec3 target) { public void lookAt(EntityAnchorArgument.Anchor anchorPoint, Vec3 target) {
@@ -3551,6 +4160,11 @@ @@ -3550,7 +4232,12 @@
vec3d = vec3d.add(vec3d1); vec3d = vec3d.add(vec3d1);
++k1; ++k1;
} + }
+ // CraftBukkit start - store last lava contact location + // CraftBukkit start - store last lava contact location
+ if (tag == FluidTags.LAVA) { + if (tag == FluidTags.LAVA) {
+ this.lastLavaContact = blockposition_mutableblockposition.immutable(); + this.lastLavaContact = blockposition_mutableblockposition.immutable();
+ } }
+ // CraftBukkit end + // CraftBukkit end
} }
} }
} }
@@ -3613,7 +4227,7 @@ @@ -3613,7 +4300,7 @@
return new ClientboundAddEntityPacket(this, entityTrackerEntry); return new ClientboundAddEntityPacket(this, entityTrackerEntry);
} }
@ -1321,7 +1402,7 @@
return this.type.getDimensions(); return this.type.getDimensions();
} }
@@ -3818,8 +4432,16 @@ @@ -3818,8 +4505,16 @@
@Override @Override
public final void setRemoved(Entity.RemovalReason reason) { public final void setRemoved(Entity.RemovalReason reason) {
@ -1339,7 +1420,7 @@
} }
if (this.removalReason.shouldDestroy()) { if (this.removalReason.shouldDestroy()) {
@@ -3827,8 +4449,8 @@ @@ -3827,8 +4522,8 @@
} }
this.getPassengers().forEach(Entity::stopRiding); this.getPassengers().forEach(Entity::stopRiding);
@ -1350,7 +1431,7 @@
} }
public void unsetRemoved() { public void unsetRemoved() {
@@ -3887,7 +4509,7 @@ @@ -3887,7 +4582,7 @@
} }
public Vec3 getKnownMovement() { public Vec3 getKnownMovement() {

View File

@ -0,0 +1,11 @@
--- a/net/minecraft/world/entity/animal/Squid.java
+++ b/net/minecraft/world/entity/animal/Squid.java
@@ -46,7 +46,7 @@
public Squid(EntityType<? extends Squid> type, Level world) {
super(type, world);
- this.random.setSeed((long)this.getId());
+ //this.random.setSeed((long)this.getId()); // Paper - Share random for entities to make them more random
this.tentacleSpeed = 1.0F / (this.random.nextFloat() + 1.0F) * 0.2F;
}