aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/xmod/gregtech/api/objects
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2018-12-28 14:49:46 +0000
committerAlkalus <3060479+draknyte1@users.noreply.github.com>2018-12-28 14:49:46 +0000
commitae46cb2fab01f82ab49b1e63172da88e0adde212 (patch)
tree89b23a834721a94b66359342b65663eac12e7a58 /src/Java/gtPlusPlus/xmod/gregtech/api/objects
parent3033ac1f6f071dbb8d2a5227957ccc6800616baa (diff)
downloadGT5-Unofficial-ae46cb2fab01f82ab49b1e63172da88e0adde212.tar.gz
GT5-Unofficial-ae46cb2fab01f82ab49b1e63172da88e0adde212.tar.bz2
GT5-Unofficial-ae46cb2fab01f82ab49b1e63172da88e0adde212.zip
% More work on Blueprints.
> Industrial Electrolyzer constructs as expected using new system, time to test this with more complex multis.
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech/api/objects')
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockBlueprint.java372
-rw-r--r--src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockLayer.java200
2 files changed, 469 insertions, 103 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockBlueprint.java b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockBlueprint.java
index 09ab8b1c14..cb6d2faabf 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockBlueprint.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockBlueprint.java
@@ -4,7 +4,12 @@ import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase;
import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.api.objects.data.Pair;
+import gtPlusPlus.api.objects.data.Triplet;
+import gtPlusPlus.api.objects.minecraft.BlockPos;
+import gtPlusPlus.xmod.gregtech.api.objects.MultiblockLayer.LayerBlockData;
import net.minecraft.block.Block;
+import net.minecraft.init.Blocks;
import net.minecraftforge.common.util.ForgeDirection;
public abstract class MultiblockBlueprint {
@@ -76,13 +81,18 @@ public abstract class MultiblockBlueprint {
}
public boolean checkMachine(final IGregTechTileEntity aBaseMetaTileEntity) {
+ int mLogID = 0;
+ //Logger.INFO("Trying to Build Blueprint ["+(mLogID++)+"]");
+
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;
@@ -90,57 +100,214 @@ public abstract class MultiblockBlueprint {
if (aControllerObject == null) {
return false;
}
+ //Logger.INFO("Trying to Build Blueprint ["+(mLogID++)+"]");
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++)+"]");
- int a1, a2;
- a1 = this.getControllerY();
- a2 = this.height;
int tAmount = 0;
+
+ //Logger.INFO("Trying to Build Blueprint ["+(mLogID++)+"] (pre-Iteration)");
+
+ //Try Fancy Cache Stuff
+
+ BlockPos aPos = getOffsetRelativeToGridPosition(aBaseMetaTileEntity, 0, 0, 0);
+ BlockPos[][][] StructureMatrix = new BlockPos[width][height][depth];
+
+ ForgeDirection aDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing());
+ Pair<Integer, Integer> controllerLocationRelativeToGrid = this.getControllerLayer().getControllerLocation();
+
+ 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;
+ }
+
+ else if (aDir == ForgeDirection.SOUTH) {
+ offsetX = -X;
+ offsetY = -this.getControllerY();
+ offsetZ = -Z;
+ }
+
+ 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;
+ }
+
+
+ StructureMatrix[X][Y][Z] = new BlockPos(negTestX, aPos.yPos + Y, negTestZ, aPos.world);
+ }
+ }
+ }
- @SuppressWarnings("unused")
- int xRelativeCounter = 0, yRelativeCounter = 0, zRelativeCounter = 0;
- for (int Y = -a1; Y < ((a2-1)-a1); Y++) {
+ int a1, a2, a3;
+ a1 = StructureMatrix.length;
+ a2 = StructureMatrix[0].length;
+ a3 = StructureMatrix[0][0].length;
+
+
+ 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;
+ }
+
+ 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);
+
+
+
+ if (!currentLayer.getBlockForPos(tBlock, tMeta, W, D, aDir)) {
+
+ 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];
+ }
+
+ 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;
+ }
+ 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;
+
- int aDepthMin, aDepthMax;
- int aWidthMin, aWidthMax;
-
- aWidthMin = -((aWidth-1)/2);
- aWidthMax = ((aWidth-1)/2);
- aDepthMin = -((aDepth-1)/2);
- aDepthMax = ((aDepth-1)/2);
-
- for (int Z = aDepthMin; Z < aDepthMax; Z++) {
- for (int X = aWidthMin; X < aWidthMax; X++) {
- int b1 = xDir + X;
- int b2 = zDir + Z;
- final IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(b1, Y, b2);
- final Block tBlock = aBaseMetaTileEntity.getBlockOffset(b1, Y, b2);
- final int tMeta = aBaseMetaTileEntity.getMetaIDOffset(b1, Y, b2);
- if (!aCurrentLayerToCheck.getBlockForPos(tBlock, tMeta, xRelativeCounter, zRelativeCounter, ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()))) {
+ 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()))) {
+
+ 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);
+
return false;
}
else {
+ Logger.INFO("Found "+tBlock.getLocalizedName()+" : "+tMeta + " | Okay");
if (!aControllerObject.addToMachineList(tTileEntity, mTextureID)) {
tAmount++;
}
}
- xRelativeCounter++;
}
- xRelativeCounter = 0;
- zRelativeCounter++;
- }
- yRelativeCounter++;
+ }
+ }
+ */}
+ catch (Throwable r) {
+ r.printStackTrace();
}
- boolean hasCorrectHatches = (aControllerObject.mInputBusses.size() >= this.getMinimumInputBus() &&
+ boolean hasCorrectHatches = (
+ aControllerObject.mInputBusses.size() >= this.getMinimumInputBus() &&
aControllerObject.mOutputBusses.size() >= this.getMinimumOutputBus() &&
aControllerObject.mInputHatches.size() >= this.getMinimumInputHatch() &&
aControllerObject.mOutputHatches.size() >= this.getMinimumOutputHatch() &&
@@ -149,8 +316,155 @@ public abstract class MultiblockBlueprint {
aControllerObject.mMaintenanceHatches.size() >= this.getMinimumMaintHatch() &&
aControllerObject.mMufflerHatches.size() >= this.getMinimumMufflers());
+
+ Logger.INFO("mInputBusses: "+aControllerObject.mInputBusses.size());
+ Logger.INFO("mOutputBusses: "+aControllerObject.mOutputBusses.size());
+ Logger.INFO("mInputHatches: "+aControllerObject.mInputHatches.size());
+ Logger.INFO("mOutputHatches: "+aControllerObject.mOutputHatches.size());
+ Logger.INFO("mEnergyHatches: "+aControllerObject.mEnergyHatches.size());
+ 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;
+ }
+
+ 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;
+
+ if (aDir == ForgeDirection.NORTH) {
+ offsetX = controllerLocationRelativeToGrid.getKey();
+ offsetY = -controllerYRelative;
+ offsetZ = controllerLocationRelativeToGrid.getValue();
+ }
+
+ else if (aDir == ForgeDirection.EAST) {
+ offsetX = controllerLocationRelativeToGrid.getValue();
+ offsetY = -controllerYRelative;
+ offsetZ = -controllerLocationRelativeToGrid.getKey();
+ }
+
+ else if (aDir == ForgeDirection.SOUTH) {
+ offsetX = controllerLocationRelativeToGrid.getKey();
+ offsetY = -controllerYRelative;
+ offsetZ = controllerLocationRelativeToGrid.getValue();
+ }
+
+ else if (aDir == ForgeDirection.WEST) {
+ offsetX = -controllerLocationRelativeToGrid.getValue();
+ offsetY = -controllerYRelative;
+ offsetZ = controllerLocationRelativeToGrid.getKey();
+ }
+ else {
+ offsetX = -controllerLocationRelativeToGrid.getKey();
+ offsetY = -controllerYRelative;
+ offsetZ = -controllerLocationRelativeToGrid.getValue();
+ }
+
+ Logger.INFO("Attempting to use offsets ["+offsetX+", "+offsetY+", "+offsetZ+"]");
+
+ //Resolve Negatives
+ int negTestX, negTestY, negTestZ;
+ if (controllerX < 0) {
+ Logger.INFO("Found Negative X Pos.");
+ int testA = controllerX;
+ testA -= -offsetX;
+ Logger.INFO("Adding Inverted Offset of "+offsetX+", making "+testA);
+ negTestX = testA;
+ }
+ else {
+ negTestX = offsetX + controllerX;
+ }
+ if (controllerZ < 0) {
+ Logger.INFO("Found Negative Z Pos.");
+ int testA = controllerZ;
+ testA -= -offsetZ;
+ Logger.INFO("Adding Inverted Offset of "+offsetZ+", making "+testA);
+ negTestZ = testA;
+ }
+ 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) {
+ return null;
+ }
+ 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());
- return hasCorrectHatches && tAmount >= mMinimumCasingCount;
}
public abstract int getMinimumInputBus();
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockLayer.java b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockLayer.java
index 2d3d8a505a..bd77c9c8a1 100644
--- a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockLayer.java
+++ b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockLayer.java
@@ -10,26 +10,28 @@ import gtPlusPlus.api.objects.data.Pair;
import gtPlusPlus.core.util.data.ArrayUtils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockAir;
+import net.minecraft.init.Blocks;
import net.minecraftforge.common.util.ForgeDirection;
public class MultiblockLayer {
-
+
public final int width;
- public final int depth;
-
+ public final int depth;
+
private boolean mFinalised;
+
/**
* WARNING!! May be {@link null}.
*/
private Pair<Integer, Integer> mControllerLocation;
-
+
/**
* Holds the North facing Orientation data.
*/
public final LayerBlockData[][] mLayerData;
public final AutoMap<LayerBlockData[][]> mVariantOrientations = new AutoMap<LayerBlockData[][]>();
-
+
/**
* A detailed class which will contain a single x/z Layer for a {@link MultiblockBlueprint}.
* Values are not relative, but in total.
@@ -42,7 +44,7 @@ public class MultiblockLayer {
mLayerData = new LayerBlockData[x][z];
Logger.INFO("Created new Blueprint Layer.");
}
-
+
/**
* A detailed class which will contain a single x/z Layer for a {@link MultiblockBlueprint}.
* Values are not relative, but in total.
@@ -52,7 +54,7 @@ public class MultiblockLayer {
depth = aData[0].length;
mLayerData = aData;
}
-
+
/**
*
* @param aBlock - The block expected as this location.
@@ -65,7 +67,7 @@ public class MultiblockLayer {
public boolean addBlockForPos(Block aBlock, int aMeta, int x, int z, boolean canBeHatch) {
return addBlockForPos(aBlock, aMeta, x, z, canBeHatch, null);
}
-
+
/**
*
* @param aBlock - The block expected as this location.
@@ -76,17 +78,17 @@ public class MultiblockLayer {
* @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) {
+ 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;
- }
+ }
mLayerData[x][z] = new LayerBlockData(aBlock, aMeta, canBeHatch, aHatchTypeClass);
return true;
}
-
+
/**
* Adds a controller to the layer at the designated location, Details about the controller do not need to be specified.
* @param x - The X location, where 0 is the top left corner & counts upwards, moving right.
@@ -97,7 +99,7 @@ public class MultiblockLayer {
setControllerLocation(new Pair<Integer, Integer>(x, z));
return addBlockForPos(GregTech_API.sBlockMachines, 0, x, z, true, GT_MetaTileEntity_MultiBlockBase.class);
}
-
+
/**
*
* @param aBlock - The block you expect.
@@ -107,32 +109,43 @@ public class MultiblockLayer {
* @param aDir - The direction the controller is facing.
* @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) {
+ public boolean getBlockForPos(Block aBlock, int aMeta, int x, int z, ForgeDirection aDir) {
+ Logger.INFO("Grid Index X: "+x+" | Z: "+z + " | "+aDir.name());
LayerBlockData g;
- if (aDir == ForgeDirection.NORTH) {
- g = mVariantOrientations.get(0)[x][z];
- }
- else if (aDir == ForgeDirection.EAST) {
- g = mVariantOrientations.get(1)[x][z];
- }
- else if (aDir == ForgeDirection.SOUTH) {
+ if (aDir == ForgeDirection.SOUTH) {
g = mVariantOrientations.get(2)[x][z];
}
else if (aDir == ForgeDirection.WEST) {
g = mVariantOrientations.get(3)[x][z];
}
+ else if (aDir == ForgeDirection.NORTH) {
+ LayerBlockData[][] aData = mVariantOrientations.get(0);
+ if (aData != null) {
+ Logger.INFO("Found Valid Orientation Data. "+aData.length + ", "+aData[0].length);
+ g = aData[x][z];
+ }
+ else {
+ Logger.INFO("Did not find valid orientation data.");
+ g = null;
+ }
+ }
+ else if (aDir == ForgeDirection.EAST) {
+ g = mVariantOrientations.get(1)[x][z];
+ }
else {
g = mLayerData[x][z];
}
if (g == null) {
- return false;
+ /*Logger.INFO("Failed to find LayerBlockData.");
+ return false;*/
+ g = LayerBlockData.FALLBACK_AIR_CHECK;
}
-
+
return g.match(aBlock, aMeta);
}
-
-
-
+
+
+
/**
* Is this layer final?
* @return - If true, layer data cannot be edited.
@@ -148,27 +161,64 @@ public class MultiblockLayer {
*/
public final void lock(boolean lockData) {
if (!lockData) {
+ Logger.INFO("Failed to lock layer");
return;
}
+ Logger.INFO("Trying to lock layer");
this.mFinalised = true;
generateOrientations();
+ Logger.INFO("Trying to Build Blueprint Layer [Constructed orietations & finalized]");
}
-
+
private void generateOrientations() {
- //North
- mVariantOrientations.put(mLayerData);
- LayerBlockData[][] val;
- //East
- val = ArrayUtils.rotateArrayClockwise(mLayerData);
- mVariantOrientations.put(val);
- //South
- val = ArrayUtils.rotateArrayClockwise(mLayerData);
- mVariantOrientations.put(val);
- //West
- val = ArrayUtils.rotateArrayClockwise(mLayerData);
- mVariantOrientations.put(val);
+ try {
+
+ Logger.INFO("Trying to gen orients for layer");
+ //North
+ mVariantOrientations.put(mLayerData);
+ LayerBlockData[][] val;
+ Logger.INFO("1 done");
+ //East
+ val = rotateArrayClockwise(mLayerData);
+ mVariantOrientations.put((LayerBlockData[][]) val);
+ Logger.INFO("2 done");
+ //South
+ val = rotateArrayClockwise(mLayerData);
+ mVariantOrientations.put((LayerBlockData[][]) val);
+ Logger.INFO("3 done");
+ //West
+ val = rotateArrayClockwise(mLayerData);
+ mVariantOrientations.put((LayerBlockData[][]) val);
+ Logger.INFO("4 done");
+
+ }
+ catch (Throwable t) {
+ t.printStackTrace();
+ }
}
-
+
+ public static LayerBlockData[][] rotateArrayClockwise(LayerBlockData[][] mat) {
+ 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);
+ 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");
+ return ret;
+ }
+ catch (Throwable t) {
+ t.printStackTrace();
+ return null;
+ }
+ }
+
public boolean hasController() {
if (getControllerLocation() == null) {
return false;
@@ -186,22 +236,22 @@ public class MultiblockLayer {
}
this.mControllerLocation = mControllerLocation;
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/**
* Generates a complete {@link MultiblockLayer} from String data.
@@ -211,7 +261,7 @@ public class MultiblockLayer {
*/
public static MultiblockLayer generateLayerFromData(HashMap<String, Pair<Block, Integer>> aDataMap, String[] aHorizontalStringRows) {
AutoMap<Pair<String, Pair<Block, Integer>>> x = new AutoMap<Pair<String, Pair<Block, Integer>>>();
-
+
for (String u : aDataMap.keySet()) {
Pair<Block, Integer> r = aDataMap.get(u);
if (r != null) {
@@ -228,8 +278,8 @@ public class MultiblockLayer {
}*/
return generateLayerFromData(x, aHorizontalStringRows);
}
-
-
+
+
/**
* Generates a complete {@link MultiblockLayer} from String data.
* @param aDataMap - An {@link AutoMap} which contains {@link Pair}s. These Pairs hold a single character {@link String} and another Pair. This inner pair holds a {@link Block} and an {@link Integer}.
@@ -241,13 +291,13 @@ public class MultiblockLayer {
int depth = aHorizontalStringRows.length;
MultiblockLayer L = new MultiblockLayer(width, depth);
HashMap<String, Pair<Block, Integer>> K = new HashMap<String, Pair<Block, Integer>>();
-
+
//24 Free Letters
//C = Controller
//H = Hatch
String aFreeLetters = "abdefgijklmnopqrstuvwxyz";
AutoMap<Pair<String, Pair<Block, Integer>>> j = new AutoMap<Pair<String, Pair<Block, Integer>>>();
-
+
//Map the keys to a Hashmap
for (Pair<String, Pair<Block, Integer>> t : aDataMap) {
String aKeyTemp = t.getKey();
@@ -262,7 +312,7 @@ public class MultiblockLayer {
aFreeLetters.replace(aKeyTemp.toLowerCase(), "");
}
}
-
+
//Map any Invalid Characters to new ones, in case someone uses C/H.
if (j.size() > 0) {
for (Pair<String, Pair<Block, Integer>> h : j) {
@@ -271,10 +321,10 @@ public class MultiblockLayer {
aFreeLetters.replace(newKey.toLowerCase(), "");
}
}
-
+
int xPos = 0;
int zPos = 0;
-
+
//Vertical Iterator
for (String s : aHorizontalStringRows) {
//Horizontal Iterator
@@ -306,45 +356,47 @@ public class MultiblockLayer {
- public class LayerBlockData{
+ public static class LayerBlockData{
+
+ public static final LayerBlockData FALLBACK_AIR_CHECK = new LayerBlockData(Blocks.air, 0, false);
public final Block mBlock;
public final int mMeta;
public final boolean canBeHatch;
public final Class mHatchClass;
-
+
private final boolean isController;
-
+
public LayerBlockData(Block aBlock, int aMeta, boolean aHatch) {
this(aBlock, aMeta, aHatch, null);
}
-
+
public LayerBlockData(Block aBlock, int aMeta, boolean aHatch, Class clazz) {
mBlock = aBlock;
mMeta = aMeta;
canBeHatch = aHatch;
mHatchClass = clazz;
- if (clazz.equals(GT_MetaTileEntity_MultiBlockBase.class)) {
+ if (clazz != null && clazz.equals(GT_MetaTileEntity_MultiBlockBase.class)) {
isController = true;
}
else {
isController = false;
}
}
-
+
public boolean match(Block blockToTest, int metaToTest) {
-
+
//If Both are some kind of Air Block, good enough.
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 Block does Match, is not controller, is not hatch and Meta does not match
if (!isController && !canBeHatch && metaToTest != mMeta) {
return false;
@@ -352,5 +404,5 @@ public class MultiblockLayer {
return true;
}
}
-
+
}