diff options
Diffstat (limited to 'src/main/java/gregtech/common')
13 files changed, 1312 insertions, 879 deletions
diff --git a/src/main/java/gregtech/common/blocks/GT_Block_Casings5.java b/src/main/java/gregtech/common/blocks/GT_Block_Casings5.java index 995de490e8..1ccd1f7164 100644 --- a/src/main/java/gregtech/common/blocks/GT_Block_Casings5.java +++ b/src/main/java/gregtech/common/blocks/GT_Block_Casings5.java @@ -2,14 +2,21 @@ package gregtech.common.blocks; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.HeatingCoilLevel; import gregtech.api.enums.ItemList; import gregtech.api.enums.Textures; +import gregtech.api.interfaces.IHeatingCoil; import gregtech.api.objects.GT_CopiedBlockTexture; import gregtech.api.util.GT_LanguageManager; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; -public class GT_Block_Casings5 extends GT_Block_Casings_Abstract { +import java.util.function.Consumer; + +import static gregtech.api.enums.HeatingCoilLevel.*; + +public class GT_Block_Casings5 extends GT_Block_Casings_Abstract implements IHeatingCoil { + public GT_Block_Casings5() { super(GT_Item_Casings5.class, "gt.blockcasings5", GT_Material_Casings.INSTANCE); for (byte i = 0; i < 16; i = (byte) (i + 1)) { @@ -24,6 +31,8 @@ public class GT_Block_Casings5 extends GT_Block_Casings_Abstract { GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".6.name", "Naquadah Alloy Coil Block"); GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".7.name", "Electrum Flux Coil Block"); GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".8.name", "Awakened Draconium Coil Block"); + GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".9.name", "HSS-S Coil Block"); + GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".10.name", "Trinium Coil Block"); ItemList.Casing_Coil_Cupronickel.set(new ItemStack(this, 1, 0)); ItemList.Casing_Coil_Kanthal.set(new ItemStack(this, 1, 1)); @@ -34,7 +43,10 @@ public class GT_Block_Casings5 extends GT_Block_Casings_Abstract { ItemList.Casing_Coil_NaquadahAlloy.set(new ItemStack(this, 1, 6)); ItemList.Casing_Coil_ElectrumFlux.set(new ItemStack(this, 1, 7)); ItemList.Casing_Coil_AwakenedDraconium.set(new ItemStack(this, 1, 8)); + ItemList.Casing_Coil_HSSS.set(new ItemStack(this, 1, 9)); + ItemList.Casing_Coil_Trinium.set(new ItemStack(this, 1, 10)); } + @Override @SideOnly(Side.CLIENT) public IIcon getIcon(int aSide, int aMeta) { @@ -57,7 +69,62 @@ public class GT_Block_Casings5 extends GT_Block_Casings_Abstract { return Textures.BlockIcons.MACHINE_COIL_ELECTRUMFLUX.getIcon(); case 8: return Textures.BlockIcons.MACHINE_COIL_AWAKENEDDRACONIUM.getIcon(); + case 9: + return Textures.BlockIcons.MACHINE_COIL_HSSS.getIcon(); + case 10: + return Textures.BlockIcons.MACHINE_COIL_TRINIUM.getIcon(); } return Textures.BlockIcons.MACHINE_COIL_CUPRONICKEL.getIcon(); } -} + + /*--------------- COIL CHECK IMPL. ------------*/ + + public static HeatingCoilLevel getCoilHeatFromDamage(int meta) { + switch (meta) { + case 0: + return LV; + case 1: + return MV; + case 2: + return HV; + case 3: + return EV; + case 4: + return IV; + case 5: + return ZPM; + case 6: + return UV; + case 7: + return UEV; + case 8: + return UIV; + case 9: + return LuV; + case 10: + return UHV; + default: + return None; + } + } + + @Override + public HeatingCoilLevel getCoilHeat(int meta) { + getOnCoilCheck().accept(this); + return getCoilHeatFromDamage(meta); + } + + /*--------------- CALLBACK ------------*/ + + private Consumer<IHeatingCoil> callback = coil -> {}; + + @Override + public void setOnCoilCheck(Consumer<IHeatingCoil> callback) { + this.callback = callback; + } + + @Override + public Consumer<IHeatingCoil> getOnCoilCheck() { + return this.callback; + } +}
\ No newline at end of file diff --git a/src/main/java/gregtech/common/blocks/GT_Item_Casings5.java b/src/main/java/gregtech/common/blocks/GT_Item_Casings5.java index 38ad1a668c..f3e58d2acc 100644 --- a/src/main/java/gregtech/common/blocks/GT_Item_Casings5.java +++ b/src/main/java/gregtech/common/blocks/GT_Item_Casings5.java @@ -2,6 +2,8 @@ package gregtech.common.blocks; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.HeatingCoilLevel; +import gregtech.api.util.GT_LanguageManager; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -12,37 +14,18 @@ public class GT_Item_Casings5 extends GT_Item_Casings_Abstract { public GT_Item_Casings5(Block par1) { super(par1); } + + protected static final String mCoilHeatTooltip = GT_LanguageManager.addStringLocalization("gt.coilheattooltip", "Base Heating Capacity = "); + protected static final String mCoilUnitTooltip = GT_LanguageManager.addStringLocalization("gt.coilunittooltip", " Kelvin"); + protected static final String mCoilTierTooltip = GT_LanguageManager.addStringLocalization("gt.coiltiertooltip", "Coil Tier = "); + @Override @SideOnly(Side.CLIENT) + @SuppressWarnings("unchecked") public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List aList, boolean aF3_H) { super.addInformation(aStack, aPlayer, aList, aF3_H); - switch (getDamage(aStack)) { - case 0: - aList.add(this.mCoil01Tooltip); - break; - case 1: - aList.add(this.mCoil02Tooltip); - break; - case 2: - aList.add(this.mCoil03Tooltip); - break; - case 3: - aList.add(this.mCoil04Tooltip); - break; - case 4: - aList.add(this.mCoil05Tooltip); - break; - case 5: - aList.add(this.mCoil06Tooltip); - break; - case 6: - aList.add(this.mCoil07Tooltip); - break; - case 7: - aList.add(this.mCoil08Tooltip); - break; - case 8: - aList.add(this.mCoil09Tooltip); - } + HeatingCoilLevel coilLevel = GT_Block_Casings5.getCoilHeatFromDamage(aStack.getItemDamage()); + aList.add(mCoilHeatTooltip + coilLevel.getHeat() + mCoilUnitTooltip); + aList.add(mCoilTierTooltip + coilLevel.getTierName()); } } diff --git a/src/main/java/gregtech/common/blocks/GT_Item_Machines.java b/src/main/java/gregtech/common/blocks/GT_Item_Machines.java index 0b3cc6182a..917f31f9ce 100644 --- a/src/main/java/gregtech/common/blocks/GT_Item_Machines.java +++ b/src/main/java/gregtech/common/blocks/GT_Item_Machines.java @@ -64,10 +64,12 @@ public class GT_Item_Machines extends ItemBlock { } if (tTileEntity.getEUCapacity() > 0L) { if (tTileEntity.getInputVoltage() > 0L) { - aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_IN", "Voltage IN: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.GREEN + tTileEntity.getInputVoltage() + " (" + GT_Values.VN[GT_Utility.getTier(tTileEntity.getInputVoltage())] + ")" + EnumChatFormatting.GRAY); + int inputTier = GT_Utility.getTier(tTileEntity.getInputVoltage()); + aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_IN", "Voltage IN: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.GREEN + tTileEntity.getInputVoltage() + " (" + GT_Values.TIER_COLORS[inputTier] + GT_Values.VN[inputTier] + EnumChatFormatting.GREEN +")" + EnumChatFormatting.GRAY); } if (tTileEntity.getOutputVoltage() > 0L) { - aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_OUT", "Voltage OUT: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.GREEN + tTileEntity.getOutputVoltage() + " (" + GT_Values.VN[GT_Utility.getTier(tTileEntity.getOutputVoltage())] + ")" + EnumChatFormatting.GRAY); + int outputTier = GT_Utility.getTier(tTileEntity.getOutputVoltage()); + aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_OUT", "Voltage OUT: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.GREEN + tTileEntity.getOutputVoltage() + " (" + GT_Values.TIER_COLORS[outputTier] + GT_Values.VN[outputTier] + EnumChatFormatting.GREEN + ")" + EnumChatFormatting.GRAY); } if (tTileEntity.getOutputAmperage() > 1L) { aList.add(GT_LanguageManager.addStringLocalization("TileEntity_EUp_AMOUNT", "Amperage: ", !GregTech_API.sPostloadFinished ) + EnumChatFormatting.YELLOW + tTileEntity.getOutputAmperage() + EnumChatFormatting.GRAY); diff --git a/src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java b/src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java index 39c87669f1..f8784d570f 100644 --- a/src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java +++ b/src/main/java/gregtech/common/covers/GT_Cover_FluidRegulator.java @@ -50,14 +50,7 @@ public class GT_Cover_FluidRegulator extends GT_CoverBehavior { tLiquid = tLiquid.copy(); tLiquid.amount = tTank2.fill(directionTo, tLiquid, false); if (tLiquid.amount > 0) { - if (aTileEntity.getUniversalEnergyCapacity() >= Math.min(1, tLiquid.amount / 10)) { - if (aTileEntity.isUniversalEnergyStored(Math.min(1, tLiquid.amount / 10))) { - aTileEntity.decreaseStoredEnergyUnits(Math.min(1, tLiquid.amount / 10), true); - tTank2.fill(directionTo, tTank1.drain(directionFrom, tLiquid.amount, true), true); - } - } else { - tTank2.fill(directionTo, tTank1.drain(directionFrom, tLiquid.amount, true), true); - } + tTank2.fill(directionTo, tTank1.drain(directionFrom, tLiquid.amount, true), true); } } } diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java index 6605d4fc35..4e80b7b779 100644 --- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java +++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ChestBuffer.java @@ -19,7 +19,7 @@ import java.util.Comparator; public class GT_MetaTileEntity_ChestBuffer extends GT_MetaTileEntity_Buffer { - private static final int[] tickRate = {400, 200, 100, 20, 4, 1, 1, 1,1,1}; + private static final int[] tickRate = {400, 200, 100, 20, 4, 1, 1, 1, 1, 1, 1, 1, 1}; public GT_MetaTileEntity_ChestBuffer(int aID, String aName, String aNameRegional, int aTier) { diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ItemDistributor.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ItemDistributor.java index 5fa3bc8c82..37d8585310 100644 --- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ItemDistributor.java +++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_ItemDistributor.java @@ -143,7 +143,6 @@ public class GT_MetaTileEntity_ItemDistributor extends GT_MetaTileEntity_Buffer } if (movedItems > 0 || aBaseMetaTileEntity.hasInventoryBeenModified()) { mSuccess = 50; - aBaseMetaTileEntity.decreaseStoredEnergyUnits(Math.abs(movedItems), true); } fillStacksIntoFirstSlots(); } diff --git a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Regulator.java b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Regulator.java index b5a33bfb81..746e182066 100644 --- a/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Regulator.java +++ b/src/main/java/gregtech/common/tileentities/automation/GT_MetaTileEntity_Regulator.java @@ -95,7 +95,6 @@ public class GT_MetaTileEntity_Regulator tCosts = GT_Utility.moveOneItemStackIntoSlot(getBaseMetaTileEntity(), getBaseMetaTileEntity().getTileEntityAtSide(getBaseMetaTileEntity().getBackFacing()), getBaseMetaTileEntity().getBackFacing(), this.mTargetSlots[i], Arrays.asList(new ItemStack[]{this.mInventory[(i + 9)]}), false, (byte) this.mInventory[(i + 9)].stackSize, (byte) this.mInventory[(i + 9)].stackSize, (byte) 64, (byte) 1) * 3; if (tCosts > 0) { this.mSuccess = 50; - getBaseMetaTileEntity().decreaseStoredEnergyUnits(tCosts, true); break; } } diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java index ce1812a9cf..92ed054b05 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Disassembler.java @@ -1,15 +1,34 @@ package gregtech.common.tileentities.machines.basic; -import gregtech.api.enums.GT_Values; +import com.google.common.collect.ArrayListMultimap; +import gregtech.api.GregTech_API; +import gregtech.api.enums.ItemList; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; 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.items.GT_MetaGenerated_Tool; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; +import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.objects.ItemData; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.oredict.OreDictionary; + +import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; +import java.util.stream.IntStream; public class GT_MetaTileEntity_Disassembler extends GT_MetaTileEntity_BasicMachine { @@ -29,79 +48,380 @@ public class GT_MetaTileEntity_Disassembler return new GT_MetaTileEntity_Disassembler(this.mName, this.mTier, this.mDescriptionArray, this.mTextures, this.mGUIName, this.mNEIName); } + private static final ItemStack[][] alwaysReplace = new ItemStack[][]{ + { + //ItemStack to look for + new ItemStack(Blocks.trapped_chest, 1, OreDictionary.WILDCARD_VALUE) + }, + { + //ItemStack to replace + new ItemStack(Blocks.chest) + } + }; + + private static final Object[][] OreDictionaryOverride = new Object[][]{ + { + //String to look for + "plankWood", + "stoneCobble", + "gemDiamond", + "logWood", + "stickWood", + "treeSapling" + }, + { + //ItemStack to replace + new ItemStack(Blocks.planks), + new ItemStack(Blocks.cobblestone), + new ItemStack(Items.diamond), + new ItemStack(Blocks.log), + new ItemStack(Items.stick), + new ItemStack(Blocks.sapling) + } + }; + + public static ArrayListMultimap<GT_ItemStack, ItemStack> getOutputHardOverrides() { + return outputHardOverrides; + } + + private static final ArrayListMultimap<GT_ItemStack, ItemStack> outputHardOverrides; + + static { + outputHardOverrides = ArrayListMultimap.create(); + outputHardOverrides.put(new GT_ItemStack(new ItemStack(Blocks.torch,6)), new ItemStack(Items.stick)); + } + public int checkRecipe() { - //if ((getInputAt(0) != null) && (isOutputEmpty())) { - // if(GT_Utility.areStacksEqual(getInputAt(0), new ItemStack(Items.egg))){ - // getInputAt(0).stackSize -= 1; - // this.mEUt = (16 * (1 << this.mTier - 1) * (1 << this.mTier - 1)); - // this.mMaxProgresstime = 2400; - // this.mMaxProgresstime = this.mMaxProgresstime >> (mTier); - //if (getBaseMetaTileEntity().getRandomNumber(100) < (this.mTier+1)) { - // this.mOutputItems[0] = ItemList.Circuit_Chip_Stemcell.get(1, new Object[0]); - //} - //return 2; - //} - NBTTagCompound tNBT = getInputAt(0).getTagCompound(); - if (tNBT != null) { - tNBT = tNBT.getCompoundTag("GT.CraftingComponents"); - if (tNBT != null) { - boolean isAnyOutput=false; - calculateOverclockedNessDisassembler(16); - this.mMaxProgresstime = 80; - //In case recipe is too OP for that machine - if (mEUt == Integer.MAX_VALUE - 1)//&& mMaxProgresstime==Integer.MAX_VALUE-1 - return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; - for (int i = 0; i < this.mOutputItems.length; i++) { - if (getBaseMetaTileEntity().getRandomNumber(100) < 50 + 10 * this.mTier) { - this.mOutputItems[i] = GT_Utility.loadItem(tNBT, "Ingredient." + i); - if (this.mOutputItems[i] != null) { - this.mMaxProgresstime *= 1.7F; - isAnyOutput=true; - } - } - } - if(!isAnyOutput) - return DID_NOT_FIND_RECIPE; - for(int i=mTier-5;i>0;i--){ - this.mMaxProgresstime>>=1; - if(this.mMaxProgresstime==0) - this.mEUt = this.mEUt>>1; - } - if(this.mEUt==0) - mEUt = 1; - if(this.mMaxProgresstime==0) - this.mMaxProgresstime = 1; - getInputAt(0).stackSize -= 1; - return FOUND_AND_SUCCESSFULLY_USED_RECIPE; - } + ItemStack is = getInputAt(0); + if (GT_Utility.isStackInvalid(is)) + return DID_NOT_FIND_RECIPE; + if (is.getItem() instanceof GT_MetaGenerated_Tool) + return DID_NOT_FIND_RECIPE; + ItemStack comp = new ItemStack(GregTech_API.sBlockMachines); + if (is.getItem() == comp.getItem()) { + IMetaTileEntity iMetaTileEntity = GregTech_API.METATILEENTITIES[is.getItemDamage()]; + if (iMetaTileEntity instanceof GT_MetaTileEntity_TieredMachineBlock && + ((GT_MetaTileEntity_TieredMachineBlock) iMetaTileEntity).mTier > this.mTier) + return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; + } + Set<GT_ItemStack> stacks = outputHardOverrides.keySet(); + for (GT_ItemStack stack : stacks) { + ItemStack in = is.copy(); + in.stackSize = 1; + if (stack.isStackEqual(in) && stack.mStackSize <= is.stackSize) { + return setOutputsAndTime(outputHardOverrides.get(stack).toArray(new ItemStack[0]), stack.mStackSize) + ? FOUND_AND_SUCCESSFULLY_USED_RECIPE + : DID_NOT_FIND_RECIPE; } + } + return process() + ? FOUND_AND_SUCCESSFULLY_USED_RECIPE + : DID_NOT_FIND_RECIPE; + } + + private boolean process(){ + + GT_Recipe gt_recipe = GT_Recipe.GT_Recipe_Map.sDisassemblerRecipes.findRecipe(this.getBaseMetaTileEntity(), true, this.mEUt, null, this.getAllInputs()); + if (gt_recipe != null) { + gt_recipe.isRecipeInputEqual(true, null, this.getRealInventory()); + return setOutputsAndTime(gt_recipe.mOutputs, gt_recipe.mInputs[0].stackSize); + } + + Collection<DissassembleReference> recipes = this.findRecipeFromMachine(); + if (recipes.isEmpty()) + return false; - return DID_NOT_FIND_RECIPE; + DissassembleReference recipe = ensureDowncasting(recipes); + + for (int i = 0; i < recipe.inputs.length; i++) + if (GT_Utility.isStackInvalid(recipe.inputs[i]) || recipe.inputs[i].stackSize < 1) + recipe.inputs[i] = null; + + recipe.inputs = GT_Utility.getArrayListWithoutNulls(recipe.inputs).toArray(new ItemStack[0]); + + return setOutputsAndTime(recipe.inputs, recipe.stackSize); } - private void calculateOverclockedNessDisassembler(int aEUt) { - if(mTier==0){ - mEUt=aEUt>>2; - }else{ - //Long EUt calculation - long xEUt=aEUt; - //Isnt too low EUt check? - long tempEUt = xEUt<GT_Values.V[1] ? GT_Values.V[1] : xEUt; + private boolean setOutputsAndTime(ItemStack[] inputs, int stackSize){ + if (this.getInputAt(0).stackSize >= stackSize) + this.getInputAt(0).stackSize -= stackSize; + else + return false; + + System.arraycopy(inputs, 0, this.mOutputItems, 0, inputs.length); + this.calculateOverclockedNess(30,600); + + return true; + } + + private static DissassembleReference ensureDowncasting(Collection<DissassembleReference> recipes) { + ItemStack[] inputs = recipes.stream() + .findFirst() + .orElseThrow(NullPointerException::new) + .inputs; + + ItemStack[] output = new ItemStack[inputs.length]; + List<GT_Recipe> recipesColl = null; + if (recipes.size() > 1) + recipesColl = recipes.stream() + .skip(1) + .map(x -> x.recipe) + .collect(Collectors.toList()); + + handleRecipeTransformation(inputs, output, recipesColl); - while (tempEUt <= GT_Values.V[mTier -1] * (long)mAmperage) { - tempEUt<<=2;//this actually controls overclocking - xEUt<<=2;//this is effect of overclocking + return new DissassembleReference(recipes.stream().mapToInt(x -> x.stackSize).min().orElseThrow(NumberFormatException::new), output, null); + } + + private static void handleRecipeTransformation(ItemStack[] inputs, ItemStack[] output, List<GT_Recipe> recipesColl) { + for (int i = 0, inputsLength = inputs.length; i < inputsLength; i++) { + Set<ItemStack[]> inputsStacks = null; + if (recipesColl != null) + inputsStacks = recipesColl.stream() + .map(x -> x.mInputs) + .collect(Collectors.toSet()); + ItemStack input = inputs[i]; + ItemData data = GT_OreDictUnificator.getItemData(input); + if (data == null || data.mMaterial == null || data.mMaterial.mMaterial == null || data.mPrefix == null) { + output[i] = input; + continue; } - if(xEUt>Integer.MAX_VALUE-1){ - mEUt = Integer.MAX_VALUE-1; - }else{ - mEUt = (int)xEUt; + handleReplacement(inputsStacks, data, output, input, i); + } + addOthersAndHandleAlwaysReplace(inputs, output); + } + + /** + * Public Interface for ReverseRecipes, do not call inside of this class. + * @param inputs + * @param output + * @param inputsStacks + */ + public static void handleRecipeTransformation(ItemStack[] inputs, ItemStack[] output, Set<ItemStack[]> inputsStacks) { + for (int i = 0, inputsLength = inputs.length; i < inputsLength; i++) { + ItemStack input = inputs[i]; + ItemData data = GT_OreDictUnificator.getItemData(input); + if (data == null || data.mMaterial == null || data.mMaterial.mMaterial == null || data.mPrefix == null) { + output[i] = input; + continue; } + handleReplacement(inputsStacks, data, output, input, i); } + addOthersAndHandleAlwaysReplace(inputs, output); + } + + private static void addOthersAndHandleAlwaysReplace(ItemStack[] inputs, ItemStack[] output){ + for (int i = 0; i < inputs.length; i++) { + //Adds rest of Items + if (output[i] == null) + output[i] = inputs[i]; + + //Math.min the recipe output if Items are the same + if (GT_Utility.areStacksEqual(output[i], inputs[i])) + output[i].stackSize = Math.min(output[i].stackSize, inputs[i].stackSize); + + //Handles replacement Overrides + ItemStack[] itemStacks = GT_MetaTileEntity_Disassembler.alwaysReplace[0]; + for (int j = 0; j < itemStacks.length; j++) { + ItemStack x = itemStacks[j]; + if (GT_Utility.areStacksEqual(x, output[i], true)) { + output[i] = GT_MetaTileEntity_Disassembler.alwaysReplace[1][j]; + break; + } + } + + //Unification + output[i] = handleUnification(output[i]); + } + } + + private static ItemStack handleUnification(ItemStack stack) { + for (int oreID : OreDictionary.getOreIDs(stack)) { + for (int i = 0; i < OreDictionaryOverride[0].length; i++) + if (OreDictionary.getOreName(oreID).equals(OreDictionaryOverride[0][i])){ + ItemStack ret = ((ItemStack) OreDictionaryOverride[1][i]).copy(); + ret.stackSize = stack.stackSize; + return ret; + } + } + return GT_OreDictUnificator.get(stack); + } + + private static void handleReplacement(Set<ItemStack[]> inputsStacks, ItemData data, ItemStack[] output, ItemStack input, int i){ + AtomicReference<Materials> toRpl = new AtomicReference<>(); + Materials first = data.mMaterial.mMaterial; + if (inputsStacks != null) { + handleInputStacks(inputsStacks, toRpl, data, first, i); + } + if (toRpl.get() == null) { + //Remove Magnetic and Annealed Modifiers + handleBetterMaterialsVersions(data, toRpl); + } + if (toRpl.get() != null) { + output[i] = GT_OreDictUnificator.get(data.mPrefix, toRpl.get(), input.stackSize); + return; + } + if (data.mPrefix == OrePrefixes.circuit) { + handleCircuits(first, output, input, i); + } + } + + private static void handleInputStacks(Set<ItemStack[]> inputsStacks, AtomicReference<Materials> toRpl, ItemData data, Materials first, int i){ + final int finalIndex = i; + inputsStacks.forEach(stackArray -> { + ItemData dataAgainst = GT_OreDictUnificator.getItemData(stackArray[finalIndex]); + if ( + dataAgainst == null || + dataAgainst.mMaterial == null || + dataAgainst.mMaterial.mMaterial == null || + dataAgainst.mPrefix == null || + dataAgainst.mPrefix != data.mPrefix + ) { + return; + } + handleDifferentMaterialsOnRecipes(first, dataAgainst.mMaterial.mMaterial, toRpl); + handleAnyMaterials(first,toRpl); + }); + } + + private static void handleAnyMaterials(Materials first, AtomicReference<Materials> toRpl){ + if (first.mOreReRegistrations.stream().anyMatch(y -> y.equals(Materials.AnyIron))) + toRpl.set(Materials.Iron); + else if (first.mOreReRegistrations.stream().anyMatch(y -> y.equals(Materials.AnyCopper))) + toRpl.set(Materials.Copper); + else if (first.mOreReRegistrations.stream().anyMatch(y -> y.equals(Materials.AnyRubber))) + toRpl.set(Materials.Rubber); + else if (first.mOreReRegistrations.stream().anyMatch(y -> y.equals(Materials.AnyBronze))) + toRpl.set(Materials.Bronze); + else if (first.mOreReRegistrations.stream().anyMatch(y -> y.equals(Materials.AnySyntheticRubber))) + toRpl.set(Materials.Rubber); + } + + private static void handleDifferentMaterialsOnRecipes(Materials first, Materials second, AtomicReference<Materials> toRpl){ + if (!first.equals(second)) + if (first.equals(Materials.Aluminium) && second.equals(Materials.Iron)) + toRpl.set(second); + else if (first.equals(Materials.Steel) && second.equals(Materials.Iron)) + toRpl.set(second); + else if (first.equals(Materials.WroughtIron) && second.equals(Materials.Iron)) + toRpl.set(second); + else if (first.equals(Materials.Aluminium) && second.equals(Materials.WroughtIron)) + toRpl.set(Materials.Iron); + else if (first.equals(Materials.Aluminium) && second.equals(Materials.Steel)) + toRpl.set(second); + else if (first.equals(Materials.Polytetrafluoroethylene) && second.equals(Materials.Plastic)) + toRpl.set(second); + else if (first.equals(Materials.Polybenzimidazole) && second.equals(Materials.Plastic)) + toRpl.set(second); + else if (first.equals(Materials.Polystyrene) && second.equals(Materials.Plastic)) + toRpl.set(second); + else if (first.equals(Materials.Silicone) && second.equals(Materials.Plastic)) + toRpl.set(second); + else if (first.equals(Materials.NetherQuartz) || first.equals(Materials.CertusQuartz) && second.equals(Materials.Quartzite)) + toRpl.set(second); + else if (first.equals(Materials.Plastic) && second.equals(Materials.Wood)) + toRpl.set(second); + else if (first.equals(Materials.Diamond) && second.equals(Materials.Glass)) + toRpl.set(second); + } + + private static void handleBetterMaterialsVersions(ItemData data, AtomicReference<Materials> toRpl){ + if (Materials.SteelMagnetic.equals(data.mMaterial.mMaterial)) { + toRpl.set(Materials.Steel); + } else if (Materials.IronMagnetic.equals(data.mMaterial.mMaterial)) { + toRpl.set(Materials.Iron); + } else if (Materials.NeodymiumMagnetic.equals(data.mMaterial.mMaterial)) { + toRpl.set(Materials.Neodymium); + } else if (Materials.SamariumMagnetic.equals(data.mMaterial.mMaterial)) { + toRpl.set(Materials.Samarium); + } else if (Materials.AnnealedCopper.equals(data.mMaterial.mMaterial)) { + toRpl.set(Materials.Copper); + } + } + + @SuppressWarnings("deprecation") + private static void handleCircuits(Materials first, ItemStack[] output, ItemStack input, int i){ + if (first.equals(Materials.Primitive)) + output[i] = ItemList.NandChip.get(input.stackSize); + else if (first.equals(Materials.Basic)) + output[i] = ItemList.Circuit_Microprocessor.get(input.stackSize); + else if (first.equals(Materials.Good)) + output[i] = ItemList.Circuit_Good.get(input.stackSize); + else if (first.equals(Materials.Advanced)) + output[i] = ItemList.Circuit_Advanced.get(input.stackSize); + else if (first.equals(Materials.Data)) + output[i] = ItemList.Circuit_Data.get(input.stackSize); + else if (first.equals(Materials.Master)) + output[i] = ItemList.Circuit_Master.get(input.stackSize); + else if (first.equals(Materials.Ultimate)) + output[i] = ItemList.Circuit_Quantummainframe.get(input.stackSize); + else if (first.equals(Materials.Superconductor)) + output[i] = ItemList.Circuit_Crystalmainframe.get(input.stackSize); + else if (first.equals(Materials.Infinite)) + output[i] = ItemList.Circuit_Wetwaremainframe.get(input.stackSize); + else if (first.equals(Materials.Bio)) + output[i] = ItemList.Circuit_Biomainframe.get(input.stackSize); + } + + static class DissassembleReference { + final int stackSize; + ItemStack[] inputs; + final GT_Recipe recipe; + + public DissassembleReference(int stackSize, ItemStack[] inputs, GT_Recipe recipe) { + this.stackSize = stackSize; + this.inputs = inputs; + this.recipe = recipe; + } + } + + private Collection<DissassembleReference> findRecipeFromMachine() { + ItemStack is = getInputAt(0); + if (GT_Utility.isStackInvalid(is)) + return Collections.emptySet(); + + AtomicInteger stacksize = new AtomicInteger(); + //Check Recipe Maps for creation of Item + List<DissassembleReference> possibleRecipes = GT_Recipe.GT_Recipe_Map.sAssemblerRecipes.mRecipeList.stream() + .filter(x -> Arrays.stream(x.mOutputs) + .anyMatch(y -> + { + ItemStack out = is.copy(); + out.stackSize = y.stackSize; + boolean isDone = GT_Utility.areStacksEqual(y, out, true) && y.stackSize <= is.stackSize; + if (isDone) + stacksize.set(y.stackSize); + return isDone; + }) + ) + .map(x -> new DissassembleReference(stacksize.get(), x.mInputs, x)) + .collect(Collectors.toList()); + + //Is there only one way to create it? + if (possibleRecipes.size() == 1) + return possibleRecipes; + + //There are Multiple Ways -> Get recipe with cheapest inputs + //More Inputs should mean cheaper Materials + return possibleRecipes + .stream() + .sorted(Comparator.comparingDouble(x -> + { + double fluidInputValueRaw = Arrays.stream(x.recipe.mFluidInputs).flatMapToInt(f -> IntStream.of(f.amount)).sum(); + fluidInputValueRaw = fluidInputValueRaw > 0 ? fluidInputValueRaw : 144D; + double inputValue = Arrays.stream(x.inputs).flatMapToInt(f -> IntStream.of(f.stackSize)).sum() + + (fluidInputValueRaw / 144D); + double fluidOutputValueRaw = Arrays.stream(x.recipe.mFluidOutputs).flatMapToInt(f -> IntStream.of(f.amount)).sum(); + fluidOutputValueRaw = fluidOutputValueRaw > 0 ? fluidOutputValueRaw : 144D; + double outputValue = Arrays.stream(x.recipe.mOutputs).flatMapToInt(f -> IntStream.of(f.stackSize)).sum() + + (fluidOutputValueRaw / 144D); + return inputValue / outputValue; + } + )).collect(Collectors.toList()); } public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) { return //(aIndex == 4 && GT_Utility.areStacksEqual(aStack, new ItemStack(Items.egg))) || (super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack)) && (aStack.getTagCompound() != null) && (aStack.getTagCompound().getCompoundTag("GT.CraftingComponents") != null); } -} +}
\ No newline at end of file diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AbstractMultiFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AbstractMultiFurnace.java new file mode 100644 index 0000000000..1ac4df6d73 --- /dev/null +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AbstractMultiFurnace.java @@ -0,0 +1,98 @@ +package gregtech.common.tileentities.machines.multi; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.HeatingCoilLevel; +import gregtech.api.interfaces.IHeatingCoil; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; + +public abstract class GT_MetaTileEntity_AbstractMultiFurnace extends GT_MetaTileEntity_MultiBlockBase { + + private static final int CASING_INDEX = 11; + + protected GT_MetaTileEntity_AbstractMultiFurnace(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + protected GT_MetaTileEntity_AbstractMultiFurnace(String aName) { + super(aName); + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + public boolean isFacingValid(byte aFacing) { + return aFacing > 1; + } + + protected HeatingCoilLevel getInitialHeatLevel(IGregTechTileEntity aBaseMetaTileEntity, int xDir, int zDir) { + Block coil = aBaseMetaTileEntity.getBlockOffset(xDir + 1, 1, zDir); + if (!(coil instanceof IHeatingCoil)) + return null; + IHeatingCoil heatingCoil = (IHeatingCoil) coil; + byte tUsedMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + 1, 1, zDir); + return heatingCoil.getCoilHeat(tUsedMeta); + } + + protected boolean checkStructure(HeatingCoilLevel heatingCap, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity){ + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + if (!checkTopLayer(i, j, xDir, zDir, aBaseMetaTileEntity)) + return false; + + if (!checkBottomLayer(i, j, xDir, zDir, aBaseMetaTileEntity)) + return false; + + if (!checkCoils(heatingCap, i, j, xDir, zDir, aBaseMetaTileEntity)) + return false; + } + } + return true; + } + + protected abstract boolean checkTopLayer(int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity); + protected abstract boolean checkCoils(HeatingCoilLevel heatingCap, int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity); + + protected boolean checkBottomLayer(int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity){ + if ((xDir + i == 0) && (zDir + j == 0)) + return true; + IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, 0, zDir + j); + if (addMaintenanceToMachineList(tTileEntity, CASING_INDEX)) + return true; + if (addInputToMachineList(tTileEntity, CASING_INDEX)) + return true; + if (addOutputToMachineList(tTileEntity, CASING_INDEX)) + return true; + if (addEnergyInputToMachineList(tTileEntity, CASING_INDEX)) + return true; + + if (aBaseMetaTileEntity.getBlockOffset(xDir + i, 0, zDir + j) != GregTech_API.sBlockCasings1) + return false; + return aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 0, zDir + j) == CASING_INDEX; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(ItemStack aStack) { + return 20; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } +} diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java index 061db80ece..488703d2b5 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ElectricBlastFurnace.java @@ -1,42 +1,43 @@ package gregtech.common.tileentities.machines.multi; -import static gregtech.api.enums.GT_Values.V; -import static gregtech.api.enums.GT_Values.VN; - -import java.util.ArrayList; - -import org.lwjgl.input.Keyboard; - import gregtech.api.GregTech_API; +import gregtech.api.enums.HeatingCoilLevel; import gregtech.api.enums.Materials; import gregtech.api.enums.Textures; import gregtech.api.gui.GT_GUIContainer_MultiMachine; +import gregtech.api.interfaces.IHeatingCoil; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; 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_MultiBlockBase; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; +import net.minecraft.block.Block; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; +import org.lwjgl.input.Keyboard; + +import static gregtech.api.enums.GT_Values.V; +import static gregtech.api.enums.GT_Values.VN; public class GT_MetaTileEntity_ElectricBlastFurnace - extends GT_MetaTileEntity_MultiBlockBase { + extends GT_MetaTileEntity_AbstractMultiFurnace { private int mHeatingCapacity = 0; private int controllerY; private FluidStack[] pollutionFluidStacks = new FluidStack[]{Materials.CarbonDioxide.getGas(1000), Materials.CarbonMonoxide.getGas(1000), Materials.SulfurDioxide.getGas(1000)}; + private static final int CASING_INDEX = 11; + public GT_MetaTileEntity_ElectricBlastFurnace(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); } @@ -45,173 +46,168 @@ public class GT_MetaTileEntity_ElectricBlastFurnace super(aName); } + @Override public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_ElectricBlastFurnace(this.mName); } + @Override public String[] getDescription() { - final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType("Blast Furnace") - .addInfo("Controller block for the Electric Blast Furnace") - .addInfo("You can use some fluids to reduce recipe time. Place the circuit in the Input Bus") - .addInfo("Each 900K over the min. Heat required multiplies EU/t by 0.95") - .addInfo("Each 1800K over the min. Heat required allows for one upgraded overclock instead of normal") - .addInfo("Upgraded overclocks reduce recipe time to 25% (instead of 50%) and increase EU/t to 400%") - .addInfo("Additionally gives +100K for every tier past MV") - .addPollutionAmount(20 * getPollutionPerTick(null)) - .addSeparator() - .beginStructureBlock(3, 4, 3, true) - .addController("Front bottom") - .addCasingInfo("Heat Proof Machine Casing", 0) - .addOtherStructurePart("Heating Coils (any tier)", "Two middle Layers") - .addEnergyHatch("Any bottom layer casing") - .addMaintenanceHatch("Any bottom layer casing") - .addMufflerHatch("Top middle") - .addInputBus("Any bottom layer casing") - .addInputHatch("Any bottom layer casing") - .addOutputBus("Any bottom layer casing") - .addOutputHatch("Gasses, Any top layer casing") - .addStructureInfo("Recovery amount scales with Muffler Hatch tier") - .addOutputHatch("Platline fluids, Any bottom layer casing") - .toolTipFinisher("Gregtech"); - if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { - return tt.getInformation(); - } else { - return tt.getStructureInformation(); - } + final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType("Blast Furnace") + .addInfo("Controller block for the Electric Blast Furnace") + .addInfo("You can use some fluids to reduce recipe time. Place the circuit in the Input Bus") + .addInfo("Each 900K over the min. Heat required multiplies EU/t by 0.95") + .addInfo("Each 1800K over the min. Heat required allows for one upgraded overclock instead of normal") + .addInfo("Upgraded overclocks reduce recipe time to 25% (instead of 50%) and increase EU/t to 400%") + .addInfo("Additionally gives +100K for every tier past MV") + .addPollutionAmount(20 * getPollutionPerTick(null)) + .addSeparator() + .beginStructureBlock(3, 4, 3, true) + .addController("Front bottom") + .addCasingInfo("Heat Proof Machine Casing", 0) + .addOtherStructurePart("Heating Coils", "Two middle Layers") + .addEnergyHatch("Any bottom layer casing") + .addMaintenanceHatch("Any bottom layer casing") + .addMufflerHatch("Top middle") + .addInputBus("Any bottom layer casing") + .addInputHatch("Any bottom layer casing") + .addOutputBus("Any bottom layer casing") + .addOutputHatch("Gasses, Any top layer casing") + .addStructureInfo("Recovery amount scales with Muffler Hatch tier") + .addOutputHatch("Platline fluids, Any bottom layer casing") + .toolTipFinisher("Gregtech"); + if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { + return tt.getInformation(); + } else { + return tt.getStructureInformation(); + } } + @Override public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { if (aSide == aFacing) { - return new ITexture[]{Textures.BlockIcons.casingTexturePages[0][11], new GT_RenderedTexture(aActive ? Textures.BlockIcons.OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_ACTIVE : Textures.BlockIcons.OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE)}; + return new ITexture[]{Textures.BlockIcons.casingTexturePages[0][CASING_INDEX], new GT_RenderedTexture(aActive ? Textures.BlockIcons.OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_ACTIVE : Textures.BlockIcons.OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE)}; } - return new ITexture[]{Textures.BlockIcons.casingTexturePages[0][11]}; + return new ITexture[]{Textures.BlockIcons.casingTexturePages[0][CASING_INDEX]}; } + @Override public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "ElectricBlastFurnace.png"); } + @Override public GT_Recipe.GT_Recipe_Map getRecipeMap() { return GT_Recipe.GT_Recipe_Map.sBlastRecipes; } + @Override public boolean isCorrectMachinePart(ItemStack aStack) { return true; } + @Override public boolean isFacingValid(byte aFacing) { return aFacing > 1; } + @Override public boolean checkRecipe(ItemStack aStack) { - ArrayList<ItemStack> tInputList = getStoredInputs(); - int tInputList_sS = tInputList.size(); - for (int i = 0; i < tInputList_sS - 1; i++) { - for (int j = i + 1; j < tInputList_sS; j++) { - if (GT_Utility.areStacksEqual(tInputList.get(i), tInputList.get(j))) { - if (tInputList.get(i).stackSize >= tInputList.get(j).stackSize) { - tInputList.remove(j--); - tInputList_sS = tInputList.size(); - } else { - tInputList.remove(i--); - tInputList_sS = tInputList.size(); - break; - } - } - } - } - ItemStack[] tInputs = tInputList.toArray(new ItemStack[tInputList.size()]); - - ArrayList<FluidStack> tFluidList = getStoredFluids(); - int tFluidList_sS = tFluidList.size(); - for (int i = 0; i < tFluidList_sS - 1; i++) { - for (int j = i + 1; j < tFluidList_sS; j++) { - if (GT_Utility.areFluidsEqual(tFluidList.get(i), tFluidList.get(j))) { - if (tFluidList.get(i).amount >= tFluidList.get(j).amount) { - tFluidList.remove(j--); - tFluidList_sS = tFluidList.size(); - } else { - tFluidList.remove(i--); - tFluidList_sS = tFluidList.size(); - break; - } - } - } + ItemStack[] tInputs = getCompactedInputs(); + FluidStack[] tFluids = getCompactedFluids(); + + if (tInputs.length <= 0) + return false; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + GT_Recipe tRecipe = GT_Recipe.GT_Recipe_Map.sBlastRecipes.findRecipe( + getBaseMetaTileEntity(), + false, + gregtech.api.enums.GT_Values.V[tTier], + tFluids, + tInputs + ); + + if (tRecipe == null) + return false; + if (this.mHeatingCapacity < tRecipe.mSpecialValue) + return false; + if (!tRecipe.isRecipeInputEqual(true, tFluids, tInputs)) + return false; + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + int tHeatCapacityDivTiers = (mHeatingCapacity - tRecipe.mSpecialValue) / 900; + byte overclockCount = calculateOverclockednessEBF(tRecipe.mEUt, tRecipe.mDuration, tVoltage); + //In case recipe is too OP for that machine + if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) + return false; + if (this.mEUt > 0) { + this.mEUt = (-this.mEUt); } - FluidStack[] tFluids = tFluidList.toArray(new FluidStack[tFluidList.size()]); - if (tInputList.size() > 0) { - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - GT_Recipe tRecipe = GT_Recipe.GT_Recipe_Map.sBlastRecipes.findRecipe(getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluids, tInputs); - if ((tRecipe != null) && (this.mHeatingCapacity >= tRecipe.mSpecialValue) && (tRecipe.isRecipeInputEqual(true, tFluids, tInputs))) { - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - int tHeatCapacityDivTiers = (mHeatingCapacity - tRecipe.mSpecialValue)/900; - byte overclockCount=calculateOverclockednessEBF(tRecipe.mEUt, tRecipe.mDuration, tVoltage); - //In case recipe is too OP for that machine - if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) - return false; - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - if(tHeatCapacityDivTiers>0){ - this.mEUt = (int) (this.mEUt * (Math.pow(0.95, tHeatCapacityDivTiers))); - this.mMaxProgresstime >>=Math.min(tHeatCapacityDivTiers/2,overclockCount);//extra free overclocking if possible - if(this.mMaxProgresstime<1) this.mMaxProgresstime=1;//no eu efficiency correction - } - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); - this.mOutputItems = new ItemStack[]{tRecipe.getOutput(0), tRecipe.getOutput(1)}; - this.mOutputFluids = new FluidStack[]{tRecipe.getFluidOutput(0)}; - updateSlots(); - return true; - } + if (tHeatCapacityDivTiers > 0) { + this.mEUt = (int) (this.mEUt * (Math.pow(0.95, tHeatCapacityDivTiers))); + this.mMaxProgresstime >>= Math.min(tHeatCapacityDivTiers / 2, overclockCount);//extra free overclocking if possible + if (this.mMaxProgresstime < 1) + this.mMaxProgresstime = 1;//no eu efficiency correction } - return false; + this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + this.mOutputItems = new ItemStack[]{ + tRecipe.getOutput(0), + tRecipe.getOutput(1) + }; + this.mOutputFluids = new FluidStack[]{ + tRecipe.getFluidOutput(0) + }; + updateSlots(); + return true; } /** * Calcualtes overclocked ness using long integers - * @param aEUt - recipe EUt - * @param aDuration - recipe Duration + * + * @param aEUt - recipe EUt + * @param aDuration - recipe Duration */ protected byte calculateOverclockednessEBF(int aEUt, int aDuration, long maxInputVoltage) { - byte mTier=(byte)Math.max(0,GT_Utility.getTier(maxInputVoltage)), timesOverclocked=0; - if(mTier==0){ + byte mTier = (byte) Math.max(0, GT_Utility.getTier(maxInputVoltage)), timesOverclocked = 0; + if (mTier == 0) { //Long time calculation - long xMaxProgresstime = ((long)aDuration)<<1; - if(xMaxProgresstime>Integer.MAX_VALUE-1){ + long xMaxProgresstime = ((long) aDuration) << 1; + if (xMaxProgresstime > Integer.MAX_VALUE - 1) { //make impossible if too long - mEUt=Integer.MAX_VALUE-1; - mMaxProgresstime=Integer.MAX_VALUE-1; - }else{ - mEUt=aEUt>>2; - mMaxProgresstime=(int)xMaxProgresstime; + mEUt = Integer.MAX_VALUE - 1; + mMaxProgresstime = Integer.MAX_VALUE - 1; + } else { + mEUt = aEUt >> 2; + mMaxProgresstime = (int) xMaxProgresstime; } //return 0; - }else{ + } else { //Long EUt calculation - long xEUt=aEUt; + long xEUt = aEUt; //Isnt too low EUt check? - long tempEUt = xEUt<V[1] ? V[1] : xEUt; + long tempEUt = Math.max(xEUt, V[1]); mMaxProgresstime = aDuration; - while (tempEUt <= V[mTier -1]) { - tempEUt<<=2;//this actually controls overclocking + while (tempEUt <= V[mTier - 1]) { + tempEUt <<= 2;//this actually controls overclocking //xEUt *= 4;//this is effect of everclocking - mMaxProgresstime>>=1;//this is effect of overclocking - xEUt = mMaxProgresstime==0 ? xEUt>>1 : xEUt<<2;//U know, if the time is less than 1 tick make the machine use less power + mMaxProgresstime >>= 1;//this is effect of overclocking + xEUt = mMaxProgresstime == 0 ? xEUt >> 1 : xEUt << 2;//U know, if the time is less than 1 tick make the machine use less power timesOverclocked++; } - if(xEUt>Integer.MAX_VALUE-1){ - mEUt = Integer.MAX_VALUE-1; - mMaxProgresstime = Integer.MAX_VALUE-1; - }else{ - mEUt = (int)xEUt; - if(mEUt==0) + if (xEUt > Integer.MAX_VALUE - 1) { + mEUt = Integer.MAX_VALUE - 1; + mMaxProgresstime = Integer.MAX_VALUE - 1; + } else { + mEUt = (int) xEUt; + if (mEUt == 0) mEUt = 1; - if(mMaxProgresstime==0) + if (mMaxProgresstime == 0) mMaxProgresstime = 1;//set time to 1 tick } } @@ -224,171 +220,136 @@ public class GT_MetaTileEntity_ElectricBlastFurnace int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; this.mHeatingCapacity = 0; - if (!aBaseMetaTileEntity.getAirOffset(xDir, 1, zDir)) { - return false; - } - if (!aBaseMetaTileEntity.getAirOffset(xDir, 2, zDir)) { + + replaceDeprecatedCoils(aBaseMetaTileEntity); + HeatingCoilLevel heatingCap = getInitialHeatLevel(aBaseMetaTileEntity, xDir, zDir); + if (heatingCap == null) return false; - } - if (!addMufflerToMachineList(aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir, 3, zDir), 11)) { + + if (!checkStructure(heatingCap, xDir, zDir, aBaseMetaTileEntity)) return false; - } - replaceDeprecatedCoils(aBaseMetaTileEntity); - byte tUsedMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + 1, 2, zDir); - switch (tUsedMeta) { - case 0: - this.mHeatingCapacity = 1801; - break; - case 1: - this.mHeatingCapacity = 2701; - break; - case 2: - this.mHeatingCapacity = 3601; - break; - case 3: - this.mHeatingCapacity = 4501; - break; - case 4: - this.mHeatingCapacity = 5401; - break; - case 5: - this.mHeatingCapacity = 7201; - break; - case 6: - this.mHeatingCapacity = 9001; - break; - case 7: - this.mHeatingCapacity = 9901; - break; - case 8: - this.mHeatingCapacity = 10801; - break; - default: - return false; - } - for (int i = -1; i < 2; i++) { - for (int j = -1; j < 2; j++) { - if ((i != 0) || (j != 0)) { - if (aBaseMetaTileEntity.getBlockOffset(xDir + i, 2, zDir + j) != GregTech_API.sBlockCasings5) { - return false; - } - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 2, zDir + j) != tUsedMeta) { - return false; - } - if (aBaseMetaTileEntity.getBlockOffset(xDir + i, 1, zDir + j) != GregTech_API.sBlockCasings5) { - return false; - } - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 1, zDir + j) != tUsedMeta) { - return false; - } - if (!addOutputToMachineList(aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, 3, zDir + j), 11)) { - if (aBaseMetaTileEntity.getBlockOffset(xDir + i, 3, zDir + j) != GregTech_API.sBlockCasings1) { - return false; - } - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 3, zDir + j) != 11) { - return false; - } - } - } - } - } - for (int i = -1; i < 2; i++) { - for (int j = -1; j < 2; j++) { - if ((xDir + i != 0) || (zDir + j != 0)) { - IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, 0, zDir + j); - if ((!addMaintenanceToMachineList(tTileEntity, 11)) && (!addInputToMachineList(tTileEntity, 11)) && (!addOutputToMachineList(tTileEntity, 11)) && (!addEnergyInputToMachineList(tTileEntity, 11))) { - if (aBaseMetaTileEntity.getBlockOffset(xDir + i, 0, zDir + j) != GregTech_API.sBlockCasings1) { - return false; - } - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 0, zDir + j) != 11) { - return false; - } - } - } - } - } + + this.mHeatingCapacity = (int) heatingCap.getHeat(); this.mHeatingCapacity += 100 * (GT_Utility.getTier(getMaxInputVoltage()) - 2); return true; } - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack){ - boolean result= this.checkMachineFunction(aBaseMetaTileEntity,aStack); - if (!result) this.mHeatingCapacity=0; - return result; - } + @Override + protected boolean checkTopLayer(int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity) { + if ((i == 0) && (j == 0)) { + return addMufflerToMachineList(aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir, 3, zDir), CASING_INDEX); + } + if (addOutputToMachineList(aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, 3, zDir + j), CASING_INDEX)) + return true; - public int getMaxEfficiency(ItemStack aStack) { - return 10000; - } + if (aBaseMetaTileEntity.getBlockOffset(xDir + i, 3, zDir + j) != GregTech_API.sBlockCasings1) + return false; - public int getPollutionPerTick(ItemStack aStack) { - return 20; + return aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 3, zDir + j) == CASING_INDEX; } - public int getDamageToComponent(ItemStack aStack) { - return 0; + @Override + protected boolean checkCoils(HeatingCoilLevel heatingCap, int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity) { + if ((i == 0) && (j == 0)) { + if (!aBaseMetaTileEntity.getAirOffset(xDir, 1, zDir)) + return false; + + return aBaseMetaTileEntity.getAirOffset(xDir, 2, zDir); + } + + Block blockLow = aBaseMetaTileEntity.getBlockOffset(xDir + i, 1, zDir + j); + if (!(blockLow instanceof IHeatingCoil)) + return false; + + Block blockHi = aBaseMetaTileEntity.getBlockOffset(xDir + i, 2, zDir + j); + if (!(blockHi instanceof IHeatingCoil)) + return false; + + byte metaLow = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 1, zDir + j); + HeatingCoilLevel coilHeatLow = ((IHeatingCoil) blockLow).getCoilHeat(metaLow); + byte metaHi = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 2, zDir + j); + HeatingCoilLevel coilHeatHi = ((IHeatingCoil) blockHi).getCoilHeat(metaHi); + + return heatingCap == coilHeatLow && heatingCap == coilHeatHi; } - public boolean explodesOnComponentBreak(ItemStack aStack) { - return false; + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + return this.checkMachineFunction(aBaseMetaTileEntity, aStack); } private void replaceDeprecatedCoils(IGregTechTileEntity aBaseMetaTileEntity) { int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; int tX = aBaseMetaTileEntity.getXCoord() + xDir; - int tY = (int) aBaseMetaTileEntity.getYCoord(); + int tY = aBaseMetaTileEntity.getYCoord(); int tZ = aBaseMetaTileEntity.getZCoord() + zDir; int tUsedMeta; for (int xPos = tX - 1; xPos <= tX + 1; xPos++) { for (int zPos = tZ - 1; zPos <= tZ + 1; zPos++) { - if ((xPos == tX) && (zPos == tZ)) { + if ((xPos == tX) && (zPos == tZ)) continue; - } for (int yPos = tY + 1; yPos <= tY + 2; yPos++) { tUsedMeta = aBaseMetaTileEntity.getMetaID(xPos, yPos, zPos); - if (tUsedMeta >= 12 && tUsedMeta <= 14 && aBaseMetaTileEntity.getBlock(xPos, yPos, zPos) == GregTech_API.sBlockCasings1) { - aBaseMetaTileEntity.getWorld().setBlock(xPos, yPos, zPos, GregTech_API.sBlockCasings5, tUsedMeta - 12, 3); - } + if (tUsedMeta < 12) + continue; + if (tUsedMeta > 14) + continue; + if (aBaseMetaTileEntity.getBlock(xPos, yPos, zPos) != GregTech_API.sBlockCasings1) + continue; + + aBaseMetaTileEntity.getWorld().setBlock( + xPos, + yPos, + zPos, + GregTech_API.sBlockCasings5, + tUsedMeta - 12, + 3 + ); } } } } + @Override - public boolean addOutput(FluidStack aLiquid) { - if (aLiquid == null) return false; + public boolean addOutput(FluidStack aLiquid) { + if (aLiquid == null) + return false; int targetHeight; FluidStack tLiquid = aLiquid.copy(); boolean isOutputPollution = false; for (FluidStack pollutionFluidStack : pollutionFluidStacks) { - if (tLiquid.isFluidEqual(pollutionFluidStack)) { - isOutputPollution = true; - break; - } + if (!tLiquid.isFluidEqual(pollutionFluidStack)) + continue; + + isOutputPollution = true; + break; } if (isOutputPollution) { targetHeight = this.controllerY + 3; int pollutionReduction = 0; for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) { - if (isValidMetaTileEntity(tHatch)) { - pollutionReduction = 100 - tHatch.calculatePollutionReduction(100); - break; - } + if (!isValidMetaTileEntity(tHatch)) + continue; + pollutionReduction = 100 - tHatch.calculatePollutionReduction(100); + break; } tLiquid.amount = tLiquid.amount * (pollutionReduction + 5) / 100; } else { targetHeight = this.controllerY; } for (GT_MetaTileEntity_Hatch_Output tHatch : mOutputHatches) { - if (isValidMetaTileEntity(tHatch) && GT_ModHandler.isSteam(aLiquid) ? tHatch.outputsSteam() : tHatch.outputsLiquids()) { - if (tHatch.getBaseMetaTileEntity().getYCoord() == targetHeight) { - int tAmount = tHatch.fill(tLiquid, false); - if (tAmount >= tLiquid.amount) { - return tHatch.fill(tLiquid, true) >= tLiquid.amount; - } else if (tAmount > 0) { - tLiquid.amount = tLiquid.amount - tHatch.fill(tLiquid, true); - } - } + if (isValidMetaTileEntity(tHatch) && GT_ModHandler.isSteam(aLiquid) ? !tHatch.outputsSteam() : !tHatch.outputsLiquids()) + continue; + + if (tHatch.getBaseMetaTileEntity().getYCoord() != targetHeight) + continue; + + int tAmount = tHatch.fill(tLiquid, false); + if (tAmount >= tLiquid.amount) { + return tHatch.fill(tLiquid, true) >= tLiquid.amount; + } else if (tAmount > 0) { + tLiquid.amount = tLiquid.amount - tHatch.fill(tLiquid, true); } } return false; @@ -396,37 +357,37 @@ public class GT_MetaTileEntity_ElectricBlastFurnace @Override public String[] getInfoData() { - int mPollutionReduction=0; + int mPollutionReduction = 0; for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) { - if (isValidMetaTileEntity(tHatch)) { - mPollutionReduction=Math.max(tHatch.calculatePollutionReduction(100),mPollutionReduction); - } + if (!isValidMetaTileEntity(tHatch)) + continue; + mPollutionReduction = Math.max(tHatch.calculatePollutionReduction(100), mPollutionReduction); } - long storedEnergy=0; - long maxEnergy=0; - for(GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches) { - if (isValidMetaTileEntity(tHatch)) { - storedEnergy+=tHatch.getBaseMetaTileEntity().getStoredEU(); - maxEnergy+=tHatch.getBaseMetaTileEntity().getEUCapacity(); - } + long storedEnergy = 0; + long maxEnergy = 0; + for (GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches) { + if (!isValidMetaTileEntity(tHatch)) + continue; + storedEnergy += tHatch.getBaseMetaTileEntity().getStoredEU(); + maxEnergy += tHatch.getBaseMetaTileEntity().getEUCapacity(); } return new String[]{ - StatCollector.translateToLocal("GT5U.multiblock.Progress")+": " +EnumChatFormatting.GREEN + Integer.toString(mProgresstime/20) + EnumChatFormatting.RESET +" s / "+ - EnumChatFormatting.YELLOW + Integer.toString(mMaxProgresstime/20) + EnumChatFormatting.RESET +" s", - StatCollector.translateToLocal("GT5U.multiblock.energy")+": " +EnumChatFormatting.GREEN + Long.toString(storedEnergy) + EnumChatFormatting.RESET +" EU / "+ - EnumChatFormatting.YELLOW + Long.toString(maxEnergy) + EnumChatFormatting.RESET +" EU", - StatCollector.translateToLocal("GT5U.multiblock.usage")+": "+EnumChatFormatting.RED + Integer.toString(-mEUt) + EnumChatFormatting.RESET + " EU/t", - StatCollector.translateToLocal("GT5U.multiblock.mei")+": "+EnumChatFormatting.YELLOW+Long.toString(getMaxInputVoltage())+EnumChatFormatting.RESET+" EU/t(*2A) "+StatCollector.translateToLocal("GT5U.machines.tier")+": "+ - EnumChatFormatting.YELLOW+VN[GT_Utility.getTier(getMaxInputVoltage())]+ EnumChatFormatting.RESET, - StatCollector.translateToLocal("GT5U.multiblock.problems")+": "+ - EnumChatFormatting.RED+ (getIdealStatus() - getRepairStatus())+EnumChatFormatting.RESET+ - " "+StatCollector.translateToLocal("GT5U.multiblock.efficiency")+": "+ - EnumChatFormatting.YELLOW+Float.toString(mEfficiency / 100.0F)+EnumChatFormatting.RESET + " %", - StatCollector.translateToLocal("GT5U.EBF.heat")+": "+ - EnumChatFormatting.GREEN+mHeatingCapacity+EnumChatFormatting.RESET+" K", - StatCollector.translateToLocal("GT5U.multiblock.pollution")+": "+ EnumChatFormatting.GREEN + mPollutionReduction+ EnumChatFormatting.RESET+" %" + StatCollector.translateToLocal("GT5U.multiblock.Progress") + ": " + EnumChatFormatting.GREEN + Integer.toString(mProgresstime / 20) + EnumChatFormatting.RESET + " s / " + + EnumChatFormatting.YELLOW + Integer.toString(mMaxProgresstime / 20) + EnumChatFormatting.RESET + " s", + StatCollector.translateToLocal("GT5U.multiblock.energy") + ": " + EnumChatFormatting.GREEN + Long.toString(storedEnergy) + EnumChatFormatting.RESET + " EU / " + + EnumChatFormatting.YELLOW + Long.toString(maxEnergy) + EnumChatFormatting.RESET + " EU", + StatCollector.translateToLocal("GT5U.multiblock.usage") + ": " + EnumChatFormatting.RED + Integer.toString(-mEUt) + EnumChatFormatting.RESET + " EU/t", + StatCollector.translateToLocal("GT5U.multiblock.mei") + ": " + EnumChatFormatting.YELLOW + Long.toString(getMaxInputVoltage()) + EnumChatFormatting.RESET + " EU/t(*2A) " + StatCollector.translateToLocal("GT5U.machines.tier") + ": " + + EnumChatFormatting.YELLOW + VN[GT_Utility.getTier(getMaxInputVoltage())] + EnumChatFormatting.RESET, + StatCollector.translateToLocal("GT5U.multiblock.problems") + ": " + + EnumChatFormatting.RED + (getIdealStatus() - getRepairStatus()) + EnumChatFormatting.RESET + + " " + StatCollector.translateToLocal("GT5U.multiblock.efficiency") + ": " + + EnumChatFormatting.YELLOW + Float.toString(mEfficiency / 100.0F) + EnumChatFormatting.RESET + " %", + StatCollector.translateToLocal("GT5U.EBF.heat") + ": " + + EnumChatFormatting.GREEN + mHeatingCapacity + EnumChatFormatting.RESET + " K", + StatCollector.translateToLocal("GT5U.multiblock.pollution") + ": " + EnumChatFormatting.GREEN + mPollutionReduction + EnumChatFormatting.RESET + " %" }; } -} +}
\ No newline at end of file diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java index 5eca30def1..8b27932511 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_MultiFurnace.java @@ -1,36 +1,39 @@ package gregtech.common.tileentities.machines.multi; -import static gregtech.api.enums.GT_Values.VN; - -import java.util.ArrayList; - -import org.lwjgl.input.Keyboard; - import gregtech.api.GregTech_API; +import gregtech.api.enums.HeatingCoilLevel; import gregtech.api.enums.Textures; import gregtech.api.gui.GT_GUIContainer_MultiMachine; +import gregtech.api.interfaces.IHeatingCoil; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffler; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; +import net.minecraft.block.Block; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; import net.minecraftforge.common.util.ForgeDirection; +import org.lwjgl.input.Keyboard; + +import java.util.ArrayList; + +import static gregtech.api.enums.GT_Values.VN; public class GT_MetaTileEntity_MultiFurnace - extends GT_MetaTileEntity_MultiBlockBase { + extends GT_MetaTileEntity_AbstractMultiFurnace { private int mLevel = 0; private int mCostDiscount = 1; + private static final int CASING_INDEX = 11; + public GT_MetaTileEntity_MultiFurnace(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); } @@ -39,10 +42,12 @@ public class GT_MetaTileEntity_MultiFurnace super(aName); } + @Override public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_MultiFurnace(this.mName); } + @Override public String[] getDescription() { final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); tt.addMachineType("Furnace") @@ -54,70 +59,56 @@ public class GT_MetaTileEntity_MultiFurnace .beginStructureBlock(3, 3, 3, true) .addController("Front bottom") .addCasingInfo("Heat Proof Machine Casing", 8) - .addOtherStructurePart("Heating Coils (any tier)", "Middle layer") + .addOtherStructurePart("Heating Coils", "Middle layer") .addEnergyHatch("Any bottom casing") .addMaintenanceHatch("Any bottom casing") .addMufflerHatch("Top Middle") .addInputBus("Any bottom casing") .addOutputBus("Any bottom casing") .toolTipFinisher("Gregtech"); - if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { - return tt.getInformation(); - } else { - return tt.getStructureInformation(); - } + if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) + return tt.getInformation(); + return tt.getStructureInformation(); } + @Override public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { - if (aSide == aFacing) { - return new ITexture[]{Textures.BlockIcons.casingTexturePages[0][11], new GT_RenderedTexture(aActive ? Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_ACTIVE : Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER)}; - } - return new ITexture[]{Textures.BlockIcons.casingTexturePages[0][11]}; + if (aSide == aFacing) + return new ITexture[]{Textures.BlockIcons.casingTexturePages[0][CASING_INDEX], new GT_RenderedTexture(aActive ? Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_ACTIVE : Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER)}; + return new ITexture[]{Textures.BlockIcons.casingTexturePages[0][CASING_INDEX]}; } + @Override public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "MultiFurnace.png"); } + @Override public GT_Recipe.GT_Recipe_Map getRecipeMap() { return GT_Recipe.GT_Recipe_Map.sFurnaceRecipes; } - public boolean isCorrectMachinePart(ItemStack aStack) { - return true; - } - - public boolean isFacingValid(byte aFacing) { - return aFacing > 1; - } - + @Override public boolean checkRecipe(ItemStack aStack) { ArrayList<ItemStack> tInputList = getStoredInputs(); - if (!tInputList.isEmpty()) { - int mVolatage=GT_Utility.safeInt(getMaxInputVoltage()); - int tMaxParrallel = 8 * this.mLevel; - int tCurrenParrallel = 0; - ItemStack tSmeltStack = tInputList.get(0); - ItemStack tOutputStack = GT_ModHandler.getSmeltingOutput(tSmeltStack,false,null); - if (tOutputStack == null) - return false; - for (int i = 0;i<tInputList.size();i++) - { - ItemStack item = tInputList.get(i); - if (tSmeltStack.isItemEqual(item)) - { - if (item.stackSize<(tMaxParrallel-tCurrenParrallel)) - { - tCurrenParrallel += item.stackSize; - item.stackSize = 0; - } - else - { - item.stackSize = (tCurrenParrallel + item.stackSize) - tMaxParrallel; - tCurrenParrallel = tMaxParrallel; - break; - } - } + if (tInputList.isEmpty()) + return false; + + int mVolatage = GT_Utility.safeInt(getMaxInputVoltage()); + int tMaxParrallel = 8 * this.mLevel; + int tCurrenParrallel = 0; + ItemStack tSmeltStack = tInputList.get(0); + ItemStack tOutputStack = GT_ModHandler.getSmeltingOutput(tSmeltStack,false,null); + if (tOutputStack == null) + return false; + for (ItemStack item : tInputList) + if (tSmeltStack.isItemEqual(item)) if (item.stackSize < (tMaxParrallel - tCurrenParrallel)) { + tCurrenParrallel += item.stackSize; + item.stackSize = 0; + } else { + item.stackSize = (tCurrenParrallel + item.stackSize) - tMaxParrallel; + tCurrenParrallel = tMaxParrallel; + break; } // this.mOutputItems = new ItemStack[8 * this.mLevel]; // for (int i = 0; (i < 256) && (j < this.mOutputItems.length); i++) { @@ -125,37 +116,33 @@ public class GT_MetaTileEntity_MultiFurnace // j++; // } // } - tCurrenParrallel *= tOutputStack.stackSize; - this.mOutputItems = new ItemStack[(tCurrenParrallel/64)+1]; - for (int i = 0; i<this.mOutputItems.length;i++) - { - ItemStack tNewStack = tOutputStack.copy(); - int size = tCurrenParrallel>64 ? 64 : tCurrenParrallel; - tNewStack.stackSize = size; - tCurrenParrallel -= size; - this.mOutputItems[i] = tNewStack; - } + tCurrenParrallel *= tOutputStack.stackSize; + this.mOutputItems = new ItemStack[(tCurrenParrallel/64)+1]; + for (int i = 0; i < this.mOutputItems.length; i++) { + ItemStack tNewStack = tOutputStack.copy(); + int size = Math.min(tCurrenParrallel, 64); + tNewStack.stackSize = size; + tCurrenParrallel -= size; + this.mOutputItems[i] = tNewStack; + } + if (this.mOutputItems.length > 0) { + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + calculateOverclockedNessMulti(4, 512, 1, mVolatage); + //In case recipe is too OP for that machine + if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) + return false; - if (this.mOutputItems != null && this.mOutputItems.length > 0) { - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; - calculateOverclockedNessMulti(4, 512, 1, mVolatage); - //In case recipe is too OP for that machine - if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) - return false; - - this.mEUt = GT_Utility.safeInt(((long)mEUt) * this.mLevel / (long)this.mCostDiscount,1); - if (mEUt == Integer.MAX_VALUE - 1) - return false; - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); - } - } - updateSlots(); - return true; + this.mEUt = GT_Utility.safeInt(((long)mEUt) * this.mLevel / (long)this.mCostDiscount,1); + if (mEUt == Integer.MAX_VALUE - 1) + return false; + + if (this.mEUt > 0) + this.mEUt = (-this.mEUt); } - return false; + updateSlots(); + return true; } private boolean checkMachineFunction(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { @@ -164,147 +151,82 @@ public class GT_MetaTileEntity_MultiFurnace this.mLevel = 0; this.mCostDiscount = 1; - if (!aBaseMetaTileEntity.getAirOffset(xDir, 1, zDir)) { - return false; - } - addMufflerToMachineList(aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir, 2, zDir), 11); + replaceDeprecatedCoils(aBaseMetaTileEntity); - byte tUsedMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + 1, 1, zDir); - switch (tUsedMeta) { - case 0: - this.mLevel = 1; - this.mCostDiscount = 1; - break; - case 1: - this.mLevel = 2; - this.mCostDiscount = 1; - break; - case 2: - this.mLevel = 4; - this.mCostDiscount = 1; - break; - case 3: - this.mLevel = 8; - this.mCostDiscount = 1; - break; - case 4: - this.mLevel = 16; - this.mCostDiscount = 2; - break; - case 5: - this.mLevel = 16; - this.mCostDiscount = 4; - break; - case 6: - this.mLevel = 16; - this.mCostDiscount = 8; - break; - case 7: - this.mLevel = 16; - this.mCostDiscount = 16; - break; - case 8: - this.mLevel = 16; - this.mCostDiscount = 24; - break; - default: - return false; - } - for (int i = -1; i < 2; i++) { - for (int j = -1; j < 2; j++) { - if ((i != 0) || (j != 0)) { - if (aBaseMetaTileEntity.getBlockOffset(xDir + i, 1, zDir + j) != GregTech_API.sBlockCasings5) { - return false; - } - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 1, zDir + j) != tUsedMeta) { - return false; - } - if (aBaseMetaTileEntity.getBlockOffset(xDir + i, 2, zDir + j) != GregTech_API.sBlockCasings1) { - return false; - } - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 2, zDir + j) != 11) { - return false; - } - } - } - } - for (int i = -1; i < 2; i++) { - for (int j = -1; j < 2; j++) { - if ((xDir + i != 0) || (zDir + j != 0)) { - IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, 0, zDir + j); - if ((!addMaintenanceToMachineList(tTileEntity, 11)) && (!addInputToMachineList(tTileEntity, 11)) && (!addOutputToMachineList(tTileEntity, 11)) && (!addEnergyInputToMachineList(tTileEntity, 11))) { - if (aBaseMetaTileEntity.getBlockOffset(xDir + i, 0, zDir + j) != GregTech_API.sBlockCasings1) { - return false; - } - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 0, zDir + j) != 11) { - return false; - } - } - } - } - } + HeatingCoilLevel heatingCap = getInitialHeatLevel(aBaseMetaTileEntity, xDir, zDir); + if (heatingCap == null) + return false; + + if (!checkStructure(heatingCap, xDir, zDir, aBaseMetaTileEntity)) + return false; + + this.mLevel = heatingCap.getLevel(); + this.mCostDiscount = heatingCap.getCostDiscount(); return true; } - public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack){ - boolean result= this.checkMachineFunction(aBaseMetaTileEntity,aStack); - if (!result) this.mLevel=0; - return result; - } - public int getMaxEfficiency(ItemStack aStack) { - return 10000; - } + @Override + protected boolean checkCoils(HeatingCoilLevel heatingCap, int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity) { + if ((i == 0) && (j == 0)) + return aBaseMetaTileEntity.getAirOffset(xDir, 1, zDir); + + Block coilM = aBaseMetaTileEntity.getBlockOffset(xDir + i, 1, zDir + j); + if (!(coilM instanceof IHeatingCoil)) + return false; + byte usedMetaM = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 1, zDir + j); + + IHeatingCoil heatingCoilM = (IHeatingCoil) coilM; + HeatingCoilLevel heatingLevelM = heatingCoilM.getCoilHeat(usedMetaM); - public int getPollutionPerTick(ItemStack aStack) { - return 20; + return heatingLevelM == heatingCap; } - public int getDamageToComponent(ItemStack aStack) { - return 0; + @Override + protected boolean checkTopLayer(int i, int j, int xDir, int zDir, IGregTechTileEntity aBaseMetaTileEntity) { + if ((i == 0) && (j == 0)) { + return addMufflerToMachineList(aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir, 2, zDir), CASING_INDEX); + } + if (aBaseMetaTileEntity.getBlockOffset(xDir + i, 2, zDir + j) != GregTech_API.sBlockCasings1) + return false; + return aBaseMetaTileEntity.getMetaIDOffset(xDir + i, 2, zDir + j) == CASING_INDEX; } - public boolean explodesOnComponentBreak(ItemStack aStack) { - return false; + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack){ + return this.checkMachineFunction(aBaseMetaTileEntity,aStack); } private void replaceDeprecatedCoils(IGregTechTileEntity aBaseMetaTileEntity) { int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; int tX = aBaseMetaTileEntity.getXCoord() + xDir; - int tY = (int) aBaseMetaTileEntity.getYCoord(); + int tY = aBaseMetaTileEntity.getYCoord(); int tZ = aBaseMetaTileEntity.getZCoord() + zDir; int tUsedMeta; - for (int xPos = tX - 1; xPos <= tX + 1; xPos++) { + for (int xPos = tX - 1; xPos <= tX + 1; xPos++) for (int zPos = tZ - 1; zPos <= tZ + 1; zPos++) { - if ((xPos == tX) && (zPos == tZ)) { - continue; - } + if ((xPos == tX) && (zPos == tZ)) continue; tUsedMeta = aBaseMetaTileEntity.getMetaID(xPos, tY + 1, zPos); - if (tUsedMeta >= 12 && tUsedMeta <= 14 && aBaseMetaTileEntity.getBlock(xPos, tY + 1, zPos) == GregTech_API.sBlockCasings1) { + if (tUsedMeta >= 12 && tUsedMeta <= 14 && aBaseMetaTileEntity.getBlock(xPos, tY + 1, zPos) == GregTech_API.sBlockCasings1) aBaseMetaTileEntity.getWorld().setBlock(xPos, tY + 1, zPos, GregTech_API.sBlockCasings5, tUsedMeta - 12, 3); - } } - } } @Override public String[] getInfoData() { int mPollutionReduction=0; - for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) { - if (isValidMetaTileEntity(tHatch)) { - mPollutionReduction=Math.max(tHatch.calculatePollutionReduction(100),mPollutionReduction); - } - } + for (GT_MetaTileEntity_Hatch_Muffler tHatch : mMufflerHatches) + if (isValidMetaTileEntity(tHatch)) + mPollutionReduction = Math.max(tHatch.calculatePollutionReduction(100), mPollutionReduction); long storedEnergy=0; long maxEnergy=0; - for(GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches) { + for(GT_MetaTileEntity_Hatch_Energy tHatch : mEnergyHatches) if (isValidMetaTileEntity(tHatch)) { - storedEnergy+=tHatch.getBaseMetaTileEntity().getStoredEU(); - maxEnergy+=tHatch.getBaseMetaTileEntity().getEUCapacity(); + storedEnergy += tHatch.getBaseMetaTileEntity().getStoredEU(); + maxEnergy += tHatch.getBaseMetaTileEntity().getEUCapacity(); } - } return new String[]{ StatCollector.translateToLocal("GT5U.multiblock.Progress")+": "+ diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilCracker.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilCracker.java index e4ad65e4a4..d0c3f1f8a0 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilCracker.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilCracker.java @@ -1,9 +1,11 @@ package gregtech.common.tileentities.machines.multi; import gregtech.api.GregTech_API; +import gregtech.api.enums.HeatingCoilLevel; import gregtech.api.enums.Materials; import gregtech.api.enums.Textures; import gregtech.api.gui.GT_GUIContainer_MultiMachine; +import gregtech.api.interfaces.IHeatingCoil; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -14,19 +16,24 @@ import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Multiblock_Tooltip_Builder; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Utility; +import net.minecraft.block.Block; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; +import org.apache.commons.lang3.mutable.MutableInt; +import org.lwjgl.input.Keyboard; import java.util.ArrayList; - -import org.lwjgl.input.Keyboard; +import java.util.BitSet; public class GT_MetaTileEntity_OilCracker extends GT_MetaTileEntity_MultiBlockBase { private ForgeDirection orientation; private int controllerX, controllerZ; + private static final byte CASING_INDEX = 49; + private HeatingCoilLevel heatLevel; + public GT_MetaTileEntity_OilCracker(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); } @@ -35,6 +42,7 @@ public class GT_MetaTileEntity_OilCracker extends GT_MetaTileEntity_MultiBlockBa super(aName); } + @Override public String[] getDescription() { final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); tt.addMachineType("Cracker") @@ -46,7 +54,8 @@ public class GT_MetaTileEntity_OilCracker extends GT_MetaTileEntity_MultiBlockBa .beginStructureBlock(5, 3, 3, true) .addController("Front center") .addCasingInfo("Clean Stainless Steel Machine Casing", 18) - .addOtherStructurePart("2 Rings of 8 Cupronickel Coils", "Each side of the controller") + .addOtherStructurePart("2 Rings of 8 Coils", "Each side of the controller") + .addInfo("Gets 5% energy cost reduction per coil tier") .addEnergyHatch("Any casing") .addMaintenanceHatch("Any casing") .addInputHatch("Steam/Hydrogen, Any middle ring casing") @@ -54,21 +63,18 @@ public class GT_MetaTileEntity_OilCracker extends GT_MetaTileEntity_MultiBlockBa .addOutputHatch("Any left/right side casing") .addStructureInfo("Input/Output Hatches must be on opposite sides!") .toolTipFinisher("Gregtech"); - if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { - return tt.getInformation(); - } else { - return tt.getStructureInformation(); - } + if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) return tt.getInformation(); + return tt.getStructureInformation(); } + @Override public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { - if (aSide == aFacing) { - return new ITexture[]{Textures.BlockIcons.casingTexturePages[0][49], - new GT_RenderedTexture(aActive ? Textures.BlockIcons.OVERLAY_FRONT_OIL_CRACKER_ACTIVE : Textures.BlockIcons.OVERLAY_FRONT_OIL_CRACKER)}; - } - return new ITexture[]{Textures.BlockIcons.casingTexturePages[0][49]}; + if (aSide == aFacing) return new ITexture[]{Textures.BlockIcons.casingTexturePages[0][CASING_INDEX], + new GT_RenderedTexture(aActive ? Textures.BlockIcons.OVERLAY_FRONT_OIL_CRACKER_ACTIVE : Textures.BlockIcons.OVERLAY_FRONT_OIL_CRACKER)}; + return new ITexture[]{Textures.BlockIcons.casingTexturePages[0][CASING_INDEX]}; } + @Override public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "OilCrackingUnit.png"); } @@ -76,13 +82,22 @@ public class GT_MetaTileEntity_OilCracker extends GT_MetaTileEntity_MultiBlockBa @Override public boolean checkRecipe(ItemStack aStack) { ArrayList<FluidStack> tInputList = getStoredFluids(); - FluidStack[] tFluidInputs = tInputList.toArray(new FluidStack[tInputList.size()]); + FluidStack[] tFluidInputs = tInputList.toArray(new FluidStack[0]); long tVoltage = getMaxInputVoltage(); byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); GT_Recipe tRecipe = GT_Recipe.GT_Recipe_Map.sCrakingRecipes.findRecipe( - getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluidInputs ,new ItemStack[]{mInventory[1]}); - if (tRecipe != null && tRecipe.isRecipeInputEqual(true, tFluidInputs, new ItemStack[]{mInventory[1]})) { + getBaseMetaTileEntity(), + false, + gregtech.api.enums.GT_Values.V[tTier], + tFluidInputs , + mInventory[1] + ); + + if (tRecipe == null) + return false; + + if (tRecipe.isRecipeInputEqual(true, tFluidInputs, mInventory[1])) { this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); this.mEfficiencyIncrease = 10000; this.mEUt = tRecipe.mEUt; @@ -91,147 +106,153 @@ public class GT_MetaTileEntity_OilCracker extends GT_MetaTileEntity_MultiBlockBa this.mEUt *= 4; this.mMaxProgresstime /= 2; } - if (this.mEUt > 0) { + + this.mEUt *= Math.pow(0.95D, this.heatLevel.getTier()); + + if (this.mEUt > 0) this.mEUt = (-this.mEUt); - } - this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime); + this.mOutputFluids = new FluidStack[]{tRecipe.getFluidOutput(0)}; return true; } return false; } + private boolean coilsNotPresent(IGregTechTileEntity aBaseMetaTileEntity, int x , int y, int z) { + + Block coil = aBaseMetaTileEntity.getBlockOffset(x, y, z); + + if (!(coil instanceof IHeatingCoil)) + return true; + + IHeatingCoil heatingCoil = (IHeatingCoil) coil; + byte meta = aBaseMetaTileEntity.getMetaIDOffset(x, y, z); + HeatingCoilLevel heatLevel = heatingCoil.getCoilHeat(meta); + if (heatLevel == HeatingCoilLevel.None) + return true; + + if (this.heatLevel == HeatingCoilLevel.None) + this.heatLevel = heatLevel; + + return this.heatLevel != heatLevel; + } + @Override public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + this.heatLevel = HeatingCoilLevel.None; this.orientation = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()); this.controllerX = aBaseMetaTileEntity.getXCoord(); this.controllerZ = aBaseMetaTileEntity.getZCoord(); int xDir = this.orientation.offsetX; int zDir = this.orientation.offsetZ; - int amount = 0; + MutableInt amount = new MutableInt(0); replaceDeprecatedCoils(aBaseMetaTileEntity); - boolean negSideInput = false, negSideOutput = false, posSideInput = false, posSideOutput = false; - if (xDir != 0) { - for (int i = -1; i < 2; i++) {// xDirection - for (int j = -1; j < 2; j++) {// height - for (int h = -2; h < 3; h++) { - if (!(j == 0 && i == 0 && (h == -1 || h == 0 || h == 1))) { - if (h == 1 || h == -1) { - if (aBaseMetaTileEntity.getBlockOffset(xDir + i, j, h + zDir) != GregTech_API.sBlockCasings5) { - return false; - } - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + i, j, h + zDir) != 0) { - return false; - } - } - if (h == 2 || h == -2) { - IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, j, h + zDir); - if (addInputToMachineList(tTileEntity, 49)) { - if (h == -2) { - negSideInput = true; - } else { - posSideInput = true; - } - } else if (addOutputToMachineList(tTileEntity, 49)) { - if (h == -2) { - negSideOutput = true; - } else { - posSideOutput = true; - } - } else if (!addEnergyInputToMachineList(tTileEntity, 49) && !addMaintenanceToMachineList(tTileEntity, 49)){ - if (aBaseMetaTileEntity.getBlockOffset(xDir + i, j, h + zDir) != GregTech_API.sBlockCasings4) { - return false; - } - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + i, j, h + zDir) != 1) { - return false; - } - amount++; - } - } - if (h == 0) { - IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, j, h + zDir); - if ((!addMaintenanceToMachineList(tTileEntity, 49)) && (!addInputToMachineList(tTileEntity, 49)) - && (!addEnergyInputToMachineList(tTileEntity, 49))) { - if (!((xDir + i) == 0 && j == 0 && (h + zDir) == 0)) { - if (aBaseMetaTileEntity.getBlockOffset(xDir + i, j, h + zDir) != GregTech_API.sBlockCasings4) { - return false; - } - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + i, j, h + zDir) != 1) { - return false; - } - amount++; - } - } - } - - } - } - } - } - } else { - for (int i = -1; i < 2; i++) {// zDirection - for (int j = -1; j < 2; j++) {// height - for (int h = -2; h < 3; h++) { - if (!(j == 0 && i == 0 && (h == -1 || h == 0 || h == 1))) { - if (h == 1 || h == -1) { - if (aBaseMetaTileEntity.getBlockOffset(xDir + h, j, i + zDir) != GregTech_API.sBlockCasings5) { - return false; - } - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + h, j, i + zDir) != 0) { - return false; - } - } - if (h == 2 || h == -2) { - IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + h, j, i + zDir); - if (addInputToMachineList(tTileEntity, 49)) { - if (h == -2) { - negSideInput = true; - } else { - posSideInput = true; - } - } else if (addOutputToMachineList(tTileEntity, 49)) { - if (h == -2) { - negSideOutput = true; - } else { - posSideOutput = true; - } - } else if (!addEnergyInputToMachineList(tTileEntity, 49) && !addMaintenanceToMachineList(tTileEntity, 49)){ - if (aBaseMetaTileEntity.getBlockOffset(xDir + h, j, i + zDir) != GregTech_API.sBlockCasings4) { - return false; - } - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + h, j, i + zDir) != 1) { - return false; - } - amount++; - } - } - if (h == 0) { - IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + h, j, i + zDir); - if ((!addMaintenanceToMachineList(tTileEntity, 49)) && (!addInputToMachineList(tTileEntity, 49)) - && (!addEnergyInputToMachineList(tTileEntity, 49))) { - if (!((xDir + h) == 0 && j == 0 && (i + zDir) == 0)) { - if (aBaseMetaTileEntity.getBlockOffset(xDir + h, j, i + zDir) != GregTech_API.sBlockCasings4) { - return false; - } - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + h, j, i + zDir) != 1) { - return false; - } - amount++; - } - } - } - - } + BitSet flags = new BitSet(4); + + for (int depth = -1; depth < 2; depth++) + for (int height = -1; height < 2; height++) + for (int slice = -2; slice < 3; slice++) + if (xDir != 0) { + if (isStructureBroken(xDir, zDir, depth, height, slice, aBaseMetaTileEntity, amount, flags)) + return false; + } else { + if (isStructureBroken(xDir, zDir, slice, height, depth, aBaseMetaTileEntity, amount, flags)) + return false; } - } - } + + if(checkInputOutputBroken(flags)) + return false; + + return amount.intValue() >= 18; + } + + private boolean checkInputOutputBroken(BitSet flags){ + if (flags.get(0) && flags.get(2)) //input and output on side 1 + return true; + if (flags.get(1) && flags.get(3)) //input and output on side 2 + return true; + if (flags.get(1) && flags.get(2)) //input on both sides + return true; + return flags.get(2) && flags.get(3); //output on both sides + } + + private boolean isStructureBroken( + int xDir, + int zDir, + int a, + int b, + int c, + IGregTechTileEntity aBaseMetaTileEntity, + MutableInt amount, + BitSet flags) { + if (b == 0 && c == 0 && (a == -1 || a == 0 || a == 1)) + return false; + if (a == 1 || a == -1) { + return coilsNotPresent(aBaseMetaTileEntity, xDir + a, b, c + zDir); } - if ((negSideInput && negSideOutput) || (posSideInput && posSideOutput) - || (negSideInput && posSideInput) || (negSideOutput && posSideOutput)) { - return false; + else if (a == 2 || a == -2) { + return checkEndsBroken(xDir, zDir, a, b, c, aBaseMetaTileEntity, amount, flags); } - if (amount < 18) return false; - return true; + else if (a == 0) + return checkMiddleBroken(xDir, zDir, a, b, c, aBaseMetaTileEntity, amount); + + return false; + } + + private boolean checkEndsBroken( + int xDir, + int zDir, + int a, + int b, + int c, + IGregTechTileEntity aBaseMetaTileEntity, + MutableInt amount, + BitSet flags + ){ + IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + c, b, a + zDir); + if (addInputToMachineList(tTileEntity, CASING_INDEX)) + if (a == -2) + flags.set(0); //input on side 1 + else + flags.set(1); //input on side 2 + else if (addOutputToMachineList(tTileEntity, CASING_INDEX)) + if (a == -2) + flags.set(2); //output on side 1 + else + flags.set(3); //output on side 2 + else if (!addEnergyInputToMachineList(tTileEntity, CASING_INDEX)) + if (!addMaintenanceToMachineList(tTileEntity, CASING_INDEX)) { + if (aBaseMetaTileEntity.getBlockOffset(xDir + c, b, a + zDir) != GregTech_API.sBlockCasings4) + return true; + if (aBaseMetaTileEntity.getMetaIDOffset(xDir + c, b, a + zDir) != 1) + return true; + amount.increment(); + } + return false; + } + + private boolean checkMiddleBroken( int xDir, + int zDir, + int a, + int b, + int c, + IGregTechTileEntity aBaseMetaTileEntity, + MutableInt amount){ + IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + c, b, a + zDir); + if (addMaintenanceToMachineList(tTileEntity, CASING_INDEX)) + return false; + if (addInputToMachineList(tTileEntity, CASING_INDEX)) + return false; + if (addEnergyInputToMachineList(tTileEntity, CASING_INDEX)) + return false; + if ((xDir + c) == 0 && b == 0 && (a + zDir) == 0) + return false; + if (aBaseMetaTileEntity.getBlockOffset(xDir + c, b, a + zDir) != GregTech_API.sBlockCasings4) + return true; + if (aBaseMetaTileEntity.getMetaIDOffset(xDir + c, b, a + zDir) != 1) + return true; + amount.increment(); + return false; } @Override @@ -259,6 +280,7 @@ public class GT_MetaTileEntity_OilCracker extends GT_MetaTileEntity_MultiBlockBa return false; } + @Override public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_OilCracker(this.mName); } @@ -267,50 +289,52 @@ public class GT_MetaTileEntity_OilCracker extends GT_MetaTileEntity_MultiBlockBa int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; int tX = aBaseMetaTileEntity.getXCoord() + xDir; - int tY = (int) aBaseMetaTileEntity.getYCoord(); + int tY = aBaseMetaTileEntity.getYCoord(); int tZ = aBaseMetaTileEntity.getZCoord() + zDir; - for (int xPos = tX - 1; xPos <= tX + 1; xPos += (xDir != 0 ? 1 : 2)) { - for (int yPos = tY - 1; yPos <= tY + 1; yPos++) { + for (int xPos = tX - 1; xPos <= tX + 1; xPos += (xDir != 0 ? 1 : 2)) + for (int yPos = tY - 1; yPos <= tY + 1; yPos++) for (int zPos = tZ - 1; zPos <= tZ + 1; zPos += (xDir != 0 ? 2 : 1)) { - if ((yPos == tY) && (xPos == tX || zPos == tZ)) { + if ((yPos == tY) && (xPos == tX || zPos == tZ)) continue; - } - if (aBaseMetaTileEntity.getBlock(xPos, yPos, zPos) == GregTech_API.sBlockCasings1 && - aBaseMetaTileEntity.getMetaID(xPos, yPos, zPos) == 12) - { - aBaseMetaTileEntity.getWorld().setBlock(xPos, yPos, zPos, GregTech_API.sBlockCasings5, 0, 3); - } + byte tUsedMeta = aBaseMetaTileEntity.getMetaID(xPos, yPos, zPos); + if (tUsedMeta < 12) + continue; + if (tUsedMeta > 14) + continue; + if (aBaseMetaTileEntity.getBlock(xPos, yPos, zPos) != GregTech_API.sBlockCasings1) + continue; + + aBaseMetaTileEntity.getWorld().setBlock( + xPos, + yPos, + zPos, + GregTech_API.sBlockCasings5, + tUsedMeta - 12, + 3 + ); } - } - } } @Override public ArrayList<FluidStack> getStoredFluids() { - ArrayList<FluidStack> rList = new ArrayList<FluidStack>(); + ArrayList<FluidStack> rList = new ArrayList<>(); for (GT_MetaTileEntity_Hatch_Input tHatch : mInputHatches) { tHatch.mRecipeMap = getRecipeMap(); if (isValidMetaTileEntity(tHatch) && tHatch.getFillableStack() != null) { FluidStack tStack = tHatch.getFillableStack(); if (tStack.isFluidEqual(GT_ModHandler.getSteam(1000)) || tStack.isFluidEqual(Materials.Hydrogen.getGas(1000))) { - if (isHatchInMiddleRing(tHatch)) { - rList.add(tStack); - } - } else { - if (!isHatchInMiddleRing(tHatch)) { + if (isHatchInMiddleRing(tHatch)) rList.add(tStack); - } - } + } else if (!isHatchInMiddleRing(tHatch)) + rList.add(tStack); } } return rList; } private boolean isHatchInMiddleRing(GT_MetaTileEntity_Hatch_Input inputHatch){ - if (orientation == ForgeDirection.NORTH || orientation == ForgeDirection.SOUTH) { + if (orientation == ForgeDirection.NORTH || orientation == ForgeDirection.SOUTH) return inputHatch.getBaseMetaTileEntity().getXCoord() == this.controllerX; - } else { - return inputHatch.getBaseMetaTileEntity().getZCoord() == this.controllerZ; - } + return inputHatch.getBaseMetaTileEntity().getZCoord() == this.controllerZ; } }
\ No newline at end of file diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java index c2e13a815f..edf652923b 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java @@ -3,8 +3,10 @@ package gregtech.common.tileentities.machines.multi; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.registry.GameRegistry; import gregtech.api.GregTech_API; +import gregtech.api.enums.HeatingCoilLevel; import gregtech.api.enums.Textures; import gregtech.api.gui.GT_GUIContainer_MultiMachine; +import gregtech.api.interfaces.IHeatingCoil; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -20,17 +22,14 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.oredict.OreDictionary; - -import java.util.ArrayList; -import java.util.Arrays; - +import org.apache.commons.lang3.mutable.MutableBoolean; import org.lwjgl.input.Keyboard; public class GT_MetaTileEntity_PyrolyseOven extends GT_MetaTileEntity_MultiBlockBase { - - private int coilMetaID; - //public static GT_CopiedBlockTexture mTextureULV = new GT_CopiedBlockTexture(Block.getBlockFromItem(ItemList.Casing_ULV.get(1).getItem()), 6, 0, Dyes.MACHINE_METAL.mRGBa); - private final int CASING_INDEX = 1090; + + private HeatingCoilLevel coilHeat; + //public static GT_CopiedBlockTexture mTextureULV = new GT_CopiedBlockTexture(Block.getBlockFromItem(ItemList.Casing_ULV.get(1).getItem()), 6, 0, Dyes.MACHINE_METAL.mRGBa); + private static final int CASING_INDEX = 1090; public GT_MetaTileEntity_PyrolyseOven(int aID, String aName, String aNameRegional) { super(aID, aName, aNameRegional); @@ -40,35 +39,37 @@ public class GT_MetaTileEntity_PyrolyseOven extends GT_MetaTileEntity_MultiBlock super(aName); } + @Override public String[] getDescription() { - final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); - tt.addMachineType("Coke Oven") - .addInfo("Controller block for the Pyrolyse Oven") - .addInfo("Industrial Charcoal producer") - .addInfo("Processing speed scales linearly with Coil tier:") - .addInfo("CuNi: 50%, FeAlCr: 100%, Ni4Cr: 150%, Fe50CW: 200%, etc.") - .addInfo("EU/t is not affected by Coil tier") - .addPollutionAmount(20 * getPollutionPerTick(null)) - .addSeparator() - .beginStructureBlock(5, 4, 5, true) - .addController("Front center") - .addCasingInfo("Pyrolyse Oven Casing", 60) - .addOtherStructurePart("Heating Coils (any tier)", "Center 3x1x3 of the bottom layer") - .addEnergyHatch("Any bottom layer casing") - .addMaintenanceHatch("Any bottom layer casing") - .addMufflerHatch("Center 3x1x3 area in top layer") - .addInputBus("Center 3x1x3 area in top layer") - .addInputHatch("Center 3x1x3 area in top layer") - .addOutputBus("Any bottom layer casing") - .addOutputHatch("Any bottom layer casing") - .toolTipFinisher("Gregtech"); - if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { - return tt.getInformation(); - } else { - return tt.getStructureInformation(); - } + final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType("Coke Oven") + .addInfo("Controller block for the Pyrolyse Oven") + .addInfo("Industrial Charcoal producer") + .addInfo("Processing speed scales linearly with Coil tier:") + .addInfo("CuNi: 50%, FeAlCr: 100%, Ni4Cr: 150%, Fe50CW: 200%, etc.") + .addInfo("EU/t is not affected by Coil tier") + .addPollutionAmount(20 * getPollutionPerTick(null)) + .addSeparator() + .beginStructureBlock(5, 4, 5, true) + .addController("Front center") + .addCasingInfo("Pyrolyse Oven Casing", 60) + .addOtherStructurePart("Heating Coils", "Center 3x1x3 of the bottom layer") + .addEnergyHatch("Any bottom layer casing") + .addMaintenanceHatch("Any bottom layer casing") + .addMufflerHatch("Center 3x1x3 area in top layer") + .addInputBus("Center 3x1x3 area in top layer") + .addInputHatch("Center 3x1x3 area in top layer") + .addOutputBus("Any bottom layer casing") + .addOutputHatch("Any bottom layer casing") + .toolTipFinisher("Gregtech"); + if (!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { + return tt.getInformation(); + } else { + return tt.getStructureInformation(); + } } + @Override public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) { if (aSide == aFacing) { return new ITexture[]{Textures.BlockIcons.casingTexturePages[8][66], new GT_RenderedTexture(aActive ? Textures.BlockIcons.OVERLAY_FRONT_PYROLYSE_OVEN_ACTIVE : Textures.BlockIcons.OVERLAY_FRONT_PYROLYSE_OVEN)}; @@ -76,145 +77,103 @@ public class GT_MetaTileEntity_PyrolyseOven extends GT_MetaTileEntity_MultiBlock return new ITexture[]{Textures.BlockIcons.casingTexturePages[8][66]}; } + @Override public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { return new GT_GUIContainer_MultiMachine(aPlayerInventory, aBaseMetaTileEntity, getLocalName(), "PyrolyseOven.png"); } @Override public boolean checkRecipe(ItemStack aStack) { - ArrayList<ItemStack> tInputList = getStoredInputs(); - int tInputList_sS=tInputList.size(); - for (int i = 0; i < tInputList_sS - 1; i++) { - for (int j = i + 1; j < tInputList_sS; j++) { - if (GT_Utility.areStacksEqual((ItemStack) tInputList.get(i), (ItemStack) tInputList.get(j))) { - if (((ItemStack) tInputList.get(i)).stackSize >= ((ItemStack) tInputList.get(j)).stackSize) { - tInputList.remove(j--); tInputList_sS=tInputList.size(); - } else { - tInputList.remove(i--); tInputList_sS=tInputList.size(); - break; - } - } - } - } - ItemStack[] tInputs = (ItemStack[]) Arrays.copyOfRange(tInputList.toArray(new ItemStack[tInputList.size()]), 0, 2); - - ArrayList<FluidStack> tFluidList = getStoredFluids(); - int tFluidList_sS=tFluidList.size(); - for (int i = 0; i < tFluidList_sS - 1; i++) { - for (int j = i + 1; j < tFluidList_sS; j++) { - if (GT_Utility.areFluidsEqual((FluidStack) tFluidList.get(i), (FluidStack) tFluidList.get(j))) { - if (((FluidStack) tFluidList.get(i)).amount >= ((FluidStack) tFluidList.get(j)).amount) { - tFluidList.remove(j--); tFluidList_sS=tFluidList.size(); - } else { - tFluidList.remove(i--); tFluidList_sS=tFluidList.size(); - break; - } - } - } - } - FluidStack[] tFluids = (FluidStack[]) Arrays.copyOfRange(tFluidList.toArray(new FluidStack[tInputList.size()]), 0, 1); - if (tInputList.size() > 0) { - long tVoltage = getMaxInputVoltage(); - byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); - GT_Recipe tRecipe = GT_Recipe.GT_Recipe_Map.sPyrolyseRecipes.findRecipe(getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluids, tInputs); - - //Dynamic recipe adding for newly found logWoods - wont be visible in nei most probably - if(tRecipe==null){ - for(ItemStack is:tInputs) { - for (int id : OreDictionary.getOreIDs(is)) { - if (OreDictionary.getOreName(id).equals("logWood")) - ProcessingLog.addPyrolyeOvenRecipes(is); - } - } - tRecipe = GT_Recipe.GT_Recipe_Map.sPyrolyseRecipes.findRecipe(getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluids, tInputs); - } + ItemStack[] tInputs = getCompactedInputs(); + FluidStack[] tFluids = getCompactedFluids(); + + if (tInputs.length <= 0) + return false; + + long tVoltage = getMaxInputVoltage(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + GT_Recipe tRecipe = GT_Recipe.GT_Recipe_Map.sPyrolyseRecipes.findRecipe(getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluids, tInputs); + + //Dynamic recipe adding for newly found logWoods - wont be visible in nei most probably + if (tRecipe == null) + tRecipe = addRecipesDynamically(tInputs, tFluids, tTier); - if (tRecipe != null && tRecipe.isRecipeInputEqual(true, tFluids, tInputs)) { - this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); - this.mEfficiencyIncrease = 10000; + if (tRecipe == null || !tRecipe.isRecipeInputEqual(true, tFluids, tInputs)) + return false; - calculateOverclockedNessMulti(tRecipe.mEUt, tRecipe.mDuration, 1, tVoltage); - //In case recipe is too OP for that machine - if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) - return false; - if (this.mEUt > 0) { - this.mEUt = (-this.mEUt); + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + calculateOverclockedNessMulti(tRecipe.mEUt, tRecipe.mDuration, 1, tVoltage); + //In case recipe is too OP for that machine + if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) + return false; + if (this.mEUt > 0) + this.mEUt = (-this.mEUt); + this.mMaxProgresstime = Math.max(mMaxProgresstime * 2 / (1 + coilHeat.getTier()), 1); + if (tRecipe.mOutputs.length > 0) + this.mOutputItems = new ItemStack[]{tRecipe.getOutput(0)}; + if (tRecipe.mFluidOutputs.length > 0) + this.mOutputFluids = new FluidStack[]{tRecipe.getFluidOutput(0)}; + updateSlots(); + return true; + } + + private GT_Recipe addRecipesDynamically(ItemStack[] tInputs, FluidStack[] tFluids, int tTier) { + if (tInputs.length > 1 || (tInputs[0] != null && tInputs[0].getItem() != GT_Utility.getIntegratedCircuit(0).getItem())) { + int oreId = OreDictionary.getOreID("logWood"); + for (ItemStack is : tInputs) { + for (int id : OreDictionary.getOreIDs(is)) { + if (oreId == id) { + ProcessingLog.addPyrolyeOvenRecipes(is); + return GT_Recipe.GT_Recipe_Map.sPyrolyseRecipes.findRecipe(getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluids, tInputs); + } } - this.mMaxProgresstime = Math.max(mMaxProgresstime * 2 / (1 + coilMetaID), 1); - if (tRecipe.mOutputs.length > 0) this.mOutputItems = new ItemStack[]{tRecipe.getOutput(0)}; - if (tRecipe.mFluidOutputs.length > 0) - this.mOutputFluids = new FluidStack[]{tRecipe.getFluidOutput(0)}; - updateSlots(); - return true; } } - return false; + return null; } @Override public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX * 2; int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ * 2; + Block casingBlock; + int casingMeta; - Block CasingBlock= Loader.isModLoaded("dreamcraft")? GameRegistry.findBlock("dreamcraft","gt.blockcasingsNH"): GregTech_API.sBlockCasings1; - int CasingMeta= Loader.isModLoaded("dreamcraft")?2:0; + if (Loader.isModLoaded("dreamcraft")) { + casingBlock = GameRegistry.findBlock("dreamcraft", "gt.blockcasingsNH"); + casingMeta = 2; + } else { + casingBlock = GregTech_API.sBlockCasings1; + casingMeta = 0; + } replaceDeprecatedCoils(aBaseMetaTileEntity); - boolean firstCoil = true; + MutableBoolean firstCoil = new MutableBoolean(true); for (int i = -2; i < 3; i++) { for (int j = -2; j < 3; j++) { for (int h = 0; h < 4; h++) { IGregTechTileEntity tTileEntity = aBaseMetaTileEntity.getIGregTechTileEntityOffset(xDir + i, h, zDir + j); if ((i != -2 && i != 2) && (j != -2 && j != 2)) {// inner 3x3 without height - if (h == 0) {// inner floor (Cupronickel or Kanthal coils) - if (aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j) != GregTech_API.sBlockCasings5) { - return false; - } - int metaID = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); - if (metaID > 8) { - return false; - } else { - if (firstCoil) { - this.coilMetaID = metaID; - firstCoil = false; - } else if (metaID != this.coilMetaID) { - return false; - } - } - } else if (h == 3) {// inner ceiling (ulv casings + input + muffler) - if ((!addInputToMachineList(tTileEntity, CASING_INDEX)) && (!addMufflerToMachineList(tTileEntity, CASING_INDEX))) { - if (aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j) != CasingBlock) { - return false; - } - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j) != CasingMeta) { - return false; - } - } - } else {// inside air - if (!aBaseMetaTileEntity.getAirOffset(xDir + i, h, zDir + j)) { - return false; - } - } + if (checkInnerBroken( + xDir, zDir, + i, h, j, + aBaseMetaTileEntity, tTileEntity, + casingBlock, casingMeta, + firstCoil + ) + ) + return false; } else {// outer 5x5 without height - if (h == 0) {// outer floor (controller, output, energy, maintainance, rest ulv casings) - if ((!addMaintenanceToMachineList(tTileEntity, CASING_INDEX)) && (!addOutputToMachineList(tTileEntity, CASING_INDEX)) && (!addEnergyInputToMachineList(tTileEntity, CASING_INDEX))) { - if ((xDir + i != 0) || (zDir + j != 0)) {//no controller - if (aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j) != CasingBlock) { - return false; - } - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j) != CasingMeta) { - return false; - } - } - } - } else {// outer above floor (ulv casings) - if (aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j) != CasingBlock) { - return false; - } - if (aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j) != CasingMeta) { - return false; - } - } + if (checkOuterBroken( + xDir, zDir, + i, h, j, + aBaseMetaTileEntity, tTileEntity, + casingBlock, casingMeta + ) + ) + return false; } } } @@ -222,6 +181,112 @@ public class GT_MetaTileEntity_PyrolyseOven extends GT_MetaTileEntity_MultiBlock return true; } + private boolean checkInnerBroken(int xDir, + int zDir, + int a, + int b, + int c, + IGregTechTileEntity aBaseMetaTileEntity, + IGregTechTileEntity tTileEntity, + Block casingBlock, + int casingMeta, + MutableBoolean firstCoil + ) { + if (b == 0) {// inner floor (Coils) + return areCoilsBroken(xDir, zDir, a, b, c, aBaseMetaTileEntity, firstCoil); + } else if (b == 3) {// inner ceiling (ulv casings + input + muffler) + return checkInnerCeilingBroken(xDir, zDir, a, b, c, aBaseMetaTileEntity, tTileEntity, casingBlock, casingMeta); + } else {// inside air + return !aBaseMetaTileEntity.getAirOffset(xDir + a, b, zDir + c); + } + } + + private boolean checkOuterBroken(int xDir, + int zDir, + int a, + int b, + int c, + IGregTechTileEntity aBaseMetaTileEntity, + IGregTechTileEntity tTileEntity, + Block casingBlock, + int casingMeta) { + if (b == 0) {// outer floor (controller, output, energy, maintainance, rest ulv casings) + if (checkOuterFloorLoopControl(xDir, zDir, a, c, tTileEntity)) + return false; + } + // outer above floor (ulv casings) + if (aBaseMetaTileEntity.getBlockOffset(xDir + a, b, zDir + c) != casingBlock) { + return true; + } + return aBaseMetaTileEntity.getMetaIDOffset(xDir + a, b, zDir + c) != casingMeta; + } + + private boolean checkOuterFloorLoopControl(int xDir, + int zDir, + int a, + int c, + IGregTechTileEntity tTileEntity + ) { + if (addMaintenanceToMachineList(tTileEntity, CASING_INDEX)) { + return true; + } + if (addOutputToMachineList(tTileEntity, CASING_INDEX)) { + return true; + } + + if (addEnergyInputToMachineList(tTileEntity, CASING_INDEX)) { + return true; + } + + return (xDir + a == 0) && (zDir + c == 0); + } + + private boolean checkInnerCeilingBroken(int xDir, + int zDir, + int a, + int b, + int c, + IGregTechTileEntity aBaseMetaTileEntity, + IGregTechTileEntity tTileEntity, + Block casingBlock, + int casingMeta) { + if ((addInputToMachineList(tTileEntity, CASING_INDEX)) || (addMufflerToMachineList(tTileEntity, CASING_INDEX))) { + return false; + } + if (aBaseMetaTileEntity.getBlockOffset(xDir + a, b, zDir + c) != casingBlock) { + return true; + } + return aBaseMetaTileEntity.getMetaIDOffset(xDir + a, b, zDir + c) != casingMeta; + } + + private boolean areCoilsBroken(int xDir, + int zDir, + int a, + int b, + int c, + IGregTechTileEntity aBaseMetaTileEntity, + MutableBoolean firstCoil + ) { + Block coil = aBaseMetaTileEntity.getBlockOffset(xDir + a, b, zDir + c); + + if (!(coil instanceof IHeatingCoil)) + return true; + + int metaID = aBaseMetaTileEntity.getMetaIDOffset(xDir + a, b, zDir + c); + + HeatingCoilLevel coilHeat = ((IHeatingCoil) coil).getCoilHeat(metaID); + + if (coilHeat == HeatingCoilLevel.None) { + return true; + } else { + if (firstCoil.isTrue()) { + this.coilHeat = coilHeat; + firstCoil.setFalse(); + } else return coilHeat != this.coilHeat; + } + return false; + } + @Override public boolean isCorrectMachinePart(ItemStack aStack) { return true; @@ -247,6 +312,7 @@ public class GT_MetaTileEntity_PyrolyseOven extends GT_MetaTileEntity_MultiBlock return false; } + @Override public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { return new GT_MetaTileEntity_PyrolyseOven(this.mName); } @@ -255,13 +321,12 @@ public class GT_MetaTileEntity_PyrolyseOven extends GT_MetaTileEntity_MultiBlock int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX; int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ; int tX = aBaseMetaTileEntity.getXCoord() + xDir * 2; - int tY = (int) aBaseMetaTileEntity.getYCoord(); + int tY = aBaseMetaTileEntity.getYCoord(); int tZ = aBaseMetaTileEntity.getZCoord() + zDir * 2; for (int xPos = tX - 1; xPos <= tX + 1; xPos++) { for (int zPos = tZ - 1; zPos <= tZ + 1; zPos++) { if (aBaseMetaTileEntity.getBlock(xPos, tY, zPos) == GregTech_API.sBlockCasings1 && - aBaseMetaTileEntity.getMetaID(xPos, tY, zPos) == 13) - { + aBaseMetaTileEntity.getMetaID(xPos, tY, zPos) == 13) { aBaseMetaTileEntity.getWorld().setBlock(xPos, tY, zPos, GregTech_API.sBlockCasings5, 1, 3); } } |