diff options
author | Draknyte1 <Draknyte1@hotmail.com> | 2017-01-05 16:45:55 +1000 |
---|---|---|
committer | Draknyte1 <Draknyte1@hotmail.com> | 2017-01-05 16:45:55 +1000 |
commit | d5f700a2279ee19386609663c40471daf69d5fbb (patch) | |
tree | cffad2d2cfe557f3a3cea0830ac3b6b2665b58f9 /src/Java/gtPlusPlus/xmod/gregtech/common/tileentities | |
parent | e21a733f3a4ab0eba98830d4244dd7ac7b138ff9 (diff) | |
download | GT5-Unofficial-d5f700a2279ee19386609663c40471daf69d5fbb.tar.gz GT5-Unofficial-d5f700a2279ee19386609663c40471daf69d5fbb.tar.bz2 GT5-Unofficial-d5f700a2279ee19386609663c40471daf69d5fbb.zip |
+ Added a casing for the perimeter of the Tree Farmer structure.
$ Improved the structure formation of the Tree Farmer, it now works better when built.
+ Added a new texture for the Farm manager blocks, which surround the Tree Farming structure.
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech/common/tileentities')
-rw-r--r-- | src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntityTreeFarm.java | 337 |
1 files changed, 148 insertions, 189 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntityTreeFarm.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntityTreeFarm.java index f26b654df8..8edf2b4c2d 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntityTreeFarm.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntityTreeFarm.java @@ -3,9 +3,11 @@ package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi; import gregtech.api.GregTech_API; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Recipe; @@ -14,13 +16,13 @@ import gtPlusPlus.core.util.Utils; import gtPlusPlus.xmod.forestry.trees.TreefarmManager; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import java.lang.reflect.Field; import java.util.ArrayList; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; -import net.minecraft.world.ChunkPosition; public class GregtechMetaTileEntityTreeFarm extends GT_MetaTileEntity_MultiBlockBase { @@ -30,6 +32,8 @@ public class GregtechMetaTileEntityTreeFarm extends GT_MetaTileEntity_MultiBlock private static final ITexture[] FACING_ACTIVE = {new GT_RenderedTexture(Textures.BlockIcons.MACHINE_BRONZEBLASTFURNACE_ACTIVE)}; + public ArrayList<GT_MetaTileEntity_TieredMachineBlock> mCasings = new ArrayList(); + private boolean running = false; private boolean p1, p2, p3, p4, p5, p6; public int mMaxProgresstime = 0; @@ -120,7 +124,7 @@ public class GregtechMetaTileEntityTreeFarm extends GT_MetaTileEntity_MultiBlock @Override public boolean checkRecipe(ItemStack aStack) { Utils.LOG_INFO("Working"); - if (!checkRecursiveBlocks()) { + /*if (!checkRecursiveBlocks()) { this.mEfficiency = 0; this.mEfficiencyIncrease = 0; this.mMaxProgresstime = 0; @@ -134,189 +138,25 @@ public class GregtechMetaTileEntityTreeFarm extends GT_MetaTileEntity_MultiBlock this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); //GT_Pollution.addPollution(new ChunkPosition(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getYCoord(), this.getBaseMetaTileEntity().getZCoord()), mMaxProgresstime*5); return true; - } + }*/ this.mEfficiency = 0; this.mEfficiencyIncrease = 0; this.mMaxProgresstime = 0; return false; } - private boolean checkRecursiveBlocks() { - ArrayList<ChunkPosition> tList1 = new ArrayList<ChunkPosition>(); - ArrayList<ChunkPosition> tList2 = new ArrayList<ChunkPosition>(); - - Block tBlock = this.getBaseMetaTileEntity().getBlockOffset(0, +1, 0); - Utils.LOG_INFO("Looking for air above the controller."); - if (!TreefarmManager.isAirBlock(tBlock)) { - Utils.LOG_INFO("Did not find air above the controller."); - return false; - } else { - Utils.LOG_INFO("Adding spot to a list?"); - tList2.add(new ChunkPosition(0, 0, 0)); - } - while (!tList2.isEmpty()) { - ChunkPosition tPos = (ChunkPosition) 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 (TreefarmManager.isWoodLog(this.getBaseMetaTileEntity().getBlockOffset(tPos.chunkPosX, tPos.chunkPosY, tPos.chunkPosZ))){ - //This does the block change to brittle charcoal. - //this.getBaseMetaTileEntity().getWorld().setBlock(this.getBaseMetaTileEntity().getXCoord() + tPos.chunkPosX, this.getBaseMetaTileEntity().getYCoord() + tPos.chunkPosY, this.getBaseMetaTileEntity().getZCoord() + tPos.chunkPosZ, GregTech_API.sBlockConcretes, 4, 3); - - } - } - running = false; - return false; - } else { - this.mMaxProgresstime = (int) Math.sqrt(tList1.size() * 240000); - } - running = true; - return true; - } - - private boolean checkAllBlockSides(int aX, int aY, int aZ, ArrayList<ChunkPosition> aList1, ArrayList<ChunkPosition> aList2) { - p1 = false; - p2 = false; - p3 = false; - p4 = false; - p5 = false; - p6 = false; - Utils.LOG_INFO("checkAllBlockSides"); - - Utils.LOG_INFO("Testing Side 1"); - Block tBlock = this.getBaseMetaTileEntity().getBlockOffset(aX + 1, aY, aZ); - if (aX + 1 < 6 && (TreefarmManager.isDirtBlock(tBlock))) { - if (!aList1.contains(new ChunkPosition(aX + 1, aY, aZ)) && (!aList2.contains(new ChunkPosition(aX + 1, aY, aZ)))){ - p1 = true; - Utils.LOG_INFO("set p1 true"); - } - } else if (!(tBlock == Blocks.dirt || tBlock == Blocks.grass)) { - Utils.LOG_INFO("1- Looking for Dirt at X:"+(aX+1)+" Y:"+aY+" Z:"+aZ+" but instead found "+tBlock.getLocalizedName()); - return false; - } - - Utils.LOG_INFO("Testing Side 2"); - tBlock = this.getBaseMetaTileEntity().getBlockOffset(aX - 1, aY, aZ); - if (aX - 1 > -6 && (TreefarmManager.isDirtBlock(tBlock))) { - if (!aList1.contains(new ChunkPosition(aX - 1, aY, aZ)) && (!aList2.contains(new ChunkPosition(aX - 1, aY, aZ)))){ - p2 = true; - Utils.LOG_INFO("set p2 true"); - } - } else if (!(tBlock == Blocks.dirt || tBlock == Blocks.grass)) { - Utils.LOG_INFO("2- Looking for Dirt at X:"+(aX-1)+" Y:"+aY+" Z:"+aZ+" but instead found "+tBlock.getLocalizedName()); - return false; - } - - Utils.LOG_INFO("Testing For Fence X+1"); - tBlock = this.getBaseMetaTileEntity().getBlockOffset(aX+1, aY+1, aZ); - if ((aY+1) == 1 && (TreefarmManager.isFenceBlock(tBlock))) { - if (!aList1.contains(new ChunkPosition(aX+1, aY+1, aZ)) && (!aList2.contains(new ChunkPosition(aX+1, aY+1, aZ)))){ - //p3 = true; - Utils.LOG_INFO("set p3 true"); - } - } else if (!(TreefarmManager.isFenceBlock(tBlock)) || !this.getBaseMetaTileEntity().getAirOffset(aX+1, aY+1, aZ)) { - Utils.LOG_INFO("3- Looking for Fence at X:"+(aX+1)+" Y:"+(aY+1)+" Z:"+aZ+" but instead found "+tBlock.getLocalizedName()); - return false; - } - Utils.LOG_INFO("Testing For Fence X-1"); - tBlock = this.getBaseMetaTileEntity().getBlockOffset(aX-1, aY+1, aZ); - if ((aY+1) == 1 && (TreefarmManager.isFenceBlock(tBlock))) { - if (!aList1.contains(new ChunkPosition(aX-1, aY+1, aZ)) && (!aList2.contains(new ChunkPosition(aX-1, aY+1, aZ)))){ - //p3 = true; - Utils.LOG_INFO("set p3 true"); - } - } else if (!(TreefarmManager.isFenceBlock(tBlock)) || !this.getBaseMetaTileEntity().getAirOffset(aX-1, aY+1, aZ)) { - Utils.LOG_INFO("3- Looking for Fence at X:"+(aX-1)+" Y:"+(aY+1)+" Z:"+aZ+" but instead found "+tBlock.getLocalizedName()); - return false; - } - Utils.LOG_INFO("Testing For Fence Z+1"); - tBlock = this.getBaseMetaTileEntity().getBlockOffset(aX, aY+1, aZ+1); - if ((aY+1) == 1 && (TreefarmManager.isFenceBlock(tBlock))) { - if (!aList1.contains(new ChunkPosition(aX, aY+1, aZ+1)) && (!aList2.contains(new ChunkPosition(aX, aY+1, aZ+1)))){ - //p3 = true; - Utils.LOG_INFO("set p3 true"); - } - } else if (!(TreefarmManager.isFenceBlock(tBlock)) || !this.getBaseMetaTileEntity().getAirOffset(aX, aY+1, aZ+1)) { - Utils.LOG_INFO("3- Looking for Fence at X:"+(aX)+" Y:"+(aY+1)+" Z:"+(aZ+1)+" but instead found "+tBlock.getLocalizedName()); - return false; - } - Utils.LOG_INFO("Testing For Fence Z-1"); - tBlock = this.getBaseMetaTileEntity().getBlockOffset(aX, aY+1, aZ-1); - if ((aY+1) == 1 && (TreefarmManager.isFenceBlock(tBlock))) { - if (!aList1.contains(new ChunkPosition(aX, aY+1, aZ-1)) && (!aList2.contains(new ChunkPosition(aX, aY+1, aZ-1)))){ - //p3 = true; - Utils.LOG_INFO("set p3 true"); - } - } else if (!(TreefarmManager.isFenceBlock(tBlock)) || !this.getBaseMetaTileEntity().getAirOffset(aX, aY+1, aZ-1)) { - Utils.LOG_INFO("3- Looking for Fence at X:"+(aX)+" Y:"+(aY+1)+" Z:"+(aZ-1)+" but instead found "+tBlock.getLocalizedName()); - return false; - } - - /*Utils.LOG_INFO("Testing Side 4"); - tBlock = this.getBaseMetaTileEntity().getBlockOffset(aX, aY - 1, aZ); - if (aY - 1 > -6 && (isDirtBlock(tBlock))) { - if (!aList1.contains(new ChunkPosition(aX, aY - 1, aZ)) && (!aList2.contains(new ChunkPosition(aX, aY - 1, aZ)))){ - p4 = true; - Utils.LOG_INFO("set p4 true"); - } - } else if (tBlock != GregTech_API.sBlockCasings1) { //The Base Layer Check - Utils.LOG_INFO("Bottom Layer is not Machine Casings HV"); - return false; - } - else if (this.getBaseMetaTileEntity().getMetaIDOffset(aX, aY - 1, aZ) != 3) { - Utils.LOG_INFO("Bottom Layer has wrong meta, expecting 3. Got "+this.getBaseMetaTileEntity().getMetaIDOffset(aX, aY - 1, aZ)); - return false; - }*/ - - Utils.LOG_INFO("Testing Side 5"); - tBlock = this.getBaseMetaTileEntity().getBlockOffset(aX, aY, aZ + 1); - if (aZ + 1 < 6 && (TreefarmManager.isDirtBlock(tBlock))) { - if (!aList1.contains(new ChunkPosition(aX, aY, aZ + 1)) && (!aList2.contains(new ChunkPosition(aX, aY, aZ + 1)))){ - p5 = true; - Utils.LOG_INFO("set p5 true"); - } - } else if (!(tBlock == Blocks.dirt || tBlock == Blocks.grass)) { - Utils.LOG_INFO("Looking for Dirt at X:"+(aX)+" Y:"+aY+" Z:"+(aZ+1)+" but instead found "+tBlock.getLocalizedName()); - return false; - } - - Utils.LOG_INFO("Testing Side 6"); - tBlock = this.getBaseMetaTileEntity().getBlockOffset(aX, aY, aZ - 1); - if (aZ - 1 > -6 && (TreefarmManager.isDirtBlock(tBlock))) { - if (!aList1.contains(new ChunkPosition(aX, aY, aZ - 1)) && (!aList2.contains(new ChunkPosition(aX, aY, aZ - 1)))){ - p6 = true; - Utils.LOG_INFO("set p6 true"); - } - } else if (!(tBlock == Blocks.dirt || tBlock == Blocks.grass)) { - Utils.LOG_INFO("Looking for Dirt at X:"+(aX)+" Y:"+aY+" Z:"+(aZ-1)+" but instead found "+tBlock.getLocalizedName()); - return false; - } - aList1.add(new ChunkPosition(aX, aY, aZ)); - if (p1) aList2.add(new ChunkPosition(aX + 1, aY, aZ)); - if (p2) aList2.add(new ChunkPosition(aX - 1, aY, aZ)); - if (p3) aList2.add(new ChunkPosition(aX, aY, aZ)); - if (p4) aList2.add(new ChunkPosition(aX, aY - 1, aZ)); - if (p5) aList2.add(new ChunkPosition(aX, aY, aZ + 1)); - if (p6) aList2.add(new ChunkPosition(aX, aY, aZ - 1)); - return true; - } - - private Block getHumus(){ - if (!LoadedMods.Forestry){ - return null; - } - return TreefarmManager.getHumus(); + if (!LoadedMods.Forestry){ + return null; + } + return TreefarmManager.getHumus(); } @Override public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + this.mCasings.clear(); Utils.LOG_INFO("Step 1"); int xDir = net.minecraftforge.common.util.ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * 7; int zDir = net.minecraftforge.common.util.ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * 7; @@ -327,7 +167,7 @@ public class GregtechMetaTileEntityTreeFarm extends GT_MetaTileEntity_MultiBlock Utils.LOG_INFO("Step 3"); for (int h = 0; h <= 1; h++) { Utils.LOG_INFO("Step 4"); - + IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, h, zDir + j); //Farm Floor inner 14x14 @@ -337,15 +177,15 @@ public class GregtechMetaTileEntityTreeFarm extends GT_MetaTileEntity_MultiBlock if (h == 0) { //Dirt Floor if (!TreefarmManager.isDirtBlock(aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j))) { - Utils.LOG_INFO("Dirt like block missing from inner 14x14."); - Utils.LOG_INFO("Instead, found "+aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j).getLocalizedName()); - aBaseMetaTileEntity.getWorld().setBlock( - (aBaseMetaTileEntity.getXCoord()+(xDir+i)), - (aBaseMetaTileEntity.getYCoord()+(h)), - (aBaseMetaTileEntity.getZCoord()+(zDir+j)), - Blocks.melon_block); - return false; - } + Utils.LOG_INFO("Dirt like block missing from inner 14x14."); + Utils.LOG_INFO("Instead, found "+aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j).getLocalizedName()); + aBaseMetaTileEntity.getWorld().setBlock( + (aBaseMetaTileEntity.getXCoord()+(xDir+i)), + (aBaseMetaTileEntity.getYCoord()+(h)), + (aBaseMetaTileEntity.getZCoord()+(zDir+j)), + Blocks.melon_block); + return false; + } } // Inside fenced area, mostly air or trees or saplings else if (h == 1){ @@ -372,18 +212,25 @@ public class GregtechMetaTileEntityTreeFarm extends GT_MetaTileEntity_MultiBlock } //Deal with Bottom edges (Add Hatches/Busses first, othercheck make sure it's dirt) //TODO change the casings to not dirt~ else if (h == 0) { - if ((!addMaintenanceToMachineList(tTileEntity, 70)) && (!addInputToMachineList(tTileEntity, 70)) && (!addOutputToMachineList(tTileEntity, 70)) && (!addDynamoToMachineList(tTileEntity, 70))) { - if ((xDir + i != 0) || (zDir + j != 0)) {//no controller - if (!TreefarmManager.isDirtBlock(aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j))) { - Utils.LOG_INFO("Dirt missing from Edge."); + + try { + addCasingToCasingList(tTileEntity); + } catch (Throwable t){} + + if ((!addMaintenanceToMachineList(tTileEntity, 70)) && (!addInputToMachineList(tTileEntity, 70)) && (!addOutputToMachineList(tTileEntity, 70)) && (!addEnergyInputToMachineList(tTileEntity, 70))) { + if ((xDir + i != 0) || (zDir + j != 0)) {//no controller + + if (!(aBaseMetaTileEntity.getMetaTileID() != 752)) { + Utils.LOG_INFO("Fark Keeper Casings Missing from one of the edges on the bottom edge. x:"+(xDir+i)+" y:"+h+" z:"+(zDir+j)+" | "+aBaseMetaTileEntity.getClass()); Utils.LOG_INFO("Instead, found "+aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j).getLocalizedName()); return false; - } + } + Utils.LOG_INFO("Found a farm keeper."); } } } Utils.LOG_INFO("Step a"); - + } Utils.LOG_INFO("Step b"); } @@ -406,7 +253,7 @@ public class GregtechMetaTileEntityTreeFarm extends GT_MetaTileEntity_MultiBlock //Must have at least one output hatch. if (this.mOutputHatches != null) { for (int i = 0; i < this.mOutputHatches.size(); i++) { - + if (this.mOutputHatches.get(i).mTier < 2 && (this.mOutputHatches.get(i).getBaseMetaTileEntity() instanceof GregtechMTE_NuclearReactor)){ Utils.LOG_INFO("You require at LEAST MV tier Output Hatches."); Utils.LOG_INFO(this.mOutputHatches.get(i).getBaseMetaTileEntity().getXCoord()+","+this.mOutputHatches.get(i).getBaseMetaTileEntity().getYCoord()+","+this.mOutputHatches.get(i).getBaseMetaTileEntity().getZCoord()); @@ -427,6 +274,7 @@ public class GregtechMetaTileEntityTreeFarm extends GT_MetaTileEntity_MultiBlock } } mSolderingTool = true; + turnCasingActive(true); Utils.LOG_INFO("Multiblock Formed."); return true; } @@ -456,4 +304,115 @@ public class GregtechMetaTileEntityTreeFarm extends GT_MetaTileEntity_MultiBlock return false; } + public boolean addCasingToCasingList(IGregTechTileEntity aTileEntity) { + if (aTileEntity == null) + return false; + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) + return false; + if (aMetaTileEntity instanceof GT_MetaTileEntity_TieredMachineBlock) { + return this.mCasings.add((GT_MetaTileEntity_TieredMachineBlock) aMetaTileEntity); + } + return false; + } + + public boolean turnCasingActive(boolean status) { + if (this.mCasings != null) { + Utils.LOG_INFO("Changing casing Textures."); + for (GT_MetaTileEntity_TieredMachineBlock hatch : this.mCasings) { + hatch = changeTextureswithReflection(hatch, getTextureSet()); + } + } + return true; + } + + private GT_MetaTileEntity_TieredMachineBlock changeTextureswithReflection(GT_MetaTileEntity_TieredMachineBlock casing, ITexture[][][] textureSet){ + GT_MetaTileEntity_TieredMachineBlock cv = casing; + System.out.println("Before: "+cv.mTextures.hashCode()); + //Get declared field from class + Field f; + try { + Field[] x = cv.getClass().getFields(); + for (int i =0; i<x.length;i++){ + //Utils.LOG_INFO(x[i].getName()); + } + try { + //Try get the field variable + f = cv.getClass().getField("mTextures"); + // set the accessiblity of the field to true, this will enable you to change the value + f.setAccessible(true); + //change the field value + f.set(cv, textureSet); + //Verify change in texture set + System.out.println("After: "+cv.mTextures.hashCode()); + return cv; + } catch (NoSuchFieldException e) { + Utils.LOG_INFO("Could not find mTextures."); + return casing; + } + } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { + // TODO Auto-generated catch block + //e.printStackTrace(); + return casing; + } + } + + + public ITexture[][][] getTextureSet() { + ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = getFront(i); + rTextures[1][i + 1] = getBack(i); + rTextures[2][i + 1] = getBottom(i); + rTextures[3][i + 1] = getTop(i); + rTextures[4][i + 1] = getSides(i); + rTextures[5][i + 1] = getFrontActive(i); + rTextures[6][i + 1] = getBackActive(i); + rTextures[7][i + 1] = getBottomActive(i); + rTextures[8][i + 1] = getTopActive(i); + rTextures[9][i + 1] = getSidesActive(i); + } + return rTextures; + } + + public ITexture[] getFront(byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[2][aColor + 1]}; + } + + public ITexture[] getBack(byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[2][aColor + 1]}; + } + + public ITexture[] getBottom(byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[2][aColor + 1]}; + } + + public ITexture[] getTop(byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[2][aColor + 1]}; + } + + public ITexture[] getSides(byte aColor) { + return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[2][aColor + 1]}; + } + + public ITexture[] getFrontActive(byte aColor) { + return getFront(aColor); + } + + public ITexture[] getBackActive(byte aColor) { + return getBack(aColor); + } + + public ITexture[] getBottomActive(byte aColor) { + return getBottom(aColor); + } + + public ITexture[] getTopActive(byte aColor) { + return getTop(aColor); + } + + public ITexture[] getSidesActive(byte aColor) { + return getSides(aColor); + } + }
\ No newline at end of file |