Skip to content

Commit

Permalink
Avoid collision shapes outside world border in findFreePosition
Browse files Browse the repository at this point in the history
This is to correctly adhere to Vanilla behavior.
  • Loading branch information
Spottedleaf committed Jul 15, 2024
1 parent aa929d6 commit 8b23018
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 22 deletions.
30 changes: 20 additions & 10 deletions patches/server/0991-Moonrise-optimisation-patches.patch
Original file line number Diff line number Diff line change
Expand Up @@ -31308,7 +31308,7 @@ index bff83fe413c7baef4ba56a3270ea4463a58c792f..a248d859cbce48f4a34c4771a7acffc1
}

diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index e27d3547d1e19c137e05e6b8d075127a8bafb237..a12ef61b42779e37d439585e479c7d73a5abf226 100644
index e27d3547d1e19c137e05e6b8d075127a8bafb237..8b3522d2ff60d2ab79837b9cb32839c2f02efad5 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -81,6 +81,7 @@ import net.minecraft.world.level.storage.LevelData;
Expand All @@ -31328,7 +31328,7 @@ index e27d3547d1e19c137e05e6b8d075127a8bafb237..a12ef61b42779e37d439585e479c7d73

public static final Codec<ResourceKey<Level>> RESOURCE_KEY_CODEC = ResourceKey.codec(Registries.DIMENSION);
public static final ResourceKey<Level> OVERWORLD = ResourceKey.create(Registries.DIMENSION, ResourceLocation.withDefaultNamespace("overworld"));
@@ -199,6 +200,441 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -199,6 +200,451 @@ public abstract class Level implements LevelAccessor, AutoCloseable {

public abstract ResourceKey<LevelStem> getTypeKey();

Expand Down Expand Up @@ -31633,6 +31633,16 @@ index e27d3547d1e19c137e05e6b8d075127a8bafb237..a12ef61b42779e37d439585e479c7d73
+ null
+ );
+
+ final WorldBorder worldBorder = this.getWorldBorder();
+ if (worldBorder != null) {
+ aabbs.removeIf((final AABB aabb) -> {
+ return !worldBorder.isWithinBounds(aabb);
+ });
+ voxels.removeIf((final VoxelShape shape) -> {
+ return !worldBorder.isWithinBounds(shape.bounds());
+ });
+ }
+
+ // push voxels into aabbs
+ for (int i = 0, len = voxels.size(); i < len; ++i) {
+ aabbs.addAll(voxels.get(i).toAabbs());
Expand Down Expand Up @@ -31770,7 +31780,7 @@ index e27d3547d1e19c137e05e6b8d075127a8bafb237..a12ef61b42779e37d439585e479c7d73
protected Level(WritableLevelData worlddatamutable, ResourceKey<Level> resourcekey, RegistryAccess iregistrycustom, Holder<DimensionType> holder, Supplier<ProfilerFiller> supplier, boolean flag, boolean flag1, long i, int j, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider, org.bukkit.World.Environment env, java.util.function.Function<org.spigotmc.SpigotWorldConfig, io.papermc.paper.configuration.WorldConfiguration> paperWorldConfigCreator) { // Paper - create paper world config
this.spigotConfig = new org.spigotmc.SpigotWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) worlddatamutable).getLevelName()); // Spigot
this.paperConfig = paperWorldConfigCreator.apply(this.spigotConfig); // Paper - create paper world config
@@ -281,6 +717,11 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -281,6 +727,11 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
this.timings = new co.aikar.timings.WorldTimingsHandler(this); // Paper - code below can generate new world and access timings
this.entityLimiter = new org.spigotmc.TickLimiter(this.spigotConfig.entityMaxTickTime);
this.tileLimiter = new org.spigotmc.TickLimiter(this.spigotConfig.tileMaxTickTime);
Expand All @@ -31782,7 +31792,7 @@ index e27d3547d1e19c137e05e6b8d075127a8bafb237..a12ef61b42779e37d439585e479c7d73
}

