diff options
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech/api')
3 files changed, 455 insertions, 247 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java index 8bcaf0b2ec..26ac0dd4b2 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java @@ -49,6 +49,7 @@ import gtPlusPlus.xmod.gregtech.api.gui.GUI_Multi_Basic_Slotted; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_ControlCore; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBattery; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_OutputBattery; +import gtPlusPlus.xmod.gregtech.api.objects.MultiblockRequirements; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IInventory; @@ -81,6 +82,7 @@ GT_MetaTileEntity_MultiBlockBase { private static final Method findRecipe09; public GT_Recipe mLastRecipe; + private MultiblockRequirements mRequirements; private boolean mInternalCircuit = false; protected long mTotalRunTime = 0; @@ -233,6 +235,17 @@ GT_MetaTileEntity_MultiBlockBase { public abstract String[] getTooltip(); + public synchronized final MultiblockRequirements getRequirements() { + return mRequirements; + } + + //public abstract MultiblockRequirements setRequirements(); + + public synchronized final void setRequirementsInternal() { + //this.mRequirements = setRequirements(); + this.mRequirements = null; + } + public int getAmountOfOutputs() { return 1; } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockBlueprint.java b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockBlueprint.java index cb6d2faabf..7af6af2ffd 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockBlueprint.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockBlueprint.java @@ -15,13 +15,24 @@ import net.minecraftforge.common.util.ForgeDirection; public abstract class MultiblockBlueprint { private final MultiblockLayer[] mBlueprintData; - + public final int height; public final int width; public final int depth; public final int mMinimumCasingCount; public final int mTextureID; - + + /** + * Cached Matrix of the Multiblock, which makes future structural checks far quicker. + */ + private final BlockPos[][][] StructureMatrix; + + /** + * Has {@value StructureMatrix} been set yet? + */ + @SuppressWarnings("unused") + private boolean mGeneratedMatrix = false; + /** * A detailed class which will contain blueprints for a Multiblock. * Values are not relative to the controller, but in total. @@ -38,9 +49,10 @@ public abstract class MultiblockBlueprint { depth = z; mMinimumCasingCount = aMinimumCasings; mTextureID = aTextureID; - Logger.INFO("Created new Blueprint."); + StructureMatrix = new BlockPos[width][height][depth]; + //Logger.INFO("Created new Blueprint."); } - + /** * * @param aY - The Y level of the layer to return, where 0 is the bottom and N is the top. @@ -49,7 +61,7 @@ public abstract class MultiblockBlueprint { public MultiblockLayer getLayer(int aY) { return mBlueprintData[aY]; } - + /** * * @param aLayer - A {@link MultiblockLayer} object. @@ -59,7 +71,7 @@ public abstract class MultiblockBlueprint { public void setLayer(MultiblockLayer aLayer, int aY) { mBlueprintData[aY] = aLayer; } - + public MultiblockLayer getControllerLayer() { for (MultiblockLayer u : mBlueprintData) { if (u.hasController()) { @@ -68,7 +80,7 @@ public abstract class MultiblockBlueprint { } return null; } - + public int getControllerY() { int i = 0; for (MultiblockLayer u : mBlueprintData) { @@ -79,20 +91,17 @@ public abstract class MultiblockBlueprint { } return 0; } - + + @SuppressWarnings({ "unused", "rawtypes" }) public boolean checkMachine(final IGregTechTileEntity aBaseMetaTileEntity) { - int mLogID = 0; - //Logger.INFO("Trying to Build Blueprint ["+(mLogID++)+"]"); - + //Check for Nulls if (aBaseMetaTileEntity == null) { return false; } - //Logger.INFO("Trying to Build Blueprint ["+(mLogID++)+"]"); final IMetaTileEntity aMetaTileEntity = aBaseMetaTileEntity.getMetaTileEntity(); if (aMetaTileEntity == null) { return false; } - //Logger.INFO("Trying to Build Blueprint ["+(mLogID++)+"]"); GT_MetaTileEntity_MultiBlockBase aControllerObject = null; if (aMetaTileEntity instanceof GT_MetaTileEntity_MultiBlockBase) { aControllerObject = (GT_MetaTileEntity_MultiBlockBase) aMetaTileEntity; @@ -100,212 +109,195 @@ public abstract class MultiblockBlueprint { if (aControllerObject == null) { return false; } - //Logger.INFO("Trying to Build Blueprint ["+(mLogID++)+"]"); - + + //Get some Vars int xOffSetMulti = ((this.getControllerLayer().width-1)/2); int zOffSetMulti = ((this.getControllerLayer().depth-1)/2); final int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * xOffSetMulti; final int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * zOffSetMulti; - - //Logger.INFO("Trying to Build Blueprint ["+(mLogID++)+"]"); - + ForgeDirection aDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()); int tAmount = 0; - //Logger.INFO("Trying to Build Blueprint ["+(mLogID++)+"] (pre-Iteration)"); - - //Try Fancy Cache Stuff + int contX = aControllerObject.getBaseMetaTileEntity().getXCoord(), contY = aControllerObject.getBaseMetaTileEntity().getYCoord(), contZ = aControllerObject.getBaseMetaTileEntity().getZCoord(); - BlockPos aPos = getOffsetRelativeToGridPosition(aBaseMetaTileEntity, 0, 0, 0); - BlockPos[][][] StructureMatrix = new BlockPos[width][height][depth]; + Logger.INFO("Controller is located at ["+contX+", "+contY+", "+contZ+"]"); - ForgeDirection aDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()); - Pair<Integer, Integer> controllerLocationRelativeToGrid = this.getControllerLayer().getControllerLocation(); + boolean debugCacheDataVisually = true; - for (int Y = 0; Y < height; Y++) { - for (int Z = 0; Z < depth; Z++) { - for (int X = 0; X < width; X++) { - - int offsetX, offsetY, offsetZ; - - if (aDir == ForgeDirection.NORTH) { - offsetX = X; - offsetY = -this.getControllerY(); - offsetZ = Z; - } - - else if (aDir == ForgeDirection.EAST) { - offsetX = -X; - offsetY = -this.getControllerY(); - offsetZ = Z; - } + + if (/*!mGeneratedMatrix || StructureMatrix == null*/ true) { + //Try Fancy Cache Stuff + BlockPos aPos = getOffsetRelativeToGridPosition(aBaseMetaTileEntity, 0, 0, 0); + for (int Y = 0; Y < height; Y++) { + for (int Z = 0; Z < depth; Z++) { + for (int X = 0; X < width; X++) { + int offsetX, offsetZ; + Pair<Integer, Integer> j = MultiblockLayer.rotateOffsetValues(aDir, X, Z); + offsetX = j.getKey(); + offsetZ = j.getValue(); - else if (aDir == ForgeDirection.SOUTH) { - offsetX = -X; - offsetY = -this.getControllerY(); - offsetZ = -Z; - } + Logger.INFO("Pre-Rotated Offsets ["+X+", "+(aPos.yPos + Y)+", "+Z+"] | "+aDir.name()); + Logger.INFO("Rotated Offsets ["+offsetX+", "+(aPos.yPos + Y)+", "+offsetZ+"]"); - else if (aDir == ForgeDirection.WEST) { - offsetX = X; - offsetY = -this.getControllerY(); - offsetZ = -Z; - } - else { - offsetX = X; - offsetY = -this.getControllerY(); - offsetZ = Z; - } - - //Resolve Negatives - int negTestX, negTestZ; - if (aPos.xPos < 0) { - //Logger.INFO("Found Negative X Pos."); - int testA = aPos.xPos; - testA -= -offsetX; - //Logger.INFO("Adding Inverted Offset of "+offsetX+", making "+testA); - negTestX = testA; - } - else { - negTestX = offsetX + aPos.xPos; - } - - if (aPos.zPos < 0) { - //Logger.INFO("Found Negative Z Pos."); - int testA = aPos.zPos; - testA -= -offsetZ; - //Logger.INFO("Adding Inverted Offset of "+offsetZ+", making "+testA); - negTestZ = testA; - } - else { - negTestZ = offsetZ + aPos.zPos; + // Resolve Negatives + int negTestX, negTestZ; + if (aPos.xPos < 0) { + int testA = aPos.xPos; + testA -= -offsetX; + negTestX = testA; + } else { + negTestX = offsetX + aPos.xPos; + } + if (aPos.zPos < 0) { + int testA = aPos.zPos; + testA -= -offsetZ; + negTestZ = testA; + } else { + negTestZ = offsetZ + aPos.zPos; + } + Logger.INFO("Caching With Offset ["+negTestX+", "+(aPos.yPos + Y)+", "+negTestZ+"]"); + StructureMatrix[X][Y][Z] = new BlockPos(negTestX, (aPos.yPos + Y), negTestZ, aPos.world); + + if (debugCacheDataVisually) { + aBaseMetaTileEntity.getWorld().setBlock(negTestX, (aPos.yPos + Y), negTestZ, Blocks.glass); + } } - - - StructureMatrix[X][Y][Z] = new BlockPos(negTestX, aPos.yPos + Y, negTestZ, aPos.world); } - } + } + Logger.INFO("Cached blueprint matrix."); + mGeneratedMatrix = true; } - + else { + Logger.INFO("Found cached blueprint matrix."); + } + + if (StructureMatrix == null) { + Logger.INFO("Error caching blueprint matrix."); + return false; + } + + int a1, a2, a3; a1 = StructureMatrix.length; a2 = StructureMatrix[0].length; - a3 = StructureMatrix[0][0].length; - - + a3 = StructureMatrix[0][0].length; + + Logger.INFO("Matrix Size ["+a1+", "+a2+", "+a3+"]"); + for (int H = 0; H < a2; H++) { - + MultiblockLayer currentLayer = this.getLayer(H); for (int W = 0; W < a1; W++) { for (int D = 0; D < a3; D++) { - + BlockPos aToCheck = StructureMatrix[W][H][D]; if (aToCheck == null) { Logger.INFO("Found bad data stored at X: "+W+", Y: "+H+", Z: "+D); continue; } - + else { + //Logger.INFO("Found data stored at X: "+W+", Y: "+H+", Z: "+D); + Logger.INFO("Checking "+aToCheck.getLocationString()); + } + final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntity(aToCheck.xPos, aToCheck.yPos, aToCheck.zPos); final Block tBlock = aBaseMetaTileEntity.getBlock(aToCheck.xPos, aToCheck.yPos, aToCheck.zPos); final int tMeta = aBaseMetaTileEntity.getMetaID(aToCheck.xPos, aToCheck.yPos, aToCheck.zPos); + + LayerBlockData g1 = currentLayer.getDataFromCoordsWithDirection(aDir, W, D); + if (g1 == null) { + Logger.INFO("Failed to find LayerBlockData. Using AIR_FALLBACK"); + //return false;*/ + g1 = LayerBlockData.FALLBACK_AIR_CHECK; + } + else { + if (g1.isController) { + Logger.INFO("Controller is at X: "+W+", Y: "+H+", Z: "+D); + } + } + + boolean isMatch = g1.match(tBlock, tMeta); - - if (!currentLayer.getBlockForPos(tBlock, tMeta, W, D, aDir)) { + if (!isMatch) { Logger.INFO("Checking ["+aToCheck.xPos+", "+ aToCheck.yPos +", "+ aToCheck.zPos+"]"); - Logger.INFO("Checking Position relative to Grid. X: "+W+", Y: "+H+", Z: "+D); - - - Logger.INFO("Found "+tBlock.getLocalizedName()+" : "+tMeta + " | Bad ["+W+", "+D+"]"); - - LayerBlockData g; - if (aDir == ForgeDirection.SOUTH) { - g = currentLayer.mVariantOrientations.get(2)[W][D]; - } - else if (aDir == ForgeDirection.WEST) { - g = currentLayer.mVariantOrientations.get(3)[W][D]; - } - else if (aDir == ForgeDirection.NORTH) { - g = currentLayer.mVariantOrientations.get(0)[W][D]; - } - else if (aDir == ForgeDirection.EAST) { - g = currentLayer.mVariantOrientations.get(1)[W][D]; - } - else { - g = currentLayer.mLayerData[W][D]; - } - + Logger.INFO("Checking Position relative to Grid. X: "+W+", Y: "+H+", Z: "+D); + Logger.INFO("Found "+tBlock.getLocalizedName()+" : "+tMeta + " | Bad ["+W+", "+D+"]"); + + LayerBlockData g = currentLayer.getDataFromCoordsWithDirection(aDir, W, D); + if (g == null) { Logger.INFO("Expected "+" BAD DATA - Possibly Unset Area in Blueprint."); - + } else { - Logger.INFO("Expected "+g.mBlock.getLocalizedName()+" : "+g.mMeta + ""); - - } - - - - /* - BlockPos aPos2 = getOffsetRelativeToGridPosition(aBaseMetaTileEntity, X, Y, Z); - aBaseMetaTileEntity.getWorld().setBlock(aPos2.xPos, aPos2.yPos, aPos2.zPos, Blocks.bedrock); */ - - return false; + Logger.INFO("Expected "+g.mBlock.getLocalizedName()+" : "+g.mMeta + ""); + } + aBaseMetaTileEntity.getWorld().setBlock(aToCheck.xPos, aToCheck.yPos, aToCheck.zPos, g.mBlock); + aBaseMetaTileEntity.getWorld().setBlockMetadataWithNotify(aToCheck.xPos, aToCheck.yPos, aToCheck.zPos, g.mMeta, 4); + //return false; } else { - //Logger.INFO("Found "+tBlock.getLocalizedName()+" : "+tMeta + " | Okay"); - if (!aControllerObject.addToMachineList(tTileEntity, mTextureID)) { - tAmount++; - } - } - } - } - } - - - - - try {/* - for (int Y = 0; Y < height; Y++) { - - MultiblockLayer aCurrentLayerToCheck = this.getLayer(Y); - int aWidth = aCurrentLayerToCheck.width; - int aDepth = aCurrentLayerToCheck.depth; - - - for (int Z = 0; Z < aDepth; Z++) { - for (int X = 0; X < aWidth; X++) { - - final IGregTechTileEntity tTileEntity = getTileAtOffset(aBaseMetaTileEntity, X, Y, Z); - final Pair<Block, Integer> tPair = getBlockAtOffset(aBaseMetaTileEntity, X, Y, Z); - final Block tBlock = tPair.getKey(); - final int tMeta = tPair.getValue(); - Logger.INFO("Checking Position relative to Controller. X: "+X+", Y: "+Y+", Z: "+Z); - Logger.INFO("Checking Position relative to Grid. X: "+X+", Y: "+Y+", Z: "+Z); - - if (!aCurrentLayerToCheck.getBlockForPos(tBlock, tMeta, X, Z, ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()))) { + LayerBlockData g = currentLayer.getDataFromCoordsWithDirection(aDir, W, D); + + + + + + + + + - Logger.INFO("Found "+tBlock.getLocalizedName()+" : "+tMeta + " | Bad"); - BlockPos aPos2 = getOffsetRelativeToGridPosition(aBaseMetaTileEntity, X, Y, Z); - aBaseMetaTileEntity.getWorld().setBlock(aPos2.xPos, aPos2.yPos, aPos2.zPos, Blocks.bedrock); + + + + + + + + + + boolean isHatchValidType = false; + if (g != null) { + if (g.canBeHatch && !g.isController && tTileEntity != null) { + IMetaTileEntity aMetaTileEntity2 = tTileEntity.getMetaTileEntity(); + if (aMetaTileEntity2 != null) { + if (aMetaTileEntity2 instanceof GT_MetaTileEntity_MultiBlockBase) { + isHatchValidType = true; + break; + } + else { + for (Class c : g.mHatchClass) { + if (c != null) { + if (c.isInstance(aMetaTileEntity2)) { + isHatchValidType = true; + break; + } + } + } + } + } + } + } - return false; - } - else { - Logger.INFO("Found "+tBlock.getLocalizedName()+" : "+tMeta + " | Okay"); + if (!isHatchValidType && !g.isController && tTileEntity != null) { + Logger.INFO("Checking ["+aToCheck.xPos+", "+ aToCheck.yPos +", "+ aToCheck.zPos+"]"); + Logger.INFO("Hatch Type did not match allowed types. "+tTileEntity.getClass().getSimpleName()); + return false; + } if (!aControllerObject.addToMachineList(tTileEntity, mTextureID)) { tAmount++; } + + } - } - } - } - */} - catch (Throwable r) { - r.printStackTrace(); - } - + } + } + } + boolean hasCorrectHatches = ( aControllerObject.mInputBusses.size() >= this.getMinimumInputBus() && aControllerObject.mOutputBusses.size() >= this.getMinimumOutputBus() && @@ -315,7 +307,7 @@ public abstract class MultiblockBlueprint { aControllerObject.mEnergyHatches.size() >= this.getMinimumInputEnergy() && aControllerObject.mMaintenanceHatches.size() >= this.getMinimumMaintHatch() && aControllerObject.mMufflerHatches.size() >= this.getMinimumMufflers()); - + Logger.INFO("mInputBusses: "+aControllerObject.mInputBusses.size()); Logger.INFO("mOutputBusses: "+aControllerObject.mOutputBusses.size()); @@ -325,30 +317,30 @@ public abstract class MultiblockBlueprint { Logger.INFO("mDynamoHatches: "+aControllerObject.mDynamoHatches.size()); Logger.INFO("mMaintenanceHatches: "+aControllerObject.mMaintenanceHatches.size()); Logger.INFO("mMufflerHatches: "+aControllerObject.mMufflerHatches.size()); - + boolean built = hasCorrectHatches && tAmount >= mMinimumCasingCount; Logger.INFO("Built? "+built); Logger.INFO("hasCorrectHatches? "+hasCorrectHatches); Logger.INFO("tAmount? "+tAmount); return built; } - + public BlockPos getOffsetRelativeToGridPosition(final IGregTechTileEntity aBaseMetaTileEntity, final int x, final int y, final int z) { - + if (aBaseMetaTileEntity == null) { return null; } - + int controllerX, controllerY, controllerZ; MultiblockLayer layerController = this.getControllerLayer(); - + if (layerController == null) { return null; } - + int controllerYRelative = this.getControllerY(); Pair<Integer, Integer> controllerLocationRelativeToGrid = layerController.getControllerLocation(); - + if (controllerLocationRelativeToGrid == null) { return null; } @@ -356,54 +348,52 @@ public abstract class MultiblockBlueprint { controllerX = aBaseMetaTileEntity.getXCoord(); controllerY = aBaseMetaTileEntity.getYCoord(); controllerZ = aBaseMetaTileEntity.getZCoord(); - + Logger.INFO("Controller is at ["+controllerX+", "+controllerY+", "+controllerZ+"]"); ForgeDirection aDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()); Logger.INFO("Controller is facing "+aDir.name()); - + //Find Bottom Left corner of Structure // 0, 0, 0 - - int offsetX, offsetY, offsetZ; - + + int offsetX, offsetY, offsetZ; + int X = controllerLocationRelativeToGrid.getKey(), Z = controllerLocationRelativeToGrid.getValue(); + Logger.INFO("Attempting to translate offsets ["+X+", "+Z+"]"); if (aDir == ForgeDirection.NORTH) { - offsetX = controllerLocationRelativeToGrid.getKey(); - offsetY = -controllerYRelative; - offsetZ = controllerLocationRelativeToGrid.getValue(); + offsetX = -X; + offsetZ = -Z; } else if (aDir == ForgeDirection.EAST) { - offsetX = controllerLocationRelativeToGrid.getValue(); - offsetY = -controllerYRelative; - offsetZ = -controllerLocationRelativeToGrid.getKey(); + offsetX = Z; + offsetZ = -X; } else if (aDir == ForgeDirection.SOUTH) { - offsetX = controllerLocationRelativeToGrid.getKey(); - offsetY = -controllerYRelative; - offsetZ = controllerLocationRelativeToGrid.getValue(); + offsetX = X; + offsetZ = Z; } else if (aDir == ForgeDirection.WEST) { - offsetX = -controllerLocationRelativeToGrid.getValue(); - offsetY = -controllerYRelative; - offsetZ = controllerLocationRelativeToGrid.getKey(); + offsetX = -Z; + offsetZ = X; } else { - offsetX = -controllerLocationRelativeToGrid.getKey(); - offsetY = -controllerYRelative; - offsetZ = -controllerLocationRelativeToGrid.getValue(); - } + offsetX = -X; + offsetZ = -Z; + } + + offsetY = -controllerYRelative; Logger.INFO("Attempting to use offsets ["+offsetX+", "+offsetY+", "+offsetZ+"]"); - + //Resolve Negatives - int negTestX, negTestY, negTestZ; + int negTestX, negTestZ; if (controllerX < 0) { Logger.INFO("Found Negative X Pos."); int testA = controllerX; - testA -= -offsetX; + testA -= offsetX; Logger.INFO("Adding Inverted Offset of "+offsetX+", making "+testA); negTestX = testA; } @@ -420,36 +410,36 @@ public abstract class MultiblockBlueprint { else { negTestZ = offsetZ + controllerZ; } - - + + //} //Bottom left Corner position BlockPos p = new BlockPos(negTestX, offsetY+controllerY, negTestZ, aBaseMetaTileEntity.getWorld()); Logger.INFO("World XYZ for Bottom left Corner Block of structure ["+p.xPos+", "+p.yPos+", "+p.zPos+"]"); - + //Add the xyz relative to the grid. BlockPos offsetPos = new BlockPos(p.xPos+x, p.yPos+y, p.zPos+z, aBaseMetaTileEntity.getWorld()); Logger.INFO("World XYZ for Target Check Block in structure ["+offsetPos.xPos+", "+offsetPos.yPos+", "+offsetPos.zPos+"]"); - + return p; } - - + + public IGregTechTileEntity getTileAtOffset(final IGregTechTileEntity aBaseMetaTileEntity, int x, int y, int z){ BlockPos aPos = getOffsetRelativeToGridPosition(aBaseMetaTileEntity, x, y, z); final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(aPos.xPos, aPos.yPos, aPos.zPos); //aBaseMetaTileEntity.getWorld().setBlock(xh, yh, zh, Blocks.gold_ore); return tTileEntity; } - + public Pair<Block, Integer> getBlockAtOffset(final IGregTechTileEntity aBaseMetaTileEntity, int x, int y, int z){ BlockPos aPos = getOffsetRelativeToGridPosition(aBaseMetaTileEntity, x, y, z); final Block tBlock = aBaseMetaTileEntity.getBlockOffset(aPos.xPos, aPos.yPos, aPos.zPos); final int tMeta = aBaseMetaTileEntity.getMetaIDOffset(aPos.xPos, aPos.yPos, aPos.zPos); return new Pair<Block, Integer>(tBlock, tMeta); } - + public Triplet<Integer, Integer, Integer> getOffsetFromControllerTo00(){ MultiblockLayer l = this.getControllerLayer(); if (l == null) { @@ -457,14 +447,14 @@ public abstract class MultiblockBlueprint { } int yOffset = this.getControllerY(); Pair<Integer, Integer> cl = l.getControllerLocation(); - + if (cl == null) { return null; } return new Triplet<Integer, Integer, Integer> (cl.getKey(), yOffset, cl.getValue()); //return new Triplet<Integer, Integer, Integer> (cl.getKey(), yOffset, cl.getValue()); - + } public abstract int getMinimumInputBus(); @@ -475,5 +465,5 @@ public abstract class MultiblockBlueprint { public abstract int getMinimumOutputEnergy(); public abstract int getMinimumMaintHatch(); public abstract int getMinimumMufflers(); - + } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockLayer.java b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockLayer.java index bd77c9c8a1..9ffe1258f8 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockLayer.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockLayer.java @@ -3,11 +3,22 @@ package gtPlusPlus.xmod.gregtech.api.objects; import java.util.HashMap; import gregtech.api.GregTech_API; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_DataAccess; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Dynamo; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Maintenance; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffler; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_OutputBus; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.api.objects.data.Pair; import gtPlusPlus.core.util.data.ArrayUtils; +import gtPlusPlus.xmod.gregtech.api.objects.MultiblockLayer.LayerBlockData; import net.minecraft.block.Block; import net.minecraft.block.BlockAir; import net.minecraft.init.Blocks; @@ -42,7 +53,7 @@ public class MultiblockLayer { width = x; depth = z; mLayerData = new LayerBlockData[x][z]; - Logger.INFO("Created new Blueprint Layer."); + //Logger.INFO("Created new Blueprint Layer."); } /** @@ -65,7 +76,7 @@ public class MultiblockLayer { * @return - Is this data added to the layer data map? */ public boolean addBlockForPos(Block aBlock, int aMeta, int x, int z, boolean canBeHatch) { - return addBlockForPos(aBlock, aMeta, x, z, canBeHatch, null); + return addBlockForPos(aBlock, aMeta, x, z, canBeHatch, new Class[] {}); } /** @@ -79,12 +90,44 @@ public class MultiblockLayer { * @return - Is this data added to the layer data map? */ public boolean addBlockForPos(Block aBlock, int aMeta, int x, int z, boolean canBeHatch, Class aHatchTypeClass) { + return addBlockForPos(aBlock, aMeta, x, z, canBeHatch, new Class[] {aHatchTypeClass}); + } + + /** + * + * @param aBlock - The block expected as this location. + * @param aMeta - The meta for the block above. + * @param x - The X location, where 0 is the top left corner & counts upwards, moving right. + * @param z - The Z location, where 0 is the top left corner & counts upwards, moving down. + * @param canBeHatch - is this location able to be substituted for a hatch? + * @param aHatchTypeClass - Specify the class for the hatch if you want it explicit. Use base classes to allow custom hatches which extend. + * @return - Is this data added to the layer data map? + */ + public boolean addBlockForPos(Block aBlock, int aMeta, int x, int z, boolean canBeHatch, Class[] aHatchTypeClass) { if (x > width -1) { return false; } if (z > depth - 1) { return false; } + + if (canBeHatch && (aHatchTypeClass == null || aHatchTypeClass.length <= 0)){ + aHatchTypeClass = new Class[] { + GT_MetaTileEntity_Hatch_DataAccess.class, + GT_MetaTileEntity_Hatch_Dynamo.class, + GT_MetaTileEntity_Hatch_Energy.class, + GT_MetaTileEntity_Hatch_Input.class, + GT_MetaTileEntity_Hatch_InputBus.class, + GT_MetaTileEntity_Hatch_Maintenance.class, + GT_MetaTileEntity_Hatch_Muffler.class, + GT_MetaTileEntity_Hatch_Output.class, + GT_MetaTileEntity_Hatch_OutputBus.class, + GT_MetaTileEntity_Hatch.class + }; + } + + + mLayerData[x][z] = new LayerBlockData(aBlock, aMeta, canBeHatch, aHatchTypeClass); return true; } @@ -99,6 +142,113 @@ public class MultiblockLayer { setControllerLocation(new Pair<Integer, Integer>(x, z)); return addBlockForPos(GregTech_API.sBlockMachines, 0, x, z, true, GT_MetaTileEntity_MultiBlockBase.class); } + + + /** + * Adds a Muffler to the layer at the designated location. + * @param x - The X location, where 0 is the top left corner & counts upwards, moving right. + * @param z - The Z location, where 0 is the top left corner & counts upwards, moving down. + * @return - Is this controller added to the layer data map? + */ + public boolean addMuffler(Block aBlock, int aMeta, int x, int z) { + return addBlockForPos(aBlock, aMeta, x, z, true, GT_MetaTileEntity_Hatch_Muffler.class); + } + + + /** + * Adds a Maint Hatch to the layer at the designated location. + * @param x - The X location, where 0 is the top left corner & counts upwards, moving right. + * @param z - The Z location, where 0 is the top left corner & counts upwards, moving down. + * @return - Is this controller added to the layer data map? + */ + public boolean addMaintHatch(Block aBlock, int aMeta, int x, int z) { + return addBlockForPos(aBlock, aMeta, x, z, true, GT_MetaTileEntity_Hatch_Maintenance.class); + } + + + /** + * Adds ah Input to the layer at the designated location. + * @param x - The X location, where 0 is the top left corner & counts upwards, moving right. + * @param z - The Z location, where 0 is the top left corner & counts upwards, moving down. + * @return - Is this controller added to the layer data map? + */ + public boolean addInputBus(Block aBlock, int aMeta, int x, int z) { + return addBlockForPos(aBlock, aMeta, x, z, true, GT_MetaTileEntity_Hatch_InputBus.class); + } + + + /** + * Adds an Output to the layer at the designated location. + * @param x - The X location, where 0 is the top left corner & counts upwards, moving right. + * @param z - The Z location, where 0 is the top left corner & counts upwards, moving down. + * @return - Is this controller added to the layer data map? + */ + public boolean addOutputBus(Block aBlock, int aMeta, int x, int z) { + return addBlockForPos(aBlock, aMeta, x, z, true, GT_MetaTileEntity_Hatch_OutputBus.class); + } + + /** + * Adds ah Input to the layer at the designated location. + * @param x - The X location, where 0 is the top left corner & counts upwards, moving right. + * @param z - The Z location, where 0 is the top left corner & counts upwards, moving down. + * @return - Is this controller added to the layer data map? + */ + public boolean addInputHatch(Block aBlock, int aMeta, int x, int z) { + return addBlockForPos(aBlock, aMeta, x, z, true, GT_MetaTileEntity_Hatch_Input.class); + } + + + /** + * Adds an Output to the layer at the designated location. + * @param x - The X location, where 0 is the top left corner & counts upwards, moving right. + * @param z - The Z location, where 0 is the top left corner & counts upwards, moving down. + * @return - Is this controller added to the layer data map? + */ + public boolean addOutputHatch(Block aBlock, int aMeta, int x, int z) { + return addBlockForPos(aBlock, aMeta, x, z, true, GT_MetaTileEntity_Hatch_Output.class); + } + + /** + * Adds ah Input to the layer at the designated location. + * @param x - The X location, where 0 is the top left corner & counts upwards, moving right. + * @param z - The Z location, where 0 is the top left corner & counts upwards, moving down. + * @return - Is this controller added to the layer data map? + */ + public boolean addInput(Block aBlock, int aMeta, int x, int z) { + return addBlockForPos(aBlock, aMeta, x, z, true, new Class[] {GT_MetaTileEntity_Hatch_Input.class, GT_MetaTileEntity_Hatch_InputBus.class}); + } + + + /** + * Adds an Output to the layer at the designated location. + * @param x - The X location, where 0 is the top left corner & counts upwards, moving right. + * @param z - The Z location, where 0 is the top left corner & counts upwards, moving down. + * @return - Is this controller added to the layer data map? + */ + public boolean addOutput(Block aBlock, int aMeta, int x, int z) { + return addBlockForPos(aBlock, aMeta, x, z, true, new Class[] {GT_MetaTileEntity_Hatch_Output.class, GT_MetaTileEntity_Hatch_OutputBus.class}); + } + + /** + * Adds ah Input to the layer at the designated location. + * @param x - The X location, where 0 is the top left corner & counts upwards, moving right. + * @param z - The Z location, where 0 is the top left corner & counts upwards, moving down. + * @return - Is this controller added to the layer data map? + */ + public boolean addEnergyInput(Block aBlock, int aMeta, int x, int z) { + return addBlockForPos(aBlock, aMeta, x, z, true, GT_MetaTileEntity_Hatch_Energy.class); + } + + + /** + * Adds an Output to the layer at the designated location. + * @param x - The X location, where 0 is the top left corner & counts upwards, moving right. + * @param z - The Z location, where 0 is the top left corner & counts upwards, moving down. + * @return - Is this controller added to the layer data map? + */ + public boolean addEnergyOutput(Block aBlock, int aMeta, int x, int z) { + return addBlockForPos(aBlock, aMeta, x, z, true, GT_MetaTileEntity_Hatch_Dynamo.class); + } /** * @@ -110,7 +260,7 @@ public class MultiblockLayer { * @return - True if the correct Block was found. May also return true if a hatch is found when allowed or it's the controller. */ public boolean getBlockForPos(Block aBlock, int aMeta, int x, int z, ForgeDirection aDir) { - Logger.INFO("Grid Index X: "+x+" | Z: "+z + " | "+aDir.name()); + //Logger.INFO("Grid Index X: "+x+" | Z: "+z + " | "+aDir.name()); LayerBlockData g; if (aDir == ForgeDirection.SOUTH) { g = mVariantOrientations.get(2)[x][z]; @@ -121,11 +271,11 @@ public class MultiblockLayer { else if (aDir == ForgeDirection.NORTH) { LayerBlockData[][] aData = mVariantOrientations.get(0); if (aData != null) { - Logger.INFO("Found Valid Orientation Data. "+aData.length + ", "+aData[0].length); + //Logger.INFO("Found Valid Orientation Data. "+aData.length + ", "+aData[0].length); g = aData[x][z]; } else { - Logger.INFO("Did not find valid orientation data."); + //Logger.INFO("Did not find valid orientation data."); g = null; } } @@ -136,8 +286,8 @@ public class MultiblockLayer { g = mLayerData[x][z]; } if (g == null) { - /*Logger.INFO("Failed to find LayerBlockData."); - return false;*/ + Logger.INFO("Failed to find LayerBlockData. Using AIR_FALLBACK"); + //return false;*/ g = LayerBlockData.FALLBACK_AIR_CHECK; } @@ -164,32 +314,32 @@ public class MultiblockLayer { Logger.INFO("Failed to lock layer"); return; } - Logger.INFO("Trying to lock layer"); + //Logger.INFO("Trying to lock layer"); this.mFinalised = true; generateOrientations(); - Logger.INFO("Trying to Build Blueprint Layer [Constructed orietations & finalized]"); + //Logger.INFO("Trying to Build Blueprint Layer [Constructed orietations & finalized]"); } private void generateOrientations() { try { - Logger.INFO("Trying to gen orients for layer"); + //Logger.INFO("Trying to gen orients for layer"); //North mVariantOrientations.put(mLayerData); LayerBlockData[][] val; - Logger.INFO("1 done"); + //Logger.INFO("1 done"); //East val = rotateArrayClockwise(mLayerData); mVariantOrientations.put((LayerBlockData[][]) val); - Logger.INFO("2 done"); + //Logger.INFO("2 done"); //South val = rotateArrayClockwise(mLayerData); mVariantOrientations.put((LayerBlockData[][]) val); - Logger.INFO("3 done"); + //Logger.INFO("3 done"); //West val = rotateArrayClockwise(mLayerData); mVariantOrientations.put((LayerBlockData[][]) val); - Logger.INFO("4 done"); + //Logger.INFO("4 done"); } catch (Throwable t) { @@ -198,19 +348,19 @@ public class MultiblockLayer { } public static LayerBlockData[][] rotateArrayClockwise(LayerBlockData[][] mat) { - Logger.INFO("Rotating Layer 90' Clockwise"); + //Logger.INFO("Rotating Layer 90' Clockwise"); try { final int M = mat.length; final int N = mat[0].length; - Logger.INFO("Dimension X: "+M); - Logger.INFO("Dimension Z: "+N); + //Logger.INFO("Dimension X: "+M); + //Logger.INFO("Dimension Z: "+N); LayerBlockData[][] ret = new LayerBlockData[N][M]; for (int r = 0; r < M; r++) { for (int c = 0; c < N; c++) { ret[c][M-1-r] = mat[r][c]; } } - Logger.INFO("Returning Rotated Layer"); + //Logger.INFO("Returning Rotated Layer"); return ret; } catch (Throwable t) { @@ -237,7 +387,55 @@ public class MultiblockLayer { this.mControllerLocation = mControllerLocation; } + public LayerBlockData getDataFromCoordsWithDirection(ForgeDirection aDir, int W, int D) { + LayerBlockData g; + if (aDir == ForgeDirection.SOUTH) { + g = this.mVariantOrientations.get(2)[W][D]; + } + else if (aDir == ForgeDirection.WEST) { + g = this.mVariantOrientations.get(3)[W][D]; + } + else if (aDir == ForgeDirection.NORTH) { + g = this.mVariantOrientations.get(0)[W][D]; + } + else if (aDir == ForgeDirection.EAST) { + g = this.mVariantOrientations.get(1)[W][D]; + } + else { + g = this.mLayerData[W][D]; + } + return g; + } + + public static Pair<Integer, Integer> rotateOffsetValues(ForgeDirection aDir, int X, int Z) { + int offsetX, offsetZ; + + if (aDir == ForgeDirection.NORTH) { + offsetX = X; + offsetZ = Z; + } + else if (aDir == ForgeDirection.EAST) { + offsetX = -X; + offsetZ = Z; + } + + else if (aDir == ForgeDirection.SOUTH) { + offsetX = -X; + offsetZ = -Z; + } + + else if (aDir == ForgeDirection.WEST) { + offsetX = X; + offsetZ = -Z; + } + else { + offsetX = X; + offsetZ = Z; + } + + return new Pair<Integer, Integer>(offsetX, offsetZ); + } @@ -363,21 +561,25 @@ public class MultiblockLayer { public final Block mBlock; public final int mMeta; public final boolean canBeHatch; - public final Class mHatchClass; + public final Class[] mHatchClass; - private final boolean isController; + public final boolean isController; public LayerBlockData(Block aBlock, int aMeta, boolean aHatch) { - this(aBlock, aMeta, aHatch, null); + this(aBlock, aMeta, aHatch, new Class[] {}); } public LayerBlockData(Block aBlock, int aMeta, boolean aHatch, Class clazz) { + this(aBlock, aMeta, aHatch, new Class[] {clazz}); + } + + public LayerBlockData(Block aBlock, int aMeta, boolean aHatch, Class[] clazz) { mBlock = aBlock; mMeta = aMeta; canBeHatch = aHatch; mHatchClass = clazz; - if (clazz != null && clazz.equals(GT_MetaTileEntity_MultiBlockBase.class)) { + if (clazz != null && clazz.length > 0 && clazz[0].equals(GT_MetaTileEntity_MultiBlockBase.class)) { isController = true; } else { @@ -391,17 +593,20 @@ public class MultiblockLayer { if (blockToTest instanceof BlockAir && mBlock instanceof BlockAir) { return true; } - - //If Block does't match at all and it cannot be hatch - if (blockToTest != mBlock && !canBeHatch) { - return false; + + if (isController && blockToTest == GregTech_API.sBlockMachines) { + return true; } - - //If Block does Match, is not controller, is not hatch and Meta does not match - if (!isController && !canBeHatch && metaToTest != mMeta) { - return false; + + if (canBeHatch && blockToTest == GregTech_API.sBlockMachines) { + return true; + } + + if (blockToTest == mBlock && metaToTest == mMeta) { + return true; } - return true; + + return false; } } |