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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
package gregtech.common.blocks;
import static gregtech.api.enums.Mods.NotEnoughItems;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.boss.EntityDragon;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.StatCollector;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.GTMod;
import gregtech.api.GregTechAPI;
import gregtech.api.enums.Materials;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.interfaces.ITexture;
import gregtech.api.items.GTGenericBlock;
import gregtech.api.util.GTLanguageManager;
import gregtech.api.util.GTModHandler;
import gregtech.api.util.GTOreDictUnificator;
import gregtech.api.util.GTUtility;
import gregtech.common.render.GTRendererBlock;
public abstract class BlockOresAbstract extends GTGenericBlock implements ITileEntityProvider {
private static final String DOT_NAME = ".name";
private static final String DOT_TOOLTIP = ".tooltip";
public static ThreadLocal<TileEntityOres> mTemporaryTileEntity = new ThreadLocal<>();
public static boolean FUCKING_LOCK = false;
public static boolean tHideOres;
public static Set<Materials> aBlockedOres = new HashSet<>();
protected BlockOresAbstract(String aUnlocalizedName, int aOreMetaCount, boolean aHideFirstMeta,
Material aMaterial) {
super(ItemOres.class, aUnlocalizedName, aMaterial);
this.isBlockContainer = true;
setStepSound(soundTypeStone);
setCreativeTab(GregTechAPI.TAB_GREGTECH_ORES);
tHideOres = NotEnoughItems.isModLoaded() && GTMod.gregtechproxy.mHideUnusedOres;
if (aOreMetaCount > 8 || aOreMetaCount < 0) aOreMetaCount = 8;
for (int i = 0; i < 16; i++) {
GTModHandler.addValuableOre(this, i, 1);
}
for (int i = 1; i < GregTechAPI.sGeneratedMaterials.length; i++) {
if (GregTechAPI.sGeneratedMaterials[i] != null) {
for (int j = 0; j < aOreMetaCount; j++) {
if (!this.getEnabledMetas()[j]) continue;
GTLanguageManager.addStringLocalization(
getUnlocalizedName() + "." + (i + (j * 1000)) + DOT_NAME,
GTLanguageManager.i18nPlaceholder ? getLocalizedNameFormat(GregTechAPI.sGeneratedMaterials[i])
: getLocalizedName(GregTechAPI.sGeneratedMaterials[i]));
GTLanguageManager.addStringLocalization(
getUnlocalizedName() + "." + (i + (j * 1000)) + DOT_TOOLTIP,
GregTechAPI.sGeneratedMaterials[i].getToolTip());
GTLanguageManager.addStringLocalization(
getUnlocalizedName() + "." + ((i + 16000) + (j * 1000)) + DOT_NAME,
"Small " + (GTLanguageManager.i18nPlaceholder
? getLocalizedNameFormat(GregTechAPI.sGeneratedMaterials[i])
: getLocalizedName(GregTechAPI.sGeneratedMaterials[i])));
GTLanguageManager.addStringLocalization(
getUnlocalizedName() + "." + ((i + 16000) + (j * 1000)) + DOT_TOOLTIP,
GregTechAPI.sGeneratedMaterials[i].getToolTip());
if ((GregTechAPI.sGeneratedMaterials[i].mTypes & 0x8) != 0
&& !aBlockedOres.contains(GregTechAPI.sGeneratedMaterials[i])) {
GTOreDictUnificator.registerOre(
this.getProcessingPrefix()[j] != null
? this.getProcessingPrefix()[j].get(GregTechAPI.sGeneratedMaterials[i])
: "",
new ItemStack(this, 1, i + (j * 1000)));
if (tHideOres) {
if (!(j == 0 && !aHideFirstMeta)) {
codechicken.nei.api.API.hideItem(new ItemStack(this, 1, i + (j * 1000)));
}
codechicken.nei.api.API.hideItem(new ItemStack(this, 1, (i + 16000) + (j * 1000)));
}
}
}
}
}
}
public int getBaseBlockHarvestLevel(int aMeta) {
return 0;
}
@Override
public void onNeighborChange(IBlockAccess aWorld, int aX, int aY, int aZ, int aTileX, int aTileY, int aTileZ) {
if (!FUCKING_LOCK) {
FUCKING_LOCK = true;
TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ);
if ((tTileEntity instanceof TileEntityOres)) {
((TileEntityOres) tTileEntity).onUpdated();
}
}
FUCKING_LOCK = false;
}
@Override
public void onNeighborBlockChange(World aWorld, int aX, int aY, int aZ, Block aBlock) {
if (!FUCKING_LOCK) {
FUCKING_LOCK = true;
TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ);
if ((tTileEntity instanceof TileEntityOres)) {
((TileEntityOres) tTileEntity).onUpdated();
}
}
FUCKING_LOCK = false;
}
public String getLocalizedNameFormat(Materials aMaterial) {
return switch (aMaterial.mName) {
case "InfusedAir", "InfusedDull", "InfusedEarth", "InfusedEntropy", "InfusedFire", "InfusedOrder", "InfusedVis", "InfusedWater" -> "%material Infused Stone";
case "Vermiculite", "Bentonite", "Kaolinite", "Talc", "BasalticMineralSand", "GraniticMineralSand", "GlauconiteSand", "CassiteriteSand", "GarnetSand", "QuartzSand", "Pitchblende", "FullersEarth" -> "%material";
default -> "%material" + OrePrefixes.ore.mLocalizedMaterialPost;
};
}
public String getLocalizedName(Materials aMaterial) {
return aMaterial.getDefaultLocalizedNameForItem(getLocalizedNameFormat(aMaterial));
}
@Override
public boolean onBlockActivated(World aWorld, int aX, int aY, int aZ, EntityPlayer aPlayer, int ordinalSide,
float aOffsetX, float aOffsetY, float aOffsetZ) {
if (!aPlayer.isSneaking() || !aPlayer.capabilities.isCreativeMode) {
return false;
}
TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ);
if (!(tTileEntity instanceof TileEntityOres)) {
return false;
}
boolean tNatural = (((TileEntityOres) tTileEntity).mNatural = !((TileEntityOres) tTileEntity).mNatural);
GTUtility.sendChatToPlayer(aPlayer, "Ore \"mNatural\" flag set to: " + tNatural);
return true;
}
@Override
public boolean onBlockEventReceived(World p_149696_1_, int p_149696_2_, int p_149696_3_, int p_149696_4_,
int p_149696_5_, int p_149696_6_) {
super.onBlockEventReceived(p_149696_1_, p_149696_2_, p_149696_3_, p_149696_4_, p_149696_5_, p_149696_6_);
TileEntity tileentity = p_149696_1_.getTileEntity(p_149696_2_, p_149696_3_, p_149696_4_);
return tileentity != null && tileentity.receiveClientEvent(p_149696_5_, p_149696_6_);
}
@Override
public boolean canEntityDestroy(IBlockAccess world, int x, int y, int z, Entity entity) {
return (!(entity instanceof EntityDragon)) && (super.canEntityDestroy(world, x, y, z, entity));
}
@Override
public String getHarvestTool(int aMeta) {
return aMeta < 8 ? "pickaxe" : "shovel";
}
@Override
public int getHarvestLevel(int aMeta) {
return aMeta == 5 || aMeta == 6 ? 2 : aMeta % 8;
}
@Override
public float getBlockHardness(World aWorld, int aX, int aY, int aZ) {
return 1.0F + getHarvestLevel(aWorld.getBlockMetadata(aX, aY, aZ)) * 1.0F;
}
@Override
public float getExplosionResistance(Entity entity, World aWorld, int aX, int aY, int aZ, double explosionX,
double explosionY, double explosionZ) {
return 1.0F + getHarvestLevel(aWorld.getBlockMetadata(aX, aY, aZ)) * 1.0F;
}
@Override
protected boolean canSilkHarvest() {
return false;
}
@Override
public abstract String getUnlocalizedName();
@Override
public String getLocalizedName() {
return StatCollector.translateToLocal(getUnlocalizedName() + DOT_NAME);
}
@Override
public int getRenderType() {
if (GTRendererBlock.INSTANCE == null) {
return super.getRenderType();
}
return GTRendererBlock.INSTANCE.mRenderID;
}
@Override
public boolean canBeReplacedByLeaves(IBlockAccess aWorld, int aX, int aY, int aZ) {
return false;
}
@Override
public boolean isNormalCube(IBlockAccess aWorld, int aX, int aY, int aZ) {
return true;
}
@Override
public boolean hasTileEntity(int aMeta) {
return true;
}
@Override
public TileEntity createNewTileEntity(World aWorld, int aMeta) {
return createTileEntity(aWorld, aMeta);
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(IBlockAccess aIBlockAccess, int aX, int aY, int aZ, int ordinalSide) {
return Blocks.stone.getIcon(0, 0);
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int ordinalSide, int aMeta) {
return Blocks.stone.getIcon(0, 0);
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister aIconRegister) {}
@Override
@SideOnly(Side.CLIENT)
public boolean addHitEffects(World worldObj, MovingObjectPosition target, EffectRenderer effectRenderer) {
GTRendererBlock
.addHitEffects(effectRenderer, this, worldObj, target.blockX, target.blockY, target.blockZ, target.sideHit);
return true;
}
@Override
@SideOnly(Side.CLIENT)
public boolean addDestroyEffects(World world, int x, int y, int z, int meta, EffectRenderer effectRenderer) {
GTRendererBlock.addDestroyEffects(effectRenderer, this, world, x, y, z);
return true;
}
@Override
public int getDamageValue(World aWorld, int aX, int aY, int aZ) {
TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ);
if (((tTileEntity instanceof TileEntityOres))) {
return ((TileEntityOres) tTileEntity).getMetaData();
}
return 0;
}
@Override
public void breakBlock(World aWorld, int aX, int aY, int aZ, Block aBlock, int aMetadata) {
TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ);
if ((tTileEntity instanceof TileEntityOres)) {
mTemporaryTileEntity.set((TileEntityOres) tTileEntity);
}
super.breakBlock(aWorld, aX, aY, aZ, aBlock, aMetadata);
aWorld.removeTileEntity(aX, aY, aZ);
}
public abstract OrePrefixes[] getProcessingPrefix(); // Must have 8 entries; an entry can be null to disable
// automatic recipes.
public abstract boolean[] getEnabledMetas(); // Must have 8 entries.
public abstract Block getDroppedBlock();
public abstract Materials[] getDroppedDusts(); // Must have 8 entries; can be null.
@Override
public ArrayList<ItemStack> getDrops(World aWorld, int aX, int aY, int aZ, int aMeta, int aFortune) {
TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ);
if ((tTileEntity instanceof TileEntityOres)) {
return ((TileEntityOres) tTileEntity).getDrops(getDroppedBlock(), aFortune);
}
return mTemporaryTileEntity.get() == null ? new ArrayList<>()
: mTemporaryTileEntity.get()
.getDrops(getDroppedBlock(), aFortune);
}
@Override
public TileEntity createTileEntity(World aWorld, int aMeta) {
return new TileEntityOres();
}
public abstract ITexture[] getTextureSet(); // Must have 16 entries.
@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item aItem, CreativeTabs aTab, List<ItemStack> aList) {
for (int i = 0; i < GregTechAPI.sGeneratedMaterials.length; i++) {
Materials tMaterial = GregTechAPI.sGeneratedMaterials[i];
if ((tMaterial != null) && ((tMaterial.mTypes & 0x8) != 0) && !aBlockedOres.contains(tMaterial)) {
for (int meta = i; meta < 23000 + i; meta += 1000) {
if (!(new ItemStack(aItem, 1, meta).getDisplayName()
.contains(DOT_NAME))) aList.add(new ItemStack(aItem, 1, meta));
}
}
}
}
}
|