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
|
package tectech.thing.metaTileEntity.hatch;
import static gregtech.api.enums.Dyes.MACHINE_METAL;
import static net.minecraft.util.StatCollector.translateToLocalFormatted;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.api.enums.Dyes;
import gregtech.api.enums.Textures;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.MTEHatch;
import gregtech.api.objects.GTRenderedTexture;
import gregtech.mixin.interfaces.accessors.EntityPlayerMPAccessor;
import tectech.mechanics.dataTransport.DataPacket;
import tectech.mechanics.pipe.IConnectsToDataPipe;
import tectech.util.CommonValues;
import tectech.util.TTUtility;
/**
* Created by danie_000 on 11.12.2016.
*/
public abstract class MTEHatchDataConnector<T extends DataPacket> extends MTEHatch implements IConnectsToDataPipe {
public static Textures.BlockIcons.CustomIcon EM_D_SIDES;
public static Textures.BlockIcons.CustomIcon EM_D_ACTIVE;
public static Textures.BlockIcons.CustomIcon EM_D_CONN;
private String clientLocale = "en_US";
public T q;
public short id = -1;
protected MTEHatchDataConnector(int aID, String aName, String aNameRegional, int aTier, String[] descr) {
super(aID, aName, aNameRegional, aTier, 0, descr);
TTUtility.setTier(aTier, this);
}
protected MTEHatchDataConnector(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) {
super(aName, aTier, 0, aDescription, aTextures);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister aBlockIconRegister) {
super.registerIcons(aBlockIconRegister);
EM_D_ACTIVE = new Textures.BlockIcons.CustomIcon("iconsets/OVERLAY_EM_D_ACTIVE");
EM_D_SIDES = new Textures.BlockIcons.CustomIcon("iconsets/OVERLAY_EM_D_SIDES");
EM_D_CONN = new Textures.BlockIcons.CustomIcon("iconsets/EM_DATA_CONN");
}
@Override
public ITexture[] getTexturesActive(ITexture aBaseTexture) {
return new ITexture[] { aBaseTexture,
new GTRenderedTexture(
EM_D_ACTIVE,
Dyes.getModulation(getBaseMetaTileEntity().getColorization(), MACHINE_METAL.getRGBA())),
new GTRenderedTexture(EM_D_CONN) };
}
@Override
public ITexture[] getTexturesInactive(ITexture aBaseTexture) {
return new ITexture[] { aBaseTexture,
new GTRenderedTexture(
EM_D_SIDES,
Dyes.getModulation(getBaseMetaTileEntity().getColorization(), MACHINE_METAL.getRGBA())),
new GTRenderedTexture(EM_D_CONN) };
}
@Override
public void saveNBTData(NBTTagCompound aNBT) {
super.saveNBTData(aNBT);
aNBT.setShort("eID", id);
if (q != null) {
aNBT.setTag("eDATA", q.toNbt());
}
}
@Override
public void loadNBTData(NBTTagCompound aNBT) {
super.loadNBTData(aNBT);
id = aNBT.getShort("eID");
if (aNBT.hasKey("eDATA")) {
q = loadPacketFromNBT(aNBT.getCompoundTag("eDATA"));
}
}
protected abstract T loadPacketFromNBT(NBTTagCompound nbt);
@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
if (aBaseMetaTileEntity.isServerSide()) {
if (CommonValues.MOVE_AT == aTick % 20) {
if (q == null) {
getBaseMetaTileEntity().setActive(false);
} else {
getBaseMetaTileEntity().setActive(true);
moveAround(aBaseMetaTileEntity);
}
}
}
}
public abstract void moveAround(IGregTechTileEntity aBaseMetaTileEntity);
@Override
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
if (aBaseMetaTileEntity.isClientSide()) {
return true;
}
if (aPlayer instanceof EntityPlayerMPAccessor) {
clientLocale = ((EntityPlayerMPAccessor) aPlayer).gt5u$getTranslator();
}
return true;
}
@Override
public boolean isFacingValid(ForgeDirection facing) {
return true;
}
@Override
public boolean isAccessAllowed(EntityPlayer aPlayer) {
return true;
}
@Override
public boolean isLiquidInput(ForgeDirection side) {
return false;
}
@Override
public boolean isFluidInputAllowed(FluidStack aFluid) {
return false;
}
@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 boolean isValidSlot(int aIndex) {
return false;
}
@Override
public boolean isGivingInformation() {
return true;
}
@Override
public String[] getInfoData() {
if (id > 0) {
return new String[] {
translateToLocalFormatted("tt.keyword.ID", clientLocale) + ": " + EnumChatFormatting.AQUA + id,
translateToLocalFormatted("tt.keyword.Content", clientLocale) + ": "
+ EnumChatFormatting.AQUA
+ (q != null ? q.getContentString() : 0),
translateToLocalFormatted("tt.keyword.PacketHistory", clientLocale) + ": "
+ EnumChatFormatting.RED
+ (q != null ? q.getTraceSize() : 0), };
}
return new String[] {
translateToLocalFormatted("tt.keyword.Content", clientLocale) + ": "
+ EnumChatFormatting.AQUA
+ (q != null ? q.getContentString() : 0),
translateToLocalFormatted("tt.keyword.PacketHistory", clientLocale) + ": "
+ EnumChatFormatting.RED
+ (q != null ? q.getTraceSize() : 0), };
}
@Override
public byte getColorization() {
return getBaseMetaTileEntity().getColorization();
}
}
|