diff options
author | Technus <daniel112092@gmail.com> | 2017-03-22 10:27:27 +0100 |
---|---|---|
committer | Technus <daniel112092@gmail.com> | 2017-03-22 10:27:27 +0100 |
commit | 5cc1821de4c8711eb5021646f66c013eba6e6754 (patch) | |
tree | d49b51d2090d28b33d7fc36608951674fd106fe2 | |
parent | eaf0d941ed7c841cb1d94f7c979691bdbe66e72c (diff) | |
download | GT5-Unofficial-5cc1821de4c8711eb5021646f66c013eba6e6754.tar.gz GT5-Unofficial-5cc1821de4c8711eb5021646f66c013eba6e6754.tar.bz2 GT5-Unofficial-5cc1821de4c8711eb5021646f66c013eba6e6754.zip |
Rework structure check, allowing it to check vertical placed blocks
6 files changed, 195 insertions, 181 deletions
diff --git a/src/main/java/com/github/technus/tectech/Util.java b/src/main/java/com/github/technus/tectech/Util.java index 87df06e7d9..05594ce1d5 100644 --- a/src/main/java/com/github/technus/tectech/Util.java +++ b/src/main/java/com/github/technus/tectech/Util.java @@ -1,5 +1,14 @@ package com.github.technus.tectech; +import gregtech.api.GregTech_API; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.fluids.FluidStack; + /** * Created by Tec on 21.03.2017. */ @@ -18,4 +27,177 @@ public class Util { return result.toString(); } + + //Check Machine Structure based on string[][] (effectively char[][][]), ond offset of the controller + //This only checks for REGULAR BLOCKS! + public static boolean StuctureCheck(String[][] structure,//0-9 casing, +- air no air, a... ignore 'a'-CHAR-1 blocks + Block[] blockType,//use numbers 0-9 for casing types + byte[] blockMeta,//use numbers 0-9 for casing types + int horizontalOffset, int verticalOffset, int depthOffset, + IGregTechTileEntity aBaseMetaTileEntity, + boolean forceCheck) { + //TE Rotation + byte facing = aBaseMetaTileEntity.getFrontFacing(); + World world=aBaseMetaTileEntity.getWorld(); + + int x, y, z, a, b, c,yPos; + //a,b,c - relative to block face! + //x,y,z - relative to block position on map! + //yPos - absolute height of checked block + + //perform your duties + c = -depthOffset; + for (String[] _structure : structure) {//front to back + b = verticalOffset; + for (String __structure : _structure) {//top to bottom + a = -horizontalOffset; + for (char block : __structure.toCharArray()) {//left to right + if (block > '`') {//characters allow to skip check a-1 skip, b-2 skips etc. + a += block - '`'; + } else { + //get x y z from rotation + switch (facing) {//translation + case 4: x = +c; z = +a; y = +b; break; + case 3: x = +a; z = -c; y = +b; break; + case 5: x = -c; z = -a; y = +b; break; + case 2: x = -a; z = +c; y = +b; break; + //Things get odd if the block faces up or down... + case 1: x = +a; y = -c; z = +b; break;//similar to 3 + case 0: x = -a; y = +c; z = -b; break;//similar to 2 + default: return false; + } + //that must be here since in some cases other axis (a,b,c) controls y + yPos=aBaseMetaTileEntity.getYCoord()+y; + if(yPos<0 || yPos>=256) return false; + //Check block + if (forceCheck||world.blockExists(x,y,z)) + switch (block) { + case '-'://must be air + if (!aBaseMetaTileEntity.getAirOffset(x, y, z)) return false; + break; + case '+'://must not be air + if (aBaseMetaTileEntity.getAirOffset(x, y, z)) return false; + break; + default: {//check for block (countable) + int pointer = block - '0'; + //countable air -> net.minecraft.block.BlockAir + if (aBaseMetaTileEntity.getBlockOffset(x, y, z) != blockType[pointer]) { + if (TecTech.ModConfig.DEBUG_MODE) + TecTech.Logger.info("Struct-block-error " + x + " " + y + " " + z + "/" + a + " " + c + "/" + aBaseMetaTileEntity.getBlockOffset(x, y, z) + " " + blockType[pointer]); + return false; + } + if (aBaseMetaTileEntity.getMetaIDOffset(x, y, z) != blockMeta[pointer]) { + if (TecTech.ModConfig.DEBUG_MODE) + TecTech.Logger.info("Struct-meta-id-error " + x + " " + y + " " + z + "/" + a + " " + c + "/" + aBaseMetaTileEntity.getMetaIDOffset(x, y, z) + " " + blockMeta[pointer]); + return false; + } + } + } + a++;//block in horizontal layer + } + } + b--;//horizontal layer + } + c++;//depth + } + return true; + } + + public static boolean isInputEqual(boolean aDecreaseStacksizeBySuccess, boolean aDontCheckStackSizes, FluidStack[] requiredFluidInputs, ItemStack[] requiredInputs, FluidStack[] givenFluidInputs, ItemStack... givenInputs) { + if (!GregTech_API.sPostloadFinished) return false; + if (requiredFluidInputs.length > 0 && givenFluidInputs == null) return false; + int amt; + for (FluidStack tFluid : requiredFluidInputs) + if (tFluid != null) { + boolean temp = true; + amt = tFluid.amount; + for (FluidStack aFluid : givenFluidInputs) + if (aFluid != null && aFluid.isFluidEqual(tFluid)) { + if (aDontCheckStackSizes) { + temp = false; + break; + } + amt -= aFluid.amount; + if (amt < 1) { + temp = false; + break; + } + } + if (temp) return false; + } + + if (requiredInputs.length > 0 && givenInputs == null) return false; + for (ItemStack tStack : requiredInputs) { + if (tStack != null) { + amt = tStack.stackSize; + boolean temp = true; + for (ItemStack aStack : givenInputs) { + if ((GT_Utility.areUnificationsEqual(aStack, tStack, true) || GT_Utility.areUnificationsEqual(GT_OreDictUnificator.get(false, aStack), tStack, true))) { + if (aDontCheckStackSizes) { + temp = false; + break; + } + amt -= aStack.stackSize; + if (amt < 1) { + temp = false; + break; + } + } + } + if (temp) return false; + } + } + + if (aDecreaseStacksizeBySuccess) { + if (givenFluidInputs != null) { + for (FluidStack tFluid : requiredFluidInputs) { + if (tFluid != null) { + amt = tFluid.amount; + for (FluidStack aFluid : givenFluidInputs) { + if (aFluid != null && aFluid.isFluidEqual(tFluid)) { + if (aDontCheckStackSizes) { + aFluid.amount -= amt; + break; + } + if (aFluid.amount < amt) { + amt -= aFluid.amount; + aFluid.amount = 0; + } else { + aFluid.amount -= amt; + amt = 0; + break; + } + } + } + } + } + } + + if (givenInputs != null) { + for (ItemStack tStack : requiredInputs) { + if (tStack != null) { + amt = tStack.stackSize; + for (ItemStack aStack : givenInputs) { + if ((GT_Utility.areUnificationsEqual(aStack, tStack, true) || GT_Utility.areUnificationsEqual(GT_OreDictUnificator.get(false, aStack), tStack, true))) { + if (aDontCheckStackSizes) { + aStack.stackSize -= amt; + break; + } + if (aStack.stackSize < amt) { + amt -= aStack.stackSize; + aStack.stackSize = 0; + } else { + aStack.stackSize -= amt; + amt = 0; + break; + } + } + } + } + } + } + } + + return true; + } } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_bhg.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_bhg.java index 1bbcb939e8..f2f7d5ebe1 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_bhg.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_bhg.java @@ -80,14 +80,14 @@ public class GT_MetaTileEntity_EM_bhg extends GT_MetaTileEntity_MultiblockBase_E @Override public boolean checkMachine(IGregTechTileEntity iGregTechTileEntity, ItemStack itemStack) { - return stuctureCheck(shape, blockType, blockMeta, 7, 7, 0, iGregTechTileEntity); + return EM_StructureCheck(shape, blockType, blockMeta, 7, 7, 0); } @Override public String[] getDescription() { return new String[]{ commonValues.tecMark, - "Singularity decay based power generation.", + "Singularity based power generation.", EnumChatFormatting.AQUA.toString() + EnumChatFormatting.BOLD + "Super unstable!!!" }; } diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_infuser.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_infuser.java index f41c55e98b..2c52d1a98d 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_infuser.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_infuser.java @@ -3,19 +3,16 @@ package com.github.technus.tectech.thing.metaTileEntity.multi; import cofh.api.energy.IEnergyContainerItem; import com.github.technus.tectech.TecTech; import com.github.technus.tectech.elementalMatter.commonValues; -import com.github.technus.tectech.thing.metaTileEntity.multi.gui.GT_GUIContainer_MultiMachineEM; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import ic2.api.item.ElectricItem; import ic2.api.item.IElectricItem; import net.minecraft.block.Block; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.common.util.ForgeDirection; -import static com.github.technus.tectech.elementalMatter.commonValues.multiCheckAt; import static com.github.technus.tectech.thing.casing.GT_Container_CasingsTT.sBlockCasingsTT; import static gregtech.api.GregTech_API.mEUtoRF; diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_quantizer.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_quantizer.java index 706a8b7958..ecfc1dc2a9 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_quantizer.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_quantizer.java @@ -24,6 +24,7 @@ import net.minecraftforge.oredict.OreDictionary; import java.util.HashMap; +import static com.github.technus.tectech.Util.isInputEqual; import static com.github.technus.tectech.elementalMatter.definitions.dAtomDefinition.getBestUnstableIsotope; import static com.github.technus.tectech.elementalMatter.definitions.dAtomDefinition.getFirstStableIsotope; import static gregtech.api.enums.GT_Values.V; diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_transformer.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_transformer.java index 5cc48e65dc..f5e15c088d 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_transformer.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_transformer.java @@ -1,15 +1,12 @@ package com.github.technus.tectech.thing.metaTileEntity.multi; import com.github.technus.tectech.elementalMatter.commonValues; -import com.github.technus.tectech.thing.metaTileEntity.multi.gui.GT_GUIContainer_MultiMachineEM; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.common.util.ForgeDirection; -import static com.github.technus.tectech.elementalMatter.commonValues.multiCheckAt; import static com.github.technus.tectech.thing.casing.GT_Container_CasingsTT.sBlockCasingsTT; /** diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_MultiblockBase_EM.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_MultiblockBase_EM.java index 779cb2ca26..8baa6dfba2 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_MultiblockBase_EM.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_MultiblockBase_EM.java @@ -10,7 +10,6 @@ import com.github.technus.tectech.thing.machineTT; import com.github.technus.tectech.thing.metaTileEntity.hatch.*; import com.github.technus.tectech.thing.metaTileEntity.multi.gui.GT_Container_MultiMachineEM; import com.github.technus.tectech.thing.metaTileEntity.multi.gui.GT_GUIContainer_MultiMachineEM; -import gregtech.api.GregTech_API; import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; @@ -18,7 +17,6 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.*; import gregtech.api.objects.GT_RenderedTexture; -import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; import gregtech.common.GT_Pollution; @@ -33,6 +31,7 @@ import net.minecraftforge.fluids.FluidStack; import java.util.ArrayList; +import static com.github.technus.tectech.Util.StuctureCheck; import static com.github.technus.tectech.elementalMatter.commonValues.*; import static gregtech.api.enums.GT_Values.V; import static gregtech.api.enums.GT_Values.VN; @@ -161,6 +160,7 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt aNBT.setBoolean("ePass", ePowerPass); aNBT.setBoolean("eVoid", eSafeVoid); aNBT.setBoolean("eBoom", eDismatleBoom); + aNBT.setBoolean("eOK", mMachine); if (outputEM != null) { aNBT.setInteger("outputStackCount", outputEM.length); @@ -211,6 +211,7 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt ePowerPass = aNBT.getBoolean("ePass"); eSafeVoid = aNBT.getBoolean("eVoid"); eDismatleBoom = aNBT.getBoolean("eBoom"); + mMachine = aNBT.getBoolean("eOK"); //Fix supermethod shit. mOutputItems = new ItemStack[aNBT.getInteger("eItemsOut")]; @@ -1205,79 +1206,13 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt return true; } - //Check Machine Structure based on string array array, ond offset of the controller - public static boolean stuctureCheck(String[][] structure,//0-9 casing, +- air no air, a-z ignore - Block[] blockType,//use numbers 0-9 for casing types - byte[] blockMeta,//use numbers 0-9 for casing types - int horizontalOffset, int verticalOffset, int depthOffset, - IGregTechTileEntity aBaseMetaTileEntity) { - //TE Rotation - byte facing = aBaseMetaTileEntity.getFrontFacing(); - - int x, y, z, a, c;//b is y no matter what - - //perform your duties - c = -depthOffset; - for (String[] _structure : structure) {//front to back - y = verticalOffset; - for (String __structure : _structure) {//top to bottom - a = -horizontalOffset; - for (char block : __structure.toCharArray()) {//left to right - if (block > '`') {//small characters allow to skip check a-1 skip, b-2 skips etc. - a += block - '`'; - } else { - //get x y z from rotation - switch (facing) {//translation - case 4: - x = c; - z = a; - break; - case 3: - x = a; - z = -c; - break; - case 5: - x = -c; - z = -a; - break; - case 2: - x = -a; - z = c; - break; - default: - return false; - } - //Check block - switch (block) { - case '-'://must be air - if (!aBaseMetaTileEntity.getAirOffset(x, y, z)) return false; - break; - case '+'://must not be air - if (aBaseMetaTileEntity.getAirOffset(x, y, z)) return false; - break; - default: {//check for block (countable) - int pointer = block - '0'; - //countable air -> net.minecraft.block.BlockAir - if (aBaseMetaTileEntity.getBlockOffset(x, y, z) != blockType[pointer]) { - if (TecTech.ModConfig.DEBUG_MODE) - TecTech.Logger.info("Struct-block-error " + x + " " + y + " " + z + "/" + a + " " + c + "/" + aBaseMetaTileEntity.getBlockOffset(x, y, z) + " " + blockType[pointer]); - return false; - } - if (aBaseMetaTileEntity.getMetaIDOffset(x, y, z) != blockMeta[pointer]) { - if (TecTech.ModConfig.DEBUG_MODE) - TecTech.Logger.info("Struct-meta-id-error " + x + " " + y + " " + z + "/" + a + " " + c + "/" + aBaseMetaTileEntity.getMetaIDOffset(x, y, z) + " " + blockMeta[pointer]); - return false; - } - } - } - a++;//block in horizontal layer - } - } - y--;//horizontal layer - } - c++;//depth - } - return true; + //can be used to check structures of multi-blocks larger than one chunk, but... + //ALL THE HATCHES AND THE CONTROLLER SHOULD BE IN ONE CHUNK OR IN LOADED CHUNKS + public final boolean EM_StructureCheck(String[][] structure,//0-9 casing, +- air no air, a-z ignore + Block[] blockType,//use numbers 0-9 for casing types + byte[] blockMeta,//use numbers 0-9 for casing types + int horizontalOffset, int verticalOffset, int depthOffset){ + return StuctureCheck(structure,blockType,blockMeta,horizontalOffset,verticalOffset,depthOffset,getBaseMetaTileEntity(),!mMachine); } @Override @@ -1319,102 +1254,4 @@ public abstract class GT_MetaTileEntity_MultiblockBase_EM extends GT_MetaTileEnt if (TecTech.ModConfig.DEBUG_MODE) e.printStackTrace(); } } - - protected boolean isInputEqual(boolean aDecreaseStacksizeBySuccess, boolean aDontCheckStackSizes, FluidStack[] requiredFluidInputs, ItemStack[] requiredInputs, FluidStack[] givenFluidInputs, ItemStack... givenInputs) { - if (!GregTech_API.sPostloadFinished) return false; - if (requiredFluidInputs.length > 0 && givenFluidInputs == null) return false; - int amt; - for (FluidStack tFluid : requiredFluidInputs) - if (tFluid != null) { - boolean temp = true; - amt = tFluid.amount; - for (FluidStack aFluid : givenFluidInputs) - if (aFluid != null && aFluid.isFluidEqual(tFluid)) { - if (aDontCheckStackSizes) { - temp = false; - break; - } - amt -= aFluid.amount; - if (amt < 1) { - temp = false; - break; - } - } - if (temp) return false; - } - - if (requiredInputs.length > 0 && givenInputs == null) return false; - for (ItemStack tStack : requiredInputs) { - if (tStack != null) { - amt = tStack.stackSize; - boolean temp = true; - for (ItemStack aStack : givenInputs) { - if ((GT_Utility.areUnificationsEqual(aStack, tStack, true) || GT_Utility.areUnificationsEqual(GT_OreDictUnificator.get(false, aStack), tStack, true))) { - if (aDontCheckStackSizes) { - temp = false; - break; - } - amt -= aStack.stackSize; - if (amt < 1) { - temp = false; - break; - } - } - } - if (temp) return false; - } - } - - if (aDecreaseStacksizeBySuccess) { - if (givenFluidInputs != null) { - for (FluidStack tFluid : requiredFluidInputs) { - if (tFluid != null) { - amt = tFluid.amount; - for (FluidStack aFluid : givenFluidInputs) { - if (aFluid != null && aFluid.isFluidEqual(tFluid)) { - if (aDontCheckStackSizes) { - aFluid.amount -= amt; - break; - } - if (aFluid.amount < amt) { - amt -= aFluid.amount; - aFluid.amount = 0; - } else { - aFluid.amount -= amt; - amt = 0; - break; - } - } - } - } - } - } - - if (givenInputs != null) { - for (ItemStack tStack : requiredInputs) { - if (tStack != null) { - amt = tStack.stackSize; - for (ItemStack aStack : givenInputs) { - if ((GT_Utility.areUnificationsEqual(aStack, tStack, true) || GT_Utility.areUnificationsEqual(GT_OreDictUnificator.get(false, aStack), tStack, true))) { - if (aDontCheckStackSizes) { - aStack.stackSize -= amt; - break; - } - if (aStack.stackSize < amt) { - amt -= aStack.stackSize; - aStack.stackSize = 0; - } else { - aStack.stackSize -= amt; - amt = 0; - break; - } - } - } - } - } - } - } - - return true; - } } |