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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
package gtPlusPlus.xmod.gregtech.common.tileentities.storage;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import org.apache.commons.lang3.ArrayUtils;
import com.gtnewhorizons.modularui.api.NumberFormatMUI;
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.api.screen.UIBuildContext;
import com.gtnewhorizons.modularui.common.widget.DrawableWidget;
import com.gtnewhorizons.modularui.common.widget.SlotWidget;
import com.gtnewhorizons.modularui.common.widget.TextWidget;
import gregtech.api.enums.Textures.BlockIcons;
import gregtech.api.gui.modularui.GTUIInfos;
import gregtech.api.gui.modularui.GTUITextures;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.modularui.IAddUIWidgets;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.implementations.MTETieredMachineBlock;
import gregtech.api.objects.GTRenderedTexture;
import gregtech.api.util.GTUtility;
import gtPlusPlus.core.lib.GTPPCore;
@Deprecated
// GT++ was adding super chests too for some reason when GT already has some
// this is deprecated but not deleted because it is used for the MTEInfiniteItemHolder
public class MTETieredChest extends MTETieredMachineBlock implements IAddUIWidgets {
public int mItemCount = 0;
public ItemStack mItemStack = null;
private static final double mStorageFactor = (270000.0D / 16);
public MTETieredChest(int aID, String aName, String aNameRegional, int aTier) {
super(
aID,
aName,
aNameRegional,
aTier,
3,
"This Chest stores " + (int) (Math.pow(6.0D, aTier) * mStorageFactor) + " Items");
}
public MTETieredChest(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) {
super(aName, aTier, 3, aDescription, aTextures);
}
@Override
public String[] getDescription() {
return ArrayUtils.add(this.mDescriptionArray, GTPPCore.GT_Tooltip.get());
}
@Override
public boolean isSimpleMachine() {
return true;
}
public boolean isFacingValid(ForgeDirection facing) {
return true;
}
@Override
public boolean isAccessAllowed(EntityPlayer aPlayer) {
return true;
}
@Override
public boolean isValidSlot(int aIndex) {
return true;
}
@Override
public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
return new MTETieredChest(this.mName, this.mTier, this.mDescriptionArray, this.mTextures);
}
@Override
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
GTUIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer);
return true;
}
@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) {
if (this.getBaseMetaTileEntity()
.isServerSide()
&& this.getBaseMetaTileEntity()
.isAllowedToWork()) {
if (this.getItemCount() <= 0) {
this.mItemStack = null;
this.mItemCount = 0;
}
if (this.mItemStack == null && this.mInventory[0] != null) {
this.mItemStack = this.mInventory[0].copy();
}
if (this.mInventory[0] != null && this.mItemCount < this.getMaxItemCount()
&& GTUtility.areStacksEqual(this.mInventory[0], this.mItemStack)) {
this.mItemCount += this.mInventory[0].stackSize;
if (this.mItemCount > this.getMaxItemCount()) {
this.mInventory[0].stackSize = this.mItemCount - this.getMaxItemCount();
this.mItemCount = this.getMaxItemCount();
} else {
this.mInventory[0] = null;
}
}
if (this.mInventory[1] == null && this.mItemStack != null) {
this.mInventory[1] = this.mItemStack.copy();
this.mInventory[1].stackSize = Math.min(this.mItemStack.getMaxStackSize(), this.mItemCount);
this.mItemCount -= this.mInventory[1].stackSize;
} else if (this.mItemCount > 0 && GTUtility.areStacksEqual(this.mInventory[1], this.mItemStack)
&& this.mInventory[1].getMaxStackSize() > this.mInventory[1].stackSize) {
int tmp = Math
.min(this.mItemCount, this.mInventory[1].getMaxStackSize() - this.mInventory[1].stackSize);
this.mInventory[1].stackSize += tmp;
this.mItemCount -= tmp;
}
if (this.mItemStack != null) {
this.mInventory[2] = this.mItemStack.copy();
this.mInventory[2].stackSize = Math.min(this.mItemStack.getMaxStackSize(), this.mItemCount);
} else {
this.mInventory[2] = null;
}
}
}
private int getItemCount() {
return this.mItemCount;
}
@Override
public void setItemCount(int aCount) {
this.mItemCount = aCount;
}
@Override
public int getProgresstime() {
return this.mItemCount + (this.mInventory[0] == null ? 0 : this.mInventory[0].stackSize)
+ (this.mInventory[1] == null ? 0 : this.mInventory[1].stackSize);
}
@Override
public int maxProgresstime() {
return this.getMaxItemCount();
}
@Override
public int getMaxItemCount() {
return (int) (Math.pow(6.0D, this.mTier) * mStorageFactor - 128.0D);
}
public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side,
ItemStack aStack) {
return aIndex == 1;
}
public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side,
ItemStack aStack) {
return aIndex == 0 && (this.mInventory[0] == null || GTUtility.areStacksEqual(this.mInventory[0], aStack));
}
@Override
public String[] getInfoData() {
return this.mItemStack == null
? new String[] { "Super Storage Chest", "Stored Items:", "No Items", Integer.toString(0),
Integer.toString(this.getMaxItemCount()) }
: new String[] { "Super Storage Chest", "Stored Items:", this.mItemStack.getDisplayName(),
Integer.toString(this.mItemCount), Integer.toString(this.getMaxItemCount()) };
}
@Override
public boolean isGivingInformation() {
return true;
}
@Override
public void saveNBTData(NBTTagCompound aNBT) {
aNBT.setInteger("mItemCount", this.mItemCount);
if (this.mItemStack != null) {
aNBT.setTag("mItemStack", this.mItemStack.writeToNBT(new NBTTagCompound()));
}
}
@Override
public void loadNBTData(NBTTagCompound aNBT) {
if (aNBT.hasKey("mItemCount")) {
this.mItemCount = aNBT.getInteger("mItemCount");
}
if (aNBT.hasKey("mItemStack")) {
this.mItemStack = ItemStack.loadItemStackFromNBT((NBTTagCompound) aNBT.getTag("mItemStack"));
}
}
public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, ForgeDirection side, ForgeDirection facing,
int aColorIndex, boolean aActive, boolean aRedstone) {
return aBaseMetaTileEntity.getFrontFacing() == ForgeDirection.DOWN && side == ForgeDirection.WEST
? new ITexture[] { BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1],
new GTRenderedTexture(BlockIcons.OVERLAY_QCHEST) }
: (side == aBaseMetaTileEntity.getFrontFacing()
? new ITexture[] { BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1],
new GTRenderedTexture(BlockIcons.OVERLAY_QCHEST) }
: new ITexture[] { BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1] });
}
@Override
public ITexture[][][] getTextureSet(ITexture[] aTextures) {
return new ITexture[0][0][0];
}
protected static final NumberFormatMUI numberFormat = new NumberFormatMUI();
@Override
public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) {
builder.widget(
new DrawableWidget().setDrawable(GTUITextures.PICTURE_SCREEN_BLACK)
.setPos(7, 16)
.setSize(71, 45))
.widget(
new SlotWidget(inventoryHandler, 0)
.setBackground(getGUITextureSet().getItemSlot(), GTUITextures.OVERLAY_SLOT_IN)
.setPos(79, 16))
.widget(
new SlotWidget(inventoryHandler, 1).setAccess(true, false)
.setBackground(getGUITextureSet().getItemSlot(), GTUITextures.OVERLAY_SLOT_OUT)
.setPos(79, 52))
.widget(
SlotWidget.phantom(inventoryHandler, 2)
.disableInteraction()
.setBackground(GTUITextures.TRANSPARENT)
.setPos(59, 42))
.widget(
new TextWidget("Item Amount").setDefaultColor(COLOR_TEXT_WHITE.get())
.setPos(10, 20))
.widget(
new TextWidget().setStringSupplier(() -> numberFormat.format(mItemCount))
.setDefaultColor(COLOR_TEXT_WHITE.get())
.setPos(10, 30));
}
}
|