172 lines
6.0 KiB
Diff
172 lines
6.0 KiB
Diff
--- a/net/minecraft/world/level/block/entity/TileEntityLectern.java
|
|
+++ b/net/minecraft/world/level/block/entity/TileEntityLectern.java
|
|
@@ -33,13 +33,72 @@
|
|
import net.minecraft.world.phys.Vec2F;
|
|
import net.minecraft.world.phys.Vec3D;
|
|
|
|
+// CraftBukkit start
|
|
+import java.util.ArrayList;
|
|
+import java.util.Arrays;
|
|
+import java.util.List;
|
|
+import org.bukkit.Location;
|
|
+import org.bukkit.block.Lectern;
|
|
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
|
+import org.bukkit.craftbukkit.util.CraftLocation;
|
|
+import org.bukkit.entity.HumanEntity;
|
|
+import org.bukkit.inventory.InventoryHolder;
|
|
+// CraftBukkit end
|
|
+
|
|
public class TileEntityLectern extends TileEntity implements Clearable, ITileInventory {
|
|
|
|
public static final int DATA_PAGE = 0;
|
|
public static final int NUM_DATA = 1;
|
|
public static final int SLOT_BOOK = 0;
|
|
public static final int NUM_SLOTS = 1;
|
|
- public final IInventory bookAccess = new IInventory() {
|
|
+ // CraftBukkit start - add fields and methods
|
|
+ public final IInventory bookAccess = new LecternInventory();
|
|
+ public class LecternInventory implements IInventory {
|
|
+
|
|
+ public List<HumanEntity> transaction = new ArrayList<>();
|
|
+ private int maxStack = 1;
|
|
+
|
|
+ @Override
|
|
+ public List<ItemStack> getContents() {
|
|
+ return Arrays.asList(book);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void onOpen(CraftHumanEntity who) {
|
|
+ transaction.add(who);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void onClose(CraftHumanEntity who) {
|
|
+ transaction.remove(who);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public List<HumanEntity> getViewers() {
|
|
+ return transaction;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setMaxStackSize(int i) {
|
|
+ maxStack = i;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Location getLocation() {
|
|
+ if (level == null) return null;
|
|
+ return CraftLocation.toBukkit(worldPosition, level.getWorld());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public InventoryHolder getOwner() {
|
|
+ return (Lectern) TileEntityLectern.this.getOwner();
|
|
+ }
|
|
+
|
|
+ public TileEntityLectern getLectern() {
|
|
+ return TileEntityLectern.this;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
@Override
|
|
public int getContainerSize() {
|
|
return 1;
|
|
@@ -84,11 +143,20 @@
|
|
}
|
|
|
|
@Override
|
|
- public void setItem(int i, ItemStack itemstack) {}
|
|
+ // CraftBukkit start
|
|
+ public void setItem(int i, ItemStack itemstack) {
|
|
+ if (i == 0) {
|
|
+ TileEntityLectern.this.setBook(itemstack);
|
|
+ if (TileEntityLectern.this.getLevel() != null) {
|
|
+ BlockLectern.resetBookState(null, TileEntityLectern.this.getLevel(), TileEntityLectern.this.getBlockPos(), TileEntityLectern.this.getBlockState(), TileEntityLectern.this.hasBook());
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ // CraftBukkit end
|
|
|
|
@Override
|
|
public int getMaxStackSize() {
|
|
- return 1;
|
|
+ return maxStack; // CraftBukkit
|
|
}
|
|
|
|
@Override
|
|
@@ -168,7 +236,7 @@
|
|
if (j != this.page) {
|
|
this.page = j;
|
|
this.setChanged();
|
|
- BlockLectern.signalPageChange(this.getLevel(), this.getBlockPos(), this.getBlockState());
|
|
+ if (this.level != null) BlockLectern.signalPageChange(this.getLevel(), this.getBlockPos(), this.getBlockState()); // CraftBukkit
|
|
}
|
|
|
|
}
|
|
@@ -193,6 +261,35 @@
|
|
return itemstack;
|
|
}
|
|
|
|
+ // CraftBukkit start
|
|
+ private final ICommandListener commandSource = new ICommandListener() {
|
|
+
|
|
+ @Override
|
|
+ public void sendSystemMessage(IChatBaseComponent ichatbasecomponent) {
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public org.bukkit.command.CommandSender getBukkitSender(CommandListenerWrapper wrapper) {
|
|
+ return wrapper.getEntity() != null ? wrapper.getEntity().getBukkitEntity() : new org.bukkit.craftbukkit.command.CraftBlockCommandSender(wrapper, TileEntityLectern.this);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean acceptsSuccess() {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean acceptsFailure() {
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean shouldInformAdmins() {
|
|
+ return false;
|
|
+ }
|
|
+ };
|
|
+ // CraftBukkit end
|
|
+
|
|
private CommandListenerWrapper createCommandSourceStack(@Nullable EntityHuman entityhuman, WorldServer worldserver) {
|
|
String s;
|
|
IChatBaseComponent ichatbasecomponent;
|
|
@@ -207,7 +304,8 @@
|
|
|
|
Vec3D vec3d = Vec3D.atCenterOf(this.worldPosition);
|
|
|
|
- return new CommandListenerWrapper(ICommandListener.NULL, vec3d, Vec2F.ZERO, worldserver, 2, s, ichatbasecomponent, worldserver.getServer(), entityhuman);
|
|
+ // CraftBukkit - commandSource
|
|
+ return new CommandListenerWrapper(commandSource, vec3d, Vec2F.ZERO, worldserver, 2, s, ichatbasecomponent, worldserver.getServer(), entityhuman);
|
|
}
|
|
|
|
@Override
|
|
@@ -244,6 +342,7 @@
|
|
if ((Boolean) iblockdata.getValue(BlockLectern.HAS_BOOK) && this.level != null) {
|
|
EnumDirection enumdirection = (EnumDirection) iblockdata.getValue(BlockLectern.FACING);
|
|
ItemStack itemstack = this.getBook().copy();
|
|
+ if (itemstack.isEmpty()) return; // CraftBukkit - SPIGOT-5500
|
|
float f = 0.25F * (float) enumdirection.getStepX();
|
|
float f1 = 0.25F * (float) enumdirection.getStepZ();
|
|
EntityItem entityitem = new EntityItem(this.level, (double) blockposition.getX() + 0.5D + (double) f, (double) (blockposition.getY() + 1), (double) blockposition.getZ() + 0.5D + (double) f1, itemstack);
|
|
@@ -256,7 +355,7 @@
|
|
|
|
@Override
|
|
public Container createMenu(int i, PlayerInventory playerinventory, EntityHuman entityhuman) {
|
|
- return new ContainerLectern(i, this.bookAccess, this.dataAccess);
|
|
+ return new ContainerLectern(i, this.bookAccess, this.dataAccess, playerinventory); // CraftBukkit
|
|
}
|
|
|
|
@Override
|