3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-29 17:40:09 +01:00
Paper/nms-patches/ContainerWorkbench.patch

91 Zeilen
3.8 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/ContainerWorkbench.java
+++ b/net/minecraft/server/ContainerWorkbench.java
2019-05-27 22:30:00 +02:00
@@ -1,6 +1,10 @@
package net.minecraft.server;
2019-04-23 04:00:00 +02:00
import java.util.Optional;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
2019-04-23 04:00:00 +02:00
public class ContainerWorkbench extends ContainerRecipeBook<InventoryCrafting> {
2019-05-27 22:30:00 +02:00
@@ -8,6 +12,10 @@
2019-04-23 04:00:00 +02:00
private final InventoryCraftResult resultInventory;
2019-05-27 22:30:00 +02:00
public final ContainerAccess containerAccess;
2019-04-23 04:00:00 +02:00
private final EntityHuman f;
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private PlayerInventory player;
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
public ContainerWorkbench(int i, PlayerInventory playerinventory) {
this(i, playerinventory, ContainerAccess.a);
@@ -15,8 +23,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
2019-04-23 04:00:00 +02:00
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
2019-05-27 22:30:00 +02:00
this.containerAccess = containeraccess;
2019-04-23 04:00:00 +02:00
this.f = playerinventory.player;
this.a((Slot) (new SlotResult(playerinventory.player, this.craftInventory, this.resultInventory, 0, 124, 35)));
@@ -42,7 +54,7 @@
}
2019-04-23 04:00:00 +02:00
- 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;
2020-06-25 02:00:00 +02:00
ItemStack itemstack = ItemStack.b;
2019-04-23 04:00:00 +02:00
@@ -55,6 +67,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 +77,7 @@
@Override
public void a(IInventory iinventory) {
2019-05-27 22:30:00 +02:00
this.containerAccess.a((world, blockposition) -> {
2019-04-23 04:00:00 +02:00
- a(this.windowId, world, this.f, this.craftInventory, this.resultInventory);
+ a(this.windowId, world, this.f, this.craftInventory, this.resultInventory, this); // CraftBukkit
});
}
@@ -94,6 +107,7 @@
@Override
2017-09-18 12:00:00 +02:00
public boolean canUse(EntityHuman entityhuman) {
+ if (!this.checkReachable) return true; // CraftBukkit
2019-05-27 22:30:00 +02:00
return a(this.containerAccess, entityhuman, Blocks.CRAFTING_TABLE);
}
2019-12-10 23:00:00 +01:00
@@ -168,4 +182,17 @@
2019-04-23 04:00:00 +02:00
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
}