fix and cleanup loot table patches (#10100)

* fix and cleanup loot table patches

* fixes
This commit is contained in:
Jake Potrebic 2024-05-26 12:51:15 -07:00
parent fff2347845
commit dd6b67a80a
11 changed files with 554 additions and 444 deletions

View file

@ -11,14 +11,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@@ -0,0 +0,0 @@ public interface Mob extends LivingEntity, Lootable {
*/
public void setLeftHanded(boolean leftHanded);
// Paper end
// Paper end - left-handed API
+
+ // Paper start
+ // Paper start - mob xp reward API
+ /**
+ * Gets the amount of experience the mob will possibly drop. This value is randomized and it can give different results
+ *
+ * @return the amount of experience the mob will possibly drop
+ */
+ public int getPossibleExperienceReward();
+ // Paper end
+ // Paper end - mob xp reward API
}

View file

@ -11,9 +11,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@@ -0,0 +0,0 @@ public interface Mob extends LivingEntity, Lootable {
*/
void setAggressive(boolean aggressive);
// Paper end
// Paper end - Missing Entity API
+
+ // Paper start
+ // Paper start - left-handed API
+ /**
+ * Check if Mob is left-handed
+ *
@ -27,5 +27,5 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param leftHanded True if left-handed
+ */
+ public void setLeftHanded(boolean leftHanded);
+ // Paper end
+ // Paper end - left-handed API
}

View file

@ -101,8 +101,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param player The player to check
+ * @return Whether or not this player has looted this block
+ */
+ default boolean hasPlayerLooted(@NotNull Player player) {
+ return hasPlayerLooted(player.getUniqueId());
+ default boolean hasPlayerLooted(final @NotNull Player player) {
+ return this.hasPlayerLooted(player.getUniqueId());
+ }
+
+ /**
@ -127,9 +127,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param player The player to check
+ * @return Timestamp last looted, or null if player has not looted this object
+ */
+ @Nullable
+ default Long getLastLooted(@NotNull Player player) {
+ return getLastLooted(player.getUniqueId());
+ default @Nullable Long getLastLooted(final @NotNull Player player) {
+ return this.getLastLooted(player.getUniqueId());
+ }
+
+ /**
@ -147,8 +146,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param looted true to add player to looted list, false to remove
+ * @return The previous state of whether the player had looted this or not
+ */
+ default boolean setHasPlayerLooted(@NotNull Player player, boolean looted) {
+ return setHasPlayerLooted(player.getUniqueId(), looted);
+ default boolean setHasPlayerLooted(final @NotNull Player player, final boolean looted) {
+ return this.setHasPlayerLooted(player.getUniqueId(), looted);
+ }
+
+ /**
@ -271,6 +270,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
/**
* Gets the inventory of the chest block represented by this block state.
diff --git a/src/main/java/org/bukkit/block/Crafter.java b/src/main/java/org/bukkit/block/Crafter.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/block/Crafter.java
+++ b/src/main/java/org/bukkit/block/Crafter.java
@@ -0,0 +0,0 @@ import org.jetbrains.annotations.ApiStatus;
*/
@ApiStatus.Experimental
@MinecraftExperimental(Requires.UPDATE_1_21)
-public interface Crafter extends Container, Lootable {
+public interface Crafter extends Container, com.destroystokyo.paper.loottable.LootableBlockInventory { // Paper - LootTable API
/**
* Gets the number of ticks which this block will remain in the crafting
diff --git a/src/main/java/org/bukkit/block/Dispenser.java b/src/main/java/org/bukkit/block/Dispenser.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/block/Dispenser.java
@ -355,6 +367,23 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
-public interface ChestBoat extends Boat, InventoryHolder, Lootable {
+public interface ChestBoat extends Boat, InventoryHolder, com.destroystokyo.paper.loottable.LootableEntityInventory { // Paper
}
diff --git a/src/main/java/org/bukkit/entity/Mob.java b/src/main/java/org/bukkit/entity/Mob.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/entity/Mob.java
+++ b/src/main/java/org/bukkit/entity/Mob.java
@@ -0,0 +0,0 @@ public interface Mob extends LivingEntity, Lootable {
*/
@Nullable
public Sound getAmbientSound();
+
+ // Paper start - LootTable API
+ @Override
+ default void setLootTable(final @Nullable org.bukkit.loot.LootTable table, final long seed) {
+ this.setLootTable(table);
+ this.setSeed(seed);
+ }
+ // Paper end - LootTable API
}
diff --git a/src/main/java/org/bukkit/entity/minecart/HopperMinecart.java b/src/main/java/org/bukkit/entity/minecart/HopperMinecart.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/entity/minecart/HopperMinecart.java
@ -408,24 +437,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @param table the Loot Table this {@link org.bukkit.block.Container} or {@link org.bukkit.entity.Mob} will have.
+ * @param seed the seed to used to generate loot. Default is 0.
+ */
+ default void setLootTable(@Nullable LootTable table, long seed) {
+ setLootTable(table);
+ setSeed(seed);
+ }
+ void setLootTable(final @Nullable LootTable table, final long seed);
+
+ /**
+ * Returns whether or not this object has a Loot Table
+ * @return Has a loot table
+ */
+ default boolean hasLootTable() {
+ return getLootTable() != null;
+ return this.getLootTable() != null;
+ }
+
+ /**
+ * Clears the associated Loot Table to this object
+ */
+ default void clearLootTable() {
+ setLootTable(null);
+ this.setLootTable(null);
+ }
+ // Paper end
+

View file

@ -742,11 +742,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/org/bukkit/entity/Mob.java
+++ b/src/main/java/org/bukkit/entity/Mob.java
@@ -0,0 +0,0 @@ public interface Mob extends LivingEntity, Lootable {
*/
@Nullable
public Sound getAmbientSound();
this.setSeed(seed);
}
// Paper end - LootTable API
+
+ // Paper start
+ // Paper start - Missing Entity API
+ /**
+ * Some mobs will raise their arm(s) when aggressive:
+ * <ul>
@ -778,7 +778,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * @see #isAggressive()
+ */
+ void setAggressive(boolean aggressive);
+ // Paper end
+ // Paper end - Missing Entity API
}
diff --git a/src/main/java/org/bukkit/entity/Panda.java b/src/main/java/org/bukkit/entity/Panda.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644

View file

@ -47,7 +47,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
public com.destroystokyo.paper.loottable.PaperLootableInventoryData lootableData; // Paper
private CraftEntity bukkitEntity;
+ public @org.jetbrains.annotations.Nullable net.minecraft.server.level.ChunkMap.TrackedEntity tracker; // Paper

View file

@ -68,8 +68,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
// Paper end - Share random for entities to make them more random
+ public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason; // Paper - Entity#getEntitySpawnReason
public com.destroystokyo.paper.loottable.PaperLootableInventoryData lootableData; // Paper
private CraftEntity bukkitEntity;
@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
nbttagcompound.put("Paper.Origin", this.newDoubleList(origin.getX(), origin.getY(), origin.getZ()));

View file

@ -20,18 +20,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+
+ @Override
+ public void setLootTable(org.bukkit.loot.LootTable table, long seed) {
+ net.minecraft.resources.ResourceKey<net.minecraft.world.level.storage.loot.LootTable> key = (table == null) ? null : net.minecraft.resources.ResourceKey.create(net.minecraft.core.registries.Registries.LOOT_TABLE, org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(table.getKey()));
+ this.getSnapshot().setLootTable(key, seed);
+ this.getSnapshot().setLootTable(org.bukkit.craftbukkit.CraftLootTable.bukkitToMinecraft(table), seed);
+ }
+
+ @Override
+ public org.bukkit.loot.LootTable getLootTable() {
+ if (this.getSnapshot().getLootTable() == null) {
+ return null;
+ }
+
+ net.minecraft.resources.ResourceKey<net.minecraft.world.level.storage.loot.LootTable> key = this.getSnapshot().getLootTable();
+ return org.bukkit.Bukkit.getLootTable(org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(key.location()));
+ return org.bukkit.craftbukkit.CraftLootTable.minecraftToBukkit(this.getSnapshot().getLootTable());
+ }
+
+ @Override

View file

@ -4,32 +4,6 @@ Date: Sat, 6 Jan 2024 14:31:00 +0100
Subject: [PATCH] Fixup NamespacedKey handling
diff --git a/src/main/java/com/destroystokyo/paper/loottable/PaperContainerEntityLootableInventory.java b/src/main/java/com/destroystokyo/paper/loottable/PaperContainerEntityLootableInventory.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/com/destroystokyo/paper/loottable/PaperContainerEntityLootableInventory.java
+++ b/src/main/java/com/destroystokyo/paper/loottable/PaperContainerEntityLootableInventory.java
@@ -0,0 +0,0 @@ public class PaperContainerEntityLootableInventory implements PaperLootableEntit
@Override
public org.bukkit.loot.LootTable getLootTable() {
- return entity.getLootTable() != null ? Optionull.map(entity.getLootTable(), rk -> Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(rk.location()))) : null;
+ return entity.getLootTable() != null && !entity.getLootTable().location().getPath().isEmpty() ? Optionull.map(entity.getLootTable(), rk -> Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(rk.location()))) : null;
}
@Override
diff --git a/src/main/java/com/destroystokyo/paper/loottable/PaperTileEntityLootableInventory.java b/src/main/java/com/destroystokyo/paper/loottable/PaperTileEntityLootableInventory.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/com/destroystokyo/paper/loottable/PaperTileEntityLootableInventory.java
+++ b/src/main/java/com/destroystokyo/paper/loottable/PaperTileEntityLootableInventory.java
@@ -0,0 +0,0 @@ public class PaperTileEntityLootableInventory implements PaperLootableBlockInven
@Override
public org.bukkit.loot.LootTable getLootTable() {
- return tileEntityLootable.lootTable != null ? Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(tileEntityLootable.lootTable.location())) : null;
+ return tileEntityLootable.lootTable != null && !tileEntityLootable.lootTable.location().getPath().isEmpty() ? Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(tileEntityLootable.lootTable.location())) : null;
}
@Override
diff --git a/src/main/java/net/minecraft/world/inventory/LoomMenu.java b/src/main/java/net/minecraft/world/inventory/LoomMenu.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/inventory/LoomMenu.java
@ -64,6 +38,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
if (!event.callEvent()) {
player.containerMenu.sendAllDataToRemote();
return false;
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java b/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java
@@ -0,0 +0,0 @@ public class CraftLootTable implements org.bukkit.loot.LootTable {
}
public static org.bukkit.loot.LootTable minecraftToBukkit(ResourceKey<LootTable> minecraft) {
- return (minecraft == null) ? null : Bukkit.getLootTable(CraftLootTable.minecraftToBukkitKey(minecraft));
+ return (minecraft == null || minecraft.location().getPath().isEmpty()) ? null : Bukkit.getLootTable(CraftLootTable.minecraftToBukkitKey(minecraft)); // Paper - fix some NamespacedKey parsing
}
public static NamespacedKey minecraftToBukkitKey(ResourceKey<LootTable> minecraft) {
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java

View file

@ -30,9 +30,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
// Paper end - Share random for entities to make them more random
public org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason; // Paper - Entity#getEntitySpawnReason
public com.destroystokyo.paper.loottable.PaperLootableInventoryData lootableData; // Paper
+ public boolean collisionLoadChunks = false; // Paper
private CraftEntity bukkitEntity;

View file

@ -39,6 +39,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
this.namespace = namespace;
this.path = path;
}
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 {
default boolean tryLoadLootTable(CompoundTag nbt) {
if (nbt.contains("LootTable", 8)) {
- this.setLootTable(ResourceKey.create(Registries.LOOT_TABLE, new ResourceLocation(nbt.getString("LootTable"))));
+ this.setLootTable(net.minecraft.Optionull.map(ResourceLocation.tryParse(nbt.getString("LootTable")), rl -> ResourceKey.create(Registries.LOOT_TABLE, rl))); // Paper - Validate ResourceLocation);
if (this.lootableData() != null && this.getLootTable() != null) this.lootableData().loadNbt(nbt); // Paper - LootTable API
if (nbt.contains("LootTableSeed", 4)) {
this.setLootTableSeed(nbt.getLong("LootTableSeed"));
diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
@ -107,9 +120,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
if (nbt.contains("LootTable", 8)) {
- this.setLootTable(ResourceKey.create(Registries.LOOT_TABLE, new ResourceLocation(nbt.getString("LootTable"))));
+ this.setLootTable(net.minecraft.Optionull.map(ResourceLocation.tryParse(nbt.getString("LootTable")), rl -> ResourceKey.create(Registries.LOOT_TABLE, rl))); // Paper - Validate ResourceLocation
this.setLootTableSeed(nbt.getLong("LootTableSeed"));
}
ContainerHelper.loadAllItems(nbt, this.getItemStacks(), registriesLookup); // Paper - always save the items, table may still remain
// Paper start - LootTable API
if (this.getLootTable() != null) {
this.lootableData().loadNbt(nbt);
diff --git a/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java