// Paper start - Cancel hit for vanished players
@@ -549,7 +990,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -549,7 +1000,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
this.setBlocksDirty(blockposition, iblockdata1, iblockdata2);
}

Expand All @@ -31791,7 +31801,7 @@ index e27d3547d1e19c137e05e6b8d075127a8bafb237..a12ef61b42779e37d439585e479c7d73
this.sendBlockUpdated(blockposition, iblockdata1, iblockdata, i);
}

@@ -813,6 +1254,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -813,6 +1264,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
// Iterator<TickingBlockEntity> iterator = this.blockEntityTickers.iterator();
boolean flag = this.tickRateManager().runsNormally();

Expand All @@ -31800,7 +31810,7 @@ index e27d3547d1e19c137e05e6b8d075127a8bafb237..a12ef61b42779e37d439585e479c7d73
int tilesThisCycle = 0;
var toRemove = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<TickingBlockEntity>(); // Paper - Fix MC-117075; use removeAll
toRemove.add(null); // Paper - Fix MC-117075
@@ -828,6 +1271,11 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -828,6 +1281,11 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
// Spigot end
} else if (flag && this.shouldTickBlocksAt(tickingblockentity.getPos())) {
tickingblockentity.tick();
Expand All @@ -31812,7 +31822,7 @@ index e27d3547d1e19c137e05e6b8d075127a8bafb237..a12ef61b42779e37d439585e479c7d73
}
}
this.blockEntityTickers.removeAll(toRemove); // Paper - Fix MC-117075
@@ -850,12 +1298,20 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -850,12 +1308,20 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
entity.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DISCARD);
// Paper end - Prevent block entity and entity crashes
}
Expand All @@ -31834,7 +31844,7 @@ index e27d3547d1e19c137e05e6b8d075127a8bafb237..a12ef61b42779e37d439585e479c7d73
}
// Paper end - Option to prevent armor stands from doing entity lookups

@@ -949,7 +1405,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -949,7 +1415,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
}
// Paper end - Perf: Optimize capturedTileEntities lookup
// CraftBukkit end
Expand All @@ -31843,7 +31853,7 @@ index e27d3547d1e19c137e05e6b8d075127a8bafb237..a12ef61b42779e37d439585e479c7d73
}

