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
|
package gregtech.common.tileentities.machines.multi;
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.casingTexturePages;
import static gregtech.api.objects.XSTR.XSTR_INSTANCE;
import java.util.ArrayList;
import javax.annotation.Nonnull;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.ChunkPosition;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.oredict.OreDictionary;
import gregtech.GTMod;
import gregtech.api.GregTechAPI;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.enums.ParticleFX;
import gregtech.api.interfaces.ISecondaryDescribable;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.MTETooltipMultiBlockBase;
import gregtech.api.recipe.RecipeMap;
import gregtech.api.recipe.check.CheckRecipeResult;
import gregtech.api.recipe.check.CheckRecipeResultRegistry;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.MultiblockTooltipBuilder;
import gregtech.api.util.WorldSpawnedEventBuilder;
import gregtech.common.Pollution;
public class MTECharcoalPit extends MTETooltipMultiBlockBase implements ISecondaryDescribable {
private boolean running = false;
public MTECharcoalPit(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional);
}
public MTECharcoalPit(String aName) {
super(aName);
}
@Override
public boolean isFacingValid(ForgeDirection facing) {
return (facing.flag & (ForgeDirection.UP.flag | ForgeDirection.DOWN.flag)) == 0;
}
@Override
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
// No GUI, do not capture right-click so it does not interfere when placing logs
return false;
}
@Override
public boolean isCorrectMachinePart(ItemStack aStack) {
return true;
}
@Nonnull
@Override
public CheckRecipeResult checkProcessing() {
if (!checkRecursiveBlocks()) {
mEfficiency = 0;
mEfficiencyIncrease = 0;
mMaxProgresstime = 0;
running = false;
return CheckRecipeResultRegistry.NO_RECIPE;
}
if (mEfficiency == 0) {
mEfficiency = 10000;
mEfficiencyIncrease = 10000;
mMaxProgresstime = Math.max(1, mMaxProgresstime);
// adds all the pollution at once when the recipe starts
Pollution.addPollution(getBaseMetaTileEntity(), mMaxProgresstime * getPollutionPerTick(null));
return CheckRecipeResultRegistry.SUCCESSFUL;
} else {
mEfficiency = 0;
mEfficiencyIncrease = 0;
mMaxProgresstime = 0;
return CheckRecipeResultRegistry.NO_RECIPE;
}
}
private boolean checkRecursiveBlocks() {
ArrayList<ChunkPosition> tList1 = new ArrayList<>();
ArrayList<ChunkPosition> tList2 = new ArrayList<>();
Block tBlock = getBaseMetaTileEntity().getBlockOffset(0, -1, 0);
if (isWoodLog(tBlock, getBaseMetaTileEntity().getMetaIDOffset(0, -1, 0))) {
tList2.add(new ChunkPosition(0, -1, 0));
} else return false;
while (!tList2.isEmpty()) {
ChunkPosition tPos = tList2.get(0);
tList2.remove(0);
if (!checkAllBlockSides(tPos.chunkPosX, tPos.chunkPosY, tPos.chunkPosZ, tList1, tList2)) {
return false;
}
}
if (running) {
for (ChunkPosition tPos : tList1) {
if (isWoodLog(
getBaseMetaTileEntity().getBlockOffset(tPos.chunkPosX, tPos.chunkPosY, tPos.chunkPosZ),
getBaseMetaTileEntity().getMetaIDOffset(tPos.chunkPosX, tPos.chunkPosY, tPos.chunkPosZ)))
getBaseMetaTileEntity().getWorld()
.setBlock(
getBaseMetaTileEntity().getXCoord() + tPos.chunkPosX,
getBaseMetaTileEntity().getYCoord() + tPos.chunkPosY,
getBaseMetaTileEntity().getZCoord() + tPos.chunkPosZ,
GregTechAPI.sBlockReinforced,
4,
3);
}
running = false;
return false;
} else {
mMaxProgresstime = (int) Math.sqrt(tList1.size() * 240000);
}
running = true;
return true;
}
private boolean isWoodLog(Block log, int meta) {
for (int id : OreDictionary.getOreIDs(new ItemStack(log, 1, meta))) {
if (OreDictionary.getOreName(id)
.equals("logWood")) return true;
}
String tTool = log.getHarvestTool(meta);
return OrePrefixes.log.contains(new ItemStack(log, 1, meta)) && ("axe".equals(tTool))
&& (log.getMaterial() == Material.wood);
}
private boolean checkAllBlockSides(int aX, int aY, int aZ, ArrayList<? super ChunkPosition> aList1,
ArrayList<? super ChunkPosition> aList2) {
boolean expandToChunkXPos = false;
boolean expandToChunkXNeg = false;
boolean expandToChunkYPos = false;
boolean expandToChunkYNeg = false;
boolean expandToChunkZPos = false;
boolean expandToChunkZNeg = false;
Block blockXPos = getBaseMetaTileEntity().getBlockOffset(aX + 1, aY, aZ);
if (aX + 1 < 6 && (isWoodLog(blockXPos, getBaseMetaTileEntity().getMetaIDOffset(aX + 1, aY, aZ)))) {
if (!aList1.contains(new ChunkPosition(aX + 1, aY, aZ))
&& (!aList2.contains(new ChunkPosition(aX + 1, aY, aZ)))) expandToChunkXPos = true;
} else if (!(blockXPos == Blocks.dirt || blockXPos == Blocks.grass)) {
return false;
}
Block blockXNeg = getBaseMetaTileEntity().getBlockOffset(aX - 1, aY, aZ);
if (aX - 1 > -6 && (isWoodLog(blockXNeg, getBaseMetaTileEntity().getMetaIDOffset(aX - 1, aY, aZ)))) {
if (!aList1.contains(new ChunkPosition(aX - 1, aY, aZ))
&& (!aList2.contains(new ChunkPosition(aX - 1, aY, aZ)))) expandToChunkXNeg = true;
} else if (!(blockXNeg == Blocks.dirt || blockXNeg == Blocks.grass)) {
return false;
}
Block blockYPos = getBaseMetaTileEntity().getBlockOffset(aX, aY + 1, aZ);
if (aY + 1 < 1 && (isWoodLog(blockYPos, getBaseMetaTileEntity().getMetaIDOffset(aX, aY + 1, aZ)))) {
if (!aList1.contains(new ChunkPosition(aX, aY + 1, aZ))
&& (!aList2.contains(new ChunkPosition(aX, aY + 1, aZ)))) expandToChunkYPos = true;
} else if (!(blockYPos == Blocks.dirt || blockYPos == Blocks.grass
|| (aX == 0 && aY == -1 && aZ == 0 && blockYPos == GregTechAPI.sBlockMachines))) {
return false;
}
Block blockYNeg = getBaseMetaTileEntity().getBlockOffset(aX, aY - 1, aZ);
if (aY - 1 > -6 && (isWoodLog(blockYNeg, getBaseMetaTileEntity().getMetaIDOffset(aX,
|