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 gregtech.common.tileentities.machines.basic;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_BOTTOM_ROCK_BREAKER;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_BOTTOM_ROCK_BREAKER_ACTIVE;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_BOTTOM_ROCK_BREAKER_ACTIVE_GLOW;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_BOTTOM_ROCK_BREAKER_GLOW;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ROCK_BREAKER;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ROCK_BREAKER_ACTIVE;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ROCK_BREAKER_ACTIVE_GLOW;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_ROCK_BREAKER_GLOW;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_SIDE_ROCK_BREAKER;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_SIDE_ROCK_BREAKER_ACTIVE;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_SIDE_ROCK_BREAKER_ACTIVE_GLOW;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_SIDE_ROCK_BREAKER_GLOW;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_TOP_ROCK_BREAKER;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_TOP_ROCK_BREAKER_ACTIVE;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_TOP_ROCK_BREAKER_ACTIVE_GLOW;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_TOP_ROCK_BREAKER_GLOW;
import static gregtech.common.UndergroundOil.undergroundOilReadInformation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import net.minecraft.block.Block;
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.world.ChunkCoordIntPair;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.fluids.FluidStack;
import gregtech.api.GregTechAPI;
import gregtech.api.enums.ItemList;
import gregtech.api.enums.Materials;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.implementations.MTEBasicMachine;
import gregtech.api.objects.ItemData;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GTOreDictUnificator;
import gregtech.api.util.GTUtility;
import gregtech.common.blocks.BlockOresAbstract;
import gregtech.common.blocks.TileEntityOres;
import ic2.core.Ic2Items;
public class MTEAdvSeismicProspector extends MTEBasicMachine {
boolean ready = false;
final int radius;
final int step;
int cX;
int cZ;
public MTEAdvSeismicProspector(int aID, String aName, String aNameRegional, int aTier, int aRadius, int aStep) {
super(
aID,
aName,
aNameRegional,
aTier,
1, // amperage
"",
1, // input slot count
1, // output slot count
TextureFactory.of(
TextureFactory.of(OVERLAY_SIDE_ROCK_BREAKER_ACTIVE),
TextureFactory.builder()
.addIcon(OVERLAY_SIDE_ROCK_BREAKER_ACTIVE_GLOW)
.glow()
.build()),
TextureFactory.of(
TextureFactory.of(OVERLAY_SIDE_ROCK_BREAKER),
TextureFactory.builder()
.addIcon(OVERLAY_SIDE_ROCK_BREAKER_GLOW)
.glow()
.build()),
TextureFactory.of(
TextureFactory.of(OVERLAY_TOP_ROCK_BREAKER_ACTIVE),
TextureFactory.builder()
.addIcon(OVERLAY_TOP_ROCK_BREAKER_ACTIVE_GLOW)
.glow()
.build()),
TextureFactory.of(
TextureFactory.of(OVERLAY_TOP_ROCK_BREAKER),
TextureFactory.builder()
.addIcon(OVERLAY_TOP_ROCK_BREAKER_GLOW)
.glow()
.build()),
TextureFactory.of(
TextureFactory.of(OVERLAY_FRONT_ROCK_BREAKER_ACTIVE),
TextureFactory.builder()
.addIcon(OVERLAY_FRONT_ROCK_BREAKER_ACTIVE_GLOW)
.glow()
.build()),
TextureFactory.of(
TextureFactory.of(OVERLAY_FRONT_ROCK_BREAKER),
TextureFactory.builder()
.addIcon(OVERLAY_FRONT_ROCK_BREAKER_GLOW)
.glow()
.build()),
TextureFactory.of(
TextureFactory.of(OVERLAY_BOTTOM_ROCK_BREAKER_ACTIVE),
TextureFactory.builder()
.addIcon(OVERLAY_BOTTOM_ROCK_BREAKER_ACTIVE_GLOW)
.glow()
.build()),
TextureFactory.of(
TextureFactory.of(OVERLAY_BOTTOM_ROCK_BREAKER),
TextureFactory.builder()
.addIcon(OVERLAY_BOTTOM_ROCK_BREAKER_GLOW)
.glow()
.build()));
radius = aRadius;
step = aStep;
}
@Override
public String[] getDescription() {
return new String[] { "Place, activate with explosives",
"2 Powderbarrels, " + "4 Glyceryl Trinitrate, " + "16 TNT, or " + "8 ITNT",
"Use Data Stick, Scan Data Stick, Print Data Stick, Bind Pages into Book",
"Ore prospecting area = " + radius * 2 + "x" + radius * 2 + " ONLY blocks below prospector",
"Oil prospecting area 3x3 oilfields, each is 8x8 chunks" };
}
protected MTEAdvSeismicProspector(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures,
int aRadius, int aStep) {
super(aName, aTier, 1, aDescription, aTextures, 1, 1);
radius = aRadius;
step = aStep;
}
@Override
public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
return new MTEAdvSeismicProspector(
this.mName,
this.mTier,
this.mDescriptionArray,
this.mTextures,
this.radius,
this.step);
}
@Override
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
if (aBaseMetaTileEntity.isServerSide()) {
ItemStack aStack = aPlayer.getCurrentEquippedItem();
if (!ready && (GTUtility.consumeItems(aPlayer, aStack, Item.getItemFromBlock(Blocks.tnt), 16)
|| GTUtility.consumeItems(aPlayer, aStack, Ic2Items.industrialTnt.getItem(), 8)
|| GTUtility.consumeItems(aPlayer, aStack, Materials.Glyceryl, 4)
|| GTUtility.consumeItems(aPlayer, aStack, ItemList.Block_Powderbarrel.getItem(), 2))) {
this.ready = true;
this.mMaxProgresstime = (aPlayer.capabilities.isCreativeMode ? 20 : 800);
} else if (ready && mMaxProgresstime == 0
&& aStack != null
&& aStack.stackSize == 1
&& aStack.getItem() == ItemList.Tool_DataStick.getItem()) {
this.ready = false;
// prospecting ores
HashMap<String, Integer> tOres = new HashMap<>(36);
prospectOres(tOres);
// prospecting oils
ArrayList<String> tOils = new ArrayList<>();
prospectOils(tOils);
GTUtility.ItemNBT.setAdvancedProspectionData(
mTier,
aStack,
this.getBaseMetaTileEntity()
.getXCoord(),
this.getBaseMetaTileEntity()
.getYCoord(),
this.getBaseMetaTileEntity()
.getZCoord(),
this.getBaseMetaTileEntity()
.getWorld().provider.dimensionId,
tOils,
GTUtility.sortByValueToList(tOres),
radius);
}
}
return true;
}
private void prospectOils(ArrayList<String> aOils) {
int xChunk = (getBaseMetaTileEntity().getXCoord() >> 7) << 3; // oil field aligned chunk coords
int zChunk = (getBaseMetaTileEntity().getZCoord() >> 7) << 3;
LinkedHashMap<ChunkCoordIntPair, FluidStack> tFluids = new LinkedHashMap<>();
int oilFieldCount = 0;
try {
final int oilfieldSize = 8;
for (int z = -1; z <= 1; ++z) {
for (int x = -1; x <= 1; ++x) {
ChunkCoordIntPair cInts = new ChunkCoordIntPair(x, z);
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
for (int i = 0; i < oilfieldSize; i++) {
for (int j = 0; j < oilfieldSize; j++) {
Chunk tChunk = getBaseMetaTileEntity().getWorld()
.getChunkFromChunkCoords(xChunk + i + x * oilfieldSize, zChunk + j + z * oilfieldSize);
FluidStack tFluid = undergroundOilReadInformation(tChunk);
if (tFluid != null) {
if (tFluid.amount > max) max = tFluid.amount;
if (tFluid.amount < min) min = tFluid.amount;
if (!tFluids.containsKey(cInts)) {
tFluids.put(cInts, tFluid);
}
}
}
}
aOils.add(
++oilFieldCount + ","
+ min
+ "-"
+ max
+ ","
+ tFluids.get(cInts)
.getLocalizedName());
}
}
} catch (Exception ignored) {}
}
private void prospectOres(Map<String, Integer> aOres) {
int tLeftXBound = this.getBaseMetaTileEntity()
.getXCoord() - radius;
int tRightXBound = tLeftXBound + 2 * radius;
int tLeftZBound = this.getBaseMetaTileEntity()
.getZCoord() - radius;
int tRightZBound = tLeftZBound + 2 * radius;
for (int i = tLeftXBound; i <= tRightXBound; i += step) {
if (Math.abs(i >> 4) % 3 != 1) continue;
for (int k = tLeftZBound; k <= tRightZBound; k += step) {
if (Math.abs(k >> 4) % 3 != 1) continue;
cX = (i >> 4) << 4;
cZ = (k >> 4) << 4;
String separator = (cX + 8) + "," + (cZ + 8) + " --------";
aOres.put(separator, 1);
prospectHole(i, k, aOres);
}
}
}
private void prospectHole(int i, int k, Map<String, Integer> aOres) {
String tFoundOre;
for (int j = this.getBaseMetaTileEntity()
.getYCoord(); j > 0; j--) {
tFoundOre = checkForOre(i, j, k);
if (tFoundOre != null) countOre(aOres, tFoundOre, cX, cZ);
}
}
private String checkForOre(int x, int y, int z) {
Block tBlock = this.getBaseMetaTileEntity()
.getBlock(x, y, z);
if (tBlock instanceof BlockOresAbstract) {
TileEntity tTileEntity = getBaseMetaTileEntity().getWorld()
.getTileEntity(x, y, z);
if ((tTileEntity instanceof TileEntityOres) && (((TileEntityOres) tTileEntity).mMetaData < 16000)) { // Filtering
// small
// ores
Materials tMaterial = GregTechAPI.sGeneratedMaterials[((TileEntityOres) tTileEntity).mMetaData % 1000];
if ((tMaterial != null) && (tMaterial != Materials._NULL)) return tMaterial.mDefaultLocalName;
}
} else {
int tMetaID = getBaseMetaTileEntity().getWorld()
.getBlockMetadata(x, y, z);
ItemStack is = new ItemStack(tBlock, 1, tMetaID);
ItemData association = GTOreDictUnificator.getAssociation(is);
if ((association != null) && (association.mPrefix.toString()
.startsWith("ore"))) return association.mMaterial.mMaterial.mDefaultLocalName;
else if (GTUtility.isOre(tBlock, tMetaID)) return tBlock.getLocalizedName();
}
return null;
}
private static void countOre(Map<String, Integer> map, String ore, int cCX, int cCZ) {
ore = (cCX + 8) + "," + (cCZ + 8) + " has " + ore;
Integer oldCount = map.get(ore);
oldCount = (oldCount == null) ? 0 : oldCount;
map.put(ore, oldCount + 1);
}
}
|