From 12e0268dab510a0ae204782ca96f06f1e9000dbf Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Sat, 14 Dec 2024 20:27:07 +0000 Subject: [PATCH] net/minecraft/core --- .../net/minecraft/core/BlockPos.java.patch | 84 ++++--------------- .../net/minecraft/core/Direction.java.patch | 22 ++--- .../net/minecraft/core/Holder.java.patch | 2 +- .../minecraft/core/MappedRegistry.java.patch | 10 +-- .../net/minecraft/core/Rotations.java.patch | 4 +- .../net/minecraft/core/Vec3i.java.patch | 16 ++-- 6 files changed, 44 insertions(+), 94 deletions(-) rename paper-server/patches/{unapplied => sources}/net/minecraft/core/BlockPos.java.patch (57%) rename paper-server/patches/{unapplied => sources}/net/minecraft/core/Direction.java.patch (75%) rename paper-server/patches/{unapplied => sources}/net/minecraft/core/Holder.java.patch (94%) rename paper-server/patches/{unapplied => sources}/net/minecraft/core/MappedRegistry.java.patch (94%) rename paper-server/patches/{unapplied => sources}/net/minecraft/core/Rotations.java.patch (84%) rename paper-server/patches/{unapplied => sources}/net/minecraft/core/Vec3i.java.patch (70%) diff --git a/paper-server/patches/unapplied/net/minecraft/core/BlockPos.java.patch b/paper-server/patches/sources/net/minecraft/core/BlockPos.java.patch similarity index 57% rename from paper-server/patches/unapplied/net/minecraft/core/BlockPos.java.patch rename to paper-server/patches/sources/net/minecraft/core/BlockPos.java.patch index 7858f6cef1..13a67b0e34 100644 --- a/paper-server/patches/unapplied/net/minecraft/core/BlockPos.java.patch +++ b/paper-server/patches/sources/net/minecraft/core/BlockPos.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/core/BlockPos.java +++ b/net/minecraft/core/BlockPos.java -@@ -158,67 +158,84 @@ +@@ -158,67 +_,84 @@ @Override public BlockPos above() { @@ -21,9 +21,9 @@ } @Override - public BlockPos below(int i) { -- return this.relative(Direction.DOWN, i); -+ return i == 0 ? this.immutable() : new BlockPos(this.getX(), this.getY() - i, this.getZ()); // Paper - Perf: Optimize BlockPosition + public BlockPos below(int distance) { +- return this.relative(Direction.DOWN, distance); ++ return distance == 0 ? this.immutable() : new BlockPos(this.getX(), this.getY() - distance, this.getZ()); // Paper - Perf: Optimize BlockPosition } @Override @@ -76,6 +76,7 @@ @Override public BlockPos relative(Direction direction) { +- return new BlockPos(this.getX() + direction.getStepX(), this.getY() + direction.getStepY(), this.getZ() + direction.getStepZ()); + // Paper start - Perf: Optimize BlockPosition + switch(direction) { + case UP: @@ -91,64 +92,13 @@ + case EAST: + return new BlockPos(this.getX() + 1, this.getY(), this.getZ()); + default: - return new BlockPos(this.getX() + direction.getStepX(), this.getY() + direction.getStepY(), this.getZ() + direction.getStepZ()); ++ return new BlockPos(this.getX() + direction.getStepX(), this.getY() + direction.getStepY(), this.getZ() + direction.getStepZ()); + } + // Paper end - Perf: Optimize BlockPosition } @Override -@@ -324,9 +341,11 @@ - - public static Iterable withinManhattan(BlockPos center, int rangeX, int rangeY, int rangeZ) { - int i = rangeX + rangeY + rangeZ; -- int j = center.getX(); -- int k = center.getY(); -- int l = center.getZ(); -+ // Paper start - rename variables to fix conflict with anonymous class (remap fix) -+ int centerX = center.getX(); -+ int centerY = center.getY(); -+ int centerZ = center.getZ(); -+ // Paper end - return () -> new AbstractIterator() { - private final BlockPos.MutableBlockPos cursor = new BlockPos.MutableBlockPos(); - private int currentDepth; -@@ -340,7 +359,7 @@ - protected BlockPos computeNext() { - if (this.zMirror) { - this.zMirror = false; -- this.cursor.setZ(l - (this.cursor.getZ() - l)); -+ this.cursor.setZ(centerZ - (this.cursor.getZ() - centerZ)); // Paper - remap fix - return this.cursor; - } else { - BlockPos blockPos; -@@ -366,7 +385,7 @@ - int k = this.currentDepth - Math.abs(i) - Math.abs(j); - if (k <= rangeZ) { - this.zMirror = k != 0; -- blockPos = this.cursor.set(j + i, k + j, l + k); -+ blockPos = this.cursor.set(centerX + i, centerY + j, centerZ + k); // Paper - remap fix - } - } - -@@ -444,12 +463,12 @@ - if (this.index == l) { - return this.endOfData(); - } else { -- int i = this.index % i; -- int j = this.index / i; -- int k = j % j; -- int l = j / j; -+ int offsetX = this.index % i; // Paper - decomp fix -+ int u = this.index / i; // Paper - decomp fix -+ int offsetY = u % j; // Paper - decomp fix -+ int offsetZ = u / j; // Paper - decomp fix - this.index++; -- return this.cursor.set(startX + i, startY + k, startZ + l); -+ return this.cursor.set(startX + offsetX, startY + offsetY, startZ + offsetZ); // Paper - decomp fix - } - } - }; -@@ -569,9 +588,9 @@ +@@ -573,9 +_,9 @@ } public BlockPos.MutableBlockPos set(int x, int y, int z) { @@ -161,26 +111,26 @@ return this; } -@@ -636,19 +655,19 @@ +@@ -638,19 +_,19 @@ @Override - public BlockPos.MutableBlockPos setX(int i) { -- super.setX(i); -+ this.x = i; // Paper - Perf: Manually inline methods in BlockPosition + public BlockPos.MutableBlockPos setX(int x) { +- super.setX(x); ++ this.x = x; // Paper - Perf: Manually inline methods in BlockPosition return this; } @Override - public BlockPos.MutableBlockPos setY(int i) { -- super.setY(i); -+ this.y = i; // Paper - Perf: Manually inline methods in BlockPosition + public BlockPos.MutableBlockPos setY(int y) { +- super.setY(y); ++ this.y = y; // Paper - Perf: Manually inline methods in BlockPosition return this; } @Override - public BlockPos.MutableBlockPos setZ(int i) { -- super.setZ(i); -+ this.z = i; // Paper - Perf: Manually inline methods in BlockPosition + public BlockPos.MutableBlockPos setZ(int z) { +- super.setZ(z); ++ this.z = z; // Paper - Perf: Manually inline methods in BlockPosition return this; } diff --git a/paper-server/patches/unapplied/net/minecraft/core/Direction.java.patch b/paper-server/patches/sources/net/minecraft/core/Direction.java.patch similarity index 75% rename from paper-server/patches/unapplied/net/minecraft/core/Direction.java.patch rename to paper-server/patches/sources/net/minecraft/core/Direction.java.patch index a0a77c5f10..1859b6bb9f 100644 --- a/paper-server/patches/unapplied/net/minecraft/core/Direction.java.patch +++ b/paper-server/patches/sources/net/minecraft/core/Direction.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/core/Direction.java +++ b/net/minecraft/core/Direction.java -@@ -57,6 +57,12 @@ +@@ -57,6 +_,12 @@ .sorted(Comparator.comparingInt(direction -> direction.data2d)) .toArray(Direction[]::new); @@ -11,21 +11,21 @@ + // Paper end - Perf: Inline shift direction fields + private Direction( - final int id, - final int idOpposite, -@@ -74,6 +80,11 @@ - this.axisDirection = direction; - this.normal = vector; - this.normalVec3 = Vec3.atLowerCornerOf(vector); + final int data3d, + final int oppositeIndex, +@@ -74,6 +_,11 @@ + this.axisDirection = axisDirection; + this.normal = normal; + this.normalVec3 = Vec3.atLowerCornerOf(normal); + // Paper start - Perf: Inline shift direction fields -+ this.adjX = vector.getX(); -+ this.adjY = vector.getY(); -+ this.adjZ = vector.getZ(); ++ this.adjX = normal.getX(); ++ this.adjY = normal.getY(); ++ this.adjZ = normal.getZ(); + // Paper end - Perf: Inline shift direction fields } public static Direction[] orderedByNearest(Entity entity) { -@@ -247,15 +258,15 @@ +@@ -247,15 +_,15 @@ } public int getStepX() { diff --git a/paper-server/patches/unapplied/net/minecraft/core/Holder.java.patch b/paper-server/patches/sources/net/minecraft/core/Holder.java.patch similarity index 94% rename from paper-server/patches/unapplied/net/minecraft/core/Holder.java.patch rename to paper-server/patches/sources/net/minecraft/core/Holder.java.patch index 634a2b2190..51a81bf5f3 100644 --- a/paper-server/patches/unapplied/net/minecraft/core/Holder.java.patch +++ b/paper-server/patches/sources/net/minecraft/core/Holder.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/core/Holder.java +++ b/net/minecraft/core/Holder.java -@@ -230,7 +230,7 @@ +@@ -230,7 +_,7 @@ } void bindTags(Collection> tags) { diff --git a/paper-server/patches/unapplied/net/minecraft/core/MappedRegistry.java.patch b/paper-server/patches/sources/net/minecraft/core/MappedRegistry.java.patch similarity index 94% rename from paper-server/patches/unapplied/net/minecraft/core/MappedRegistry.java.patch rename to paper-server/patches/sources/net/minecraft/core/MappedRegistry.java.patch index 4d3c8b552e..400d714abe 100644 --- a/paper-server/patches/unapplied/net/minecraft/core/MappedRegistry.java.patch +++ b/paper-server/patches/sources/net/minecraft/core/MappedRegistry.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/core/MappedRegistry.java +++ b/net/minecraft/core/MappedRegistry.java -@@ -33,11 +33,11 @@ +@@ -33,11 +_,11 @@ public class MappedRegistry implements WritableRegistry { private final ResourceKey> key; private final ObjectList> byId = new ObjectArrayList<>(256); @@ -17,17 +17,17 @@ private Lifecycle registryLifecycle; private final Map, HolderSet.Named> frozenTags = new IdentityHashMap<>(); MappedRegistry.TagSet allTags = MappedRegistry.TagSet.unbound(); -@@ -508,5 +508,13 @@ - void forEach(BiConsumer, ? super HolderSet.Named> consumer); +@@ -509,4 +_,13 @@ Stream> getTags(); -+ } + } ++ + // Paper start + // used to clear intrusive holders from GameEvent, Item, Block, EntityType, and Fluid from unused instances of those types + public void clearIntrusiveHolder(final T instance) { + if (this.unregisteredIntrusiveHolders != null) { + this.unregisteredIntrusiveHolders.remove(instance); + } - } ++ } + // Paper end } diff --git a/paper-server/patches/unapplied/net/minecraft/core/Rotations.java.patch b/paper-server/patches/sources/net/minecraft/core/Rotations.java.patch similarity index 84% rename from paper-server/patches/unapplied/net/minecraft/core/Rotations.java.patch rename to paper-server/patches/sources/net/minecraft/core/Rotations.java.patch index 29c5bfc220..0b17d3ac2a 100644 --- a/paper-server/patches/unapplied/net/minecraft/core/Rotations.java.patch +++ b/paper-server/patches/sources/net/minecraft/core/Rotations.java.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/core/Rotations.java +++ b/net/minecraft/core/Rotations.java -@@ -34,6 +34,18 @@ - this(serialized.getFloat(0), serialized.getFloat(1), serialized.getFloat(2)); +@@ -34,6 +_,18 @@ + this(tag.getFloat(0), tag.getFloat(1), tag.getFloat(2)); } + // Paper start - faster alternative constructor diff --git a/paper-server/patches/unapplied/net/minecraft/core/Vec3i.java.patch b/paper-server/patches/sources/net/minecraft/core/Vec3i.java.patch similarity index 70% rename from paper-server/patches/unapplied/net/minecraft/core/Vec3i.java.patch rename to paper-server/patches/sources/net/minecraft/core/Vec3i.java.patch index 8c19b63ae6..cd374686c0 100644 --- a/paper-server/patches/unapplied/net/minecraft/core/Vec3i.java.patch +++ b/paper-server/patches/sources/net/minecraft/core/Vec3i.java.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/core/Vec3i.java +++ b/net/minecraft/core/Vec3i.java -@@ -16,9 +16,9 @@ - vec -> IntStream.of(vec.getX(), vec.getY(), vec.getZ()) +@@ -16,9 +_,9 @@ + vec3i -> IntStream.of(vec3i.getX(), vec3i.getY(), vec3i.getZ()) ); public static final Vec3i ZERO = new Vec3i(0, 0, 0); - private int x; @@ -11,15 +11,15 @@ + protected int y; // Paper - Perf: Manually inline methods in BlockPosition; protected + protected int z; // Paper - Perf: Manually inline methods in BlockPosition; protected - public static Codec offsetCodec(int maxAbsValue) { + public static Codec offsetCodec(int maxOffset) { return CODEC.validate( -@@ -35,12 +35,12 @@ +@@ -35,12 +_,12 @@ } @Override -- public boolean equals(Object object) { -+ public final boolean equals(Object object) { // Paper - Perf: Final for inline - return this == object || object instanceof Vec3i vec3i && this.getX() == vec3i.getX() && this.getY() == vec3i.getY() && this.getZ() == vec3i.getZ(); +- public boolean equals(Object other) { ++ public final boolean equals(Object other) { // Paper - Perf: Final for inline + return this == other || other instanceof Vec3i vec3i && this.getX() == vec3i.getX() && this.getY() == vec3i.getY() && this.getZ() == vec3i.getZ(); } @Override @@ -28,7 +28,7 @@ return (this.getY() + this.getZ() * 31) * 31 + this.getX(); } -@@ -53,15 +53,15 @@ +@@ -53,15 +_,15 @@ } }