From bee1482bcb27ccf76cf45a86283072cde9527b4b Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 6 Dec 2023 22:17:56 +0100 Subject: [PATCH] Fix lootable patch, cb crash due to unimplemented methods --- ...x-decorated-pots-crashing-the-server.patch | 57 +++++++ ...-API-Replenishable-Lootables-Feature.patch | 142 ++++++++++-------- 2 files changed, 137 insertions(+), 62 deletions(-) create mode 100644 patches/server/Fix-decorated-pots-crashing-the-server.patch diff --git a/patches/server/Fix-decorated-pots-crashing-the-server.patch b/patches/server/Fix-decorated-pots-crashing-the-server.patch new file mode 100644 index 0000000000..0c0b9b80f1 --- /dev/null +++ b/patches/server/Fix-decorated-pots-crashing-the-server.patch @@ -0,0 +1,57 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Nassim Jahnke +Date: Wed, 6 Dec 2023 22:00:10 +0100 +Subject: [PATCH] Fix decorated pots crashing the server + + +diff --git a/src/main/java/net/minecraft/world/level/block/entity/DecoratedPotBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/DecoratedPotBlockEntity.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/level/block/entity/DecoratedPotBlockEntity.java ++++ b/src/main/java/net/minecraft/world/level/block/entity/DecoratedPotBlockEntity.java +@@ -0,0 +0,0 @@ public class DecoratedPotBlockEntity extends BlockEntity implements Randomizable + @Nullable + protected ResourceLocation lootTable; + protected long lootTableSeed; ++ // Paper start - fix cb dumb ++ public java.util.List transaction = new java.util.ArrayList<>(); ++ private int maxStack = MAX_STACK; ++ ++ @Override ++ public int getMaxStackSize() { ++ return this.maxStack; ++ } ++ ++ @Override ++ public java.util.List getContents() { ++ return java.util.Arrays.asList(this.item); ++ } ++ ++ @Override ++ public void onOpen(org.bukkit.craftbukkit.entity.CraftHumanEntity who) { ++ this.transaction.add(who); ++ } ++ ++ @Override ++ public void onClose(org.bukkit.craftbukkit.entity.CraftHumanEntity who) { ++ this.transaction.remove(who); ++ } ++ ++ @Override ++ public java.util.List getViewers() { ++ return this.transaction; ++ } ++ ++ @Override ++ public void setMaxStackSize(int size) { ++ this.maxStack = size; ++ } ++ ++ @Override ++ public org.bukkit.Location getLocation() { ++ if (this.level == null) return null; ++ return new org.bukkit.Location(this.level.getWorld(), this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ()); ++ } ++ // Paper end - fix cb dumb + + public DecoratedPotBlockEntity(BlockPos pos, BlockState state) { + super(BlockEntityType.DECORATED_POT, pos, state); diff --git a/patches/server/LootTable-API-Replenishable-Lootables-Feature.patch b/patches/server/LootTable-API-Replenishable-Lootables-Feature.patch index 17760b56fa..3f872b3200 100644 --- a/patches/server/LootTable-API-Replenishable-Lootables-Feature.patch +++ b/patches/server/LootTable-API-Replenishable-Lootables-Feature.patch @@ -503,67 +503,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return tileEntityLootable.getLevel(); + } +} -diff --git a/src/main/java/net/minecraft/world/RandomizableContainer.java b/src/main/java/net/minecraft/world/RandomizableContainer.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/net/minecraft/world/RandomizableContainer.java -+++ b/src/main/java/net/minecraft/world/RandomizableContainer.java -@@ -0,0 +0,0 @@ public interface RandomizableContainer extends Container { - - } - -+ // Paper start -+ private static net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity blockEntity(final RandomizableContainer container) { -+ return (net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity) container; -+ } - default boolean tryLoadLootTable(CompoundTag nbt) { -+ final net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity entity = blockEntity(this); -+ entity.lootableData.loadNbt(nbt); - if (nbt.contains("LootTable", 8)) { - this.setLootTable(new ResourceLocation(nbt.getString("LootTable"))); -+ try { org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(entity.lootTable); } catch (IllegalArgumentException ex) { entity.lootTable = null; } // Paper - validate - this.setLootTableSeed(nbt.getLong("LootTableSeed")); -- return true; -+ return false; // Paper - always load the items, table may still remain -+ // Paper end - } else { - return false; - } - } - - default boolean trySaveLootTable(CompoundTag nbt) { -+ // Paper start -+ final net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity entity = blockEntity(this); -+ entity.lootableData.saveNbt(nbt); -+ // Paper end - ResourceLocation resourceLocation = this.getLootTable(); - if (resourceLocation == null) { - return false; -@@ -0,0 +0,0 @@ public interface RandomizableContainer extends Container { - nbt.putLong("LootTableSeed", l); - } - -- return true; -+ return false; // Paper - always save the items, table may still remain - } - } - - default void unpackLootTable(@Nullable Player player) { -+ final net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity entity = blockEntity(this); // Paper - Level level = this.getLevel(); - BlockPos blockPos = this.getBlockPos(); - ResourceLocation resourceLocation = this.getLootTable(); -- if (resourceLocation != null && level != null && level.getServer() != null) { -+ if (entity.lootableData.shouldReplenish(player) && level != null) { // Paper - LootTable lootTable = level.getServer().getLootData().getLootTable(resourceLocation); - if (player instanceof ServerPlayer) { - CriteriaTriggers.GENERATE_LOOT.trigger((ServerPlayer)player, resourceLocation); - } - -- this.setLootTable((ResourceLocation)null); -+ entity.lootableData.processRefill(player); // Paper - LootParams.Builder builder = (new LootParams.Builder((ServerLevel)level)).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(blockPos)); - if (player != null) { - builder.withLuck(player.getLuck()).withParameter(LootContextParams.THIS_ENTITY, player); diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java @@ -718,7 +657,33 @@ diff --git a/src/main/java/net/minecraft/world/level/block/entity/RandomizableCo index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/level/block/entity/RandomizableContainerBlockEntity.java +++ b/src/main/java/net/minecraft/world/level/block/entity/RandomizableContainerBlockEntity.java -@@ -0,0 +0,0 @@ public abstract class RandomizableContainerBlockEntity extends BaseContainerBloc +@@ -0,0 +0,0 @@ + package net.minecraft.world.level.block.entity; + + import javax.annotation.Nullable; ++import net.minecraft.advancements.CriteriaTriggers; + import net.minecraft.core.BlockPos; + import net.minecraft.core.NonNullList; ++import net.minecraft.nbt.CompoundTag; + import net.minecraft.resources.ResourceLocation; ++import net.minecraft.server.level.ServerLevel; ++import net.minecraft.server.level.ServerPlayer; + import net.minecraft.world.Container; + import net.minecraft.world.ContainerHelper; + import net.minecraft.world.RandomizableContainer; +@@ -0,0 +0,0 @@ import net.minecraft.world.entity.player.Inventory; + import net.minecraft.world.entity.player.Player; + import net.minecraft.world.inventory.AbstractContainerMenu; + import net.minecraft.world.item.ItemStack; ++import net.minecraft.world.level.Level; + import net.minecraft.world.level.block.state.BlockState; ++import net.minecraft.world.level.storage.loot.LootParams; ++import net.minecraft.world.level.storage.loot.LootTable; ++import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; ++import net.minecraft.world.level.storage.loot.parameters.LootContextParams; ++import net.minecraft.world.phys.Vec3; + + public abstract class RandomizableContainerBlockEntity extends BaseContainerBlockEntity implements RandomizableContainer { @Nullable public ResourceLocation lootTable; public long lootTableSeed; @@ -726,6 +691,59 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 protected RandomizableContainerBlockEntity(BlockEntityType type, BlockPos pos, BlockState state) { super(type, pos, state); +@@ -0,0 +0,0 @@ public abstract class RandomizableContainerBlockEntity extends BaseContainerBloc + this.lootTableSeed = lootTableSeed; + } + ++ // Paper start ++ @Override ++ public boolean tryLoadLootTable(final CompoundTag nbt) { ++ // Copied from super with changes, always check the original method ++ this.lootableData.loadNbt(nbt); // Paper ++ if (nbt.contains("LootTable", 8)) { ++ this.setLootTable(new ResourceLocation(nbt.getString("LootTable"))); ++ try { org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(this.lootTable); } catch (IllegalArgumentException ex) { this.lootTable = null; } // Paper - validate ++ this.setLootTableSeed(nbt.getLong("LootTableSeed")); ++ return false; // Paper - always load the items, table may still remain ++ } else { ++ return false; ++ } ++ } ++ ++ @Override ++ public boolean trySaveLootTable(final CompoundTag nbt) { ++ this.lootableData.saveNbt(nbt); ++ RandomizableContainer.super.trySaveLootTable(nbt); ++ return false; ++ } ++ ++ @Override ++ public void unpackLootTable(@org.jetbrains.annotations.Nullable final Player player) { ++ // Copied from super with changes, always check the original method ++ Level level = this.getLevel(); ++ BlockPos blockPos = this.getBlockPos(); ++ ResourceLocation resourceLocation = this.getLootTable(); ++ if (this.lootableData.shouldReplenish(player) && level != null) { // Paper ++ LootTable lootTable = level.getServer().getLootData().getLootTable(resourceLocation); ++ if (player instanceof ServerPlayer) { ++ CriteriaTriggers.GENERATE_LOOT.trigger((ServerPlayer)player, resourceLocation); ++ } ++ ++ this.lootableData.processRefill(player); // Paper ++ LootParams.Builder builder = (new LootParams.Builder((ServerLevel)level)).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(blockPos)); ++ if (player != null) { ++ builder.withLuck(player.getLuck()).withParameter(LootContextParams.THIS_ENTITY, player); ++ } ++ ++ lootTable.fill(this, builder.create(LootContextParamSets.CHEST), this.getLootTableSeed()); ++ } ++ ++ } ++ // Paper end ++ + @Override + public boolean isEmpty() { + this.unpackLootTable((Player)null); diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBrushableBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBrushableBlock.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBrushableBlock.java