2021-03-15 23:00:00 +01:00
|
|
|
--- a/net/minecraft/world/inventory/ContainerLectern.java
|
|
|
|
+++ b/net/minecraft/world/inventory/ContainerLectern.java
|
2021-06-11 07:00:00 +02:00
|
|
|
@@ -5,8 +5,33 @@
|
2021-03-15 23:00:00 +01:00
|
|
|
import net.minecraft.world.entity.player.EntityHuman;
|
|
|
|
import net.minecraft.world.item.ItemStack;
|
2019-04-23 04:00:00 +02:00
|
|
|
|
|
|
|
+// CraftBukkit start
|
2021-05-29 10:52:49 +02:00
|
|
|
+import net.minecraft.world.level.block.entity.TileEntityLectern.LecternInventory;
|
2021-03-15 23:00:00 +01:00
|
|
|
+import net.minecraft.world.entity.player.PlayerInventory;
|
2019-05-07 17:15:32 +02:00
|
|
|
+import org.bukkit.Bukkit;
|
2019-04-23 04:00:00 +02:00
|
|
|
+import org.bukkit.craftbukkit.inventory.CraftInventoryLectern;
|
|
|
|
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
|
|
|
+import org.bukkit.entity.Player;
|
2019-05-07 17:15:32 +02:00
|
|
|
+import org.bukkit.event.player.PlayerTakeLecternBookEvent;
|
2019-04-23 04:00:00 +02:00
|
|
|
+// 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;
|
|
|
|
+ }
|
|
|
|
+
|
2021-06-11 07:00:00 +02:00
|
|
|
+ CraftInventoryLectern inventory = new CraftInventoryLectern(this.lectern);
|
2019-04-23 04:00:00 +02:00
|
|
|
+ bukkitEntity = new CraftInventoryView(this.player, inventory, this);
|
|
|
|
+ return bukkitEntity;
|
|
|
|
+ }
|
|
|
|
+ // CraftBukkit end
|
2021-06-11 07:00:00 +02:00
|
|
|
private static final int DATA_COUNT = 1;
|
|
|
|
private static final int SLOT_COUNT = 1;
|
|
|
|
public static final int BUTTON_PREV_PAGE = 1;
|
|
|
|
@@ -16,11 +41,13 @@
|
|
|
|
private final IInventory lectern;
|
|
|
|
private final IContainerProperties lecternData;
|
2019-04-23 04:00:00 +02:00
|
|
|
|
|
|
|
- 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);
|
2021-06-11 07:00:00 +02:00
|
|
|
@@ -34,6 +61,7 @@
|
2019-04-23 04:00:00 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
this.a(icontainerproperties);
|
|
|
|
+ player = (Player) playerinventory.player.getBukkitEntity(); // CraftBukkit
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-06-11 07:00:00 +02:00
|
|
|
@@ -59,6 +87,13 @@
|
2019-05-27 22:30:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
2019-05-07 17:15:32 +02:00
|
|
|
|
2019-05-27 22:30:00 +02:00
|
|
|
+ // 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
|
2021-06-11 07:00:00 +02:00
|
|
|
ItemStack itemstack = this.lectern.splitWithoutUpdate(0);
|
2019-05-07 17:15:32 +02:00
|
|
|
|
2021-06-11 07:00:00 +02:00
|
|
|
this.lectern.update();
|
|
|
|
@@ -81,6 +116,8 @@
|
2019-04-23 04:00:00 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canUse(EntityHuman entityhuman) {
|
2021-06-11 07:00:00 +02:00
|
|
|
+ if (lectern instanceof LecternInventory && !((LecternInventory) lectern).getLectern().hasBook()) return false; // CraftBukkit
|
2019-04-23 04:00:00 +02:00
|
|
|
+ if (!this.checkReachable) return true; // CraftBukkit
|
2021-06-11 07:00:00 +02:00
|
|
|
return this.lectern.a(entityhuman);
|
2019-04-23 04:00:00 +02:00
|
|
|
}
|
2021-06-11 07:00:00 +02:00
|
|
|
|