blob: 8813987a7b753d785b024b135cdd353b97185ab3 (
plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
package miscutil.core.tileentities;
import miscutil.core.item.ModItems;
import miscutil.core.item.general.fuelrods.FuelRod_Base;
import miscutil.core.util.UtilsItems;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.Constants;
public class TileEntityNHG extends TileEntity implements IInventory
{
private ItemStack[] items = new ItemStack[19]; //18
private int internalClock = 0;
@Override
public int getSizeInventory()
{
return items.length;
}
@Override
public ItemStack getStackInSlot(int slot)
{
return items[slot];
}
@Override
public ItemStack decrStackSize(int slot, int amount)
{
if (items[slot] != null)
{
ItemStack itemstack;
if (items[slot].stackSize == amount)
{
itemstack = items[slot];
items[slot] = null;
markDirty();
return itemstack;
}
itemstack = items[slot].splitStack(amount);
if (items[slot].stackSize == 0) items[slot] = null;
markDirty();
return itemstack;
}
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int slot)
{
if (items[slot] != null)
{
ItemStack itemstack = items[slot];
items[slot] = null;
return itemstack;
}
return null;
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack)
{
if (stack != null){
items[slot] = stack;
if (stack != null && stack.stackSize > getInventoryStackLimit())
{
stack.stackSize = getInventoryStackLimit();
}
markDirty();
}
}
@Override
public String getInventoryName()
{
return "container.NHG";
}
@Override
public boolean hasCustomInventoryName()
{
return false;
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
NBTTagList list = nbt.getTagList("Items", Constants.NBT.TAG_COMPOUND);
items = new ItemStack[getSizeInventory()];
for (int i = 0; i < list.tagCount(); ++i) { NBTTagCompound comp = list.getCompoundTagAt(i); int j = comp.getByte("Slot") & 255; if (j >= 0 && j < items.length)
{
items[j] = ItemStack.loadItemStackFromNBT(comp);
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
NBTTagList list = new NBTTagList();
for (int i = 0; i < items.length; ++i)
{
if (items[i] != null)
{
NBTTagCompound comp = new NBTTagCompound();
comp.setByte("Slot", (byte)i);
items[i].writeToNBT(comp);
list.appendTag(comp);
}
}
nbt.setTag("Items", list);
}
@Override
public int getInventoryStackLimit()
{
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player)
{
return worldObj.getTileEntity(xCoord, yCoord, zCoord) != this ? false : player.getDistanceSq((double)xCoord + 0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64.0D;
}
@Override
public void openInventory() {}
@Override
public void closeInventory() {}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack)
{
return true;
}
//Machine Code - TODO
@Override
public void updateEntity() {
if (internalClock <= 20){
internalClock++;
}
else {
ItemStack validFuelRod_Type_A = UtilsItems.getSimpleStack(ModItems.FuelRod_Thorium);
ItemStack validFuelRod_Type_B = UtilsItems.getSimpleStack(ModItems.FuelRod_Uranium);
ItemStack validFuelRod_Type_C = UtilsItems.getSimpleStack(ModItems.FuelRod_Plutonium);
for (int i = 0; i < getSizeInventory(); i++){
ItemStack tempCurrent = items[i];
if (tempCurrent == validFuelRod_Type_A ||tempCurrent == validFuelRod_Type_B || tempCurrent == validFuelRod_Type_C){
Item tempItem = tempCurrent.getItem();
FuelRod_Base tempItem2 = (FuelRod_Base) tempItem;
if (tempItem2.getHeat() <= 5000){
tempItem2.addHeat(5);
}
if (tempItem2.getFuelRemaining() >= 1){
tempItem2.addFuel(-1);
}
ItemStack validFuelRod = UtilsItems.getSimpleStack(tempItem2);
setInventorySlotContents(i, validFuelRod);
}
}
internalClock=0;
}
super.updateEntity();
}
}
|