Skip to content

Commit 8bb16e8

Browse files
committed
* Updated logic of adv miner 2
Former-commit-id: 557800c
1 parent 9ed0563 commit 8bb16e8

7 files changed

Lines changed: 196 additions & 58 deletions

File tree

build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
minecraft.version=1.7.10
22
forge.version=10.13.4.1566-1.7.10
33

4-
detravscanner.version=gt.9.29-0.40.0
4+
detravscanner.version=gt.9.29-0.41.0
55

66
ae2.version=rv2-beta-33
77
applecore.version=1.7.10-1.2.1+107.59407

src/main/java/com/detrav/DetravScannerMod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
public class DetravScannerMod
2424
{
2525
public static final String MODID = "detravscannermod";
26-
public static final String VERSION = "0.40";
26+
public static final String VERSION = "0.41";
2727

2828
public static final CreativeTabs TAB_DETRAV = new DetravCreativeTab();
2929

src/main/java/com/detrav/enums/DetravItemList.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public enum DetravItemList implements IItemContainer {
1818
Solar_Boiler_Low,
1919
Solar_Boiler_Medium,
2020
Solar_Boiler_High,
21-
DetravAdvancedMiner2;
21+
DetravAdvancedMiner2,
22+
ConfiguredCircuit;
2223

2324

2425
private ItemStack mStack;

src/main/java/com/detrav/items/DetravMetaGeneratedItem01.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
import com.detrav.enums.Textures01;
99
import gregtech.api.enums.Materials;
1010
import gregtech.api.interfaces.IIconContainer;
11+
import net.minecraft.entity.player.EntityPlayer;
12+
import net.minecraft.item.ItemStack;
13+
import net.minecraft.nbt.NBTTagCompound;
14+
import net.minecraft.util.EnumChatFormatting;
15+
16+
import java.util.List;
1117

1218
/**
1319
* Created by wital_000 on 19.03.2016.
@@ -23,6 +29,7 @@ public DetravMetaGeneratedItem01() {
2329
this.setCreativeTab(DetravScannerMod.TAB_DETRAV);
2430
int tLastID;
2531
DetravItemList.Shape_Extruder_ProPick.set(addItem(tLastID = 0, "Extruder Shape (Prospector's Pick Head)", "Extruder Shape for making Prospector's Picks", new Object[0]));
32+
DetravItemList.ConfiguredCircuit.set(addItem(tLastID = 1, "Configured Circuit", "", new Object[0]));
2633
//DetravItemList.Anvil.set(addItem(tLastID = 1, "Detrav Anvil","",new Object[0]));
2734
//addItemBehavior(tLastID,new BahaviourDetravAnvil());
2835
}
@@ -35,4 +42,52 @@ public final IIconContainer getIconContainer(int aMetaData, Materials aMaterial)
3542
public boolean doesShowInCreative(DetravSimpleItems aPrefix, Materials aMaterial, boolean aDoShowAllItems) {
3643
return aDoShowAllItems || !aPrefix.name().startsWith("toolHead");
3744
}
45+
46+
public boolean isConfiguredCircuit(ItemStack aStack)
47+
{
48+
return aStack.getUnlocalizedName().indexOf("gt.detrav.metaitem.01." + (mOffset+1)) == 0;
49+
}
50+
51+
52+
53+
public void addAdditionalToolTips(List aList, ItemStack aStack, EntityPlayer aPlayer) {
54+
int tOffset = aList.size();
55+
String name = aStack.getUnlocalizedName();
56+
String num = name.substring("gt.detrav.metaitem.01.".length());
57+
int meta = Integer.parseInt(num) - mOffset;
58+
switch (meta) {
59+
case 1: {
60+
NBTTagCompound aNBT = aStack.getTagCompound();
61+
if (aNBT != null) {
62+
NBTTagCompound detravPosition = aNBT.getCompoundTag("DetravPosition");
63+
if (detravPosition != null) {
64+
tOffset = addToList(tOffset, aList, detravPosition, "Finished", false);
65+
tOffset = addToList(tOffset, aList, detravPosition, "Percent", true);
66+
tOffset = addToList(tOffset, aList, detravPosition, "XCurrent", true);
67+
tOffset = addToList(tOffset, aList, detravPosition, "ZCurrent", true);
68+
tOffset = addToList(tOffset, aList, detravPosition, "XFrom", true);
69+
tOffset = addToList(tOffset, aList, detravPosition, "XTo", true);
70+
tOffset = addToList(tOffset, aList, detravPosition, "ZFrom", true);
71+
tOffset = addToList(tOffset, aList, detravPosition, "ZTo", true);
72+
tOffset = addToList(tOffset, aList, detravPosition, "Configurated", false);
73+
}
74+
}
75+
}
76+
break;
77+
}
78+
}
79+
80+
public int addToList(int tOffset, List aList, NBTTagCompound tag,String name, boolean integer) {
81+
if (!tag.hasKey(name))
82+
return tOffset;
83+
if (integer) {
84+
int value = tag.getInteger(name);
85+
aList.add(tOffset, EnumChatFormatting.WHITE + name + " = " + value);
86+
} else {
87+
if (tag.getBoolean(name)) {
88+
aList.add(tOffset, EnumChatFormatting.WHITE + name + EnumChatFormatting.GRAY);
89+
}
90+
}
91+
return tOffset + 1;
92+
}
3893
}

src/main/java/com/detrav/proxies/CommonProxy.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public void onPostLoad() {
6767
GT_ModHandler.addShapelessCraftingRecipe(DetravMetaGeneratedTool01.INSTANCE.getToolWithStats(10,1, Materials.Wood,Materials.Wood, null ),
6868
new Object[]{Ic2Items.treetap,Ic2Items.rubberWood,Ic2Items.resin});
6969

70+
GT_ModHandler.addShapelessCraftingRecipe(ItemList.Circuit_Integrated.get(1), new Object[]{ DetravItemList.ConfiguredCircuit } );
7071
//DetravCraftingEventHandler.register();
7172
DetravEntityDropEvent.register();
7273
DetravLevelUpEvent.register();

src/main/java/com/detrav/tileentities/Detrav_MetaTileEntity_AdvMiner2.java

Lines changed: 136 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
/**
44
* Created by Detrav on 13.12.2016.
55
*/
6+
import com.detrav.enums.DetravItemList;
7+
import com.detrav.items.DetravMetaGeneratedItem01;
8+
import com.detrav.items.DetravMetaGeneratedTool01;
69
import gregtech.api.GregTech_API;
710
import gregtech.api.enums.ItemList;
811
import gregtech.api.enums.Materials;
@@ -30,10 +33,12 @@
3033
import net.minecraft.world.ChunkPosition;
3134
import net.minecraft.world.World;
3235
import net.minecraft.world.chunk.Chunk;
36+
import net.minecraft.world.chunk.IChunkProvider;
3337
import net.minecraftforge.common.util.ForgeDirection;
3438
import net.minecraftforge.fluids.FluidStack;
3539

3640
import java.util.ArrayList;
41+
import java.util.zip.Inflater;
3742

3843
public class Detrav_MetaTileEntity_AdvMiner2 extends GT_MetaTileEntity_MultiBlockBase {
3944

@@ -73,6 +78,8 @@ public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechT
7378
return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "AdvMiner2.png");
7479
}
7580

81+
82+
7683
@Override
7784
public boolean checkRecipe(ItemStack aStack) {
7885

@@ -93,18 +100,23 @@ public boolean checkRecipe(ItemStack aStack) {
93100
depleteInput(tFluid);
94101
long tVoltage = getMaxInputVoltage();
95102

96-
if (getBaseMetaTileEntity().getRandomNumber(10) <= 4) {
103+
if (getBaseMetaTileEntity().getRandomNumber(10) <= 4 &&
104+
DetravMetaGeneratedItem01.INSTANCE.isConfiguredCircuit(mInventory[1])) {
105+
97106
if (mMineList.isEmpty()) {
98107
int x = getXCurrent();
99108
int z = getZCurrent();
100109
World w = getBaseMetaTileEntity().getWorld();
101110
if(w==null) return false;
111+
Chunk c = w.getChunkProvider().provideChunk(x>>4,z>>4);
112+
x = x & 15;
113+
z = z & 15;
102114
for(int yLevel = getBaseMetaTileEntity().getYCoord() - 1; yLevel>1; yLevel --)
103115
{
104-
Block tBlock = w.getBlock(x,yLevel,z);
105-
int tMetaID = w.getBlockMetadata(x,yLevel,z);
116+
Block tBlock = c.getBlock(x,yLevel,z);
117+
int tMetaID = c.getBlockMetadata(x,yLevel,z);
106118
if (tBlock instanceof GT_Block_Ores_Abstract) {
107-
TileEntity tTileEntity = w.getTileEntity(x,yLevel,z);
119+
TileEntity tTileEntity = c.getTileEntityUnsafe(x,yLevel,z);
108120
if ((tTileEntity!=null)
109121
&& (tTileEntity instanceof GT_TileEntity_Ores)
110122
&& ((GT_TileEntity_Ores) tTileEntity).mNatural == true
@@ -209,56 +221,121 @@ public boolean checkRecipe(ItemStack aStack) {
209221
return true;
210222
}
211223

224+
225+
226+
212227
private boolean moveFirst() {
213228
int circuit_config = 1;
214-
if (mInventory[1] == null && !mInventory[1].getUnlocalizedName().startsWith("gt.integrated_circuit")) return false;
229+
if (mInventory[1] == null)
230+
return false;
231+
if (mInventory[1].stackSize > 1) return false;
232+
if (mInventory[1].getUnlocalizedName().startsWith("gt.integrated_circuit")) {
233+
circuit_config = mInventory[1].getItemDamage();
234+
circuit_config *= 2;
235+
circuit_config++;
236+
{
237+
ItemStack aCircuit = mInventory[1];
238+
NBTTagCompound aNBT = aCircuit.getTagCompound();
239+
if (aNBT == null) {
240+
aNBT = new NBTTagCompound();
241+
NBTTagCompound detravPosition = new NBTTagCompound();
242+
aNBT.setTag("DetravPosition", detravPosition);
243+
aCircuit.setTagCompound(aNBT);
244+
}
215245

216-
circuit_config = mInventory[1].getItemDamage();
246+
NBTTagCompound detravPosition = aNBT.getCompoundTag("DetravPosition");
247+
if (detravPosition == null) {
248+
detravPosition = new NBTTagCompound();
249+
aNBT.setTag("DetravPosition", detravPosition);
250+
}
217251

218-
ItemStack aCircuit = mInventory[1];
219-
220-
circuit_config *= 2;
221-
circuit_config++;
222-
//in here if circuit is empty set data to chunk
223-
boolean configurated = false;
252+
int x_from = ((getBaseMetaTileEntity().getXCoord() >> 4) - circuit_config + 1) * 16 - 16 * 3;
253+
int x_to = ((getBaseMetaTileEntity().getXCoord() >> 4) + circuit_config) * 16 + 16 * 3;
254+
int z_from = ((getBaseMetaTileEntity().getZCoord() >> 4) - circuit_config + 1) * 16 - 16 * 3;
255+
int z_to = ((getBaseMetaTileEntity().getZCoord() >> 4) + circuit_config) * 16 + 16 * 3;
224256

225-
NBTTagCompound aNBT = aCircuit.getTagCompound();
226-
if(aNBT == null) {
227-
aNBT = new NBTTagCompound();
228-
NBTTagCompound detravPosition = new NBTTagCompound();
229-
aNBT.setTag("DetravPosition", detravPosition);
230-
aCircuit.setTagCompound(aNBT);
231-
}
232-
233-
NBTTagCompound detravPosition = aNBT.getCompoundTag("DetravPosition");
234-
if (detravPosition == null ) {
235-
detravPosition = new NBTTagCompound();
236-
aNBT.setTag("DetravPosition", detravPosition);
257+
int x_current = x_from;
258+
int z_current = z_from;
259+
260+
if(!detravPosition.hasKey("Configured")) {
261+
detravPosition.setBoolean("Configured", true);
262+
detravPosition.setInteger("XCurrent",x_current);
263+
detravPosition.setInteger("ZCurrent",z_current);
264+
}
265+
else
266+
{
267+
if(detravPosition.hasKey("XCurrent"))
268+
x_current = detravPosition.getInteger("XCurrent");
269+
if(detravPosition.hasKey("ZCurrent"))
270+
z_current = detravPosition.getInteger("ZCurrent");
271+
}
272+
273+
World aWorld = getBaseMetaTileEntity().getWorld();
274+
IChunkProvider provider = aWorld.getChunkProvider();
275+
for (int i = x_current; i <= x_to; i += 16)
276+
for (int j = z_current; j <= z_to; j += 16) {
277+
if (!provider.provideChunk(i >> 4, j >> 4).isTerrainPopulated) {
278+
provider.populate(provider, (i >> 4), (j >> 4) );
279+
detravPosition.setInteger("XCurrent",i);
280+
detravPosition.setInteger("ZCurrent",j);
281+
return true;
282+
}
283+
}
284+
285+
}
286+
{
287+
mInventory[1] = DetravItemList.ConfiguredCircuit.get(1);
288+
ItemStack aCircuit = mInventory[1];
289+
290+
//in here if circuit is empty set data to chunk
291+
292+
293+
NBTTagCompound aNBT = aCircuit.getTagCompound();
294+
if (aNBT == null) {
295+
aNBT = new NBTTagCompound();
296+
NBTTagCompound detravPosition = new NBTTagCompound();
297+
aNBT.setTag("DetravPosition", detravPosition);
298+
aCircuit.setTagCompound(aNBT);
299+
}
300+
301+
NBTTagCompound detravPosition = aNBT.getCompoundTag("DetravPosition");
302+
if (detravPosition == null) {
303+
detravPosition = new NBTTagCompound();
304+
aNBT.setTag("DetravPosition", detravPosition);
305+
}
306+
307+
308+
int x_from = ((getBaseMetaTileEntity().getXCoord() >> 4) - circuit_config + 1) * 16;
309+
int x_to = ((getBaseMetaTileEntity().getXCoord() >> 4) + circuit_config) * 16;
310+
int x_current = x_from;
311+
int z_from = ((getBaseMetaTileEntity().getZCoord() >> 4) - circuit_config + 1) * 16;
312+
int z_to = ((getBaseMetaTileEntity().getZCoord() >> 4) + circuit_config) * 16;
313+
int z_current = z_from;
314+
315+
detravPosition.setInteger("XFrom", x_from);
316+
detravPosition.setInteger("XTo", x_to);
317+
detravPosition.setInteger("XCurrent", x_current);
318+
detravPosition.setInteger("ZFrom", z_from);
319+
detravPosition.setInteger("ZTo", z_to);
320+
detravPosition.setInteger("ZCurrent", z_current);
321+
322+
}
237323
}
238-
configurated = detravPosition.hasKey("Configurated") && detravPosition.getBoolean("Configurated");
239-
240-
if(!configurated)
241-
{
242-
configurated = true;
243-
int x_from = ((getBaseMetaTileEntity().getXCoord() >> 4) - circuit_config+1) * 16;
244-
int x_to = ((getBaseMetaTileEntity().getXCoord() >> 4) + circuit_config) * 16;
245-
int x_current = x_from;
246-
int z_from = ((getBaseMetaTileEntity().getZCoord() >> 4) - circuit_config+1) * 16;
247-
int z_to = ((getBaseMetaTileEntity().getZCoord() >> 4) + circuit_config) * 16;
248-
int z_current = z_from;
249-
250-
detravPosition.setInteger("XFrom",x_from);
251-
detravPosition.setInteger("XTo",x_to);
252-
detravPosition.setInteger("XCurrent",x_current);
253-
detravPosition.setInteger("ZFrom",z_from);
254-
detravPosition.setInteger("ZTo",z_to);
255-
detravPosition.setInteger("ZCurrent",z_current);
256-
257-
detravPosition.setBoolean("Configurated",configurated);
324+
if (DetravMetaGeneratedItem01.INSTANCE.isConfiguredCircuit(mInventory[1])) {
325+
NBTTagCompound aNBT = mInventory[1].getTagCompound();
326+
if (aNBT == null) {
327+
return false;
328+
}
329+
330+
NBTTagCompound detravPosition = aNBT.getCompoundTag("DetravPosition");
331+
if (detravPosition == null) {
332+
return false;
333+
}
334+
if (detravPosition.hasKey("Finished"))
335+
return !detravPosition.getBoolean("Finished");
336+
return true;
258337
}
259-
if(detravPosition.hasKey("Finished"))
260-
configurated = !detravPosition.getBoolean("Finished");
261-
return configurated;
338+
return false;
262339
}
263340

264341
private int getXCurrent()
@@ -317,20 +394,24 @@ private boolean moveNext() {
317394

318395
if(z_current < z_to)
319396
z_current++;
320-
else
321-
{
322-
if(x_current < x_to)
323-
{
397+
else {
398+
if (x_current < x_to) {
324399
z_current = z_from;
325400
x_current++;
326-
}
327-
else
328-
{
329-
detravPosition.setBoolean("Finished",true);
401+
} else {
402+
detravPosition.setBoolean("Finished", true);
403+
if (detravPosition.hasKey("Percent"))
404+
detravPosition.removeTag("Percent");
330405
return false;
331406
}
332407
}
333408

409+
detravPosition.setInteger("Percent", (int)(
410+
((float)(z_current - z_from + (x_current - x_from) * (z_to - z_from )))
411+
* 100f
412+
/((float)( (x_to - x_from + 1 )*(z_to-z_from)))));
413+
414+
334415
detravPosition.setInteger("XCurrent",x_current);
335416
detravPosition.setInteger("ZCurrent",z_current);
336417

318 Bytes
Loading

0 commit comments

Comments
 (0)