2018-08-12 17:11:08 +00:00
From fd6c2c49c3fa2bbf29d1ea1ec2c04d901a1060d6 Mon Sep 17 00:00:00 2001
2016-05-02 03:54:08 +00:00
From: Aikar <aikar@aikar.co>
Date: Sun, 1 May 2016 21:19:14 -0400
Subject: [PATCH] LootTable API & Replenishable Lootables Feature
Provides an API to control the loot table for an object.
Also provides a feature that any Lootable Inventory (Chests in Structures)
can automatically replenish after a given time.
This feature is good for long term worlds so that newer players
do not suffer with "Every chest has been looted"
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2018-08-05 23:46:43 +00:00
index 8d54af6bb7..a3823408ca 100644
2016-05-02 03:54:08 +00:00
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2018-07-24 00:24:44 +00:00
@@ -254,4 +254,26 @@ public class PaperWorldConfig {
2016-05-02 03:54:08 +00:00
this.frostedIceDelayMax = this.getInt("frosted-ice.delay.max", this.frostedIceDelayMax);
2017-03-25 03:18:58 +00:00
log("Frosted Ice: " + (this.frostedIceEnabled ? "enabled" : "disabled") + " / delay: min=" + this.frostedIceDelayMin + ", max=" + this.frostedIceDelayMax);
2016-05-02 03:54:08 +00:00
}
+
+ public boolean autoReplenishLootables;
+ public boolean restrictPlayerReloot;
+ public boolean changeLootTableSeedOnFill;
+ public int maxLootableRefills;
+ public int lootableRegenMin;
+ public int lootableRegenMax;
+ private void enhancedLootables() {
+ autoReplenishLootables = getBoolean("lootables.auto-replenish", false);
+ restrictPlayerReloot = getBoolean("lootables.restrict-player-reloot", true);
+ changeLootTableSeedOnFill = getBoolean("lootables.reset-seed-on-fill", true);
+ maxLootableRefills = getInt("lootables.max-refills", -1);
+ lootableRegenMin = PaperConfig.getSeconds(getString("lootables.refresh-min", "12h"));
+ lootableRegenMax = PaperConfig.getSeconds(getString("lootables.refresh-max", "2d"));
+ if (autoReplenishLootables) {
+ log("Lootables: Replenishing every " +
+ PaperConfig.timeSummary(lootableRegenMin) + " to " +
+ PaperConfig.timeSummary(lootableRegenMax) +
+ (restrictPlayerReloot ? " (restricting reloot)" : "")
+ );
+ }
+ }
}
diff --git a/src/main/java/com/destroystokyo/paper/loottable/CraftLootable.java b/src/main/java/com/destroystokyo/paper/loottable/CraftLootable.java
new file mode 100644
2018-08-05 23:46:43 +00:00
index 0000000000..36c36d158f
2016-05-02 03:54:08 +00:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/loottable/CraftLootable.java
@@ -0,0 +1,12 @@
+package com.destroystokyo.paper.loottable;
+
+import net.minecraft.server.World;
+
+interface CraftLootable extends Lootable {
+
+ World getNMSWorld();
+
+ default org.bukkit.World getBukkitWorld() {
+ return getNMSWorld().getWorld();
+ }
+}
diff --git a/src/main/java/com/destroystokyo/paper/loottable/CraftLootableBlockInventory.java b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableBlockInventory.java
new file mode 100644
2018-08-05 23:46:43 +00:00
index 0000000000..20d236c451
2016-05-02 03:54:08 +00:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableBlockInventory.java
2016-05-08 01:16:38 +00:00
@@ -0,0 +1,33 @@
2016-05-02 03:54:08 +00:00
+package com.destroystokyo.paper.loottable;
+
+import net.minecraft.server.BlockPosition;
+import net.minecraft.server.TileEntityLootable;
+import net.minecraft.server.World;
+import org.bukkit.Chunk;
+import org.bukkit.block.Block;
+
+public interface CraftLootableBlockInventory extends LootableBlockInventory, CraftLootableInventory {
+
+ TileEntityLootable getTileEntity();
+
+ @Override
2016-05-08 01:16:38 +00:00
+ default LootableInventory getAPILootableInventory() {
+ return this;
+ }
+
+ @Override
2016-05-02 03:54:08 +00:00
+ default World getNMSWorld() {
+ return getTileEntity().getWorld();
+ }
+
+ default Block getBlock() {
+ final BlockPosition position = getTileEntity().getPosition();
+ final Chunk bukkitChunk = getTileEntity().getWorld().getChunkAtWorldCoords(position).bukkitChunk;
+ return bukkitChunk.getBlock(position.getX(), position.getY(), position.getZ());
+ }
+
+ @Override
+ default CraftLootableInventoryData getLootableData() {
+ return getTileEntity().getLootableData();
+ }
+}
diff --git a/src/main/java/com/destroystokyo/paper/loottable/CraftLootableEntityInventory.java b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableEntityInventory.java
new file mode 100644
2018-08-05 23:46:43 +00:00
index 0000000000..1150dee01e
2016-05-02 03:54:08 +00:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableEntityInventory.java
2016-05-08 01:16:38 +00:00
@@ -0,0 +1,31 @@
2016-05-02 03:54:08 +00:00
+package com.destroystokyo.paper.loottable;
+
+import net.minecraft.server.World;
+import org.bukkit.entity.Entity;
+
+public interface CraftLootableEntityInventory extends LootableEntityInventory, CraftLootableInventory {
+
+ net.minecraft.server.Entity getHandle();
+
2016-05-08 01:16:38 +00:00
+ @Override
+ default LootableInventory getAPILootableInventory() {
+ return this;
+ }
+
2016-05-02 03:54:08 +00:00
+ default Entity getEntity() {
+ return getHandle().getBukkitEntity();
+ }
+
+ @Override
+ default World getNMSWorld() {
+ return getHandle().getWorld();
+ }
+
+ @Override
+ default CraftLootableInventoryData getLootableData() {
+ if (getHandle() instanceof CraftLootableInventory) {
+ return ((CraftLootableInventory) getHandle()).getLootableData();
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/com/destroystokyo/paper/loottable/CraftLootableInventory.java b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableInventory.java
new file mode 100644
2018-08-12 17:11:08 +00:00
index 0000000000..b72232093b
2016-05-02 03:54:08 +00:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableInventory.java
2018-08-12 17:11:08 +00:00
@@ -0,0 +1,62 @@
2016-05-02 03:54:08 +00:00
+package com.destroystokyo.paper.loottable;
+
+import java.util.UUID;
+
+public interface CraftLootableInventory extends CraftLootable, LootableInventory {
+
+ CraftLootableInventoryData getLootableData();
2016-05-08 01:16:38 +00:00
+ LootableInventory getAPILootableInventory();
2016-05-02 03:54:08 +00:00
+
+ @Override
+ default boolean isRefillEnabled() {
+ return getNMSWorld().paperConfig.autoReplenishLootables;
+ }
+
+ @Override
+ default boolean hasBeenFilled() {
+ return getLastFilled() != -1;
+ }
+
+ @Override
+ default boolean hasPlayerLooted(UUID player) {
+ return getLootableData().hasPlayerLooted(player);
+ }
+
+ @Override
+ default Long getLastLooted(UUID player) {
+ return getLootableData().getLastLooted(player);
+ }
+
+ @Override
+ default boolean setHasPlayerLooted(UUID player, boolean looted) {
+ final boolean hasLooted = hasPlayerLooted(player);
+ if (hasLooted != looted) {
+ getLootableData().setPlayerLootedState(player, looted);
+ }
+ return hasLooted;
+ }
+
+ @Override
+ default boolean hasPendingRefill() {
+ long nextRefill = getLootableData().getNextRefill();
+ return nextRefill != -1 && nextRefill > getLootableData().getLastFill();
+ }
+
+ @Override
+ default long getLastFilled() {
+ return getLootableData().getLastFill();
+ }
+
+ @Override
+ default long getNextRefill() {
+ return getLootableData().getNextRefill();
+ }
+
+ @Override
+ default long setNextRefill(long refillAt) {
+ if (refillAt < -1) {
+ refillAt = -1;
+ }
+ return getLootableData().setNextRefill(refillAt);
+ }
+}
diff --git a/src/main/java/com/destroystokyo/paper/loottable/CraftLootableInventoryData.java b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableInventoryData.java
new file mode 100644
2018-08-12 17:11:08 +00:00
index 0000000000..8547205456
2016-05-02 03:54:08 +00:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/loottable/CraftLootableInventoryData.java
2018-08-12 17:11:08 +00:00
@@ -0,0 +1,179 @@
2016-05-02 03:54:08 +00:00
+package com.destroystokyo.paper.loottable;
+
+import com.destroystokyo.paper.PaperWorldConfig;
+import net.minecraft.server.*;
+import org.bukkit.entity.Player;
2018-08-12 17:11:08 +00:00
+import org.bukkit.loot.LootTable;
2016-05-02 03:54:08 +00:00
+
2016-05-12 02:07:46 +00:00
+import javax.annotation.Nullable;
2016-05-02 03:54:08 +00:00
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
+import java.util.UUID;
+
+public class CraftLootableInventoryData {
+
+ private static final Random RANDOM = new Random();
+
+ private long lastFill = -1;
+ private long nextRefill = -1;
+ private int numRefills = 0;
+ private Map<UUID, Long> lootedPlayers;
+ private final CraftLootableInventory lootable;
+
+ public CraftLootableInventoryData(CraftLootableInventory lootable) {
+ this.lootable = lootable;
+ }
+
+ long getLastFill() {
+ return this.lastFill;
+ }
+
+ long getNextRefill() {
+ return this.nextRefill;
+ }
+
+ long setNextRefill(long nextRefill) {
+ long prev = this.nextRefill;
+ this.nextRefill = nextRefill;
+ return prev;
+ }
+
2016-05-12 02:07:46 +00:00
+ public boolean shouldReplenish(@Nullable EntityHuman player) {
2018-08-12 17:11:08 +00:00
+ LootTable table = this.lootable.getLootTable();
2016-05-02 03:54:08 +00:00
+
+ // No Loot Table associated
2018-08-12 17:11:08 +00:00
+ if (table == null) {
2016-05-02 03:54:08 +00:00
+ return false;
+ }
+
+ // ALWAYS process the first fill
+ if (this.lastFill == -1) {
+ return true;
+ }
+
+ // Only process refills when a player is set
+ if (player == null) {
+ return false;
+ }
+
+ // Chest is not scheduled for refill
+ if (this.nextRefill == -1) {
+ return false;
+ }
+
+ final PaperWorldConfig paperConfig = this.lootable.getNMSWorld().paperConfig;
+
+ // Check if max refills has been hit
+ if (paperConfig.maxLootableRefills != -1 && this.numRefills >= paperConfig.maxLootableRefills) {
+ return false;
+ }
+
+ // Refill has not been reached
+ if (this.nextRefill > System.currentTimeMillis()) {
+ return false;
+ }
+
+
+ final Player bukkitPlayer = (Player) player.getBukkitEntity();
2016-05-08 01:16:38 +00:00
+ LootableInventoryReplenishEvent event = new LootableInventoryReplenishEvent(bukkitPlayer, lootable.getAPILootableInventory());
2016-05-02 03:54:08 +00:00
+ if (paperConfig.restrictPlayerReloot && hasPlayerLooted(player.getUniqueID())) {
+ event.setCancelled(true);
+ }
+ return event.callEvent();
+ }
2016-05-15 06:41:36 +00:00
+ public void processRefill(@Nullable EntityHuman player) {
2016-05-02 03:54:08 +00:00
+ this.lastFill = System.currentTimeMillis();
+ final PaperWorldConfig paperConfig = this.lootable.getNMSWorld().paperConfig;
+ if (paperConfig.autoReplenishLootables) {
2018-06-13 18:15:31 +00:00
+ int min = paperConfig.lootableRegenMin;
+ int max = paperConfig.lootableRegenMax;
+ this.nextRefill = this.lastFill + (min + RANDOM.nextInt(max - min + 1)) * 1000L;
2016-05-02 03:54:08 +00:00
+ this.numRefills++;
+ if (paperConfig.changeLootTableSeedOnFill) {
+ this.lootable.setLootTableSeed(0);
+ }
2016-05-15 06:41:36 +00:00
+ if (player != null) { // This means that numRefills can be incremented without a player being in the lootedPlayers list - Seems to be EntityMinecartChest specific
+ this.setPlayerLootedState(player.getUniqueID(), true);
+ }
2016-05-02 03:54:08 +00:00
+ } else {
+ this.lootable.clearLootTable();
+ }
+ }
+
+
+ public void loadNbt(NBTTagCompound base) {
+ if (!base.hasKeyOfType("Paper.LootableData", 10)) { // 10 = compound
+ return;
+ }
+ NBTTagCompound comp = base.getCompound("Paper.LootableData");
+ if (comp.hasKey("lastFill")) {
+ this.lastFill = comp.getLong("lastFill");
+ }
+ if (comp.hasKey("nextRefill")) {
+ this.nextRefill = comp.getLong("nextRefill");
+ }
+
+ if (comp.hasKey("numRefills")) {
+ this.numRefills = comp.getInt("numRefills");
+ }
+ if (comp.hasKeyOfType("lootedPlayers", 9)) { // 9 = list
+ NBTTagList list = comp.getList("lootedPlayers", 10); // 10 = compound
+ final int size = list.size();
+ if (size > 0) {
+ this.lootedPlayers = new HashMap<>(list.size());
+ }
+ for (int i = 0; i < size; i++) {
2018-07-16 15:34:55 +00:00
+ final NBTTagCompound cmp = list.getCompound(i);
2016-05-02 03:54:08 +00:00
+ lootedPlayers.put(cmp.getUUID("UUID"), cmp.getLong("Time"));
+ }
+ }
+ }
+ public void saveNbt(NBTTagCompound base) {
+ NBTTagCompound comp = new NBTTagCompound();
+ if (this.nextRefill != -1) {
+ comp.setLong("nextRefill", this.nextRefill);
+ }
+ if (this.lastFill != -1) {
+ comp.setLong("lastFill", this.lastFill);
+ }
+ if (this.numRefills != 0) {
+ comp.setInt("numRefills", this.numRefills);
+ }
+ if (this.lootedPlayers != null && !this.lootedPlayers.isEmpty()) {
+ NBTTagList list = new NBTTagList();
+ for (Map.Entry<UUID, Long> entry : this.lootedPlayers.entrySet()) {
+ NBTTagCompound cmp = new NBTTagCompound();
+ cmp.setUUID("UUID", entry.getKey());
+ cmp.setLong("Time", entry.getValue());
+ list.add(cmp);
+ }
+ comp.set("lootedPlayers", list);
+ }
+
+ if (!comp.isEmpty()) {
+ base.set("Paper.LootableData", comp);
+ }
+ }
+
+ void setPlayerLootedState(UUID player, boolean looted) {
+ if (looted && this.lootedPlayers == null) {
+ this.lootedPlayers = new HashMap<>();
+ }
+ if (looted) {
+ if (!this.lootedPlayers.containsKey(player)) {
+ this.lootedPlayers.put(player, System.currentTimeMillis());
+ }
+ } else if (this.lootedPlayers != null) {
+ this.lootedPlayers.remove(player);
+ }
+ }
+
+ boolean hasPlayerLooted(UUID player) {
+ return this.lootedPlayers != null && this.lootedPlayers.containsKey(player);
+ }
+
+ Long getLastLooted(UUID player) {
+ return lootedPlayers != null ? lootedPlayers.get(player) : null;
+ }
+}
diff --git a/src/main/java/net/minecraft/server/EntityMinecartContainer.java b/src/main/java/net/minecraft/server/EntityMinecartContainer.java
2018-08-12 17:11:08 +00:00
index 91b38fd64b..7120f00b6a 100644
2016-05-02 03:54:08 +00:00
--- a/src/main/java/net/minecraft/server/EntityMinecartContainer.java
+++ b/src/main/java/net/minecraft/server/EntityMinecartContainer.java
2018-08-12 17:11:08 +00:00
@@ -5,18 +5,25 @@ import java.util.Random;
import javax.annotation.Nullable;
2016-05-02 03:54:08 +00:00
// CraftBukkit start
import java.util.List;
2018-08-12 17:11:08 +00:00
+// Paper start
+import com.destroystokyo.paper.loottable.CraftLootableInventoryData;
+import com.destroystokyo.paper.loottable.CraftLootableInventory;
+import com.destroystokyo.paper.loottable.LootableInventory;
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.util.CraftNamespacedKey;
+// Paper end
2016-05-12 02:07:46 +00:00
import org.bukkit.Location;
2016-05-02 03:54:08 +00:00
import org.bukkit.craftbukkit.entity.CraftHumanEntity;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.InventoryHolder;
// CraftBukkit end
-public abstract class EntityMinecartContainer extends EntityMinecartAbstract implements ITileInventory, ILootable {
+public abstract class EntityMinecartContainer extends EntityMinecartAbstract implements ITileInventory, ILootable, CraftLootableInventory { // Paper
2016-11-17 02:23:38 +00:00
private NonNullList<ItemStack> items;
private boolean b;
2018-08-12 17:11:08 +00:00
- private MinecraftKey c;
- public long d; // CraftBukkit private -> public
+ private MinecraftKey c; private MinecraftKey getLootTableKey() { return c; } private void setLootTable(MinecraftKey key) { c = key; } // Paper - OBFHELPER
+ public long d; public long getSeed() { return d; } public void setSeed(long seed) { d = seed; } // Paper - OBFHELPER // CraftBukkit private -> public
2016-05-02 03:54:08 +00:00
// CraftBukkit start
public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
2018-08-12 17:11:08 +00:00
@@ -168,12 +175,13 @@ public abstract class EntityMinecartContainer extends EntityMinecartAbstract imp
2016-05-02 03:54:08 +00:00
protected void b(NBTTagCompound nbttagcompound) {
super.b(nbttagcompound);
+ lootableData.saveNbt(nbttagcompound); // Paper
if (this.c != null) {
nbttagcompound.setString("LootTable", this.c.toString());
if (this.d != 0L) {
2016-06-06 23:56:51 +00:00
nbttagcompound.setLong("LootTableSeed", this.d);
}
- } else {
+ } if (true) { // Paper - Always save the items, Table may stick around
2016-11-17 02:23:38 +00:00
ContainerUtil.a(nbttagcompound, this.items);
}
2016-06-06 23:56:51 +00:00
2018-08-12 17:11:08 +00:00
@@ -181,11 +189,12 @@ public abstract class EntityMinecartContainer extends EntityMinecartAbstract imp
2017-06-20 22:59:18 +00:00
protected void a(NBTTagCompound nbttagcompound) {
super.a(nbttagcompound);
+ lootableData.loadNbt(nbttagcompound); // Paper
this.items = NonNullList.a(this.getSize(), ItemStack.a);
2016-05-02 03:54:08 +00:00
if (nbttagcompound.hasKeyOfType("LootTable", 8)) {
this.c = new MinecraftKey(nbttagcompound.getString("LootTable"));
this.d = nbttagcompound.getLong("LootTableSeed");
2016-06-06 23:56:51 +00:00
- } else {
+ } if (true) { // Paper - always load the items, table may still remain
2016-11-17 02:23:38 +00:00
ContainerUtil.b(nbttagcompound, this.items);
}
2016-06-06 23:56:51 +00:00
2018-08-12 17:11:08 +00:00
@@ -234,10 +243,10 @@ public abstract class EntityMinecartContainer extends EntityMinecartAbstract imp
2016-05-02 03:54:08 +00:00
}
2016-05-12 02:07:46 +00:00
public void f(@Nullable EntityHuman entityhuman) {
2018-07-16 15:34:55 +00:00
- if (this.c != null && this.world.getMinecraftServer() != null) {
+ if (lootableData.shouldReplenish(entityhuman) && this.world.getMinecraftServer() != null) { // Paper
LootTable loottable = this.world.getMinecraftServer().aP().a(this.c);
2016-05-02 03:54:08 +00:00
- this.c = null;
+ lootableData.processRefill(entityhuman); // Paper
Random random;
if (this.d == 0L) {
2018-08-12 17:11:08 +00:00
@@ -270,4 +279,39 @@ public abstract class EntityMinecartContainer extends EntityMinecartAbstract imp
2018-07-16 15:34:55 +00:00
public MinecraftKey Q_() {
2016-05-02 03:54:08 +00:00
return this.c;
}
+
+ // Paper start
+ @Override
2018-08-12 17:11:08 +00:00
+ public org.bukkit.loot.LootTable getLootTable() {
+ return getLootTableKey() != null ? Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(getLootTableKey())) : null;
2016-05-02 03:54:08 +00:00
+ }
+
2016-05-05 00:33:16 +00:00
+ @Override
2018-08-12 17:11:08 +00:00
+ public void setLootTable(org.bukkit.loot.LootTable table, long seed) {
+ setLootTable(table);
+ setSeed(seed);
2016-05-08 01:16:38 +00:00
+ }
+
+ @Override
2018-08-12 17:11:08 +00:00
+ public void setLootTable(org.bukkit.loot.LootTable table) {
+ MinecraftKey newKey = (table == null) ? null : CraftNamespacedKey.toMinecraft(table.getKey());
+ setLootTable(newKey);
2016-05-05 00:33:16 +00:00
+ }
2018-08-12 17:11:08 +00:00
+ private final CraftLootableInventoryData lootableData = new CraftLootableInventoryData(this);
2016-05-05 00:33:16 +00:00
+
2018-08-12 17:11:08 +00:00
+ @Override
+ public CraftLootableInventoryData getLootableData() {
+ return lootableData;
2016-05-02 03:54:08 +00:00
+ }
+
+ @Override
2018-08-12 17:11:08 +00:00
+ public LootableInventory getAPILootableInventory() {
+ return (LootableInventory) this.getBukkitEntity();
2016-05-02 03:54:08 +00:00
+ }
+
+ @Override
2018-08-12 17:11:08 +00:00
+ public World getNMSWorld() {
+ return this.world;
2016-05-02 03:54:08 +00:00
+ }
+ // Paper end
}
diff --git a/src/main/java/net/minecraft/server/TileEntityLootable.java b/src/main/java/net/minecraft/server/TileEntityLootable.java
2018-08-12 17:11:08 +00:00
index fbda02b321..e0f87a3533 100644
2016-05-02 03:54:08 +00:00
--- a/src/main/java/net/minecraft/server/TileEntityLootable.java
+++ b/src/main/java/net/minecraft/server/TileEntityLootable.java
2018-08-12 17:11:08 +00:00
@@ -1,12 +1,20 @@
2016-05-02 03:54:08 +00:00
package net.minecraft.server;
2018-08-12 17:11:08 +00:00
+// Paper start
+import com.destroystokyo.paper.loottable.CraftLootableInventoryData;
+import com.destroystokyo.paper.loottable.CraftLootableInventory;
+import com.destroystokyo.paper.loottable.LootableInventory;
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.util.CraftNamespacedKey;
+// Paper end
2016-05-02 03:54:08 +00:00
+
import java.util.Random;
2016-05-12 02:07:46 +00:00
import javax.annotation.Nullable;
2016-05-02 03:54:08 +00:00
-public abstract class TileEntityLootable extends TileEntityContainer implements ILootable {
+public abstract class TileEntityLootable extends TileEntityContainer implements ILootable, CraftLootableInventory { // Paper
2018-08-12 17:11:08 +00:00
- protected MinecraftKey g;
2018-07-16 15:34:55 +00:00
- protected long h;
2018-08-12 17:11:08 +00:00
+ protected MinecraftKey g; private MinecraftKey getLootTableKey() { return g; } private void setLootTable(MinecraftKey key) { g = key; } // Paper - OBFHELPER
+ protected long h; public long getSeed() { return h; } public void setSeed(long seed) { h = seed; } // Paper - OBFHELPER
2018-07-16 15:34:55 +00:00
protected IChatBaseComponent i;
2016-05-02 03:54:08 +00:00
2018-07-16 15:34:55 +00:00
protected TileEntityLootable(TileEntityTypes<?> tileentitytypes) {
2018-08-12 17:11:08 +00:00
@@ -23,16 +31,18 @@ public abstract class TileEntityLootable extends TileEntityContainer implements
2018-07-16 15:34:55 +00:00
}
2016-05-02 03:54:08 +00:00
2018-07-16 15:34:55 +00:00
protected boolean d(NBTTagCompound nbttagcompound) {
2016-05-02 03:54:08 +00:00
+ lootableData.loadNbt(nbttagcompound); // Paper
if (nbttagcompound.hasKeyOfType("LootTable", 8)) {
2018-07-16 15:34:55 +00:00
this.g = new MinecraftKey(nbttagcompound.getString("LootTable"));
this.h = nbttagcompound.getLong("LootTableSeed");
2016-06-07 07:03:51 +00:00
- return true;
+ return false; // Paper - always load the items, table may still remain
2016-06-06 23:56:51 +00:00
} else {
2016-06-07 07:03:51 +00:00
return false;
2016-06-06 23:56:51 +00:00
}
2016-05-02 03:54:08 +00:00
}
2018-07-16 15:34:55 +00:00
protected boolean e(NBTTagCompound nbttagcompound) {
2016-05-02 03:54:08 +00:00
+ lootableData.saveNbt(nbttagcompound); // Paper
2018-07-16 15:34:55 +00:00
if (this.g == null) {
return false;
} else {
2018-08-12 17:11:08 +00:00
@@ -41,15 +51,15 @@ public abstract class TileEntityLootable extends TileEntityContainer implements
2018-07-16 15:34:55 +00:00
nbttagcompound.setLong("LootTableSeed", this.h);
2016-06-07 07:03:51 +00:00
}
2016-06-06 23:56:51 +00:00
2016-06-07 07:03:51 +00:00
- return true;
+ return false; // Paper - always save the items, table may still remain
2016-06-06 23:56:51 +00:00
}
2016-05-02 03:54:08 +00:00
}
2016-11-17 02:23:38 +00:00
public void d(@Nullable EntityHuman entityhuman) {
2018-07-16 15:34:55 +00:00
- if (this.g != null && this.world.getMinecraftServer() != null) {
+ if (lootableData.shouldReplenish(entityhuman) && this.world.getMinecraftServer() != null) { // Paper
LootTable loottable = this.world.getMinecraftServer().aP().a(this.g);
2016-05-02 03:54:08 +00:00
2018-07-16 15:34:55 +00:00
- this.g = null;
2016-05-02 03:54:08 +00:00
+ lootableData.processRefill(entityhuman); // Paper
Random random;
2018-07-16 15:34:55 +00:00
if (this.h == 0L) {
2018-08-12 17:11:08 +00:00
@@ -152,4 +162,39 @@ public abstract class TileEntityLootable extends TileEntityContainer implements
2016-11-17 02:23:38 +00:00
protected abstract NonNullList<ItemStack> q();
2018-07-16 15:34:55 +00:00
protected abstract void a(NonNullList<ItemStack> nonnulllist);
2016-05-02 03:54:08 +00:00
+ // Paper start - LootTable API
+ @Override
2018-08-12 17:11:08 +00:00
+ public org.bukkit.loot.LootTable getLootTable() {
+ return getLootTableKey() != null ? Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(getLootTableKey())) : null;
2016-05-02 03:54:08 +00:00
+ }
+
+ @Override
2018-08-12 17:11:08 +00:00
+ public void setLootTable(org.bukkit.loot.LootTable table, long seed) {
+ setLootTable(table);
+ setSeed(seed);
2016-05-08 01:16:38 +00:00
+ }
+
+ @Override
2018-08-12 17:11:08 +00:00
+ public void setLootTable(org.bukkit.loot.LootTable table) {
+ MinecraftKey newKey = (table == null) ? null : CraftNamespacedKey.toMinecraft(table.getKey());
+ setLootTable(newKey);
2016-05-02 03:54:08 +00:00
+ }
2018-08-12 17:11:08 +00:00
+ private final CraftLootableInventoryData lootableData = new CraftLootableInventoryData(this);
2016-05-02 03:54:08 +00:00
+
2018-08-12 17:11:08 +00:00
+ @Override
+ public CraftLootableInventoryData getLootableData() {
+ return lootableData;
2016-05-02 03:54:08 +00:00
+ }
+
+ @Override
2018-08-12 17:11:08 +00:00
+ public LootableInventory getAPILootableInventory() {
+ return (LootableInventory) getBukkitWorld().getBlockAt(MCUtil.toLocation(world, getPosition())).getState();
2016-05-02 03:54:08 +00:00
+ }
+
+ @Override
2018-08-12 17:11:08 +00:00
+ public World getNMSWorld() {
+ return world;
2016-05-02 03:54:08 +00:00
+ }
+ // Paper end
2016-11-17 02:23:38 +00:00
+
2016-05-02 03:54:08 +00:00
}
2017-08-05 22:36:47 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
2018-08-05 23:46:43 +00:00
index ac9b4297b2..0558cafe31 100644
2017-08-05 22:36:47 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
2018-07-16 15:34:55 +00:00
@@ -61,7 +61,7 @@ public class CraftBlockEntityState<T extends TileEntity> extends CraftBlockState
2017-08-05 22:36:47 +00:00
}
// gets the wrapped TileEntity
- protected T getTileEntity() {
+ public T getTileEntity() { // Paper - protected -> public
return tileEntity;
}
2016-05-02 03:54:08 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftChest.java b/src/main/java/org/bukkit/craftbukkit/block/CraftChest.java
2018-08-05 23:46:43 +00:00
index dff5bb5171..e7b719b43d 100644
2016-05-02 03:54:08 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftChest.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftChest.java
2018-07-16 15:34:55 +00:00
@@ -1,6 +1,7 @@
2016-05-02 03:54:08 +00:00
package org.bukkit.craftbukkit.block;
2018-07-16 15:34:55 +00:00
import net.minecraft.server.BlockChest;
2016-05-02 03:54:08 +00:00
+import com.destroystokyo.paper.loottable.CraftLootableBlockInventory; // Paper
import net.minecraft.server.BlockPosition;
2018-07-16 15:34:55 +00:00
import net.minecraft.server.Blocks;
import net.minecraft.server.ITileInventory;
@@ -15,7 +16,7 @@ import org.bukkit.craftbukkit.inventory.CraftInventory;
2016-05-02 03:54:08 +00:00
import org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest;
import org.bukkit.inventory.Inventory;
2017-08-05 22:36:47 +00:00
-public class CraftChest extends CraftLootable<TileEntityChest> implements Chest {
+public class CraftChest extends CraftLootable<TileEntityChest> implements Chest, CraftLootableBlockInventory { // Paper
2016-05-02 03:54:08 +00:00
2017-08-05 22:36:47 +00:00
public CraftChest(final Block block) {
super(block, TileEntityChest.class);
2018-08-12 17:11:08 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java b/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java
index 34bcc49cf9..7ff7d33f06 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java
2016-11-19 17:31:01 +00:00
@@ -1,5 +1,6 @@
package org.bukkit.craftbukkit.block;
+import com.destroystokyo.paper.loottable.CraftLootableBlockInventory;
2018-08-12 17:11:08 +00:00
import net.minecraft.server.MinecraftKey;
import net.minecraft.server.TileEntityLootable;
import org.bukkit.Bukkit;
@@ -11,7 +12,7 @@ import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.loot.LootTable;
import org.bukkit.loot.Lootable;
-public abstract class CraftLootable<T extends TileEntityLootable> extends CraftContainer<T> implements Nameable, Lootable {
+public abstract class CraftLootable<T extends TileEntityLootable> extends CraftContainer<T> implements Nameable, Lootable, CraftLootableBlockInventory {
public CraftLootable(Block block, Class<T> tileEntityClass) {
super(block, tileEntityClass);
@@ -69,7 +70,7 @@ public abstract class CraftLootable<T extends TileEntityLootable> extends CraftC
setLootTable(getLootTable(), seed);
}
2016-11-19 17:31:01 +00:00
2018-08-12 17:11:08 +00:00
- private void setLootTable(LootTable table, long seed) {
+ public void setLootTable(LootTable table, long seed) { // Paper - public
MinecraftKey key = (table == null) ? null : CraftNamespacedKey.toMinecraft(table.getKey());
getSnapshot().a(key, seed); // PAIL setLootTable
}
2016-05-02 03:54:08 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartChest.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartChest.java
2018-08-12 17:11:08 +00:00
index 1b5b266c05..3d5225e9f2 100644
2016-05-02 03:54:08 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartChest.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartChest.java
@@ -1,5 +1,6 @@
package org.bukkit.craftbukkit.entity;
+import com.destroystokyo.paper.loottable.CraftLootableEntityInventory; // Paper
import net.minecraft.server.EntityMinecartChest;
import org.bukkit.craftbukkit.CraftServer;
2016-11-17 02:23:38 +00:00
@@ -9,7 +10,7 @@ import org.bukkit.entity.minecart.StorageMinecart;
2016-05-02 03:54:08 +00:00
import org.bukkit.inventory.Inventory;
@SuppressWarnings("deprecation")
2018-08-12 17:11:08 +00:00
-public class CraftMinecartChest extends CraftMinecartContainer implements StorageMinecart {
+public class CraftMinecartChest extends CraftMinecartContainer implements StorageMinecart, CraftLootableEntityInventory { // Paper
2016-05-02 03:54:08 +00:00
private final CraftInventory inventory;
public CraftMinecartChest(CraftServer server, EntityMinecartChest entity) {
2018-08-12 17:11:08 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartContainer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartContainer.java
index 8ce9737451..7e11993aa6 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartContainer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartContainer.java
@@ -47,7 +47,7 @@ public abstract class CraftMinecartContainer extends CraftMinecart implements Lo
return getHandle().d; // PAIL rename lootTableSeed
}
- private void setLootTable(LootTable table, long seed) {
+ public void setLootTable(LootTable table, long seed) {
MinecraftKey newKey = (table == null) ? null : CraftNamespacedKey.toMinecraft(table.getKey());
getHandle().a(newKey, seed);
}
2016-05-02 03:54:08 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartHopper.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartHopper.java
2018-08-12 17:11:08 +00:00
index f29365c948..c51de47433 100644
2016-05-02 03:54:08 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartHopper.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartHopper.java
@@ -1,5 +1,6 @@
package org.bukkit.craftbukkit.entity;
+import com.destroystokyo.paper.loottable.CraftLootableEntityInventory; // Paper
import net.minecraft.server.EntityMinecartHopper;
import org.bukkit.craftbukkit.CraftServer;
@@ -8,7 +9,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.minecart.HopperMinecart;
import org.bukkit.inventory.Inventory;
2018-08-12 17:11:08 +00:00
-public final class CraftMinecartHopper extends CraftMinecartContainer implements HopperMinecart {
+public final class CraftMinecartHopper extends CraftMinecartContainer implements HopperMinecart, CraftLootableEntityInventory { // Paper
2016-05-02 03:54:08 +00:00
private final CraftInventory inventory;
2018-08-12 17:11:08 +00:00
public CraftMinecartHopper(CraftServer server, EntityMinecartHopper entity) {
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
index eb643cff3a..a3789c86b0 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java
@@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntityInsentient;
+import net.minecraft.server.MinecraftKey;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.CraftServer;
@@ -46,6 +47,13 @@ public abstract class CraftMob extends CraftLivingEntity implements Mob {
getHandle().bI = (table == null) ? null : CraftNamespacedKey.toMinecraft(table.getKey()); // PAIL rename lootTableKey
}
+ // Paper start
+ public void setLootTable(LootTable table, long seed) {
+ setLootTable(table);
+ setSeed(seed);
+ }
+ // Paper end
+
@Override
public LootTable getLootTable() {
if (getHandle().bI == null) {
2016-05-02 03:54:08 +00:00
--
2018-07-19 04:42:43 +00:00
2.18.0
2016-05-02 03:54:08 +00:00