diff options
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockLayer.java')
-rw-r--r-- | src/Java/gtPlusPlus/xmod/gregtech/api/objects/MultiblockLayer.java | 200 |
1 files changed, 126 insertions, 74 deletions
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; } } - + } |