more patches (#5799)

This commit is contained in:
Jake Potrebic 2021-06-11 19:24:43 -07:00 committed by GitHub
parent 650edb93ca
commit 933a189a04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 155 additions and 176 deletions

View File

@ -6,10 +6,10 @@ Subject: [PATCH] Use a Shared Random for Entities
Reduces memory usage and provides ensures more randomness, Especially since a lot of garbage entity objects get created.
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 93d3408231a177cf6d2086594756adffe3efa702..61048140cf0adca03bfb57193ada0adaee73b1bb 100644
index e9e87dc8c80d83dc7c472b0611077d8f9f4e5fcf..eceaeed527f34860e1c55b9f96863f140055faa7 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -142,6 +142,21 @@ public abstract class Entity implements Nameable, CommandSource, net.minecraft.s
@@ -153,6 +153,21 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
return tag.contains("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level;
}
@ -31,10 +31,10 @@ index 93d3408231a177cf6d2086594756adffe3efa702..61048140cf0adca03bfb57193ada0ada
private CraftEntity bukkitEntity;
public CraftEntity getBukkitEntity() {
@@ -271,7 +286,7 @@ public abstract class Entity implements Nameable, CommandSource, net.minecraft.s
@@ -304,7 +319,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, n
this.bb = Entity.INITIAL_AABB;
this.stuckSpeedMultiplier = Vec3.ZERO;
this.nextStep = 1.0F;
this.nextFlap = 1.0F;
- this.random = new Random();
+ this.random = SHARED_RANDOM; // Paper
this.remainingFireTicks = -this.getFireImmuneTicks();

View File

@ -22,15 +22,15 @@ index 3c78d3234054ce2dc46ef77decb6adb0cbd10620..cd64fb9d0c6d123e1c86cb33f12cd9ce
+ }
}
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index e1f9a12c7fb4818a785b9a4819f94fccde02b6a2..22c687e3db79bcfbc512ce3993d6e8a6db062360 100644
index 6aab4ba5da83f523632a0a39d45a0bcb2405f0cc..69b52097eede1a5c408aa7f34442e42255386436 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -584,7 +584,7 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
blockposition = this.findLightingTargetAround(this.getBlockRandomPos(j, 0, k, 15));
@@ -596,7 +596,7 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
blockposition = this.findLightningTargetAround(this.getBlockRandomPos(j, 0, k, 15));
if (this.isRainingAt(blockposition)) {
DifficultyInstance difficultydamagescaler = this.getCurrentDifficultyAt(blockposition);
- boolean flag1 = this.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && this.random.nextDouble() < (double) difficultydamagescaler.getEffectiveDifficulty() * 0.01D;
+ boolean flag1 = this.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && this.random.nextDouble() < (double) difficultydamagescaler.getEffectiveDifficulty() * paperConfig.skeleHorseSpawnChance; // Paper
- boolean flag1 = this.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && this.random.nextDouble() < (double) difficultydamagescaler.getEffectiveDifficulty() * 0.01D && !this.getBlockState(blockposition.below()).is(Blocks.LIGHTNING_ROD);
+ boolean flag1 = this.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && this.random.nextDouble() < (double) difficultydamagescaler.getEffectiveDifficulty() * paperConfig.skeleHorseSpawnChance && !this.getBlockState(blockposition.below()).is(Blocks.LIGHTNING_ROD); // Paper
if (flag1) {
SkeletonHorse entityhorseskeleton = (SkeletonHorse) EntityType.SKELETON_HORSE.create((net.minecraft.world.level.Level) this);

View File

@ -13,19 +13,19 @@ Replace all calls to the new place to the unnecessary forward.
Optimize getType and getBlockData to manually inline and optimize the calls
diff --git a/src/main/java/net/minecraft/core/Vec3i.java b/src/main/java/net/minecraft/core/Vec3i.java
index 3e79b274b8e0406a3cbdd94c7cec091b583109ca..c22de593be404c4e921724bba6a69c13759a95fd 100644
index f4b5792e080d5181184eb661d005ce6cab649bf3..c66ae4d9eea993f3b7fcc6e253259db3346229d1 100644
--- a/src/main/java/net/minecraft/core/Vec3i.java
+++ b/src/main/java/net/minecraft/core/Vec3i.java
@@ -22,6 +22,15 @@ public class Vec3i implements Comparable<Vec3i> {
private int y;public final void setY(final int y) { this.y = y; } // Paper - OBFHELPER
private int z;public final void setZ(final int z) { this.z = z; } // Paper - OBFHELPER
@@ -21,6 +21,15 @@ public class Vec3i implements Comparable<Vec3i> {
private int y;
private int z;
+ // Paper start
+ public boolean isValidLocation() {
+ return getX() >= -30000000 && getZ() >= -30000000 && getX() < 30000000 && getZ() < 30000000 && getY() >= 0 && getY() < 256;
+ public boolean isValidLocation(net.minecraft.world.level.Level level) {
+ return getX() >= -30000000 && getZ() >= -30000000 && getX() < 30000000 && getZ() < 30000000 && !level.isOutsideBuildHeight(getY());
+ }
+ public boolean isInvalidYLocation() {
+ return y < 0 || y >= 256;
+ public boolean isInvalidYLocation(net.minecraft.world.level.Level level) {
+ return level.isOutsideBuildHeight(getY());
+ }
+ // Paper end
+
@ -33,45 +33,36 @@ index 3e79b274b8e0406a3cbdd94c7cec091b583109ca..c22de593be404c4e921724bba6a69c13
this.x = x;
this.y = y;
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index 799721ac63f0c08dd03a788b87eafa9a8cc976cc..24a6429059f58f51c97386ca2823ca0910288dec 100644
index aee97243cc3e73f9e07ba8ed5d6dbe8c73ba016e..fdab998241a682bc3d75094e0893f98886e06266 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -239,7 +239,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -259,7 +259,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
}
public static boolean isInWorldBounds(BlockPos pos) {
- return !isOutsideBuildHeight(pos) && isInWorldBoundsHorizontal(pos);
+ return pos.isValidLocation(); // Paper - use better/optimized check
public boolean isInWorldBounds(BlockPos pos) {
- return !this.isOutsideBuildHeight(pos) && Level.isInWorldBoundsHorizontal(pos);
+ return pos.isValidLocation(this); // Paper - use better/optimized check
}
public static boolean isInSpawnableBounds(BlockPos pos) {
diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java b/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
index 3ca6289ba4952b5036367451b50cd90a78c0f938..e6303cdb433ee2b6782e2a0bd6b03e4f6ecb18ba 100644
index 6a3f98edbc2b4056c5baf00277caee327e444a77..974ab04b08bbd3c27a394b37c1af112be5f28f43 100644
--- a/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
+++ b/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
@@ -25,6 +25,7 @@ import org.apache.logging.log4j.LogManager;
public interface ChunkAccess extends BlockGetter, FeatureAccess {
@@ -29,6 +29,7 @@ public interface ChunkAccess extends BlockGetter, FeatureAccess {
return GameEventDispatcher.NOOP;
}
+ BlockState getType(final int x, final int y, final int z); // Paper
@Nullable
BlockState setBlockState(BlockPos pos, BlockState state, boolean moved);
diff --git a/src/main/java/net/minecraft/world/level/chunk/EmptyLevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/EmptyLevelChunk.java
index a26de06252207cf333ea4a8d73f0af6ddc239103..e369730ac6909ff5343468bd685c9ea2b6b3cfed 100644
index 84ebfdfc4350fb57ca2959e000b33b8d5efa6e0b..69c2454533e6f21c70792b555ec02c6bc6d169b3 100644
--- a/src/main/java/net/minecraft/world/level/chunk/EmptyLevelChunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/EmptyLevelChunk.java
@@ -23,7 +23,7 @@ import net.minecraft.world.phys.AABB;
public class EmptyLevelChunk extends LevelChunk {
- private static final Biome[] BIOMES = (Biome[]) Util.make((Object) (new Biome[ChunkBiomeContainer.BIOMES_SIZE]), (abiomebase) -> {
+ private static final Biome[] BIOMES = Util.make((new Biome[ChunkBiomeContainer.BIOMES_SIZE]), (abiomebase) -> { // Paper - decompile error
Arrays.fill(abiomebase, Biomes.PLAINS);
});
@@ -31,6 +31,11 @@ public class EmptyLevelChunk extends LevelChunk {
super(world, pos, new ChunkBiomeContainer(world.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), EmptyLevelChunk.BIOMES));
@@ -19,6 +19,11 @@ public class EmptyLevelChunk extends LevelChunk {
super(world, pos, new EmptyLevelChunk.EmptyChunkBiomeContainer(world));
}
+ // Paper start
@ -83,10 +74,10 @@ index a26de06252207cf333ea4a8d73f0af6ddc239103..e369730ac6909ff5343468bd685c9ea2
public BlockState getBlockState(BlockPos pos) {
return Blocks.VOID_AIR.defaultBlockState();
diff --git a/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java b/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java
index 04940ab2814cf39157d234dc4615646d7c760460..17fa8b23d1000ae53f2b4f1a6e8817c1005c1c81 100644
index c1beb6d5fc3cabfeacf0ffbf563e53ff7984c5d3..452b513e8b89d865a396066adaf4feb1140e1c62 100644
--- a/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/ImposterProtoChunk.java
@@ -42,6 +42,11 @@ public class ImposterProtoChunk extends ProtoChunk {
@@ -40,6 +40,11 @@ public class ImposterProtoChunk extends ProtoChunk {
public BlockState getBlockState(BlockPos pos) {
return this.wrapped.getBlockState(pos);
}
@ -99,47 +90,47 @@ index 04940ab2814cf39157d234dc4615646d7c760460..17fa8b23d1000ae53f2b4f1a6e8817c1
@Override
public FluidState getFluidState(BlockPos pos) {
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
index 9ca05aa06696883adc8b67a68ca6d2d850e95d25..546fb2f42e6bf333582b504d0a29991698505df3 100644
index 9939c4c39549771afe971a6433dfd57e36050dd8..7e5e16fd61b39d2093459766e8aaa10bb05f6763 100644
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
@@ -347,12 +347,27 @@ public class LevelChunk implements ChunkAccess {
@@ -337,12 +337,28 @@ public class LevelChunk implements ChunkAccess {
return this.sections;
}
- @Override
+ // Paper start - Optimize getBlockData to reduce instructions
+ public final BlockState getBlockData(BlockPos pos) { return getBlockData(pos.getX(), pos.getY(), pos.getZ()); } // Paper
@Override
public BlockState getBlockState(BlockPos pos) {
- int i = pos.getX();
- int j = pos.getY();
- int k = pos.getZ();
+ return this.getBlockData(pos.getX(), pos.getY(), pos.getZ());
+ }
+
+ public BlockState getType(final int x, final int y, final int z) {
+ return getBlockData(x, y, z);
+ return this.getBlockData(x, y, z);
+ }
+ public final BlockState getBlockData(final int x, final int y, final int z) {
+ // Method body / logic copied from below
+ final int i = y >> 4;
+ if (y < 0 || i >= this.sections.length || this.sections[i] == null || this.sections[i].nonEmptyBlockCount == 0) {
+ final int i = this.getSectionIndex(y);
+ if (i < 0 || i >= this.sections.length || this.sections[i] == null || this.sections[i].nonEmptyBlockCount == 0) {
+ return Blocks.AIR.defaultBlockState();
+ }
+ // Inlined ChunkSection.getType() and DataPaletteBlock.a(int,int,int)
+ return this.sections[i].states.get((y & 15) << 8 | (z & 15) << 4 | x & 15);
+ }
+
+ public BlockState getBlockData_unused(int i, int j, int k) {
+ // Paper end
if (this.world.isDebug()) {
if (this.level.isDebug()) {
BlockState iblockdata = null;
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
index b54d82e0f41a03c91e0de8df8249a91da3c04d0e..f5db97fb0dac78e1d9aa68d0417aa13f39914f52 100644
index 03fd5684aec8fa0d87963f2adcd8244e92840917..5fd66020a937b641e2a060cf38df731a43f3bf55 100644
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
@@ -13,10 +13,10 @@ public class LevelChunkSection {
@@ -15,10 +15,10 @@ public class LevelChunkSection {
public static final int SECTION_SIZE = 4096;
public static final Palette<BlockState> GLOBAL_BLOCKSTATE_PALETTE = new GlobalPalette<>(Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState());
private final int bottomBlockY;
- private short nonEmptyBlockCount;
@ -151,22 +142,20 @@ index b54d82e0f41a03c91e0de8df8249a91da3c04d0e..f5db97fb0dac78e1d9aa68d0417aa13f
public LevelChunkSection(int yOffset) {
this(yOffset, (short)0, (short)0, (short)0);
@@ -30,8 +30,8 @@ public class LevelChunkSection {
this.states = new PalettedContainer<>(LevelChunkSection.GLOBAL_BLOCKSTATE_PALETTE, Block.BLOCK_STATE_REGISTRY, NbtUtils::readBlockState, NbtUtils::writeBlockState, Blocks.AIR.defaultBlockState());
@@ -37,7 +37,7 @@ public class LevelChunkSection {
}
- public BlockState getBlockState(int x, int y, int z) {
- return (BlockState) this.states.get(x, y, z);
+ public final BlockState getBlockState(int x, int y, int z) { // Paper
public BlockState getBlockState(int x, int y, int z) {
- return this.states.get(x, y, z);
+ return this.states.get(y << 8 | z << 4 | x); // Paper - inline
}
public FluidState getFluidState(int x, int y, int z) {
diff --git a/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java b/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java
index d4db27421736f665739436c1ac4d3c6d5cae95cd..6d3dcd19ce1abc9d502903b8008949b5174a13c3 100644
index 4a6781919eb78abc33f549693d88019b42ef6e95..5ea60bbb56450502f1ceb41959239ab579458ac2 100644
--- a/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java
+++ b/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java
@@ -133,7 +133,7 @@ public class PalettedContainer<T> implements PaletteResize<T> {
@@ -136,7 +136,7 @@ public class PalettedContainer<T> implements PaletteResize<T> {
}
public T get(int x, int y, int z) {
@ -176,27 +165,25 @@ index d4db27421736f665739436c1ac4d3c6d5cae95cd..6d3dcd19ce1abc9d502903b8008949b5
protected T get(int index) {
diff --git a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java b/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java
index 7cd3f89004b0a64772fc3dfbdd132ba5a850b63e..d8b7b210484079c9ca2c34831c84102cba6692f5 100644
index 39fe8f64528ad08594aaaa88e5c989c82e4e29d3..da36e6d40ad3e8b7cdbe09ef911d1e5b8c28670f 100644
--- a/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/ProtoChunk.java
@@ -113,16 +113,18 @@ public class ProtoChunk implements ChunkAccess {
@@ -104,14 +104,18 @@ public class ProtoChunk implements ChunkAccess {
@Override
public BlockState getBlockState(BlockPos pos) {
- int i = pos.getY();
-
- if (Level.isOutsideBuildHeight(i)) {
- if (this.isOutsideBuildHeight(i)) {
+ // Paper start
+ return getType(pos.getX(), pos.getY(), pos.getZ());
+ }
+ // Paper start
+ public BlockState getType(final int x, final int y, final int z) {
+ if (y < 0 || y >= 256) {
+ if (this.isOutsideBuildHeight(y)) {
return Blocks.VOID_AIR.defaultBlockState();
} else {
- LevelChunkSection chunksection = this.getSections()[i >> 4];
-
- return LevelChunkSection.isEmpty(chunksection) ? Blocks.AIR.defaultBlockState() : chunksection.getBlockState(pos.getX() & 15, i & 15, pos.getZ() & 15);
+ LevelChunkSection chunksection = this.getSections()[y >> 4];
- LevelChunkSection levelChunkSection = this.getSections()[this.getSectionIndex(i)];
- return LevelChunkSection.isEmpty(levelChunkSection) ? Blocks.AIR.defaultBlockState() : levelChunkSection.getBlockState(pos.getX() & 15, i & 15, pos.getZ() & 15);
+ LevelChunkSection chunksection = this.getSections()[this.getSectionIndex(y)];
+ return chunksection == LevelChunk.EMPTY_CHUNK_SECTION || chunksection.isEmpty() ? Blocks.AIR.defaultBlockState() : chunksection.getBlockState(x & 15, y & 15, z & 15);
}
}

View File

@ -6,10 +6,10 @@ Subject: [PATCH] Only process BlockPhysicsEvent if a plugin has a listener
Saves on some object allocation and processing when no plugin listens to this
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 901d5497667706c049718dc4fca37a1bc489c465..f7763a773bce4d8d947c8c859fe84d8a601034c5 100644
index c6a59fa4b30d54baa638c931f045b2d546da021a..591f7452005cbfb567b611b3ba71c16596f9edfa 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1290,6 +1290,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1362,6 +1362,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
while (iterator.hasNext()) {
ServerLevel worldserver = (ServerLevel) iterator.next();
@ -18,10 +18,10 @@ index 901d5497667706c049718dc4fca37a1bc489c465..f7763a773bce4d8d947c8c859fe84d8a
this.profiler.push(() -> {
return worldserver + " " + worldserver.dimension().location();
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 22c687e3db79bcfbc512ce3993d6e8a6db062360..8b0a384caa09848d61b3a6259dd56590cd52d0a0 100644
index 69b52097eede1a5c408aa7f34442e42255386436..9394dd781bb27b273c442972c5923615ac406507 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -190,6 +190,7 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
@@ -201,6 +201,7 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
private int tickPosition;
public final LevelStorageSource.LevelStorageAccess convertable;
public final UUID uuid;
@ -30,10 +30,10 @@ index 22c687e3db79bcfbc512ce3993d6e8a6db062360..8b0a384caa09848d61b3a6259dd56590
@Override public LevelChunk getChunkIfLoaded(int x, int z) { // Paper - this was added in world too but keeping here for NMS ABI
return this.chunkSource.getChunk(x, z, false);
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index 24a6429059f58f51c97386ca2823ca0910288dec..d47ed15382f98aabd509e32a3c202a91088adf6b 100644
index fdab998241a682bc3d75094e0893f98886e06266..81a8e314b5073a5888a3c04d53ff279c8142a7d4 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -458,7 +458,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -470,7 +470,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
// CraftBukkit start
iblockdata1.updateIndirectNeighbourShapes(this, blockposition, k, j - 1); // Don't call an event for the old block to limit event spam
CraftWorld world = ((ServerLevel) this).getWorld();
@ -42,29 +42,29 @@ index 24a6429059f58f51c97386ca2823ca0910288dec..d47ed15382f98aabd509e32a3c202a91
BlockPhysicsEvent event = new BlockPhysicsEvent(world.getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()), CraftBlockData.fromData(iblockdata));
this.getCraftServer().getPluginManager().callEvent(event);
@@ -560,7 +560,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -580,7 +580,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
try {
// CraftBukkit start
CraftWorld world = ((ServerLevel) this).getWorld();
- if (world != null) {
+ if (world != null && ((ServerLevel)this).hasPhysicsEvent) { // Paper
BlockPhysicsEvent event = new BlockPhysicsEvent(world.getBlockAt(sourcePos.getX(), sourcePos.getY(), sourcePos.getZ()), CraftBlockData.fromData(iblockdata), world.getBlockAt(neighborPos.getX(), neighborPos.getY(), neighborPos.getZ()));
BlockPhysicsEvent event = new BlockPhysicsEvent(world.getBlockAt(pos.getX(), pos.getY(), pos.getZ()), CraftBlockData.fromData(iblockdata), world.getBlockAt(neighborPos.getX(), neighborPos.getY(), neighborPos.getZ()));
this.getCraftServer().getPluginManager().callEvent(event);
diff --git a/src/main/java/net/minecraft/world/level/block/BushBlock.java b/src/main/java/net/minecraft/world/level/block/BushBlock.java
index d6cb341d4d8e20b77979a241dd2e4346455796d7..42635b6115187abeffb290ca040350fd97cf89f7 100644
index 24227939493f852a88477c84160bda1605291eb0..1f8cf302d2309aec2955832ffafd87f14934e141 100644
--- a/src/main/java/net/minecraft/world/level/block/BushBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/BushBlock.java
@@ -2,6 +2,7 @@ package net.minecraft.world.level.block;
import net.minecraft.core.BlockPos;
@@ -4,6 +4,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.Tag;
+import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
@@ -23,7 +24,7 @@ public class BushBlock extends Block {
public BlockState updateShape(BlockState state, Direction direction, BlockState newState, LevelAccessor world, BlockPos pos, BlockPos posFrom) {
@@ -25,7 +26,7 @@ public class BushBlock extends Block {
public BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
// CraftBukkit start
if (!state.canSurvive(world, pos)) {
- if (!org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPhysicsEvent(world, pos).isCancelled()) {
@ -73,18 +73,18 @@ index d6cb341d4d8e20b77979a241dd2e4346455796d7..42635b6115187abeffb290ca040350fd
}
}
diff --git a/src/main/java/net/minecraft/world/level/block/DoublePlantBlock.java b/src/main/java/net/minecraft/world/level/block/DoublePlantBlock.java
index db444689092f537dd736dc73c532bd540fadcf86..86c5025d1b21dc35782124eca66288c63626147a 100644
index 08870ea2431ba27474a275006071801c01cc9b1c..9c010d8359a36f3b2d4af3d828bc2dca792ef2f4 100644
--- a/src/main/java/net/minecraft/world/level/block/DoublePlantBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/DoublePlantBlock.java
@@ -3,6 +3,7 @@ package net.minecraft.world.level.block;
import javax.annotation.Nullable;
@@ -4,6 +4,7 @@ import javax.annotation.Nullable;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
+import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
@@ -83,7 +84,7 @@ public class DoublePlantBlock extends BushBlock {
@@ -85,7 +86,7 @@ public class DoublePlantBlock extends BushBlock {
protected static void preventCreativeDropFromBottomPart(Level world, BlockPos pos, BlockState state, Player player) {
// CraftBukkit start

View File

@ -5,19 +5,10 @@ Subject: [PATCH] Entity AddTo/RemoveFrom World Events
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 8b0a384caa09848d61b3a6259dd56590cd52d0a0..f7eddb39985072afeb79ec0cbfc084d7e84638e6 100644
index 9394dd781bb27b273c442972c5923615ac406507..b1c9a21574d6adba5d01caea0abac16a0e214a8f 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -1208,7 +1208,7 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
if (entity instanceof Mob) {
this.navigations.remove(((Mob) entity).getNavigation());
}
-
+ new com.destroystokyo.paper.event.entity.EntityRemoveFromWorldEvent(entity.getBukkitEntity()).callEvent(); // Paper - fire while valid
entity.valid = false; // CraftBukkit
}
@@ -1246,6 +1246,7 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
@@ -1116,6 +1116,7 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
entity.origin = entity.getBukkitEntity().getLocation();
}
// Paper end
@ -25,3 +16,11 @@ index 8b0a384caa09848d61b3a6259dd56590cd52d0a0..f7eddb39985072afeb79ec0cbfc084d7
}
}
@@ -1964,6 +1965,7 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
}
entity.valid = false; // CraftBukkit
+ new com.destroystokyo.paper.event.entity.EntityRemoveFromWorldEvent(entity.getBukkitEntity()).callEvent(); // Paper - fire while valid
}
}
}

View File

@ -30,15 +30,15 @@ index cd64fb9d0c6d123e1c86cb33f12cd9cefc9f80d0..74ba5dbb83c13ce1721619b755036a78
+ }
}
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
index 546fb2f42e6bf333582b504d0a29991698505df3..70f5b025c2b803df3de8a51cbcfafbe915866f42 100644
index 7e5e16fd61b39d2093459766e8aaa10bb05f6763..5c5a55003658d75ad8295cbd7ff0450e08600d68 100644
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
@@ -1021,7 +1021,7 @@ public class LevelChunk implements ChunkAccess {
@@ -978,7 +978,7 @@ public class LevelChunk implements ChunkAccess {
@Override
public long getInhabitedTime() {
- return this.inhabitedTime;
+ return world.paperConfig.fixedInhabitedTime < 0 ? this.inhabitedTime : world.paperConfig.fixedInhabitedTime; // Paper
+ return this.level.paperConfig.fixedInhabitedTime < 0 ? this.inhabitedTime : this.level.paperConfig.fixedInhabitedTime; // Paper
}
@Override

View File

@ -6,10 +6,10 @@ Subject: [PATCH] EntityPathfindEvent
Fires when an Entity decides to start moving to a location.
diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/FlyingPathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/FlyingPathNavigation.java
index 0af2c5dde41043a6fb2fcd07db96288c7f96e0c7..5e7e678c4469e34c7ae39656f547243fbcf1d0da 100644
index 3afe97f4e330016164e741934c888f5b85824e67..48a42a8374641f4737d5eb6a460bf80a12c2cae5 100644
--- a/src/main/java/net/minecraft/world/entity/ai/navigation/FlyingPathNavigation.java
+++ b/src/main/java/net/minecraft/world/entity/ai/navigation/FlyingPathNavigation.java
@@ -37,7 +37,7 @@ public class FlyingPathNavigation extends PathNavigation {
@@ -35,7 +35,7 @@ public class FlyingPathNavigation extends PathNavigation {
@Override
public Path createPath(Entity entity, int distance) {
@ -19,10 +19,10 @@ index 0af2c5dde41043a6fb2fcd07db96288c7f96e0c7..5e7e678c4469e34c7ae39656f547243f
@Override
diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java
index cd7cb7cbe55a36282de394efc95f4ba7cc6a75cf..01be1de9d9ca0a86d69b2e82693bd0fea61a969f 100644
index d2e71f1e70a8b3360110f7e5e6c5ec278218ae27..0ac90b5fefa9720a9d0130f5438e5ef55fccf29a 100644
--- a/src/main/java/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java
+++ b/src/main/java/net/minecraft/world/entity/ai/navigation/GroundPathNavigation.java
@@ -75,7 +75,7 @@ public class GroundPathNavigation extends PathNavigation {
@@ -70,7 +70,7 @@ public class GroundPathNavigation extends PathNavigation {
@Override
public Path createPath(Entity entity, int distance) {
@ -32,27 +32,27 @@ index cd7cb7cbe55a36282de394efc95f4ba7cc6a75cf..01be1de9d9ca0a86d69b2e82693bd0fe
private int getSurfaceY() {
diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
index 3cfd913e31236e35e7225ba19d292cacb8b4134a..ae8d430382b20ddd837c47e39515c7995f25312a 100644
index 92e1c43b0b7d901636b7fee7136e573f440e0179..e6a2f836e70a267da36ec87e0df68e36bae3626c 100644
--- a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
+++ b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
@@ -10,6 +10,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.Position;
import net.minecraft.core.Vec3i;
import net.minecraft.network.protocol.game.DebugPackets;
import net.minecraft.tags.BlockTags;
+import net.minecraft.server.MCUtil;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Mob;
@@ -28,7 +29,7 @@ import net.minecraft.world.phys.Vec3;
@@ -26,7 +27,7 @@ import net.minecraft.world.phys.Vec3;
public abstract class PathNavigation {
private static final int MAX_TIME_RECOMPUTE = 20;
- protected final Mob mob;
+ protected final Mob mob; public Entity getEntity() { return mob; } // Paper - OBFHELPER
protected final Level level;
@Nullable
protected Path path;
@@ -115,36 +116,63 @@ public abstract class PathNavigation {
@@ -108,7 +109,12 @@ public abstract class PathNavigation {
@Nullable
public Path createPath(BlockPos target, int distance) {
@ -60,66 +60,59 @@ index 3cfd913e31236e35e7225ba19d292cacb8b4134a..ae8d430382b20ddd837c47e39515c799
+ // Paper start - add target parameter
+ return this.a(target, null, distance);
+ }
+ @Nullable public Path a(BlockPos blockposition, Entity target, int i) {
+ return this.a(ImmutableSet.of(blockposition), target, 8, false, i);
+ @Nullable public Path a(BlockPos blockposition, Entity target, int distance) {
+ return this.createPath(ImmutableSet.of(blockposition), target, 8, false, distance);
+ // Paper end
}
@Nullable
@@ -118,7 +124,7 @@ public abstract class PathNavigation {
@Nullable
public Path createPath(Entity entity, int distance) {
- return this.createPath(ImmutableSet.of(entity.blockPosition()), 16, true, distance);
+ return this.a(ImmutableSet.of(entity.blockPosition()), entity, 16, true, distance); // Paper
+ return this.createPath(ImmutableSet.of(entity.blockPosition()), entity, 16, true, distance); // Paper
}
@Nullable
+ // Paper start - Add target
protected Path createPath(Set<BlockPos> positions, int range, boolean flag, int distance) {
- if (positions.isEmpty()) {
+ return this.a(positions, null, range, flag, distance);
@@ -128,6 +134,16 @@ public abstract class PathNavigation {
@Nullable
protected Path createPath(Set<BlockPos> positions, int range, boolean useHeadPos, int distance, float followRange) {
+ return this.createPath(positions, null, range, useHeadPos, distance, (float) this.mob.getAttributeValue(Attributes.FOLLOW_RANGE));
+ }
+ @Nullable protected Path a(Set<BlockPos> set, Entity target, int i, boolean flag, int j) {
+
+ @Nullable
+ protected Path createPath(Set<BlockPos> positions, Entity target, int range, boolean useHeadPos, int distance) {
+ return this.createPath(positions, target, range, useHeadPos, distance, (float) this.mob.getAttributeValue(Attributes.FOLLOW_RANGE));
+ }
+
+ @Nullable protected Path createPath(Set<BlockPos> positions, Entity target, int range, boolean useHeadPos, int distance, float followRange) {
+ // Paper end
+ if (set.isEmpty()) {
if (positions.isEmpty()) {
return null;
} else if (this.mob.getY() < 0.0D) {
return null;
} else if (!this.canUpdatePath()) {
return null;
- } else if (this.path != null && !this.path.isDone() && positions.contains(this.targetPos)) {
+ } else if (this.path != null && !this.path.isDone() && set.contains(this.targetPos)) {
} else if (this.mob.getY() < (double)this.level.getMinBuildHeight()) {
@@ -137,6 +153,23 @@ public abstract class PathNavigation {
} else if (this.path != null && !this.path.isDone() && positions.contains(this.targetPos)) {
return this.path;
} else {
+ // Paper start - Pathfind event
+ boolean copiedSet = false;
+ for (BlockPos possibleTarget : set) {
+ for (BlockPos possibleTarget : positions) {
+ if (!new com.destroystokyo.paper.event.entity.EntityPathfindEvent(getEntity().getBukkitEntity(),
+ MCUtil.toLocation(getEntity().level, possibleTarget), target == null ? null : target.getBukkitEntity()).callEvent()) {
+ if (!copiedSet) {
+ copiedSet = true;
+ set = new java.util.HashSet<>(set);
+ positions = new java.util.HashSet<>(positions);
+ }
+ // note: since we copy the set this remove call is safe, since we're iterating over the old copy
+ set.remove(possibleTarget);
+ if (set.isEmpty()) {
+ positions.remove(possibleTarget);
+ if (positions.isEmpty()) {
+ return null;
+ }
+ }
+ }
+ // Paper end
this.level.getProfiler().push("pathfind");
float f = (float) this.mob.getAttributeValue(Attributes.FOLLOW_RANGE);
BlockPos blockposition = flag ? this.mob.blockPosition().above() : this.mob.blockPosition();
- int k = (int) (f + (float) range);
+ int k = (int) (f + (float) i);
PathNavigationRegion chunkcache = new PathNavigationRegion(this.level, blockposition.offset(-k, -k, -k), blockposition.offset(k, k, k));
- Path pathentity = this.pathFinder.findPath(chunkcache, this.mob, positions, f, distance, this.maxVisitedNodesMultiplier);
+ Path pathentity = this.pathFinder.findPath(chunkcache, this.mob, set, f, j, this.maxVisitedNodesMultiplier);
this.level.getProfiler().pop();
if (pathentity != null && pathentity.getTarget() != null) {
this.targetPos = pathentity.getTarget();
- this.reachRange = distance;
+ this.reachRange = j;
this.resetStuckTimeout();
}
BlockPos blockPos = useHeadPos ? this.mob.blockPosition().above() : this.mob.blockPosition();
int i = (int)(followRange + (float)range);

View File

@ -25,10 +25,10 @@ index 716f285e67019b8a62922d09c15883c99f9421aa..439dcc6effdc91830d2b7ede90639829
+ }
}
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
index 97a58da9d64d812942ceb71426d35b490bbbe817..f33a5fc725d1d5e895f8878d82ebc4172237ad29 100644
index 1ed8232493c94bc0cf28ef8d4b647cb84bd3fe32..3c82f98a34a5911fdb9e3ba66c54d25f6944fd07 100644
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
@@ -33,7 +33,7 @@ public final class RegionFileStorage implements AutoCloseable {
@@ -35,7 +35,7 @@ public final class RegionFileStorage implements AutoCloseable {
if (regionfile != null) {
return regionfile;
} else {

View File

@ -5,64 +5,64 @@ Subject: [PATCH] Do not load chunks for Pathfinding
diff --git a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
index ae8d430382b20ddd837c47e39515c7995f25312a..25bc3adfad956157cef0953e6e632b7b7e352f3a 100644
index e6a2f836e70a267da36ec87e0df68e36bae3626c..6c063351c76e92a8a91142a12db846d1c1f11921 100644
--- a/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
+++ b/src/main/java/net/minecraft/world/entity/ai/navigation/PathNavigation.java
@@ -48,7 +48,7 @@ public abstract class PathNavigation {
@@ -46,7 +46,7 @@ public abstract class PathNavigation {
private BlockPos targetPos;
private int reachRange;
private float maxVisitedNodesMultiplier;
private float maxVisitedNodesMultiplier = 1.0F;
- private final PathFinder pathFinder;
+ private final PathFinder pathFinder; public PathFinder getPathfinder() { return this.pathFinder; } // Paper - OBFHELPER
private boolean isStuck;
public PathNavigation(Mob mob, Level world) {
diff --git a/src/main/java/net/minecraft/world/level/pathfinder/PathFinder.java b/src/main/java/net/minecraft/world/level/pathfinder/PathFinder.java
index 99f3f0b895295229b75d93e98141c0cd75789b69..ba8ee93032aabe7ec4ecf52d452e1a580d6ebc20 100644
index e855754bdb8431efc06c77b42d9a90b870abab8d..800d464207026d145056b39b298045121342b899 100644
--- a/src/main/java/net/minecraft/world/level/pathfinder/PathFinder.java
+++ b/src/main/java/net/minecraft/world/level/pathfinder/PathFinder.java
@@ -20,7 +20,7 @@ public class PathFinder {
@@ -21,7 +21,7 @@ public class PathFinder {
private static final float FUDGING = 1.5F;
private final Node[] neighbors = new Node[32];
private final int maxVisitedNodes;
- private final NodeEvaluator nodeEvaluator;
+ private final NodeEvaluator nodeEvaluator; public NodeEvaluator getPathfinder() { return this.nodeEvaluator; } // Paper - OBFHELPER
private static final boolean DEBUG = false;
private final BinaryHeap openSet = new BinaryHeap();
public PathFinder(NodeEvaluator pathNodeMaker, int range) {
diff --git a/src/main/java/net/minecraft/world/level/pathfinder/WalkNodeEvaluator.java b/src/main/java/net/minecraft/world/level/pathfinder/WalkNodeEvaluator.java
index 0b378348cb9e9576e2a209e651264e2caccfd182..7ae24381b91c282745b7fe5f6897865e74bc0acf 100644
index 204ed5665adf2df7252fe2d21872db6956415311..b37acb6e6e253529a38f44a518a02c7747d3145e 100644
--- a/src/main/java/net/minecraft/world/level/pathfinder/WalkNodeEvaluator.java
+++ b/src/main/java/net/minecraft/world/level/pathfinder/WalkNodeEvaluator.java
@@ -479,7 +479,12 @@ public class WalkNodeEvaluator extends NodeEvaluator {
for (int j1 = -1; j1 <= 1; ++j1) {
if (l != 0 || j1 != 0) {
blockposition_mutableblockposition.set(i + l, j + i1, k + j1);
- BlockState iblockdata = iblockaccess.getBlockState(blockposition_mutableblockposition);
@@ -453,7 +453,12 @@ public class WalkNodeEvaluator extends NodeEvaluator {
for(int n = -1; n <= 1; ++n) {
if (l != 0 || n != 0) {
pos.set(i + l, j + m, k + n);
- BlockState blockState = world.getBlockState(pos);
+ // Paper start
+ BlockState iblockdata = iblockaccess.getTypeIfLoaded(blockposition_mutableblockposition);
+ if (iblockdata == null) {
+ pathtype = BlockPathTypes.BLOCKED;
+ BlockState blockState = world.getTypeIfLoaded(pos);
+ if (blockState == null) {
+ return BlockPathTypes.BLOCKED;
+ } else {
+ // Paper end
if (iblockdata.is(Blocks.CACTUS)) {
if (blockState.is(Blocks.CACTUS)) {
return BlockPathTypes.DANGER_CACTUS;
@@ -496,6 +501,7 @@ public class WalkNodeEvaluator extends NodeEvaluator {
if (iblockaccess.getFluidState(blockposition_mutableblockposition).is((Tag) FluidTags.WATER)) {
}
@@ -469,6 +474,7 @@ public class WalkNodeEvaluator extends NodeEvaluator {
if (world.getFluidState(pos).is(FluidTags.WATER)) {
return BlockPathTypes.WATER_BORDER;
}
+ } // Paper
}
}
}
@@ -505,7 +511,8 @@ public class WalkNodeEvaluator extends NodeEvaluator {
@@ -478,7 +484,8 @@ public class WalkNodeEvaluator extends NodeEvaluator {
}
protected static BlockPathTypes getBlockPathTypeRaw(BlockGetter iblockaccess, BlockPos blockposition) {
- BlockState iblockdata = iblockaccess.getBlockState(blockposition);
+ BlockState iblockdata = iblockaccess.getTypeIfLoaded(blockposition); // Paper
+ if (iblockdata == null) return BlockPathTypes.BLOCKED; // Paper
Block block = iblockdata.getBlock();
Material material = iblockdata.getMaterial();
protected static BlockPathTypes getBlockPathTypeRaw(BlockGetter world, BlockPos pos) {
- BlockState blockState = world.getBlockState(pos);
+ BlockState blockState = world.getTypeIfLoaded(pos); // Paper
+ if (blockState == null) return BlockPathTypes.BLOCKED; // Paper
Block block = blockState.getBlock();
Material material = blockState.getMaterial();
if (blockState.isAir()) {