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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
package gregtech.common.tileentities.storage;
import static gregtech.api.enums.Textures.BlockIcons.LOCKERS;
import static gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAYS_ENERGY_IN;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_LOCKER;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import gregtech.api.enums.GTValues;
import gregtech.api.enums.SoundResource;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.MTETieredMachineBlock;
import gregtech.api.objects.GTItemStack;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GTModHandler;
import gregtech.api.util.GTUtility;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
public class MTELocker extends MTETieredMachineBlock {
private static final String CHARGE_SLOT_WAILA_TAG = "charge_slot_";
public byte mType = 0;
public MTELocker(int aID, String aName, String aNameRegional, int aTier) {
super(aID, aName, aNameRegional, aTier, 4, "Stores and recharges Armor");
}
public MTELocker(String aName, int aTier, String aDescription, ITexture[][][] aTextures) {
super(aName, aTier, 4, aDescription, aTextures);
}
public MTELocker(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) {
super(aName, aTier, 4, aDescription, aTextures);
}
@Override
public String[] getDescription() {
String[] desc = new String[mDescriptionArray.length + 1];
System.arraycopy(mDescriptionArray, 0, desc, 0, mDescriptionArray.length);
desc[mDescriptionArray.length] = "Click with Screwdriver to change Style";
return desc;
}
@Override
public ITexture[][][] getTextureSet(ITexture[] aTextures) {
ITexture[][][] rTextures = new ITexture[3][17][];
for (byte i = -1; i < 16; i = (byte) (i + 1)) {
ITexture[] tmp0 = { MACHINE_CASINGS[this.mTier][(i + 1)] };
rTextures[0][(i + 1)] = tmp0;
ITexture[] tmp1 = { MACHINE_CASINGS[this.mTier][(i + 1)], OVERLAYS_ENERGY_IN[this.mTier] };
rTextures[1][(i + 1)] = tmp1;
ITexture[] tmp2 = { MACHINE_CASINGS[this.mTier][(i + 1)], TextureFactory.of(OVERLAY_LOCKER) };
rTextures[2][(i + 1)] = tmp2;
}
return rTextures;
}
@Override
public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, ForgeDirection side, ForgeDirection aFacing,
int colorIndex, boolean aActive, boolean redstoneLevel) {
if (side == aFacing) {
return new ITexture[] { this.mTextures[2][(colorIndex + 1)][0], this.mTextures[2][(colorIndex + 1)][1],
LOCKERS[Math.abs(this.mType % LOCKERS.length)] };
}
return this.mTextures[0][(colorIndex + 1)];
}
@Override
public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
return new MTELocker(this.mName, this.mTier, this.mDescriptionArray, this.mTextures);
}
@Override
public boolean isSimpleMachine() {
return false;
}
@Override
public boolean isElectric() {
return true;
}
@Override
public boolean isValidSlot(int aIndex) {
return true;
}
@Override
public boolean isFacingValid(ForgeDirection facing) {
return (facing.flag & (ForgeDirection.UP.flag | ForgeDirection.DOWN.flag)) == 0;
}
@Override
public boolean isEnetInput() {
return true;
}
@Override
public boolean isInputFacing(ForgeDirection side) {
return side == getBaseMetaTileEntity().getBackFacing();
}
@Override
public boolean isTeleporterCompatible() {
return false;
}
@Override
public long maxEUStore() {
return GTValues.V[this.mTier] * maxAmperesIn();
}
@Override
public long maxEUInput() {
return GTValues.V[this.mTier];
}
@Override
public long maxAmperesIn() {
return this.mInventory.length * 2L;
}
@Override
public int rechargerSlotStartIndex() {
return 0;
}
@Override
public int rechargerSlotCount() {
return getBaseMetaTileEntity().isAllowedToWork() ? this.mInventory.length : 0;
}
@Override
public boolean isAccessAllowed(EntityPlayer aPlayer) {
return true;
}
@Override
public void saveNBTData(NBTTagCompound aNBT) {
aNBT.setByte("mType", this.mType);
}
@Override
public void loadNBTData(NBTTagCompound aNBT) {
this.mType = aNBT.getByte("mType");
}
@Override
public void onValueUpdate(byte aValue) {
this.mType = aValue;
}
@Override
public byte getUpdateData() {
return this.mType;
}
@Override
public void doSound(byte aIndex, double aX, double aY, double aZ) {
if (aIndex == 16) {
GTUtility.doSoundAtClient(SoundResource.RANDOM_CLICK, 1, 1.0F);
}
}
@Override
public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) {
if (side == getBaseMetaTileEntity().getFrontFacing()) {
this.mType = ((byte) (this.mType + 1));
}
}
@Override
public boolean allowCoverOnSide(ForgeDirection side, GTItemStack aStack) {
return side != getBaseMetaTileEntity().getFrontFacing();
}
@Override
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, ForgeDirection side,
float aX, float aY, float aZ) {
if ((aBaseMetaTileEntity.isServerSide()) && (side == aBaseMetaTileEntity.getFrontFacing())) {
for (int i = 0; i < 4; i++) {
ItemStack tSwapStack = this.mInventory[i];
this.mInventory[i] = aPlayer.inventory.armorInventory[i];
aPlayer.inventory.armorInventory[i] = tSwapStack;
}
aPlayer.inventoryContainer.detectAndSendChanges();
sendSound((byte) 16);
}
return true;
}
@Override
public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side,
ItemStack aStack) {
return false;
}
@Override
public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side,
ItemStack aStack) {
return false;
}
@Override
public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompound tag, World world, int x, int y,
int z) {
super.getWailaNBTData(player, tile, tag, world, x, y, z);
for (int i = 0; i < 4; i++) {
final ItemStack itemStack = this.mInventory[3 - i];
if (itemStack != null) {
tag.setTag(CHARGE_SLOT_WAILA_TAG + i, itemStack.writeToNBT(new NBTTagCompound()));
}
}
}
@Override
public void getWailaBody(ItemStack itemStack, List<String> currentTip, IWailaDataAccessor accessor,
IWailaConfigHandler config) {
super.getWailaBody(itemStack, currentTip, accessor, config);
final NBTTagCompound tag = accessor.getNBTData();
for (int i = 0; i < 4; i++) {
final String index = GTUtility.formatNumbers(i + 1);
if (tag.hasKey(CHARGE_SLOT_WAILA_TAG + i)) {
final ItemStack slotItem = ItemStack
.loadItemStackFromNBT(tag.getCompoundTag(CHARGE_SLOT_WAILA_TAG + i));
assert slotItem != null;
currentTip.add(
GTModHandler.getElectricItemCharge(slotItem)
.map(chargeInfo -> {
final float ratio = (float) chargeInfo[0] / (float) chargeInfo[1];
final EnumChatFormatting chargeFormat;
if (ratio == 0L) {
chargeFormat = EnumChatFormatting.GRAY;
} else if (ratio < 0.25) {
chargeFormat = EnumChatFormatting.RED;
} else if (ratio < 0.5) {
chargeFormat = EnumChatFormatting.GOLD;
} else if (ratio < 0.75) {
chargeFormat = EnumChatFormatting.YELLOW;
} else if (ratio < 1L) {
chargeFormat = EnumChatFormatting.GREEN;
} else {
chargeFormat = EnumChatFormatting.AQUA;
}
return StatCollector.translateToLocalFormatted(
"gt.locker.waila_armor_slot_charged",
index,
slotItem.getDisplayName(),
chargeFormat,
GTUtility.formatNumbers(ratio * 100));
})
.orElseGet(
// Lazy initialization
() -> StatCollector.translateToLocalFormatted(
"gt.locker.waila_armor_slot_generic",
index,
slotItem.getDisplayName())));
} else {
currentTip.add(StatCollector.translateToLocalFormatted("gt.locker.waila_armor_slot_none", index));
}
}
}
}
|