PaperMC/paper-server/nms-patches/net/minecraft/world/inventory/ContainerLectern.patch

81 lines
3.1 KiB
Diff
Raw Normal View History

2021-03-15 23:00:00 +01:00
--- a/net/minecraft/world/inventory/ContainerLectern.java
+++ b/net/minecraft/world/inventory/ContainerLectern.java
@@ -5,16 +5,43 @@
2021-03-15 23:00:00 +01:00
import net.minecraft.world.entity.player.EntityHuman;
import net.minecraft.world.item.ItemStack;
+// CraftBukkit start
+import net.minecraft.world.level.block.entity.TileEntityLectern.LecternInventory;
2021-03-15 23:00:00 +01:00
+import net.minecraft.world.entity.player.PlayerInventory;
+import org.bukkit.Bukkit;
+import org.bukkit.craftbukkit.inventory.CraftInventoryLectern;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+import org.bukkit.entity.Player;
+import org.bukkit.event.player.PlayerTakeLecternBookEvent;
+// CraftBukkit end
+
public class ContainerLectern extends Container {
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private Player player;
+
+ @Override
+ public CraftInventoryView getBukkitView() {
+ if (bukkitEntity != null) {
+ return bukkitEntity;
+ }
+
+ CraftInventoryLectern inventory = new CraftInventoryLectern(this.inventory);
+ bukkitEntity = new CraftInventoryView(this.player, inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
private final IInventory inventory;
private final IContainerProperties containerProperties;
- public ContainerLectern(int i) {
- this(i, new InventorySubcontainer(1), new ContainerProperties(1));
+ // CraftBukkit start - add player
+ public ContainerLectern(int i, PlayerInventory playerinventory) {
+ this(i, new InventorySubcontainer(1), new ContainerProperties(1), playerinventory);
}
- public ContainerLectern(int i, IInventory iinventory, IContainerProperties icontainerproperties) {
+ public ContainerLectern(int i, IInventory iinventory, IContainerProperties icontainerproperties, PlayerInventory playerinventory) {
+ // CraftBukkit end
super(Containers.LECTERN, i);
a(iinventory, 1);
a(icontainerproperties, 1);
@@ -28,6 +55,7 @@
}
});
this.a(icontainerproperties);
+ player = (Player) playerinventory.player.getBukkitEntity(); // CraftBukkit
}
@Override
@@ -53,6 +81,13 @@
return false;
}
+ // CraftBukkit start - Event for taking the book
+ PlayerTakeLecternBookEvent event = new PlayerTakeLecternBookEvent(player, ((CraftInventoryLectern) getBukkitView().getTopInventory()).getHolder());
+ Bukkit.getServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return false;
+ }
+ // CraftBukkit end
ItemStack itemstack = this.inventory.splitWithoutUpdate(0);
this.inventory.update();
@@ -75,6 +110,8 @@
@Override
public boolean canUse(EntityHuman entityhuman) {
+ if (inventory instanceof LecternInventory && !((LecternInventory) inventory).getLectern().hasBook()) return false; // CraftBukkit
+ if (!this.checkReachable) return true; // CraftBukkit
return this.inventory.a(entityhuman);
}
}