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 ;
69import gregtech .api .GregTech_API ;
710import gregtech .api .enums .ItemList ;
811import gregtech .api .enums .Materials ;
3033import net .minecraft .world .ChunkPosition ;
3134import net .minecraft .world .World ;
3235import net .minecraft .world .chunk .Chunk ;
36+ import net .minecraft .world .chunk .IChunkProvider ;
3337import net .minecraftforge .common .util .ForgeDirection ;
3438import net .minecraftforge .fluids .FluidStack ;
3539
3640import java .util .ArrayList ;
41+ import java .util .zip .Inflater ;
3742
3843public 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
0 commit comments