@@ -0,0 +1,151 @@
|
||||
--- a/net/minecraft/server/Container.java
|
||||
+++ b/net/minecraft/server/Container.java
|
||||
@@ -7,6 +7,18 @@
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import com.google.common.base.Preconditions;
|
||||
+import java.util.HashMap;
|
||||
+import java.util.Map;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
+import org.bukkit.event.Event.Result;
|
||||
+import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
+import org.bukkit.event.inventory.InventoryType;
|
||||
+import org.bukkit.inventory.InventoryView;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public abstract class Container {
|
||||
|
||||
public NonNullList<ItemStack> items = NonNullList.a();
|
||||
@@ -21,6 +33,27 @@
|
||||
private final List<ICrafting> listeners = Lists.newArrayList();
|
||||
private final Set<EntityHuman> k = Sets.newHashSet();
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ public boolean checkReachable = true;
|
||||
+ public abstract InventoryView getBukkitView();
|
||||
+ public void transferTo(Container other, org.bukkit.craftbukkit.entity.CraftHumanEntity player) {
|
||||
+ InventoryView source = this.getBukkitView(), destination = other.getBukkitView();
|
||||
+ ((CraftInventory) source.getTopInventory()).getInventory().onClose(player);
|
||||
+ ((CraftInventory) source.getBottomInventory()).getInventory().onClose(player);
|
||||
+ ((CraftInventory) destination.getTopInventory()).getInventory().onOpen(player);
|
||||
+ ((CraftInventory) destination.getBottomInventory()).getInventory().onOpen(player);
|
||||
+ }
|
||||
+ private IChatBaseComponent title;
|
||||
+ public final IChatBaseComponent getTitle() {
|
||||
+ Preconditions.checkState(this.title != null, "Title not set");
|
||||
+ return this.title;
|
||||
+ }
|
||||
+ public final void setTitle(IChatBaseComponent title) {
|
||||
+ Preconditions.checkState(this.title == null, "Title already set");
|
||||
+ this.title = title;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
protected Container(@Nullable Containers<?> containers, int i) {
|
||||
this.e = containers;
|
||||
this.windowId = i;
|
||||
@@ -202,6 +235,7 @@
|
||||
k = playerinventory.getCarried().getCount();
|
||||
Iterator iterator = this.i.iterator();
|
||||
|
||||
+ Map<Integer, ItemStack> draggedSlots = new HashMap<Integer, ItemStack>(); // CraftBukkit - Store slots from drag in map (raw slot id -> new stack)
|
||||
while (iterator.hasNext()) {
|
||||
Slot slot1 = (Slot) iterator.next();
|
||||
ItemStack itemstack3 = playerinventory.getCarried();
|
||||
@@ -217,12 +251,48 @@
|
||||
}
|
||||
|
||||
k -= itemstack4.getCount() - j1;
|
||||
- slot1.set(itemstack4);
|
||||
+ // slot1.set(itemstack4);
|
||||
+ draggedSlots.put(slot1.rawSlotIndex, itemstack4); // CraftBukkit - Put in map instead of setting
|
||||
}
|
||||
}
|
||||
|
||||
- itemstack2.setCount(k);
|
||||
- playerinventory.setCarried(itemstack2);
|
||||
+ // CraftBukkit start - InventoryDragEvent
|
||||
+ InventoryView view = getBukkitView();
|
||||
+ org.bukkit.inventory.ItemStack newcursor = CraftItemStack.asCraftMirror(itemstack2);
|
||||
+ newcursor.setAmount(k);
|
||||
+ Map<Integer, org.bukkit.inventory.ItemStack> eventmap = new HashMap<Integer, org.bukkit.inventory.ItemStack>();
|
||||
+ for (Map.Entry<Integer, ItemStack> ditem : draggedSlots.entrySet()) {
|
||||
+ eventmap.put(ditem.getKey(), CraftItemStack.asBukkitCopy(ditem.getValue()));
|
||||
+ }
|
||||
+
|
||||
+ // It's essential that we set the cursor to the new value here to prevent item duplication if a plugin closes the inventory.
|
||||
+ ItemStack oldCursor = playerinventory.getCarried();
|
||||
+ playerinventory.setCarried(CraftItemStack.asNMSCopy(newcursor));
|
||||
+
|
||||
+ InventoryDragEvent event = new InventoryDragEvent(view, (newcursor.getType() != org.bukkit.Material.AIR ? newcursor : null), CraftItemStack.asBukkitCopy(oldCursor), this.dragType == 1, eventmap);
|
||||
+ entityhuman.world.getServer().getPluginManager().callEvent(event);
|
||||
+
|
||||
+ // Whether or not a change was made to the inventory that requires an update.
|
||||
+ boolean needsUpdate = event.getResult() != Result.DEFAULT;
|
||||
+
|
||||
+ if (event.getResult() != Result.DENY) {
|
||||
+ for (Map.Entry<Integer, ItemStack> dslot : draggedSlots.entrySet()) {
|
||||
+ view.setItem(dslot.getKey(), CraftItemStack.asBukkitCopy(dslot.getValue()));
|
||||
+ }
|
||||
+ // The only time the carried item will be set to null is if the inventory is closed by the server.
|
||||
+ // If the inventory is closed by the server, then the cursor items are dropped. This is why we change the cursor early.
|
||||
+ if (playerinventory.getCarried() != null) {
|
||||
+ playerinventory.setCarried(CraftItemStack.asNMSCopy(event.getCursor()));
|
||||
+ needsUpdate = true;
|
||||
+ }
|
||||
+ } else {
|
||||
+ playerinventory.setCarried(oldCursor);
|
||||
+ }
|
||||
+
|
||||
+ if (needsUpdate && entityhuman instanceof EntityPlayer) {
|
||||
+ ((EntityPlayer) entityhuman).updateInventory(this);
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
|
||||
this.d();
|
||||
@@ -239,8 +309,11 @@
|
||||
if (i == -999) {
|
||||
if (!playerinventory.getCarried().isEmpty()) {
|
||||
if (j == 0) {
|
||||
- entityhuman.drop(playerinventory.getCarried(), true);
|
||||
+ // CraftBukkit start
|
||||
+ ItemStack carried = playerinventory.getCarried();
|
||||
playerinventory.setCarried(ItemStack.b);
|
||||
+ entityhuman.drop(carried, true);
|
||||
+ // CraftBukkit start
|
||||
}
|
||||
|
||||
if (j == 1) {
|
||||
@@ -328,6 +401,15 @@
|
||||
}
|
||||
|
||||
slot2.d();
|
||||
+ // CraftBukkit start - Make sure the client has the right slot contents
|
||||
+ if (entityhuman instanceof EntityPlayer && slot2.getMaxStackSize() != 64) {
|
||||
+ ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutSetSlot(this.windowId, slot2.rawSlotIndex, slot2.getItem()));
|
||||
+ // Updating a crafting inventory makes the client reset the result slot, have to send it again
|
||||
+ if (this.getBukkitView().getType() == InventoryType.WORKBENCH || this.getBukkitView().getType() == InventoryType.CRAFTING) {
|
||||
+ ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutSetSlot(this.windowId, 0, this.getSlot(0).getItem()));
|
||||
+ }
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
}
|
||||
} else if (inventoryclicktype == InventoryClickType.SWAP) {
|
||||
@@ -430,8 +512,11 @@
|
||||
PlayerInventory playerinventory = entityhuman.inventory;
|
||||
|
||||
if (!playerinventory.getCarried().isEmpty()) {
|
||||
- entityhuman.drop(playerinventory.getCarried(), false);
|
||||
+ // CraftBukkit start - SPIGOT-4556
|
||||
+ ItemStack carried = playerinventory.getCarried();
|
||||
playerinventory.setCarried(ItemStack.b);
|
||||
+ entityhuman.drop(carried, false);
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
--- a/net/minecraft/server/ContainerAccess.java
|
||||
+++ b/net/minecraft/server/ContainerAccess.java
|
||||
@@ -6,6 +6,20 @@
|
||||
|
||||
public interface ContainerAccess {
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ default World getWorld() {
|
||||
+ throw new UnsupportedOperationException("Not supported yet.");
|
||||
+ }
|
||||
+
|
||||
+ default BlockPosition getPosition() {
|
||||
+ throw new UnsupportedOperationException("Not supported yet.");
|
||||
+ }
|
||||
+
|
||||
+ default org.bukkit.Location getLocation() {
|
||||
+ return new org.bukkit.Location(getWorld().getWorld(), getPosition().getX(), getPosition().getY(), getPosition().getZ());
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
ContainerAccess a = new ContainerAccess() {
|
||||
@Override
|
||||
public <T> Optional<T> a(BiFunction<World, BlockPosition, T> bifunction) {
|
||||
@@ -15,6 +29,18 @@
|
||||
|
||||
static ContainerAccess at(final World world, final BlockPosition blockposition) {
|
||||
return new ContainerAccess() {
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public World getWorld() {
|
||||
+ return world;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public BlockPosition getPosition() {
|
||||
+ return blockposition;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
@Override
|
||||
public <T> Optional<T> a(BiFunction<World, BlockPosition, T> bifunction) {
|
||||
return Optional.of(bifunction.apply(world, blockposition));
|
||||
@@ -0,0 +1,102 @@
|
||||
--- a/net/minecraft/server/ContainerAnvil.java
|
||||
+++ b/net/minecraft/server/ContainerAnvil.java
|
||||
@@ -6,12 +6,20 @@
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ContainerAnvil extends ContainerAnvilAbstract {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private int h;
|
||||
public String renameText;
|
||||
public final ContainerProperty levelCost;
|
||||
+ // CraftBukkit start
|
||||
+ public int maximumRepairCost = 40;
|
||||
+ private CraftInventoryView bukkitEntity;
|
||||
+ // CraftBukkit end
|
||||
|
||||
public ContainerAnvil(int i, PlayerInventory playerinventory) {
|
||||
this(i, playerinventory, ContainerAccess.a);
|
||||
@@ -85,7 +93,7 @@
|
||||
byte b1 = 0;
|
||||
|
||||
if (itemstack.isEmpty()) {
|
||||
- this.resultInventory.setItem(0, ItemStack.b);
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.b); // CraftBukkit
|
||||
this.levelCost.set(0);
|
||||
} else {
|
||||
ItemStack itemstack1 = itemstack.cloneItemStack();
|
||||
@@ -103,7 +111,7 @@
|
||||
if (itemstack1.e() && itemstack1.getItem().a(itemstack, itemstack2)) {
|
||||
k = Math.min(itemstack1.getDamage(), itemstack1.h() / 4);
|
||||
if (k <= 0) {
|
||||
- this.resultInventory.setItem(0, ItemStack.b);
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.b); // CraftBukkit
|
||||
this.levelCost.set(0);
|
||||
return;
|
||||
}
|
||||
@@ -118,7 +126,7 @@
|
||||
this.h = i1;
|
||||
} else {
|
||||
if (!flag && (itemstack1.getItem() != itemstack2.getItem() || !itemstack1.e())) {
|
||||
- this.resultInventory.setItem(0, ItemStack.b);
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.b); // CraftBukkit
|
||||
this.levelCost.set(0);
|
||||
return;
|
||||
}
|
||||
@@ -208,7 +216,7 @@
|
||||
}
|
||||
|
||||
if (flag2 && !flag1) {
|
||||
- this.resultInventory.setItem(0, ItemStack.b);
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.b); // CraftBukkit
|
||||
this.levelCost.set(0);
|
||||
return;
|
||||
}
|
||||
@@ -232,11 +240,11 @@
|
||||
itemstack1 = ItemStack.b;
|
||||
}
|
||||
|
||||
- if (b1 == i && b1 > 0 && this.levelCost.get() >= 40) {
|
||||
- this.levelCost.set(39);
|
||||
+ if (b1 == i && b1 > 0 && this.levelCost.get() >= maximumRepairCost) { // CraftBukkit
|
||||
+ this.levelCost.set(maximumRepairCost - 1); // CraftBukkit
|
||||
}
|
||||
|
||||
- if (this.levelCost.get() >= 40 && !this.player.abilities.canInstantlyBuild) {
|
||||
+ if (this.levelCost.get() >= maximumRepairCost && !this.player.abilities.canInstantlyBuild) { // CraftBukkit
|
||||
itemstack1 = ItemStack.b;
|
||||
}
|
||||
|
||||
@@ -255,7 +263,7 @@
|
||||
EnchantmentManager.a(map, itemstack1);
|
||||
}
|
||||
|
||||
- this.resultInventory.setItem(0, itemstack1);
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), itemstack1); // CraftBukkit
|
||||
this.c();
|
||||
}
|
||||
}
|
||||
@@ -278,4 +286,18 @@
|
||||
|
||||
this.e();
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public CraftInventoryView getBukkitView() {
|
||||
+ if (bukkitEntity != null) {
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+
|
||||
+ org.bukkit.craftbukkit.inventory.CraftInventory inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryAnvil(
|
||||
+ containerAccess.getLocation(), this.repairInventory, this.resultInventory, this);
|
||||
+ bukkitEntity = new CraftInventoryView(this.player.getBukkitEntity(), inventory, this);
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
--- a/net/minecraft/server/ContainerAnvilAbstract.java
|
||||
+++ b/net/minecraft/server/ContainerAnvilAbstract.java
|
||||
@@ -79,6 +79,7 @@
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityhuman) {
|
||||
+ if (!this.checkReachable) return true; // CraftBukkit
|
||||
return (Boolean) this.containerAccess.a((world, blockposition) -> {
|
||||
return !this.a(world.getType(blockposition)) ? false : entityhuman.h((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) <= 64.0D;
|
||||
}, true);
|
||||
@@ -0,0 +1,54 @@
|
||||
--- a/net/minecraft/server/ContainerBeacon.java
|
||||
+++ b/net/minecraft/server/ContainerBeacon.java
|
||||
@@ -1,11 +1,17 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryView; // CraftBukkit
|
||||
+
|
||||
public class ContainerBeacon extends Container {
|
||||
|
||||
private final IInventory beacon;
|
||||
private final ContainerBeacon.SlotBeacon d;
|
||||
private final ContainerAccess containerAccess;
|
||||
private final IContainerProperties containerProperties;
|
||||
+ // CraftBukkit start
|
||||
+ private CraftInventoryView bukkitEntity = null;
|
||||
+ private PlayerInventory player;
|
||||
+ // CraftBukkit end
|
||||
|
||||
public ContainerBeacon(int i, IInventory iinventory) {
|
||||
this(i, iinventory, new ContainerProperties(3), ContainerAccess.a);
|
||||
@@ -13,6 +19,7 @@
|
||||
|
||||
public ContainerBeacon(int i, IInventory iinventory, IContainerProperties icontainerproperties, ContainerAccess containeraccess) {
|
||||
super(Containers.BEACON, i);
|
||||
+ player = (PlayerInventory) iinventory; // CraftBukkit - TODO: check this
|
||||
this.beacon = new InventorySubcontainer(1) {
|
||||
@Override
|
||||
public boolean b(int j, ItemStack itemstack) {
|
||||
@@ -62,6 +69,7 @@
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityhuman) {
|
||||
+ if (!this.checkReachable) return true; // CraftBukkit
|
||||
return a(this.containerAccess, entityhuman, Blocks.BEACON);
|
||||
}
|
||||
|
||||
@@ -143,4 +151,17 @@
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public CraftInventoryView getBukkitView() {
|
||||
+ if (bukkitEntity != null) {
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+
|
||||
+ org.bukkit.craftbukkit.inventory.CraftInventory inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryBeacon(this.beacon);
|
||||
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
--- a/net/minecraft/server/ContainerBrewingStand.java
|
||||
+++ b/net/minecraft/server/ContainerBrewingStand.java
|
||||
@@ -1,17 +1,28 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryBrewer;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ContainerBrewingStand extends Container {
|
||||
|
||||
private final IInventory brewingStand;
|
||||
private final IContainerProperties d;
|
||||
private final Slot e;
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ private CraftInventoryView bukkitEntity = null;
|
||||
+ private PlayerInventory player;
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public ContainerBrewingStand(int i, PlayerInventory playerinventory) {
|
||||
this(i, playerinventory, new InventorySubcontainer(5), new ContainerProperties(2));
|
||||
}
|
||||
|
||||
public ContainerBrewingStand(int i, PlayerInventory playerinventory, IInventory iinventory, IContainerProperties icontainerproperties) {
|
||||
super(Containers.BREWING_STAND, i);
|
||||
+ player = playerinventory; // CraftBukkit
|
||||
a(iinventory, 5);
|
||||
a(icontainerproperties, 2);
|
||||
this.brewingStand = iinventory;
|
||||
@@ -39,6 +50,7 @@
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityhuman) {
|
||||
+ if (!this.checkReachable) return true; // CraftBukkit
|
||||
return this.brewingStand.a(entityhuman);
|
||||
}
|
||||
|
||||
@@ -171,4 +183,17 @@
|
||||
return item == Items.POTION || item == Items.SPLASH_POTION || item == Items.LINGERING_POTION || item == Items.GLASS_BOTTLE;
|
||||
}
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public CraftInventoryView getBukkitView() {
|
||||
+ if (bukkitEntity != null) {
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+
|
||||
+ CraftInventoryBrewer inventory = new CraftInventoryBrewer(this.brewingStand);
|
||||
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
--- a/net/minecraft/server/ContainerCartography.java
|
||||
+++ b/net/minecraft/server/ContainerCartography.java
|
||||
@@ -1,7 +1,29 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.Location;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryCartography;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
+import org.bukkit.entity.Player;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ContainerCartography extends Container {
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ private CraftInventoryView bukkitEntity = null;
|
||||
+ private Player player;
|
||||
+
|
||||
+ @Override
|
||||
+ public CraftInventoryView getBukkitView() {
|
||||
+ if (bukkitEntity != null) {
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+
|
||||
+ CraftInventoryCartography inventory = new CraftInventoryCartography(this.inventory, this.resultInventory);
|
||||
+ bukkitEntity = new CraftInventoryView(this.player, inventory, this);
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
private final ContainerAccess containerAccess;
|
||||
private long e;
|
||||
public final IInventory inventory;
|
||||
@@ -19,6 +41,13 @@
|
||||
ContainerCartography.this.a((IInventory) this);
|
||||
super.update();
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public Location getLocation() {
|
||||
+ return containeraccess.getLocation();
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
};
|
||||
this.resultInventory = new InventoryCraftResult() {
|
||||
@Override
|
||||
@@ -26,6 +55,13 @@
|
||||
ContainerCartography.this.a((IInventory) this);
|
||||
super.update();
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public Location getLocation() {
|
||||
+ return containeraccess.getLocation();
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
};
|
||||
this.containerAccess = containeraccess;
|
||||
this.a(new Slot(this.inventory, 0, 15, 15) {
|
||||
@@ -78,10 +114,12 @@
|
||||
this.a(new Slot(playerinventory, j, 8 + j * 18, 142));
|
||||
}
|
||||
|
||||
+ player = (Player) playerinventory.player.getBukkitEntity(); // CraftBukkit
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityhuman) {
|
||||
+ if (!this.checkReachable) return true; // CraftBukkit
|
||||
return a(this.containerAccess, entityhuman, Blocks.CARTOGRAPHY_TABLE);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
--- a/net/minecraft/server/ContainerChest.java
|
||||
+++ b/net/minecraft/server/ContainerChest.java
|
||||
@@ -1,9 +1,37 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ContainerChest extends Container {
|
||||
|
||||
private final IInventory container;
|
||||
private final int d;
|
||||
+ // CraftBukkit start
|
||||
+ private CraftInventoryView bukkitEntity = null;
|
||||
+ private PlayerInventory player;
|
||||
+
|
||||
+ @Override
|
||||
+ public CraftInventoryView getBukkitView() {
|
||||
+ if (bukkitEntity != null) {
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+
|
||||
+ CraftInventory inventory;
|
||||
+ if (this.container instanceof PlayerInventory) {
|
||||
+ inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryPlayer((PlayerInventory) this.container);
|
||||
+ } else if (this.container instanceof InventoryLargeChest) {
|
||||
+ inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest((InventoryLargeChest) this.container);
|
||||
+ } else {
|
||||
+ inventory = new CraftInventory(this.container);
|
||||
+ }
|
||||
+
|
||||
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
private ContainerChest(Containers<?> containers, int i, PlayerInventory playerinventory, int j) {
|
||||
this(containers, i, playerinventory, new InventorySubcontainer(9 * j), j);
|
||||
@@ -49,6 +77,10 @@
|
||||
iinventory.startOpen(playerinventory.player);
|
||||
int k = (this.d - 4) * 18;
|
||||
|
||||
+ // CraftBukkit start - Save player
|
||||
+ this.player = playerinventory;
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
int l;
|
||||
int i1;
|
||||
|
||||
@@ -72,6 +104,7 @@
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityhuman) {
|
||||
+ if (!this.checkReachable) return true; // CraftBukkit
|
||||
return this.container.a(entityhuman);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
--- a/net/minecraft/server/ContainerDispenser.java
|
||||
+++ b/net/minecraft/server/ContainerDispenser.java
|
||||
@@ -1,8 +1,17 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ContainerDispenser extends Container {
|
||||
|
||||
public final IInventory items;
|
||||
+ // CraftBukkit start
|
||||
+ private CraftInventoryView bukkitEntity = null;
|
||||
+ private PlayerInventory player;
|
||||
+ // CraftBukkit end
|
||||
|
||||
public ContainerDispenser(int i, PlayerInventory playerinventory) {
|
||||
this(i, playerinventory, new InventorySubcontainer(9));
|
||||
@@ -10,6 +19,10 @@
|
||||
|
||||
public ContainerDispenser(int i, PlayerInventory playerinventory, IInventory iinventory) {
|
||||
super(Containers.GENERIC_3X3, i);
|
||||
+ // CraftBukkit start - Save player
|
||||
+ this.player = playerinventory;
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
a(iinventory, 9);
|
||||
this.items = iinventory;
|
||||
iinventory.startOpen(playerinventory.player);
|
||||
@@ -37,6 +50,7 @@
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityhuman) {
|
||||
+ if (!this.checkReachable) return true; // CraftBukkit
|
||||
return this.items.a(entityhuman);
|
||||
}
|
||||
|
||||
@@ -78,4 +92,17 @@
|
||||
super.b(entityhuman);
|
||||
this.items.closeContainer(entityhuman);
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public CraftInventoryView getBukkitView() {
|
||||
+ if (bukkitEntity != null) {
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+
|
||||
+ CraftInventory inventory = new CraftInventory(this.items);
|
||||
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
--- a/net/minecraft/server/ContainerEnchantTable.java
|
||||
+++ b/net/minecraft/server/ContainerEnchantTable.java
|
||||
@@ -3,6 +3,20 @@
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import java.util.Map;
|
||||
+import org.bukkit.Location;
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryEnchanting;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
+import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
+import org.bukkit.enchantments.EnchantmentOffer;
|
||||
+import org.bukkit.event.enchantment.EnchantItemEvent;
|
||||
+import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
|
||||
+import org.bukkit.entity.Player;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ContainerEnchantTable extends Container {
|
||||
|
||||
private final IInventory enchantSlots;
|
||||
@@ -12,6 +26,10 @@
|
||||
public final int[] costs;
|
||||
public final int[] enchantments;
|
||||
public final int[] levels;
|
||||
+ // CraftBukkit start
|
||||
+ private CraftInventoryView bukkitEntity = null;
|
||||
+ private Player player;
|
||||
+ // CraftBukkit end
|
||||
|
||||
public ContainerEnchantTable(int i, PlayerInventory playerinventory) {
|
||||
this(i, playerinventory, ContainerAccess.a);
|
||||
@@ -25,6 +43,13 @@
|
||||
super.update();
|
||||
ContainerEnchantTable.this.a((IInventory) this);
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public Location getLocation() {
|
||||
+ return containeraccess.getLocation();
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
};
|
||||
this.h = new Random();
|
||||
this.i = ContainerProperty.a();
|
||||
@@ -72,6 +97,9 @@
|
||||
this.a(ContainerProperty.a(this.levels, 0));
|
||||
this.a(ContainerProperty.a(this.levels, 1));
|
||||
this.a(ContainerProperty.a(this.levels, 2));
|
||||
+ // CraftBukkit start
|
||||
+ player = (Player) playerinventory.player.getBukkitEntity();
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,7 +107,7 @@
|
||||
if (iinventory == this.enchantSlots) {
|
||||
ItemStack itemstack = iinventory.getItem(0);
|
||||
|
||||
- if (!itemstack.isEmpty() && itemstack.canEnchant()) {
|
||||
+ if (!itemstack.isEmpty()) { // CraftBukkit - relax condition
|
||||
this.containerAccess.a((world, blockposition) -> {
|
||||
int i = 0;
|
||||
|
||||
@@ -135,12 +163,47 @@
|
||||
if (list != null && !list.isEmpty()) {
|
||||
WeightedRandomEnchant weightedrandomenchant = (WeightedRandomEnchant) list.get(this.h.nextInt(list.size()));
|
||||
|
||||
- this.enchantments[j] = IRegistry.ENCHANTMENT.a((Object) weightedrandomenchant.enchantment);
|
||||
+ this.enchantments[j] = IRegistry.ENCHANTMENT.a(weightedrandomenchant.enchantment); // CraftBukkit - decompile error
|
||||
this.levels[j] = weightedrandomenchant.level;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ CraftItemStack item = CraftItemStack.asCraftMirror(itemstack);
|
||||
+ org.bukkit.enchantments.EnchantmentOffer[] offers = new EnchantmentOffer[3];
|
||||
+ for (j = 0; j < 3; ++j) {
|
||||
+ org.bukkit.enchantments.Enchantment enchantment = (this.enchantments[j] >= 0) ? org.bukkit.enchantments.Enchantment.getByKey(CraftNamespacedKey.fromMinecraft(IRegistry.ENCHANTMENT.getKey(IRegistry.ENCHANTMENT.fromId(this.enchantments[j])))) : null;
|
||||
+ offers[j] = (enchantment != null) ? new EnchantmentOffer(enchantment, this.levels[j], this.costs[j]) : null;
|
||||
+ }
|
||||
+
|
||||
+ PrepareItemEnchantEvent event = new PrepareItemEnchantEvent(player, this.getBukkitView(), containerAccess.getLocation().getBlock(), item, offers, i);
|
||||
+ event.setCancelled(!itemstack.canEnchant());
|
||||
+ world.getServer().getPluginManager().callEvent(event);
|
||||
+
|
||||
+ if (event.isCancelled()) {
|
||||
+ for (j = 0; j < 3; ++j) {
|
||||
+ this.costs[j] = 0;
|
||||
+ this.enchantments[j] = -1;
|
||||
+ this.levels[j] = -1;
|
||||
+ }
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ for (j = 0; j < 3; j++) {
|
||||
+ EnchantmentOffer offer = event.getOffers()[j];
|
||||
+ if (offer != null) {
|
||||
+ this.costs[j] = offer.getCost();
|
||||
+ this.enchantments[j] = IRegistry.ENCHANTMENT.a(IRegistry.ENCHANTMENT.get(CraftNamespacedKey.toMinecraft(offer.getEnchantment().getKey())));
|
||||
+ this.levels[j] = offer.getEnchantmentLevel();
|
||||
+ } else {
|
||||
+ this.costs[j] = 0;
|
||||
+ this.enchantments[j] = -1;
|
||||
+ this.levels[j] = -1;
|
||||
+ }
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
this.c();
|
||||
});
|
||||
} else {
|
||||
@@ -167,9 +230,24 @@
|
||||
ItemStack itemstack2 = itemstack;
|
||||
List<WeightedRandomEnchant> list = this.a(itemstack, i, this.costs[i]);
|
||||
|
||||
- if (!list.isEmpty()) {
|
||||
- entityhuman.enchantDone(itemstack, j);
|
||||
+ // CraftBukkit start
|
||||
+ if (true || !list.isEmpty()) {
|
||||
+ // entityhuman.enchantDone(itemstack, j); // Moved down
|
||||
boolean flag = itemstack.getItem() == Items.BOOK;
|
||||
+ Map<org.bukkit.enchantments.Enchantment, Integer> enchants = new java.util.HashMap<org.bukkit.enchantments.Enchantment, Integer>();
|
||||
+ for (Object obj : list) {
|
||||
+ WeightedRandomEnchant instance = (WeightedRandomEnchant) obj;
|
||||
+ enchants.put(org.bukkit.enchantments.Enchantment.getByKey(CraftNamespacedKey.fromMinecraft(IRegistry.ENCHANTMENT.getKey(instance.enchantment))), instance.level);
|
||||
+ }
|
||||
+ CraftItemStack item = CraftItemStack.asCraftMirror(itemstack2);
|
||||
+
|
||||
+ EnchantItemEvent event = new EnchantItemEvent((Player) entityhuman.getBukkitEntity(), this.getBukkitView(), containerAccess.getLocation().getBlock(), item, this.costs[i], enchants, i);
|
||||
+ world.getServer().getPluginManager().callEvent(event);
|
||||
+
|
||||
+ int level = event.getExpLevelCost();
|
||||
+ if (event.isCancelled() || (level > entityhuman.expLevel && !entityhuman.abilities.canInstantlyBuild) || event.getEnchantsToAdd().isEmpty()) {
|
||||
+ return;
|
||||
+ }
|
||||
|
||||
if (flag) {
|
||||
itemstack2 = new ItemStack(Items.ENCHANTED_BOOK);
|
||||
@@ -182,16 +260,29 @@
|
||||
this.enchantSlots.setItem(0, itemstack2);
|
||||
}
|
||||
|
||||
- for (int k = 0; k < list.size(); ++k) {
|
||||
- WeightedRandomEnchant weightedrandomenchant = (WeightedRandomEnchant) list.get(k);
|
||||
+ for (Map.Entry<org.bukkit.enchantments.Enchantment, Integer> entry : event.getEnchantsToAdd().entrySet()) {
|
||||
+ try {
|
||||
+ if (flag) {
|
||||
+ NamespacedKey enchantId = entry.getKey().getKey();
|
||||
+ Enchantment nms = IRegistry.ENCHANTMENT.get(CraftNamespacedKey.toMinecraft(enchantId));
|
||||
+ if (nms == null) {
|
||||
+ continue;
|
||||
+ }
|
||||
|
||||
- if (flag) {
|
||||
- ItemEnchantedBook.a(itemstack2, weightedrandomenchant);
|
||||
- } else {
|
||||
- itemstack2.addEnchantment(weightedrandomenchant.enchantment, weightedrandomenchant.level);
|
||||
+ WeightedRandomEnchant weightedrandomenchant = new WeightedRandomEnchant(nms, entry.getValue());
|
||||
+ ItemEnchantedBook.a(itemstack2, weightedrandomenchant);
|
||||
+ } else {
|
||||
+ item.addUnsafeEnchantment(entry.getKey(), entry.getValue());
|
||||
+ }
|
||||
+ } catch (IllegalArgumentException e) {
|
||||
+ /* Just swallow invalid enchantments */
|
||||
}
|
||||
}
|
||||
|
||||
+ entityhuman.enchantDone(itemstack, j);
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
+ // CraftBukkit - TODO: let plugins change this
|
||||
if (!entityhuman.abilities.canInstantlyBuild) {
|
||||
itemstack1.subtract(j);
|
||||
if (itemstack1.isEmpty()) {
|
||||
@@ -238,6 +329,7 @@
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityhuman) {
|
||||
+ if (!this.checkReachable) return true; // CraftBukkit
|
||||
return a(this.containerAccess, entityhuman, Blocks.ENCHANTING_TABLE);
|
||||
}
|
||||
|
||||
@@ -289,4 +381,17 @@
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public CraftInventoryView getBukkitView() {
|
||||
+ if (bukkitEntity != null) {
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+
|
||||
+ CraftInventoryEnchanting inventory = new CraftInventoryEnchanting(this.enchantSlots);
|
||||
+ bukkitEntity = new CraftInventoryView(this.player, inventory, this);
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
--- a/net/minecraft/server/ContainerFurnace.java
|
||||
+++ b/net/minecraft/server/ContainerFurnace.java
|
||||
@@ -1,5 +1,10 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryFurnace;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public abstract class ContainerFurnace extends ContainerRecipeBook<IInventory> {
|
||||
|
||||
private final IInventory furnace;
|
||||
@@ -8,6 +13,22 @@
|
||||
private final Recipes<? extends RecipeCooking> f;
|
||||
private final RecipeBookType g;
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ private CraftInventoryView bukkitEntity = null;
|
||||
+ private PlayerInventory player;
|
||||
+
|
||||
+ @Override
|
||||
+ public CraftInventoryView getBukkitView() {
|
||||
+ if (bukkitEntity != null) {
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+
|
||||
+ CraftInventoryFurnace inventory = new CraftInventoryFurnace((TileEntityFurnace) this.furnace);
|
||||
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
protected ContainerFurnace(Containers<?> containers, Recipes<? extends RecipeCooking> recipes, RecipeBookType recipebooktype, int i, PlayerInventory playerinventory) {
|
||||
this(containers, recipes, recipebooktype, i, playerinventory, new InventorySubcontainer(3), new ContainerProperties(4));
|
||||
}
|
||||
@@ -24,6 +45,7 @@
|
||||
this.a(new Slot(iinventory, 0, 56, 17));
|
||||
this.a((Slot) (new SlotFurnaceFuel(this, iinventory, 1, 56, 53)));
|
||||
this.a((Slot) (new SlotFurnaceResult(playerinventory.player, iinventory, 2, 116, 35)));
|
||||
+ this.player = playerinventory; // CraftBukkit - save player
|
||||
|
||||
int j;
|
||||
|
||||
@@ -55,7 +77,7 @@
|
||||
|
||||
@Override
|
||||
public void a(boolean flag, IRecipe<?> irecipe, EntityPlayer entityplayer) {
|
||||
- (new AutoRecipeFurnace<>(this)).a(entityplayer, irecipe, flag);
|
||||
+ (new AutoRecipeFurnace(this)).a(entityplayer, irecipe, flag); // CraftBukkit - decompile error
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,6 +102,7 @@
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityhuman) {
|
||||
+ if (!this.checkReachable) return true; // CraftBukkit
|
||||
return this.furnace.a(entityhuman);
|
||||
}
|
||||
|
||||
@@ -135,7 +158,7 @@
|
||||
}
|
||||
|
||||
protected boolean a(ItemStack itemstack) {
|
||||
- return this.c.getCraftingManager().craft(this.f, new InventorySubcontainer(new ItemStack[]{itemstack}), this.c).isPresent();
|
||||
+ return this.c.getCraftingManager().craft((Recipes<RecipeCooking>) this.f, new InventorySubcontainer(new ItemStack[]{itemstack}), this.c).isPresent(); // Eclipse fail
|
||||
}
|
||||
|
||||
protected boolean b(ItemStack itemstack) {
|
||||
@@ -0,0 +1,63 @@
|
||||
--- a/net/minecraft/server/ContainerGrindstone.java
|
||||
+++ b/net/minecraft/server/ContainerGrindstone.java
|
||||
@@ -5,8 +5,30 @@
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.Location;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryGrindstone;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
+import org.bukkit.entity.Player;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ContainerGrindstone extends Container {
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ private CraftInventoryView bukkitEntity = null;
|
||||
+ private Player player;
|
||||
+
|
||||
+ @Override
|
||||
+ public CraftInventoryView getBukkitView() {
|
||||
+ if (bukkitEntity != null) {
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+
|
||||
+ CraftInventoryGrindstone inventory = new CraftInventoryGrindstone(this.craftInventory, this.resultInventory);
|
||||
+ bukkitEntity = new CraftInventoryView(this.player, inventory, this);
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
private final IInventory resultInventory;
|
||||
private final IInventory craftInventory;
|
||||
private final ContainerAccess containerAccess;
|
||||
@@ -24,6 +46,13 @@
|
||||
super.update();
|
||||
ContainerGrindstone.this.a((IInventory) this);
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public Location getLocation() {
|
||||
+ return containeraccess.getLocation();
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
};
|
||||
this.containerAccess = containeraccess;
|
||||
this.a(new Slot(this.craftInventory, 0, 49, 19) {
|
||||
@@ -108,6 +137,7 @@
|
||||
this.a(new Slot(playerinventory, j, 8 + j * 18, 142));
|
||||
}
|
||||
|
||||
+ player = (Player) playerinventory.player.getBukkitEntity(); // CraftBukkit
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -235,6 +265,7 @@
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityhuman) {
|
||||
+ if (!this.checkReachable) return true; // CraftBukkit
|
||||
return a(this.containerAccess, entityhuman, Blocks.GRINDSTONE);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
--- a/net/minecraft/server/ContainerHopper.java
|
||||
+++ b/net/minecraft/server/ContainerHopper.java
|
||||
@@ -1,9 +1,30 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ContainerHopper extends Container {
|
||||
|
||||
private final IInventory hopper;
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ private CraftInventoryView bukkitEntity = null;
|
||||
+ private PlayerInventory player;
|
||||
+
|
||||
+ @Override
|
||||
+ public CraftInventoryView getBukkitView() {
|
||||
+ if (bukkitEntity != null) {
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+
|
||||
+ CraftInventory inventory = new CraftInventory(this.hopper);
|
||||
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public ContainerHopper(int i, PlayerInventory playerinventory) {
|
||||
this(i, playerinventory, new InventorySubcontainer(5));
|
||||
}
|
||||
@@ -11,6 +32,7 @@
|
||||
public ContainerHopper(int i, PlayerInventory playerinventory, IInventory iinventory) {
|
||||
super(Containers.HOPPER, i);
|
||||
this.hopper = iinventory;
|
||||
+ this.player = playerinventory; // CraftBukkit - save player
|
||||
a(iinventory, 5);
|
||||
iinventory.startOpen(playerinventory.player);
|
||||
boolean flag = true;
|
||||
@@ -35,6 +57,7 @@
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityhuman) {
|
||||
+ if (!this.checkReachable) return true; // CraftBukkit
|
||||
return this.hopper.a(entityhuman);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
--- a/net/minecraft/server/ContainerHorse.java
|
||||
+++ b/net/minecraft/server/ContainerHorse.java
|
||||
@@ -1,12 +1,32 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
+import org.bukkit.inventory.InventoryView;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ContainerHorse extends Container {
|
||||
|
||||
private final IInventory c;
|
||||
private final EntityHorseAbstract d;
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ org.bukkit.craftbukkit.inventory.CraftInventoryView bukkitEntity;
|
||||
+ PlayerInventory player;
|
||||
+
|
||||
+ @Override
|
||||
+ public InventoryView getBukkitView() {
|
||||
+ if (bukkitEntity != null) {
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+
|
||||
+ return bukkitEntity = new CraftInventoryView(player.player.getBukkitEntity(), c.getOwner().getInventory(), this);
|
||||
+ }
|
||||
+
|
||||
public ContainerHorse(int i, PlayerInventory playerinventory, IInventory iinventory, final EntityHorseAbstract entityhorseabstract) {
|
||||
super((Containers) null, i);
|
||||
+ player = playerinventory;
|
||||
+ // CraftBukkit end
|
||||
this.c = iinventory;
|
||||
this.d = entityhorseabstract;
|
||||
boolean flag = true;
|
||||
@@ -0,0 +1,76 @@
|
||||
--- a/net/minecraft/server/ContainerLectern.java
|
||||
+++ b/net/minecraft/server/ContainerLectern.java
|
||||
@@ -1,15 +1,40 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
+// CraftBukkit start
|
||||
+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);
|
||||
@@ -23,6 +48,7 @@
|
||||
}
|
||||
});
|
||||
this.a(icontainerproperties);
|
||||
+ player = (Player) playerinventory.player.getBukkitEntity(); // CraftBukkit
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,6 +74,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();
|
||||
@@ -70,6 +103,7 @@
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityhuman) {
|
||||
+ if (!this.checkReachable) return true; // CraftBukkit
|
||||
return this.inventory.a(entityhuman);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
--- a/net/minecraft/server/ContainerLoom.java
|
||||
+++ b/net/minecraft/server/ContainerLoom.java
|
||||
@@ -1,7 +1,29 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.Location;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryLoom;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
+import org.bukkit.entity.Player;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ContainerLoom extends Container {
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ private CraftInventoryView bukkitEntity = null;
|
||||
+ private Player player;
|
||||
+
|
||||
+ @Override
|
||||
+ public CraftInventoryView getBukkitView() {
|
||||
+ if (bukkitEntity != null) {
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+
|
||||
+ CraftInventoryLoom inventory = new CraftInventoryLoom(this.craftInventory, this.resultInventory);
|
||||
+ bukkitEntity = new CraftInventoryView(this.player, inventory, this);
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
private final ContainerAccess containerAccess;
|
||||
private final ContainerProperty d;
|
||||
private Runnable e;
|
||||
@@ -29,6 +51,13 @@
|
||||
ContainerLoom.this.a((IInventory) this);
|
||||
ContainerLoom.this.e.run();
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public Location getLocation() {
|
||||
+ return containeraccess.getLocation();
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
};
|
||||
this.resultInventory = new InventorySubcontainer(1) {
|
||||
@Override
|
||||
@@ -36,6 +65,13 @@
|
||||
super.update();
|
||||
ContainerLoom.this.e.run();
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public Location getLocation() {
|
||||
+ return containeraccess.getLocation();
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
};
|
||||
this.containerAccess = containeraccess;
|
||||
this.f = this.a(new Slot(this.craftInventory, 0, 13, 26) {
|
||||
@@ -96,10 +132,12 @@
|
||||
}
|
||||
|
||||
this.a(this.d);
|
||||
+ player = (Player) playerinventory.player.getBukkitEntity(); // CraftBukkit
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityhuman) {
|
||||
+ if (!this.checkReachable) return true; // CraftBukkit
|
||||
return a(this.containerAccess, entityhuman, Blocks.LOOM);
|
||||
}
|
||||
|
||||
@@ -218,6 +256,11 @@
|
||||
|
||||
if (nbttagcompound.hasKeyOfType("Patterns", 9)) {
|
||||
nbttaglist = nbttagcompound.getList("Patterns", 10);
|
||||
+ // CraftBukkit start
|
||||
+ while (nbttaglist.size() > 20) {
|
||||
+ nbttaglist.remove(20);
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
} else {
|
||||
nbttaglist = new NBTTagList();
|
||||
nbttagcompound.set("Patterns", nbttaglist);
|
||||
@@ -0,0 +1,45 @@
|
||||
--- a/net/minecraft/server/ContainerMerchant.java
|
||||
+++ b/net/minecraft/server/ContainerMerchant.java
|
||||
@@ -1,10 +1,25 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryView; // CraftBukkit
|
||||
+
|
||||
public class ContainerMerchant extends Container {
|
||||
|
||||
private final IMerchant merchant;
|
||||
private final InventoryMerchant inventoryMerchant;
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ private CraftInventoryView bukkitEntity = null;
|
||||
+ private PlayerInventory player;
|
||||
+
|
||||
+ @Override
|
||||
+ public CraftInventoryView getBukkitView() {
|
||||
+ if (bukkitEntity == null) {
|
||||
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), new org.bukkit.craftbukkit.inventory.CraftInventoryMerchant(merchant, inventoryMerchant), this);
|
||||
+ }
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public ContainerMerchant(int i, PlayerInventory playerinventory) {
|
||||
this(i, playerinventory, new MerchantWrapper(playerinventory.player));
|
||||
}
|
||||
@@ -16,6 +31,7 @@
|
||||
this.a(new Slot(this.inventoryMerchant, 0, 136, 37));
|
||||
this.a(new Slot(this.inventoryMerchant, 1, 162, 37));
|
||||
this.a((Slot) (new SlotMerchantResult(playerinventory.player, imerchant, this.inventoryMerchant, 2, 220, 37)));
|
||||
+ this.player = playerinventory; // CraftBukkit - save player
|
||||
|
||||
int j;
|
||||
|
||||
@@ -96,7 +112,7 @@
|
||||
}
|
||||
|
||||
private void k() {
|
||||
- if (!this.merchant.getWorld().isClientSide) {
|
||||
+ if (!this.merchant.getWorld().isClientSide && this.merchant instanceof Entity) { // CraftBukkit - SPIGOT-5035
|
||||
Entity entity = (Entity) this.merchant;
|
||||
|
||||
this.merchant.getWorld().a(entity.locX(), entity.locY(), entity.locZ(), this.merchant.getTradeSound(), SoundCategory.NEUTRAL, 1.0F, 1.0F, false);
|
||||
@@ -0,0 +1,71 @@
|
||||
--- a/net/minecraft/server/ContainerPlayer.java
|
||||
+++ b/net/minecraft/server/ContainerPlayer.java
|
||||
@@ -1,5 +1,10 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ContainerPlayer extends ContainerRecipeBook<InventoryCrafting> {
|
||||
|
||||
public static final MinecraftKey c = new MinecraftKey("textures/atlas/blocks.png");
|
||||
@@ -10,15 +15,28 @@
|
||||
public static final MinecraftKey h = new MinecraftKey("item/empty_armor_slot_shield");
|
||||
private static final MinecraftKey[] j = new MinecraftKey[]{ContainerPlayer.g, ContainerPlayer.f, ContainerPlayer.e, ContainerPlayer.d};
|
||||
private static final EnumItemSlot[] k = new EnumItemSlot[]{EnumItemSlot.HEAD, EnumItemSlot.CHEST, EnumItemSlot.LEGS, EnumItemSlot.FEET};
|
||||
- private final InventoryCrafting craftInventory = new InventoryCrafting(this, 2, 2);
|
||||
- private final InventoryCraftResult resultInventory = new InventoryCraftResult();
|
||||
+ // CraftBukkit start
|
||||
+ private final InventoryCrafting craftInventory;
|
||||
+ private final InventoryCraftResult resultInventory;
|
||||
+ // CraftBukkit end
|
||||
public final boolean i;
|
||||
private final EntityHuman owner;
|
||||
+ // CraftBukkit start
|
||||
+ private CraftInventoryView bukkitEntity = null;
|
||||
+ private PlayerInventory player;
|
||||
+ // CraftBukkit end
|
||||
|
||||
public ContainerPlayer(PlayerInventory playerinventory, boolean flag, EntityHuman entityhuman) {
|
||||
super((Containers) null, 0);
|
||||
this.i = flag;
|
||||
this.owner = entityhuman;
|
||||
+ // CraftBukkit start
|
||||
+ this.resultInventory = new InventoryCraftResult(); // CraftBukkit - moved to before InventoryCrafting construction
|
||||
+ this.craftInventory = new InventoryCrafting(this, 2, 2, playerinventory.player); // CraftBukkit - pass player
|
||||
+ this.craftInventory.resultInventory = this.resultInventory; // CraftBukkit - let InventoryCrafting know about its result slot
|
||||
+ this.player = playerinventory; // CraftBukkit - save player
|
||||
+ setTitle(new ChatMessage("container.crafting")); // SPIGOT-4722: Allocate title for player inventory
|
||||
+ // CraftBukkit end
|
||||
this.a((Slot) (new SlotResult(playerinventory.player, this.craftInventory, this.resultInventory, 0, 154, 28)));
|
||||
|
||||
int i;
|
||||
@@ -85,7 +103,7 @@
|
||||
|
||||
@Override
|
||||
public void a(IInventory iinventory) {
|
||||
- ContainerWorkbench.a(this.windowId, this.owner.world, this.owner, this.craftInventory, this.resultInventory);
|
||||
+ ContainerWorkbench.a(this.windowId, this.owner.world, this.owner, this.craftInventory, this.resultInventory, this); // CraftBukkit
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -192,4 +210,17 @@
|
||||
public InventoryCrafting j() {
|
||||
return this.craftInventory;
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public CraftInventoryView getBukkitView() {
|
||||
+ if (bukkitEntity != null) {
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+
|
||||
+ CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftInventory, this.resultInventory);
|
||||
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
--- a/net/minecraft/server/ContainerShulkerBox.java
|
||||
+++ b/net/minecraft/server/ContainerShulkerBox.java
|
||||
@@ -1,8 +1,27 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventory;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ContainerShulkerBox extends Container {
|
||||
|
||||
private final IInventory c;
|
||||
+ // CraftBukkit start
|
||||
+ private CraftInventoryView bukkitEntity;
|
||||
+ private PlayerInventory player;
|
||||
+
|
||||
+ @Override
|
||||
+ public CraftInventoryView getBukkitView() {
|
||||
+ if (bukkitEntity != null) {
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+
|
||||
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), new CraftInventory(this.c), this);
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
public ContainerShulkerBox(int i, PlayerInventory playerinventory) {
|
||||
this(i, playerinventory, new InventorySubcontainer(27));
|
||||
@@ -12,6 +31,7 @@
|
||||
super(Containers.SHULKER_BOX, i);
|
||||
a(iinventory, 27);
|
||||
this.c = iinventory;
|
||||
+ this.player = playerinventory; // CraftBukkit - save player
|
||||
iinventory.startOpen(playerinventory.player);
|
||||
boolean flag = true;
|
||||
boolean flag1 = true;
|
||||
@@ -0,0 +1,55 @@
|
||||
--- a/net/minecraft/server/ContainerSmithing.java
|
||||
+++ b/net/minecraft/server/ContainerSmithing.java
|
||||
@@ -3,12 +3,17 @@
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryView; // CraftBukkit
|
||||
+
|
||||
public class ContainerSmithing extends ContainerAnvilAbstract {
|
||||
|
||||
private final World g;
|
||||
@Nullable
|
||||
private RecipeSmithing h;
|
||||
private final List<RecipeSmithing> i;
|
||||
+ // CraftBukkit start
|
||||
+ private CraftInventoryView bukkitEntity;
|
||||
+ // CraftBukkit end
|
||||
|
||||
public ContainerSmithing(int i, PlayerInventory playerinventory) {
|
||||
this(i, playerinventory, ContainerAccess.a);
|
||||
@@ -54,13 +59,13 @@
|
||||
List<RecipeSmithing> list = this.g.getCraftingManager().b(Recipes.SMITHING, this.repairInventory, this.g);
|
||||
|
||||
if (list.isEmpty()) {
|
||||
- this.resultInventory.setItem(0, ItemStack.b);
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareSmithingEvent(getBukkitView(), ItemStack.b); // CraftBukkit
|
||||
} else {
|
||||
this.h = (RecipeSmithing) list.get(0);
|
||||
ItemStack itemstack = this.h.a(this.repairInventory);
|
||||
|
||||
this.resultInventory.a((IRecipe) this.h);
|
||||
- this.resultInventory.setItem(0, itemstack);
|
||||
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareSmithingEvent(getBukkitView(), itemstack); // CraftBukkit
|
||||
}
|
||||
|
||||
}
|
||||
@@ -76,4 +81,18 @@
|
||||
public boolean a(ItemStack itemstack, Slot slot) {
|
||||
return slot.inventory != this.resultInventory && super.a(itemstack, slot);
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public CraftInventoryView getBukkitView() {
|
||||
+ if (bukkitEntity != null) {
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+
|
||||
+ org.bukkit.craftbukkit.inventory.CraftInventory inventory = new org.bukkit.craftbukkit.inventory.CraftInventorySmithing(
|
||||
+ containerAccess.getLocation(), this.repairInventory, this.resultInventory);
|
||||
+ bukkitEntity = new CraftInventoryView(this.player.getBukkitEntity(), inventory, this);
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
--- a/net/minecraft/server/ContainerStonecutter.java
|
||||
+++ b/net/minecraft/server/ContainerStonecutter.java
|
||||
@@ -3,6 +3,13 @@
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.Location;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryStonecutter;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
+import org.bukkit.entity.Player;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ContainerStonecutter extends Container {
|
||||
|
||||
private final ContainerAccess containerAccess;
|
||||
@@ -16,6 +23,21 @@
|
||||
private Runnable l;
|
||||
public final IInventory inventory;
|
||||
private final InventoryCraftResult resultInventory;
|
||||
+ // CraftBukkit start
|
||||
+ private CraftInventoryView bukkitEntity = null;
|
||||
+ private Player player;
|
||||
+
|
||||
+ @Override
|
||||
+ public CraftInventoryView getBukkitView() {
|
||||
+ if (bukkitEntity != null) {
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+
|
||||
+ CraftInventoryStonecutter inventory = new CraftInventoryStonecutter(this.inventory, this.resultInventory);
|
||||
+ bukkitEntity = new CraftInventoryView(this.player, inventory, this);
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
public ContainerStonecutter(int i, PlayerInventory playerinventory) {
|
||||
this(i, playerinventory, ContainerAccess.a);
|
||||
@@ -35,6 +57,13 @@
|
||||
ContainerStonecutter.this.a((IInventory) this);
|
||||
ContainerStonecutter.this.l.run();
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public Location getLocation() {
|
||||
+ return containeraccess.getLocation();
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
};
|
||||
this.resultInventory = new InventoryCraftResult();
|
||||
this.containerAccess = containeraccess;
|
||||
@@ -82,10 +111,12 @@
|
||||
}
|
||||
|
||||
this.a(this.containerProperty);
|
||||
+ player = (Player) playerinventory.player.getBukkitEntity(); // CraftBukkit
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityhuman) {
|
||||
+ if (!this.checkReachable) return true; // CraftBukkit
|
||||
return a(this.containerAccess, entityhuman, Blocks.STONECUTTER);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
--- a/net/minecraft/server/ContainerWorkbench.java
|
||||
+++ b/net/minecraft/server/ContainerWorkbench.java
|
||||
@@ -2,12 +2,21 @@
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting;
|
||||
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class ContainerWorkbench extends ContainerRecipeBook<InventoryCrafting> {
|
||||
|
||||
private final InventoryCrafting craftInventory;
|
||||
private final InventoryCraftResult resultInventory;
|
||||
public final ContainerAccess containerAccess;
|
||||
private final EntityHuman f;
|
||||
+ // CraftBukkit start
|
||||
+ private CraftInventoryView bukkitEntity = null;
|
||||
+ private PlayerInventory player;
|
||||
+ // CraftBukkit end
|
||||
|
||||
public ContainerWorkbench(int i, PlayerInventory playerinventory) {
|
||||
this(i, playerinventory, ContainerAccess.a);
|
||||
@@ -15,8 +24,12 @@
|
||||
|
||||
public ContainerWorkbench(int i, PlayerInventory playerinventory, ContainerAccess containeraccess) {
|
||||
super(Containers.CRAFTING, i);
|
||||
- this.craftInventory = new InventoryCrafting(this, 3, 3);
|
||||
+ // CraftBukkit start - Switched order of IInventory construction and stored player
|
||||
this.resultInventory = new InventoryCraftResult();
|
||||
+ this.craftInventory = new InventoryCrafting(this, 3, 3, playerinventory.player); // CraftBukkit - pass player
|
||||
+ this.craftInventory.resultInventory = this.resultInventory;
|
||||
+ this.player = playerinventory;
|
||||
+ // CraftBukkit end
|
||||
this.containerAccess = containeraccess;
|
||||
this.f = playerinventory.player;
|
||||
this.a((Slot) (new SlotResult(playerinventory.player, this.craftInventory, this.resultInventory, 0, 124, 35)));
|
||||
@@ -42,7 +55,7 @@
|
||||
|
||||
}
|
||||
|
||||
- protected static void a(int i, World world, EntityHuman entityhuman, InventoryCrafting inventorycrafting, InventoryCraftResult inventorycraftresult) {
|
||||
+ protected static void a(int i, World world, EntityHuman entityhuman, InventoryCrafting inventorycrafting, InventoryCraftResult inventorycraftresult, Container container) { // CraftBukkit
|
||||
if (!world.isClientSide) {
|
||||
EntityPlayer entityplayer = (EntityPlayer) entityhuman;
|
||||
ItemStack itemstack = ItemStack.b;
|
||||
@@ -55,6 +68,7 @@
|
||||
itemstack = recipecrafting.a(inventorycrafting);
|
||||
}
|
||||
}
|
||||
+ itemstack = org.bukkit.craftbukkit.event.CraftEventFactory.callPreCraftEvent(inventorycrafting, inventorycraftresult, itemstack, container.getBukkitView(), false); // CraftBukkit
|
||||
|
||||
inventorycraftresult.setItem(0, itemstack);
|
||||
entityplayer.playerConnection.sendPacket(new PacketPlayOutSetSlot(i, 0, itemstack));
|
||||
@@ -64,7 +78,7 @@
|
||||
@Override
|
||||
public void a(IInventory iinventory) {
|
||||
this.containerAccess.a((world, blockposition) -> {
|
||||
- a(this.windowId, world, this.f, this.craftInventory, this.resultInventory);
|
||||
+ a(this.windowId, world, this.f, this.craftInventory, this.resultInventory, this); // CraftBukkit
|
||||
});
|
||||
}
|
||||
|
||||
@@ -94,6 +108,7 @@
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityhuman) {
|
||||
+ if (!this.checkReachable) return true; // CraftBukkit
|
||||
return a(this.containerAccess, entityhuman, Blocks.CRAFTING_TABLE);
|
||||
}
|
||||
|
||||
@@ -168,4 +183,17 @@
|
||||
public int h() {
|
||||
return this.craftInventory.f();
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ @Override
|
||||
+ public CraftInventoryView getBukkitView() {
|
||||
+ if (bukkitEntity != null) {
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+
|
||||
+ CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftInventory, this.resultInventory);
|
||||
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
|
||||
+ return bukkitEntity;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
--- a/net/minecraft/server/Containers.java
|
||||
+++ b/net/minecraft/server/Containers.java
|
||||
@@ -19,7 +19,7 @@
|
||||
public static final Containers<ContainerGrindstone> GRINDSTONE = a("grindstone", ContainerGrindstone::new);
|
||||
public static final Containers<ContainerHopper> HOPPER = a("hopper", ContainerHopper::new);
|
||||
public static final Containers<ContainerLectern> LECTERN = a("lectern", (i, playerinventory) -> {
|
||||
- return new ContainerLectern(i);
|
||||
+ return new ContainerLectern(i, playerinventory); // CraftBukkit
|
||||
});
|
||||
public static final Containers<ContainerLoom> LOOM = a("loom", ContainerLoom::new);
|
||||
public static final Containers<ContainerMerchant> MERCHANT = a("merchant", ContainerMerchant::new);
|
||||
@@ -31,12 +31,17 @@
|
||||
private final Containers.Supplier<T> y;
|
||||
|
||||
private static <T extends Container> Containers<T> a(String s, Containers.Supplier<T> containers_supplier) {
|
||||
- return (Containers) IRegistry.a(IRegistry.MENU, s, (Object) (new Containers<>(containers_supplier)));
|
||||
+ return (Containers) IRegistry.a(IRegistry.MENU, s, (new Containers<>(containers_supplier))); // CraftBukkit - decompile error
|
||||
}
|
||||
|
||||
private Containers(Containers.Supplier<T> containers_supplier) {
|
||||
this.y = containers_supplier;
|
||||
}
|
||||
|
||||
- interface Supplier<T extends Container> {}
|
||||
+ // CraftBukkit start
|
||||
+ interface Supplier<T extends Container> {
|
||||
+
|
||||
+ T supply(int id, PlayerInventory playerinventory);
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
--- a/net/minecraft/server/InventoryCraftResult.java
|
||||
+++ b/net/minecraft/server/InventoryCraftResult.java
|
||||
@@ -3,12 +3,51 @@
|
||||
import java.util.Iterator;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.Location;
|
||||
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
||||
+import org.bukkit.entity.HumanEntity;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class InventoryCraftResult implements IInventory, RecipeHolder {
|
||||
|
||||
private final NonNullList<ItemStack> items;
|
||||
@Nullable
|
||||
private IRecipe<?> b;
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ private int maxStack = MAX_STACK;
|
||||
+
|
||||
+ public java.util.List<ItemStack> getContents() {
|
||||
+ return this.items;
|
||||
+ }
|
||||
+
|
||||
+ public org.bukkit.inventory.InventoryHolder getOwner() {
|
||||
+ return null; // Result slots don't get an owner
|
||||
+ }
|
||||
+
|
||||
+ // Don't need a transaction; the InventoryCrafting keeps track of it for us
|
||||
+ public void onOpen(CraftHumanEntity who) {}
|
||||
+ public void onClose(CraftHumanEntity who) {}
|
||||
+ public java.util.List<HumanEntity> getViewers() {
|
||||
+ return new java.util.ArrayList<HumanEntity>();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public int getMaxStackSize() {
|
||||
+ return maxStack;
|
||||
+ }
|
||||
+
|
||||
+ public void setMaxStackSize(int size) {
|
||||
+ maxStack = size;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public Location getLocation() {
|
||||
+ return null;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public InventoryCraftResult() {
|
||||
this.items = NonNullList.a(1, ItemStack.b);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
--- a/net/minecraft/server/InventoryCrafting.java
|
||||
+++ b/net/minecraft/server/InventoryCrafting.java
|
||||
@@ -2,6 +2,15 @@
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import java.util.List;
|
||||
+import org.bukkit.Location;
|
||||
+
|
||||
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
||||
+import org.bukkit.entity.HumanEntity;
|
||||
+import org.bukkit.event.inventory.InventoryType;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class InventoryCrafting implements IInventory, AutoRecipeOutput {
|
||||
|
||||
private final NonNullList<ItemStack> items;
|
||||
@@ -9,6 +18,68 @@
|
||||
private final int c;
|
||||
public final Container container;
|
||||
|
||||
+ // CraftBukkit start - add fields
|
||||
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
|
||||
+ private IRecipe currentRecipe;
|
||||
+ public IInventory resultInventory;
|
||||
+ private EntityHuman owner;
|
||||
+ private int maxStack = MAX_STACK;
|
||||
+
|
||||
+ public List<ItemStack> getContents() {
|
||||
+ return this.items;
|
||||
+ }
|
||||
+
|
||||
+ public void onOpen(CraftHumanEntity who) {
|
||||
+ transaction.add(who);
|
||||
+ }
|
||||
+
|
||||
+ public InventoryType getInvType() {
|
||||
+ return items.size() == 4 ? InventoryType.CRAFTING : InventoryType.WORKBENCH;
|
||||
+ }
|
||||
+
|
||||
+ public void onClose(CraftHumanEntity who) {
|
||||
+ transaction.remove(who);
|
||||
+ }
|
||||
+
|
||||
+ public List<HumanEntity> getViewers() {
|
||||
+ return transaction;
|
||||
+ }
|
||||
+
|
||||
+ public org.bukkit.inventory.InventoryHolder getOwner() {
|
||||
+ return (owner == null) ? null : owner.getBukkitEntity();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public int getMaxStackSize() {
|
||||
+ return maxStack;
|
||||
+ }
|
||||
+
|
||||
+ public void setMaxStackSize(int size) {
|
||||
+ maxStack = size;
|
||||
+ resultInventory.setMaxStackSize(size);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public Location getLocation() {
|
||||
+ return container instanceof ContainerWorkbench ? ((ContainerWorkbench) container).containerAccess.getLocation() : owner.getBukkitEntity().getLocation();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public IRecipe getCurrentRecipe() {
|
||||
+ return currentRecipe;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setCurrentRecipe(IRecipe currentRecipe) {
|
||||
+ this.currentRecipe = currentRecipe;
|
||||
+ }
|
||||
+
|
||||
+ public InventoryCrafting(Container container, int i, int j, EntityHuman player) {
|
||||
+ this(container, i, j);
|
||||
+ this.owner = player;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public InventoryCrafting(Container container, int i, int j) {
|
||||
this.items = NonNullList.a(i * j, ItemStack.b);
|
||||
this.container = container;
|
||||
@@ -0,0 +1,33 @@
|
||||
--- a/net/minecraft/server/InventoryEnderChest.java
|
||||
+++ b/net/minecraft/server/InventoryEnderChest.java
|
||||
@@ -1,11 +1,29 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import org.bukkit.Location;
|
||||
+import org.bukkit.inventory.InventoryHolder;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class InventoryEnderChest extends InventorySubcontainer {
|
||||
|
||||
private TileEntityEnderChest a;
|
||||
+ // CraftBukkit start
|
||||
+ private final EntityHuman owner;
|
||||
+
|
||||
+ public InventoryHolder getBukkitOwner() {
|
||||
+ return owner.getBukkitEntity();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public Location getLocation() {
|
||||
+ return this.a != null ? new Location(this.a.getWorld().getWorld(), this.a.getPosition().getX(), this.a.getPosition().getY(), this.a.getPosition().getZ()) : null;
|
||||
+ }
|
||||
|
||||
- public InventoryEnderChest() {
|
||||
+ public InventoryEnderChest(EntityHuman owner) {
|
||||
super(27);
|
||||
+ this.owner = owner;
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
|
||||
public void a(TileEntityEnderChest tileentityenderchest) {
|
||||
@@ -0,0 +1,64 @@
|
||||
--- a/net/minecraft/server/InventoryMerchant.java
|
||||
+++ b/net/minecraft/server/InventoryMerchant.java
|
||||
@@ -3,6 +3,14 @@
|
||||
import java.util.Iterator;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import java.util.List;
|
||||
+import org.bukkit.Location;
|
||||
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
|
||||
+import org.bukkit.craftbukkit.entity.CraftAbstractVillager;
|
||||
+import org.bukkit.entity.HumanEntity;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
public class InventoryMerchant implements IInventory {
|
||||
|
||||
private final IMerchant merchant;
|
||||
@@ -12,6 +20,46 @@
|
||||
public int selectedIndex;
|
||||
private int e;
|
||||
|
||||
+ // CraftBukkit start - add fields and methods
|
||||
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
|
||||
+ private int maxStack = MAX_STACK;
|
||||
+
|
||||
+ public List<ItemStack> getContents() {
|
||||
+ return this.itemsInSlots;
|
||||
+ }
|
||||
+
|
||||
+ public void onOpen(CraftHumanEntity who) {
|
||||
+ transaction.add(who);
|
||||
+ }
|
||||
+
|
||||
+ public void onClose(CraftHumanEntity who) {
|
||||
+ transaction.remove(who);
|
||||
+ merchant.setTradingPlayer((EntityHuman) null); // SPIGOT-4860
|
||||
+ }
|
||||
+
|
||||
+ public List<HumanEntity> getViewers() {
|
||||
+ return transaction;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public int getMaxStackSize() {
|
||||
+ return maxStack;
|
||||
+ }
|
||||
+
|
||||
+ public void setMaxStackSize(int i) {
|
||||
+ maxStack = i;
|
||||
+ }
|
||||
+
|
||||
+ public org.bukkit.inventory.InventoryHolder getOwner() {
|
||||
+ return (merchant instanceof EntityVillagerAbstract) ? (CraftAbstractVillager) ((EntityVillagerAbstract) this.merchant).getBukkitEntity() : null;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public Location getLocation() {
|
||||
+ return (merchant instanceof EntityVillager) ? ((EntityVillager) this.merchant).getBukkitEntity().getLocation() : null;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public InventoryMerchant(IMerchant imerchant) {
|
||||
this.itemsInSlots = NonNullList.a(3, ItemStack.b);
|
||||
this.merchant = imerchant;
|
||||
@@ -0,0 +1,11 @@
|
||||
--- a/net/minecraft/server/SlotFurnaceResult.java
|
||||
+++ b/net/minecraft/server/SlotFurnaceResult.java
|
||||
@@ -41,7 +41,7 @@
|
||||
protected void c(ItemStack itemstack) {
|
||||
itemstack.a(this.a.world, this.a, this.b);
|
||||
if (!this.a.world.isClientSide && this.inventory instanceof TileEntityFurnace) {
|
||||
- ((TileEntityFurnace) this.inventory).d(this.a);
|
||||
+ ((TileEntityFurnace) this.inventory).d(this.a, itemstack, this.b); // CraftBukkit
|
||||
}
|
||||
|
||||
this.b = 0;
|
||||
Reference in New Issue
Block a user