From c4ef2add487429ec5aae64c1c4ef0ed3c39934d0 Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 24 Nov 2021 14:50:33 -0800 Subject: [PATCH] patches and remap fixes --- ...0309-Add-PufferFishStateChangeEvent.patch} | 0 .../0310-Add-BellRevealRaiderEvent.patch} | 0 patches/server/0005-MC-Dev-fixes.patch | 36 ++++++++ ...0662-Add-PufferFishStateChangeEvent.patch} | 0 ...erBucketEmptyEvent-result-itemstack.patch} | 8 +- ...ttedContainer-instead-of-ReentrantLo.patch | 91 ++++++++++++++++++ ...-to-fix-items-merging-through-walls.patch} | 9 +- .../0666-Add-BellRevealRaiderEvent.patch} | 8 +- ...ttedContainer-instead-of-ReentrantLo.patch | 92 ------------------- 9 files changed, 139 insertions(+), 105 deletions(-) rename patches/{unapplied/api/0314-Add-PufferFishStateChangeEvent.patch => api/0309-Add-PufferFishStateChangeEvent.patch} (100%) rename patches/{unapplied/api/0315-Add-BellRevealRaiderEvent.patch => api/0310-Add-BellRevealRaiderEvent.patch} (100%) rename patches/{unapplied/server/0691-Add-PufferFishStateChangeEvent.patch => server/0662-Add-PufferFishStateChangeEvent.patch} (100%) rename patches/{unapplied/server/0693-Fix-PlayerBucketEmptyEvent-result-itemstack.patch => server/0663-Fix-PlayerBucketEmptyEvent-result-itemstack.patch} (86%) create mode 100644 patches/server/0664-Synchronize-PalettedContainer-instead-of-ReentrantLo.patch rename patches/{unapplied/server/0695-Add-option-to-fix-items-merging-through-walls.patch => server/0665-Add-option-to-fix-items-merging-through-walls.patch} (87%) rename patches/{unapplied/server/0696-Add-BellRevealRaiderEvent.patch => server/0666-Add-BellRevealRaiderEvent.patch} (84%) delete mode 100644 patches/unapplied/server/0694-Synchronize-PalettedContainer-instead-of-ReentrantLo.patch diff --git a/patches/unapplied/api/0314-Add-PufferFishStateChangeEvent.patch b/patches/api/0309-Add-PufferFishStateChangeEvent.patch similarity index 100% rename from patches/unapplied/api/0314-Add-PufferFishStateChangeEvent.patch rename to patches/api/0309-Add-PufferFishStateChangeEvent.patch diff --git a/patches/unapplied/api/0315-Add-BellRevealRaiderEvent.patch b/patches/api/0310-Add-BellRevealRaiderEvent.patch similarity index 100% rename from patches/unapplied/api/0315-Add-BellRevealRaiderEvent.patch rename to patches/api/0310-Add-BellRevealRaiderEvent.patch diff --git a/patches/server/0005-MC-Dev-fixes.patch b/patches/server/0005-MC-Dev-fixes.patch index 27c7c04c0..dd3c83506 100644 --- a/patches/server/0005-MC-Dev-fixes.patch +++ b/patches/server/0005-MC-Dev-fixes.patch @@ -305,3 +305,39 @@ index 0f7950458dc2dfac51ed0d56f1790395f0b03bc2..fa4544541b9c5f163b633596e73a5197 public static class BiomeBuilder { @Nullable private Biome.Precipitation precipitation; +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 3f9929ac29f23068d233f164fbe6a562aba5a1b5..d030baca9dd3c34d14653094c139d853c67ac332 100644 +--- a/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java ++++ b/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java +@@ -275,10 +275,6 @@ public class PalettedContainer implements PaletteResize { + } + + static record Configuration(Palette.Factory factory, int bits) { +- Configuration(Palette.Factory factory, int i) { +- this.factory = factory; +- this.bits = i; +- } + + public PalettedContainer.Data createData(IdMap idList, PaletteResize listener, int size) { + BitStorage bitStorage = (BitStorage)(this.bits == 0 ? new ZeroBitStorage(size) : new SimpleBitStorage(this.bits, size)); +@@ -293,9 +289,6 @@ public class PalettedContainer implements PaletteResize { + } + + static record Data(PalettedContainer.Configuration configuration, BitStorage storage, Palette palette) { +- final BitStorage storage; +- final Palette palette; +- + public void copyFrom(Palette palette, BitStorage storage) { + for(int i = 0; i < storage.getSize(); ++i) { + T object = palette.valueFor(storage.get(i)); +@@ -316,10 +309,6 @@ public class PalettedContainer implements PaletteResize { + } + + static record DiscData(List paletteEntries, Optional storage) { +- DiscData(List list, Optional optional) { +- this.paletteEntries = list; +- this.storage = optional; +- } + } + + public abstract static class Strategy { diff --git a/patches/unapplied/server/0691-Add-PufferFishStateChangeEvent.patch b/patches/server/0662-Add-PufferFishStateChangeEvent.patch similarity index 100% rename from patches/unapplied/server/0691-Add-PufferFishStateChangeEvent.patch rename to patches/server/0662-Add-PufferFishStateChangeEvent.patch diff --git a/patches/unapplied/server/0693-Fix-PlayerBucketEmptyEvent-result-itemstack.patch b/patches/server/0663-Fix-PlayerBucketEmptyEvent-result-itemstack.patch similarity index 86% rename from patches/unapplied/server/0693-Fix-PlayerBucketEmptyEvent-result-itemstack.patch rename to patches/server/0663-Fix-PlayerBucketEmptyEvent-result-itemstack.patch index 8745cea68..2b9de8138 100644 --- a/patches/unapplied/server/0693-Fix-PlayerBucketEmptyEvent-result-itemstack.patch +++ b/patches/server/0663-Fix-PlayerBucketEmptyEvent-result-itemstack.patch @@ -6,10 +6,10 @@ Subject: [PATCH] Fix PlayerBucketEmptyEvent result itemstack Fixes SPIGOT-2560: https://hub.spigotmc.org/jira/projects/SPIGOT/issues/SPIGOT-2560 diff --git a/src/main/java/net/minecraft/world/item/BucketItem.java b/src/main/java/net/minecraft/world/item/BucketItem.java -index 650b59b69eb12112bc71e5ff164767e3118e1c2a..69c992ef0c526adf35907de7726832605187beb6 100644 +index 5406acd65d4e1146f3bd7340ff9a1954a5c39ddb..b5a5c56fbb66c17dd2e2d1f4d69d2b1826cd4951 100644 --- a/src/main/java/net/minecraft/world/item/BucketItem.java +++ b/src/main/java/net/minecraft/world/item/BucketItem.java -@@ -41,6 +41,8 @@ import org.bukkit.event.player.PlayerBucketFillEvent; +@@ -39,6 +39,8 @@ import org.bukkit.event.player.PlayerBucketFillEvent; public class BucketItem extends Item implements DispensibleContainerItem { @@ -18,7 +18,7 @@ index 650b59b69eb12112bc71e5ff164767e3118e1c2a..69c992ef0c526adf35907de772683260 public final Fluid content; public BucketItem(Fluid fluid, Item.Properties settings) { -@@ -122,6 +124,13 @@ public class BucketItem extends Item implements DispensibleContainerItem { +@@ -120,6 +122,13 @@ public class BucketItem extends Item implements DispensibleContainerItem { } public static ItemStack getEmptySuccessItem(ItemStack stack, Player player) { @@ -32,7 +32,7 @@ index 650b59b69eb12112bc71e5ff164767e3118e1c2a..69c992ef0c526adf35907de772683260 return !player.getAbilities().instabuild ? new ItemStack(Items.BUCKET) : stack; } -@@ -154,6 +163,9 @@ public class BucketItem extends Item implements DispensibleContainerItem { +@@ -152,6 +161,9 @@ public class BucketItem extends Item implements DispensibleContainerItem { ((ServerPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541 return false; } diff --git a/patches/server/0664-Synchronize-PalettedContainer-instead-of-ReentrantLo.patch b/patches/server/0664-Synchronize-PalettedContainer-instead-of-ReentrantLo.patch new file mode 100644 index 000000000..5d4a0e1e8 --- /dev/null +++ b/patches/server/0664-Synchronize-PalettedContainer-instead-of-ReentrantLo.patch @@ -0,0 +1,91 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Aikar +Date: Fri, 29 May 2020 20:29:02 -0400 +Subject: [PATCH] Synchronize PalettedContainer instead of ReentrantLock + +Mojang has flaws in their logic about chunks being concurrently +wrote to. So we constantly see crashes around multiple threads writing. + +Additionally, java has optimized synchronization so well that its +in many times faster than trying to manage read wrote locks for low +contention situations. + +And this is extremely a low contention situation. + +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 d030baca9dd3c34d14653094c139d853c67ac332..bd003e980ac0fe8c4e4b5df5b4002ae3ada39862 100644 +--- a/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java ++++ b/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java +@@ -35,15 +35,15 @@ public class PalettedContainer implements PaletteResize { + private final ThreadingDetector threadingDetector = new ThreadingDetector("PalettedContainer"); + + public void acquire() { +- this.threadingDetector.checkAndLock(); ++ // this.threadingDetector.checkAndLock(); // Paper - disable this - use proper synchronization + } + + public void release() { +- this.threadingDetector.checkAndUnlock(); ++ // this.threadingDetector.checkAndUnlock(); // Paper - disable this + } + + public static Codec> codec(IdMap idList, Codec entryCodec, PalettedContainer.Strategy provider, T object) { +- return RecordCodecBuilder.create((instance) -> { ++ return RecordCodecBuilder.>create((instance) -> { // Paper - decompile fixes + return instance.group(entryCodec.mapResult(ExtraCodecs.orElsePartial(object)).listOf().fieldOf("palette").forGetter(PalettedContainer.DiscData::paletteEntries), Codec.LONG_STREAM.optionalFieldOf("data").forGetter(PalettedContainer.DiscData::storage)).apply(instance, PalettedContainer.DiscData::new); + }).comapFlatMap((serialized) -> { + return read(idList, provider, serialized); +@@ -85,7 +85,7 @@ public class PalettedContainer implements PaletteResize { + return data2.palette.idFor(object); + } + +- public T getAndSet(int x, int y, int z, T value) { ++ public synchronized T getAndSet(int x, int y, int z, T value) { // Paper - synchronize + this.acquire(); + + Object var5; +@@ -108,7 +108,7 @@ public class PalettedContainer implements PaletteResize { + return this.data.palette.valueFor(j); + } + +- public void set(int x, int y, int z, T value) { ++ public synchronized void set(int x, int y, int z, T value) { // Paper - synchronize + this.acquire(); + + try { +@@ -142,7 +142,7 @@ public class PalettedContainer implements PaletteResize { + }); + } + +- public void read(FriendlyByteBuf buf) { ++ public synchronized void read(FriendlyByteBuf buf) { // Paper - synchronize + this.acquire(); + + try { +@@ -157,7 +157,7 @@ public class PalettedContainer implements PaletteResize { + + } + +- public void write(FriendlyByteBuf buf) { ++ public synchronized void write(FriendlyByteBuf buf) { // Paper - synchronize + this.acquire(); + + try { +@@ -168,7 +168,7 @@ public class PalettedContainer implements PaletteResize { + + } + +- private static DataResult> read(IdMap idList, PalettedContainer.Strategy provider, PalettedContainer.DiscData serialized) { ++ private static synchronized DataResult> read(IdMap idList, PalettedContainer.Strategy provider, PalettedContainer.DiscData serialized) { // Paper - synchronize + List list = serialized.paletteEntries(); + int i = provider.size(); + int j = provider.calculateBitsForSerialization(idList, list.size()); +@@ -207,7 +207,7 @@ public class PalettedContainer implements PaletteResize { + return DataResult.success(new PalettedContainer<>(idList, provider, configuration, bitStorage, list)); + } + +- private PalettedContainer.DiscData write(IdMap idList, PalettedContainer.Strategy provider) { ++ private synchronized PalettedContainer.DiscData write(IdMap idList, PalettedContainer.Strategy provider) { // Paper - synchronize + this.acquire(); + + PalettedContainer.DiscData var12; diff --git a/patches/unapplied/server/0695-Add-option-to-fix-items-merging-through-walls.patch b/patches/server/0665-Add-option-to-fix-items-merging-through-walls.patch similarity index 87% rename from patches/unapplied/server/0695-Add-option-to-fix-items-merging-through-walls.patch rename to patches/server/0665-Add-option-to-fix-items-merging-through-walls.patch index ffc5ef9a2..4c3761cc7 100644 --- a/patches/unapplied/server/0695-Add-option-to-fix-items-merging-through-walls.patch +++ b/patches/server/0665-Add-option-to-fix-items-merging-through-walls.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Add option to fix items merging through walls diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java -index 88e6919e7c850727100a5739ed3ac332bc004b40..d8ed734450a14ffeed6d7a42eed238645b0cb380 100644 +index cc04fe5b0275ef5466fad2ca84f2273d274baadd..06878b0a9b57e3024179edea70e763a7893fbb95 100644 --- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java +++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java -@@ -863,5 +863,10 @@ public class PaperWorldConfig { +@@ -772,4 +772,9 @@ public class PaperWorldConfig { private void mapItemFrameCursorLimit() { mapItemFrameCursorLimit = getInt("map-item-frame-cursor-limit", mapItemFrameCursorLimit); } @@ -18,12 +18,11 @@ index 88e6919e7c850727100a5739ed3ac332bc004b40..d8ed734450a14ffeed6d7a42eed23864 + fixItemsMergingThroughWalls = getBoolean("fix-items-merging-through-walls", fixItemsMergingThroughWalls); + } } - diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java -index e0c13a112c95eed9867d4608e18dc797b0c9c9cf..158719d46c96bb733a00e08c8285f41a48406abf 100644 +index 5a6534904e977b5ffbd55d05c4b65f02b3995910..7897b3324bc8d5a33cd3cd144b9fae9ffdc9241e 100644 --- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java +++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java -@@ -241,6 +241,14 @@ public class ItemEntity extends Entity { +@@ -240,6 +240,14 @@ public class ItemEntity extends Entity { ItemEntity entityitem = (ItemEntity) iterator.next(); if (entityitem.isMergable()) { diff --git a/patches/unapplied/server/0696-Add-BellRevealRaiderEvent.patch b/patches/server/0666-Add-BellRevealRaiderEvent.patch similarity index 84% rename from patches/unapplied/server/0696-Add-BellRevealRaiderEvent.patch rename to patches/server/0666-Add-BellRevealRaiderEvent.patch index c434ce8f0..069c85f11 100644 --- a/patches/unapplied/server/0696-Add-BellRevealRaiderEvent.patch +++ b/patches/server/0666-Add-BellRevealRaiderEvent.patch @@ -5,13 +5,13 @@ Subject: [PATCH] Add BellRevealRaiderEvent diff --git a/src/main/java/net/minecraft/world/level/block/entity/BellBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BellBlockEntity.java -index a71bf0802d04217dd11086901b7148957d32ca89..b4a5da7e2baecc856c75283cc776398042d17108 100644 +index b06e911acb825883c93da73358fa81653e8a0d4a..41e139c750dd3aadb7692e362e2d83f43799c905 100644 --- a/src/main/java/net/minecraft/world/level/block/entity/BellBlockEntity.java +++ b/src/main/java/net/minecraft/world/level/block/entity/BellBlockEntity.java @@ -138,7 +138,7 @@ public class BellBlockEntity extends BlockEntity { private static void makeRaidersGlow(Level world, BlockPos pos, List hearingEntities) { - hearingEntities.stream().filter((livingEntity) -> { - return isRaiderWithinRange(pos, livingEntity); + hearingEntities.stream().filter((entity) -> { + return isRaiderWithinRange(pos, entity); - }).forEach(BellBlockEntity::glow); + }).forEach(entity -> glow(entity, pos)); // Paper - pass BlockPos } @@ -24,7 +24,7 @@ index a71bf0802d04217dd11086901b7148957d32ca89..b4a5da7e2baecc856c75283cc7763980 - private static void glow(LivingEntity entity) { + // Paper start + private static void glow(LivingEntity entity) { glow(entity, null); } -+ private static void glow(LivingEntity entity, BlockPos pos) { ++ private static void glow(LivingEntity entity, @javax.annotation.Nullable BlockPos pos) { + if (pos != null && !new io.papermc.paper.event.block.BellRevealRaiderEvent(entity.level.getWorld().getBlockAt(net.minecraft.server.MCUtil.toLocation(entity.level, pos)), entity.getBukkitEntity()).callEvent()) return; + // Paper end entity.addEffect(new MobEffectInstance(MobEffects.GLOWING, 60)); diff --git a/patches/unapplied/server/0694-Synchronize-PalettedContainer-instead-of-ReentrantLo.patch b/patches/unapplied/server/0694-Synchronize-PalettedContainer-instead-of-ReentrantLo.patch deleted file mode 100644 index 2584559a0..000000000 --- a/patches/unapplied/server/0694-Synchronize-PalettedContainer-instead-of-ReentrantLo.patch +++ /dev/null @@ -1,92 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Aikar -Date: Fri, 29 May 2020 20:29:02 -0400 -Subject: [PATCH] Synchronize PalettedContainer instead of ReentrantLock - -Mojang has flaws in their logic about chunks being concurrently -wrote to. So we constantly see crashes around multiple threads writing. - -Additionally, java has optimized synchronization so well that its -in many times faster than trying to manage read wrote locks for low -contention situations. - -And this is extremely a low contention situation. - -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 ac51089aae57a5f1d2411367ff177e058702894c..554474d4b2e57d8a005b3c3b9b23f32a62243058 100644 ---- a/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java -+++ b/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java -@@ -37,16 +37,18 @@ public class PalettedContainer implements PaletteResize { - private final DebugBuffer> traces = null; - - public void acquire() { -+ /* // Paper start - disable this - use proper synchronization - if (this.traces != null) { - Thread thread = Thread.currentThread(); - this.traces.push(Pair.of(thread, thread.getStackTrace())); - } - - ThreadingDetector.checkAndLock(this.lock, this.traces, "PalettedContainer"); -+ */ // Paper end - } - - public void release() { -- this.lock.release(); -+ //this.lock.release(); // Paper - disable this - } - - // Paper start - Anti-Xray - Add preset values -@@ -129,7 +131,7 @@ public class PalettedContainer implements PaletteResize { - return this.palette.idFor(objectAdded); - } - -- public T getAndSet(int x, int y, int z, T value) { -+ public synchronized T getAndSet(int x, int y, int z, T value) { // Paper - synchronize - Object var6; - try { - this.acquire(); -@@ -153,7 +155,7 @@ public class PalettedContainer implements PaletteResize { - return (T)(object == null ? this.defaultValue : object); - } - -- public void set(int i, int j, int k, T object) { -+ public synchronized void set(int i, int j, int k, T object) { // Paper - synchronize - try { - this.acquire(); - this.set(getIndex(i, j, k), object); -@@ -177,7 +179,7 @@ public class PalettedContainer implements PaletteResize { - return (T)(object == null ? this.defaultValue : object); - } - -- public void read(FriendlyByteBuf buf) { -+ public synchronized void read(FriendlyByteBuf buf) { // Paper - synchronize - try { - this.acquire(); - int i = buf.readByte(); -@@ -201,7 +203,7 @@ public class PalettedContainer implements PaletteResize { - - // Paper start - Anti-Xray - Add chunk packet info - @Deprecated public void write(FriendlyByteBuf buf) { write(buf, null, 0); } // Notice for updates: Please make sure this method isn't used anywhere -- public void write(FriendlyByteBuf buf, com.destroystokyo.paper.antixray.ChunkPacketInfo chunkPacketInfo, int bottomBlockY) { -+ public synchronized void write(FriendlyByteBuf buf, com.destroystokyo.paper.antixray.ChunkPacketInfo chunkPacketInfo, int bottomBlockY) { // Paper - synchronize - // Paper end - try { - this.acquire(); -@@ -226,7 +228,7 @@ public class PalettedContainer implements PaletteResize { - - } - -- public void read(ListTag paletteNbt, long[] data) { -+ public synchronized void read(ListTag paletteNbt, long[] data) { // Paper - synchronize - try { - this.acquire(); - // Paper - Anti-Xray - TODO: Should this.presetValues.length just be added here (faster) or should the contents be compared to calculate the size (less RAM)? -@@ -261,7 +263,7 @@ public class PalettedContainer implements PaletteResize { - - } - -- public void write(CompoundTag nbt, String paletteKey, String dataKey) { -+ public synchronized void write(CompoundTag nbt, String paletteKey, String dataKey) { // Paper - synchronize - try { - this.acquire(); - HashMapPalette hashMapPalette = new HashMapPalette<>(this.registry, this.bits, this.dummyPaletteResize, this.reader, this.writer);