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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
package gtPlusPlus.core.block.base;
import static gregtech.api.enums.Mods.GTPlusPlus;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.core.CreativeTab;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gtPlusPlus.api.interfaces.ITileTooltip;
import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.api.objects.minecraft.CubicObject;
import gtPlusPlus.api.objects.minecraft.SafeTexture;
import gtPlusPlus.core.util.Utils;
import gtPlusPlus.core.util.minecraft.InventoryUtils;
import gtPlusPlus.core.util.minecraft.ItemUtils;
public abstract class BasicTileBlockWithTooltip extends BlockContainer implements ITileTooltip {
/**
* Each mapped object holds the data for the six sides.
*/
@SideOnly(Side.CLIENT)
private ArrayList<CubicObject<SafeTexture>> mSidedTextureArray;
/**
* Does this block have any meta at all?
*/
public final boolean hasMeta() {
return getMetaCount() > 0;
}
/**
* The amount of meta this block has.
*/
public abstract int getMetaCount();
/**
* Does this {@link Block} require special {@link ItemBlock} handling?
*
* @return The {@link Class} that will be used for this {@link Block}.
*/
public Class<? extends ItemBlock> getItemBlockClass() {
return ItemBlock.class;
}
/**
* A lazy way to declare the unlocal name for the block, makes boilerplate easy.
*
* @return The internal name for this block.
*/
public abstract String getUnlocalBlockName();
/**
* Lazy Boilerplate.
*
* @return Block Hardness.
*/
protected abstract float initBlockHardness();
/**
* Lazy Boilerplate.
*
* @return Block Resistance.
*/
protected abstract float initBlockResistance();
/**
* Lazy Boilerplate.
*
* @return The {@link CreativeTab} this Block is shown on.
*/
protected abstract CreativeTabs initCreativeTab();
/**
* The ID used by the {@link ITileTooltip} handler. Return -1 if you are not providing a custom {@link ItemBlock} in
* {@link #getItemBlockClass}().
*/
@Override
public abstract int getTooltipID();
public BasicTileBlockWithTooltip(Material aBlockMat) {
super(aBlockMat);
// Use Abstract method values
this.setHardness(initBlockHardness());
this.setResistance(initBlockResistance());
this.setBlockName(getUnlocalBlockName());
this.setCreativeTab(initCreativeTab());
// Register the block last.
GameRegistry.registerBlock(this, getItemBlockClass(), getUnlocalBlockName());
Logger.INFO("Registered " + getTileEntityName() + ".");
if (Utils.isClient()) {
// Handle Textures
handleTextures();
}
}
/**
* The name of the Tile Entity.
*/
protected abstract String getTileEntityName();
/**
* The String used for texture pathing.
*
* @return Sanitized {@link String}, containing no spaces or illegal characters.
*/
private String getTileEntityNameForTexturePathing() {
return Utils.sanitizeString(getTileEntityName().replace(" ", ""));
}
/**
* An array of CubicObjects, one for each meta, else just a single cell array. Expected to be null regularly, as the
* default texture handling should suffice. Handy if re-using textures or using a non-standard structure for them.
* FULL texture path must be used, inclusive of the MOD ID and a colon.
*/
public CubicObject<String>[] getCustomTextureDirectoryObject() {
return null;
}
@Override
@SideOnly(Side.CLIENT)
public final IIcon getIcon(final int ordinalSide, final int aMeta) {
return mSidedTextureArray.get(aMeta)
.get(ForgeDirection.getOrientation(ordinalSide))
.getIcon();
}
@Override
public IIcon getIcon(IBlockAccess aWorld, int aX, int aY, int aZ, int ordinalSide) {
return super.getIcon(aWorld, aX, aY, aZ, ordinalSide);
}
@SideOnly(Side.CLIENT)
private void handleTextures() {
Logger.INFO("[TeTexture] Building Texture Maps for " + getTileEntityName() + ".");
// Init on the Client side only, to prevent Field initializers existing in the Server side bytecode.
mSidedTextureArray = new ArrayList<>();
// Holds the data for the six sides, each side holds an array of data for each respective meta.
ArrayList<CubicObject<String>> sidedTexturePathArray = new ArrayList<>();
// Store them in forge order
// DOWN, UP, NORTH, SOUTH, WEST, EAST
// Default Path Name, this will make us look inside 'miscutils\textures\blocks'
String aTexPathBuilt = GTPlusPlus.ID + ":TileEntities/" + getTileEntityNameForTexturePathing() + "/";
// File Name Suffixes, without meta tags
String aStringBot;
String aStringTop;
String aStringBack;
String aStringFront;
String aStringLeft;
String aStringRight;
// Do we provide a matrix of custom data to be used for texture processing instead?
if (getCustomTextureDirectoryObject() != null) {
// Get custom provided texture data.
CubicObject<String>[] aDataMap = getCustomTextureDirectoryObject();
Logger.INFO("[TeTexture] Found custom texture data, using this instead. Size: " + aDataMap.length);
// Map each meta string data to the main map.
for (int i = 0; i < aDataMap.length; i++) {
sidedTexturePathArray.add(aDataMap[i]);
Logger.INFO("Mapped value for meta " + i + ".");
}
} else {
Logger.INFO("[TeTexture] Processing " + (1 + getMetaCount()) + " sets.");
// Iterate once for each meta
for (int i = 0; i < (1 + getMetaCount()); i++) {
// File Name Suffixes, without meta tags
aStringBot = "Bottom";
aStringTop = "Top";
aStringBack = "Back";
aStringFront = "Front";
aStringLeft = "Left";
aStringRight = "Right";
// Add tails if we have meta
if (hasMeta()) {
aStringBot = aStringBot + "_" + i;
aStringTop = aStringTop + "_" + i;
aStringBack = aStringBack + "_" + i;
aStringFront = aStringFront + "_" + i;
aStringLeft = aStringLeft + "_" + i;
aStringRight = aStringRight + "_" + i;
}
// Append the full path
aStringBot = aTexPathBuilt + aStringBot;
aStringTop = aTexPathBuilt + aStringTop;
aStringBack = aTexPathBuilt + aStringBack;
aStringFront = aTexPathBuilt + aStringFront;
aStringLeft = aTexPathBuilt + aStringLeft;
aStringRight = aTexPathBuilt + aStringRight;
// Convenience Blob
CubicObject<String> aMetaBlob = new CubicObject<>(
aStringBot,
aStringTop,
aStringBack,
aStringFront,
aStringLeft,
aStringRight);
sidedTexturePathArray.add(aMetaBlob);
Logger.INFO("[TeTexture] Added Texture Path data to map for meta " + i);
}
}
Logger.INFO("[TeTexture] Map size for pathing: " + sidedTexturePathArray.size());
// Iteration Index
int aIndex = 0;
// Iterate each CubicObject, holding the six texture paths for each meta.
for (CubicObject<String> aMetaBlob : sidedTexturePathArray) {
// Make a Safe Texture for each side
SafeTexture aBottom = SafeTexture.register(aMetaBlob.DOWN);
SafeTexture aTop = SafeTexture.register(aMetaBlob.UP);
SafeTexture aBack = SafeTexture.register(aMetaBlob.NORTH);
SafeTexture aFont = SafeTexture.register(aMetaBlob.SOUTH);
SafeTexture aWest = SafeTexture.register(aMetaBlob.WEST);
SafeTexture aEast = SafeTexture.register(aMetaBlob.EAST);
// Store them in an Array
SafeTexture[] aInjectBlob = new SafeTexture[] { aBottom, aTop, aBack, aFont, aWest, aEast };
// Convenience Blob
CubicObject<SafeTexture> aMetaBlob2 = new CubicObject<>(aInjectBlob);
// Store this Blob into
mSidedTextureArray.add(aMetaBlob2);
Logger.INFO("[TeTexture] Added SafeTexture data to map for meta " + (aIndex++));
}
Logger.INFO("[TeTexture] Map size for registration: " + mSidedTextureArray.size());
}
@Override
@SideOnly(Side.CLIENT)
public final void registerBlockIcons(final IIconRegister aRegisterer) {}
@Override
public abstract TileEntity createNewTileEntity(final World world, final int p_149915_2_);
/**
* Called when {@link #breakBlock}() is called, but before {@link InventoryUtils#dropInventoryItems} and the super
* call.
*/
public void onBlockBreak() {}
@Override
public final void breakBlock(final World world, final int x, final int y, final int z, final Block block,
final int number) {
onBlockBreak();
InventoryUtils.dropInventoryItems(world, x, y, z, block);
super.breakBlock(world, x, y, z, block, number);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
|