1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
package com.detrav.gui.containers;
import com.detrav.items.DetravMetaGeneratedTool01;
import com.detrav.utils.PortableAnvilInventory;
import gregtech.api.gui.GT_Slot_Output;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.*;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import gregtech.common.items.armor.gui.SlotLocked;
/**
* Created by Detrav on 30.10.2016.
*/
public class DetravPortableAnvilContainer extends Container {
public InventoryPlayer inventoryPlayer;
public IInventory slots;
ItemStack stack;
World worldObj;
public DetravPortableAnvilContainer(InventoryPlayer inventory, World world, ItemStack currentEquippedItem) {
worldObj = world;
inventoryPlayer = inventory;
stack = currentEquippedItem;
slots = new PortableAnvilInventory("Item", false, 3);
this.addSlotToContainer(new Slot(this.slots, 0, 27, 47));
this.addSlotToContainer(new Slot(this.slots, 1, 76, 47));
this.addSlotToContainer(new GT_Slot_Output(this.slots, 2, 134, 47));
slots.setInventorySlotContents(1, DetravMetaGeneratedTool01.INSTANCE.getItemStackFromDetravData(stack));
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 9; ++j) {
this.addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for (int i = 0; i < 9; ++i) {
ItemStack stackInSlot = inventoryPlayer.getStackInSlot(i);
if (currentEquippedItem != null && stackInSlot != null && currentEquippedItem == stackInSlot) {
addSlotToContainer(new SlotLocked(inventoryPlayer, i, 8 + i * 18, 142));
} else {
this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 142));
}
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
return null;
}
public void onContainerClosed(EntityPlayer p_75134_1_) {
super.onContainerClosed(p_75134_1_);
if (!this.worldObj.isRemote) {
ItemStack itemstack = this.slots.getStackInSlot(0);
if (itemstack != null) {
p_75134_1_.dropPlayerItemWithRandomChoice(itemstack, false);
}
itemstack = this.slots.getStackInSlot(1);
if (itemstack != null) {
if (stack == null || !DetravMetaGeneratedTool01.INSTANCE.setItemStackToDetravData(stack, itemstack)) {
p_75134_1_.dropPlayerItemWithRandomChoice(itemstack, false);
}
}
//itemstack.writeToNBT()
}
}
@Override
public boolean canInteractWith(EntityPlayer p_75145_1_) {
return true;
}
}
|