Files
2019-02-24 22:29:41 +08:00

61 lines
2.9 KiB
Diff

--- ../src-base/minecraft/net/minecraft/inventory/ContainerPlayer.java
+++ ../src-work/minecraft/net/minecraft/inventory/ContainerPlayer.java
@@ -9,19 +9,30 @@
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
+import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
public class ContainerPlayer extends Container
{
private static final EntityEquipmentSlot[] VALID_EQUIPMENT_SLOTS = new EntityEquipmentSlot[] {EntityEquipmentSlot.HEAD, EntityEquipmentSlot.CHEST, EntityEquipmentSlot.LEGS, EntityEquipmentSlot.FEET};
- public InventoryCrafting craftMatrix = new InventoryCrafting(this, 2, 2);
- public InventoryCraftResult craftResult = new InventoryCraftResult();
+ public InventoryCrafting craftMatrix; // CraftBukkit - move initialization into constructor
+ public InventoryCraftResult craftResult; // CraftBukkit - move initialization into constructor
public boolean isLocalWorld;
private final EntityPlayer player;
+ private CraftInventoryView bukkitEntity = null;
+ private InventoryPlayer playerInventory;
+
public ContainerPlayer(InventoryPlayer playerInventory, boolean localWorld, EntityPlayer playerIn)
{
this.isLocalWorld = localWorld;
this.player = playerIn;
+ // CraftBukkit start
+ this.craftResult = new InventoryCraftResult(); // CraftBukkit - moved to before InventoryCrafting construction
+ this.craftMatrix = new InventoryCrafting(this, 2, 2, playerInventory.player); // CraftBukkit - pass player
+ this.craftMatrix.resultInventory = this.craftResult; // CraftBukkit - let InventoryCrafting know about its result slot
+ this.playerInventory = playerInventory; // CraftBukkit - save player
+ // CraftBukkit end
this.addSlotToContainer(new SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 154, 28));
for (int i = 0; i < 2; ++i)
@@ -43,7 +54,7 @@
}
public boolean isItemValid(ItemStack stack)
{
- return entityequipmentslot == EntityLiving.getSlotForItemStack(stack);
+ return stack.getItem().isValidArmor(stack, entityequipmentslot, player);
}
public boolean canTakeStack(EntityPlayer playerIn)
{
@@ -202,4 +213,15 @@
{
return slotIn.inventory != this.craftResult && super.canMergeSlot(stack, slotIn);
}
+
+ @Override
+ public CraftInventoryView getBukkitView() {
+ if (bukkitEntity != null) {
+ return bukkitEntity;
+ }
+
+ CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftMatrix, this.craftResult);
+ bukkitEntity = new CraftInventoryView(this.playerInventory.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
}