public void setBlockEntity(BlockEntity blockEntity) {
@@ -1039,28 +1495,13 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -1039,28 +1505,13 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@Override
public List<Entity> getEntities(@Nullable Entity except, AABB box, Predicate<? super Entity> predicate) {
this.getProfiler().incrementCounter("getEntities");
Expand Down Expand Up @@ -31877,7 +31887,7 @@ index e27d3547d1e19c137e05e6b8d075127a8bafb237..a12ef61b42779e37d439585e479c7d73
}

@Override
@@ -1075,36 +1516,77 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
@@ -1075,36 +1526,77 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
this.getEntities(filter, box, predicate, result, Integer.MAX_VALUE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ index 02367ef1371dde94ff6c4cd40bd32e800d6ccaaf..7b0fc7135bc107103dcaed6dc0707b18
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 a12ef61b42779e37d439585e479c7d73a5abf226..78dc1e76a579d135dd0eee989acc9f7de2fd5996 100644
index 8b3522d2ff60d2ab79837b9cb32839c2f02efad5..b5f0590e85b00b728f833f7c17ca1c1cf57957cd 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -782,7 +782,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
@@ -792,7 +792,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
// Paper end

public boolean isInWorldBounds(BlockPos pos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ index bb8e962e63c7a2d931f9bd7f7c002aa35cfa5fd3..0fa131a6c98adb498fc8d534e0e39647
default BlockHitResult clip(ClipContext raytrace1, BlockPos blockposition) {
// Paper start - Add predicate for blocks when raytracing
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index 78dc1e76a579d135dd0eee989acc9f7de2fd5996..559855092c375db066cad35018958718014633ff 100644
index b5f0590e85b00b728f833f7c17ca1c1cf57957cd..6b7f61d0418cc1203726d4bb99ba0a996539b9c4 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -774,10 +774,87 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
@@ -784,10 +784,87 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
return null;
}

Expand Down
8 changes: 4 additions & 4 deletions patches/server/1002-Anti-Xray.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ index 9b1a6d8351fb473eec75a2fd08fb892b770e3586..0d0b07c9199be9ca0d5ac3feb1d44f14
}
// Paper end - Send empty chunk
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index 01a50831285fa99782c18c66e6d49c78026e04e0..f4cffb4e0856126ea3dded5ab6a663d6bfcb4e26 100644
index 11fa27f6fdf763f589fba46337a144f7bb02adb8..070071096d30d368c25e748834f2b695a93903d2 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -172,6 +172,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
Expand All @@ -1179,7 +1179,7 @@ index 01a50831285fa99782c18c66e6d49c78026e04e0..f4cffb4e0856126ea3dded5ab6a663d6
public final co.aikar.timings.WorldTimingsHandler timings; // Paper
public static BlockPos lastPhysicsProblem; // Spigot
private org.spigotmc.TickLimiter entityLimiter;
@@ -641,7 +642,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
@@ -651,7 +652,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
}
// Paper end - optimise collisions

Expand All @@ -1188,15 +1188,15 @@ index 01a50831285fa99782c18c66e6d49c78026e04e0..f4cffb4e0856126ea3dded5ab6a663d6
this.spigotConfig = new org.spigotmc.SpigotWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) worlddatamutable).getLevelName()); // Spigot
this.paperConfig = paperWorldConfigCreator.apply(this.spigotConfig); // Paper - create paper world config
this.generator = gen;
@@ -728,6 +729,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
@@ -738,6 +739,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
this.minSection = ca.spottedleaf.moonrise.common.util.WorldUtil.getMinSection(this);
this.maxSection = ca.spottedleaf.moonrise.common.util.WorldUtil.getMaxSection(this);
// Paper end - optimise collisions
+ this.chunkPacketBlockController = this.paperConfig().anticheat.antiXray.enabled ? new com.destroystokyo.paper.antixray.ChunkPacketBlockControllerAntiXray(this, executor) : com.destroystokyo.paper.antixray.ChunkPacketBlockController.NO_OPERATION_INSTANCE; // Paper - Anti-Xray
}

// Paper start - Cancel hit for vanished players
@@ -1005,6 +1007,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
@@ -1015,6 +1017,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
// CraftBukkit end

BlockState iblockdata1 = chunk.setBlockState(pos, state, (flags & 64) != 0, (flags & 1024) == 0); // CraftBukkit custom NO_PLACE flag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2035,10 +2035,10 @@ index 8a3f58e6dfdb0af767be334087748f93c06ec797..7ba34da235ea536b929e1c8bc2cc39e4

EntityCallbacks() {}
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index f4cffb4e0856126ea3dded5ab6a663d6bfcb4e26..f59c544b72a8d5c00f83ed51c54d2bba0e8a05de 100644
index 070071096d30d368c25e748834f2b695a93903d2..260ce9660346774bda4c93da17596b968fdc1611 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -1971,4 +1971,14 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
@@ -1981,4 +1981,14 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
}
}
// Paper end - notify observers even if grow failed
Expand Down
4 changes: 2 additions & 2 deletions patches/server/1026-Improved-Watchdog-Support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,10 @@ index 2510589400b3012b827efcab477c6483d9d55901..43487a9ee202c5b0e5a416519939111f
}
}
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index f59c544b72a8d5c00f83ed51c54d2bba0e8a05de..b16c3beda0fc7d7d06cfc82f450165096a88bade 100644
index 260ce9660346774bda4c93da17596b968fdc1611..a72a189f537e0a64c2c31e7eefbb49fa896a6f3c 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -1377,6 +1377,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
@@ -1387,6 +1387,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
try {
tickConsumer.accept(entity);
} catch (Throwable throwable) {
Expand Down

0 comments on commit 8b23018

Please sign in to comment.