diff options
Diffstat (limited to 'src/main/java/gtPlusPlus/xmod/gregtech/common')
128 files changed, 37036 insertions, 0 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/Meta_GT_Proxy.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/Meta_GT_Proxy.java new file mode 100644 index 0000000000..c53e217560 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/Meta_GT_Proxy.java @@ -0,0 +1,96 @@ +package gtPlusPlus.xmod.gregtech.common; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; + +import cpw.mods.fml.common.registry.LanguageRegistry; +import gregtech.api.enums.ItemList; +import gregtech.api.enums.TAE; +import gregtech.api.util.GT_LanguageManager; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.handler.AchievementHandler; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.LangUtils; +import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; +import gtPlusPlus.xmod.gregtech.common.covers.CoverManager; +import ic2.core.init.BlocksItems; +import ic2.core.init.InternalName; + +public class Meta_GT_Proxy { + + public static AchievementHandler mAssemblyAchievements; + + public Meta_GT_Proxy() {} + + public static void preInit() { + fixIC2FluidNames(); + CoverManager.generateCustomCovers(); + } + + public static void init() { + PollutionUtils.setPollutionFluids(); + fixIC2FluidNames(); + } + + public static void postInit() { + mAssemblyAchievements = new AchievementHandler(); + fixIC2FluidNames(); + + // Finalise TAE + TAE.finalizeTAE(); + } + + @SuppressWarnings("deprecation") + public static void fixIC2FluidNames() { + // Fix IC2 Hot Water name + try { + String aNewHeatedWaterName = "Heated Water"; + Logger.INFO("Renaming [IC2 Hotspring Water] --> [" + aNewHeatedWaterName + "]."); + LanguageRegistry.instance() + .addStringLocalization("fluidHotWater", "Heated Water"); + LanguageRegistry.instance() + .addStringLocalization("fluidHotWater", aNewHeatedWaterName); + LanguageRegistry.instance() + .addStringLocalization("ic2.fluidHotWater", aNewHeatedWaterName); + GT_LanguageManager.addStringLocalization("fluidHotWater", aNewHeatedWaterName); + GT_LanguageManager.addStringLocalization("ic2.fluidHotWater", aNewHeatedWaterName); + + Block b = BlocksItems.getFluidBlock(InternalName.fluidHotWater); + if (b != null) { + LanguageRegistry.addName(ItemUtils.getSimpleStack(b), aNewHeatedWaterName); + LanguageRegistry.instance() + .addStringLocalization(b.getUnlocalizedName(), aNewHeatedWaterName); + GT_LanguageManager.addStringLocalization(b.getUnlocalizedName(), aNewHeatedWaterName); + } + Fluid f = BlocksItems.getFluid(InternalName.fluidHotWater); + if (f != null) { + LanguageRegistry.instance() + .addStringLocalization(f.getUnlocalizedName(), aNewHeatedWaterName); + GT_LanguageManager.addStringLocalization(f.getUnlocalizedName(), aNewHeatedWaterName); + int aDam = FluidRegistry.getFluidID(f); + ItemStack s = ItemList.Display_Fluid.getWithDamage(1, aDam); + if (s != null) { + LanguageRegistry.addName(s, aNewHeatedWaterName); + } + } + + String[] aLangs = new String[] { "de_DE", "en_US", "en_GB", "en_IC", "es_AR", "es_ES", "es_MX", "es_UY", + "es_VE", "fr_CA", "fr_FR", "it_IT", "ko_KR", "pt_BR", "pt_PT", "ru_RU", "sv_SE", "tr_TR", "zh_CN", + "zh_TW", }; + String[] aLangValues = new String[] { "Erhitztes Wasser", "Heated Water", "Heated Water", "Heated Water", + "Agua caliente", "Agua caliente", "Agua caliente", "Agua caliente", "Agua caliente", "Eau chauffée", + "Eau chauffée", "Acqua riscaldata", "온수", "Água aquecida", "Água aquecida", "Вода с подогревом", + "Uppvärmt vatten", "Isıtılmış Su", "热水", "热水", }; + for (int i = 0; i < aLangs.length; i++) { + Logger + .REFLECTION("Trying to inject new lang data for " + aLangs[i] + ", using value: " + aLangValues[i]); + LangUtils.rewriteEntryForLanguageRegistry(aLangs[i], "fluidHotWater", aLangValues[i]); + LangUtils.rewriteEntryForLanguageRegistry(aLangs[i], "ic2.fluidHotWater", aLangValues[i]); + } + } catch (Throwable t) { + + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks.java new file mode 100644 index 0000000000..ee0d040394 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks.java @@ -0,0 +1,79 @@ +package gtPlusPlus.xmod.gregtech.common.blocks; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.TAE; +import gregtech.api.util.GT_LanguageManager; +import gregtech.common.blocks.GT_Material_Casings; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import gtPlusPlus.xmod.gregtech.api.objects.GTPP_CopiedBlockTexture; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.CasingTextureHandler; + +public class GregtechMetaCasingBlocks extends GregtechMetaCasingBlocksAbstract { + + CasingTextureHandler TextureHandler = new CasingTextureHandler(); + + public GregtechMetaCasingBlocks() { + super(GregtechMetaCasingItems.class, "miscutils.blockcasings", GT_Material_Casings.INSTANCE); + for (byte i = 0; i < 16; i = (byte) (i + 1)) { + if (i == 2 || i == 3 || i == 4) { + continue; + } + TAE.registerTexture(0, i, new GTPP_CopiedBlockTexture(this, 6, i)); + } + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".0.name", "Centrifuge Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".1.name", "Structural Coke Oven Casing"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".2.name", "Heat Resistant Coke Oven Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".3.name", "Heat Proof Coke Oven Casing"); // 60 + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".4.name", "Material Press Machine Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".5.name", "Electrolyzer Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".6.name", "Wire Factory Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".7.name", "Maceration Stack Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".8.name", "Matter Generation Coil"); // 65 + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".9.name", "Matter Fabricator Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".10.name", "Iron Plated Bricks"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".11.name", "Multitank Exterior Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".12.name", "Hastelloy-N Reactor Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".13.name", "Zeron-100 Reactor Shielding"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".14.name", "Blast Smelter Heat Containment Coil "); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".15.name", "Blast Smelter Casing Block"); + GregtechItemList.Casing_Centrifuge1.set(new ItemStack(this, 1, 0)); + GregtechItemList.Casing_CokeOven.set(new ItemStack(this, 1, 1)); + GregtechItemList.Casing_CokeOven_Coil1.set(new ItemStack(this, 1, 2)); + GregtechItemList.Casing_CokeOven_Coil2.set(new ItemStack(this, 1, 3)); + GregtechItemList.Casing_MaterialPress.set(new ItemStack(this, 1, 4)); + GregtechItemList.Casing_Electrolyzer.set(new ItemStack(this, 1, 5)); + GregtechItemList.Casing_WireFactory.set(new ItemStack(this, 1, 6)); + GregtechItemList.Casing_MacerationStack.set(new ItemStack(this, 1, 7)); + GregtechItemList.Casing_MatterGen.set(new ItemStack(this, 1, 8)); + GregtechItemList.Casing_MatterFab.set(new ItemStack(this, 1, 9)); + GregtechItemList.Casing_IronPlatedBricks.set(new ItemStack(this, 1, 10)); + GregtechItemList.Casing_MultitankExterior.set(new ItemStack(this, 1, 11)); + GregtechItemList.Casing_Reactor_I.set(new ItemStack(this, 1, 12)); + GregtechItemList.Casing_Reactor_II.set(new ItemStack(this, 1, 13)); + GregtechItemList.Casing_Coil_BlastSmelter.set(new ItemStack(this, 1, 14)); + GregtechItemList.Casing_BlastSmelter.set(new ItemStack(this, 1, 15)); + } + + @Override + public IIcon getIcon(final int ordinalSide, final int aMeta) { // Texture ID's. case 0 == ID[57] + return CasingTextureHandler.getIcon(ordinalSide, aMeta); + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(final IBlockAccess aWorld, final int xCoord, final int yCoord, final int zCoord, + final int ordinalSide) { + final GregtechMetaCasingBlocks i = this; + return CasingTextureHandler + .handleCasingsGT(aWorld, xCoord, yCoord, zCoord, ForgeDirection.getOrientation(ordinalSide), i); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks2.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks2.java new file mode 100644 index 0000000000..9d53c281a2 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks2.java @@ -0,0 +1,111 @@ +package gtPlusPlus.xmod.gregtech.common.blocks; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; + +import gregtech.api.enums.TAE; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_Utility; +import gregtech.common.blocks.GT_Material_Casings; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import gtPlusPlus.xmod.gregtech.api.objects.GTPP_CopiedBlockTexture; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.CasingTextureHandler2; +import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.storage.GregtechMetaTileEntity_PowerSubStationController; + +public class GregtechMetaCasingBlocks2 extends GregtechMetaCasingBlocksAbstract { + + @Override + public void getSubBlocks(Item aItem, CreativeTabs par2CreativeTabs, List aList) { + aList.add(new ItemStack(aItem, 1, 0)); + aList.add(new ItemStack(aItem, 1, 1)); + aList.add(new ItemStack(aItem, 1, 2)); + aList.add(new ItemStack(aItem, 1, 3)); + aList.add(new ItemStack(aItem, 1, 4)); + aList.add(new ItemStack(aItem, 1, 5)); + aList.add(new ItemStack(aItem, 1, 6)); + aList.add(new ItemStack(aItem, 1, 7)); + aList.add(new ItemStack(aItem, 1, 8)); + aList.add(new ItemStack(aItem, 1, 9)); + aList.add(new ItemStack(aItem, 1, 10)); + aList.add(new ItemStack(aItem, 1, 11)); + aList.add(new ItemStack(aItem, 1, 12)); + aList.add(new ItemStack(aItem, 1, 13)); + + aList.add(new ItemStack(aItem, 1, 15)); + + } + + public static class GregtechMetaCasingItemBlocks2 extends GregtechMetaCasingItems { + + public GregtechMetaCasingItemBlocks2(Block par1) { + super(par1); + } + + @Override + public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List aList, boolean aF3_H) { + int meta = aStack.getItemDamage(); + int tier = GregtechMetaTileEntity_PowerSubStationController.getCellTier(field_150939_a, meta); + if (meta == 7 && tier > 0) { + long capacity = GregtechMetaTileEntity_PowerSubStationController.getCapacityFromCellTier(tier); + aList.add("Energy Storage: " + GT_Utility.formatNumbers(capacity)); + } + super.addInformation(aStack, aPlayer, aList, aF3_H); + } + } + + public GregtechMetaCasingBlocks2() { + super(GregtechMetaCasingItemBlocks2.class, "gtplusplus.blockcasings.2", GT_Material_Casings.INSTANCE); + for (byte i = 0; i < 16; i = (byte) (i + 1)) { + if (i == 4 || i == 10 || i == 11 || i == 12 || i == 14) { + continue; + } + TAE.registerTexture(1, i, new GTPP_CopiedBlockTexture(this, 6, i)); + } + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".0.name", "Thermal Processing Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".1.name", "Hastelloy-N Sealant Block"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".2.name", "Hastelloy-X Structural Block"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".3.name", "Incoloy-DS Fluid Containment Block"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".4.name", "Wash Plant Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".5.name", "Industrial Sieve Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".6.name", "Large Sieve Grate"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".7.name", "Vanadium Redox Power Cell (EV)"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".8.name", "Sub-Station External Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".9.name", "Cyclotron Coil"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".10.name", "Cyclotron Outer Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".11.name", "Thermal Containment Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".12.name", "Bulk Production Frame"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".13.name", "Cutting Factory Frame"); + + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".15.name", "Sterile Farm Casing"); + + GregtechItemList.Casing_ThermalCentrifuge.set(new ItemStack(this, 1, 0)); + GregtechItemList.Casing_Refinery_External.set(new ItemStack(this, 1, 1)); + GregtechItemList.Casing_Refinery_Structural.set(new ItemStack(this, 1, 2)); + GregtechItemList.Casing_Refinery_Internal.set(new ItemStack(this, 1, 3)); + GregtechItemList.Casing_WashPlant.set(new ItemStack(this, 1, 4)); + GregtechItemList.Casing_Sifter.set(new ItemStack(this, 1, 5)); + GregtechItemList.Casing_SifterGrate.set(new ItemStack(this, 1, 6)); + GregtechItemList.Casing_Vanadium_Redox.set(new ItemStack(this, 1, 7)); + GregtechItemList.Casing_Power_SubStation.set(new ItemStack(this, 1, 8)); + GregtechItemList.Casing_Cyclotron_Coil.set(new ItemStack(this, 1, 9)); + GregtechItemList.Casing_Cyclotron_External.set(new ItemStack(this, 1, 10)); + GregtechItemList.Casing_ThermalContainment.set(new ItemStack(this, 1, 11)); + GregtechItemList.Casing_Autocrafter.set(new ItemStack(this, 1, 12)); + GregtechItemList.Casing_CuttingFactoryFrame.set(new ItemStack(this, 1, 13)); + + GregtechItemList.Casing_PLACEHOLDER_TreeFarmer.set(new ItemStack(this, 1, 15)); // Tree Farmer Textures + } + + @Override + public IIcon getIcon(final int ordinalSide, final int aMeta) { + return CasingTextureHandler2.getIcon(ordinalSide, aMeta); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks3.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks3.java new file mode 100644 index 0000000000..76fb077de1 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks3.java @@ -0,0 +1,379 @@ +package gtPlusPlus.xmod.gregtech.common.blocks; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.TAE; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_Utility; +import gregtech.common.blocks.GT_Material_Casings; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import gtPlusPlus.xmod.gregtech.api.objects.GTPP_CopiedBlockTexture; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.CasingTextureHandler3; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.storage.GregtechMetaTileEntity_PowerSubStationController; + +public class GregtechMetaCasingBlocks3 extends GregtechMetaCasingBlocksAbstract { + + public static boolean mConnectedMachineTextures = false; + CasingTextureHandler3 TextureHandler = new CasingTextureHandler3(); + + public static class GregtechMetaCasingItemBlocks3 extends GregtechMetaCasingItems { + + public GregtechMetaCasingItemBlocks3(Block par1) { + super(par1); + } + + @Override + public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List aList, boolean aF3_H) { + int meta = aStack.getItemDamage(); + int tier = GregtechMetaTileEntity_PowerSubStationController.getCellTier(field_150939_a, meta); + if (tier > 0) { + long capacity = GregtechMetaTileEntity_PowerSubStationController.getCapacityFromCellTier(tier); + aList.add("Energy Storage: " + GT_Utility.formatNumbers(capacity)); + } + super.addInformation(aStack, aPlayer, aList, aF3_H); + } + } + + public GregtechMetaCasingBlocks3() { + super(GregtechMetaCasingItemBlocks3.class, "gtplusplus.blockcasings.3", GT_Material_Casings.INSTANCE); + for (byte i = 0; i < 16; i = (byte) (i + 1)) { + // Free up Redox casing in TAE + if (i >= 4 && i <= 8) { + continue; + } + TAE.registerTexture(2, i, new GTPP_CopiedBlockTexture(this, 6, i)); + } + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".0.name", "Aquatic Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".1.name", "Inconel Reinforced Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".2.name", "Multi-Use Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".3.name", "Trinium Plated Casing"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".4.name", "Vanadium Redox Power Cell (IV)"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".5.name", "Vanadium Redox Power Cell (LuV)"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".6.name", "Vanadium Redox Power Cell (ZPM)"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".7.name", "Vanadium Redox Power Cell (UV)"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".8.name", "Vanadium Redox Power Cell (UHV)"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".9.name", "Supply Depot Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".10.name", "Advanced Cryogenic Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".11.name", "Volcanus Casing"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".12.name", "Fusion Machine Casing MK III"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".13.name", "Advanced Fusion Coil"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".14.name", "Unnamed"); // Can Use, don't + // change texture + // (Used for Fusion + // MK4) + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".15.name", "Containment Casing"); + GregtechItemList.Casing_FishPond.set(new ItemStack(this, 1, 0)); + GregtechItemList.Casing_Extruder.set(new ItemStack(this, 1, 1)); + GregtechItemList.Casing_Multi_Use.set(new ItemStack(this, 1, 2)); + GregtechItemList.Casing_BedrockMiner.set(new ItemStack(this, 1, 3)); + GregtechItemList.Casing_Vanadium_Redox_IV.set(new ItemStack(this, 1, 4)); + GregtechItemList.Casing_Vanadium_Redox_LuV.set(new ItemStack(this, 1, 5)); + GregtechItemList.Casing_Vanadium_Redox_ZPM.set(new ItemStack(this, 1, 6)); + GregtechItemList.Casing_Vanadium_Redox_UV.set(new ItemStack(this, 1, 7)); + GregtechItemList.Casing_Vanadium_Redox_MAX.set(new ItemStack(this, 1, 8)); + GregtechItemList.Casing_AmazonWarehouse.set(new ItemStack(this, 1, 9)); + GregtechItemList.Casing_AdvancedVacuum.set(new ItemStack(this, 1, 10)); + GregtechItemList.Casing_Adv_BlastFurnace.set(new ItemStack(this, 1, 11)); + GregtechItemList.Casing_Fusion_External.set(new ItemStack(this, 1, 12)); + GregtechItemList.Casing_Fusion_Internal.set(new ItemStack(this, 1, 13)); + GregtechItemList.Casing_Containment.set(new ItemStack(this, 1, 15)); + } + + @Override + public IIcon getIcon(final int ordinalSide, final int aMeta) { + return CasingTextureHandler3.getIcon(ordinalSide, aMeta); + } + + @SideOnly(Side.CLIENT) + @Override + public IIcon getIcon(final IBlockAccess aWorld, final int xCoord, final int yCoord, final int zCoord, + final int ordinalSide) { + final Block thisBlock = aWorld.getBlock(xCoord, yCoord, zCoord); + final int tMeta = aWorld.getBlockMetadata(xCoord, yCoord, zCoord); + if ((tMeta != 12) || !GregtechMetaCasingBlocks3.mConnectedMachineTextures) { + return getIcon(ordinalSide, tMeta); + } + final int tStartIndex = 0; + if (tMeta == 12) { + final boolean[] tConnectedSides = { + aWorld.getBlock(xCoord, yCoord - 1, zCoord) == thisBlock + && aWorld.getBlockMetadata(xCoord, yCoord - 1, zCoord) == tMeta, + aWorld.getBlock(xCoord, yCoord + 1, zCoord) == thisBlock + && aWorld.getBlockMetadata(xCoord, yCoord + 1, zCoord) == tMeta, + aWorld.getBlock(xCoord + 1, yCoord, zCoord) == thisBlock + && aWorld.getBlockMetadata(xCoord + 1, yCoord, zCoord) == tMeta, + aWorld.getBlock(xCoord, yCoord, zCoord + 1) == thisBlock + && aWorld.getBlockMetadata(xCoord, yCoord, zCoord + 1) == tMeta, + aWorld.getBlock(xCoord - 1, yCoord, zCoord) == thisBlock + && aWorld.getBlockMetadata(xCoord - 1, yCoord, zCoord) == tMeta, + aWorld.getBlock(xCoord, yCoord, zCoord - 1) == thisBlock + && aWorld.getBlockMetadata(xCoord, yCoord, zCoord - 1) == tMeta }; + switch (ordinalSide) { + case 0: { + if (tConnectedSides[0]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 7].getIcon(); + } + if (tConnectedSides[4] && tConnectedSides[5] && tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 6].getIcon(); + } + if (!tConnectedSides[4] && tConnectedSides[5] && tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 2].getIcon(); + } + if (tConnectedSides[4] && !tConnectedSides[5] && tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 3].getIcon(); + } + if (tConnectedSides[4] && tConnectedSides[5] && !tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 4].getIcon(); + } + if (tConnectedSides[4] && tConnectedSides[5] && tConnectedSides[2] && !tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 5].getIcon(); + } + if (!tConnectedSides[4] && !tConnectedSides[5] && tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 8].getIcon(); + } + if (tConnectedSides[4] && !tConnectedSides[5] && !tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 9].getIcon(); + } + if (tConnectedSides[4] && tConnectedSides[5] && !tConnectedSides[2] && !tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 10].getIcon(); + } + if (!tConnectedSides[4] && tConnectedSides[5] && tConnectedSides[2] && !tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 11].getIcon(); + } + if (!tConnectedSides[4] && !tConnectedSides[5] && !tConnectedSides[2] && !tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 7].getIcon(); + } + if (!tConnectedSides[4] && !tConnectedSides[2]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 1].getIcon(); + } + if (!tConnectedSides[5] && !tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 0].getIcon(); + } + } + case 1: { + if (tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 7].getIcon(); + } + if (tConnectedSides[4] && tConnectedSides[5] && tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 6].getIcon(); + } + if (!tConnectedSides[4] && tConnectedSides[5] && tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 2].getIcon(); + } + if (tConnectedSides[4] && !tConnectedSides[5] && tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 3].getIcon(); + } + if (tConnectedSides[4] && tConnectedSides[5] && !tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 4].getIcon(); + } + if (tConnectedSides[4] && tConnectedSides[5] && tConnectedSides[2] && !tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 5].getIcon(); + } + if (!tConnectedSides[4] && !tConnectedSides[5] && tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 8].getIcon(); + } + if (tConnectedSides[4] && !tConnectedSides[5] && !tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 9].getIcon(); + } + if (tConnectedSides[4] && tConnectedSides[5] && !tConnectedSides[2] && !tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 10].getIcon(); + } + if (!tConnectedSides[4] && tConnectedSides[5] && tConnectedSides[2] && !tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 11].getIcon(); + } + if (!tConnectedSides[4] && !tConnectedSides[5] && !tConnectedSides[2] && !tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 7].getIcon(); + } + if (!tConnectedSides[2] && !tConnectedSides[4]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 1].getIcon(); + } + if (!tConnectedSides[3] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 0].getIcon(); + } + } + case 2: { + if (tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 7].getIcon(); + } + if (tConnectedSides[2] && tConnectedSides[0] && tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 6].getIcon(); + } + if (!tConnectedSides[2] && tConnectedSides[0] && tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 2].getIcon(); + } + if (tConnectedSides[2] && !tConnectedSides[0] && tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 5].getIcon(); + } + if (tConnectedSides[2] && tConnectedSides[0] && !tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 4].getIcon(); + } + if (tConnectedSides[2] && tConnectedSides[0] && tConnectedSides[4] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 3].getIcon(); + } + if (!tConnectedSides[2] && !tConnectedSides[0] && tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 11].getIcon(); + } + if (tConnectedSides[2] && !tConnectedSides[0] && !tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 10].getIcon(); + } + if (tConnectedSides[2] && tConnectedSides[0] && !tConnectedSides[4] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 9].getIcon(); + } + if (!tConnectedSides[2] && tConnectedSides[0] && tConnectedSides[4] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 8].getIcon(); + } + if (!tConnectedSides[2] && !tConnectedSides[0] && !tConnectedSides[4] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 7].getIcon(); + } + if (!tConnectedSides[2] && !tConnectedSides[4]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 1].getIcon(); + } + if (!tConnectedSides[0] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 0].getIcon(); + } + } + case 3: { + if (tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 7].getIcon(); + } + if (tConnectedSides[2] && tConnectedSides[0] && tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 6].getIcon(); + } + if (!tConnectedSides[2] && tConnectedSides[0] && tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 4].getIcon(); + } + if (tConnectedSides[2] && !tConnectedSides[0] && tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 5].getIcon(); + } + if (tConnectedSides[2] && tConnectedSides[0] && !tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 2].getIcon(); + } + if (tConnectedSides[2] && tConnectedSides[0] && tConnectedSides[4] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 3].getIcon(); + } + if (!tConnectedSides[2] && !tConnectedSides[0] && tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 10].getIcon(); + } + if (tConnectedSides[2] && !tConnectedSides[0] && !tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 11].getIcon(); + } + if (tConnectedSides[2] && tConnectedSides[0] && !tConnectedSides[4] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 8].getIcon(); + } + if (!tConnectedSides[2] && tConnectedSides[0] && tConnectedSides[4] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 9].getIcon(); + } + if (!tConnectedSides[2] && !tConnectedSides[0] && !tConnectedSides[4] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 7].getIcon(); + } + if (!tConnectedSides[2] && !tConnectedSides[4]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 1].getIcon(); + } + if (!tConnectedSides[0] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 0].getIcon(); + } + } + case 4: { + if (tConnectedSides[4]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 7].getIcon(); + } + if (tConnectedSides[0] && tConnectedSides[3] && tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 6].getIcon(); + } + if (!tConnectedSides[0] && tConnectedSides[3] && tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 5].getIcon(); + } + if (tConnectedSides[0] && !tConnectedSides[3] && tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 4].getIcon(); + } + if (tConnectedSides[0] && tConnectedSides[3] && !tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 3].getIcon(); + } + if (tConnectedSides[0] && tConnectedSides[3] && tConnectedSides[1] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 2].getIcon(); + } + if (!tConnectedSides[0] && !tConnectedSides[3] && tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 10].getIcon(); + } + if (tConnectedSides[0] && !tConnectedSides[3] && !tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 9].getIcon(); + } + if (tConnectedSides[0] && tConnectedSides[3] && !tConnectedSides[1] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 8].getIcon(); + } + if (!tConnectedSides[0] && tConnectedSides[3] && tConnectedSides[1] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 11].getIcon(); + } + if (!tConnectedSides[0] && !tConnectedSides[3] && !tConnectedSides[1] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 7].getIcon(); + } + if (!tConnectedSides[0] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 0].getIcon(); + } + if (!tConnectedSides[3] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 1].getIcon(); + } + } + case 5: { + if (tConnectedSides[2]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 7].getIcon(); + } + if (tConnectedSides[0] && tConnectedSides[3] && tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 6].getIcon(); + } + if (!tConnectedSides[0] && tConnectedSides[3] && tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 5].getIcon(); + } + if (tConnectedSides[0] && !tConnectedSides[3] && tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 2].getIcon(); + } + if (tConnectedSides[0] && tConnectedSides[3] && !tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 3].getIcon(); + } + if (tConnectedSides[0] && tConnectedSides[3] && tConnectedSides[1] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 4].getIcon(); + } + if (!tConnectedSides[0] && !tConnectedSides[3] && tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 11].getIcon(); + } + if (tConnectedSides[0] && !tConnectedSides[3] && !tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 8].getIcon(); + } + if (tConnectedSides[0] && tConnectedSides[3] && !tConnectedSides[1] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 9].getIcon(); + } + if (!tConnectedSides[0] && tConnectedSides[3] && tConnectedSides[1] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 10].getIcon(); + } + if (!tConnectedSides[0] && !tConnectedSides[3] && !tConnectedSides[1] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 7].getIcon(); + } + if (!tConnectedSides[0] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 0].getIcon(); + } + if (!tConnectedSides[3] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 1].getIcon(); + } + break; + } + } + return TexturesGtBlock.CONNECTED_FUSION_HULLS[tStartIndex + 7].getIcon(); + } + return CasingTextureHandler3.getIcon(ordinalSide, tMeta); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks4.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks4.java new file mode 100644 index 0000000000..a150d7e828 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks4.java @@ -0,0 +1,126 @@ +package gtPlusPlus.xmod.gregtech.common.blocks; + +import java.util.List; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; + +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.util.GT_LanguageManager; +import gregtech.common.blocks.GT_Material_Casings; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import gtPlusPlus.xmod.gregtech.api.objects.GTPP_CopiedBlockTexture; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaCasingBlocks4 extends GregtechMetaCasingBlocksAbstract { + + public GregtechMetaCasingBlocks4() { + super(GregtechMetaCasingItems.class, "gtplusplus.blockcasings.4", GT_Material_Casings.INSTANCE); + for (byte i = 0; i < 16; i = (byte) (i + 1)) { + if (i == 2 || i == 4 || i == 5 || i == 6 || i == 7 || i == 8 || i == 12 || i == 13 || i == 14 || i == 15) { + continue; + } + TAE.registerTexture(3, i, new GTPP_CopiedBlockTexture(this, 6, i)); + } + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".0.name", "Naquadah Reactor Base"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".1.name", "Reactor Piping"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".2.name", "Naquadah Containment Chamber"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".3.name", "Tempered Arc Furnace Casing"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".4.name", "Quantum Force Transformer Coil Casings"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".10.name", "Vacuum Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".11.name", "Turbodyne Casing"); + + GregtechItemList.Casing_Naq_Reactor_A.set(new ItemStack(this, 1, 0)); + GregtechItemList.Casing_Naq_Reactor_B.set(new ItemStack(this, 1, 1)); + GregtechItemList.Casing_Naq_Reactor_C.set(new ItemStack(this, 1, 2)); + GregtechItemList.Casing_Industrial_Arc_Furnace.set(new ItemStack(this, 1, 3)); + GregtechItemList.Casing_Coil_QuantumForceTransformer.set(new ItemStack(this, 1, 4)); + GregtechItemList.Casing_Vacuum_Furnace.set(new ItemStack(this, 1, 10)); + GregtechItemList.Casing_RocketEngine.set(new ItemStack(this, 1, 11)); + } + + @Override + public IIcon getIcon(final int ordinalSide, final int aMeta) { + return getStaticIcon((byte) ordinalSide, (byte) aMeta); + } + + public static IIcon getStaticIcon(final byte aSide, final byte aMeta) { + // Texture ID's. case 0 == ID[57] + if ((aMeta >= 0) && (aMeta < 16)) { + switch (aMeta) { + case 0 -> { + return TexturesGtBlock.Casing_Trinium_Titanium.getIcon(); + } + case 1 -> { + return TexturesGtBlock.TEXTURE_TECH_C.getIcon(); + } + case 2 -> { + return TexturesGtBlock.TEXTURE_ORGANIC_PANEL_A_GLOWING.getIcon(); + } + case 3 -> { + return TexturesGtBlock.TEXTURE_METAL_PANEL_A.getIcon(); + } + case 4 -> { + return TexturesGtBlock.Casing_Coil_QFT.getIcon(); + } + case 5 -> { + return Textures.BlockIcons.RENDERING_ERROR.getIcon(); + } + case 6 -> { + return Textures.BlockIcons.RENDERING_ERROR.getIcon(); + } + case 7 -> { + return Textures.BlockIcons.RENDERING_ERROR.getIcon(); + } + case 8 -> { + return Textures.BlockIcons.RENDERING_ERROR.getIcon(); + } + case 9 -> { + return TexturesGtBlock.Casing_Material_MaragingSteel.getIcon(); + } + case 10 -> { + if (aSide < 2) { + return TexturesGtBlock.TEXTURE_STONE_RED_B.getIcon(); + } else { + return TexturesGtBlock.TEXTURE_STONE_RED_A.getIcon(); + } + } + case 11 -> { + return TexturesGtBlock.TEXTURE_CASING_ROCKETDYNE.getIcon(); + } + case 12 -> { + return Textures.BlockIcons.RENDERING_ERROR.getIcon(); + } + case 13 -> { + return Textures.BlockIcons.RENDERING_ERROR.getIcon(); + } + case 14 -> { + return Textures.BlockIcons.RENDERING_ERROR.getIcon(); + } + case 15 -> { + return Textures.BlockIcons.RENDERING_ERROR.getIcon(); + } + default -> { + return TexturesGtBlock.Casing_Material_MaragingSteel.getIcon(); + } + } + } + return TexturesGtBlock._PlaceHolder.getIcon(); + } + + @Override + public void getSubBlocks(Item aItem, CreativeTabs par2CreativeTabs, List aList) { + aList.add(new ItemStack(aItem, 1, 0)); + aList.add(new ItemStack(aItem, 1, 1)); + aList.add(new ItemStack(aItem, 1, 2)); + aList.add(new ItemStack(aItem, 1, 3)); + aList.add(new ItemStack(aItem, 1, 4)); + + aList.add(new ItemStack(aItem, 1, 10)); + aList.add(new ItemStack(aItem, 1, 11)); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks5.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks5.java new file mode 100644 index 0000000000..cc573cd188 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks5.java @@ -0,0 +1,159 @@ +package gtPlusPlus.xmod.gregtech.common.blocks; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.util.GT_LanguageManager; +import gregtech.common.blocks.GT_Material_Casings; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import gtPlusPlus.xmod.gregtech.api.objects.GTPP_CopiedBlockTexture; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGrinderMultiblock; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaCasingBlocks5 extends GregtechMetaCasingBlocksAbstract { + + // Free Indexes within TAE: 91, 92, 94, 100, 101, 102, 103, 104, 114, 116, 117, 118, 119, 120, 121, 124, 125, 126, + // 127 + // 19 Free Indexes + private static final TexturesGrinderMultiblock mGrinderOverlayHandler = new TexturesGrinderMultiblock(); + + public GregtechMetaCasingBlocks5() { + super(GregtechMetaCasingItems.class, "gtplusplus.blockcasings.5", GT_Material_Casings.INSTANCE); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".0.name", "IsaMill Exterior Casing"); // IsaMill + // Casing + TAE.registerTexture(0, 2, new GTPP_CopiedBlockTexture(this, 6, 0)); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".1.name", "IsaMill Piping"); // IsaMill + // Pipe + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".2.name", "IsaMill Gearbox"); // IsaMill + // Gearbox + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".3.name", "Elemental Confinement Shell"); // Duplicator + // Casing + TAE.registerTexture(0, 3, new GTPP_CopiedBlockTexture(this, 6, 3)); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".4.name", "Sparge Tower Exterior Casing"); // Sparge + // Tower + // Casing + TAE.registerTexture(0, 4, new GTPP_CopiedBlockTexture(this, 6, 4)); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".5.name", "Sturdy Printer Casing"); // Unused + TAE.registerTexture(1, 10, new GTPP_CopiedBlockTexture(this, 6, 5)); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".6.name", "Forge Casing"); // Forge Hammer + // Casing + TAE.registerTexture(1, 11, new GTPP_CopiedBlockTexture(this, 6, 6)); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".7.name", "Neutron Pulse Manipulator"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".8.name", "Cosmic Fabric Manipulator"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".9.name", "Infinity Infused Manipulator"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".10.name", "SpaceTime Continuum Ripper"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".11.name", "Neutron Shielding Core"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".12.name", "Cosmic Fabric Shielding Core"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".13.name", "Infinity Infused Shielding Core"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".14.name", "SpaceTime Bending Core"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".15.name", "Force Field Glass"); + + GregtechItemList.Casing_IsaMill_Casing.set(new ItemStack(this, 1, 0)); + GregtechItemList.Casing_IsaMill_Pipe.set(new ItemStack(this, 1, 1)); + GregtechItemList.Casing_IsaMill_Gearbox.set(new ItemStack(this, 1, 2)); + GregtechItemList.Casing_ElementalDuplicator.set(new ItemStack(this, 1, 3)); + GregtechItemList.Casing_Sparge_Tower_Exterior.set(new ItemStack(this, 1, 4)); + GregtechItemList.Casing_IndustrialAutoChisel.set(new ItemStack(this, 1, 5)); + GregtechItemList.Casing_IndustrialForgeHammer.set(new ItemStack(this, 1, 6)); + GregtechItemList.NeutronPulseManipulator.set(new ItemStack(this, 1, 7)); + GregtechItemList.CosmicFabricManipulator.set(new ItemStack(this, 1, 8)); + GregtechItemList.InfinityInfusedManipulator.set(new ItemStack(this, 1, 9)); + GregtechItemList.SpaceTimeContinuumRipper.set(new ItemStack(this, 1, 10)); + GregtechItemList.NeutronShieldingCore.set(new ItemStack(this, 1, 11)); + GregtechItemList.CosmicFabricShieldingCore.set(new ItemStack(this, 1, 12)); + GregtechItemList.InfinityInfusedShieldingCore.set(new ItemStack(this, 1, 13)); + GregtechItemList.SpaceTimeBendingCore.set(new ItemStack(this, 1, 14)); + GregtechItemList.ForceFieldGlass.set(new ItemStack(this, 1, 15)); + } + + @Override + public IIcon getIcon(final int ordinalSide, final int aMeta) { + return getStaticIcon(ordinalSide, aMeta); + } + + public static IIcon getStaticIcon(final int ordinalSide, final int aMeta) { + if ((aMeta >= 0) && (aMeta < 16)) { + switch (aMeta) { + case 0 -> { + return TexturesGtBlock.TEXTURE_PIPE_GRINDING_MILL.getIcon(); + } + case 1 -> { + return TexturesGtBlock.TEXTURE_CASING_GRINDING_MILL.getIcon(); + } + case 2 -> { + return TexturesGtBlock.TEXTURE_GEARBOX_GRINDING_MILL.getIcon(); + } + case 3 -> { + return TexturesGtBlock.TEXTURE_TECH_PANEL_D.getIcon(); + } + case 4 -> { + return TexturesGtBlock.Casing_Machine_Metal_Sheet_H.getIcon(); + } + case 5 -> { + return TexturesGtBlock.Casing_Machine_Metal_Sheet_I.getIcon(); + } + case 6 -> { + return TexturesGtBlock.TEXTURE_TECH_PANEL_H.getIcon(); + } + case 7 -> { + if (ordinalSide == 0 || ordinalSide == 1) { + return TexturesGtBlock.Manipulator_Top.getIcon(); + } + return TexturesGtBlock.NeutronPulseManipulator.getIcon(); + } + case 8 -> { + if (ordinalSide == 0 || ordinalSide == 1) { + return TexturesGtBlock.Manipulator_Top.getIcon(); + } + return TexturesGtBlock.CosmicFabricManipulator.getIcon(); + } + case 9 -> { + if (ordinalSide == 0 || ordinalSide == 1) { + return TexturesGtBlock.Manipulator_Top.getIcon(); + } + return TexturesGtBlock.InfinityInfusedManipulator.getIcon(); + } + case 10 -> { + if (ordinalSide == 0 || ordinalSide == 1) { + return TexturesGtBlock.Manipulator_Top.getIcon(); + } + return TexturesGtBlock.SpaceTimeContinuumRipper.getIcon(); + } + case 11 -> { + return TexturesGtBlock.NeutronShieldingCore.getIcon(); + } + case 12 -> { + return TexturesGtBlock.CosmicFabricShieldingCore.getIcon(); + } + case 13 -> { + return TexturesGtBlock.InfinityInfusedShieldingCore.getIcon(); + } + case 14 -> { + return TexturesGtBlock.SpaceTimeBendingCore.getIcon(); + } + case 15 -> { + if (ordinalSide == 0 || ordinalSide == 1) { + return TexturesGtBlock.Blank.getIcon(); + } + return TexturesGtBlock.ForceFieldGlass.getIcon(); + } + } + } + return Textures.BlockIcons.RENDERING_ERROR.getIcon(); + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(final IBlockAccess aWorld, final int xCoord, final int yCoord, final int zCoord, + final int ordinalSide) { + final GregtechMetaCasingBlocks5 i = this; + return mGrinderOverlayHandler.handleCasingsGT(aWorld, xCoord, yCoord, zCoord, ordinalSide, i); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks6.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks6.java new file mode 100644 index 0000000000..d257078461 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocks6.java @@ -0,0 +1,341 @@ +package gtPlusPlus.xmod.gregtech.common.blocks; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.TAE; +import gregtech.api.util.GT_LanguageManager; +import gregtech.common.blocks.GT_Material_Casings; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import gtPlusPlus.xmod.gregtech.api.objects.GTPP_CopiedBlockTexture; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.CasingTextureHandler6; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaCasingBlocks6 extends GregtechMetaCasingBlocksAbstract { + + public static boolean mConnectedMachineTextures = false; + CasingTextureHandler6 TextureHandler = new CasingTextureHandler6(); + + @Override + public void getSubBlocks(Item aItem, CreativeTabs par2CreativeTabs, List aList) { + for (int i = 0; i < 3; i++) { + aList.add(new ItemStack(aItem, 1, i)); + } + } + + public static class GregtechMetaCasingItemBlocks3 extends GregtechMetaCasingItems { + + public GregtechMetaCasingItemBlocks3(Block par1) { + super(par1); + } + + @Override + public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List aList, boolean aF3_H) { + super.addInformation(aStack, aPlayer, aList, aF3_H); + } + } + + public GregtechMetaCasingBlocks6() { + super(GregtechMetaCasingItemBlocks3.class, "gtplusplus.blockcasings.6", GT_Material_Casings.INSTANCE); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".0.name", "Fusion Machine Casing MK IV"); + TAE.registerTexture(3, 4, new GTPP_CopiedBlockTexture(this, 6, 0)); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".1.name", "Advanced Fusion Coil II"); + TAE.registerTexture(3, 5, new GTPP_CopiedBlockTexture(this, 6, 1)); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".2.name", "Unnamed"); + TAE.registerTexture(3, 6, new GTPP_CopiedBlockTexture(this, 6, 2)); + GregtechItemList.Casing_Fusion_External2.set(new ItemStack(this, 1, 0)); + GregtechItemList.Casing_Fusion_Internal2.set(new ItemStack(this, 1, 1)); + } + + @Override + public IIcon getIcon(final int ordinalSide, final int aMeta) { + return CasingTextureHandler6.getIcon(ordinalSide, aMeta); + } + + @SideOnly(Side.CLIENT) + @Override + public IIcon getIcon(final IBlockAccess aWorld, final int xCoord, final int yCoord, final int zCoord, + final int ordinalSide) { + final Block thisBlock = aWorld.getBlock(xCoord, yCoord, zCoord); + final int tMeta = aWorld.getBlockMetadata(xCoord, yCoord, zCoord); + if ((tMeta != 0) || !GregtechMetaCasingBlocks6.mConnectedMachineTextures) { + return getIcon(ordinalSide, tMeta); + } + final int tStartIndex = 0; + if (tMeta == 0) { + final boolean[] tConnectedSides = { + aWorld.getBlock(xCoord, yCoord - 1, zCoord) == thisBlock + && aWorld.getBlockMetadata(xCoord, yCoord - 1, zCoord) == tMeta, + aWorld.getBlock(xCoord, yCoord + 1, zCoord) == thisBlock + && aWorld.getBlockMetadata(xCoord, yCoord + 1, zCoord) == tMeta, + aWorld.getBlock(xCoord + 1, yCoord, zCoord) == thisBlock + && aWorld.getBlockMetadata(xCoord + 1, yCoord, zCoord) == tMeta, + aWorld.getBlock(xCoord, yCoord, zCoord + 1) == thisBlock + && aWorld.getBlockMetadata(xCoord, yCoord, zCoord + 1) == tMeta, + aWorld.getBlock(xCoord - 1, yCoord, zCoord) == thisBlock + && aWorld.getBlockMetadata(xCoord - 1, yCoord, zCoord) == tMeta, + aWorld.getBlock(xCoord, yCoord, zCoord - 1) == thisBlock + && aWorld.getBlockMetadata(xCoord, yCoord, zCoord - 1) == tMeta }; + switch (ordinalSide) { + case 0: { + if (tConnectedSides[0]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 7].getIcon(); + } + if (tConnectedSides[4] && tConnectedSides[5] && tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 6].getIcon(); + } + if (!tConnectedSides[4] && tConnectedSides[5] && tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 2].getIcon(); + } + if (tConnectedSides[4] && !tConnectedSides[5] && tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 3].getIcon(); + } + if (tConnectedSides[4] && tConnectedSides[5] && !tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 4].getIcon(); + } + if (tConnectedSides[4] && tConnectedSides[5] && tConnectedSides[2] && !tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 5].getIcon(); + } + if (!tConnectedSides[4] && !tConnectedSides[5] && tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 8].getIcon(); + } + if (tConnectedSides[4] && !tConnectedSides[5] && !tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 9].getIcon(); + } + if (tConnectedSides[4] && tConnectedSides[5] && !tConnectedSides[2] && !tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 10].getIcon(); + } + if (!tConnectedSides[4] && tConnectedSides[5] && tConnectedSides[2] && !tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 11].getIcon(); + } + if (!tConnectedSides[4] && !tConnectedSides[5] && !tConnectedSides[2] && !tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 7].getIcon(); + } + if (!tConnectedSides[4] && !tConnectedSides[2]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 1].getIcon(); + } + if (!tConnectedSides[5] && !tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 0].getIcon(); + } + } + case 1: { + if (tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 7].getIcon(); + } + if (tConnectedSides[4] && tConnectedSides[5] && tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 6].getIcon(); + } + if (!tConnectedSides[4] && tConnectedSides[5] && tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 2].getIcon(); + } + if (tConnectedSides[4] && !tConnectedSides[5] && tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 3].getIcon(); + } + if (tConnectedSides[4] && tConnectedSides[5] && !tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 4].getIcon(); + } + if (tConnectedSides[4] && tConnectedSides[5] && tConnectedSides[2] && !tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 5].getIcon(); + } + if (!tConnectedSides[4] && !tConnectedSides[5] && tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 8].getIcon(); + } + if (tConnectedSides[4] && !tConnectedSides[5] && !tConnectedSides[2] && tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 9].getIcon(); + } + if (tConnectedSides[4] && tConnectedSides[5] && !tConnectedSides[2] && !tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 10].getIcon(); + } + if (!tConnectedSides[4] && tConnectedSides[5] && tConnectedSides[2] && !tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 11].getIcon(); + } + if (!tConnectedSides[4] && !tConnectedSides[5] && !tConnectedSides[2] && !tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 7].getIcon(); + } + if (!tConnectedSides[2] && !tConnectedSides[4]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 1].getIcon(); + } + if (!tConnectedSides[3] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 0].getIcon(); + } + } + case 2: { + if (tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 7].getIcon(); + } + if (tConnectedSides[2] && tConnectedSides[0] && tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 6].getIcon(); + } + if (!tConnectedSides[2] && tConnectedSides[0] && tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 2].getIcon(); + } + if (tConnectedSides[2] && !tConnectedSides[0] && tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 5].getIcon(); + } + if (tConnectedSides[2] && tConnectedSides[0] && !tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 4].getIcon(); + } + if (tConnectedSides[2] && tConnectedSides[0] && tConnectedSides[4] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 3].getIcon(); + } + if (!tConnectedSides[2] && !tConnectedSides[0] && tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 11].getIcon(); + } + if (tConnectedSides[2] && !tConnectedSides[0] && !tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 10].getIcon(); + } + if (tConnectedSides[2] && tConnectedSides[0] && !tConnectedSides[4] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 9].getIcon(); + } + if (!tConnectedSides[2] && tConnectedSides[0] && tConnectedSides[4] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 8].getIcon(); + } + if (!tConnectedSides[2] && !tConnectedSides[0] && !tConnectedSides[4] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 7].getIcon(); + } + if (!tConnectedSides[2] && !tConnectedSides[4]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 1].getIcon(); + } + if (!tConnectedSides[0] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 0].getIcon(); + } + } + case 3: { + if (tConnectedSides[3]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 7].getIcon(); + } + if (tConnectedSides[2] && tConnectedSides[0] && tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 6].getIcon(); + } + if (!tConnectedSides[2] && tConnectedSides[0] && tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 4].getIcon(); + } + if (tConnectedSides[2] && !tConnectedSides[0] && tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 5].getIcon(); + } + if (tConnectedSides[2] && tConnectedSides[0] && !tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 2].getIcon(); + } + if (tConnectedSides[2] && tConnectedSides[0] && tConnectedSides[4] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 3].getIcon(); + } + if (!tConnectedSides[2] && !tConnectedSides[0] && tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 10].getIcon(); + } + if (tConnectedSides[2] && !tConnectedSides[0] && !tConnectedSides[4] && tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 11].getIcon(); + } + if (tConnectedSides[2] && tConnectedSides[0] && !tConnectedSides[4] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 8].getIcon(); + } + if (!tConnectedSides[2] && tConnectedSides[0] && tConnectedSides[4] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 9].getIcon(); + } + if (!tConnectedSides[2] && !tConnectedSides[0] && !tConnectedSides[4] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 7].getIcon(); + } + if (!tConnectedSides[2] && !tConnectedSides[4]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 1].getIcon(); + } + if (!tConnectedSides[0] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 0].getIcon(); + } + } + case 4: { + if (tConnectedSides[4]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 7].getIcon(); + } + if (tConnectedSides[0] && tConnectedSides[3] && tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 6].getIcon(); + } + if (!tConnectedSides[0] && tConnectedSides[3] && tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 5].getIcon(); + } + if (tConnectedSides[0] && !tConnectedSides[3] && tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 4].getIcon(); + } + if (tConnectedSides[0] && tConnectedSides[3] && !tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 3].getIcon(); + } + if (tConnectedSides[0] && tConnectedSides[3] && tConnectedSides[1] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 2].getIcon(); + } + if (!tConnectedSides[0] && !tConnectedSides[3] && tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 10].getIcon(); + } + if (tConnectedSides[0] && !tConnectedSides[3] && !tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 9].getIcon(); + } + if (tConnectedSides[0] && tConnectedSides[3] && !tConnectedSides[1] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 8].getIcon(); + } + if (!tConnectedSides[0] && tConnectedSides[3] && tConnectedSides[1] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 11].getIcon(); + } + if (!tConnectedSides[0] && !tConnectedSides[3] && !tConnectedSides[1] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 7].getIcon(); + } + if (!tConnectedSides[0] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 0].getIcon(); + } + if (!tConnectedSides[3] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 1].getIcon(); + } + } + case 5: { + if (tConnectedSides[2]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 7].getIcon(); + } + if (tConnectedSides[0] && tConnectedSides[3] && tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 6].getIcon(); + } + if (!tConnectedSides[0] && tConnectedSides[3] && tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 5].getIcon(); + } + if (tConnectedSides[0] && !tConnectedSides[3] && tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 2].getIcon(); + } + if (tConnectedSides[0] && tConnectedSides[3] && !tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 3].getIcon(); + } + if (tConnectedSides[0] && tConnectedSides[3] && tConnectedSides[1] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 4].getIcon(); + } + if (!tConnectedSides[0] && !tConnectedSides[3] && tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 11].getIcon(); + } + if (tConnectedSides[0] && !tConnectedSides[3] && !tConnectedSides[1] && tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 8].getIcon(); + } + if (tConnectedSides[0] && tConnectedSides[3] && !tConnectedSides[1] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 9].getIcon(); + } + if (!tConnectedSides[0] && tConnectedSides[3] && tConnectedSides[1] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 10].getIcon(); + } + if (!tConnectedSides[0] && !tConnectedSides[3] && !tConnectedSides[1] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 7].getIcon(); + } + if (!tConnectedSides[0] && !tConnectedSides[1]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 0].getIcon(); + } + if (!tConnectedSides[3] && !tConnectedSides[5]) { + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 1].getIcon(); + } + break; + } + } + return TexturesGtBlock.CONNECTED_FUSION_HULLS_MK4[tStartIndex + 7].getIcon(); + } + return CasingTextureHandler6.getIcon(ordinalSide, tMeta); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocksAbstract.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocksAbstract.java new file mode 100644 index 0000000000..a87f6c92b3 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocksAbstract.java @@ -0,0 +1,151 @@ +package gtPlusPlus.xmod.gregtech.common.blocks; + +import java.util.List; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EnumCreatureType; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.StatCollector; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.GregTech_API; +import gregtech.api.util.GT_LanguageManager; +import gregtech.common.blocks.GT_Block_Casings_Abstract; +import gtPlusPlus.core.creative.AddToCreativeTab; + +public abstract class GregtechMetaCasingBlocksAbstract extends GT_Block_Casings_Abstract { + + public GregtechMetaCasingBlocksAbstract(final Class<? extends ItemBlock> aItemClass, final String aName, + final Material aMaterial) { + super(aItemClass, aName, aMaterial); + this.setStepSound(soundTypeMetal); + this.setCreativeTab(AddToCreativeTab.tabMachines); + GregTech_API.registerMachineBlock(this, -1); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + "." + 32767 + ".name", "Any Sub Block of this"); + } + + @Override + public String getHarvestTool(final int aMeta) { + return "wrench"; + } + + @Override + public int getHarvestLevel(final int aMeta) { + return 2; + } + + @Override + public float getBlockHardness(final World aWorld, final int aX, final int aY, final int aZ) { + return Blocks.iron_block.getBlockHardness(aWorld, aX, aY, aZ); + } + + @Override + public float getExplosionResistance(final Entity aTNT) { + return Blocks.iron_block.getExplosionResistance(aTNT); + } + + @Override + protected boolean canSilkHarvest() { + return false; + } + + @Override + public void onBlockAdded(final World aWorld, final int aX, final int aY, final int aZ) { + if (GregTech_API.isMachineBlock(this, aWorld.getBlockMetadata(aX, aY, aZ))) { + GregTech_API.causeMachineUpdate(aWorld, aX, aY, aZ); + } + } + + @Override + public String getUnlocalizedName() { + return this.mUnlocalizedName; + } + + @Override + public String getLocalizedName() { + return StatCollector.translateToLocal(this.mUnlocalizedName + ".name"); + } + + @Override + public boolean canBeReplacedByLeaves(final IBlockAccess aWorld, final int aX, final int aY, final int aZ) { + return false; + } + + @Override + public boolean isNormalCube(final IBlockAccess aWorld, final int aX, final int aY, final int aZ) { + return true; + } + + @Override + public boolean renderAsNormalBlock() { + return true; + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + @Override + public int getRenderBlockPass() { + return 0; + } + + @Override + public void breakBlock(final World aWorld, final int aX, final int aY, final int aZ, final Block aBlock, + final int aMetaData) { + if (GregTech_API.isMachineBlock(this, aWorld.getBlockMetadata(aX, aY, aZ))) { + GregTech_API.causeMachineUpdate(aWorld, aX, aY, aZ); + } + } + + @Override + public boolean canCreatureSpawn(final EnumCreatureType type, final IBlockAccess world, final int x, final int y, + final int z) { + return false; + } + + @Override + public int damageDropped(final int par1) { + return par1; + } + + @Override + public int getDamageValue(final World par1World, final int par2, final int par3, final int par4) { + return par1World.getBlockMetadata(par2, par3, par4); + } + + @Override + public int quantityDropped(final Random par1Random) { + return 1; + } + + @Override + public Item getItemDropped(final int par1, final Random par2Random, final int par3) { + return Item.getItemFromBlock(this); + } + + @Override + @SideOnly(Side.CLIENT) + public void registerBlockIcons(final IIconRegister aIconRegister) {} + + @Override + @SideOnly(Side.CLIENT) + public void getSubBlocks(final Item aItem, final CreativeTabs par2CreativeTabs, final List aList) { + for (int i = 0; i < 16; i++) { + aList.add(new ItemStack(aItem, 1, i)); + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocksPipeGearbox.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocksPipeGearbox.java new file mode 100644 index 0000000000..ad2b11f924 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingBlocksPipeGearbox.java @@ -0,0 +1,91 @@ +package gtPlusPlus.xmod.gregtech.common.blocks; + +import java.util.HashMap; + +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.Textures; +import gregtech.api.util.GT_LanguageManager; +import gregtech.common.blocks.GT_Material_Casings; +import gtPlusPlus.core.material.ALLOY; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaCasingBlocksPipeGearbox extends GregtechMetaCasingBlocksAbstract { + + private static HashMap<Integer, Integer> sMaterialMapping = new HashMap<>(); + + public GregtechMetaCasingBlocksPipeGearbox() { + super(GregtechMetaCasingItems.class, "gtplusplus.blockcasings.pipesgears", GT_Material_Casings.INSTANCE); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".0.name", "Eglin Steel Gear Box Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".1.name", "Inconel-792 Gear Box Casing"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".2.name", "Incoloy MA956 Gear Box Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".3.name", "Nitinol-60 Gear Box Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".4.name", "Zeron-100 Gear Box Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".5.name", "Pikyonium Gear Box Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".6.name", "Titansteel Gear Box Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".7.name", "Abyssal Gear Box Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".8.name", "Babbit Alloy Pipe Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".9.name", "Inconel-690 Pipe Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".10.name", "Stellite Pipe Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".11.name", "Nitinol-60 Pipe Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".12.name", "Lafium Pipe Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".13.name", "Cinobite Pipe Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".14.name", "Titansteel Pipe Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".15.name", "Abyssal Pipe Casing"); + + int aMappingID = 0; + sMaterialMapping.put(aMappingID++, ALLOY.EGLIN_STEEL.getRgbAsHex()); + sMaterialMapping.put(aMappingID++, ALLOY.INCONEL_792.getRgbAsHex()); + sMaterialMapping.put(aMappingID++, ALLOY.INCOLOY_MA956.getRgbAsHex()); + sMaterialMapping.put(aMappingID++, ALLOY.NITINOL_60.getRgbAsHex()); + sMaterialMapping.put(aMappingID++, ALLOY.ZERON_100.getRgbAsHex()); + sMaterialMapping.put(aMappingID++, ALLOY.PIKYONIUM.getRgbAsHex()); + sMaterialMapping.put(aMappingID++, ALLOY.TITANSTEEL.getRgbAsHex()); + sMaterialMapping.put(aMappingID++, ALLOY.ABYSSAL.getRgbAsHex()); + sMaterialMapping.put(aMappingID++, ALLOY.BABBIT_ALLOY.getRgbAsHex()); + sMaterialMapping.put(aMappingID++, ALLOY.INCONEL_690.getRgbAsHex()); + sMaterialMapping.put(aMappingID++, ALLOY.STELLITE.getRgbAsHex()); + sMaterialMapping.put(aMappingID++, ALLOY.NITINOL_60.getRgbAsHex()); + sMaterialMapping.put(aMappingID++, ALLOY.LAFIUM.getRgbAsHex()); + sMaterialMapping.put(aMappingID++, ALLOY.CINOBITE.getRgbAsHex()); + sMaterialMapping.put(aMappingID++, ALLOY.TITANSTEEL.getRgbAsHex()); + sMaterialMapping.put(aMappingID++, ALLOY.ABYSSAL.getRgbAsHex()); + } + + @Override + public IIcon getIcon(final int ordinalSide, final int meta) { + if ((meta >= 0) && (meta < 16)) { + switch (meta) { + case 0, 1, 2, 3, 4, 5, 6, 7 -> { + return TexturesGtBlock.TEXTURE_GEARBOX_GENERIC.getIcon(); + } + case 8, 9, 10, 11, 12, 13, 14, 15 -> { + return TexturesGtBlock.TEXTURE_PIPE_GENERIC.getIcon(); + } + } + } + return Textures.BlockIcons.RENDERING_ERROR.getIcon(); + } + + @SideOnly(Side.CLIENT) + @Override + public int colorMultiplier(final IBlockAccess par1IBlockAccess, final int par2, final int par3, final int par4) { + return sMaterialMapping.get(par1IBlockAccess.getBlockMetadata(par2, par3, par4)); + } + + @SideOnly(Side.CLIENT) + @Override + public int getRenderColor(final int aMeta) { + return sMaterialMapping.get(aMeta); + } + + @SideOnly(Side.CLIENT) + @Override + public int getBlockColor() { + return super.getBlockColor(); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingItems.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingItems.java new file mode 100644 index 0000000000..f86c6af265 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaCasingItems.java @@ -0,0 +1,10 @@ +package gtPlusPlus.xmod.gregtech.common.blocks; + +import net.minecraft.block.Block; + +public class GregtechMetaCasingItems extends GregtechMetaItemCasingsAbstract { + + public GregtechMetaCasingItems(final Block par1) { + super(par1); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaItemCasingsAbstract.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaItemCasingsAbstract.java new file mode 100644 index 0000000000..23d9ab5007 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaItemCasingsAbstract.java @@ -0,0 +1,67 @@ +package gtPlusPlus.xmod.gregtech.common.blocks; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; + +import gregtech.api.util.GT_LanguageManager; + +public abstract class GregtechMetaItemCasingsAbstract extends ItemBlock { + + protected final String mCasing_Centrifuge = GT_LanguageManager + .addStringLocalization("mu.centrifugecasing", "Warning! Standing in the Centrifuge not recommended"); + protected final String mCasing_CokeOven = GT_LanguageManager + .addStringLocalization("mu.cokeoven", "Sturdy and Strong"); + protected final String mCasing_CokeCoil1 = GT_LanguageManager + .addStringLocalization("mu.coil01tooltip", "Base Heating Capacity = 1350 Kelvin"); + protected final String mCasing_CokeCoil2 = GT_LanguageManager + .addStringLocalization("mu.coil02tooltip", "Base Heating Capacity = 2275 Kelvin"); + protected final String mNoMobsToolTip = GT_LanguageManager + .addStringLocalization("gt.nomobspawnsonthisblock", "Mobs cannot Spawn on this Block"); + protected final String mNoTileEntityToolTip = GT_LanguageManager + .addStringLocalization("gt.notileentityinthisblock", "This is NOT a TileEntity!"); + + public GregtechMetaItemCasingsAbstract(final Block par1) { + super(par1); + this.setMaxDamage(0); + this.setHasSubtypes(true); + // setCreativeTab(AddToCreativeTab.tabMachines); + } + + @Override + public int getMetadata(final int aMeta) { + return aMeta; + } + + @Override + public String getUnlocalizedName(final ItemStack aStack) { + return this.field_150939_a.getUnlocalizedName() + "." + this.getDamage(aStack); + } + + @Override + public void addInformation(final ItemStack aStack, final EntityPlayer aPlayer, final List aList, + final boolean aF3_H) { + super.addInformation(aStack, aPlayer, aList, aF3_H); + switch (this.getDamage(aStack)) { + case 0: + // aList.add(this.mCasing_Centrifuge); + break; + case 1: + // aList.add(this.mCasing_CokeOven); + break; + case 2: + // aList.add(this.mCasing_CokeCoil1); + break; + case 3: + // aList.add(this.mCasing_CokeCoil2); + break; + default: + break; + } + aList.add(this.mNoMobsToolTip); + aList.add(this.mNoTileEntityToolTip); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaSpecialMachineCasings.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaSpecialMachineCasings.java new file mode 100644 index 0000000000..473c13f3da --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaSpecialMachineCasings.java @@ -0,0 +1,76 @@ +package gtPlusPlus.xmod.gregtech.common.blocks; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; + +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.util.GT_LanguageManager; +import gregtech.common.blocks.GT_Material_Casings; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import gtPlusPlus.xmod.gregtech.api.objects.GTPP_CopiedBlockTexture; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaSpecialMachineCasings extends GregtechMetaCasingBlocksAbstract { + + @Override + public void getSubBlocks(Item aItem, CreativeTabs par2CreativeTabs, List aList) { + for (int i = 0; i < 4; i++) { + aList.add(new ItemStack(aItem, 1, i)); + } + } + + public static class SpecialCasingItemBlock extends GregtechMetaCasingItems { + + public SpecialCasingItemBlock(Block par1) { + super(par1); + } + + @Override + public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List aList, boolean aF3_H) { + int aMeta = aStack.getItemDamage(); + if (aMeta < 10) { + // aList.add("Tier: "+GT_Values.VN[aMeta]); + } + super.addInformation(aStack, aPlayer, aList, aF3_H); + } + } + + public GregtechMetaSpecialMachineCasings() { + super(SpecialCasingItemBlock.class, "gtplusplus.blockspecialcasings.2", GT_Material_Casings.INSTANCE); + for (byte i = 0; i < 16; i = (byte) (i + 1)) { + // TAE.registerTextures(new GT_CopiedBlockTexture(this, 6, i)); + // Don't register these Textures, They already exist within vanilla GT. (May not exist in 5.08) + } + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".0.name", "Strong Bronze Machine Casing"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".1.name", "Sturdy Aluminium Machine Casing"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".2.name", "Vigorous Laurenium Machine Casing"); + TAE.registerTexture(84, new GTPP_CopiedBlockTexture(this, 6, 2)); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".3.name", "Rugged Botmium Machine Casing"); + + GregtechItemList.Casing_Machine_Custom_1.set(new ItemStack(this, 1, 0)); + GregtechItemList.Casing_Machine_Custom_2.set(new ItemStack(this, 1, 1)); + GregtechItemList.Casing_Machine_Custom_3.set(new ItemStack(this, 1, 2)); + GregtechItemList.Casing_Machine_Custom_4.set(new ItemStack(this, 1, 3)); + } + + @Override + public IIcon getIcon(int ordinalSide, int aMeta) { + return switch (aMeta) { + case 0 -> Textures.BlockIcons.MACHINE_BRONZEPLATEDBRICKS.getIcon(); + case 1 -> Textures.BlockIcons.MACHINE_CASING_FROST_PROOF.getIcon(); + case 2 -> TexturesGtBlock.Casing_Material_Laurenium.getIcon(); + case 3 -> Textures.BlockIcons.MACHINE_HEATPROOFCASING.getIcon(); + default -> Textures.BlockIcons.RENDERING_ERROR.getIcon(); + }; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaSpecialMultiCasings.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaSpecialMultiCasings.java new file mode 100644 index 0000000000..1d7c853e71 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaSpecialMultiCasings.java @@ -0,0 +1,120 @@ +package gtPlusPlus.xmod.gregtech.common.blocks; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.util.GT_LanguageManager; +import gregtech.common.blocks.GT_Material_Casings; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import gtPlusPlus.xmod.gregtech.api.objects.GTPP_CopiedBlockTexture; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.turbine.LargeTurbineTextureHandler; + +public class GregtechMetaSpecialMultiCasings extends GregtechMetaCasingBlocksAbstract { + + public static class SpecialCasingItemBlock extends GregtechMetaCasingItems { + + public SpecialCasingItemBlock(Block par1) { + super(par1); + } + + @Override + public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List aList, boolean aF3_H) { + int aMeta = aStack.getItemDamage(); + if (aMeta < 10) { + // aList.add("Tier: "+GT_Values.VN[aMeta]); + } + super.addInformation(aStack, aPlayer, aList, aF3_H); + } + } + + public GregtechMetaSpecialMultiCasings() { + super(SpecialCasingItemBlock.class, "gtplusplus.blockspecialcasings.1", GT_Material_Casings.INSTANCE); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".0.name", "Turbine Shaft"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".1.name", "Reinforced Steam Turbine Casing"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".2.name", "Reinforced HP Steam Turbine Casing"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".3.name", "Reinforced Gas Turbine Casing"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".4.name", "Reinforced Plasma Turbine Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".5.name", "Tesla Containment Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".6.name", "Structural Solar Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".7.name", "Salt Containment Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".8.name", "Thermally Insulated Casing"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".9.name", "Flotation Cell Casings"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".10.name", "Reinforced Engine Casing"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".11.name", "Molecular Containment Casing"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".12.name", "High Voltage Current Capacitor"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".13.name", "Particle Containment Casing"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".14.name", "Reinforced Heat Exchanger Casing"); + GT_LanguageManager + .addStringLocalization(this.getUnlocalizedName() + ".15.name", "Reinforced SC Turbine Casing"); + TAE.registerTexture(1, 12, new GTPP_CopiedBlockTexture(this, 6, 14)); + + GregtechItemList.Casing_Turbine_Shaft.set(new ItemStack(this, 1, 0)); + GregtechItemList.Casing_Turbine_LP.set(new ItemStack(this, 1, 1)); + GregtechItemList.Casing_Turbine_HP.set(new ItemStack(this, 1, 2)); + GregtechItemList.Casing_Turbine_Gas.set(new ItemStack(this, 1, 3)); + GregtechItemList.Casing_Turbine_Plasma.set(new ItemStack(this, 1, 4)); + GregtechItemList.Casing_SolarTower_Structural.set(new ItemStack(this, 1, 6)); + GregtechItemList.Casing_SolarTower_SaltContainment.set(new ItemStack(this, 1, 7)); + GregtechItemList.Casing_SolarTower_HeatContainment.set(new ItemStack(this, 1, 8)); + GregtechItemList.Casing_Flotation_Cell.set(new ItemStack(this, 1, 9)); + GregtechItemList.Casing_Reinforced_Engine_Casing.set(new ItemStack(this, 1, 10)); + GregtechItemList.Casing_Molecular_Transformer_1.set(new ItemStack(this, 1, 11)); + GregtechItemList.Casing_Molecular_Transformer_2.set(new ItemStack(this, 1, 12)); + GregtechItemList.Casing_Molecular_Transformer_3.set(new ItemStack(this, 1, 13)); + GregtechItemList.Casing_XL_HeatExchanger.set(new ItemStack(this, 1, 14)); + GregtechItemList.Casing_Turbine_SC.set(new ItemStack(this, 1, 15)); + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(final IBlockAccess aWorld, final int xCoord, final int yCoord, final int zCoord, + final int ordinalSide) { + return LargeTurbineTextureHandler + .handleCasingsGT(aWorld, xCoord, yCoord, zCoord, ForgeDirection.getOrientation(ordinalSide), this); + } + + @Override + public IIcon getIcon(final int ordinalSide, final int aMeta) { + return getStaticIcon((byte) ordinalSide, (byte) aMeta); + } + + public static IIcon getStaticIcon(final int ordinalSide, final byte aMeta) { + return switch (aMeta) { + case 0 -> TexturesGtBlock.Casing_Redox_1.getIcon(); + case 1 -> Textures.BlockIcons.MACHINE_CASING_TURBINE.getIcon(); + case 2 -> Textures.BlockIcons.MACHINE_CASING_STABLE_TITANIUM.getIcon(); + case 3 -> Textures.BlockIcons.MACHINE_CASING_CLEAN_STAINLESSSTEEL.getIcon(); + case 4 -> Textures.BlockIcons.MACHINE_CASING_ROBUST_TUNGSTENSTEEL.getIcon(); + case 5 -> TexturesGtBlock.Casing_Material_RedSteel.getIcon(); + case 6 -> TexturesGtBlock.Casing_Material_MaragingSteel.getIcon(); + case 7 -> TexturesGtBlock.Casing_Material_Stellite.getIcon(); + case 8 -> TexturesGtBlock.Casing_Machine_Simple_Top.getIcon(); + case 9 -> TexturesGtBlock.TEXTURE_CASING_FLOTATION.getIcon(); + case 10 -> TexturesGtBlock.Casing_Material_Talonite.getIcon(); + case 11 -> Textures.BlockIcons.MACHINE_CASING_RADIATIONPROOF.getIcon(); + case 12 -> TexturesGtBlock.Casing_Redox_5.getIcon(); + case 13 -> TexturesGtBlock.TEXTURE_MAGIC_PANEL_B.getIcon(); + case 14 -> TexturesGtBlock.Casing_Material_Talonite.getIcon(); + case 15 -> TexturesGtBlock.Turbine_SC_Material_Casing.getIcon(); + default -> Textures.BlockIcons.RENDERING_ERROR.getIcon(); + }; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaSpecialMultiCasings2.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaSpecialMultiCasings2.java new file mode 100644 index 0000000000..9a2912c2c5 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaSpecialMultiCasings2.java @@ -0,0 +1,99 @@ +package gtPlusPlus.xmod.gregtech.common.blocks; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.Textures; +import gregtech.api.util.GT_LanguageManager; +import gregtech.common.blocks.GT_Material_Casings; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaSpecialMultiCasings2 extends GregtechMetaCasingBlocksAbstract { + + @Override + public void getSubBlocks(Item aItem, CreativeTabs par2CreativeTabs, List aList) { + for (int i = 0; i < 8; i++) { + aList.add(new ItemStack(aItem, 1, i)); + } + } + + public static class SpecialCasingItemBlock extends GregtechMetaCasingItems { + + public SpecialCasingItemBlock(Block par1) { + super(par1); + } + + @Override + public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List aList, boolean aF3_H) { + int aMeta = aStack.getItemDamage(); + if (aMeta < 4) { + aList.add("Provides quantum stability"); + } + if (aMeta >= 4 && aMeta < 8) { + aList.add("Provides quantum modulation"); + } + super.addInformation(aStack, aPlayer, aList, aF3_H); + } + } + + public GregtechMetaSpecialMultiCasings2() { + super(SpecialCasingItemBlock.class, "gtplusplus.blockspecialcasings.3", GT_Material_Casings.INSTANCE); + for (byte i = 0; i < 16; i = (byte) (i + 1)) { + // TAE.registerTextures(new GT_CopiedBlockTexture(this, 6, i)); + // Don't register these Textures, They already exist within vanilla GT. (May not exist in 5.08) + } + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".0.name", "Resonance Chamber I"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".1.name", "Resonance Chamber II"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".2.name", "Resonance Chamber III"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".3.name", "Resonance Chamber IV"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".4.name", "Modulator I"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".5.name", "Modulator II"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".6.name", "Modulator III"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".7.name", "Modulator IV"); + + GregtechItemList.ResonanceChamber_I.set(new ItemStack(this, 1, 0)); + GregtechItemList.ResonanceChamber_II.set(new ItemStack(this, 1, 1)); + GregtechItemList.ResonanceChamber_III.set(new ItemStack(this, 1, 2)); + GregtechItemList.ResonanceChamber_IV.set(new ItemStack(this, 1, 3)); + GregtechItemList.Modulator_I.set(new ItemStack(this, 1, 4)); + GregtechItemList.Modulator_II.set(new ItemStack(this, 1, 5)); + GregtechItemList.Modulator_III.set(new ItemStack(this, 1, 6)); + GregtechItemList.Modulator_IV.set(new ItemStack(this, 1, 7)); + } + + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(final IBlockAccess aWorld, final int xCoord, final int yCoord, final int zCoord, + final int ordinalSide) { + return getStaticIcon((byte) ordinalSide, (byte) aWorld.getBlockMetadata(xCoord, yCoord, zCoord)); + } + + @Override + public IIcon getIcon(final int ordinalSide, final int aMeta) { + return getStaticIcon((byte) ordinalSide, (byte) aMeta); + } + + public static IIcon getStaticIcon(final byte aSide, final byte aMeta) { + return switch (aMeta) { + case 0 -> TexturesGtBlock.Casing_Resonance_1.getIcon(); + case 1 -> TexturesGtBlock.Casing_Resonance_2.getIcon(); + case 2 -> TexturesGtBlock.Casing_Resonance_3.getIcon(); + case 3 -> TexturesGtBlock.Casing_Resonance_4.getIcon(); + case 4 -> TexturesGtBlock.Casing_Modulator_1.getIcon(); + case 5 -> TexturesGtBlock.Casing_Modulator_2.getIcon(); + case 6 -> TexturesGtBlock.Casing_Modulator_3.getIcon(); + case 7 -> TexturesGtBlock.Casing_Modulator_4.getIcon(); + default -> Textures.BlockIcons.RENDERING_ERROR.getIcon(); + }; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaTieredCasingBlocks1.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaTieredCasingBlocks1.java new file mode 100644 index 0000000000..7ddab1c471 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/GregtechMetaTieredCasingBlocks1.java @@ -0,0 +1,84 @@ +package gtPlusPlus.xmod.gregtech.common.blocks; + +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; + +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Textures; +import gregtech.api.util.GT_LanguageManager; +import gregtech.common.blocks.GT_Material_Casings; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTieredCasingBlocks1 extends GregtechMetaCasingBlocksAbstract { + + @Override + public void getSubBlocks(Item aItem, CreativeTabs par2CreativeTabs, List aList) { + for (int i = 0; i < 10; i++) { + aList.add(new ItemStack(aItem, 1, i)); + } + } + + public static class TieredCasingItemBlock extends GregtechMetaCasingItems { + + public TieredCasingItemBlock(Block par1) { + super(par1); + } + + @Override + public void addInformation(ItemStack aStack, EntityPlayer aPlayer, List aList, boolean aF3_H) { + int aMeta = aStack.getItemDamage(); + if (aMeta < 10) { + aList.add("Tier: " + GT_Values.VN[aMeta]); + } + super.addInformation(aStack, aPlayer, aList, aF3_H); + } + } + + public GregtechMetaTieredCasingBlocks1() { + super(TieredCasingItemBlock.class, "gtplusplus.blocktieredcasings.1", GT_Material_Casings.INSTANCE); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".0.name", "Integral Encasement I"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".1.name", "Integral Encasement II"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".2.name", "Integral Encasement III"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".3.name", "Integral Encasement IV"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".4.name", "Integral Encasement V"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".5.name", "Integral Framework I"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".6.name", "Integral Framework II"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".7.name", "Integral Framework III"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".8.name", "Integral Framework IV"); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName() + ".9.name", "Integral Framework V"); + + GregtechItemList.GTPP_Casing_ULV.set(new ItemStack(this, 1, 0)); + GregtechItemList.GTPP_Casing_LV.set(new ItemStack(this, 1, 1)); + GregtechItemList.GTPP_Casing_MV.set(new ItemStack(this, 1, 2)); + GregtechItemList.GTPP_Casing_HV.set(new ItemStack(this, 1, 3)); + GregtechItemList.GTPP_Casing_EV.set(new ItemStack(this, 1, 4)); + GregtechItemList.GTPP_Casing_IV.set(new ItemStack(this, 1, 5)); + GregtechItemList.GTPP_Casing_LuV.set(new ItemStack(this, 1, 6)); + GregtechItemList.GTPP_Casing_ZPM.set(new ItemStack(this, 1, 7)); + GregtechItemList.GTPP_Casing_UV.set(new ItemStack(this, 1, 8)); + GregtechItemList.GTPP_Casing_UHV.set(new ItemStack(this, 1, 9)); + } + + @Override + public IIcon getIcon(int ordinalSide, int aMeta) { + if (aMeta < 10) { + return TexturesGtBlock.TIERED_MACHINE_HULLS[aMeta].getIcon(); + } + return switch (aMeta) { + case 10 -> Textures.BlockIcons.RENDERING_ERROR.getIcon(); + case 11 -> Textures.BlockIcons.RENDERING_ERROR.getIcon(); + case 12 -> Textures.BlockIcons.RENDERING_ERROR.getIcon(); + case 13 -> Textures.BlockIcons.RENDERING_ERROR.getIcon(); + case 14 -> Textures.BlockIcons.RENDERING_ERROR.getIcon(); + case 15 -> Textures.BlockIcons.RENDERING_ERROR.getIcon(); + default -> Textures.BlockIcons.RENDERING_ERROR.getIcon(); + }; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/fluid/GregtechFluidHandler.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/fluid/GregtechFluidHandler.java new file mode 100644 index 0000000000..e478bf5c18 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/fluid/GregtechFluidHandler.java @@ -0,0 +1,146 @@ +package gtPlusPlus.xmod.gregtech.common.blocks.fluid; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidRegistry; + +import gregtech.api.enums.OrePrefixes; +import gregtech.api.util.GT_OreDictUnificator; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials; + +public class GregtechFluidHandler { + + protected static int cellID = 0; + + public static void run() { + start(); + } + + private static void start() { + Logger.INFO("Adding in our own GT versions of Thermal Foundation Fluids if they do not already exist."); + if (!FluidRegistry.isFluidRegistered("cryotheum")) { + FluidUtils.addGtFluid( + "cryotheum", + "Gelid Cryotheum", + GT_Materials.Cryotheum, + 4, + -1200, + GT_OreDictUnificator.get(OrePrefixes.cell, GT_Materials.Cryotheum, 1L), + ItemUtils.getEmptyCell(), + 1000); + } + if (!FluidRegistry.isFluidRegistered("pyrotheum")) { + FluidUtils.addGtFluid( + "pyrotheum", + "Blazing Pyrotheum", + GT_Materials.Pyrotheum, + 4, + 4000, + GT_OreDictUnificator.get(OrePrefixes.cell, GT_Materials.Pyrotheum, 1L), + ItemUtils.getEmptyCell(), + 1000); + } + if (!FluidRegistry.isFluidRegistered("ender")) { + FluidUtils.addGtFluid( + "ender", + "Resonant Ender", + GT_Materials.Ender, + 4, + 4000, + GT_OreDictUnificator.get(OrePrefixes.cell, GT_Materials.Ender, 1L), + ItemUtils.getEmptyCell(), + 1000); + } + Logger.INFO("Adding in GT Fluids for various nuclear related content."); + + FluidUtils.addGtFluid( + "hydrofluoricAcid", + "Industrial Strength Hydrofluoric Acid", + GT_Materials.HydrofluoricAcid, + 1, + 120, + GT_OreDictUnificator.get(OrePrefixes.cell, GT_Materials.HydrofluoricAcid, 1L), + ItemUtils.getEmptyCell(), + 1000, + false); + generateIC2FluidCell("HydrofluoricAcid"); + + FluidUtils.generateFluidNoPrefix( + "SulfurDioxide", + "High Quality Sulfur Dioxide", + 263, + GT_Materials.SulfurDioxide.mRGBa); + + FluidUtils.addGtFluid( + "sulfurousAcid", + "Sulfurous Acid", + GT_Materials.SulfurousAcid, + 4, + 75, + GT_OreDictUnificator.get(OrePrefixes.cell, GT_Materials.SulfurousAcid, 1L), + ItemUtils.getEmptyCell(), + 1000, + false); + generateIC2FluidCell("SulfurousAcid"); + + FluidUtils.addGtFluid( + "sulfuricApatite", + "Sulfuric Apatite Mix", + GT_Materials.SulfuricApatite, + 4, + 500, + GT_OreDictUnificator.get(OrePrefixes.cell, GT_Materials.SulfuricApatite, 1L), + ItemUtils.getEmptyCell(), + 1000, + false); + generateIC2FluidCell("SulfuricApatite"); + + // Check for Hydrogen Chloride + if (FluidUtils.getFluidStack("hydrogenchloride", 1) == null) { + FluidUtils.addGtFluid( + "hydrogenChloride", + "Industrial Strength Hydrogen Chloride", + GT_Materials.HydrogenChloride, + 4, + 75, + GT_OreDictUnificator.get(OrePrefixes.cell, GT_Materials.HydrogenChloride, 1L), + ItemUtils.getEmptyCell(), + 1000, + false); + generateIC2FluidCell("HydrogenChloride"); + } + + FluidUtils.addGtFluid( + "sulfuricLithium", + "Sulfuric Lithium Mix", + GT_Materials.SulfuricLithium, + 4, + 280, + GT_OreDictUnificator.get(OrePrefixes.cell, GT_Materials.SulfuricLithium, 1L), + ItemUtils.getEmptyCell(), + 1000, + false); + generateIC2FluidCell("SulfuricLithium"); + + FluidUtils.addGtFluid( + "lithiumHydroxide", + "Lithium Hydroxide", + GT_Materials.LithiumHydroxide, + 4, + 500, + GT_OreDictUnificator.get(OrePrefixes.cell, GT_Materials.LithiumHydroxide, 1L), + ItemUtils.getEmptyCell(), + 1000, + false); + generateIC2FluidCell("LithiumHydroxide"); + } + + private static ItemStack generateIC2FluidCell(final String fluidNameWithCaps) { + Logger.INFO("Adding a Cell for " + fluidNameWithCaps); + return Utils.createInternalNameAndFluidCell(fluidNameWithCaps); + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/CasingTextureHandler.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/CasingTextureHandler.java new file mode 100644 index 0000000000..c85bac7115 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/CasingTextureHandler.java @@ -0,0 +1,57 @@ +package gtPlusPlus.xmod.gregtech.common.blocks.textures; + +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.enums.Textures; +import gtPlusPlus.xmod.gregtech.common.blocks.GregtechMetaCasingBlocks; + +public class CasingTextureHandler { + + private static final TexturesCentrifugeMultiblock gregtechX = new TexturesCentrifugeMultiblock(); + + public static IIcon getIcon(final int ordinalSide, final int aMeta) { // Texture ID's. case 0 == ID[57] + if ((aMeta >= 0) && (aMeta < 16)) { + return switch (aMeta) { + // Centrifuge + case 0 -> TexturesGtBlock.Casing_Material_Centrifuge.getIcon(); + // Coke Oven Frame + case 1 -> TexturesGtBlock.Casing_Material_Tantalloy61.getIcon(); + // Coke Oven Casing Tier 1 + case 2 -> Textures.BlockIcons.MACHINE_CASING_FIREBOX_BRONZE.getIcon(); + // Coke Oven Casing Tier 2 + case 3 -> Textures.BlockIcons.MACHINE_CASING_FIREBOX_STEEL.getIcon(); + // Material Press Casings + case 4 -> Textures.BlockIcons.MACHINE_CASING_STABLE_TITANIUM.getIcon(); + // Electrolyzer Casings + case 5 -> TexturesGtBlock.Casing_Material_Potin.getIcon(); + // Broken Blue Fusion Casings + case 6 -> TexturesGtBlock.Casing_Material_MaragingSteel.getIcon(); + // Maceration Stack Casings + case 7 -> TexturesGtBlock.Casing_Material_Tumbaga.getIcon(); + // Broken Pink Fusion Casings + case 8 -> TexturesGtBlock.TEXTURE_ORGANIC_PANEL_A_GLOWING.getIcon(); + // Matter Fabricator Casings + case 9 -> TexturesGtBlock.TEXTURE_METAL_PANEL_F.getIcon(); + // Iron Blast Fuance Textures + case 10 -> TexturesGtBlock.Casing_Machine_Simple_Top.getIcon(); + // Multitank Exterior Casing + case 11 -> TexturesGtBlock.Casing_Material_Grisium.getIcon(); + // Reactor Casing I + case 12 -> TexturesGtBlock.Casing_Material_Stellite.getIcon(); + // Reactor Casing II + case 13 -> TexturesGtBlock.Casing_Material_Zeron100.getIcon(); + case 14 -> TexturesGtBlock.Casing_Staballoy_Firebox.getIcon(); + case 15 -> TexturesGtBlock.Casing_Material_ZirconiumCarbide.getIcon(); + default -> Textures.BlockIcons.MACHINE_CASING_RADIOACTIVEHAZARD.getIcon(); + }; + } + return Textures.BlockIcons.MACHINE_CASING_GEARBOX_TUNGSTENSTEEL.getIcon(); + } + + public static IIcon handleCasingsGT(final IBlockAccess aWorld, final int xCoord, final int yCoord, final int zCoord, + final ForgeDirection side, final GregtechMetaCasingBlocks thisBlock) { + return gregtechX.handleCasingsGT(aWorld, xCoord, yCoord, zCoord, side, thisBlock); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/CasingTextureHandler2.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/CasingTextureHandler2.java new file mode 100644 index 0000000000..1da572fb35 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/CasingTextureHandler2.java @@ -0,0 +1,71 @@ +package gtPlusPlus.xmod.gregtech.common.blocks.textures; + +import net.minecraft.util.IIcon; + +import gregtech.api.enums.Textures; + +public class CasingTextureHandler2 { + + public static IIcon getIcon(final int ordinalSide, final int aMeta) { // Texture ID's. case 0 == ID[57] + if ((aMeta >= 0) && (aMeta < 16)) { + switch (aMeta) { + case 0 -> { + return TexturesGtBlock.Casing_Material_RedSteel.getIcon(); + } + case 1 -> { + return TexturesGtBlock.Casing_Material_HastelloyX.getIcon(); + } + case 2 -> { + return TexturesGtBlock.Casing_Material_HastelloyN.getIcon(); + } + case 3 -> { + return TexturesGtBlock.Casing_Material_Fluid_IncoloyDS.getIcon(); + } + case 4 -> { + return TexturesGtBlock.Casing_Material_Grisium.getIcon(); + } + case 5 -> { + return TexturesGtBlock.Casing_Machine_Metal_Panel_A.getIcon(); + } + case 6 -> { + return TexturesGtBlock.Casing_Machine_Metal_Grate_A.getIcon(); + } + case 7 -> { + return TexturesGtBlock.Casing_Redox_1.getIcon(); + } + case 8 -> { + return TexturesGtBlock.Casing_Machine_Metal_Sheet_A.getIcon(); + } + case 9 -> { + return TexturesGtBlock.Overlay_Machine_Cyber_A.getIcon(); + } + case 10 -> { + return Textures.BlockIcons.MACHINE_CASING_RADIATIONPROOF.getIcon(); + } + case 11 -> { + return TexturesGtBlock.Casing_Material_Tantalloy61.getIcon(); + } + case 12 -> { + return TexturesGtBlock.Casing_Machine_Simple_Top.getIcon(); + } + case 13 -> { + if (ordinalSide < 2) { + return TexturesGtBlock.TEXTURE_TECH_A.getIcon(); + } else { + return TexturesGtBlock.TEXTURE_TECH_B.getIcon(); + } + } + case 14 -> { + return Textures.BlockIcons.RENDERING_ERROR.getIcon(); + } + case 15 -> { + return TexturesGtBlock.Casing_Machine_Acacia_Log.getIcon(); + } + default -> { + return TexturesGtBlock.Overlay_UU_Matter.getIcon(); + } + } + } + return TexturesGtBlock._PlaceHolder.getIcon(); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/CasingTextureHandler3.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/CasingTextureHandler3.java new file mode 100644 index 0000000000..6b2627ec39 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/CasingTextureHandler3.java @@ -0,0 +1,61 @@ +package gtPlusPlus.xmod.gregtech.common.blocks.textures; + +import net.minecraft.util.IIcon; + +import gtPlusPlus.xmod.gregtech.common.blocks.GregtechMetaCasingBlocks3; + +public class CasingTextureHandler3 { + + public static IIcon getIcon(final int ordinalSide, final int aMeta) { // Texture ID's. case 0 == ID[57] + if ((aMeta >= 0) && (aMeta < 16)) { + return switch (aMeta) { + case 0 -> + // Aquatic Casing + TexturesGtBlock.TEXTURE_METAL_PANEL_B.getIcon(); + case 1 -> + // Inconel Reinforced Casing + TexturesGtBlock.TEXTURE_METAL_PANEL_D.getIcon(); + case 2 -> + // Multi-Use Casing + TexturesGtBlock.TEXTURE_METAL_PANEL_C.getIcon(); + case 3 -> + // Trinium Plated Mining Platform Casing + TexturesGtBlock.Casing_Trinium_Naquadah_Vent.getIcon(); + case 4 -> + // Vanadium Redox IV + TexturesGtBlock.Casing_Redox_2.getIcon(); + case 5 -> + // Vanadium Redox LuV + TexturesGtBlock.Casing_Redox_3.getIcon(); + case 6 -> + // Vanadium Redox ZPM + TexturesGtBlock.Casing_Redox_4.getIcon(); + case 7 -> + // Vanadium Redox UV + TexturesGtBlock.Casing_Redox_5.getIcon(); + case 8 -> + // Vanadium Redox MAX + TexturesGtBlock.Casing_Redox_6.getIcon(); + case 9 -> + // Amazon Warehouse Casing + TexturesGtBlock.TEXTURE_CASING_AMAZON.getIcon(); + case 10 -> + // Adv. Vac. Freezer + TexturesGtBlock.TEXTURE_CASING_ADVANCED_CRYOGENIC.getIcon(); + case 11 -> + // Adv. EBF + TexturesGtBlock.TEXTURE_CASING_ADVANCED_VOLCNUS.getIcon(); + case 12 -> TexturesGtBlock.TEXTURE_CASING_FUSION_COIL_II.getIcon(); + case 13 -> TexturesGtBlock.TEXTURE_CASING_FUSION_COIL_II_INNER.getIcon(); + case 14 -> TexturesGtBlock.TEXTURE_CASING_FUSION_CASING_ULTRA.getIcon(); + case 15 -> TexturesGtBlock.TEXTURE_MAGIC_PANEL_A.getIcon(); + default -> TexturesGtBlock._PlaceHolder.getIcon(); + }; + } + return TexturesGtBlock._PlaceHolder.getIcon(); + } + + static { + GregtechMetaCasingBlocks3.mConnectedMachineTextures = true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/CasingTextureHandler6.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/CasingTextureHandler6.java new file mode 100644 index 0000000000..b8d5a024df --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/CasingTextureHandler6.java @@ -0,0 +1,25 @@ +package gtPlusPlus.xmod.gregtech.common.blocks.textures; + +import net.minecraft.util.IIcon; + +import gtPlusPlus.xmod.gregtech.common.blocks.GregtechMetaCasingBlocks6; + +public class CasingTextureHandler6 { + + public static IIcon getIcon(final int ordinalSide, final int aMeta) { // Texture ID's. case 0 == ID[57] + if ((aMeta >= 0) && (aMeta < 16)) { + return switch (aMeta) { + case 0 -> TexturesGtBlock.TEXTURE_CASING_FUSION_COIL_III.getIcon(); + case 1 -> TexturesGtBlock.TEXTURE_CASING_FUSION_COIL_III_INNER.getIcon(); + case 2 -> TexturesGtBlock.TEXTURE_CASING_FUSION_CASING_HYPER.getIcon(); + default -> TexturesGtBlock._PlaceHolder.getIcon(); + }; + } + return TexturesGtBlock._PlaceHolder.getIcon(); + } + + static { + GregtechMetaCasingBlocks6.mConnectedMachineTextures = true; + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/TexturesCentrifugeMultiblock.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/TexturesCentrifugeMultiblock.java new file mode 100644 index 0000000000..058d2a7f1e --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/TexturesCentrifugeMultiblock.java @@ -0,0 +1,151 @@ +package gtPlusPlus.xmod.gregtech.common.blocks.textures; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gtPlusPlus.xmod.gregtech.common.blocks.GregtechMetaCasingBlocks; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.CustomIcon; +import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.GregtechMetaTileEntity_IndustrialCentrifuge; + +public class TexturesCentrifugeMultiblock { + + private static CustomIcon GT8_1_Active = new CustomIcon("iconsets/LARGECENTRIFUGE_ACTIVE1"); + private static CustomIcon GT8_1 = new CustomIcon("iconsets/LARGECENTRIFUGE1"); + private static CustomIcon GT8_2_Active = new CustomIcon("iconsets/LARGECENTRIFUGE_ACTIVE2"); + private static CustomIcon GT8_2 = new CustomIcon("iconsets/LARGECENTRIFUGE2"); + private static CustomIcon GT8_3_Active = new CustomIcon("iconsets/LARGECENTRIFUGE_ACTIVE3"); + private static CustomIcon GT8_3 = new CustomIcon("iconsets/LARGECENTRIFUGE3"); + private static CustomIcon GT8_4_Active = new CustomIcon("iconsets/LARGECENTRIFUGE_ACTIVE4"); + private static CustomIcon GT8_4 = new CustomIcon("iconsets/LARGECENTRIFUGE4"); + private static CustomIcon GT8_5_Active = new CustomIcon("iconsets/LARGECENTRIFUGE_ACTIVE5"); + private static CustomIcon GT8_5 = new CustomIcon("iconsets/LARGECENTRIFUGE5"); + private static CustomIcon GT8_6_Active = new CustomIcon("iconsets/LARGECENTRIFUGE_ACTIVE6"); + private static CustomIcon GT8_6 = new CustomIcon("iconsets/LARGECENTRIFUGE6"); + private static CustomIcon GT8_7_Active = new CustomIcon("iconsets/LARGECENTRIFUGE_ACTIVE7"); + private static CustomIcon GT8_7 = new CustomIcon("iconsets/LARGECENTRIFUGE7"); + private static CustomIcon GT8_8_Active = new CustomIcon("iconsets/LARGECENTRIFUGE_ACTIVE8"); + private static CustomIcon GT8_8 = new CustomIcon("iconsets/LARGECENTRIFUGE8"); + private static CustomIcon GT8_9_Active = new CustomIcon("iconsets/LARGECENTRIFUGE_ACTIVE9"); + private static CustomIcon GT8_9 = new CustomIcon("iconsets/LARGECENTRIFUGE9"); + + private static CustomIcon frontFace_0 = (GT8_1); + private static CustomIcon frontFaceActive_0 = (GT8_1_Active); + private static CustomIcon frontFace_1 = (GT8_2); + private static CustomIcon frontFaceActive_1 = (GT8_2_Active); + private static CustomIcon frontFace_2 = (GT8_3); + private static CustomIcon frontFaceActive_2 = (GT8_3_Active); + private static CustomIcon frontFace_3 = (GT8_4); + private static CustomIcon frontFaceActive_3 = (GT8_4_Active); + private static CustomIcon frontFace_4 = (GT8_5); + private static CustomIcon frontFaceActive_4 = (GT8_5_Active); + private static CustomIcon frontFace_5 = (GT8_6); + private static CustomIcon frontFaceActive_5 = (GT8_6_Active); + private static CustomIcon frontFace_6 = (GT8_7); + private static CustomIcon frontFaceActive_6 = (GT8_7_Active); + private static CustomIcon frontFace_7 = (GT8_8); + private static CustomIcon frontFaceActive_7 = (GT8_8_Active); + private static CustomIcon frontFace_8 = (GT8_9); + private static CustomIcon frontFaceActive_8 = (GT8_9_Active); + + CustomIcon[] CENTRIFUGE = new CustomIcon[] { frontFace_0, frontFace_1, frontFace_2, frontFace_3, frontFace_4, + frontFace_5, frontFace_6, frontFace_7, frontFace_8 }; + + CustomIcon[] CENTRIFUGE_ACTIVE = new CustomIcon[] { frontFaceActive_0, frontFaceActive_1, frontFaceActive_2, + frontFaceActive_3, frontFaceActive_4, frontFaceActive_5, frontFaceActive_6, frontFaceActive_7, + frontFaceActive_8 }; + + public IIcon handleCasingsGT(final IBlockAccess aWorld, final int xCoord, final int yCoord, final int zCoord, + final ForgeDirection side, final GregtechMetaCasingBlocks thisBlock) { + return this.handleCasingsGT58(aWorld, xCoord, yCoord, zCoord, side, thisBlock); + } + + private static int isCentrifugeControllerWithSide(IBlockAccess aWorld, int aX, int aY, int aZ, + ForgeDirection side) { + TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); + if (!(tTileEntity instanceof IGregTechTileEntity tTile)) return 0; + if (tTile.getMetaTileEntity() instanceof GregtechMetaTileEntity_IndustrialCentrifuge + && tTile.getFrontFacing() == side) return tTile.isActive() ? 1 : 2; + return 0; + } + + public IIcon handleCasingsGT58(final IBlockAccess aWorld, final int xCoord, final int yCoord, final int zCoord, + final ForgeDirection side, final GregtechMetaCasingBlocks thisBlock) { + final int tMeta = aWorld.getBlockMetadata(xCoord, yCoord, zCoord); + final int ordinalSide = side.ordinal(); + if (tMeta != 0) { + return CasingTextureHandler.getIcon(ordinalSide, tMeta); + } + + int tInvertLeftRightMod = ordinalSide % 2 * 2 - 1; + switch (ordinalSide / 2) { + case 0 -> { + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + if (i == 0 && j == 0) continue; + if (isCentrifugeControllerWithSide(aWorld, xCoord + j, yCoord, zCoord + i, side) != 0) { + IMetaTileEntity tMetaTileEntity = ((IGregTechTileEntity) aWorld + .getTileEntity(xCoord + j, yCoord, zCoord + i)).getMetaTileEntity(); + return getIconByIndex(tMetaTileEntity, 4 - i * 3 - j); + } + } + } + } + case 1 -> { + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + if (i == 0 && j == 0) continue; + if (isCentrifugeControllerWithSide(aWorld, xCoord + j, yCoord + i, zCoord, side) != 0) { + IMetaTileEntity tMetaTileEntity = ((IGregTechTileEntity) aWorld + .getTileEntity(xCoord + j, yCoord + i, zCoord)).getMetaTileEntity(); + return getIconByIndex(tMetaTileEntity, 4 + i * 3 - j * tInvertLeftRightMod); + } + } + } + } + case 2 -> { + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + if (i == 0 && j == 0) continue; + if (isCentrifugeControllerWithSide(aWorld, xCoord, yCoord + i, zCoord + j, side) != 0) { + IMetaTileEntity tMetaTileEntity = ((IGregTechTileEntity) aWorld + .getTileEntity(xCoord, yCoord + i, zCoord + j)).getMetaTileEntity(); + return getIconByIndex(tMetaTileEntity, 4 + i * 3 + j * tInvertLeftRightMod); + } + } + } + } + } + return TexturesGtBlock.Casing_Material_Centrifuge.getIcon(); + } + + public boolean isCentrifugeRunning(IMetaTileEntity aTile) { + if (aTile == null) { + return false; + } else { + return aTile.getBaseMetaTileEntity() + .isActive(); + } + } + + public boolean isUsingAnimatedTexture(IMetaTileEntity aMetaTileEntity) { + if (aMetaTileEntity != null) { + if (aMetaTileEntity instanceof GregtechMetaTileEntity_IndustrialCentrifuge) { + return ((GregtechMetaTileEntity_IndustrialCentrifuge) aMetaTileEntity).usingAnimations(); + } + } + return false; + } + + public IIcon getIconByIndex(IMetaTileEntity aMetaTileEntity, int aIndex) { + if (isUsingAnimatedTexture(aMetaTileEntity)) { + if (isCentrifugeRunning(aMetaTileEntity)) { + return this.CENTRIFUGE_ACTIVE[aIndex].getIcon(); + } + } + return this.CENTRIFUGE[aIndex].getIcon(); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/TexturesGrinderMultiblock.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/TexturesGrinderMultiblock.java new file mode 100644 index 0000000000..e7d09bd308 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/TexturesGrinderMultiblock.java @@ -0,0 +1,134 @@ +package gtPlusPlus.xmod.gregtech.common.blocks.textures; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gtPlusPlus.xmod.gregtech.common.blocks.GregtechMetaCasingBlocks5; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.CustomIcon; +import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.GregtechMetaTileEntity_IsaMill; + +public class TexturesGrinderMultiblock { + + private static CustomIcon GT8_1_Active = new CustomIcon("iconsets/Grinder/GRINDER_ACTIVE1"); + private static CustomIcon GT8_1 = new CustomIcon("iconsets/Grinder/GRINDER1"); + private static CustomIcon GT8_2_Active = new CustomIcon("iconsets/Grinder/GRINDER_ACTIVE2"); + private static CustomIcon GT8_2 = new CustomIcon("iconsets/Grinder/GRINDER2"); + private static CustomIcon GT8_3_Active = new CustomIcon("iconsets/Grinder/GRINDER_ACTIVE3"); + private static CustomIcon GT8_3 = new CustomIcon("iconsets/Grinder/GRINDER3"); + private static CustomIcon GT8_4_Active = new CustomIcon("iconsets/Grinder/GRINDER_ACTIVE4"); + private static CustomIcon GT8_4 = new CustomIcon("iconsets/Grinder/GRINDER4"); + private static CustomIcon GT8_5_Active = new CustomIcon("iconsets/Grinder/GRINDER_ACTIVE5"); + private static CustomIcon GT8_5 = new CustomIcon("iconsets/Grinder/GRINDER5"); + private static CustomIcon GT8_6_Active = new CustomIcon("iconsets/Grinder/GRINDER_ACTIVE6"); + private static CustomIcon GT8_6 = new CustomIcon("iconsets/Grinder/GRINDER6"); + private static CustomIcon GT8_7_Active = new CustomIcon("iconsets/Grinder/GRINDER_ACTIVE7"); + private static CustomIcon GT8_7 = new CustomIcon("iconsets/Grinder/GRINDER7"); + private static CustomIcon GT8_8_Active = new CustomIcon("iconsets/Grinder/GRINDER_ACTIVE8"); + private static CustomIcon GT8_8 = new CustomIcon("iconsets/Grinder/GRINDER8"); + private static CustomIcon GT8_9_Active = new CustomIcon("iconsets/Grinder/GRINDER_ACTIVE9"); + private static CustomIcon GT8_9 = new CustomIcon("iconsets/Grinder/GRINDER9"); + + private static CustomIcon frontFace_0 = (GT8_1); + private static CustomIcon frontFaceActive_0 = (GT8_1_Active); + private static CustomIcon frontFace_1 = (GT8_2); + private static CustomIcon frontFaceActive_1 = (GT8_2_Active); + private static CustomIcon frontFace_2 = (GT8_3); + private static CustomIcon frontFaceActive_2 = (GT8_3_Active); + private static CustomIcon frontFace_3 = (GT8_4); + private static CustomIcon frontFaceActive_3 = (GT8_4_Active); + private static CustomIcon frontFace_4 = (GT8_5); + private static CustomIcon frontFaceActive_4 = (GT8_5_Active); + private static CustomIcon frontFace_5 = (GT8_6); + private static CustomIcon frontFaceActive_5 = (GT8_6_Active); + private static CustomIcon frontFace_6 = (GT8_7); + private static CustomIcon frontFaceActive_6 = (GT8_7_Active); + private static CustomIcon frontFace_7 = (GT8_8); + private static CustomIcon frontFaceActive_7 = (GT8_8_Active); + private static CustomIcon frontFace_8 = (GT8_9); + private static CustomIcon frontFaceActive_8 = (GT8_9_Active); + + CustomIcon[] GRINDER = new CustomIcon[] { frontFace_0, frontFace_1, frontFace_2, frontFace_3, frontFace_4, + frontFace_5, frontFace_6, frontFace_7, frontFace_8 }; + + CustomIcon[] GRINDER_ACTIVE = new CustomIcon[] { frontFaceActive_0, frontFaceActive_1, frontFaceActive_2, + frontFaceActive_3, frontFaceActive_4, frontFaceActive_5, frontFaceActive_6, frontFaceActive_7, + frontFaceActive_8 }; + + private static int isIsaControllerWithSide(IBlockAccess aWorld, int aX, int aY, int aZ, ForgeDirection side) { + TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); + if (!(tTileEntity instanceof IGregTechTileEntity tTile)) return 0; + if (tTile.getMetaTileEntity() instanceof GregtechMetaTileEntity_IsaMill && tTile.getFrontFacing() == side) + return tTile.isActive() ? 1 : 2; + return 0; + } + + public IIcon handleCasingsGT(final IBlockAccess aWorld, final int xCoord, final int yCoord, final int zCoord, + final int ordinalSide, final GregtechMetaCasingBlocks5 ii) { + final int tMeta = aWorld.getBlockMetadata(xCoord, yCoord, zCoord); + final ForgeDirection side = ForgeDirection.getOrientation(ordinalSide); + if (tMeta != 1) { + return GregtechMetaCasingBlocks5.getStaticIcon(ordinalSide, tMeta); + } + int tInvertLeftRightMod = ordinalSide % 2 * 2 - 1; + switch (ordinalSide / 2) { + case 0 -> { + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + if (i == 0 && j == 0) continue; + if (isIsaControllerWithSide(aWorld, xCoord + j, yCoord, zCoord + i, side) != 0) { + IMetaTileEntity tMetaTileEntity = ((IGregTechTileEntity) aWorld + .getTileEntity(xCoord + j, yCoord, zCoord + i)).getMetaTileEntity(); + return getIconByIndex(tMetaTileEntity, 4 - i * 3 - j); + } + } + } + } + case 1 -> { + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + if (i == 0 && j == 0) continue; + if (isIsaControllerWithSide(aWorld, xCoord + j, yCoord + i, zCoord, side) != 0) { + IMetaTileEntity tMetaTileEntity = ((IGregTechTileEntity) aWorld + .getTileEntity(xCoord + j, yCoord + i, zCoord)).getMetaTileEntity(); + return getIconByIndex(tMetaTileEntity, 4 + i * 3 - j * tInvertLeftRightMod); + } + } + } + } + case 2 -> { + for (int i = -1; i < 2; i++) { + for (int j = -1; j < 2; j++) { + if (i == 0 && j == 0) continue; + if (isIsaControllerWithSide(aWorld, xCoord, yCoord + i, zCoord + j, side) != 0) { + IMetaTileEntity tMetaTileEntity = ((IGregTechTileEntity) aWorld + .getTileEntity(xCoord, yCoord + i, zCoord + j)).getMetaTileEntity(); + return getIconByIndex(tMetaTileEntity, 4 + i * 3 + j * tInvertLeftRightMod); + } + } + } + } + } + return TexturesGtBlock.TEXTURE_CASING_GRINDING_MILL.getIcon(); + } + + public boolean isCentrifugeRunning(IMetaTileEntity aTile) { + if (aTile == null) { + return false; + } else { + return aTile.getBaseMetaTileEntity() + .isActive(); + } + } + + public IIcon getIconByIndex(IMetaTileEntity aMetaTileEntity, int aIndex) { + if (isCentrifugeRunning(aMetaTileEntity)) { + return this.GRINDER_ACTIVE[aIndex].getIcon(); + } + + return this.GRINDER[aIndex].getIcon(); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/TexturesGtBlock.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/TexturesGtBlock.java new file mode 100644 index 0000000000..743cd0b85b --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/TexturesGtBlock.java @@ -0,0 +1,486 @@ +package gtPlusPlus.xmod.gregtech.common.blocks.textures; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.util.IIcon; +import net.minecraft.util.ResourceLocation; + +import gregtech.api.GregTech_API; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.ITexture; +import gregtech.api.objects.GT_RenderedTexture; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.lib.CORE; + +public class TexturesGtBlock { + + private static boolean mAnimated = CORE.ConfigSwitches.enableAnimatedTextures; + + private static AutoMap<Runnable> mCustomiconMap = new AutoMap<>(); + + /* + * Handles Custom Textures. + */ + + public static class CustomIcon implements IIconContainer, Runnable { + + protected IIcon mIcon; + protected String mIconName; + protected String mModID; + + public CustomIcon(final String aIconName) { + this(GTPlusPlus.ID, aIconName); + } + + public CustomIcon(final String aModID, final String aIconName) { + this.mIconName = aIconName; + this.mModID = aModID; + mCustomiconMap.put(this); + Logger.WARNING("Constructing a Custom Texture. " + this.mIconName); + GregTech_API.sGTBlockIconload.add(this); + } + + @Override + public IIcon getIcon() { + return this.mIcon; + } + + @Override + public IIcon getOverlayIcon() { + return null; + } + + @Override + public void run() { + this.mIcon = GregTech_API.sBlockIcons.registerIcon(this.mModID + ":" + this.mIconName); + Logger.WARNING( + "FIND ME _ Processing texture: " + this.getTextureFile() + .getResourcePath()); + } + + @Override + public ResourceLocation getTextureFile() { + return TextureMap.locationBlocksTexture; + } + } + + /* + * Add Some Custom Textures below. I am not sure whether or not I need to declare them as such, but better to be + * safe than sorry. Right? + */ + + // PlaceHolder Texture + private static final CustomIcon Internal_PlaceHolder = new CustomIcon("TileEntities/_PlaceHolder"); + public static final CustomIcon _PlaceHolder = Internal_PlaceHolder; + + public static final CustomIcon OVERLAY_ENERGY_OUT_MULTI_BUFFER = new CustomIcon( + "iconsets/OVERLAY_ENERGY_OUT_MULTI_BUFFER"); + + // Machine Casings + // Simple + private static final CustomIcon Internal_Casing_Machine_Simple_Top = new CustomIcon("TileEntities/machine_top"); + public static final CustomIcon Casing_Machine_Simple_Top = Internal_Casing_Machine_Simple_Top; + private static final CustomIcon Internal_Casing_Machine_Simple_Bottom = new CustomIcon( + "TileEntities/machine_bottom"); + public static final CustomIcon Casing_Machine_Simple_Bottom = Internal_Casing_Machine_Simple_Bottom; + // Advanced and Ultra + private static final CustomIcon Internal_Casing_Machine_Advanced = new CustomIcon("TileEntities/high_adv_machine"); + public static final CustomIcon Casing_Machine_Advanced = Internal_Casing_Machine_Advanced; + private static final CustomIcon Internal_Casing_Machine_Ultra = new CustomIcon("TileEntities/adv_machine_lesu"); + public static final CustomIcon Casing_Machine_Ultra = Internal_Casing_Machine_Ultra; + // Dimensional - Non Overlay + private static final CustomIcon Internal_Casing_Machine_Dimensional = new CustomIcon( + "TileEntities/adv_machine_dimensional"); + public static final CustomIcon Casing_Machine_Dimensional = Internal_Casing_Machine_Dimensional; + + // Material Casings + private static final CustomIcon Internal_Casing_Tantalloy61 = new CustomIcon( + "TileEntities/MACHINE_CASING_STABLE_TANTALLOY61"); + public static final CustomIcon Casing_Material_Tantalloy61 = Internal_Casing_Tantalloy61; + private static final CustomIcon Internal_Casing_MaragingSteel = new CustomIcon( + "TileEntities/MACHINE_CASING_STABLE_MARAGINGSTEEL"); + public static final CustomIcon Casing_Material_MaragingSteel = Internal_Casing_MaragingSteel; + private static final CustomIcon Internal_Casing_Stellite = new CustomIcon( + "TileEntities/MACHINE_CASING_STABLE_STELLITE"); + public static final CustomIcon Casing_Material_Stellite = Internal_Casing_Stellite; + private static final CustomIcon Internal_Casing_Talonite = new CustomIcon( + "TileEntities/MACHINE_CASING_STABLE_TALONITE"); + public static final CustomIcon Casing_Material_Talonite = Internal_Casing_Talonite; + private static final CustomIcon Internal_Turbine_SC_Casing = new TexturesGtBlock.CustomIcon("iconsets/SC_TURBINE"); + public static final CustomIcon Turbine_SC_Material_Casing = Internal_Turbine_SC_Casing; + private static final CustomIcon Internal_Casing_Tumbaga = new CustomIcon( + "TileEntities/MACHINE_CASING_STABLE_TUMBAGA"); + public static final CustomIcon Casing_Material_Tumbaga = Internal_Casing_Tumbaga; + private static final CustomIcon Internal_Casing_Zeron100 = new CustomIcon( + "TileEntities/MACHINE_CASING_STABLE_ZERON100"); + public static final CustomIcon Casing_Material_Zeron100 = Internal_Casing_Zeron100; + private static final CustomIcon Internal_Casing_Potin = new CustomIcon("TileEntities/MACHINE_CASING_STABLE_POTIN"); + public static final CustomIcon Casing_Material_Potin = Internal_Casing_Potin; + + private static final CustomIcon Internal_Casing_Grisium = new CustomIcon( + "TileEntities/MACHINE_CASING_STABLE_GRISIUM"); + public static final CustomIcon Casing_Material_Grisium = Internal_Casing_Grisium; + private static final CustomIcon Internal_Casing_RedSteel = new CustomIcon( + "TileEntities/MACHINE_CASING_STABLE_RED_STEEL"); + public static final CustomIcon Casing_Material_RedSteel = Internal_Casing_RedSteel; + private static final CustomIcon Internal_Casing_ZirconiumCarbide = new CustomIcon( + "TileEntities/MACHINE_CASING_STABLE_ZIRCONIUM_CARBIDE"); + public static final CustomIcon Casing_Material_ZirconiumCarbide = Internal_Casing_ZirconiumCarbide; + + private static final CustomIcon Internal_Casing_HastelloyX = new CustomIcon( + "TileEntities/MACHINE_CASING_STABLE_HASTELLOY_X"); + public static final CustomIcon Casing_Material_HastelloyX = Internal_Casing_HastelloyX; + private static final CustomIcon Internal_Casing_HastelloyN = new CustomIcon( + "TileEntities/MACHINE_CASING_STABLE_HASTELLOY_N"); + public static final CustomIcon Casing_Material_HastelloyN = Internal_Casing_HastelloyN; + private static final CustomIcon Internal_Casing_Fluid_IncoloyDS = new CustomIcon( + "TileEntities/MACHINE_CASING_FLUID_INCOLOY_DS"); + public static final CustomIcon Casing_Material_Fluid_IncoloyDS = Internal_Casing_Fluid_IncoloyDS; + + private static final CustomIcon Internal_Casing_Laurenium = new CustomIcon("TileEntities/MACHINE_CASING_LAURENIUM"); + public static final CustomIcon Casing_Material_Laurenium = Internal_Casing_Laurenium; + + // Trinium Alloys + public static final CustomIcon Casing_Trinium_Titanium = new CustomIcon( + "TileEntities/MACHINE_CASING_STABLE_TRINIUM_TITANIUM"); + public static final CustomIcon Casing_Trinium_Naquadah_Vent = new CustomIcon( + "TileEntities/MACHINE_CASING_STABLE_TRINIUM_NAQUADAH_VENT"); + + // Material Machine/Firebox Casings + private static final CustomIcon Internal_Casing_Staballoy_Firebox = new CustomIcon( + "TileEntities/MACHINE_CASING_FIREBOX_STABALLOY"); + public static final CustomIcon Casing_Staballoy_Firebox = Internal_Casing_Staballoy_Firebox; + + // Misc Casings + private static final CustomIcon Internal_Casing_Machine_Redstone_Off = new CustomIcon( + "TileEntities/cover_redstone_conductor"); + public static final CustomIcon Casing_Machine_Redstone_Off = Internal_Casing_Machine_Redstone_Off; + private static final CustomIcon Internal_Casing_Machine_Redstone_On = new CustomIcon( + "TileEntities/cover_redstone_emitter"); + public static final CustomIcon Casing_Machine_Redstone_On = Internal_Casing_Machine_Redstone_On; + + // Redox Cells + public static final CustomIcon Casing_Redox_1 = new CustomIcon("redox/redox1"); + public static final CustomIcon Casing_Redox_2 = new CustomIcon("redox/redox2"); + public static final CustomIcon Casing_Redox_3 = new CustomIcon("redox/redox3"); + public static final CustomIcon Casing_Redox_4 = new CustomIcon("redox/redox4"); + public static final CustomIcon Casing_Redox_5 = new CustomIcon("redox/redox5"); + public static final CustomIcon Casing_Redox_6 = new CustomIcon("redox/redox6"); + + // Special Block 2 + public static final CustomIcon Casing_Resonance_1 = new CustomIcon("special/block_1"); + public static final CustomIcon Casing_Resonance_2 = new CustomIcon("special/block_2"); + public static final CustomIcon Casing_Resonance_3 = new CustomIcon("special/block_3"); + public static final CustomIcon Casing_Resonance_4 = new CustomIcon("special/block_4"); + public static final CustomIcon Casing_Modulator_1 = new CustomIcon("special/block_5"); + public static final CustomIcon Casing_Modulator_2 = new CustomIcon("special/block_6"); + public static final CustomIcon Casing_Modulator_3 = new CustomIcon("special/block_7"); + public static final CustomIcon Casing_Modulator_4 = new CustomIcon("special/block_8"); + + // Centrifuge Casing + private static final CustomIcon Internal_Casing_Centrifuge = new CustomIcon( + "TileEntities/MACHINE_CASING_CENTRIFUGE"); + public static final CustomIcon Casing_Material_Centrifuge = Internal_Casing_Centrifuge; + + // Quantum Force Transformer Casing + // spotless:off + private static final CustomIcon Internal_Casing_QFT = new CustomIcon("TileEntities/MACHINE_CASING_QFT_COIL"); + public static final CustomIcon Casing_Coil_QFT = Internal_Casing_QFT; + public static final CustomIcon NeutronPulseManipulator = mAnimated ? new CustomIcon("NeutronPulseManipulator") : new CustomIcon("NeutronPulseManipulatorStatic"); + public static final CustomIcon CosmicFabricManipulator = mAnimated ? new CustomIcon("CosmicFabricManipulator") : new CustomIcon("CosmicFabricManipulatorStatic"); + public static final CustomIcon InfinityInfusedManipulator = mAnimated ? new CustomIcon("InfinityInfusedManipulator") : new CustomIcon("InfinityInfusedManipulatorStatic"); + public static final CustomIcon SpaceTimeContinuumRipper = mAnimated ? new CustomIcon("SpaceTimeContinuumRipper") : new CustomIcon("SpaceTimeContinuumRipperStatic"); + public static final CustomIcon Manipulator_Top = new CustomIcon("Manipulator_Top"); + public static final CustomIcon NeutronShieldingCore = mAnimated ? new CustomIcon("NeutronShieldingCore") : new CustomIcon("NeutronShieldingCoreStatic"); + public static final CustomIcon CosmicFabricShieldingCore = mAnimated ? new CustomIcon("CosmicFabricShieldingCore") : new CustomIcon("CosmicFabricShieldingCoreStatic"); + public static final CustomIcon InfinityInfusedShieldingCore = mAnimated ? new CustomIcon("InfinityInfusedShieldingCore") : new CustomIcon("InfinityInfusedShieldingCoreStatic"); + public static final CustomIcon SpaceTimeBendingCore = mAnimated ? new CustomIcon("SpaceTimeBendingCore") : new CustomIcon("SpaceTimeBendingCoreStatic"); + public static final CustomIcon ForceFieldGlass = new CustomIcon("ForceFieldGlass"); + public static final CustomIcon ForceField = new CustomIcon("rendering/ForceField"); + public static final CustomIcon Blank = new CustomIcon("Blank"); + //spotless:on + + // MACHINE_CASING_FARM_MANAGER_STRUCTURAL + // Farm Manager Casings + private static final CustomIcon Internal_Casing_Machine_Farm_Manager = new CustomIcon( + "TileEntities/MACHINE_CASING_FARM_MANAGER_STRUCTURAL"); + public static final CustomIcon Casing_Machine_Farm_Manager = Internal_Casing_Machine_Farm_Manager; + // Acacia_Log + private static final CustomIcon Internal_Casing_Machine_Acacia_Log = new CustomIcon("TileEntities/log_acacia_top"); + public static final CustomIcon Casing_Machine_Acacia_Log = Internal_Casing_Machine_Acacia_Log; + // Podzol Top + private static final CustomIcon Internal_Casing_Machine_Podzol = new CustomIcon("TileEntities/dirt_podzol_top"); + public static final CustomIcon Casing_Machine_Podzol = Internal_Casing_Machine_Podzol; + + // Structural Blocks + private static final CustomIcon Internal_Casing_Machine_Metal_Grate_A = new CustomIcon("chrono/MetalGrate"); + public static final CustomIcon Casing_Machine_Metal_Grate_A = Internal_Casing_Machine_Metal_Grate_A; + + private static final CustomIcon Internal_Casing_Machine_Metal_Panel_A = new CustomIcon("chrono/MetalPanel"); + public static final CustomIcon Casing_Machine_Metal_Panel_A = Internal_Casing_Machine_Metal_Panel_A; + private static final CustomIcon Internal_Casing_Machine_Metal_Sheet_A = new CustomIcon("chrono/MetalSheet"); + public static final CustomIcon Casing_Machine_Metal_Sheet_A = Internal_Casing_Machine_Metal_Sheet_A; + private static final CustomIcon Internal_Casing_Machine_Metal_Sheet_H = new CustomIcon("chrono/MetalSheet8"); + public static final CustomIcon Casing_Machine_Metal_Sheet_H = Internal_Casing_Machine_Metal_Sheet_H; + private static final CustomIcon Internal_Casing_Machine_Metal_Sheet_I = new CustomIcon("chrono/MetalSheet9"); + public static final CustomIcon Casing_Machine_Metal_Sheet_I = Internal_Casing_Machine_Metal_Sheet_I; + private static final CustomIcon Internal_Overlay_Machine_Cyber_A = new CustomIcon("chrono/CyberPanel"); + public static final CustomIcon Overlay_Machine_Cyber_A = Internal_Overlay_Machine_Cyber_A; + + public static final CustomIcon TEXTURE_CASING_AMAZON = new CustomIcon("TileEntities/CASING_AMAZON"); + public static final CustomIcon TEXTURE_CASING_ADVANCED_CRYOGENIC = new CustomIcon( + "TileEntities/MACHINE_CASING_ADVANCED_CRYOGENIC"); + public static final CustomIcon TEXTURE_CASING_ADVANCED_VOLCNUS = new CustomIcon( + "TileEntities/MACHINE_CASING_ADVANCED_VOLCANUS"); + public static final CustomIcon TEXTURE_CASING_ROCKETDYNE = new CustomIcon("TileEntities/MACHINE_CASING_ROCKETDYNE"); + public static final CustomIcon TEXTURE_CASING_GRINDING_MILL = new CustomIcon( + "TileEntities/MACHINE_CASING_GRINDING_FACTORY"); + public static final CustomIcon TEXTURE_CASING_FLOTATION = new CustomIcon("TileEntities/MACHINE_CASING_FLOTATION"); + + // Custom Pipes + public static final CustomIcon TEXTURE_PIPE_GRINDING_MILL = new CustomIcon("TileEntities/MACHINE_CASING_PIPE_T1"); + public static final CustomIcon TEXTURE_PIPE_GENERIC = new CustomIcon("iconsets/MACHINE_CASING_PIPE_GENERIC"); + + // Custom Gearboxes + public static final CustomIcon TEXTURE_GEARBOX_GRINDING_MILL = new CustomIcon( + "TileEntities/MACHINE_CASING_GEARBOX_T1"); + public static final CustomIcon TEXTURE_GEARBOX_GENERIC = new CustomIcon("iconsets/MACHINE_CASING_GEARBOX_GENERIC"); + + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_II = new CustomIcon("iconsets/MACHINE_CASING_FUSION_3"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_II_INNER = new CustomIcon( + "iconsets/MACHINE_CASING_FUSION_COIL_II"); + public static final CustomIcon TEXTURE_CASING_FUSION_CASING_ULTRA = new CustomIcon( + "iconsets/MACHINE_CASING_FUSION_GLASS_ULTRA"); + + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_III = new CustomIcon("iconsets/MACHINE_CASING_FUSION_4"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_III_INNER = new CustomIcon( + "iconsets/MACHINE_CASING_FUSION_COIL_III"); + public static final CustomIcon TEXTURE_CASING_FUSION_CASING_HYPER = new CustomIcon( + "iconsets/MACHINE_CASING_FUSION_GLASS_HYPER"); + // + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_II_1 = new CustomIcon("iconsets/FUSIONIII_1"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_II_2 = new CustomIcon("iconsets/FUSIONIII_2"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_II_3 = new CustomIcon("iconsets/FUSIONIII_3"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_II_4 = new CustomIcon("iconsets/FUSIONIII_4"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_II_5 = new CustomIcon("iconsets/FUSIONIII_5"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_II_6 = new CustomIcon("iconsets/FUSIONIII_6"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_II_7 = new CustomIcon("iconsets/FUSIONIII_7"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_II_8 = new CustomIcon("iconsets/FUSIONIII_8"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_II_9 = new CustomIcon("iconsets/FUSIONIII_9"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_II_10 = new CustomIcon("iconsets/FUSIONIII_10"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_II_11 = new CustomIcon("iconsets/FUSIONIII_11"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_II_12 = new CustomIcon("iconsets/FUSIONIII_12"); + + // MK5 Fusion casings + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_III_1 = new CustomIcon("iconsets/FUSIONIV_1"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_III_2 = new CustomIcon("iconsets/FUSIONIV_2"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_III_3 = new CustomIcon("iconsets/FUSIONIV_3"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_III_4 = new CustomIcon("iconsets/FUSIONIV_4"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_III_5 = new CustomIcon("iconsets/FUSIONIV_5"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_III_6 = new CustomIcon("iconsets/FUSIONIV_6"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_III_7 = new CustomIcon("iconsets/FUSIONIV_7"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_III_8 = new CustomIcon("iconsets/FUSIONIV_8"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_III_9 = new CustomIcon("iconsets/FUSIONIV_9"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_III_10 = new CustomIcon("iconsets/FUSIONIV_10"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_III_11 = new CustomIcon("iconsets/FUSIONIV_11"); + public static final CustomIcon TEXTURE_CASING_FUSION_COIL_III_12 = new CustomIcon("iconsets/FUSIONIV_12"); + + // Overlays + // Fan Textures + private static final CustomIcon Internal_Overlay_Machine_Vent = new CustomIcon( + "TileEntities/machine_top_vent_rotating"); + public static final CustomIcon Overlay_Machine_Vent = Internal_Overlay_Machine_Vent; + private static final CustomIcon Internal_Overlay_Machine_Vent_Fast = new CustomIcon( + "TileEntities/machine_top_vent_rotating_fast"); + public static final CustomIcon Overlay_Machine_Vent_Fast = Internal_Overlay_Machine_Vent_Fast; + private static final CustomIcon Internal_Overlay_Machine_Vent_Adv = new CustomIcon( + "TileEntities/adv_machine_vent_rotating"); + // Diesel Engines + private static final CustomIcon Internal_Overlay_Machine_Diesel_Vertical = new CustomIcon( + "TileEntities/machine_top_dieselmotor"); + public static final CustomIcon Overlay_Machine_Diesel_Vertical = Internal_Overlay_Machine_Diesel_Vertical; + private static final CustomIcon Internal_Overlay_Machine_Diesel_Horizontal = new CustomIcon( + "TileEntities/machine_top_dieselmotor2"); + public static final CustomIcon Overlay_Machine_Diesel_Horizontal = Internal_Overlay_Machine_Diesel_Horizontal; + private static final CustomIcon Internal_Overlay_Machine_Diesel_Vertical_Active = new CustomIcon( + "TileEntities/machine_top_dieselmotor_active"); + public static final CustomIcon Overlay_Machine_Diesel_Vertical_Active = Internal_Overlay_Machine_Diesel_Vertical_Active; + private static final CustomIcon Internal_Overlay_Machine_Diesel_Horizontal_Active = new CustomIcon( + "TileEntities/machine_top_dieselmotor2_active"); + public static final CustomIcon Overlay_Machine_Diesel_Horizontal_Active = Internal_Overlay_Machine_Diesel_Horizontal_Active; + // Computer Screens + private static final CustomIcon Internal_Casing_Machine_Screen_1 = new CustomIcon( + "TileEntities/adv_machine_screen_random1"); + public static final CustomIcon Casing_Machine_Screen_1 = Internal_Casing_Machine_Screen_1; + private static final CustomIcon Internal_Casing_Machine_Screen_2 = new CustomIcon( + "TileEntities/adv_machine_screen_random2"); + public static final CustomIcon Casing_Machine_Screen_2 = Internal_Casing_Machine_Screen_2; + private static final CustomIcon Internal_Casing_Machine_Screen_3 = new CustomIcon( + "TileEntities/adv_machine_screen_random3"); + public static final CustomIcon Casing_Machine_Screen_3 = Internal_Casing_Machine_Screen_3; + + private static final CustomIcon Internal_Casing_Machine_Screen_Rainbow = new CustomIcon( + "TileEntities/overlay_rainbowscreen"); + public static final CustomIcon Casing_Machine_Screen_Rainbow = Internal_Casing_Machine_Screen_Rainbow; + private static final CustomIcon Internal_Casing_Machine_Screen_Frequency = new CustomIcon( + "TileEntities/adv_machine_screen_frequency"); + public static final CustomIcon Casing_Machine_Screen_Frequency = Internal_Casing_Machine_Screen_Frequency; + private static final CustomIcon Internal_Overlay_Machine_Screen_Logo = new CustomIcon( + "TileEntities/adv_machine_screen_logo"); + public static final CustomIcon Overlay_Machine_Screen_Logo = Internal_Overlay_Machine_Screen_Logo; + + // Machine Controller Overlays + private static final CustomIcon Internal_Overlay_Machine_Controller_Default = new CustomIcon( + "iconsets/OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_ANIMATED"); + public static final CustomIcon Overlay_Machine_Controller_Default = Internal_Overlay_Machine_Controller_Default; + private static final CustomIcon Internal_Overlay_Machine_Controller_Default_Active = new CustomIcon( + "iconsets/OVERLAY_FRONT_ELECTRIC_BLAST_FURNACE_ANIMATED_ACTIVE"); + public static final CustomIcon Overlay_Machine_Controller_Default_Active = Internal_Overlay_Machine_Controller_Default_Active; + + private static final CustomIcon Internal_Overlay_Machine_Controller_Advanced = new CustomIcon( + "iconsets/OVERLAY_FRONT_ADVANCED_MULTIBLOCK_ANIMATED"); + public static final CustomIcon Overlay_Machine_Controller_Advanced = Internal_Overlay_Machine_Controller_Advanced; + private static final CustomIcon Internal_Overlay_Machine_Controller_Advanced_Active = new CustomIcon( + "iconsets/OVERLAY_FRONT_ADVANCED_MULTIBLOCK_ANIMATED_ACTIVE"); + public static final CustomIcon Overlay_Machine_Controller_Advanced_Active = Internal_Overlay_Machine_Controller_Advanced_Active; + + // Crafting Overlays + public static final CustomIcon Casing_Adv_Workbench_Crafting_Overlay = new CustomIcon( + "TileEntities/gt4/machine_top_crafting"); + + public static final CustomIcon Casing_CropHarvester_Cutter = new CustomIcon("TileEntities/gt4/OVERLAY_CROP"); + public static final CustomIcon Casing_CropHarvester_Boxes = new CustomIcon("TileEntities/gt4/OVERLAY_BOXES"); + + // Covers + private static final CustomIcon Internal_Overlay_Overflow_Valve = new CustomIcon("iconsets/OVERLAY_OVERFLOW_VALVE"); + public static final CustomIcon Overlay_Overflow_Valve = Internal_Overlay_Overflow_Valve; + + // Hatch Overlays + // Charger Texture + private static final CustomIcon Internal_Overlay_Hatch_Charger = new CustomIcon("TileEntities/cover_charger"); + public static final CustomIcon Overlay_Hatch_Charger = Internal_Overlay_Hatch_Charger; + // Discharger Texture + private static final CustomIcon Internal_Overlay_Hatch_Discharger = new CustomIcon("TileEntities/cover_discharge"); + public static final CustomIcon Overlay_Hatch_Discharger = Internal_Overlay_Hatch_Discharger; + // Advanced Muffler + private static final CustomIcon Internal_Overlay_Hatch_Muffler_Adv = new CustomIcon("iconsets/OVERLAY_MUFFLER_ADV"); + public static final CustomIcon Overlay_Hatch_Muffler_Adv = Internal_Overlay_Hatch_Muffler_Adv; + // Milling Ball Bus + private static final CustomIcon Internal_Overlay_Bus_Milling_Balls = new CustomIcon( + "iconsets/OVERLAY_MILLING_BALL_BUS"); + public static final CustomIcon Overlay_Bus_Milling_Balls = Internal_Overlay_Bus_Milling_Balls; + // Catalyst Bus + private static final CustomIcon Internal_Overlay_Bus_Catalyst = new CustomIcon("iconsets/OVERLAY_CATALYSTS"); + public static final CustomIcon Overlay_Bus_Catalyst = Internal_Overlay_Bus_Catalyst; + + // Data Orb Hatch + public static final CustomIcon Overlay_Hatch_Data_Orb = new CustomIcon("iconsets/OVERLAY_DATA_ORB"); + + // Dimensional + private static final CustomIcon Internal_Overlay_Machine_Dimensional_Orange = new CustomIcon( + "TileEntities/adv_machine_dimensional_cover_orange"); + public static final CustomIcon Overlay_Machine_Dimensional_Orange = Internal_Overlay_Machine_Dimensional_Orange; + // Icons + private static final CustomIcon Internal_Overlay_MatterFab = new CustomIcon("TileEntities/adv_machine_matterfab"); + public static final CustomIcon Overlay_MatterFab = Internal_Overlay_MatterFab; + private static final CustomIcon Internal_Overlay_MatterFab_Active = new CustomIcon( + "TileEntities/adv_machine_matterfab_active"); + public static final CustomIcon Overlay_MatterFab_Active = Internal_Overlay_MatterFab_Active; + + private static final CustomIcon Internal_Overlay_MatterFab_Animated = new CustomIcon( + "TileEntities/adv_machine_matterfab_animated"); + public static final CustomIcon Overlay_MatterFab_Animated = Internal_Overlay_MatterFab_Animated; + private static final CustomIcon Internal_Overlay_MatterFab_Active_Animated = new CustomIcon( + "TileEntities/adv_machine_matterfab_active_animated"); + public static final CustomIcon Overlay_MatterFab_Active_Animated = Internal_Overlay_MatterFab_Active_Animated; + + private static final CustomIcon Internal_Overlay_Water = new CustomIcon("TileEntities/adv_machine_water"); + public static final CustomIcon Overlay_Water = Internal_Overlay_Water; + private static final CustomIcon Internal_Overlay_UU_Matter = new CustomIcon("TileEntities/adv_machine_uum"); + public static final CustomIcon Overlay_UU_Matter = Internal_Overlay_UU_Matter; + + // GT++ Tiered Hulls + public static final CustomIcon TEXTURE_CASING_TIERED_ULV = new CustomIcon("iconsets/TieredHulls/CASING_ULV"); + public static final CustomIcon TEXTURE_CASING_TIERED_LV = new CustomIcon("iconsets/TieredHulls/CASING_LV"); + public static final CustomIcon TEXTURE_CASING_TIERED_MV = new CustomIcon("iconsets/TieredHulls/CASING_MV"); + public static final CustomIcon TEXTURE_CASING_TIERED_HV = new CustomIcon("iconsets/TieredHulls/CASING_HV"); + public static final CustomIcon TEXTURE_CASING_TIERED_EV = new CustomIcon("iconsets/TieredHulls/CASING_EV"); + public static final CustomIcon TEXTURE_CASING_TIERED_IV = new CustomIcon("iconsets/TieredHulls/CASING_IV"); + public static final CustomIcon TEXTURE_CASING_TIERED_LuV = new CustomIcon("iconsets/TieredHulls/CASING_LuV"); + public static final CustomIcon TEXTURE_CASING_TIERED_ZPM = new CustomIcon("iconsets/TieredHulls/CASING_ZPM"); + public static final CustomIcon TEXTURE_CASING_TIERED_UV = new CustomIcon("iconsets/TieredHulls/CASING_UV"); + public static final CustomIcon TEXTURE_CASING_TIERED_MAX = new CustomIcon("iconsets/TieredHulls/CASING_MAX"); + + // Metroid related + public static final CustomIcon TEXTURE_METAL_PANEL_A = new CustomIcon("metro/TEXTURE_METAL_PANEL_A"); + public static final CustomIcon TEXTURE_METAL_PANEL_B = new CustomIcon("metro/TEXTURE_METAL_PANEL_B"); + public static final CustomIcon TEXTURE_METAL_PANEL_C = new CustomIcon("metro/TEXTURE_METAL_PANEL_C"); + public static final CustomIcon TEXTURE_METAL_PANEL_D = new CustomIcon("metro/TEXTURE_METAL_PANEL_D"); + public static final CustomIcon TEXTURE_METAL_PANEL_F = new CustomIcon("metro/TEXTURE_METAL_PANEL_F"); + + public static final CustomIcon TEXTURE_MAGIC_PANEL_A = new CustomIcon("metro/TEXTURE_MAGIC_A"); + public static final CustomIcon TEXTURE_MAGIC_PANEL_B = new CustomIcon("metro/TEXTURE_MAGIC_B"); + + public static final CustomIcon TEXTURE_ORGANIC_PANEL_A_GLOWING = new CustomIcon( + "metro/TEXTURE_ORGANIC_PANEL_A_GLOWING"); + + public static final CustomIcon TEXTURE_STONE_RED_A = new CustomIcon("metro/TEXTURE_STONE_RED_A"); + public static final CustomIcon TEXTURE_STONE_RED_B = new CustomIcon("metro/TEXTURE_STONE_RED_B"); + + public static final CustomIcon OVERLAY_SC_TURBINE1 = new TexturesGtBlock.CustomIcon("iconsets/SC_TURBINE_IDEL1"); + public static final CustomIcon OVERLAY_SC_TURBINE2 = new TexturesGtBlock.CustomIcon("iconsets/SC_TURBINE_IDEL2"); + public static final CustomIcon OVERLAY_SC_TURBINE3 = new TexturesGtBlock.CustomIcon("iconsets/SC_TURBINE_IDEL3"); + public static final CustomIcon OVERLAY_SC_TURBINE4 = new TexturesGtBlock.CustomIcon("iconsets/SC_TURBINE_IDEL4"); + public static final CustomIcon OVERLAY_SC_TURBINE5 = new TexturesGtBlock.CustomIcon("iconsets/SC_TURBINE_IDEL5"); + public static final CustomIcon OVERLAY_SC_TURBINE6 = new TexturesGtBlock.CustomIcon("iconsets/SC_TURBINE_IDEL6"); + public static final CustomIcon OVERLAY_SC_TURBINE7 = new TexturesGtBlock.CustomIcon("iconsets/SC_TURBINE_IDEL7"); + public static final CustomIcon OVERLAY_SC_TURBINE8 = new TexturesGtBlock.CustomIcon("iconsets/SC_TURBINE_IDEL8"); + public static final CustomIcon OVERLAY_SC_TURBINE9 = new TexturesGtBlock.CustomIcon("iconsets/SC_TURBINE_IDEL9"); + + public static final CustomIcon OVERLAY_SC_TURBINE1_ACTIVE = new TexturesGtBlock.CustomIcon("iconsets/SC_TURBINE1"); + public static final CustomIcon OVERLAY_SC_TURBINE2_ACTIVE = new TexturesGtBlock.CustomIcon("iconsets/SC_TURBINE2"); + public static final CustomIcon OVERLAY_SC_TURBINE3_ACTIVE = new TexturesGtBlock.CustomIcon("iconsets/SC_TURBINE3"); + public static final CustomIcon OVERLAY_SC_TURBINE4_ACTIVE = new TexturesGtBlock.CustomIcon("iconsets/SC_TURBINE4"); + public static final CustomIcon OVERLAY_SC_TURBINE5_ACTIVE = new TexturesGtBlock.CustomIcon("iconsets/SC_TURBINE5"); + public static final CustomIcon OVERLAY_SC_TURBINE6_ACTIVE = new TexturesGtBlock.CustomIcon("iconsets/SC_TURBINE6"); + public static final CustomIcon OVERLAY_SC_TURBINE7_ACTIVE = new TexturesGtBlock.CustomIcon("iconsets/SC_TURBINE7"); + public static final CustomIcon OVERLAY_SC_TURBINE8_ACTIVE = new TexturesGtBlock.CustomIcon("iconsets/SC_TURBINE8"); + public static final CustomIcon OVERLAY_SC_TURBINE9_ACTIVE = new TexturesGtBlock.CustomIcon("iconsets/SC_TURBINE9"); + public static final CustomIcon TEXTURE_TECH_A = new CustomIcon("metro/TEXTURE_TECH_A"); + public static final CustomIcon TEXTURE_TECH_B = new CustomIcon("metro/TEXTURE_TECH_B"); + public static final CustomIcon TEXTURE_TECH_C = new CustomIcon("metro/TEXTURE_TECH_C"); + + public static final CustomIcon TEXTURE_TECH_PANEL_D = new CustomIcon("metro/TEXTURE_TECH_PANEL_D"); + public static final CustomIcon TEXTURE_TECH_PANEL_H = new CustomIcon("metro/TEXTURE_TECH_PANEL_H"); + + public static ITexture[] OVERLAYS_ENERGY_OUT_MULTI_BUFFER = new ITexture[] { + new GT_RenderedTexture(OVERLAY_ENERGY_OUT_MULTI_BUFFER, new short[] { 220, 220, 220, 0 }), + new GT_RenderedTexture(OVERLAY_ENERGY_OUT_MULTI_BUFFER, new short[] { 220, 220, 220, 0 }), + new GT_RenderedTexture(OVERLAY_ENERGY_OUT_MULTI_BUFFER, new short[] { 255, 100, 0, 0 }), + new GT_RenderedTexture(OVERLAY_ENERGY_OUT_MULTI_BUFFER, new short[] { 255, 255, 30, 0 }), + new GT_RenderedTexture(OVERLAY_ENERGY_OUT_MULTI_BUFFER, new short[] { 128, 128, 128, 0 }), + new GT_RenderedTexture(OVERLAY_ENERGY_OUT_MULTI_BUFFER, new short[] { 240, 240, 245, 0 }), + new GT_RenderedTexture(OVERLAY_ENERGY_OUT_MULTI_BUFFER, new short[] { 240, 240, 245, 0 }), + new GT_RenderedTexture(OVERLAY_ENERGY_OUT_MULTI_BUFFER, new short[] { 240, 240, 245, 0 }), + new GT_RenderedTexture(OVERLAY_ENERGY_OUT_MULTI_BUFFER, new short[] { 240, 240, 245, 0 }), + new GT_RenderedTexture(OVERLAY_ENERGY_OUT_MULTI_BUFFER, new short[] { 240, 240, 245, 0 }) }; + + public static IIconContainer[] CONNECTED_FUSION_HULLS = new IIconContainer[] { TEXTURE_CASING_FUSION_COIL_II_1, + TEXTURE_CASING_FUSION_COIL_II_2, TEXTURE_CASING_FUSION_COIL_II_3, TEXTURE_CASING_FUSION_COIL_II_4, + TEXTURE_CASING_FUSION_COIL_II_5, TEXTURE_CASING_FUSION_COIL_II_6, TEXTURE_CASING_FUSION_COIL_II_7, + TEXTURE_CASING_FUSION_COIL_II_8, TEXTURE_CASING_FUSION_COIL_II_9, TEXTURE_CASING_FUSION_COIL_II_10, + TEXTURE_CASING_FUSION_COIL_II_11, TEXTURE_CASING_FUSION_COIL_II_12 }; + + public static IIconContainer[] CONNECTED_FUSION_HULLS_MK4 = new IIconContainer[] { TEXTURE_CASING_FUSION_COIL_III_1, + TEXTURE_CASING_FUSION_COIL_III_2, TEXTURE_CASING_FUSION_COIL_III_3, TEXTURE_CASING_FUSION_COIL_III_4, + TEXTURE_CASING_FUSION_COIL_III_5, TEXTURE_CASING_FUSION_COIL_III_6, TEXTURE_CASING_FUSION_COIL_III_7, + TEXTURE_CASING_FUSION_COIL_III_8, TEXTURE_CASING_FUSION_COIL_III_9, TEXTURE_CASING_FUSION_COIL_III_10, + TEXTURE_CASING_FUSION_COIL_III_11, TEXTURE_CASING_FUSION_COIL_III_12 }; + + public static IIconContainer[] TIERED_MACHINE_HULLS = new IIconContainer[] { TEXTURE_CASING_TIERED_ULV, + TEXTURE_CASING_TIERED_LV, TEXTURE_CASING_TIERED_MV, TEXTURE_CASING_TIERED_HV, TEXTURE_CASING_TIERED_EV, + TEXTURE_CASING_TIERED_IV, TEXTURE_CASING_TIERED_LuV, TEXTURE_CASING_TIERED_ZPM, TEXTURE_CASING_TIERED_UV, + TEXTURE_CASING_TIERED_MAX }; +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/TexturesGtTools.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/TexturesGtTools.java new file mode 100644 index 0000000000..a9f74cd75d --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/TexturesGtTools.java @@ -0,0 +1,51 @@ +package gtPlusPlus.xmod.gregtech.common.blocks.textures; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.util.IIcon; +import net.minecraft.util.ResourceLocation; + +import gregtech.api.GregTech_API; +import gregtech.api.interfaces.IIconContainer; +import gtPlusPlus.api.objects.Logger; + +public final class TexturesGtTools { + + public static final CustomIcon ANGLE_GRINDER = new CustomIcon("iconsets/ANGLE_GRINDER"); + public static final CustomIcon ELECTRIC_SNIPS = new CustomIcon("iconsets/ELECTRIC_SNIPS"); + + public static final class CustomIcon implements IIconContainer, Runnable { + + private IIcon mIcon, mOverlay; + private final String mIconName; + + public CustomIcon(final String aIconName) { + this.mIconName = aIconName; + Logger.INFO("Constructing a Custom Texture. " + this.mIconName); + GregTech_API.sGTItemIconload.add(this); + } + + @Override + public IIcon getIcon() { + return this.mIcon; + } + + @Override + public IIcon getOverlayIcon() { + return this.mOverlay; + } + + @Override + public void run() { + this.mIcon = GregTech_API.sItemIcons.registerIcon(GTPlusPlus.ID + ":" + this.mIconName); + // Utils.LOG_INFO("Registering a Custom Texture. "+mIcon.g); + this.mOverlay = GregTech_API.sItemIcons.registerIcon(GTPlusPlus.ID + ":" + this.mIconName + "_OVERLAY"); + } + + @Override + public ResourceLocation getTextureFile() { + return TextureMap.locationItemsTexture; + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/turbine/LargeTurbineTextureHandler.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/turbine/LargeTurbineTextureHandler.java new file mode 100644 index 0000000000..c983044319 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/blocks/textures/turbine/LargeTurbineTextureHandler.java @@ -0,0 +1,410 @@ +package gtPlusPlus.xmod.gregtech.common.blocks.textures.turbine; + +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS1; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS2; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS3; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS4; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS5; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS6; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS7; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS8; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS9; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS_ACTIVE1; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS_ACTIVE2; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS_ACTIVE3; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS_ACTIVE4; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS_ACTIVE5; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS_ACTIVE6; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS_ACTIVE7; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS_ACTIVE8; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_SS_ACTIVE9; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST1; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST2; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST3; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST4; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST5; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST6; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST7; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST8; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST9; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST_ACTIVE1; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST_ACTIVE2; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST_ACTIVE3; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST_ACTIVE4; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST_ACTIVE5; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST_ACTIVE6; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST_ACTIVE7; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST_ACTIVE8; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_ST_ACTIVE9; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI1; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI2; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI3; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI4; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI5; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI6; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI7; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI8; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI9; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI_ACTIVE1; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI_ACTIVE2; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI_ACTIVE3; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI_ACTIVE4; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI_ACTIVE5; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI_ACTIVE6; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI_ACTIVE7; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI_ACTIVE8; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TI_ACTIVE9; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU1; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU2; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU3; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU4; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU5; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU6; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU7; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU8; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU9; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU_ACTIVE1; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU_ACTIVE2; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU_ACTIVE3; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU_ACTIVE4; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU_ACTIVE5; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU_ACTIVE6; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU_ACTIVE7; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU_ACTIVE8; +import static gregtech.api.enums.Textures.BlockIcons.LARGETURBINE_TU_ACTIVE9; +import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.OVERLAY_SC_TURBINE1; +import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.OVERLAY_SC_TURBINE1_ACTIVE; +import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.OVERLAY_SC_TURBINE2; +import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.OVERLAY_SC_TURBINE2_ACTIVE; +import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.OVERLAY_SC_TURBINE3; +import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.OVERLAY_SC_TURBINE3_ACTIVE; +import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.OVERLAY_SC_TURBINE4; +import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.OVERLAY_SC_TURBINE4_ACTIVE; +import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.OVERLAY_SC_TURBINE5; +import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.OVERLAY_SC_TURBINE5_ACTIVE; +import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.OVERLAY_SC_TURBINE6; +import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.OVERLAY_SC_TURBINE6_ACTIVE; +import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.OVERLAY_SC_TURBINE7; +import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.OVERLAY_SC_TURBINE7_ACTIVE; +import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.OVERLAY_SC_TURBINE8; +import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.OVERLAY_SC_TURBINE8_ACTIVE; +import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.OVERLAY_SC_TURBINE9; +import static gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.OVERLAY_SC_TURBINE9_ACTIVE; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Turbine; +import gtPlusPlus.xmod.gregtech.common.blocks.GregtechMetaSpecialMultiCasings; + +public class LargeTurbineTextureHandler { + + /** + * LP Turbines + */ + public static IIcon[] OVERLAY_LP_TURBINE = new IIcon[] { LARGETURBINE_ST1.getIcon(), LARGETURBINE_ST2.getIcon(), + LARGETURBINE_ST3.getIcon(), LARGETURBINE_ST4.getIcon(), LARGETURBINE_ST5.getIcon(), LARGETURBINE_ST6.getIcon(), + LARGETURBINE_ST7.getIcon(), LARGETURBINE_ST8.getIcon(), LARGETURBINE_ST9.getIcon(), }; + + public static IIcon[] OVERLAY_LP_TURBINE_ACTIVE = new IIcon[] { LARGETURBINE_ST_ACTIVE1.getIcon(), + LARGETURBINE_ST_ACTIVE2.getIcon(), LARGETURBINE_ST_ACTIVE3.getIcon(), LARGETURBINE_ST_ACTIVE4.getIcon(), + LARGETURBINE_ST_ACTIVE5.getIcon(), LARGETURBINE_ST_ACTIVE6.getIcon(), LARGETURBINE_ST_ACTIVE7.getIcon(), + LARGETURBINE_ST_ACTIVE8.getIcon(), LARGETURBINE_ST_ACTIVE9.getIcon(), }; + + /** + * HP Turbines + */ + public static IIcon[] OVERLAY_HP_TURBINE = new IIcon[] { LARGETURBINE_TI1.getIcon(), LARGETURBINE_TI2.getIcon(), + LARGETURBINE_TI3.getIcon(), LARGETURBINE_TI4.getIcon(), LARGETURBINE_TI5.getIcon(), LARGETURBINE_TI6.getIcon(), + LARGETURBINE_TI7.getIcon(), LARGETURBINE_TI8.getIcon(), LARGETURBINE_TI9.getIcon(), }; + + public static IIcon[] OVERLAY_HP_TURBINE_ACTIVE = new IIcon[] { LARGETURBINE_TI_ACTIVE1.getIcon(), + LARGETURBINE_TI_ACTIVE2.getIcon(), LARGETURBINE_TI_ACTIVE3.getIcon(), LARGETURBINE_TI_ACTIVE4.getIcon(), + LARGETURBINE_TI_ACTIVE5.getIcon(), LARGETURBINE_TI_ACTIVE6.getIcon(), LARGETURBINE_TI_ACTIVE7.getIcon(), + LARGETURBINE_TI_ACTIVE8.getIcon(), LARGETURBINE_TI_ACTIVE9.getIcon(), }; + + /** + * Gas Turbines + */ + public static IIcon[] OVERLAY_GAS_TURBINE = new IIcon[] { LARGETURBINE_SS1.getIcon(), LARGETURBINE_SS2.getIcon(), + LARGETURBINE_SS3.getIcon(), LARGETURBINE_SS4.getIcon(), LARGETURBINE_SS5.getIcon(), LARGETURBINE_SS6.getIcon(), + LARGETURBINE_SS7.getIcon(), LARGETURBINE_SS8.getIcon(), LARGETURBINE_SS9.getIcon(), }; + + public static IIcon[] OVERLAY_GAS_TURBINE_ACTIVE = new IIcon[] { LARGETURBINE_SS_ACTIVE1.getIcon(), + LARGETURBINE_SS_ACTIVE2.getIcon(), LARGETURBINE_SS_ACTIVE3.getIcon(), LARGETURBINE_SS_ACTIVE4.getIcon(), + LARGETURBINE_SS_ACTIVE5.getIcon(), LARGETURBINE_SS_ACTIVE6.getIcon(), LARGETURBINE_SS_ACTIVE7.getIcon(), + LARGETURBINE_SS_ACTIVE8.getIcon(), LARGETURBINE_SS_ACTIVE9.getIcon(), }; + + /** + * Plasma Turbines + */ + public static IIcon[] OVERLAY_PLASMA_TURBINE = new IIcon[] { LARGETURBINE_TU1.getIcon(), LARGETURBINE_TU2.getIcon(), + LARGETURBINE_TU3.getIcon(), LARGETURBINE_TU4.getIcon(), LARGETURBINE_TU5.getIcon(), LARGETURBINE_TU6.getIcon(), + LARGETURBINE_TU7.getIcon(), LARGETURBINE_TU8.getIcon(), LARGETURBINE_TU9.getIcon(), }; + + public static IIcon[] OVERLAY_PLASMA_TURBINE_ACTIVE = new IIcon[] { LARGETURBINE_TU_ACTIVE1.getIcon(), + LARGETURBINE_TU_ACTIVE2.getIcon(), LARGETURBINE_TU_ACTIVE3.getIcon(), LARGETURBINE_TU_ACTIVE4.getIcon(), + LARGETURBINE_TU_ACTIVE5.getIcon(), LARGETURBINE_TU_ACTIVE6.getIcon(), LARGETURBINE_TU_ACTIVE7.getIcon(), + LARGETURBINE_TU_ACTIVE8.getIcon(), LARGETURBINE_TU_ACTIVE9.getIcon(), }; + + public static IIcon[] OVERLAY_SC_TURBINE = new IIcon[] { OVERLAY_SC_TURBINE1.getIcon(), + OVERLAY_SC_TURBINE2.getIcon(), OVERLAY_SC_TURBINE3.getIcon(), OVERLAY_SC_TURBINE4.getIcon(), + OVERLAY_SC_TURBINE5.getIcon(), OVERLAY_SC_TURBINE6.getIcon(), OVERLAY_SC_TURBINE7.getIcon(), + OVERLAY_SC_TURBINE8.getIcon(), OVERLAY_SC_TURBINE9.getIcon(), }; + + public static IIcon[] OVERLAY_SC_TURBINE_ACTIVE = new IIcon[] { OVERLAY_SC_TURBINE1_ACTIVE.getIcon(), + OVERLAY_SC_TURBINE2_ACTIVE.getIcon(), OVERLAY_SC_TURBINE3_ACTIVE.getIcon(), + OVERLAY_SC_TURBINE4_ACTIVE.getIcon(), OVERLAY_SC_TURBINE5_ACTIVE.getIcon(), + OVERLAY_SC_TURBINE6_ACTIVE.getIcon(), OVERLAY_SC_TURBINE7_ACTIVE.getIcon(), + OVERLAY_SC_TURBINE8_ACTIVE.getIcon(), OVERLAY_SC_TURBINE9_ACTIVE.getIcon(), }; + + public static IIcon handleCasingsGT(final IBlockAccess aWorld, final int xCoord, final int yCoord, final int zCoord, + final ForgeDirection side, final GregtechMetaSpecialMultiCasings i) { + final int tMeta = aWorld.getBlockMetadata(xCoord, yCoord, zCoord); + + // 0 shaft + // 1 LP + // 2 HP + // 3 Gas + // 4 Plasma + + IIcon[] mGetCurrentTextureSet = null; + IIcon[] mGetCurrentTextureSet_ACTIVE = null; + + if ((tMeta <= 0 || tMeta >= 5) && tMeta != 15) { + return GregtechMetaSpecialMultiCasings.getStaticIcon(side.ordinal(), (byte) tMeta); + } else { + if (tMeta == 1) { + mGetCurrentTextureSet = OVERLAY_LP_TURBINE; + mGetCurrentTextureSet_ACTIVE = OVERLAY_LP_TURBINE_ACTIVE; + } else if (tMeta == 2) { + mGetCurrentTextureSet = OVERLAY_HP_TURBINE; + mGetCurrentTextureSet_ACTIVE = OVERLAY_HP_TURBINE_ACTIVE; + } else if (tMeta == 3) { + mGetCurrentTextureSet = OVERLAY_GAS_TURBINE; + mGetCurrentTextureSet_ACTIVE = OVERLAY_GAS_TURBINE_ACTIVE; + } else if (tMeta == 4) { + mGetCurrentTextureSet = OVERLAY_PLASMA_TURBINE; + mGetCurrentTextureSet_ACTIVE = OVERLAY_PLASMA_TURBINE_ACTIVE; + } else { + mGetCurrentTextureSet = OVERLAY_SC_TURBINE; + mGetCurrentTextureSet_ACTIVE = OVERLAY_SC_TURBINE_ACTIVE; + } + if (mGetCurrentTextureSet == null || mGetCurrentTextureSet_ACTIVE == null) { + return GregtechMetaSpecialMultiCasings.getStaticIcon(side.ordinal(), (byte) tMeta); + } + + if ((side == ForgeDirection.NORTH) || (side == ForgeDirection.SOUTH)) { + TileEntity tTileEntity; + IMetaTileEntity tMetaTileEntity; + if ((null != (tTileEntity = aWorld + .getTileEntity(xCoord + (side == ForgeDirection.SOUTH ? 1 : -1), yCoord - 1, zCoord))) + && ((tTileEntity instanceof IGregTechTileEntity)) + && (((IGregTechTileEntity) tTileEntity).getFrontFacing() == side) + && (null != (tMetaTileEntity = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity())) + && ((tMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine))) { + if (isUsingAnimatedTexture(tTileEntity)) { + return mGetCurrentTextureSet_ACTIVE[0]; + } + return mGetCurrentTextureSet[0]; + } + if ((null != (tTileEntity = aWorld + .getTileEntity(xCoord + (side == ForgeDirection.SOUTH ? 1 : -1), yCoord, zCoord))) + && ((tTileEntity instanceof IGregTechTileEntity)) + && (((IGregTechTileEntity) tTileEntity).getFrontFacing() == side) + && (null != (tMetaTileEntity = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity())) + && ((tMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine))) { + if (isUsingAnimatedTexture(tTileEntity)) { + return mGetCurrentTextureSet_ACTIVE[3]; + } + return mGetCurrentTextureSet[3]; + } + if ((null != (tTileEntity = aWorld + .getTileEntity(xCoord + (side == ForgeDirection.SOUTH ? 1 : -1), yCoord + 1, zCoord))) + && ((tTileEntity instanceof IGregTechTileEntity)) + && (((IGregTechTileEntity) tTileEntity).getFrontFacing() == side) + && (null != (tMetaTileEntity = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity())) + && ((tMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine))) { + if (isUsingAnimatedTexture(tTileEntity)) { + return mGetCurrentTextureSet_ACTIVE[6]; + } + return mGetCurrentTextureSet[6]; + } + if ((null != (tTileEntity = aWorld.getTileEntity(xCoord, yCoord - 1, zCoord))) + && ((tTileEntity instanceof IGregTechTileEntity)) + && (((IGregTechTileEntity) tTileEntity).getFrontFacing() == side) + && (null != (tMetaTileEntity = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity())) + && ((tMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine))) { + if (isUsingAnimatedTexture(tTileEntity)) { + return mGetCurrentTextureSet_ACTIVE[1]; + } + return mGetCurrentTextureSet[1]; + } + if ((null != (tTileEntity = aWorld.getTileEntity(xCoord, yCoord + 1, zCoord))) + && ((tTileEntity instanceof IGregTechTileEntity)) + && (((IGregTechTileEntity) tTileEntity).getFrontFacing() == side) + && (null != (tMetaTileEntity = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity())) + && ((tMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine))) { + if (isUsingAnimatedTexture(tTileEntity)) { + return mGetCurrentTextureSet_ACTIVE[7]; + } + return mGetCurrentTextureSet[7]; + } + if ((null != (tTileEntity = aWorld + .getTileEntity(xCoord + (side == ForgeDirection.NORTH ? 1 : -1), yCoord + 1, zCoord))) + && ((tTileEntity instanceof IGregTechTileEntity)) + && (((IGregTechTileEntity) tTileEntity).getFrontFacing() == side) + && (null != (tMetaTileEntity = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity())) + && ((tMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine))) { + if (isUsingAnimatedTexture(tTileEntity)) { + return mGetCurrentTextureSet_ACTIVE[8]; + } + return mGetCurrentTextureSet[8]; + } + if ((null != (tTileEntity = aWorld + .getTileEntity(xCoord + (side == ForgeDirection.NORTH ? 1 : -1), yCoord, zCoord))) + && ((tTileEntity instanceof IGregTechTileEntity)) + && (((IGregTechTileEntity) tTileEntity).getFrontFacing() == side) + && (null != (tMetaTileEntity = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity())) + && ((tMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine))) { + if (isUsingAnimatedTexture(tTileEntity)) { + return mGetCurrentTextureSet_ACTIVE[5]; + } + return mGetCurrentTextureSet[5]; + } + if ((null != (tTileEntity = aWorld + .getTileEntity(xCoord + (side == ForgeDirection.NORTH ? 1 : -1), yCoord - 1, zCoord))) + && ((tTileEntity instanceof IGregTechTileEntity)) + && (((IGregTechTileEntity) tTileEntity).getFrontFacing() == side) + && (null != (tMetaTileEntity = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity())) + && ((tMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine))) { + if (isUsingAnimatedTexture(tTileEntity)) { + return mGetCurrentTextureSet_ACTIVE[2]; + } + return mGetCurrentTextureSet[2]; + } + } else if ((side == ForgeDirection.WEST) || (side == ForgeDirection.EAST)) { + TileEntity tTileEntity; + Object tMetaTileEntity; + if ((null != (tTileEntity = aWorld + .getTileEntity(xCoord, yCoord - 1, zCoord + (side == ForgeDirection.WEST ? 1 : -1)))) + && ((tTileEntity instanceof IGregTechTileEntity)) + && (((IGregTechTileEntity) tTileEntity).getFrontFacing() == side) + && (null != (tMetaTileEntity = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity())) + && ((tMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine))) { + if (isUsingAnimatedTexture(tTileEntity)) { + return mGetCurrentTextureSet_ACTIVE[0]; + } + return mGetCurrentTextureSet[0]; + } + if ((null != (tTileEntity = aWorld + .getTileEntity(xCoord, yCoord, zCoord + (side == ForgeDirection.WEST ? 1 : -1)))) + && ((tTileEntity instanceof IGregTechTileEntity)) + && (((IGregTechTileEntity) tTileEntity).getFrontFacing() == side) + && (null != (tMetaTileEntity = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity())) + && ((tMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine))) { + if (isUsingAnimatedTexture(tTileEntity)) { + return mGetCurrentTextureSet_ACTIVE[3]; + } + return mGetCurrentTextureSet[3]; + } + if ((null != (tTileEntity = aWorld + .getTileEntity(xCoord, yCoord + 1, zCoord + (side == ForgeDirection.WEST ? 1 : -1)))) + && ((tTileEntity instanceof IGregTechTileEntity)) + && (((IGregTechTileEntity) tTileEntity).getFrontFacing() == side) + && (null != (tMetaTileEntity = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity())) + && ((tMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine))) { + if (isUsingAnimatedTexture(tTileEntity)) { + return mGetCurrentTextureSet_ACTIVE[6]; + } + return mGetCurrentTextureSet[6]; + } + if ((null != (tTileEntity = aWorld.getTileEntity(xCoord, yCoord - 1, zCoord))) + && ((tTileEntity instanceof IGregTechTileEntity)) + && (((IGregTechTileEntity) tTileEntity).getFrontFacing() == side) + && (null != (tMetaTileEntity = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity())) + && ((tMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine))) { + if (isUsingAnimatedTexture(tTileEntity)) { + return mGetCurrentTextureSet_ACTIVE[1]; + } + return mGetCurrentTextureSet[1]; + } + if ((null != (tTileEntity = aWorld.getTileEntity(xCoord, yCoord + 1, zCoord))) + && ((tTileEntity instanceof IGregTechTileEntity)) + && (((IGregTechTileEntity) tTileEntity).getFrontFacing() == side) + && (null != (tMetaTileEntity = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity())) + && ((tMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine))) { + if (isUsingAnimatedTexture(tTileEntity)) { + return mGetCurrentTextureSet_ACTIVE[7]; + } + return mGetCurrentTextureSet[7]; + } + if ((null != (tTileEntity = aWorld + .getTileEntity(xCoord, yCoord + 1, zCoord + (side == ForgeDirection.EAST ? 1 : -1)))) + && ((tTileEntity instanceof IGregTechTileEntity)) + && (((IGregTechTileEntity) tTileEntity).getFrontFacing() == side) + && (null != (tMetaTileEntity = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity())) + && ((tMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine))) { + if (isUsingAnimatedTexture(tTileEntity)) { + return mGetCurrentTextureSet_ACTIVE[8]; + } + return mGetCurrentTextureSet[8]; + } + if ((null != (tTileEntity = aWorld + .getTileEntity(xCoord, yCoord, zCoord + (side == ForgeDirection.EAST ? 1 : -1)))) + && ((tTileEntity instanceof IGregTechTileEntity)) + && (((IGregTechTileEntity) tTileEntity).getFrontFacing() == side) + && (null != (tMetaTileEntity = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity())) + && ((tMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine))) { + if (isUsingAnimatedTexture(tTileEntity)) { + return mGetCurrentTextureSet_ACTIVE[5]; + } + return mGetCurrentTextureSet[5]; + } + if ((null != (tTileEntity = aWorld + .getTileEntity(xCoord, yCoord - 1, zCoord + (side == ForgeDirection.EAST ? 1 : -1)))) + && ((tTileEntity instanceof IGregTechTileEntity)) + && (((IGregTechTileEntity) tTileEntity).getFrontFacing() == side) + && (null != (tMetaTileEntity = ((IGregTechTileEntity) tTileEntity).getMetaTileEntity())) + && ((tMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine))) { + if (isUsingAnimatedTexture(tTileEntity)) { + return mGetCurrentTextureSet_ACTIVE[2]; + } + return mGetCurrentTextureSet[2]; + } + } + } + return GregtechMetaSpecialMultiCasings.getStaticIcon(side.ordinal(), (byte) tMeta); + } + + public static boolean isUsingAnimatedTexture(TileEntity tTileEntity) { + boolean aVal = true; + IGregTechTileEntity aTile; + if (tTileEntity instanceof IGregTechTileEntity) { + aTile = (IGregTechTileEntity) tTileEntity; + if (aTile != null) { + final IMetaTileEntity aMetaTileEntity = aTile.getMetaTileEntity(); + if (aMetaTileEntity != null && aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine) { + aVal = ((GT_MetaTileEntity_Hatch_Turbine) aMetaTileEntity).getBaseMetaTileEntity() + .isActive(); + // Logger.INFO("Returning "+aVal+" as Rotor Assembly controller status"); + } + } + } + return aVal; + } + + public static GT_MetaTileEntity_Hatch_Turbine isTurbineHatch(final IGregTechTileEntity aTileEntity) { + if (aTileEntity != null) { + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity != null && aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine) { + return (GT_MetaTileEntity_Hatch_Turbine) aMetaTileEntity; + } + } + return null; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/covers/CoverManager.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/covers/CoverManager.java new file mode 100644 index 0000000000..c1f87ef041 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/covers/CoverManager.java @@ -0,0 +1,16 @@ +package gtPlusPlus.xmod.gregtech.common.covers; + +import gtPlusPlus.xmod.gregtech.common.items.covers.MetaItemCoverCasings; + +public class CoverManager { + + // GT + public static MetaItemCoverCasings Cover_Gt_Machine_Casing; + + public static void generateCustomCovers() { + + // GT Machine Casings + Cover_Gt_Machine_Casing = new MetaItemCoverCasings(); + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/covers/GTPP_Cover_Overflow.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/covers/GTPP_Cover_Overflow.java new file mode 100644 index 0000000000..8b75f4f156 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/covers/GTPP_Cover_Overflow.java @@ -0,0 +1,203 @@ +package gtPlusPlus.xmod.gregtech.common.covers; + +import java.util.concurrent.atomic.AtomicBoolean; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidHandler; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.common.widget.TextWidget; + +import gregtech.api.gui.modularui.GT_CoverUIBuildContext; +import gregtech.api.interfaces.tileentity.ICoverable; +import gregtech.api.util.GT_CoverBehavior; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.ISerializableObject; +import gregtech.common.gui.modularui.widget.CoverDataControllerWidget; +import gregtech.common.gui.modularui.widget.CoverDataFollower_NumericWidget; + +public class GTPP_Cover_Overflow extends GT_CoverBehavior { + + public final int mTransferRate; + public final int mInitialTransferRate; + public final int mMaxTransferRate; + + public GTPP_Cover_Overflow(int aTransferRate) { + this.mTransferRate = aTransferRate * 1000 / 10; + this.mInitialTransferRate = aTransferRate; + this.mMaxTransferRate = aTransferRate * 1000; + } + + public int doCoverThings(ForgeDirection side, byte aInputRedstone, int aCoverID, int aCoverVariable, + ICoverable aTileEntity, long aTimer) { + if (aCoverVariable == 0) { + return aCoverVariable; + } + if ((aTileEntity instanceof IFluidHandler)) { + // Logger.INFO("Trying to Void via Overflow."); + IFluidHandler tTank1; + ForgeDirection directionFrom; + directionFrom = ForgeDirection.UNKNOWN; + tTank1 = (IFluidHandler) aTileEntity; + if (tTank1 != null) { + FluidStack aTankStack = tTank1.getTankInfo(directionFrom)[0].fluid; + if (aTankStack != null) { + // Logger.INFO("Found Fluid inside self - "+aTankStack.getLocalizedName()+", overflow point set at + // "+aCoverVariable+"L and we have "+aTankStack.amount+"L inside."); + if (aTankStack.amount > aCoverVariable) { + int aAmountToDrain = aTankStack.amount - aCoverVariable; + // Logger.INFO("There is "+aAmountToDrain+" more fluid in the tank than we would like."); + if (aAmountToDrain > 0) { + FluidStack tLiquid = tTank1.drain(directionFrom, Math.abs(aAmountToDrain), true); + if (tLiquid != null) { + // Logger.INFO("Drained "+aAmountToDrain+"L."); + } + } + } + } else { + // Logger.INFO("Could not simulate drain on self."); + } + } + } + return aCoverVariable; + } + + public int onCoverScrewdriverclick(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity, + EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (GT_Utility.getClickedFacingCoords(side, aX, aY, aZ)[0] >= 0.5F) { + aCoverVariable += (mMaxTransferRate * (aPlayer.isSneaking() ? 0.1f : 0.01f)); + } else { + aCoverVariable -= (mMaxTransferRate * (aPlayer.isSneaking() ? 0.1f : 0.01f)); + } + if (aCoverVariable > mMaxTransferRate) { + aCoverVariable = mInitialTransferRate; + } + if (aCoverVariable <= 0) { + aCoverVariable = mMaxTransferRate; + } + GT_Utility.sendChatToPlayer( + aPlayer, + GT_Utility.trans("322", "Overflow point: ") + aCoverVariable + GT_Utility.trans("323", "L")); + return aCoverVariable; + } + + public boolean onCoverRightclick(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity, + EntityPlayer aPlayer, float aX, float aY, float aZ) { + boolean aShift = aPlayer.isSneaking(); + int aAmount = aShift ? 128 : 8; + if (GT_Utility.getClickedFacingCoords(side, aX, aY, aZ)[0] >= 0.5F) { + aCoverVariable += aAmount; + } else { + aCoverVariable -= aAmount; + } + if (aCoverVariable > mMaxTransferRate) { + aCoverVariable = mInitialTransferRate; + } + if (aCoverVariable <= 0) { + aCoverVariable = mMaxTransferRate; + } + GT_Utility.sendChatToPlayer( + aPlayer, + GT_Utility.trans("322", "Overflow point: ") + aCoverVariable + GT_Utility.trans("323", "L")); + aTileEntity.setCoverDataAtSide(side, new ISerializableObject.LegacyCoverData(aCoverVariable)); + return true; + } + + public boolean letsRedstoneGoIn(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return true; + } + + public boolean letsRedstoneGoOut(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return true; + } + + public boolean letsEnergyIn(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return true; + } + + public boolean letsEnergyOut(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return true; + } + + public boolean letsItemsIn(ForgeDirection side, int aCoverID, int aCoverVariable, int aSlot, + ICoverable aTileEntity) { + return true; + } + + public boolean letsItemsOut(ForgeDirection side, int aCoverID, int aCoverVariable, int aSlot, + ICoverable aTileEntity) { + return true; + } + + public boolean letsFluidIn(ForgeDirection side, int aCoverID, int aCoverVariable, Fluid aFluid, + ICoverable aTileEntity) { + return false; + } + + public boolean letsFluidOut(ForgeDirection side, int aCoverID, int aCoverVariable, Fluid aFluid, + ICoverable aTileEntity) { + return true; + } + + public boolean alwaysLookConnected(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return true; + } + + public int getTickRate(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return 5; + } + + // GUI + + @Override + public boolean hasCoverGUI() { + return true; + } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public ModularWindow createWindow(GT_CoverUIBuildContext buildContext) { + return new OverflowUIFactory(buildContext).createWindow(); + } + + private class OverflowUIFactory extends UIFactory { + + private static final int startX = 10; + private static final int startY = 25; + private static final int spaceX = 18; + private static final int spaceY = 18; + + public OverflowUIFactory(GT_CoverUIBuildContext buildContext) { + super(buildContext); + } + + @SuppressWarnings("PointlessArithmeticExpression") + @Override + protected void addUIWidgets(ModularWindow.Builder builder) { + AtomicBoolean warn = new AtomicBoolean(false); + + builder + .widget( + new CoverDataControllerWidget<>(this::getCoverData, this::setCoverData, GTPP_Cover_Overflow.this) + .addFollower( + new CoverDataFollower_NumericWidget<>(), + coverData -> (double) convert(coverData), + (coverData, state) -> new ISerializableObject.LegacyCoverData(state.intValue()), + widget -> widget.setBounds(0, mMaxTransferRate) + .setScrollValues(1000, 144, 100000) + .setFocusOnGuiOpen(true) + .setPos(startX + spaceX * 0, startY + spaceY * 1 + 8) + .setSize(spaceX * 4 - 3, 12))) + .widget( + new TextWidget(GT_Utility.trans("322", "Overflow point: ")).setDefaultColor(COLOR_TEXT_GRAY.get()) + .setPos(startX, 4 + startY + spaceY * 0 + 8)); + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/covers/GTPP_Cover_ToggleVisual.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/covers/GTPP_Cover_ToggleVisual.java new file mode 100644 index 0000000000..42ab793c9c --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/covers/GTPP_Cover_ToggleVisual.java @@ -0,0 +1,184 @@ +package gtPlusPlus.xmod.gregtech.common.covers; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; + +import gregtech.api.interfaces.tileentity.ICoverable; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.objects.XSTR; +import gregtech.api.util.GT_CoverBehavior; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.ISerializableObject; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.util.minecraft.PlayerUtils; + +public class GTPP_Cover_ToggleVisual extends GT_CoverBehavior { + + private static final Map<String, Integer> sConnectionStateForEntityMap = new ConcurrentHashMap<>(); + private static final Map<String, String> sPrefixMap = new ConcurrentHashMap<>(); + private static final int VALUE_OFF = 0; + private static final int VALUE_ON = 1; + + public static String generateUniqueKey(ForgeDirection side, ICoverable aEntity) { + try { + BlockPos aPos = new BlockPos( + aEntity.getIGregTechTileEntity(aEntity.getXCoord(), aEntity.getYCoord(), aEntity.getZCoord())); + + String s = aEntity.getInventoryName() + "." + aPos.getUniqueIdentifier() + side.name(); + return s; + } catch (Throwable t) {} + XSTR x = new XSTR(); + return "ERROR." + x.getSeed() + x.hashCode() + x.nextDouble() + ".ID"; + } + + public boolean onCoverRightclick(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity, + EntityPlayer aPlayer, float aX, float aY, float aZ) { + PlayerUtils + .messagePlayer(aPlayer, GT_Utility.trans("756", "Connectable: ") + getConnectionState(aCoverVariable)); + return super.onCoverRightclick(side, aCoverID, aCoverVariable, aTileEntity, aPlayer, aX, aY, aZ); + } + + public int onCoverScrewdriverclick(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity, + EntityPlayer aPlayer, float aX, float aY, float aZ) { + return super.onCoverScrewdriverclick(side, aCoverID, aCoverVariable, aTileEntity, aPlayer, aX, aY, aZ); + } + + public boolean letsEnergyIn(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return getConnectionState(aCoverVariable); + } + + public boolean letsEnergyOut(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return getConnectionState(aCoverVariable); + } + + public boolean letsFluidIn(ForgeDirection side, int aCoverID, int aCoverVariable, Fluid aFluid, + ICoverable aTileEntity) { + return getConnectionState(aCoverVariable); + } + + public boolean letsFluidOut(ForgeDirection side, int aCoverID, int aCoverVariable, Fluid aFluid, + ICoverable aTileEntity) { + return getConnectionState(aCoverVariable); + } + + public boolean letsItemsIn(ForgeDirection side, int aCoverID, int aCoverVariable, int aSlot, + ICoverable aTileEntity) { + return getConnectionState(aCoverVariable); + } + + public boolean letsItemsOut(ForgeDirection side, int aCoverID, int aCoverVariable, int aSlot, + ICoverable aTileEntity) { + return getConnectionState(aCoverVariable); + } + + public int getTickRate(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return 1; + } + + @Override + public int doCoverThings(ForgeDirection side, byte aInputRedstone, int aCoverID, int aCoverVariable, + ICoverable aTileEntity, long aTimer) { + try { + String aKey = generateUniqueKey(side, aTileEntity); + Integer b = sConnectionStateForEntityMap.get(aKey); + // Logger.INFO("Val: "+aCoverVariable); + if (b != null && aCoverVariable != b) { + aCoverVariable = b; + } + if (b == null) { + b = aCoverVariable; + sConnectionStateForEntityMap.put(aKey, b); + trySetState(side, b == VALUE_ON ? VALUE_ON : VALUE_OFF, aTileEntity); + } + } catch (Throwable t) { + + } + return aCoverVariable; + } + + @Override + public boolean letsRedstoneGoIn(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return getConnectionState(aCoverVariable); + } + + @Override + public boolean letsRedstoneGoOut(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return getConnectionState(aCoverVariable); + } + + @Override + public boolean alwaysLookConnected(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { + return super.alwaysLookConnected(side, aCoverID, aCoverVariable, aTileEntity); + } + + @Override + public byte getRedstoneInput(ForgeDirection side, byte aInputRedstone, int aCoverID, int aCoverVariable, + ICoverable aTileEntity) { + if (!getConnectionState(aCoverVariable)) { + return 0; + } + return super.getRedstoneInput(side, aInputRedstone, aCoverID, aCoverVariable, aTileEntity); + } + + @Override + public void placeCover(ForgeDirection side, ItemStack aCover, ICoverable aTileEntity) { + String aKey = generateUniqueKey(side, aTileEntity); + boolean state = getCoverConnections(aCover); + sPrefixMap.put(aKey, aCover.getUnlocalizedName()); + Logger.INFO("Mapping key " + aKey + " to " + state); + sConnectionStateForEntityMap.put(aKey, state ? VALUE_ON : VALUE_OFF); + Logger.INFO("Key Value: " + (state ? VALUE_ON : VALUE_OFF)); + // Try set cover state directly + // trySetState(aSide, state ? VALUE_ON : VALUE_OFF, aTileEntity); + super.placeCover(side, aCover, aTileEntity); + } + + @Override + public boolean onCoverRemoval(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity, + boolean aForced) { + String aKey = generateUniqueKey(side, aTileEntity); + sConnectionStateForEntityMap.remove(aKey); + // Logger.INFO("Unmapping key "+aKey+"."); + return true; + } + + public static boolean getConnectionState(int aCoverVar) { + return aCoverVar == VALUE_ON; + } + + private static void trySetState(ForgeDirection side, int aState, ICoverable aTile) { + // Try set cover state directly + if (aTile instanceof IGregTechTileEntity gTileEntity) { + gTileEntity.setCoverDataAtSide(side, new ISerializableObject.LegacyCoverData(aState)); + } + } + + public static boolean getConnectionState(ForgeDirection side, ICoverable aTile) { + String aKey = generateUniqueKey(side, aTile); + return getConnectionState(aKey); + } + + public static boolean getConnectionState(String aKey) { + Integer b = sConnectionStateForEntityMap.get(aKey); + // Logger.INFO("Get State: "+b+" | "+aKey); + return b != null ? b == VALUE_ON : false; + } + + public static final boolean getCoverConnections(final ItemStack aStack) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("CustomCoverMeta"); + if (aNBT != null) { + return aNBT.getBoolean("AllowConnections"); + } + } + return false; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/ChargingHelper.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/ChargingHelper.java new file mode 100644 index 0000000000..924484e098 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/ChargingHelper.java @@ -0,0 +1,346 @@ +package gtPlusPlus.xmod.gregtech.common.helpers; + +import static gregtech.api.GregTech_API.mEUtoRF; +import static gregtech.api.enums.Mods.Baubles; +import static gregtech.api.enums.Mods.COFHCore; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import javax.annotation.Nonnull; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +import baubles.api.BaublesApi; +import cofh.api.energy.IEnergyContainerItem; +import cpw.mods.fml.common.eventhandler.EventPriority; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.TickEvent.ServerTickEvent; +import gregtech.api.enums.GT_Values; +import gregtech.api.util.GT_ModHandler; +import gregtech.common.items.GT_MetaGenerated_Item_01; +import gregtech.common.items.GT_MetaGenerated_Item_02; +import gregtech.common.items.GT_MetaGenerated_Item_03; +import gregtech.common.items.GT_MetaGenerated_Tool_01; +import gtPlusPlus.api.objects.data.Pair; +import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.NBTUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic.GregtechMetaWirelessCharger; +import ic2.api.item.ElectricItem; +import ic2.api.item.IElectricItem; + +public class ChargingHelper { + + private static final Map<String, Pair<GregtechMetaWirelessCharger, Byte>> mValidPlayers = new HashMap<>(); + protected static Map<BlockPos, GregtechMetaWirelessCharger> mChargerMap = new HashMap<>(); + private int mTickTimer = 0; + private static final int mTickMultiplier = 20; + + @SubscribeEvent(priority = EventPriority.HIGHEST) + public void onServerTick(ServerTickEvent event) { + if (++mTickTimer % mTickMultiplier == 0) { + if (Utils.isServer()) { + for (EntityPlayer mPlayerMan : PlayerUtils.getOnlinePlayers()) { + doPlayerChargeTick(mPlayerMan); + } + } + } + } + + @SuppressWarnings("unused") + private void doPlayerChargeTick(EntityPlayer mPlayerMan) { + try { + long mVoltage; + long mEuStored; + + if (!mChargerMap.isEmpty() && mValidPlayers.containsKey(mPlayerMan.getDisplayName())) { + InventoryPlayer mPlayerInventory = mPlayerMan.inventory; + ItemStack[] mArmourContents = mPlayerInventory.armorInventory.clone(); + ItemStack[] mInventoryContents = mPlayerInventory.mainInventory.clone(); + ItemStack[] baubleSlots = null; + if (Baubles.isModLoaded()) { + IInventory baubleInv = BaublesApi.getBaubles(mPlayerMan); + if (baubleInv != null) { + baubleSlots = new ItemStack[baubleInv.getSizeInventory()]; + for (int i = 0; i < baubleInv.getSizeInventory(); i++) { + baubleSlots[i] = baubleInv.getStackInSlot(i); + } + } + } + + for (GregtechMetaWirelessCharger mEntityTemp : mChargerMap.values()) { + if (mEntityTemp != null) { + if (mEntityTemp.getBaseMetaTileEntity() == null || !mEntityTemp.getBaseMetaTileEntity() + .isAllowedToWork()) continue; + if (mPlayerMan.getEntityWorld().provider.dimensionId == mEntityTemp.getDimensionID()) { + mVoltage = mEntityTemp.maxEUInput(); + mEuStored = mEntityTemp.getEUVar(); + if (mVoltage > 0 && mEuStored >= mVoltage) { + Map<String, UUID> LR = mEntityTemp.getLongRangeMap(); + Map<String, UUID> LO = mEntityTemp.getLocalMap(); + + long mStartingEu = mEntityTemp.getEUVar(); + if (canCharge(mEntityTemp, mPlayerMan, LR, LO)) { + chargeItems(mEntityTemp, mArmourContents); + chargeItems(mEntityTemp, mInventoryContents); + chargeItems(mEntityTemp, baubleSlots); + } + + if (mStartingEu - mEntityTemp.getEUVar() <= 0) { + long mMaxDistance; + if (mEntityTemp.getMode() == 0) { + mMaxDistance = (4 * GT_Values.V[mEntityTemp.getTier()]); + } else if (mEntityTemp.getMode() == 1) { + mMaxDistance = (mEntityTemp.getTier() * 10L); + } else { + mMaxDistance = (4 * GT_Values.V[mEntityTemp.getTier()] / 2); + } + double mDistance = calculateDistance(mEntityTemp, mPlayerMan); + long mVoltageCost = MathUtils.findPercentageOfInt(mMaxDistance, (float) mDistance); + + if (mVoltageCost > 0) { + if (mVoltageCost > mEntityTemp.maxEUInput()) { + mEntityTemp.setEUVar((mEntityTemp.getEUVar() - mEntityTemp.maxEUInput())); + } else { + mEntityTemp.setEUVar((mEntityTemp.getEUVar() - mVoltageCost)); + } + } + } + } + } + } + } + } + } catch (Throwable t) { + if (!mChargerMap.isEmpty()) { + for (BlockPos aPos : mChargerMap.keySet()) { + GregtechMetaWirelessCharger r = mChargerMap.get(aPos); + if (r == null || r.getBaseMetaTileEntity() + .isInvalidTileEntity()) { + mChargerMap.remove(aPos); + } + } + } + } + } + + public static GregtechMetaWirelessCharger getEntry(BlockPos mPos) { + return mChargerMap.get(mPos); + } + + public static boolean addEntry(BlockPos mPos, GregtechMetaWirelessCharger mEntity) { + if (mEntity == null) { + return false; + } + mChargerMap.put(mPos, mEntity); + return true; + } + + public static boolean removeEntry(BlockPos mPos, GregtechMetaWirelessCharger mEntity) { + if (mEntity == null) { + return false; + } + if (mChargerMap.containsKey(mPos)) { + return mChargerMap.remove(mPos, mEntity); + } else { + return false; + } + } + + public static boolean addValidPlayer(EntityPlayer mPlayer, GregtechMetaWirelessCharger mEntity) { + if (mEntity == null) { + return false; + } + if (mValidPlayers.containsKey(mPlayer.getDisplayName())) { + return false; + } else { + Pair<GregtechMetaWirelessCharger, Byte> mEntry = new Pair<>(mEntity, (byte) mEntity.getMode()); + return mValidPlayers.put(mPlayer.getDisplayName(), mEntry) == null; + } + } + + public static boolean removeValidPlayer(EntityPlayer mPlayer, GregtechMetaWirelessCharger mEntity) { + if (mEntity == null) { + return false; + } + if (mValidPlayers.containsKey(mPlayer.getDisplayName())) { + Pair<GregtechMetaWirelessCharger, Byte> mEntry = new Pair<>(mEntity, (byte) mEntity.getMode()); + return mValidPlayers.remove(mPlayer.getDisplayName(), mEntry); + } else { + return false; + } + } + + private boolean canCharge(GregtechMetaWirelessCharger charger, EntityPlayer chargeablePlayer, + Map<String, UUID> longRangeChargers, Map<String, UUID> shortRangeChargers) { + if (charger.getMode() == 0) { + return !longRangeChargers.isEmpty() && longRangeChargers.containsKey(chargeablePlayer.getDisplayName()); + } else if (charger.getMode() == 1) { + return !shortRangeChargers.isEmpty() && shortRangeChargers.containsKey(chargeablePlayer.getDisplayName()); + } else { + if (!longRangeChargers.isEmpty() && longRangeChargers.containsKey(chargeablePlayer.getDisplayName())) { + return true; + } + return !shortRangeChargers.isEmpty() && shortRangeChargers.containsKey(chargeablePlayer.getDisplayName()); + } + } + + private double calculateDistance(GregtechMetaWirelessCharger mEntityTemp, EntityPlayer mPlayerMan) { + if (mEntityTemp == null || mPlayerMan == null) { + return 0; + } + return mEntityTemp.getDistanceBetweenTwoPositions( + mEntityTemp.getTileEntityPosition(), + mEntityTemp.getPositionOfEntity(mPlayerMan)); + } + + private void chargeItems(@Nonnull GregtechMetaWirelessCharger mEntity, ItemStack[] mItems) { + if (mItems == null || mItems.length == 0) { + return; + } + chargeItemsEx(mEntity, mItems); + } + + private void chargeItemsEx(@Nonnull GregtechMetaWirelessCharger mEntity, ItemStack[] mItems) { + // Bad Inventory + if (mItems == null || mItems.length == 0) { + return; + } + // Set Variables to Charge + final long mVoltage = mEntity.maxEUInput(); + long mEuStored = mEntity.getEUVar(); + // For Inventory Contents + + for (ItemStack mTemp : mItems) { + // Is item Electrical + if (isItemValid(mTemp)) { + // Transfer Limit + double mItemEuTLimit = ((IElectricItem) mTemp.getItem()).getTransferLimit(mTemp); + // Check if Tile has more or equal EU to what can be transferred into the item. + if (mEuStored >= mItemEuTLimit) { + + double mItemMaxCharge = ((IElectricItem) mTemp.getItem()).getMaxCharge(mTemp); + double mitemCurrentCharge = ElectricItem.manager.getCharge(mTemp); + + if (mitemCurrentCharge >= mItemMaxCharge) { + continue; + } + + // Try to get charge direct from NBT for GT and IC2 stacks + if (mTemp.getItem() instanceof GT_MetaGenerated_Tool_01 + || mTemp.getItem() instanceof GT_MetaGenerated_Item_01 + || mTemp.getItem() instanceof GT_MetaGenerated_Item_02 + || mTemp.getItem() instanceof GT_MetaGenerated_Item_03 + || mTemp.getItem() + .getClass() + .getName() + .equalsIgnoreCase(GT_MetaGenerated_Tool_01.class.getName())) { + if (!NBTUtils.hasKey(mTemp, "GT.ItemCharge")) { + if (!mTemp.getDisplayName() + .toLowerCase() + .contains("battery")) { + if (!GT_ModHandler.isElectricItem(mTemp)) { + continue; + } + } else { + mitemCurrentCharge = 0; + } + } else { + mitemCurrentCharge = NBTUtils.getLong(mTemp, "GT.ItemCharge"); + } + } else if (mTemp.getItem() instanceof IElectricItem) { + mitemCurrentCharge = NBTUtils.getLong(mTemp, "charge"); + } + + double mVoltageIncrease; + if (mItemEuTLimit >= mVoltage) { + mVoltageIncrease = mVoltage; + } else if (mItemEuTLimit < mVoltage) { + mVoltageIncrease = mItemEuTLimit; + } else { + mVoltageIncrease = mItemEuTLimit; + } + + int mMulti; + if ((mitemCurrentCharge + (mVoltageIncrease * 20)) <= (mItemMaxCharge - (mVoltageIncrease * 20))) { + mMulti = 20; + } else if ((mitemCurrentCharge + (mVoltageIncrease * 10)) + <= (mItemMaxCharge - (mVoltageIncrease * 10))) { + mMulti = 10; + } else if ((mitemCurrentCharge + (mVoltageIncrease * 5)) + <= (mItemMaxCharge - (mVoltageIncrease * 5))) { + mMulti = 5; + } else { + mMulti = 1; + } + + int mMultiVoltage = (int) (mMulti * mVoltageIncrease); + + if ((mitemCurrentCharge + mMultiVoltage) <= mItemMaxCharge) { + if (GT_ModHandler.chargeElectricItem(mTemp, mMultiVoltage, Integer.MAX_VALUE, true, false) + > 0) { + for (int i = 0; i < mMulti; i++) { + ElectricItem.manager.charge(mTemp, mVoltageIncrease, Integer.MAX_VALUE, false, false); + } + } + if (ElectricItem.manager.getCharge(mTemp) > mitemCurrentCharge) { + mEntity.setEUVar(mEuStored - (mVoltage * mMulti)); + mEuStored = mEntity.getEUVar(); + } + } + + // Try top up Item Chrage + mitemCurrentCharge = ElectricItem.manager.getCharge(mTemp); + if (mitemCurrentCharge < mItemMaxCharge && mitemCurrentCharge >= (mItemMaxCharge - mVoltage)) { + int xDif = (int) (mItemMaxCharge - mitemCurrentCharge); + if (GT_ModHandler.chargeElectricItem(mTemp, xDif, Integer.MAX_VALUE, true, false) >= 0) { + if (ElectricItem.manager.getCharge(mTemp) >= mItemMaxCharge) { + mEntity.setEUVar(mEntity.getEUVar() - (xDif)); + mEuStored = mEntity.getEUVar(); + } + } + } + } + } else if (isItemValidRF(mTemp)) { + try { + IEnergyContainerItem rfItem = (IEnergyContainerItem) mTemp.getItem(); + if (rfItem != null) { + long chargedPower = Math.min( + rfItem.getMaxEnergyStored(mTemp) - rfItem.getEnergyStored(mTemp), + mEntity.getEUVar() * mEUtoRF / 100L); + chargedPower = rfItem.receiveEnergy( + mTemp, + chargedPower > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) chargedPower, + false); + chargedPower = chargedPower * 100L / mEUtoRF; + mEntity.setEUVar(Math.max(mEntity.getEUVar() - chargedPower, 0)); + mEuStored = mEntity.getEUVar(); + } + } catch (Exception ignored) { + + } + } + } + } + + public static boolean isItemValid(final ItemStack itemstack) { + if (itemstack == null) { + return false; + } + if (GT_ModHandler.isElectricItem(itemstack)) { + return true; + } + return itemstack.getItem() instanceof IElectricItem; + } + + private static boolean isItemValidRF(final ItemStack itemStack) { + return itemStack != null && COFHCore.isModLoaded() && itemStack.getItem() instanceof IEnergyContainerItem; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/FlotationRecipeHandler.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/FlotationRecipeHandler.java new file mode 100644 index 0000000000..8cbb473a42 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/FlotationRecipeHandler.java @@ -0,0 +1,62 @@ +package gtPlusPlus.xmod.gregtech.common.helpers; + +import java.util.HashMap; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; + +import gregtech.api.enums.OrePrefixes; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.material.Material; + +public class FlotationRecipeHandler { + + private static final HashMap<String, Material> sMaterialMap = new HashMap<>(); + private static final HashMap<String, ItemStack> sMilledMap = new HashMap<>(); + + public static boolean registerOreType(Material aMaterial) { + String aMaterialKey = aMaterial.getUnlocalizedName(); + if (sMaterialMap.containsKey(aMaterialKey)) { + Logger.WARNING("Tried to register a Flotation material already in use. Material: " + aMaterialKey); + return false; + } else { + sMaterialMap.put(aMaterialKey, aMaterial); + sMilledMap.put(aMaterialKey, aMaterial.getMilled(1)); + } + return true; + } + + public static Material getMaterialOfMilledProduct(ItemStack aMilled) { + for (String aKey : sMilledMap.keySet()) { + ItemStack aTempMilledStack = sMilledMap.get(aKey); + if (GT_Utility.areStacksEqual(aTempMilledStack, aMilled, true)) { + return sMaterialMap.get(aKey); + } + } + return null; + } + + public static ItemStack findMilledStack(GT_Recipe aRecipe) { + if (aRecipe == null || aRecipe.mInputs == null || aRecipe.mInputs.length <= 0) { + return null; + } + return findMilledStack(aRecipe.mInputs); + } + + public static ItemStack findMilledStack(ItemStack[] aInputs) { + if (aInputs == null || aInputs.length <= 0) { + return null; + } + for (ItemStack aStack : aInputs) { + for (int oredictID : OreDictionary.getOreIDs(aStack)) { + String oredict = OreDictionary.getOreName(oredictID); + if (oredict.startsWith(OrePrefixes.milled.toString())) { + return aStack; + } + } + } + return null; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/GT_MethodHelper.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/GT_MethodHelper.java new file mode 100644 index 0000000000..ced9b46c3e --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/GT_MethodHelper.java @@ -0,0 +1,19 @@ +package gtPlusPlus.xmod.gregtech.common.helpers; + +import net.minecraft.block.Block; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.enums.Textures.BlockIcons; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.ITexturedTileEntity; + +public class GT_MethodHelper { + + public static ITexture[] getTexture(TileEntity tTileEntity, Block aBlock, ForgeDirection side) { + if (tTileEntity instanceof ITexturedTileEntity) { + return ((ITexturedTileEntity) tTileEntity).getTexture(aBlock, side); + } + return BlockIcons.ERROR_RENDERING; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/VolumetricFlaskHelper.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/VolumetricFlaskHelper.java new file mode 100644 index 0000000000..2b0e2a7a4d --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/VolumetricFlaskHelper.java @@ -0,0 +1,125 @@ +package gtPlusPlus.xmod.gregtech.common.helpers; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.FluidStack; + +import gregtech.api.enums.ItemList; +import gregtech.common.items.GT_VolumetricFlask; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; + +public class VolumetricFlaskHelper { + + public static ItemStack getVolumetricFlask(int aAmount) { + return ItemList.VOLUMETRIC_FLASK.get(aAmount); + } + + public static ItemStack getLargeVolumetricFlask(int aAmount) { + return GregtechItemList.VOLUMETRIC_FLASK_8k.get(aAmount); + } + + public static ItemStack getGiganticVolumetricFlask(int aAmount) { + return GregtechItemList.VOLUMETRIC_FLASK_32k.get(aAmount); + } + + public static boolean isVolumetricFlask(ItemStack aStack) { + return isNormalVolumetricFlask(aStack) || isLargeVolumetricFlask(aStack) || isGiganticVolumetricFlask(aStack); + } + + public static boolean isNormalVolumetricFlask(ItemStack aStack) { + return aStack.getItem() == ItemList.VOLUMETRIC_FLASK.getItem(); + } + + public static boolean isLargeVolumetricFlask(ItemStack aStack) { + return GregtechItemList.VOLUMETRIC_FLASK_8k.getItem() == aStack.getItem(); + } + + public static boolean isGiganticVolumetricFlask(ItemStack aStack) { + return GregtechItemList.VOLUMETRIC_FLASK_32k.getItem() == aStack.getItem(); + } + + public static int getMaxFlaskCapacity(ItemStack aStack) { + if (aStack != null) { + Item aItem = aStack.getItem(); + if (aItem instanceof GT_VolumetricFlask) { + return ((GT_VolumetricFlask) aItem).getMaxCapacity(); + } + } + return 0; + } + + public static boolean isFlaskEmpty(ItemStack aStack) { + return getFlaskFluid(aStack) == null; + } + + public static FluidStack getFlaskFluid(ItemStack aStack) { + if (aStack.hasTagCompound()) { + NBTTagCompound nbt = aStack.getTagCompound(); + if (nbt.hasKey("Fluid", 10)) return FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag("Fluid")); + } + return null; + } + + public static void setFluid(ItemStack stack, FluidStack fluidStack) { + boolean removeFluid = (fluidStack == null) || (fluidStack.amount <= 0); + NBTTagCompound nbt = stack.getTagCompound(); + if (nbt == null) { + if (removeFluid) return; + stack.setTagCompound(nbt = new NBTTagCompound()); + } + if (removeFluid) { + nbt.removeTag("Fluid"); + if (nbt.hasNoTags()) { + stack.setTagCompound(null); + } + } else { + nbt.setTag("Fluid", fluidStack.writeToNBT(new NBTTagCompound())); + } + } + + public static int getFlaskCapacity(ItemStack aStack) { + int capacity = 1000; + if (aStack.hasTagCompound()) { + NBTTagCompound nbt = aStack.getTagCompound(); + if (nbt.hasKey("Capacity", 3)) capacity = nbt.getInteger("Capacity"); + } + return Math.min(getMaxFlaskCapacity(aStack), capacity); + } + + public static boolean setNewFlaskCapacity(ItemStack aStack, int aCapacity) { + if (aStack == null || aCapacity <= 0) { + return false; + } + aCapacity = Math.min(aCapacity, getMaxFlaskCapacity(aStack)); + NBTTagCompound nbt = aStack.getTagCompound(); + if (nbt == null) { + aStack.setTagCompound(nbt = new NBTTagCompound()); + } + nbt.setInteger("Capacity", aCapacity); + return true; + } + + public static int fillFlask(ItemStack stack, FluidStack resource, boolean doFill) { + if (stack.stackSize != 1) return 0; + if ((resource == null) || (resource.amount <= 0)) { + return 0; + } + FluidStack fluidStack = getFlaskFluid(stack); + if (fluidStack == null) { + fluidStack = new FluidStack(resource, 0); + } else if (!fluidStack.isFluidEqual(resource)) { + return 0; + } + int amount = Math.min(getMaxFlaskCapacity(stack) - fluidStack.amount, resource.amount); + if ((doFill) && (amount > 0)) { + fluidStack.amount += amount; + setFluid(stack, fluidStack); + } + return amount; + } + + public static Item generateNewFlask(String unlocalized, String english, int maxCapacity) { + return new GT_VolumetricFlask(unlocalized, english, maxCapacity); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/tesseract/TesseractHelper.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/tesseract/TesseractHelper.java new file mode 100644 index 0000000000..3717f17554 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/helpers/tesseract/TesseractHelper.java @@ -0,0 +1,256 @@ +package gtPlusPlus.xmod.gregtech.common.helpers.tesseract; + +import static gtPlusPlus.core.lib.CORE.sTesseractGeneratorOwnershipMap; +import static gtPlusPlus.core.lib.CORE.sTesseractTerminalOwnershipMap; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.UUID; + +import net.minecraft.entity.player.EntityPlayer; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.xmod.gregtech.common.tileentities.automation.GT_MetaTileEntity_TesseractGenerator; +import gtPlusPlus.xmod.gregtech.common.tileentities.automation.GT_MetaTileEntity_TesseractTerminal; + +public class TesseractHelper { + + /** + * Tesseract Generator Helpers + * + * @param player + * @return + */ + + // Checks if a Generator is owned by a player. + public static final boolean isGeneratorOwnedByPlayer(EntityPlayer player, + GT_MetaTileEntity_TesseractGenerator generator) { + if (player == null) { + Logger.WARNING("Failed. [isGeneratorOwnedByPlayer]"); + return false; + } + // Utils.LOG_WARNING("Success. [isGeneratorOwnedByPlayer] 1"); + UUID playerIdentifier = player.getUniqueID(); + if (!sTesseractGeneratorOwnershipMap.isEmpty() && playerIdentifier != null) { + // Utils.LOG_WARNING("Success. [isGeneratorOwnedByPlayer] 2"); + Map<Integer, GT_MetaTileEntity_TesseractGenerator> generators = getGeneratorOwnershipByPlayer(player); + Set<Entry<Integer, GT_MetaTileEntity_TesseractGenerator>> players = generators.entrySet(); + for (Entry<Integer, GT_MetaTileEntity_TesseractGenerator> current : players) { + // Utils.LOG_WARNING("Success. [isGeneratorOwnedByPlayer] 3"); + if (current.getValue() + .equals(generator)) { + // Utils.LOG_WARNING("Success. [isGeneratorOwnedByPlayer] 4"); + return true; + } + } + } + Logger.WARNING("Failed. [isGeneratorOwnedByPlayer]"); + return false; + } + + // Saves A Generator to the Players UUID map along with the Freq. + public static final boolean setGeneratorOwnershipByPlayer(EntityPlayer player, int freq, + GT_MetaTileEntity_TesseractGenerator generator) { + if (player == null) { + return false; + } + UUID playerIdentifier = player.getUniqueID(); + Logger.WARNING("Setting Generator on " + freq + " for " + player.getDisplayName() + "."); + if (playerIdentifier != null) { + Map<Integer, GT_MetaTileEntity_TesseractGenerator> playerOwned = sTesseractGeneratorOwnershipMap + .get(playerIdentifier); + if (playerOwned == null || playerOwned.isEmpty()) { + Map<Integer, GT_MetaTileEntity_TesseractGenerator> newOwnershipMap = new HashMap<>(); + newOwnershipMap.put(freq, generator); + sTesseractGeneratorOwnershipMap.put(playerIdentifier, newOwnershipMap); + Logger.WARNING("Success! [Empty Map]"); + return true; + } else if (sTesseractGeneratorOwnershipMap.containsKey(playerIdentifier)) { + Map<Integer, GT_MetaTileEntity_TesseractGenerator> ownershipMap = sTesseractGeneratorOwnershipMap + .get(playerIdentifier); + if (!ownershipMap.containsKey(freq)) { + ownershipMap.put(freq, generator); + } + ownershipMap.put(freq, generator); + sTesseractGeneratorOwnershipMap.put(playerIdentifier, ownershipMap); + Logger.WARNING("Success!"); + return true; + } + } + Logger.WARNING("Failed. [setGeneratorOwnershipByPlayer]"); + return false; + } + + // Gets Generator based on Frequency. + public static final GT_MetaTileEntity_TesseractGenerator getGeneratorByFrequency(EntityPlayer player, int freq) { + if (player == null) { + return null; + } + UUID playerIdentifier = player.getUniqueID(); + Logger.WARNING("Getting Generator on " + freq + " for " + player.getDisplayName() + "."); + if (!sTesseractGeneratorOwnershipMap.isEmpty() && playerIdentifier != null) { + // Utils.LOG_WARNING("Success. [getGeneratorByFrequency] 1"); + Map<Integer, GT_MetaTileEntity_TesseractGenerator> generators = getGeneratorOwnershipByPlayer(player); + Set<Entry<Integer, GT_MetaTileEntity_TesseractGenerator>> players = generators.entrySet(); + for (Entry<Integer, GT_MetaTileEntity_TesseractGenerator> current : players) { + // Utils.LOG_WARNING("Success. [getGeneratorByFrequency] 2"); + if (current.getKey() + .equals(freq)) { + // Utils.LOG_WARNING("Success. [getGeneratorByFrequency] 3"); + Logger.WARNING("Success!"); + return current.getValue(); + } + } + } + Logger.WARNING("Failed. [getGeneratorByFrequency]"); + return null; + } + + // Remove Tesseract Generator + public static final boolean removeGenerator(EntityPlayer player, int frequency) { + if (player == null) { + return false; + } + UUID playerIdentifier = player.getUniqueID(); + if (!sTesseractGeneratorOwnershipMap.isEmpty() && playerIdentifier != null) { + sTesseractGeneratorOwnershipMap.get(playerIdentifier) + .remove(frequency); + return true; + } + return false; + } + + /** + * + * Tesseract Terminal Helpers + * + * @param player + * @return + */ + + // Checks if a Terminal is owned by a player. + public static final boolean isTerminalOwnedByPlayer(EntityPlayer player, + GT_MetaTileEntity_TesseractTerminal generator) { + if (player == null) { + return false; + } + UUID playerIdentifier = player.getUniqueID(); + if (!sTesseractTerminalOwnershipMap.isEmpty() && playerIdentifier != null) { + Map<Integer, GT_MetaTileEntity_TesseractTerminal> generators = getTerminalOwnershipByPlayer(player); + Set<Entry<Integer, GT_MetaTileEntity_TesseractTerminal>> players = generators.entrySet(); + for (Entry<Integer, GT_MetaTileEntity_TesseractTerminal> current : players) { + if (current.getValue() + .equals(generator)) { + return true; + } + } + } + return false; + } + + // Saves A Terminal to the Players UUID map along with the Freq. + public static final boolean setTerminalOwnershipByPlayer(EntityPlayer player, int freq, + GT_MetaTileEntity_TesseractTerminal generator) { + if (player == null) { + return false; + } + UUID playerIdentifier = player.getUniqueID(); + if (playerIdentifier != null) { + Logger.WARNING("Setting Terminal on " + freq + " for " + player.getDisplayName() + "."); + Map<Integer, GT_MetaTileEntity_TesseractTerminal> playerOwned = sTesseractTerminalOwnershipMap + .get(playerIdentifier); + if (playerOwned == null || playerOwned.isEmpty()) { + Map<Integer, GT_MetaTileEntity_TesseractTerminal> newOwnershipMap = new HashMap<>(); + newOwnershipMap.put(freq, generator); + sTesseractTerminalOwnershipMap.put(playerIdentifier, newOwnershipMap); + Logger.WARNING("Success! [Empty Map]"); + return true; + } else if (sTesseractTerminalOwnershipMap.containsKey(playerIdentifier)) { + Map<Integer, GT_MetaTileEntity_TesseractTerminal> ownershipMap = sTesseractTerminalOwnershipMap + .get(playerIdentifier); + if (!ownershipMap.containsKey(freq)) { + ownershipMap.put(freq, generator); + } + sTesseractTerminalOwnershipMap.put(playerIdentifier, ownershipMap); + Logger.WARNING("Success!"); + return true; + } + } + Logger.WARNING("Failed. [setTerminalOwnershipByPlayer]"); + return false; + } + + // Gets Terminal based on Frequency. + public static final GT_MetaTileEntity_TesseractTerminal getTerminalByFrequency(EntityPlayer player, int freq) { + if (player == null) { + return null; + } + UUID playerIdentifier = player.getUniqueID(); + Logger.WARNING("Getting Terminal on " + freq + " for " + player.getDisplayName() + "."); + if (!sTesseractTerminalOwnershipMap.isEmpty() && playerIdentifier != null) { + Map<Integer, GT_MetaTileEntity_TesseractTerminal> generators = getTerminalOwnershipByPlayer(player); + Set<Entry<Integer, GT_MetaTileEntity_TesseractTerminal>> players = generators.entrySet(); + for (Entry<Integer, GT_MetaTileEntity_TesseractTerminal> current : players) { + if (current.getKey() + .equals(freq)) { + Logger.WARNING("Success!"); + return current.getValue(); + } + } + } + Logger.WARNING("Failed. [getTerminalByFrequency]"); + return null; + } + + // Remove Tesseract Terminal + public static final boolean removeTerminal(EntityPlayer player, int frequency) { + if (player == null) { + return false; + } + UUID playerIdentifier = player.getUniqueID(); + if (!sTesseractTerminalOwnershipMap.isEmpty() && playerIdentifier != null) { + sTesseractTerminalOwnershipMap.get(playerIdentifier) + .remove(frequency); + return true; + } + return false; + } + + /** + * + * Internal Methods + * + */ + private static Map<Integer, GT_MetaTileEntity_TesseractGenerator> getGeneratorOwnershipByPlayer( + EntityPlayer player) { + UUID playerIdentifier = player.getUniqueID(); + if (!sTesseractGeneratorOwnershipMap.isEmpty() && playerIdentifier != null) { + Set<Entry<UUID, Map<Integer, GT_MetaTileEntity_TesseractGenerator>>> players = sTesseractGeneratorOwnershipMap + .entrySet(); + for (Entry<UUID, Map<Integer, GT_MetaTileEntity_TesseractGenerator>> current : players) { + if (current.getKey() + .compareTo(playerIdentifier) == 0) { + return current.getValue(); + } + } + } + return null; + } + + private static Map<Integer, GT_MetaTileEntity_TesseractTerminal> getTerminalOwnershipByPlayer(EntityPlayer player) { + UUID playerIdentifier = player.getUniqueID(); + if (!sTesseractTerminalOwnershipMap.isEmpty() && playerIdentifier != null) { + Set<Entry<UUID, Map<Integer, GT_MetaTileEntity_TesseractTerminal>>> players = sTesseractTerminalOwnershipMap + .entrySet(); + for (Entry<UUID, Map<Integer, GT_MetaTileEntity_TesseractTerminal>> current : players) { + if (current.getKey() + .compareTo(playerIdentifier) == 0) { + return current.getValue(); + } + } + } + return null; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/items/MetaCustomCoverItem.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/items/MetaCustomCoverItem.java new file mode 100644 index 0000000000..8edb8c2cf9 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/items/MetaCustomCoverItem.java @@ -0,0 +1,222 @@ +package gtPlusPlus.xmod.gregtech.common.items; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import java.util.List; + +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; + +import org.apache.commons.lang3.StringUtils; + +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.GregTech_API; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.ITexture; +import gregtech.api.objects.GT_MultiTexture; +import gregtech.api.objects.GT_RenderedTexture; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.sys.KeyboardUtils; +import gtPlusPlus.xmod.gregtech.common.covers.GTPP_Cover_ToggleVisual; + +public class MetaCustomCoverItem extends Item { + + protected final IIcon[] icons; + private final String mModID; + private final String mTextureSetName; + protected final IIconContainer[] mTextures; + private final short[][] mRGB; + + public MetaCustomCoverItem(String aModId, int aTextureCount, String aTextureSetName, IIconContainer[] aTextures, + short[][] aRGB) { + super(); + icons = new IIcon[aTextureCount]; + mModID = aModId; + mTextureSetName = Utils.sanitizeString(aTextureSetName); + mTextures = aTextures; + mRGB = aRGB; + this.setTextureName(GTPlusPlus.ID + ":" + "itemPlate"); + this.setHasSubtypes(true); + String unlocalizedName = "itemCustomMetaCover." + mModID + "." + mTextureSetName; + this.setUnlocalizedName(unlocalizedName); + this.setCreativeTab(AddToCreativeTab.tabMisc); + this.setMaxStackSize(1); + GameRegistry.registerItem(this, unlocalizedName); + registerCover(); + Logger.INFO( + "[Covers] Generated Custom covers for " + mModID + + " using " + + aTextureCount + + " textures from " + + mTextureSetName + + "."); + } + + public boolean hide() { + return true; + } + + private void registerCover() { + // CommonProxy.registerItemRendererGlobal(this, new CustomItemBlockRenderer()); + for (int i = 0; i < icons.length; i++) { + ItemStack thisStack = ItemUtils.simpleMetaStack(this, i, 1); + if (i > 0 && hide()) { + ItemUtils.hideItemFromNEI(thisStack); + } + GregTech_API.registerCover( + thisStack, + new GT_MultiTexture(new ITexture[] { new GT_RenderedTexture(mTextures[i]) }), + new GTPP_Cover_ToggleVisual()); + } + } + + /* + * @Override public void registerIcons(IIconRegister reg) { for (int i = 0; i < icons.length; i++) { this.icons[i] = + * mTextures[i].getIcon(); } } + * @Override public IIcon getIconFromDamage(int meta) { return this.icons[meta]; } + */ + + @Override + public void getSubItems(Item item, CreativeTabs tab, List list) { + for (int i = 0; i < icons.length; i++) { + list.add(new ItemStack(item, 1, i)); + } + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + return this.getUnlocalizedName() + "_" + stack.getItemDamage(); + } + + @Override + public String getItemStackDisplayName(final ItemStack tItem) { + return StringUtils.capitalize(mTextureSetName) + " (" + tItem.getItemDamage() + ")"; // super.getItemStackDisplayName(tItem); + } + + private static boolean createNBT(ItemStack rStack) { + final NBTTagCompound tagMain = new NBTTagCompound(); + final NBTTagCompound tagNBT = new NBTTagCompound(); + tagNBT.setLong("Damage", 0); + tagNBT.setBoolean("AllowConnections", false); + tagMain.setTag("CustomCoverMeta", tagNBT); + rStack.setTagCompound(tagMain); + return true; + } + + public static final long getCoverDamage(final ItemStack aStack) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("CustomCoverMeta"); + if (aNBT != null) { + return aNBT.getLong("Damage"); + } + } else { + createNBT(aStack); + } + return 0L; + } + + public static final boolean setCoverDamage(final ItemStack aStack, final long aDamage) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("CustomCoverMeta"); + if (aNBT != null) { + aNBT.setLong("Damage", aDamage); + return true; + } + } + return false; + } + + public static final boolean getCoverConnections(final ItemStack aStack) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("CustomCoverMeta"); + if (aNBT != null) { + return aNBT.getBoolean("AllowConnections"); + } + } else { + createNBT(aStack); + } + return false; + } + + public static final boolean setCoverConnections(final ItemStack aStack, final boolean aConnections) { + NBTTagCompound aNBT = aStack.getTagCompound(); + if (aNBT != null) { + aNBT = aNBT.getCompoundTag("CustomCoverMeta"); + if (aNBT != null) { + aNBT.setBoolean("AllowConnections", aConnections); + return true; + } + } + return false; + } + + @Override + public double getDurabilityForDisplay(ItemStack stack) { + if (stack.getTagCompound() == null) { + createNBT(stack); + } + double currentDamage = getCoverDamage(stack); + double meta = stack.getItemDamage() == 0 ? 50 : 2500; + double durabilitypercent = currentDamage / meta; + return durabilitypercent; + } + + @Override + public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { + if (KeyboardUtils.isShiftKeyDown()) { + boolean con = getCoverConnections(stack); + if (con) { + setCoverConnections(stack, false); + } else { + setCoverConnections(stack, true); + } + } + return stack; + } + + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) { + boolean cons = getCoverConnections(stack); + list.add(EnumChatFormatting.GRAY + "Allows Connections: " + cons); + list.add(EnumChatFormatting.GRAY + "Shift Rmb to change state before applying"); + super.addInformation(stack, player, list, bool); + } + + @Override + public boolean showDurabilityBar(ItemStack stack) { + return false; + } + + @Override + public Item setFull3D() { + // TODO Auto-generated method stub + return super.setFull3D(); + } + + @Override + public boolean isFull3D() { + // TODO Auto-generated method stub + return super.isFull3D(); + } + + @Override + public int getColorFromItemStack(final ItemStack stack, final int HEX_OxFFFFFF) { + if (this.mRGB == null) { + return super.getColorFromItemStack(stack, HEX_OxFFFFFF); + } + int aMeta = stack.getItemDamage(); + return Utils.rgbtoHexValue(mRGB[aMeta][0], mRGB[aMeta][1], mRGB[aMeta][2]); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/items/MetaGeneratedGregtechItems.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/items/MetaGeneratedGregtechItems.java new file mode 100644 index 0000000000..8173a868aa --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/items/MetaGeneratedGregtechItems.java @@ -0,0 +1,292 @@ +package gtPlusPlus.xmod.gregtech.common.items; + +import static gregtech.client.GT_TooltipHandler.Tier.EV; +import static gregtech.client.GT_TooltipHandler.registerTieredTooltip; +import static gtPlusPlus.core.util.Utils.getTcAspectStack; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.TC_Aspects; +import gregtech.api.enums.Textures; +import gregtech.api.objects.GT_MultiTexture; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_ModHandler; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.data.StringUtils; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import gtPlusPlus.xmod.gregtech.api.items.Gregtech_MetaItem_X32; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.common.covers.GTPP_Cover_Overflow; + +public class MetaGeneratedGregtechItems extends Gregtech_MetaItem_X32 { + + public static final MetaGeneratedGregtechItems INSTANCE; + + static { + INSTANCE = new MetaGeneratedGregtechItems(); + } + + public MetaGeneratedGregtechItems() { + super("MU-metaitem.01", new OrePrefixes[] { null }); + } + + public void generateMetaItems() { + int tLastID = 0; + + // Extruder Shape + GregtechItemList.Shape_Extruder_WindmillShaft + .set(this.addItem(40, "Extruder Shape (Shaft)", "Extruder Shape for making Windmill Shafts")); + + // Batteries + GregtechItemList.Battery_RE_EV_Sodium.set( + this.addItem( + tLastID = 50, + "Quad Cell Sodium Battery", + "Reusable", + getTcAspectStack(TC_Aspects.ELECTRUM, 2L), + getTcAspectStack(TC_Aspects.METALLUM, 2L), + getTcAspectStack(TC_Aspects.POTENTIA, 2L))); + this.setElectricStats(32000 + tLastID, 3200000L, GT_Values.V[4], 4L, -3L, true); + registerTieredTooltip(GregtechItemList.Battery_RE_EV_Sodium.get(1), EV); + + GregtechItemList.Battery_RE_EV_Cadmium.set( + this.addItem( + tLastID = 52, + "Quad Cell Cadmium Battery", + "Reusable", + getTcAspectStack(TC_Aspects.ELECTRUM, 1L), + getTcAspectStack(TC_Aspects.METALLUM, 1L), + getTcAspectStack(TC_Aspects.POTENTIA, 1L))); + this.setElectricStats(32000 + tLastID, 4800000L, GT_Values.V[4], 4L, -3L, true); + registerTieredTooltip(GregtechItemList.Battery_RE_EV_Cadmium.get(1), EV); + + GregtechItemList.Battery_RE_EV_Lithium.set( + this.addItem( + tLastID = 54, + "Quad Cell Lithium Battery", + "Reusable", + getTcAspectStack(TC_Aspects.ELECTRUM, 3L), + getTcAspectStack(TC_Aspects.METALLUM, 3L), + getTcAspectStack(TC_Aspects.POTENTIA, 3L))); + this.setElectricStats(32000 + tLastID, 6400000L, GT_Values.V[4], 4L, -3L, true); + registerTieredTooltip(GregtechItemList.Battery_RE_EV_Lithium.get(1), EV); + + /** + * Power Gems + */ + GregtechItemList.Battery_Gem_1.set( + this.addItem( + tLastID = 66, + "Proton Cell", + "Reusable", + getTcAspectStack(TC_Aspects.ELECTRUM, 8L), + getTcAspectStack(TC_Aspects.METALLUM, 24L), + getTcAspectStack(TC_Aspects.POTENTIA, 16L))); + this.setElectricStats(32000 + tLastID, GT_Values.V[6] * 20 * 300 / 4, GT_Values.V[6], 6L, -3L, false); + GregtechItemList.Battery_Gem_2.set( + this.addItem( + tLastID = 68, + "Electron Cell", + "Reusable", + getTcAspectStack(TC_Aspects.ELECTRUM, 16L), + getTcAspectStack(TC_Aspects.METALLUM, 32L), + getTcAspectStack(TC_Aspects.POTENTIA, 32L))); + this.setElectricStats(32000 + tLastID, GT_Values.V[7] * 20 * 300 / 4, GT_Values.V[7], 7L, -3L, false); + GregtechItemList.Battery_Gem_3.set( + this.addItem( + tLastID = 70, + "Quark Entanglement", + "Reusable", + getTcAspectStack(TC_Aspects.ELECTRUM, 32L), + getTcAspectStack(TC_Aspects.METALLUM, 48L), + getTcAspectStack(TC_Aspects.POTENTIA, 64L))); + this.setElectricStats(32000 + tLastID, GT_Values.V[8] * 20 * 300 / 4, GT_Values.V[8], 8L, -3L, false); + + // RTG Pellet + GregtechItemList.Pellet_RTG_PU238.set( + this.addItem( + 41, + StringUtils.superscript("238") + "Pu Pellet", + "", + getTcAspectStack(TC_Aspects.RADIO, 4L), + getTcAspectStack(TC_Aspects.POTENTIA, 2L), + getTcAspectStack(TC_Aspects.METALLUM, 2L))); + GregtechItemList.Pellet_RTG_SR90.set( + this.addItem( + 42, + StringUtils.superscript("90") + "Sr Pellet", + "", + getTcAspectStack(TC_Aspects.RADIO, 4L), + getTcAspectStack(TC_Aspects.POTENTIA, 2L), + getTcAspectStack(TC_Aspects.METALLUM, 2L))); + GregtechItemList.Pellet_RTG_PO210.set( + this.addItem( + 43, + StringUtils.superscript("210") + "Po Pellet", + "", + getTcAspectStack(TC_Aspects.RADIO, 4L), + getTcAspectStack(TC_Aspects.POTENTIA, 2L), + getTcAspectStack(TC_Aspects.METALLUM, 2L))); + GregtechItemList.Pellet_RTG_AM241.set( + this.addItem( + 44, + StringUtils.superscript("241") + "Am Pellet", + "", + getTcAspectStack(TC_Aspects.RADIO, 4L), + getTcAspectStack(TC_Aspects.POTENTIA, 2L), + getTcAspectStack(TC_Aspects.METALLUM, 2L))); + + CORE.RA.addFuelForRTG(GregtechItemList.Pellet_RTG_PU238.get(1), MathUtils.roundToClosestInt(87.7f), 64); + CORE.RA.addFuelForRTG(GregtechItemList.Pellet_RTG_SR90.get(1), MathUtils.roundToClosestInt(28.8f), 32); + CORE.RA.addFuelForRTG(GregtechItemList.Pellet_RTG_PO210.get(1), 1, 512); + CORE.RA.addFuelForRTG(GregtechItemList.Pellet_RTG_AM241.get(1), 216, 16); + CORE.RA.addFuelForRTG(GT_ModHandler.getIC2Item("RTGPellets", 1), MathUtils.roundToClosestInt(2.6f), 8); + + // Computer Cube + GregtechItemList.Gregtech_Computer_Cube.set( + this.addItem( + tLastID = 55, + "Gregtech Computer Cube", + "Reusable", + getTcAspectStack(TC_Aspects.ELECTRUM, 8L), + getTcAspectStack(TC_Aspects.METALLUM, 8L), + getTcAspectStack(TC_Aspects.POTENTIA, 8L))); + this.setElectricStats(32000 + tLastID, GT_Values.V[6] * 10 * 60 * 20, GT_Values.V[5], 5L, -3L, false); + + GregtechItemList.Cover_Overflow_LV.set( + this.addItem( + 72, + "Overflow Valve (LV)", + "Maximum void amount: 64,000", + getTcAspectStack(TC_Aspects.ELECTRUM, 1L), + getTcAspectStack(TC_Aspects.MACHINA, 1L), + getTcAspectStack(TC_Aspects.ITER, 1L), + getTcAspectStack(TC_Aspects.AQUA, 1L))); + GregtechItemList.Cover_Overflow_MV.set( + this.addItem( + 73, + "Overflow Valve (MV)", + "Maximum void amount: 512,000", + getTcAspectStack(TC_Aspects.ELECTRUM, 1L), + getTcAspectStack(TC_Aspects.MACHINA, 1L), + getTcAspectStack(TC_Aspects.ITER, 1L), + getTcAspectStack(TC_Aspects.AQUA, 1L))); + GregtechItemList.Cover_Overflow_HV.set( + this.addItem( + 74, + "Overflow Valve (HV)", + "Maximum void amount: 4,096,000", + getTcAspectStack(TC_Aspects.ELECTRUM, 1L), + getTcAspectStack(TC_Aspects.MACHINA, 1L), + getTcAspectStack(TC_Aspects.ITER, 1L), + getTcAspectStack(TC_Aspects.AQUA, 1L))); + GregtechItemList.Cover_Overflow_EV.set( + this.addItem( + 75, + "Overflow Valve (EV)", + "Maximum void amount: 32,768,000", + getTcAspectStack(TC_Aspects.ELECTRUM, 1L), + getTcAspectStack(TC_Aspects.MACHINA, 1L), + getTcAspectStack(TC_Aspects.ITER, 1L), + getTcAspectStack(TC_Aspects.AQUA, 1L))); + GregtechItemList.Cover_Overflow_IV.set( + this.addItem( + 76, + "Overflow Valve (IV)", + "Maximum void amount: 262,144,000", + getTcAspectStack(TC_Aspects.ELECTRUM, 1L), + getTcAspectStack(TC_Aspects.MACHINA, 1L), + getTcAspectStack(TC_Aspects.ITER, 1L), + getTcAspectStack(TC_Aspects.AQUA, 1L))); + + GregTech_API.registerCover( + GregtechItemList.Cover_Overflow_LV.get(1L), + new GT_MultiTexture( + Textures.BlockIcons.MACHINE_CASINGS[4][0], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Overflow_Valve)), + new GTPP_Cover_Overflow(64)); + GregTech_API.registerCover( + GregtechItemList.Cover_Overflow_MV.get(1L), + new GT_MultiTexture( + Textures.BlockIcons.MACHINE_CASINGS[5][0], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Overflow_Valve)), + new GTPP_Cover_Overflow(512)); + GregTech_API.registerCover( + GregtechItemList.Cover_Overflow_HV.get(1L), + new GT_MultiTexture( + Textures.BlockIcons.MACHINE_CASINGS[5][0], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Overflow_Valve)), + new GTPP_Cover_Overflow(4096)); + GregTech_API.registerCover( + GregtechItemList.Cover_Overflow_EV.get(1L), + new GT_MultiTexture( + Textures.BlockIcons.MACHINE_CASINGS[8][0], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Overflow_Valve)), + new GTPP_Cover_Overflow(32768)); + GregTech_API.registerCover( + GregtechItemList.Cover_Overflow_IV.get(1L), + new GT_MultiTexture( + Textures.BlockIcons.MACHINE_CASINGS[8][0], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Overflow_Valve)), + new GTPP_Cover_Overflow(262144)); + + // Fusion Reactor MK4 Singularity + GregtechItemList.Compressed_Fusion_Reactor.set( + this.addItem( + 100, + "Hypervisor Matrix (Fusion)", + "A memory unit containing an RI (Restricted Intelligence)")); + + GregtechItemList.Laser_Lens_Special + .set(this.addItem(105, "Quantum Anomaly", "Probably should shoot it with lasers")); + + GregtechItemList.Battery_Casing_Gem_1.set(this.addItem(106, "Containment Unit I", "Used in crafting")); + GregtechItemList.Battery_Casing_Gem_2.set(this.addItem(107, "Containment Unit II", "Used in crafting")); + GregtechItemList.Battery_Casing_Gem_3.set(this.addItem(108, "Advanced Containment Unit", "Used in crafting")); + GregtechItemList.Battery_Casing_Gem_4.set(this.addItem(109, "Exotic Containment Unit", "Used in crafting")); + + GregtechItemList.Battery_Gem_4.set( + this.addItem( + tLastID = 110, + "Graviton Anomaly", + "Reusable", + getTcAspectStack(TC_Aspects.ELECTRUM, 64L), + getTcAspectStack(TC_Aspects.METALLUM, 64L), + getTcAspectStack(TC_Aspects.POTENTIA, 64L))); + this.setElectricStats(32000 + tLastID, (64000000000L * 16), GT_Values.V[9], 9L, -3L, false); + + /* + * High Tier 'Saws' for the tree Farm + */ + + GregtechItemList.Laser_Lens_WoodsGlass.set( + this.addItem(140, "Wood's Glass Lens", "Allows UV & IF to pass through, blocks visible light spectrums")); + + // 141 now unused, was the ulv transmission component + int aStartID = 142; + GregtechItemList[] aTransParts = new GregtechItemList[] { GregtechItemList.TransmissionComponent_LV, + GregtechItemList.TransmissionComponent_MV, GregtechItemList.TransmissionComponent_HV, + GregtechItemList.TransmissionComponent_EV, GregtechItemList.TransmissionComponent_IV, + GregtechItemList.TransmissionComponent_LuV, GregtechItemList.TransmissionComponent_ZPM, + GregtechItemList.TransmissionComponent_UV, GregtechItemList.TransmissionComponent_UHV, }; + for (int tier = 1; tier < aTransParts.length + 1; tier++) { + aTransParts[tier - 1].set( + this.addItem( + aStartID++, + "Transmission Component (" + GT_Values.VN[tier] + ")", + "", + getTcAspectStack(TC_Aspects.ELECTRUM, tier), + getTcAspectStack(TC_Aspects.MACHINA, tier), + getTcAspectStack(TC_Aspects.MAGNETO, tier))); + } + + // Distillus Chip + GregtechItemList.Distillus_Upgrade_Chip + .set(this.addItem(151, "Distillus Upgrade Chip", "Used to upgrade Distillus to Tier 2")); + GregtechItemList.Maceration_Upgrade_Chip + .set(this.addItem(152, "Maceration Upgrade Chip", "Used to upgrade Maceration Stack to Tier 2")); + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/items/MetaGeneratedGregtechTools.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/items/MetaGeneratedGregtechTools.java new file mode 100644 index 0000000000..30250a46f3 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/items/MetaGeneratedGregtechTools.java @@ -0,0 +1,54 @@ +package gtPlusPlus.xmod.gregtech.common.items; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.TC_Aspects; +import gregtech.api.enums.ToolDictNames; +import gregtech.api.items.GT_MetaGenerated_Tool; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechToolDictNames; +import gtPlusPlus.xmod.gregtech.common.tools.TOOL_Gregtech_AngleGrinder; +import gtPlusPlus.xmod.gregtech.common.tools.TOOL_Gregtech_ElectricSnips; + +public class MetaGeneratedGregtechTools extends GT_MetaGenerated_Tool { + + public static final short ANGLE_GRINDER = 7834; + public static final short ELECTRIC_SNIPS = 7934; + public static GT_MetaGenerated_Tool INSTANCE; + + static { + INSTANCE = new MetaGeneratedGregtechTools(); + } + + public static GT_MetaGenerated_Tool getInstance() { + return INSTANCE; + } + + private MetaGeneratedGregtechTools() { + super("plusplus.metatool.01"); + + // Electric File + this.addTool( + ANGLE_GRINDER, + "Angle Grinder", + "Hand-held electric filing device", + new TOOL_Gregtech_AngleGrinder(), + GregtechToolDictNames.craftingToolAngleGrinder, + ToolDictNames.craftingToolFile, + new TC_Aspects.TC_AspectStack(TC_Aspects.INSTRUMENTUM, 2L), + new TC_Aspects.TC_AspectStack(TC_Aspects.FABRICO, 2L), + new TC_Aspects.TC_AspectStack(TC_Aspects.ORDO, 2L)); + + // Electric Wire Cutter + GregTech_API.registerWireCutter( + this.addTool( + ELECTRIC_SNIPS, + "Automatic Snips", + "Hand-held electric wire cutter", + new TOOL_Gregtech_ElectricSnips(), + GregtechToolDictNames.craftingToolElectricSnips, + ToolDictNames.craftingToolWireCutter, + new TC_Aspects.TC_AspectStack(TC_Aspects.INSTRUMENTUM, 4L), + new TC_Aspects.TC_AspectStack(TC_Aspects.FABRICO, 4L), + new TC_Aspects.TC_AspectStack(TC_Aspects.ORDO, 4L))); + + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/items/behaviours/Behaviour_Choocher.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/items/behaviours/Behaviour_Choocher.java new file mode 100644 index 0000000000..f85822750d --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/items/behaviours/Behaviour_Choocher.java @@ -0,0 +1,91 @@ +package gtPlusPlus.xmod.gregtech.common.items.behaviours; + +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.items.GT_MetaBase_Item; +import gregtech.api.util.GT_LanguageManager; +import gregtech.common.items.behaviors.Behaviour_None; +import gregtech.common.items.behaviors.Behaviour_Wrench; +import gtPlusPlus.core.util.minecraft.NBTUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; + +public class Behaviour_Choocher extends Behaviour_None { + + private boolean isWrench = true; + private final Behaviour_Wrench wrench = new Behaviour_Wrench(150); + private final Behaviour_Prospecting_Ex prospecting = new Behaviour_Prospecting_Ex(10, 1250); + private final String mTooltip1 = GT_LanguageManager + .addStringLocalization("gt.behaviour.choochering1", "Current tool mode: "); + private final String mTooltip2 = GT_LanguageManager + .addStringLocalization("gt.behaviour.choochering2", "Change tool mode using Shift+Rightclick."); + private final String mTooltipH = GT_LanguageManager + .addStringLocalization("gt.behaviour.prospectingEx", "Usable for Prospecting large areas."); + private final String mTooltipW = GT_LanguageManager + .addStringLocalization("gt.behaviour.wrench", "Rotates Blocks on Rightclick."); + + public Behaviour_Choocher() {} + + @Override + public boolean onItemUseFirst(final GT_MetaBase_Item aItem, final ItemStack aStack, final EntityPlayer aPlayer, + final World aWorld, final int aX, final int aY, final int aZ, final ForgeDirection side, final float hitX, + final float hitY, final float hitZ) { + if (aWorld.isRemote) { + return false; + } + + boolean inWrenchMode; + if (NBTUtils.hasKey(aStack, "aMode")) { + inWrenchMode = NBTUtils.getBoolean(aStack, "aMode"); + } else { + aStack.getTagCompound() + .setBoolean("aMode", true); + inWrenchMode = true; + } + + if (aPlayer.isSneaking()) { + boolean aModeNew = !inWrenchMode; + aStack.getTagCompound() + .setBoolean("aMode", aModeNew); + PlayerUtils.messagePlayer(aPlayer, "Mode: " + (aModeNew ? "Wrench" : "Hammer")); + return true; + } else { + if (inWrenchMode) { + return this.wrench.onItemUseFirst(aItem, aStack, aPlayer, aWorld, aX, aY, aZ, side, hitZ, hitZ, hitZ); + } else { + return this.prospecting + .onItemUseFirst(aItem, aStack, aPlayer, aWorld, aX, aY, aZ, side, hitX, hitY, hitZ); + } + } + } + + @Override + public List<String> getAdditionalToolTips(final GT_MetaBase_Item aItem, final List<String> aList, + final ItemStack aStack) { + + boolean inWrenchMode; + if (NBTUtils.hasKey(aStack, "aMode")) { + inWrenchMode = NBTUtils.getBoolean(aStack, "aMode"); + } else { + NBTUtils.setBoolean(aStack, "aMode", true); + aStack.getTagCompound() + .setBoolean("aMode", true); + inWrenchMode = true; + } + + if (inWrenchMode) { + aList.add(this.mTooltip1 + "Wrench"); + aList.add(this.mTooltipW); + } else { + aList.add(this.mTooltip1 + "Prospecting"); + aList.add(this.mTooltipH); + } + aList.add(this.mTooltip2); + + return aList; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/items/behaviours/Behaviour_Electric_Lighter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/items/behaviours/Behaviour_Electric_Lighter.java new file mode 100644 index 0000000000..f3d7f87a86 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/items/behaviours/Behaviour_Electric_Lighter.java @@ -0,0 +1,225 @@ +package gtPlusPlus.xmod.gregtech.common.items.behaviours; + +import java.util.List; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.monster.EntityCreeper; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +import codechicken.lib.math.MathHelper; +import gregtech.api.enums.SoundResource; +import gregtech.api.items.GT_MetaBase_Item; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_Utility; +import gregtech.common.items.behaviors.Behaviour_None; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.entity.projectile.EntityLightningAttack; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.NBTUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.common.helpers.ChargingHelper; +import gtPlusPlus.xmod.gregtech.common.items.MetaGeneratedGregtechTools; +import ic2.api.item.IElectricItemManager; + +public class Behaviour_Electric_Lighter extends Behaviour_None { + + private final String mTooltip = GT_LanguageManager + .addStringLocalization("gt.behaviour.lighter.tooltip", "Can light things on Fire"); + private final String mTooltipUses = GT_LanguageManager + .addStringLocalization("gt.behaviour.lighter.uses", "Remaining Uses:"); + private final String mTooltipUnstackable = GT_LanguageManager + .addStringLocalization("gt.behaviour.unstackable", "Not usable when stacked!"); + + public Behaviour_Electric_Lighter() {} + + @Override + public boolean onLeftClickEntity(GT_MetaBase_Item aItem, ItemStack aStack, EntityPlayer aPlayer, Entity aEntity) { + if (!aPlayer.worldObj.isRemote && aStack != null && aStack.stackSize == 1) { + boolean rOutput = false; + if (aEntity instanceof EntityCreeper) { + if (this.prepare(aStack) || aPlayer.capabilities.isCreativeMode) { + GT_Utility.sendSoundToPlayers( + aPlayer.worldObj, + SoundResource.FIRE_IGNITE, + 1.0F, + 1.0F, + MathHelper.floor_double(aEntity.posX), + MathHelper.floor_double(aEntity.posY), + MathHelper.floor_double(aEntity.posZ)); + ((EntityCreeper) aEntity).func_146079_cb(); + rOutput = true; + } + } + return rOutput; + } else { + return false; + } + } + + @Override + public boolean onItemUse(GT_MetaBase_Item aItem, ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, + int aY, int aZ, int ordinalSide, float hitX, float hitY, float hitZ) { + if (!aWorld.isRemote && aStack != null && aStack.stackSize == 1) { + if (aPlayer.isSneaking()) { + Logger.INFO("Changing Mode"); + boolean aCurrentMode = NBTUtils.getBoolean(aStack, "aFireballMode"); + Logger.INFO("Is currently in Fireball mode? " + aCurrentMode); + boolean aNewMode = !aCurrentMode; + Logger.INFO("Is now set to Fireball mode? " + aNewMode); + aStack.getTagCompound() + .setBoolean("aFireballMod", aNewMode); + // NBTUtils.setBoolean(aStack, "aFireballMode", aNewMode); + PlayerUtils.messagePlayer( + aPlayer, + "Current Mode: " + EnumChatFormatting.RED + (aNewMode ? "Projectile" : "Fire Starter")); + } else { + boolean aCurrentMode = NBTUtils.getBoolean(aStack, "aFireballMode"); + if (aCurrentMode) { + // Shoot Lightning Attack + aWorld + .playSoundAtEntity(aPlayer, "random.bow", 0.5F, 0.4F / (CORE.RANDOM.nextFloat() * 0.4F + 0.8F)); + if (!aWorld.isRemote) { + aWorld.spawnEntityInWorld(new EntityLightningAttack(aWorld, aPlayer, hitX, hitY, hitZ)); + } + } else { + // Lights Fires Mode + Logger.WARNING("Preparing Lighter a"); + boolean rOutput = false; + ForgeDirection tDirection = ForgeDirection.getOrientation(ordinalSide); + aX += tDirection.offsetX; + aY += tDirection.offsetY; + aZ += tDirection.offsetZ; + if (GT_Utility.isBlockAir(aWorld, aX, aY, aZ) + && aPlayer.canPlayerEdit(aX, aY, aZ, ordinalSide, aStack)) { + Logger.WARNING("Preparing Lighter b"); + if (this.prepare(aStack) || aPlayer.capabilities.isCreativeMode) { + Logger.WARNING("Preparing Lighter c"); + GT_Utility.sendSoundToPlayers(aWorld, SoundResource.FIRE_IGNITE, 1.0F, 1.0F, aX, aY, aZ); + aWorld.setBlock(aX, aY, aZ, Blocks.fire); + rOutput = true; + // ItemNBT.setLighterFuel(aStack, tFuelAmount); + return rOutput; + } + } + } + } + } + Logger.WARNING("Preparing Lighter z"); + return false; + } + + public boolean onItemUseFirst(GT_MetaBase_Item aItem, ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, + int aY, int aZ, int ordinalSide, float hitX, float hitY, float hitZ) { + if (!aWorld.isRemote && aStack != null && aStack.stackSize == 1) { + if (aPlayer.isSneaking()) { + Logger.INFO("Changing Mode"); + boolean aCurrentMode = NBTUtils.getBoolean(aStack, "aFireballMode"); + Logger.INFO("Is currently in Fireball mode? " + aCurrentMode); + boolean aNewMode = !aCurrentMode; + Logger.INFO("Is now set to Fireball mode? " + aNewMode); + aStack.getTagCompound() + .setBoolean("aFireballMode", aNewMode); + // NBTUtils.setBoolean(aStack, "aFireballMode", aNewMode); + PlayerUtils.messagePlayer( + aPlayer, + "Current Mode: " + EnumChatFormatting.RED + (aNewMode ? "Projectile" : "Fire Starter")); + } else { + boolean aCurrentMode = NBTUtils.getBoolean(aStack, "aFireballMode"); + if (aCurrentMode) { + // Shoot Lightning Attack + aWorld + .playSoundAtEntity(aPlayer, "random.bow", 0.5F, 0.4F / (CORE.RANDOM.nextFloat() * 0.4F + 0.8F)); + if (!aWorld.isRemote) { + aWorld.spawnEntityInWorld(new EntityLightningAttack(aWorld, aPlayer, hitX, hitY, hitZ)); + } + } else { + // Lights Fires Mode + Logger.WARNING("Preparing Lighter a"); + boolean rOutput = false; + ForgeDirection tDirection = ForgeDirection.getOrientation(ordinalSide); + aX += tDirection.offsetX; + aY += tDirection.offsetY; + aZ += tDirection.offsetZ; + if (GT_Utility.isBlockAir(aWorld, aX, aY, aZ) + && aPlayer.canPlayerEdit(aX, aY, aZ, ordinalSide, aStack)) { + Logger.WARNING("Preparing Lighter b"); + if (this.prepare(aStack) || aPlayer.capabilities.isCreativeMode) { + Logger.WARNING("Preparing Lighter c"); + GT_Utility.sendSoundToPlayers(aWorld, SoundResource.FIRE_IGNITE, 1.0F, 1.0F, aX, aY, aZ); + aWorld.setBlock(aX, aY, aZ, Blocks.fire); + rOutput = true; + // ItemNBT.setLighterFuel(aStack, tFuelAmount); + return rOutput; + } + } + } + } + } + Logger.WARNING("Preparing Lighter z"); + return false; + } + + private boolean prepare(ItemStack aStack) { + if (aStack != null) { + Logger.WARNING("Preparing Lighter 1"); + if (aStack.getItem() instanceof MetaGeneratedGregtechTools) { + Logger.WARNING("Preparing Lighter 2"); + if (ChargingHelper.isItemValid(aStack)) { + Logger.WARNING("Preparing Lighter 3"); + if (aStack.getItem() instanceof IElectricItemManager aItemElec) { + Logger.WARNING("Preparing Lighter 4"); + double aCharge = aItemElec.getCharge(aStack); + long aEuCost = 4096 * 2; + if (aCharge >= aEuCost) { + Logger.WARNING("Preparing Lighter 5"); + aItemElec.discharge(aStack, aEuCost, 3, true, true, false); + return true; + } + } + } + } + } + Logger.WARNING("Preparing Lighter 0"); + return false; + } + + private void useUp(ItemStack aStack) {} + + @Override + public List<String> getAdditionalToolTips(GT_MetaBase_Item aItem, List<String> aList, ItemStack aStack) { + aList.add(this.mTooltip); + int aUses = 0; + if (aStack != null) { + if (aStack.getItem() instanceof MetaGeneratedGregtechTools) { + if (ChargingHelper.isItemValid(aStack)) { + if (aStack.getItem() instanceof IElectricItemManager aItemElec) { + double aCharge = aItemElec.getCharge(aStack); + long aEuCost = 4096 * 2; + aUses = (int) (aCharge / aEuCost); + } + } + boolean aCurrentMode; + if (!NBTUtils.hasTagCompound(aStack)) { + NBTUtils.createEmptyTagCompound(aStack); + } + if (NBTUtils.hasKey(aStack, "aFireballMode")) { + aCurrentMode = NBTUtils.getBoolean(aStack, "aFireballMode"); + } else { + aStack.getTagCompound() + .setBoolean("aFireballMode", false); + aCurrentMode = false; + } + aList.add("Current Mode: " + EnumChatFormatting.RED + (aCurrentMode ? "Projectile" : "Fire Starter")); + } + } + + aList.add(this.mTooltipUses + " " + aUses); + aList.add(this.mTooltipUnstackable); + return aList; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/items/behaviours/Behaviour_Prospecting_Ex.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/items/behaviours/Behaviour_Prospecting_Ex.java new file mode 100644 index 0000000000..5749204296 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/items/behaviours/Behaviour_Prospecting_Ex.java @@ -0,0 +1,140 @@ +package gtPlusPlus.xmod.gregtech.common.items.behaviours; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.IFluidBlock; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.Materials; +import gregtech.api.enums.SoundResource; +import gregtech.api.items.GT_MetaBase_Item; +import gregtech.api.items.GT_MetaGenerated_Tool; +import gregtech.api.objects.ItemData; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; +import gregtech.common.blocks.GT_Block_Ores; +import gregtech.common.blocks.GT_TileEntity_Ores; +import gregtech.common.items.behaviors.Behaviour_Prospecting; + +public class Behaviour_Prospecting_Ex extends Behaviour_Prospecting { + + private final int mVanillaCosts; + private final int mEUCosts; + + public Behaviour_Prospecting_Ex(final int aVanillaCosts, final int aEUCosts) { + super(aVanillaCosts, aEUCosts); + this.mVanillaCosts = aVanillaCosts; + this.mEUCosts = aEUCosts; + } + + @Override + public boolean onItemUseFirst(final GT_MetaBase_Item aItem, final ItemStack aStack, final EntityPlayer aPlayer, + final World aWorld, final int aX, final int aY, final int aZ, final ForgeDirection side, final float hitX, + final float hitY, final float hitZ) { + if (aWorld.isRemote) { + return false; + } + final Block aBlock = aWorld.getBlock(aX, aY, aZ); + if (aBlock == null) { + return false; + } + final byte aMeta = (byte) aWorld.getBlockMetadata(aX, aY, aZ); + + ItemData tAssotiation = GT_OreDictUnificator.getAssociation(new ItemStack(aBlock, 1, aMeta)); + if ((tAssotiation != null) && (tAssotiation.mPrefix.toString() + .startsWith("ore"))) { + GT_Utility + .sendChatToPlayer(aPlayer, "This is " + tAssotiation.mMaterial.mMaterial.mDefaultLocalName + " Ore."); + GT_Utility.sendSoundToPlayers(aWorld, SoundResource.RANDOM_ANVIL_USE, 1.0F, -1.0F, aX, aY, aZ); + return true; + } + if ((aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.stone)) + || (aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, GregTech_API.sBlockGranites)) + || (aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.netherrack)) + || (aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.end_stone)) + || (aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.dirt)) + || (aBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, Blocks.grass))) { + if (GT_ModHandler.damageOrDechargeItem(aStack, this.mVanillaCosts, this.mEUCosts, aPlayer)) { + GT_Utility.sendSoundToPlayers(aWorld, SoundResource.RANDOM_ANVIL_USE, 1.0F, -1.0F, aX, aY, aZ); + int tX = aX; + int tY = aY; + int tZ = aZ; + int tMetaID = 0; + final int tQuality = ((aItem instanceof GT_MetaGenerated_Tool) + ? ((GT_MetaGenerated_Tool) aItem).getHarvestLevel(aStack, "") + : 0) * 3; + + int i = 0; + for (final int j = 6 + tQuality; i < j; i++) { + tX -= side.offsetX; + tY -= side.offsetY; + tZ -= side.offsetZ; + + final Block tBlock = aWorld.getBlock(tX, tY, tZ); + if ((tBlock == Blocks.lava) || (tBlock == Blocks.flowing_lava)) { + GT_Utility.sendChatToPlayer(aPlayer, "There is Lava behind this Block."); + break; + } + if ((tBlock == Blocks.water) || (tBlock == Blocks.flowing_water) + || ((tBlock instanceof IFluidBlock))) { + GT_Utility.sendChatToPlayer(aPlayer, "There is a Liquid behind this Block."); + break; + } + if ((tBlock == Blocks.monster_egg) || (!GT_Utility.hasBlockHitBox(aWorld, tX, tY, tZ))) { + GT_Utility.sendChatToPlayer(aPlayer, "There is an Air Pocket behind this Block."); + break; + } + if (tBlock != aBlock) { + if (i >= 4) { + break; + } + GT_Utility.sendChatToPlayer(aPlayer, "Material is changing behind this Block."); + break; + } + } + final Random tRandom = new Random(aX ^ aY ^ aZ ^ side.ordinal()); + i = 0; + for (final int j = 9 + (2 * tQuality); i < j; i++) { + tX = (aX - 4 - tQuality) + tRandom.nextInt(j); + tY = (aY - 4 - tQuality) + tRandom.nextInt(j); + tZ = (aZ - 4 - tQuality) + tRandom.nextInt(j); + final Block tBlock = aWorld.getBlock(tX, tY, tZ); + if ((tBlock instanceof GT_Block_Ores)) { + final TileEntity tTileEntity = aWorld.getTileEntity(tX, tY, tZ); + if ((tTileEntity instanceof GT_TileEntity_Ores)) { + final Materials tMaterial = GregTech_API.sGeneratedMaterials[(((GT_TileEntity_Ores) tTileEntity).mMetaData + % 1000)]; + if ((tMaterial != null) && (tMaterial != Materials._NULL)) { + GT_Utility.sendChatToPlayer( + aPlayer, + "Found traces of " + tMaterial.mDefaultLocalName + " Ore."); + return true; + } + } + } else { + tMetaID = aWorld.getBlockMetadata(tX, tY, tZ); + tAssotiation = GT_OreDictUnificator.getAssociation(new ItemStack(tBlock, 1, tMetaID)); + if ((tAssotiation != null) && (tAssotiation.mPrefix.toString() + .startsWith("ore"))) { + GT_Utility.sendChatToPlayer( + aPlayer, + "Found traces of " + tAssotiation.mMaterial.mMaterial.mDefaultLocalName + " Ore."); + return true; + } + } + } + GT_Utility.sendChatToPlayer(aPlayer, "No Ores found."); + } + return true; + } + return false; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/items/covers/MetaItemCoverCasings.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/items/covers/MetaItemCoverCasings.java new file mode 100644 index 0000000000..987924952a --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/items/covers/MetaItemCoverCasings.java @@ -0,0 +1,50 @@ +package gtPlusPlus.xmod.gregtech.common.items.covers; + +import static gregtech.api.enums.Mods.GTPlusPlus; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; +import net.minecraft.util.StatCollector; + +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Textures; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.xmod.gregtech.common.items.MetaCustomCoverItem; + +public class MetaItemCoverCasings extends MetaCustomCoverItem { + + public MetaItemCoverCasings() { + super( + GTPlusPlus.ID, + Textures.BlockIcons.MACHINECASINGS_SIDE.length, + "Gt Machine Casings", + Textures.BlockIcons.MACHINECASINGS_SIDE, + null); + } + + @Override + public void registerIcons(IIconRegister reg) { + for (int i = 0; i < icons.length; i++) { + this.icons[i] = reg.registerIcon(GTPlusPlus.ID + ":" + "covers/" + i); + } + } + + @Override + public boolean hide() { + return false; + } + + @Override + public IIcon getIconFromDamage(int meta) { + return this.icons[MathUtils.balance(meta, 0, 15)]; + } + + @Override + public String getItemStackDisplayName(final ItemStack tItem) { + return EnumChatFormatting.LIGHT_PURPLE + StatCollector.translateToLocalFormatted( + "item.itemCustomMetaCover.miscutils.GtMachineCasings", + GT_Values.VOLTAGE_NAMES[MathUtils.balance(tItem.getItemDamage(), 0, GT_Values.VOLTAGE_NAMES.length - 1)]); // super.getItemStackDisplayName(tItem); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/render/GTPP_CapeRenderer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/render/GTPP_CapeRenderer.java new file mode 100644 index 0000000000..a281a205d2 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/render/GTPP_CapeRenderer.java @@ -0,0 +1,500 @@ +package gtPlusPlus.xmod.gregtech.common.render; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Date; +import java.util.List; +import java.util.concurrent.ForkJoinPool; + +import net.minecraft.client.entity.AbstractClientPlayer; +import net.minecraft.client.model.ModelBiped; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.entity.RenderPlayer; +import net.minecraft.potion.Potion; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.event.RenderPlayerEvent; + +import org.apache.commons.io.IOUtils; +import org.lwjgl.opengl.GL11; + +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.objects.data.Pair; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.lib.CORE.ConfigSwitches; +import gtPlusPlus.core.proxy.ClientProxy; +import gtPlusPlus.core.util.data.AES; +import gtPlusPlus.core.util.data.FileUtils; +import gtPlusPlus.core.util.math.MathUtils; + +public class GTPP_CapeRenderer extends RenderPlayer { + + private static final ResourceLocation[] mCapes = { new ResourceLocation("miscutils:textures/OrangeHD.png"), + new ResourceLocation("miscutils:textures/FancyCapeHD.png"), + new ResourceLocation("miscutils:textures/TesterCapeHD.png"), + new ResourceLocation("miscutils:textures/PatreonCapeHD.png"), + new ResourceLocation("miscutils:textures/DevCapeHD.png"), }; + + private final boolean mInit; + + public GTPP_CapeRenderer() { + mInit = init(); + } + + private boolean init() { + if (mInit) { + return false; + } + return CapeUtils.init(); + } + + private static boolean hasResourceChecked = false; + private static boolean hasSetRenderer = false; + private boolean hasCape = false; + private ResourceLocation tResource = null; + + public synchronized void receiveRenderSpecialsEvent(RenderPlayerEvent.Specials.Pre aEvent) { + + // Check we have set Render Manager + if (this.renderManager == null) { + hasSetRenderer = false; + } + + // Set Render Manager + if (!hasSetRenderer) { + if (RenderManager.instance != null) { + setRenderManager(RenderManager.instance); + hasSetRenderer = true; + } + } + + // Actually Render + if (hasSetRenderer) { + + // We have capes turned off, so let's not render. + if (!ConfigSwitches.enableCustomCapes) { + return; + } + + if (!CapeUtils.mapsPopulated) { + if (!CapeUtils.cacheReady) { + return; + } + CapeUtils.writeCacheToMaps(); + CapeUtils.mapsPopulated = true; + } + + // We have already checked if this player has a cape, but since they do not, we best not render. + if (hasResourceChecked) { + if (!hasCape && !CORE.DEVENV) { + return; + } + } + + // Allocate client player object + AbstractClientPlayer aPlayer = (AbstractClientPlayer) aEvent.entityPlayer; + + // Make sure we don't keep checking on clients who dont have capes. + if (!hasResourceChecked) { + + // Get players UUID + String aPlayerUUID = aPlayer != null ? aPlayer.getGameProfile() + .getId() + .toString() : "BAD"; + + // If for whatever reason this fails, we just exit early. + if (aPlayerUUID.equals("BAD")) { + return; + } + + // Automatically allocate a Dev cape while in Dev mode. + if (tResource == null && CORE.DEVENV) { + tResource = mCapes[4]; + hasCape = true; + } + + String aPlayerName = ClientProxy.playerName; + + // Check cape lists for the cape this player owns. + if (!hasCape) { + for (Pair<String, String> aData : CapeUtils.mOrangeCapes) { + if (aData.getKey() + .equals(aPlayerUUID) || aPlayerName.equals(aData.getValue())) { + tResource = mCapes[0]; + hasCape = true; + break; + } + } + } + if (!hasCape) { + for (Pair<String, String> aData : CapeUtils.mMiscCapes) { + if (aData.getKey() + .equals(aPlayerUUID) || aPlayerName.equals(aData.getValue())) { + tResource = mCapes[1]; + hasCape = true; + break; + } + } + } + if (!hasCape) { + for (Pair<String, String> aData : CapeUtils.mBetaTestCapes) { + if (aData.getKey() + .equals(aPlayerUUID) || aPlayerName.equals(aData.getValue())) { + tResource = mCapes[2]; + hasCape = true; + break; + } + } + } + if (!hasCape) { + for (Pair<String, String> aData : CapeUtils.mPatreonCapes) { + if (aData.getKey() + .equals(aPlayerUUID) || aPlayerName.equals(aData.getValue())) { + tResource = mCapes[3]; + hasCape = true; + break; + } + } + } + if (!hasCape) { + for (Pair<String, String> aData : CapeUtils.mDevCapes) { + if (aData.getKey() + .equals(aPlayerUUID) || aPlayerName.equals(aData.getValue())) { + tResource = mCapes[4]; + hasCape = true; + break; + } + } + } + hasResourceChecked = true; + } + + if (hasResourceChecked) { + // We have met all the conditions, let's render that cape. + renderCapeOnPlayer(aEvent, aPlayer); + } + } + } + + private boolean renderCapeOnPlayer(RenderPlayerEvent.Specials.Pre aEvent, AbstractClientPlayer aPlayer) { + float aPartialTicks = aEvent.partialRenderTick; + try { + if (tResource == null && CORE.DEVENV) { + tResource = mCapes[3]; + } + + // If player is invisible, don't render. + if (GT_Utility.getFullInvisibility(aPlayer) || aPlayer.isInvisible() + || GT_Utility.getPotion(aPlayer, Integer.valueOf(Potion.invisibility.id))) { + aEvent.setCanceled(true); + return false; + } + + if ((tResource != null) && (!aPlayer.getHideCape())) { + bindTexture(tResource); + GL11.glPushMatrix(); + GL11.glTranslatef(0.0F, 0.0F, 0.125F); + double d0 = aPlayer.field_71091_bM + (aPlayer.field_71094_bP - aPlayer.field_71091_bM) * aPartialTicks + - (aPlayer.prevPosX + (aPlayer.posX - aPlayer.prevPosX) * aPartialTicks); + double d1 = aPlayer.field_71096_bN + (aPlayer.field_71095_bQ - aPlayer.field_71096_bN) * aPartialTicks + - (aPlayer.prevPosY + (aPlayer.posY - aPlayer.prevPosY) * aPartialTicks); + double d2 = aPlayer.field_71097_bO + (aPlayer.field_71085_bR - aPlayer.field_71097_bO) * aPartialTicks + - (aPlayer.prevPosZ + (aPlayer.posZ - aPlayer.prevPosZ) * aPartialTicks); + float f6 = aPlayer.prevRenderYawOffset + + (aPlayer.renderYawOffset - aPlayer.prevRenderYawOffset) * aPartialTicks; + double d3 = MathHelper.sin(f6 * CORE.PI / 180.0F); + double d4 = -MathHelper.cos(f6 * CORE.PI / 180.0F); + float f7 = (float) d1 * 10.0F; + float f8 = (float) (d0 * d3 + d2 * d4) * 100.0F; + float f9 = (float) (d0 * d4 - d2 * d3) * 100.0F; + if (f7 < -6.0F) { + f7 = -6.0F; + } + if (f7 > 32.0F) { + f7 = 32.0F; + } + if (f8 < 0.0F) { + f8 = 0.0F; + } + float f10 = aPlayer.prevCameraYaw + (aPlayer.cameraYaw - aPlayer.prevCameraYaw) * aPartialTicks; + f7 += MathHelper.sin( + (aPlayer.prevDistanceWalkedModified + + (aPlayer.distanceWalkedModified - aPlayer.prevDistanceWalkedModified) * aPartialTicks) * 6.0F) + * 32.0F + * f10; + if (aPlayer.isSneaking()) { + f7 += 25.0F; + } + GL11.glRotatef(6.0F + f8 / 2.0F + f7, 1.0F, 0.0F, 0.0F); + GL11.glRotatef(f9 / 2.0F, 0.0F, 0.0F, 1.0F); + GL11.glRotatef(-f9 / 2.0F, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F); + ((ModelBiped) this.mainModel).renderCloak(0.0625F); + GL11.glPopMatrix(); + return true; + } + } catch (Throwable e) { + + } + return false; + } + + private static class CapeUtils { + + private static char SPLIT_CHARACTER = '§'; + private static AES sAES; + private static volatile boolean cacheReady = false; + private static boolean mapsPopulated = false; + + // UUID - Username + private static final AutoMap<Pair<String, String>> mOrangeCapes = new AutoMap<>(); + private static final AutoMap<Pair<String, String>> mMiscCapes = new AutoMap<>(); + private static final AutoMap<Pair<String, String>> mBetaTestCapes = new AutoMap<>(); + private static final AutoMap<Pair<String, String>> mPatreonCapes = new AutoMap<>(); + private static final AutoMap<Pair<String, String>> mDevCapes = new AutoMap<>(); + + private static boolean init() { + CapeUtils.handleOldCapeCache(); + if (CORE.DEVENV) { + return true; + } + ForkJoinPool.commonPool() + .execute(() -> { + try { + if (shouldDownloadCapeList()) { + downloadCapeList(); + } + } catch (Exception ignored) {} + cacheReady = true; + }); + return true; + } + + private static boolean shouldDownloadCapeList() { + if (!doesCapeCacheExistLocally()) { + return true; + } + if (isCapeCacheWeekOld()) { + return true; + } + return false; + } + + private static boolean isCapeCacheWeekOld() { + if (!doesCapeCacheExistLocally()) { + return true; + } else { + File dat = CapeUtils.getCapeCache(); + Date dateLastMod = new Date(dat.lastModified()); + Date dateNow = new Date(System.currentTimeMillis() - (7l * 24 * 60 * 60 * 1000)); + if (dateLastMod.before(dateNow)) { + return true; + } + } + return false; + } + + private static void downloadCapeList() { + try { + File dat = getCapeCache(); + File temp = allocateTempFile(); + InputStream inputStream = new URL("https://alkcorp.overminddl1.com/CapeCache.dat").openStream(); + FileOutputStream fileOS = new FileOutputStream(temp); + IOUtils.copy(inputStream, fileOS); + if (isDownloadedCapeListBigger(temp)) { + fileOS = new FileOutputStream(dat); + IOUtils.copy(inputStream, fileOS); + } + } catch (Throwable t) { + Logger.INFO("Unable to download GT++ cape list."); + } + } + + private static boolean isDownloadedCapeListBigger(File aFile) { + double aExistingFileSize = (doesCapeCacheExistLocally() ? getCapeCache().length() : 0); + double aNewFileSize = aFile.length(); + if (aNewFileSize > aExistingFileSize) { + return true; + } + return false; + } + + private static void handleOldCapeCache() { + File aCacheFile = FileUtils.getFile("GTPP", "dat"); + if (FileUtils.doesFileExist(aCacheFile)) { + aCacheFile.delete(); + } + } + + private static boolean doesCapeCacheExistLocally() { + File aCacheFile = FileUtils.getFile("CapeCache", "dat"); + if (FileUtils.doesFileExist(aCacheFile)) { + return true; + } + return false; + } + + private static File getCapeCache() { + File aCacheFile = FileUtils.getFile("CapeCache", "dat"); + if (FileUtils.doesFileExist(aCacheFile)) { + FileUtils.createFile(aCacheFile); + } + return aCacheFile; + } + + public static final List<String> getDataFromCache() { + File aCacheFile = getCapeCache(); + List<String> aCache = FileUtils.readLines(aCacheFile); + if (aCache != null && !aCache.isEmpty()) { + return aCache; + } + return new AutoMap<>(); + } + + private static File allocateTempFile() { + File tempFile = null; + try { + tempFile = File.createTempFile("gtpp-", null); + } catch (IOException e) { + e.printStackTrace(); + } + if (tempFile == null) { + tempFile = FileUtils + .createFile("", "gtpp-" + MathUtils.randInt(Short.MAX_VALUE, (Integer.MAX_VALUE / 2)), "tmp"); + } + tempFile.deleteOnExit(); + return tempFile; + } + + public static final void writeCacheToMaps() { + List<String> aCacheData = getDataFromCache(); + if (aCacheData != null && !aCacheData.isEmpty()) { + if (sAES == null) { + sAES = new AES(); + } + AutoMap<String> aDecodedData = new AutoMap<>(); + for (String aToDecode : aCacheData) { + aDecodedData.put(sAES.decode(aToDecode)); + } + if (!aDecodedData.isEmpty()) { + AutoMap<Pair<String, String>> aCapeType1 = new AutoMap<>(); + AutoMap<Pair<String, String>> aCapeType2 = new AutoMap<>(); + AutoMap<Pair<String, String>> aCapeType3 = new AutoMap<>(); + AutoMap<Pair<String, String>> aCapeType4 = new AutoMap<>(); + AutoMap<Pair<String, String>> aCapeType5 = new AutoMap<>(); + boolean didProcessStringData = false; + Logger.INFO("Decoded String Count: " + aDecodedData.size()); + for (String aToSplit : aDecodedData) { + String[] aSplitData = aToSplit.split("" + SPLIT_CHARACTER); + if (aSplitData != null && aSplitData.length >= 2) { + if (aSplitData[0] != null) { + Integer aCapeTypeID2 = Integer.parseInt(aSplitData[0]); + if (aCapeTypeID2 != null) { + int aCapeTypeID = aCapeTypeID2; + Pair<String, String> aFinalString = new Pair<>( + "UUID: " + aSplitData[1], + "Username: " + + (aSplitData[2] != null && aSplitData[0].length() > 0 ? aSplitData[2] + : "Not Specified")); + Logger.INFO("Cape Type: " + aCapeTypeID); + switch (aCapeTypeID) { + case 0 -> { + aCapeType1.add(aFinalString); + Logger.INFO( + "Added user to map " + aCapeTypeID + + ", map now holds " + + aCapeType1.size() + + " users."); + } + case 1 -> { + aCapeType2.add(aFinalString); + Logger.INFO( + "Added user to map " + aCapeTypeID + + ", map now holds " + + aCapeType2.size() + + " users."); + } + case 2 -> { + aCapeType3.add(aFinalString); + Logger.INFO( + "Added user to map " + aCapeTypeID + + ", map now holds " + + aCapeType3.size() + + " users."); + } + case 3 -> { + aCapeType4.add(aFinalString); + Logger.INFO( + "Added user to map " + aCapeTypeID + + ", map now holds " + + aCapeType4.size() + + " users."); + } + case 4 -> { + aCapeType5.add(aFinalString); + Logger.INFO( + "Added user to map " + aCapeTypeID + + ", map now holds " + + aCapeType5.size() + + " users."); + } + default -> {} + } + } + } + } + } + if (!aCapeType1.isEmpty() || !aCapeType2.isEmpty() + || !aCapeType3.isEmpty() + || !aCapeType4.isEmpty() + || !aCapeType5.isEmpty()) { + didProcessStringData = true; + } else { + // did not process any data + } + if (didProcessStringData) { + if (!aCapeType1.isEmpty()) { + for (Pair<String, String> aUser : aCapeType1) { + Logger.INFO("Adding Generic cape for " + aUser.getKey()); + mOrangeCapes.add(aUser); + } + } + if (!aCapeType2.isEmpty()) { + for (Pair<String, String> aUser : aCapeType2) { + Logger.INFO("Adding Blue cape for " + aUser.getKey()); + mMiscCapes.add(aUser); + } + } + if (!aCapeType3.isEmpty()) { + for (Pair<String, String> aUser : aCapeType3) { + Logger.INFO("Adding Beta cape for " + aUser.getKey()); + mBetaTestCapes.add(aUser); + } + } + if (!aCapeType4.isEmpty()) { + for (Pair<String, String> aUser : aCapeType4) { + Logger.INFO("Adding Patreon cape for " + aUser.getKey()); + mPatreonCapes.add(aUser); + } + } + if (!aCapeType5.isEmpty()) { + for (Pair<String, String> aUser : aCapeType5) { + Logger.INFO("Adding Dev cape for " + aUser.getKey()); + mDevCapes.add(aUser); + } + } + } + } else { + // No data decoded + } + } else { + // Nothing was cached? + } + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/render/GTPP_FlaskRenderer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/render/GTPP_FlaskRenderer.java new file mode 100644 index 0000000000..0c9e59e2f2 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/render/GTPP_FlaskRenderer.java @@ -0,0 +1,107 @@ +package gtPlusPlus.xmod.gregtech.common.render; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraftforge.client.IItemRenderer; +import net.minecraftforge.client.MinecraftForgeClient; +import net.minecraftforge.fluids.FluidStack; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.common.items.GT_VolumetricFlask; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import ic2.core.util.DrawUtil; + +@SideOnly(cpw.mods.fml.relauncher.Side.CLIENT) +public final class GTPP_FlaskRenderer implements net.minecraftforge.client.IItemRenderer { + + public GTPP_FlaskRenderer() { + MinecraftForgeClient.registerItemRenderer(GregtechItemList.VOLUMETRIC_FLASK_8k.getItem(), this); + MinecraftForgeClient.registerItemRenderer(GregtechItemList.VOLUMETRIC_FLASK_32k.getItem(), this); + } + + @Override + public boolean handleRenderType(ItemStack item, ItemRenderType type) { + return type != ItemRenderType.FIRST_PERSON_MAP; + } + + @Override + public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, IItemRenderer.ItemRendererHelper helper) { + return type == ItemRenderType.ENTITY; + } + + @Override + public void renderItem(ItemRenderType type, ItemStack item, Object... data) { + GT_VolumetricFlask cell = (GT_VolumetricFlask) item.getItem(); + + int aType = cell.getMaxCapacity() == 8000 ? 0 : 1; + IIcon icon = item.getIconIndex(); + GL11.glEnable(3042); + GL11.glEnable(3008); + if (type.equals(ItemRenderType.ENTITY)) { + GL11.glRotated(180.0D, 0.0D, 0.0D, 1.0D); + GL11.glRotated(90.0D, 0.0D, 1.0D, 0.0D); + GL11.glTranslated(-0.5D, -0.6D, 0.0D); + } else if (type.equals(ItemRenderType.EQUIPPED_FIRST_PERSON)) { + GL11.glTranslated(1.0D, 1.0D, 0.0D); + GL11.glRotated(180.0D, 0.0D, 0.0D, 1.0D); + } else if (type.equals(ItemRenderType.EQUIPPED)) { + GL11.glRotated(180.0D, 0.0D, 0.0D, 1.0D); + GL11.glTranslated(-1.0D, -1.0D, 0.0D); + } + + FluidStack fs = cell.getFluid(item); + if (fs != null) { + IIcon iconWindow = cell.iconWindow; + IIcon fluidicon = fs.getFluid() + .getIcon(fs); + int fluidColor = fs.getFluid() + .getColor(fs); + Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationItemsTexture); + GL11.glBlendFunc(0, 1); + if (type.equals(ItemRenderType.INVENTORY)) { + DrawUtil.renderIcon(iconWindow, 16.0D, 0.0D, 0.0F, 0.0F, -1.0F); + } else { + DrawUtil.renderIcon(iconWindow, 1.0D, -0.001D, 0.0F, 0.0F, 1.0F); + DrawUtil.renderIcon(iconWindow, 1.0D, -0.0615D, 0.0F, 0.0F, -1.0F); + } + + Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture); + GL11.glBlendFunc(770, 771); + GL11.glDepthFunc(514); + GL11.glColor3ub((byte) (fluidColor >> 16), (byte) (fluidColor >> 8), (byte) fluidColor); + if (type.equals(ItemRenderType.INVENTORY)) { + DrawUtil.renderIcon(fluidicon, 16.0D, 0.0D, 0.0F, 0.0F, -1.0F); + } else { + DrawUtil.renderIcon(fluidicon, 1.0D, -0.001D, 0.0F, 0.0F, 1.0F); + DrawUtil.renderIcon(fluidicon, 1.0D, -0.0615D, 0.0F, 0.0F, -1.0F); + } + + GL11.glColor3ub((byte) -1, (byte) -1, (byte) -1); + GL11.glDepthFunc(515); + } + + Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationItemsTexture); + GL11.glBlendFunc(770, 771); + if (type.equals(ItemRenderType.INVENTORY)) { + DrawUtil.renderIcon(icon, 16.0D, 0.001D, 0.0F, 0.0F, -1.0F); + } else { + ItemRenderer.renderItemIn2D( + Tessellator.instance, + icon.getMaxU(), + icon.getMinV(), + icon.getMinU(), + icon.getMaxV(), + icon.getIconWidth(), + icon.getIconHeight(), + 0.0625F); + } + GL11.glDisable(3008); + GL11.glDisable(3042); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/render/GTPP_Render_MachineBlock.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/render/GTPP_Render_MachineBlock.java new file mode 100644 index 0000000000..bfd16b4cc5 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/render/GTPP_Render_MachineBlock.java @@ -0,0 +1,1250 @@ +package gtPlusPlus.xmod.gregtech.common.render; + +import static gregtech.api.interfaces.metatileentity.IConnectable.CONNECTED_DOWN; +import static gregtech.api.interfaces.metatileentity.IConnectable.CONNECTED_EAST; +import static gregtech.api.interfaces.metatileentity.IConnectable.CONNECTED_NORTH; +import static gregtech.api.interfaces.metatileentity.IConnectable.CONNECTED_SOUTH; +import static gregtech.api.interfaces.metatileentity.IConnectable.CONNECTED_UP; +import static gregtech.api.interfaces.metatileentity.IConnectable.CONNECTED_WEST; +import static gregtech.api.interfaces.metatileentity.IConnectable.HAS_FOAM; +import static gregtech.api.interfaces.metatileentity.IConnectable.NO_CONNECTION; +import static net.minecraftforge.common.util.ForgeDirection.DOWN; +import static net.minecraftforge.common.util.ForgeDirection.EAST; +import static net.minecraftforge.common.util.ForgeDirection.NORTH; +import static net.minecraftforge.common.util.ForgeDirection.SOUTH; +import static net.minecraftforge.common.util.ForgeDirection.UP; +import static net.minecraftforge.common.util.ForgeDirection.WEST; + +import java.util.EnumMap; +import java.util.EnumSet; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.client.registry.RenderingRegistry; +import gregtech.api.GregTech_API; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.interfaces.tileentity.IPipeRenderedTileEntity; +import gregtech.api.interfaces.tileentity.ITexturedTileEntity; +import gregtech.api.metatileentity.MetaPipeEntity; +import gregtech.common.blocks.GT_Block_Machines; +import gregtech.common.render.GT_Renderer_Block; +import gtPlusPlus.xmod.gregtech.common.helpers.GT_MethodHelper; + +public class GTPP_Render_MachineBlock extends GT_Renderer_Block { + + public static GTPP_Render_MachineBlock INSTANCE; + public final int mRenderID = RenderingRegistry.getNextAvailableRenderId(); + + public GTPP_Render_MachineBlock() { + INSTANCE = this; + RenderingRegistry.registerBlockHandler(this); + } + + private static ITexture[] getTexture(IMetaTileEntity tile, ForgeDirection side, ForgeDirection facing, + int colorIndex, boolean active, boolean arg5) { + final IGregTechTileEntity gtTile = tile.getBaseMetaTileEntity(); + return tile.getTexture(gtTile, side, facing, (byte) colorIndex, active, arg5); + } + + private static ITexture[] getTexture(IMetaTileEntity tile, ForgeDirection side, int facingMask, int colorIndex, + boolean active, boolean arg5) { + final MetaPipeEntity gtTile = (MetaPipeEntity) tile.getBaseMetaTileEntity(); + return gtTile.getTexture((IGregTechTileEntity) tile, side, facingMask, colorIndex, active, arg5); + } + + private static void renderNormalInventoryMetaTileEntity(Block aBlock, int aMeta, RenderBlocks aRenderer) { + if (aMeta > 0 && aMeta < GregTech_API.METATILEENTITIES.length) { + IMetaTileEntity tMetaTileEntity = GregTech_API.METATILEENTITIES[aMeta]; + if (tMetaTileEntity != null) { + aBlock.setBlockBoundsForItemRender(); + aRenderer.setRenderBoundsFromBlock(aBlock); + GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); + GL11.glTranslatef(-0.5F, -0.5F, -0.5F); + if (tMetaTileEntity.getBaseMetaTileEntity() instanceof IPipeRenderedTileEntity pipeRenderedTile) { + float tThickness = pipeRenderedTile.getThickNess(); + float sp = (1.0F - tThickness) / 2.0F; + aBlock.setBlockBounds(0.0F, sp, sp, 1.0F, sp + tThickness, sp + tThickness); + aRenderer.setRenderBoundsFromBlock(aBlock); + Tessellator.instance.startDrawingQuads(); + Tessellator.instance.setNormal(0.0F, -1.0F, 0.0F); + renderNegativeYFacing( + null, + aRenderer, + aBlock, + 0, + 0, + 0, + getTexture(tMetaTileEntity, DOWN, 0b001001, -1, false, false), + true); + Tessellator.instance.draw(); + Tessellator.instance.startDrawingQuads(); + Tessellator.instance.setNormal(0.0F, 1.0F, 0.0F); + renderPositiveYFacing( + null, + aRenderer, + aBlock, + 0, + 0, + 0, + getTexture(tMetaTileEntity, UP, 0b001001, -1, false, false), + true); + Tessellator.instance.draw(); + Tessellator.instance.startDrawingQuads(); + Tessellator.instance.setNormal(0.0F, 0.0F, -1.0F); + renderNegativeZFacing( + null, + aRenderer, + aBlock, + 0, + 0, + 0, + getTexture(tMetaTileEntity, ForgeDirection.NORTH, 0b001001, -1, false, false), + true); + Tessellator.instance.draw(); + Tessellator.instance.startDrawingQuads(); + Tessellator.instance.setNormal(0.0F, 0.0F, 1.0F); + renderPositiveZFacing( + null, + aRenderer, + aBlock, + 0, + 0, + 0, + getTexture(tMetaTileEntity, ForgeDirection.SOUTH, 0b001001, -1, false, false), + true); + Tessellator.instance.draw(); + Tessellator.instance.startDrawingQuads(); + Tessellator.instance.setNormal(-1.0F, 0.0F, 0.0F); + renderNegativeXFacing( + null, + aRenderer, + aBlock, + 0, + 0, + 0, + getTexture(tMetaTileEntity, ForgeDirection.WEST, 0b001001, -1, true, false), + true); + Tessellator.instance.draw(); + Tessellator.instance.startDrawingQuads(); + Tessellator.instance.setNormal(1.0F, 0.0F, 0.0F); + renderPositiveXFacing( + null, + aRenderer, + aBlock, + 0, + 0, + 0, + getTexture(tMetaTileEntity, ForgeDirection.EAST, 0b001001, -1, true, false), + true); + Tessellator.instance.draw(); + } else { + Tessellator.instance.startDrawingQuads(); + Tessellator.instance.setNormal(0.0F, -1.0F, 0.0F); + renderNegativeYFacing( + null, + aRenderer, + aBlock, + 0, + 0, + 0, + getTexture(tMetaTileEntity, DOWN, ForgeDirection.WEST, -1, true, false), + true); + Tessellator.instance.draw(); + Tessellator.instance.startDrawingQuads(); + Tessellator.instance.setNormal(0.0F, 1.0F, 0.0F); + renderPositiveYFacing( + null, + aRenderer, + aBlock, + 0, + 0, + 0, + getTexture(tMetaTileEntity, UP, ForgeDirection.WEST, -1, true, false), + true); + Tessellator.instance.draw(); + Tessellator.instance.startDrawingQuads(); + Tessellator.instance.setNormal(0.0F, 0.0F, -1.0F); + renderNegativeZFacing( + null, + aRenderer, + aBlock, + 0, + 0, + 0, + getTexture(tMetaTileEntity, ForgeDirection.NORTH, ForgeDirection.WEST, -1, true, false), + true); + Tessellator.instance.draw(); + Tessellator.instance.startDrawingQuads(); + Tessellator.instance.setNormal(0.0F, 0.0F, 1.0F); + renderPositiveZFacing( + null, + aRenderer, + aBlock, + 0, + 0, + 0, + getTexture(tMetaTileEntity, ForgeDirection.SOUTH, ForgeDirection.WEST, -1, true, false), + true); + Tessellator.instance.draw(); + Tessellator.instance.startDrawingQuads(); + Tessellator.instance.setNormal(-1.0F, 0.0F, 0.0F); + renderNegativeXFacing( + null, + aRenderer, + aBlock, + 0, + 0, + 0, + getTexture(tMetaTileEntity, ForgeDirection.WEST, ForgeDirection.WEST, -1, true, false), + true); + Tessellator.instance.draw(); + Tessellator.instance.startDrawingQuads(); + Tessellator.instance.setNormal(1.0F, 0.0F, 0.0F); + renderPositiveXFacing( + null, + aRenderer, + aBlock, + 0, + 0, + 0, + getTexture(tMetaTileEntity, ForgeDirection.EAST, ForgeDirection.WEST, -1, true, false), + true); + Tessellator.instance.draw(); + } + + aBlock.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + aRenderer.setRenderBoundsFromBlock(aBlock); + GL11.glTranslatef(0.5F, 0.5F, 0.5F); + } + } + } + + public boolean renderStandardBlock(IBlockAccess aWorld, int aX, int aY, int aZ, Block aBlock, + RenderBlocks aRenderer) { + TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); + + return tTileEntity instanceof ITexturedTileEntity + ? renderStandardBlock( + aWorld, + aX, + aY, + aZ, + aBlock, + aRenderer, + new ITexture[][] { GT_MethodHelper.getTexture(tTileEntity, aBlock, DOWN), + GT_MethodHelper.getTexture(tTileEntity, aBlock, UP), + GT_MethodHelper.getTexture(tTileEntity, aBlock, ForgeDirection.NORTH), + GT_MethodHelper.getTexture(tTileEntity, aBlock, ForgeDirection.SOUTH), + GT_MethodHelper.getTexture(tTileEntity, aBlock, ForgeDirection.WEST), + GT_MethodHelper.getTexture(tTileEntity, aBlock, ForgeDirection.EAST) }) + : false; + } + + public boolean renderStandardBlock(IBlockAccess aWorld, int aX, int aY, int aZ, Block aBlock, + RenderBlocks aRenderer, ITexture[][] aTextures) { + aBlock.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + aRenderer.setRenderBoundsFromBlock(aBlock); + renderNegativeYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, aTextures[DOWN.ordinal()], true); + renderPositiveYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, aTextures[UP.ordinal()], true); + renderNegativeZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, aTextures[ForgeDirection.NORTH.ordinal()], true); + renderPositiveZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, aTextures[ForgeDirection.SOUTH.ordinal()], true); + renderNegativeXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, aTextures[ForgeDirection.WEST.ordinal()], true); + renderPositiveXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, aTextures[ForgeDirection.EAST.ordinal()], true); + return true; + } + + public boolean renderPipeBlock(IBlockAccess aWorld, int aX, int aY, int aZ, Block aBlock, + IPipeRenderedTileEntity aTileEntity, RenderBlocks aRenderer) { + final int aConnections = aTileEntity.getConnections(); + if ((aConnections & HAS_FOAM) != 0) { + return renderStandardBlock(aWorld, aX, aY, aZ, aBlock, aRenderer); + } else { + float tThickness = aTileEntity.getThickNess(); + if (tThickness >= 0.99F) { + return renderStandardBlock(aWorld, aX, aY, aZ, aBlock, aRenderer); + } else { + float sp = (1.0F - tThickness) / 2.0F; + int connexionSidesBits = 0; + + for (int ordinalSide = 0; ordinalSide < 6; ++ordinalSide) { + if ((aConnections & 1 << ordinalSide) != 0) { + connexionSidesBits = connexionSidesBits | 1 << (ordinalSide + 2) % 6; + } + } + + final EnumSet<ForgeDirection> coveredSides = EnumSet.noneOf(ForgeDirection.class); + + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + if (aTileEntity.getCoverIDAtSide(side) != 0) coveredSides.add(side); + } + + if (coveredSides.containsAll(EnumSet.of(DOWN, UP, NORTH, SOUTH, WEST, EAST))) { + return renderStandardBlock(aWorld, aX, aY, aZ, aBlock, aRenderer); + } else { + final EnumMap<ForgeDirection, ITexture[]> texture = new EnumMap<>(ForgeDirection.class); + final EnumMap<ForgeDirection, ITexture[]> textureUncovered = new EnumMap<>(ForgeDirection.class); + + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + texture.put(side, GT_MethodHelper.getTexture((TileEntity) aTileEntity, aBlock, side)); + textureUncovered.put(side, aTileEntity.getTextureUncovered(side)); + } + + switch (connexionSidesBits) { + case NO_CONNECTION -> { + aBlock.setBlockBounds(sp, sp, sp, sp + tThickness, sp + tThickness, sp + tThickness); + aRenderer.setRenderBoundsFromBlock(aBlock); + renderNegativeYFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(DOWN), + false); + renderPositiveYFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(UP), + false); + renderNegativeZFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(NORTH), + false); + renderPositiveZFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(SOUTH), + false); + renderNegativeXFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(WEST), + false); + renderPositiveXFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(EAST), + false); + } + case (CONNECTED_DOWN | CONNECTED_UP) -> { + aBlock.setBlockBounds(0.0F, sp, sp, 1.0F, sp + tThickness, sp + tThickness); + aRenderer.setRenderBoundsFromBlock(aBlock); + renderNegativeYFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(DOWN), + false); + renderPositiveYFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(UP), + false); + renderNegativeZFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(NORTH), + false); + renderPositiveZFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(SOUTH), + false); + if (!coveredSides.contains(WEST)) { + renderNegativeXFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(WEST), + false); + } + if (!coveredSides.contains(EAST)) { + renderPositiveXFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(EAST), + false); + } + } + case (CONNECTED_NORTH | CONNECTED_SOUTH) -> { + aBlock.setBlockBounds(sp, 0.0F, sp, sp + tThickness, 1.0F, sp + tThickness); + aRenderer.setRenderBoundsFromBlock(aBlock); + renderNegativeZFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(NORTH), + false); + renderPositiveZFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(SOUTH), + false); + renderNegativeXFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(WEST), + false); + renderPositiveXFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(EAST), + false); + if (!coveredSides.contains(DOWN)) { + renderNegativeYFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(DOWN), + false); + } + if (!coveredSides.contains(UP)) { + renderPositiveYFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(UP), + false); + } + } + case (CONNECTED_WEST | CONNECTED_EAST) -> { + aBlock.setBlockBounds(sp, sp, 0.0F, sp + tThickness, sp + tThickness, 1.0F); + aRenderer.setRenderBoundsFromBlock(aBlock); + renderNegativeYFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(DOWN), + false); + renderPositiveYFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(UP), + false); + renderNegativeXFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(WEST), + false); + renderPositiveXFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(EAST), + false); + if (!coveredSides.contains(NORTH)) { + renderNegativeZFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(NORTH), + false); + } + if (!coveredSides.contains(SOUTH)) { + renderPositiveZFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(SOUTH), + false); + } + } + default -> { + if ((connexionSidesBits & CONNECTED_DOWN) == 0) { + aBlock.setBlockBounds(sp, sp, sp, sp + tThickness, sp + tThickness, sp + tThickness); + aRenderer.setRenderBoundsFromBlock(aBlock); + renderNegativeXFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(WEST), + false); + } else { + aBlock.setBlockBounds(0.0F, sp, sp, sp, sp + tThickness, sp + tThickness); + aRenderer.setRenderBoundsFromBlock(aBlock); + renderNegativeYFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(DOWN), + false); + renderPositiveYFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(UP), + false); + renderNegativeZFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(NORTH), + false); + renderPositiveZFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(SOUTH), + false); + if (!coveredSides.contains(WEST)) { + renderNegativeXFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(WEST), + false); + } + } + if ((connexionSidesBits & CONNECTED_UP) == 0) { + aBlock.setBlockBounds(sp, sp, sp, sp + tThickness, sp + tThickness, sp + tThickness); + aRenderer.setRenderBoundsFromBlock(aBlock); + renderPositiveXFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(EAST), + false); + } else { + aBlock.setBlockBounds(sp + tThickness, sp, sp, 1.0F, sp + tThickness, sp + tThickness); + aRenderer.setRenderBoundsFromBlock(aBlock); + renderNegativeYFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(DOWN), + false); + renderPositiveYFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(UP), + false); + renderNegativeZFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(NORTH), + false); + renderPositiveZFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(SOUTH), + false); + if (!coveredSides.contains(EAST)) { + renderPositiveXFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(EAST), + false); + } + } + if ((connexionSidesBits & CONNECTED_NORTH) == 0) { + aBlock.setBlockBounds(sp, sp, sp, sp + tThickness, sp + tThickness, sp + tThickness); + aRenderer.setRenderBoundsFromBlock(aBlock); + renderNegativeYFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(DOWN), + false); + } else { + aBlock.setBlockBounds(sp, 0.0F, sp, sp + tThickness, sp, sp + tThickness); + aRenderer.setRenderBoundsFromBlock(aBlock); + renderNegativeZFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(NORTH), + false); + renderPositiveZFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(SOUTH), + false); + renderNegativeXFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(WEST), + false); + renderPositiveXFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(EAST), + false); + if (!coveredSides.contains(DOWN)) { + renderNegativeYFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(DOWN), + false); + } + } + if ((connexionSidesBits & CONNECTED_SOUTH) == 0) { + aBlock.setBlockBounds(sp, sp, sp, sp + tThickness, sp + tThickness, sp + tThickness); + aRenderer.setRenderBoundsFromBlock(aBlock); + renderPositiveYFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(UP), + false); + } else { + aBlock.setBlockBounds(sp, sp + tThickness, sp, sp + tThickness, 1.0F, sp + tThickness); + aRenderer.setRenderBoundsFromBlock(aBlock); + renderNegativeZFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(NORTH), + false); + renderPositiveZFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(SOUTH), + false); + renderNegativeXFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(WEST), + false); + renderPositiveXFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(EAST), + false); + if (!coveredSides.contains(UP)) { + renderPositiveYFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(UP), + false); + } + } + if ((connexionSidesBits & CONNECTED_WEST) == 0) { + aBlock.setBlockBounds(sp, sp, sp, sp + tThickness, sp + tThickness, sp + tThickness); + aRenderer.setRenderBoundsFromBlock(aBlock); + renderNegativeZFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(NORTH), + false); + } else { + aBlock.setBlockBounds(sp, sp, 0.0F, sp + tThickness, sp + tThickness, sp); + aRenderer.setRenderBoundsFromBlock(aBlock); + renderNegativeYFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(DOWN), + false); + renderPositiveYFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(UP), + false); + renderNegativeXFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(WEST), + false); + renderPositiveXFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(EAST), + false); + if (!coveredSides.contains(NORTH)) { + renderNegativeZFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(NORTH), + false); + } + } + if ((connexionSidesBits & CONNECTED_EAST) == 0) { + aBlock.setBlockBounds(sp, sp, sp, sp + tThickness, sp + tThickness, sp + tThickness); + aRenderer.setRenderBoundsFromBlock(aBlock); + renderPositiveZFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(SOUTH), + false); + } else { + aBlock.setBlockBounds(sp, sp, sp + tThickness, sp + tThickness, sp + tThickness, 1.0F); + aRenderer.setRenderBoundsFromBlock(aBlock); + renderNegativeYFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(DOWN), + false); + renderPositiveYFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(UP), + false); + renderNegativeXFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(WEST), + false); + renderPositiveXFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(EAST), + false); + if (!coveredSides.contains(SOUTH)) { + renderPositiveZFacing( + aWorld, + aRenderer, + aBlock, + aX, + aY, + aZ, + textureUncovered.get(SOUTH), + false); + } + } + } + } + + if (coveredSides.contains(DOWN)) { + aBlock.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.125F, 1.0F); + aRenderer.setRenderBoundsFromBlock(aBlock); + renderNegativeYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(DOWN), false); + renderPositiveYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(DOWN), false); + if (!coveredSides.contains(NORTH)) { + renderNegativeZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(DOWN), false); + } + + if (!coveredSides.contains(SOUTH)) { + renderPositiveZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(DOWN), false); + } + + if (!coveredSides.contains(WEST)) { + renderNegativeXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(DOWN), false); + } + + if (!coveredSides.contains(EAST)) { + renderPositiveXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(DOWN), false); + } + } + + if (coveredSides.contains(UP)) { + aBlock.setBlockBounds(0.0F, 0.875F, 0.0F, 1.0F, 1.0F, 1.0F); + aRenderer.setRenderBoundsFromBlock(aBlock); + renderNegativeYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(UP), false); + renderPositiveYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(UP), false); + if (!coveredSides.contains(NORTH)) { + renderNegativeZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(UP), false); + } + + if (!coveredSides.contains(SOUTH)) { + renderPositiveZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(UP), false); + } + + if (!coveredSides.contains(WEST)) { + renderNegativeXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(UP), false); + } + + if (!coveredSides.contains(EAST)) { + renderPositiveXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(UP), false); + } + } + + if (coveredSides.contains(NORTH)) { + aBlock.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.125F); + aRenderer.setRenderBoundsFromBlock(aBlock); + if (!coveredSides.contains(DOWN)) { + renderNegativeYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(NORTH), false); + } + + if (!coveredSides.contains(UP)) { + renderPositiveYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(NORTH), false); + } + + renderNegativeZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(NORTH), false); + renderPositiveZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(NORTH), false); + if (!coveredSides.contains(WEST)) { + renderNegativeXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(NORTH), false); + } + + if (!coveredSides.contains(EAST)) { + renderPositiveXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(NORTH), false); + } + } + + if (coveredSides.contains(SOUTH)) { + aBlock.setBlockBounds(0.0F, 0.0F, 0.875F, 1.0F, 1.0F, 1.0F); + aRenderer.setRenderBoundsFromBlock(aBlock); + if (!coveredSides.contains(DOWN)) { + renderNegativeYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(SOUTH), false); + } + + if (!coveredSides.contains(UP)) { + renderPositiveYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(SOUTH), false); + } + + renderNegativeZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(SOUTH), false); + renderPositiveZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(SOUTH), false); + if (!coveredSides.contains(WEST)) { + renderNegativeXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(SOUTH), false); + } + + if (!coveredSides.contains(EAST)) { + renderPositiveXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(SOUTH), false); + } + } + + if (coveredSides.contains(WEST)) { + aBlock.setBlockBounds(0.0F, 0.0F, 0.0F, 0.125F, 1.0F, 1.0F); + aRenderer.setRenderBoundsFromBlock(aBlock); + if (!coveredSides.contains(DOWN)) { + renderNegativeYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(WEST), false); + } + + if (!coveredSides.contains(UP)) { + renderPositiveYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(WEST), false); + } + + if (!coveredSides.contains(NORTH)) { + renderNegativeZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(WEST), false); + } + + if (!coveredSides.contains(SOUTH)) { + renderPositiveZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(WEST), false); + } + + renderNegativeXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(WEST), false); + renderPositiveXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(WEST), false); + } + + if (coveredSides.contains(EAST)) { + aBlock.setBlockBounds(0.875F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + aRenderer.setRenderBoundsFromBlock(aBlock); + if (!coveredSides.contains(DOWN)) { + renderNegativeYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(EAST), false); + } + + if (!coveredSides.contains(UP)) { + renderPositiveYFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(EAST), false); + } + + if (!coveredSides.contains(NORTH)) { + renderNegativeZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(EAST), false); + } + + if (!coveredSides.contains(SOUTH)) { + renderPositiveZFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(EAST), false); + } + + renderNegativeXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(EAST), false); + renderPositiveXFacing(aWorld, aRenderer, aBlock, aX, aY, aZ, texture.get(EAST), false); + } + + aBlock.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + aRenderer.setRenderBoundsFromBlock(aBlock); + return true; + } + } + } + } + + public static void renderNegativeYFacing(IBlockAccess aWorld, RenderBlocks aRenderer, Block aBlock, int aX, int aY, + int aZ, ITexture[] aIcon, boolean aFullBlock) { + if (aWorld != null) { + if (aFullBlock && !aBlock.shouldSideBeRendered(aWorld, aX, aY - 1, aZ, 0)) { + return; + } + + Tessellator.instance + .setBrightness(aBlock.getMixedBrightnessForBlock(aWorld, aX, aFullBlock ? aY - 1 : aY, aZ)); + } + + if (aIcon != null) { + for (ITexture iTexture : aIcon) { + if (iTexture != null) { + iTexture.renderYNeg(aRenderer, aBlock, aX, aY, aZ); + } + } + } + + aRenderer.flipTexture = false; + } + + public static void renderPositiveYFacing(IBlockAccess aWorld, RenderBlocks aRenderer, Block aBlock, int aX, int aY, + int aZ, ITexture[] aIcon, boolean aFullBlock) { + if (aWorld != null) { + if (aFullBlock && !aBlock.shouldSideBeRendered(aWorld, aX, aY + 1, aZ, 1)) { + return; + } + + Tessellator.instance + .setBrightness(aBlock.getMixedBrightnessForBlock(aWorld, aX, aFullBlock ? aY + 1 : aY, aZ)); + } + + if (aIcon != null) { + for (ITexture iTexture : aIcon) { + if (iTexture != null) { + iTexture.renderYPos(aRenderer, aBlock, aX, aY, aZ); + } + } + } + + aRenderer.flipTexture = false; + } + + public static void renderNegativeZFacing(IBlockAccess aWorld, RenderBlocks aRenderer, Block aBlock, int aX, int aY, + int aZ, ITexture[] aIcon, boolean aFullBlock) { + if (aWorld != null) { + if (aFullBlock && !aBlock.shouldSideBeRendered(aWorld, aX, aY, aZ - 1, 2)) { + return; + } + + Tessellator.instance + .setBrightness(aBlock.getMixedBrightnessForBlock(aWorld, aX, aY, aFullBlock ? aZ - 1 : aZ)); + } + + aRenderer.flipTexture = !aFullBlock; + if (aIcon != null) { + for (ITexture iTexture : aIcon) { + if (iTexture != null) { + iTexture.renderZNeg(aRenderer, aBlock, aX, aY, aZ); + } + } + } + + aRenderer.flipTexture = false; + } + + public static void renderPositiveZFacing(IBlockAccess aWorld, RenderBlocks aRenderer, Block aBlock, int aX, int aY, + int aZ, ITexture[] aIcon, boolean aFullBlock) { + if (aWorld != null) { + if (aFullBlock && !aBlock.shouldSideBeRendered(aWorld, aX, aY, aZ + 1, 3)) { + return; + } + + Tessellator.instance + .setBrightness(aBlock.getMixedBrightnessForBlock(aWorld, aX, aY, aFullBlock ? aZ + 1 : aZ)); + } + + if (aIcon != null) { + for (ITexture iTexture : aIcon) { + if (iTexture != null) { + iTexture.renderZPos(aRenderer, aBlock, aX, aY, aZ); + } + } + } + + aRenderer.flipTexture = false; + } + + public static void renderNegativeXFacing(IBlockAccess aWorld, RenderBlocks aRenderer, Block aBlock, int aX, int aY, + int aZ, ITexture[] aIcon, boolean aFullBlock) { + if (aWorld != null) { + if (aFullBlock && !aBlock.shouldSideBeRendered(aWorld, aX - 1, aY, aZ, 4)) { + return; + } + + Tessellator.instance + .setBrightness(aBlock.getMixedBrightnessForBlock(aWorld, aFullBlock ? aX - 1 : aX, aY, aZ)); + } + + if (aIcon != null) { + for (ITexture iTexture : aIcon) { + if (iTexture != null) { + iTexture.renderXNeg(aRenderer, aBlock, aX, aY, aZ); + } + } + } + + aRenderer.flipTexture = false; + } + + public static void renderPositiveXFacing(IBlockAccess aWorld, RenderBlocks aRenderer, Block aBlock, int aX, int aY, + int aZ, ITexture[] aIcon, boolean aFullBlock) { + if (aWorld != null) { + if (aFullBlock && !aBlock.shouldSideBeRendered(aWorld, aX + 1, aY, aZ, 5)) { + return; + } + + Tessellator.instance + .setBrightness(aBlock.getMixedBrightnessForBlock(aWorld, aFullBlock ? aX + 1 : aX, aY, aZ)); + } + + aRenderer.flipTexture = !aFullBlock; + if (aIcon != null) { + for (ITexture iTexture : aIcon) { + if (iTexture != null) { + iTexture.renderXPos(aRenderer, aBlock, aX, aY, aZ); + } + } + } + + aRenderer.flipTexture = false; + } + + @Override + public void renderInventoryBlock(Block aBlock, int aMeta, int aModelID, RenderBlocks aRenderer) { + aMeta += 30400; + if (aBlock instanceof GT_Block_Machines) { + if (aMeta > 0 && aMeta < GregTech_API.METATILEENTITIES.length + && GregTech_API.METATILEENTITIES[aMeta] != null + && !GregTech_API.METATILEENTITIES[aMeta].renderInInventory(aBlock, aMeta, aRenderer)) { + renderNormalInventoryMetaTileEntity(aBlock, aMeta, aRenderer); + } + } + aBlock.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + aRenderer.setRenderBoundsFromBlock(aBlock); + GL11.glTranslatef(0.5F, 0.5F, 0.5F); + } + + @Override + public boolean renderWorldBlock(IBlockAccess aWorld, int aX, int aY, int aZ, Block aBlock, int aModelID, + RenderBlocks aRenderer) { + TileEntity aTileEntity = aWorld.getTileEntity(aX, aY, aZ); + return aTileEntity == null ? false + : (aTileEntity instanceof IGregTechTileEntity + && ((IGregTechTileEntity) aTileEntity).getMetaTileEntity() != null + && ((IGregTechTileEntity) aTileEntity).getMetaTileEntity() + .renderInWorld(aWorld, aX, aY, aZ, aBlock, aRenderer) + ? true + : (aTileEntity instanceof IPipeRenderedTileEntity + ? renderPipeBlock( + aWorld, + aX, + aY, + aZ, + aBlock, + (IPipeRenderedTileEntity) aTileEntity, + aRenderer) + : renderStandardBlock(aWorld, aX, aY, aZ, aBlock, aRenderer))); + } + + @Override + public boolean shouldRender3DInInventory(int aModel) { + return true; + } + + @Override + public int getRenderId() { + return this.mRenderID; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_ElectricAutoWorkbench.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_ElectricAutoWorkbench.java new file mode 100644 index 0000000000..87ae66b2ad --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_ElectricAutoWorkbench.java @@ -0,0 +1,873 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.automation; + +import java.util.ArrayList; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.oredict.OreDictionary; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.SlotGroup; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; + +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.Textures; +import gregtech.api.enums.Textures.BlockIcons; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.modularui.IAddGregtechLogo; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; +import gregtech.api.objects.GT_ItemStack; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.gui.GTPP_UITextures; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GT_MetaTileEntity_ElectricAutoWorkbench extends GT_MetaTileEntity_BasicTank implements IAddGregtechLogo { + + public int mMode = 0, mCurrentSlot = 0, mThroughPut = 0, mTicksUntilNextUpdate = 20; + public boolean mLastCraftSuccessful = false; + protected String mLocalName; + + private static final int MAX_MODES = 10; + private static final int MAX_THROUGHPUT = 4; + + public GT_MetaTileEntity_ElectricAutoWorkbench(final int aID, final int aTier, final String aDescription) { + super( + aID, + "basicmachine.automation.autoworkbench.0" + aTier, + "Auto Workbench (" + GT_Values.VN[aTier] + ")", + aTier, + 30, + aDescription); + mLocalName = "Auto Workbench (" + GT_Values.VN[aTier] + ")"; + } + + public GT_MetaTileEntity_ElectricAutoWorkbench(final String aName, final int aTier, final String[] aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, 30, aDescription, aTextures); + } + + @Override + public boolean isTransformerUpgradable() { + return true; + } + + @Override + public boolean isOverclockerUpgradable() { + return false; + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isValidSlot(int aIndex) { + return aIndex < 19; + } + + @Override + public boolean isFacingValid(ForgeDirection facing) { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isEnetOutput() { + return true; + } + + @Override + public boolean isInputFacing(ForgeDirection side) { + return !isOutputFacing(side); + } + + @Override + public boolean isOutputFacing(ForgeDirection side) { + return side == getBaseMetaTileEntity().getBackFacing(); + } + + @Override + public boolean isTeleporterCompatible() { + return false; + } + + @Override + public long maxEUInput() { + return GT_Values.V[mTier]; + } + + @Override + public long maxEUOutput() { + return mThroughPut % 2 == 0 ? GT_Values.V[mTier] : 0; + } + + @Override + public long getMinimumStoredEU() { + return GT_Values.V[this.mTier]; + } + + @Override + public long maxEUStore() { + return Math.max(2048L, GT_Values.V[this.mTier] * (this.mTier * GT_Values.V[this.mTier])); + } + + @Override + public int getSizeInventory() { + return 30; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_ElectricAutoWorkbench( + this.mName, + this.mTier, + this.mDescriptionArray, + this.mTextures); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mMode", mMode); + aNBT.setInteger("mThroughPut", mThroughPut); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mMode = aNBT.getInteger("mMode"); + mThroughPut = aNBT.getInteger("mThroughPut"); + } + + @Override + public boolean doesFillContainers() { + return false; + } + + @Override + public boolean doesEmptyContainers() { + return false; + } + + @Override + public boolean canTankBeFilled() { + return true; + } + + @Override + public boolean canTankBeEmptied() { + return true; + } + + @Override + public boolean displaysItemStack() { + return false; + } + + @Override + public boolean displaysStackSize() { + return false; + } + + @Override + public boolean allowCoverOnSide(ForgeDirection side, GT_ItemStack aStack) { + return side != getBaseMetaTileEntity().getFrontFacing() && side != getBaseMetaTileEntity().getBackFacing(); + } + + private void switchMode() { + mInventory[28] = null; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (getBaseMetaTileEntity().isAllowedToWork() && getBaseMetaTileEntity().isServerSide() + && getBaseMetaTileEntity().getUniversalEnergyStored() >= (mMode == 5 || mMode == 6 ? 128 : 2048) + && (getBaseMetaTileEntity().hasWorkJustBeenEnabled() || --mTicksUntilNextUpdate < 1)) { + mTicksUntilNextUpdate = 32; + + for (byte i = 19; i < 28; i++) { + if (mInventory[i] != null && mInventory[i].isItemStackDamageable() + && mInventory[i].getItem() + .hasContainerItem(mInventory[i])) { + mInventory[i].setItemDamage(OreDictionary.WILDCARD_VALUE); + } + } + + if (mInventory[18] == null) { + for (byte i = 0; i < 18 && mFluid != null; i++) { + ItemStack tOutput = GT_Utility.fillFluidContainer(mFluid, mInventory[i], false, true); + if (tOutput != null) { + for (byte j = 0; j < 9; j++) { + if (mInventory[j] == null || (GT_Utility.areStacksEqual(tOutput, mInventory[j]) + && mInventory[j].stackSize + tOutput.stackSize <= tOutput.getMaxStackSize())) { + mFluid.amount -= GT_Utility.getFluidForFilledItem(tOutput, true).amount + * tOutput.stackSize; + getBaseMetaTileEntity().decrStackSize(i, 1); + if (mInventory[j] == null) { + mInventory[j] = tOutput; + } else { + mInventory[j].stackSize++; + } + if (mFluid.amount <= 0) mFluid = null; + break; + } + } + } + } + + ItemStack[] tRecipe = new ItemStack[9]; + ItemStack tTempStack = null, tOutput = null; + + if (mInventory[17] != null && mThroughPut < 2 && mMode != 0) { + if (mInventory[18] == null) { + mInventory[18] = mInventory[17]; + mInventory[17] = null; + } + } else { + if (!mLastCraftSuccessful) { + mCurrentSlot = (mCurrentSlot + 1) % 18; + for (int i = 0; i < 17 && mInventory[mCurrentSlot] == null; i++) + mCurrentSlot = (mCurrentSlot + 1) % 18; + } + switch (mMode) { + case 0 -> { + if (mInventory[mCurrentSlot] != null + && !isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { + if (mInventory[18] == null && mThroughPut < 2 && mCurrentSlot < 8) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + for (int i = 0; i < 9; i++) { + tRecipe[i] = mInventory[i + 19]; + if (tRecipe[i] != null) { + tRecipe[i] = GT_Utility.copy(tRecipe[i]); + tRecipe[i].stackSize = 1; + } + } + } + case 1 -> { + if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { + if (mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); + tTempStack.stackSize = 1; + tRecipe[0] = tTempStack; + if (GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) == null) { + tRecipe[1] = tTempStack; + tRecipe[3] = tTempStack; + tRecipe[4] = tTempStack; + } else break; + if (GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) == null) { + tRecipe[2] = tTempStack; + tRecipe[5] = tTempStack; + tRecipe[6] = tTempStack; + tRecipe[7] = tTempStack; + tRecipe[8] = tTempStack; + } else break; + if (GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) == null) { + if (mInventory[18] == null) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + } + } + case 2 -> { + if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { + if (mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); + tTempStack.stackSize = 1; + tRecipe[0] = tTempStack; + if (GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) == null) { + if (mInventory[18] == null) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + } + } + case 3 -> { + if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { + if (mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); + tTempStack.stackSize = 1; + tRecipe[0] = tTempStack; + tRecipe[1] = tTempStack; + tRecipe[3] = tTempStack; + tRecipe[4] = tTempStack; + if (GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) == null) { + if (mInventory[18] == null) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + } + } + case 4 -> { + if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { + if (mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); + tTempStack.stackSize = 1; + tRecipe[0] = tTempStack; + tRecipe[1] = tTempStack; + tRecipe[2] = tTempStack; + tRecipe[3] = tTempStack; + tRecipe[4] = tTempStack; + tRecipe[5] = tTempStack; + tRecipe[6] = tTempStack; + tRecipe[7] = tTempStack; + tRecipe[8] = tTempStack; + if (GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) == null) { + if (mInventory[18] == null) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + } + } + case 5 -> { + if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { + if (mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); + tTempStack.stackSize = 1; + tRecipe[0] = tTempStack; + tOutput = GT_OreDictUnificator.get(true, tTempStack); + if (tOutput != null && GT_Utility.areStacksEqual(tOutput, tTempStack)) tOutput = null; + if (tOutput == null) { + tRecipe[0] = null; + if (mInventory[18] == null) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + } + } + case 6 -> { + if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { + if (mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + } else if (OrePrefixes.dustSmall.contains(mInventory[mCurrentSlot])) { + tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); + tTempStack.stackSize = 1; + tRecipe[0] = tTempStack; + tRecipe[1] = tTempStack; + tRecipe[3] = tTempStack; + tRecipe[4] = tTempStack; + if (GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) + == null) { + if (mInventory[18] == null) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + } + } else if (OrePrefixes.dustTiny.contains(mInventory[mCurrentSlot])) { + tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); + tTempStack.stackSize = 1; + tRecipe[0] = tTempStack; + tRecipe[1] = tTempStack; + tRecipe[2] = tTempStack; + tRecipe[3] = tTempStack; + tRecipe[4] = tTempStack; + tRecipe[5] = tTempStack; + tRecipe[6] = tTempStack; + tRecipe[7] = tTempStack; + tRecipe[8] = tTempStack; + if (GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) + == null) { + if (mInventory[18] == null) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + } + } else { + if (mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + } + } + case 7 -> { + if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot]) + || !OrePrefixes.nugget.contains(mInventory[mCurrentSlot])) { + if (mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); + tTempStack.stackSize = 1; + tRecipe[0] = tTempStack; + tRecipe[1] = tTempStack; + tRecipe[2] = tTempStack; + tRecipe[3] = tTempStack; + tRecipe[4] = tTempStack; + tRecipe[5] = tTempStack; + tRecipe[6] = tTempStack; + tRecipe[7] = tTempStack; + tRecipe[8] = tTempStack; + if (GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) == null) { + if (mInventory[18] == null) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + } + } + case 8 -> { + if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot]) + || mInventory[mCurrentSlot].getItemDamage() <= 0 + || !mInventory[mCurrentSlot].getItem() + .isRepairable()) { + if (mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + tTempStack = GT_Utility.copy(mInventory[mCurrentSlot]); + tTempStack.stackSize = 1; + for (int i = mCurrentSlot + 1; i < 18; i++) { + if (mInventory[i] != null && mInventory[i].getItem() == tTempStack.getItem() + && mInventory[mCurrentSlot].getItemDamage() + mInventory[i].getItemDamage() + > tTempStack.getMaxDamage()) { + tRecipe[0] = tTempStack; + tRecipe[1] = GT_Utility.copy(mInventory[i]); + if (GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) + == null) { + if (mInventory[18] == null) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + } + break; + } + } + } + case 9 -> { + if (isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(mInventory[mCurrentSlot])) { + if (mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mCurrentSlot]; + mInventory[mCurrentSlot] = null; + mTicksUntilNextUpdate = 1; + } + break; + } + for (byte i = 0, j = 0; i < 18 && j < 9 + && (j < 2 + || GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe) + == null); i++) { + tRecipe[j] = mInventory[(mCurrentSlot + i) % 18]; + if (tRecipe[j] != null) { + tRecipe[j] = GT_Utility.copy(tRecipe[j]); + tRecipe[j].stackSize = 1; + j++; + } + } + if (tRecipe[1] == null) tRecipe[0] = null; + } + } + } + + if (tOutput == null) + tOutput = GT_ModHandler.getAllRecipeOutput(getBaseMetaTileEntity().getWorld(), tRecipe); + + if (tOutput != null || mMode == 0) mInventory[28] = tOutput; + + if (tOutput == null) { + mLastCraftSuccessful = false; + } else { + if ((tTempStack = GT_OreDictUnificator.get(true, tOutput)) != null) { + tTempStack.stackSize = tOutput.stackSize; + tOutput = tTempStack; + } + + mInventory[28] = GT_Utility.copy(tOutput); + ArrayList<ItemStack> tList = recipeContent(tRecipe), tContent = benchContent(); + if (tList.size() > 0 && tContent.size() > 0) { + + boolean success = (mMode == 6 || mMode == 7 || mInventory[17] == null); + for (byte i = 0; i < tList.size() && success; i++) { + success = false; + for (byte j = 0; j < tContent.size() && !success; j++) { + if (GT_Utility.areStacksEqual(tList.get(i), tContent.get(j))) { + if (tList.get(i).stackSize <= tContent.get(j).stackSize) { + success = true; + } + } + } + } + + if (success) { + mLastCraftSuccessful = true; + + for (byte i = 8; i > -1; i--) { + for (byte j = 17; j > -1; j--) { + if (tRecipe[i] != null && mInventory[j] != null) { + if (GT_Utility.areStacksEqual(tRecipe[i], mInventory[j])) { + ItemStack tStack = GT_Utility.getContainerItem(mInventory[j], true); + if (tStack != null) { + getBaseMetaTileEntity().decrStackSize(j, 1); + if (!tStack.isItemStackDamageable() + || tStack.getItemDamage() < tStack.getMaxDamage()) { + for (byte k = 9; k < 18; k++) { + if (mInventory[k] == null) { + mInventory[k] = GT_Utility.copy(tStack); + break; + } else if (GT_Utility.areStacksEqual(mInventory[k], tStack) + && mInventory[k].stackSize + tStack.stackSize + <= tStack.getMaxStackSize()) { + mInventory[k].stackSize += tStack.stackSize; + break; + } + } + } + } else { + getBaseMetaTileEntity().decrStackSize(j, 1); + } + break; + } + } + } + } + + mInventory[18] = GT_Utility.copy(tOutput); + getBaseMetaTileEntity() + .decreaseStoredEnergyUnits(mMode == 5 || mMode == 6 || mMode == 7 ? 128 : 2048, true); + mTicksUntilNextUpdate = 1; + } else { + mLastCraftSuccessful = false; + if (mInventory[mMode == 0 ? 8 : 17] != null && mInventory[18] == null && mThroughPut < 2) { + mInventory[18] = mInventory[mMode == 0 ? 8 : 17]; + mInventory[mMode == 0 ? 8 : 17] = null; + mTicksUntilNextUpdate = 1; + } + } + } + + if (mInventory[18] == null && mThroughPut < 2) { + for (byte i = 0; i < 8; i++) { + for (byte j = i; ++j < 9;) { + if (GT_Utility.areStacksEqual(mInventory[i], mInventory[j]) + && mInventory[i].getMaxStackSize() > 8) { + mInventory[18] = mInventory[j]; + mInventory[j] = null; + mTicksUntilNextUpdate = 1; + break; + } + } + } + } + } + } + + if (mThroughPut < 2) { + getBaseMetaTileEntity().decreaseStoredEnergyUnits( + GT_Utility.moveOneItemStack( + getBaseMetaTileEntity(), + getBaseMetaTileEntity().getIInventoryAtSide(getBaseMetaTileEntity().getBackFacing()), + getBaseMetaTileEntity().getBackFacing(), + getBaseMetaTileEntity().getFrontFacing(), + null, + false, + (byte) 64, + (byte) 1, + (byte) 64, + (byte) 1) * 10, + true); + } + } + } + + private boolean isItemTypeOrItsEmptyLiquidContainerInCraftingGrid(ItemStack aStack) { + if (aStack == null) return true; + for (byte i = 19; i < 28; i++) { + if (mInventory[i] != null) { + if (GT_Utility.areStacksEqual(mInventory[i], aStack)) return true; + if (GT_Utility.areStacksEqual(GT_Utility.getContainerForFilledItem(mInventory[i], true), aStack)) + return true; + } + } + return false; + } + + private ArrayList<ItemStack> recipeContent(ItemStack[] tRecipe) { + ArrayList<ItemStack> tList = new ArrayList<>(); + for (byte i = 0; i < 9; i++) { + if (tRecipe[i] != null) { + boolean temp = false; + for (ItemStack itemStack : tList) { + if (GT_Utility.areStacksEqual(tRecipe[i], itemStack)) { + itemStack.stackSize++; + temp = true; + break; + } + } + if (!temp) tList.add(GT_Utility.copy(1, tRecipe[i])); + } + } + return tList; + } + + private ArrayList<ItemStack> benchContent() { + ArrayList<ItemStack> tList = new ArrayList<>(); + for (byte i = 0; i < 18; i++) { + if (mInventory[i] != null) { + boolean temp = false; + for (byte j = 0; j < tList.size(); j++) { + if (GT_Utility.areStacksEqual(mInventory[i], mInventory[j])) { + tList.get(j).stackSize += mInventory[i].stackSize; + temp = true; + break; + } + } + if (!temp) tList.add(GT_Utility.copy(mInventory[i])); + } + } + return tList; + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return mMode == 0 ? aIndex >= 10 : aIndex >= 18; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return mMode == 0 ? aIndex < 9 : aIndex < 18; + } + + /* + * @Override public int getTextureIndex(byte aSide, byte aFacing, boolean aActive, boolean aRedstone) { if (aSide == + * aFacing) return 112; if (GT_Utility.getOppositeSide(aSide) == aFacing) return 113; return 114; } + */ + + @Override + public int getCapacity() { + return 16000; + } + + @Override + public int getTankPressure() { + return -100; + } + + @Override + public String[] getDescription() { + return new String[] { "Automatic Crafting Table Mk III", + // this.mDescription, + CORE.GT_Tooltip.get() }; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFront(i); + rTextures[6][i + 1] = this.getBack(i); + rTextures[7][i + 1] = this.getBottom(i); + rTextures[8][i + 1] = this.getTop(i); + rTextures[9][i + 1] = this.getSides(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + if (side == facing) { + return this.mTextures[0][aColorIndex + 1]; + } else if (side.getOpposite() == facing) { + return this.mTextures[1][aColorIndex + 1]; + } else { + return this.mTextures[4][aColorIndex + 1]; + } + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Crafting_Overlay) }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(BlockIcons.OVERLAY_PIPE) }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Crafting_Overlay) }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Adv_Workbench_Crafting_Overlay) }; + } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addGregTechLogo(ModularWindow.Builder builder) { + builder.widget( + new DrawableWidget().setDrawable(getGUITextureSet().getGregTechLogo()) + .setSize(17, 17) + .setPos(118, 22)); + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget( + SlotGroup.ofItemHandler(inventoryHandler, 3) + .endAtSlot(8) + .build() + .setPos(7, 4)) + .widget( + SlotGroup.ofItemHandler(inventoryHandler, 9) + .startFromSlot(9) + .endAtSlot(17) + .canInsert(false) + .background(GT_UITextures.SLOT_DARK_GRAY) + .applyForWidget(SlotWidget::disableShiftInsert) + .build() + .setPos(7, 59)) + .widget( + new SlotWidget(inventoryHandler, 18).setAccess(true, false) + .setBackground(getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_OUT) + .setPos(151, 40)) + .widget( + new DrawableWidget().setDrawable(GT_UITextures.PICTURE_SLOTS_HOLO_3BY3) + .setPos(62, 4) + .setSize(54, 54)) + .widget( + SlotGroup.ofItemHandler(inventoryHandler, 3) + .startFromSlot(19) + .endAtSlot(27) + .phantom(true) + .background(GT_UITextures.TRANSPARENT) + .build() + .setPos(62, 4)) + .widget( + SlotWidget.phantom(inventoryHandler, 28) + .disableInteraction() + .setBackground(getGUITextureSet().getItemSlot(), GTPP_UITextures.OVERLAY_SLOT_ARROW_4) + .setPos(151, 4)); + builder.widget( + new CycleButtonWidget().setGetter(() -> mThroughPut) + .setSetter(val -> mThroughPut = val) + .setLength(MAX_THROUGHPUT) + .setTextureGetter(i -> GTPP_UITextures.OVERLAY_BUTTON_THROUGHPUT[i]) + .setBackground(GT_UITextures.BUTTON_STANDARD) + .setPos(120, 4) + .setSize(18, 18)); + String[] mModeText = new String[] { "Normal Crafting Table", "???", "1x1", "2x2", "3x3", "Unifier", "Dust", + "???", "Hammer?", "Circle" }; + CycleButtonWidget modeButton = new CycleButtonWidget().setGetter(() -> mMode) + .setSetter(val -> { + mMode = val; + switchMode(); + }) + .setLength(MAX_MODES) + .setTextureGetter(i -> GTPP_UITextures.OVERLAY_BUTTON_MODE[i]); + for (int i = 0; i < MAX_MODES; i++) { + modeButton.addTooltip(i, "Mode: " + mModeText[i]); + } + builder.widget( + modeButton.setBackground(GT_UITextures.BUTTON_STANDARD) + .setPos(120, 40) + .setSize(18, 18)); + builder.widget( + new DrawableWidget().setDrawable(GTPP_UITextures.PICTURE_WORKBENCH_CIRCLE) + .setPos(136, 23) + .setSize(16, 16)) + .widget( + new DrawableWidget().setDrawable(GTPP_UITextures.PICTURE_ARROW_WHITE_DOWN) + .setPos(155, 23) + .setSize(10, 16)); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_TesseractGenerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_TesseractGenerator.java new file mode 100644 index 0000000000..7fc2b50f68 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_TesseractGenerator.java @@ -0,0 +1,834 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.automation; + +import static gtPlusPlus.core.lib.CORE.sTesseractGeneratorOwnershipMap; +import static gtPlusPlus.core.lib.CORE.sTesseractTerminalOwnershipMap; + +import java.util.UUID; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; + +import org.apache.commons.lang3.ArrayUtils; + +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IDigitalChest; +import gregtech.api.interfaces.tileentity.IGregTechDeviceInformation; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Config; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.common.helpers.tesseract.TesseractHelper; + +public class GT_MetaTileEntity_TesseractGenerator extends GT_MetaTileEntity_BasicTank { + + public static int TESSERACT_ENERGY_COST_DIMENSIONAL = 512; + public static int TESSERACT_ENERGY_COST = 128; + public byte isWorking = 0; + public int oFrequency = 0; + public int mNeededEnergy = 0; + public int mFrequency = 0; + public UUID mOwner; + + public GT_MetaTileEntity_TesseractGenerator(final int aID, final String aName, final String aNameRegional, + final int aTier) { + super(aID, aName, aNameRegional, aTier, 3, ""); + } + + public GT_MetaTileEntity_TesseractGenerator(final String aName, final int aTier, final String[] aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, 3, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_TesseractGenerator(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); + } + + @Override + public boolean isTransformerUpgradable() { + return true; + } + + @Override + public boolean isOverclockerUpgradable() { + return false; + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isFacingValid(final ForgeDirection facing) { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isEnetOutput() { + return false; + } + + @Override + public boolean isInputFacing(final ForgeDirection side) { + return true; + } + + @Override + public boolean isOutputFacing(final ForgeDirection side) { + return side == this.getBaseMetaTileEntity() + .getBackFacing(); + } + + @Override + public boolean isValidSlot(final int aIndex) { + return false; + } + + @Override + public long getMinimumStoredEU() { + return this.getBaseMetaTileEntity() + .getEUCapacity() / 2; + } + + @Override + public long maxEUInput() { + return 512; + } + + @Override + public long maxEUOutput() { + return 0; + } + + @Override + public long maxEUStore() { + return 512 * 32; + } + + @Override + public long maxSteamStore() { + return this.maxEUStore(); + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean ownerControl() { + return true; + } + + @Override + public int getProgresstime() { + return (TesseractHelper.getGeneratorByFrequency(PlayerUtils.getPlayerOnServerFromUUID(mOwner), this.mFrequency) + == this) && (this.isWorking >= 20) ? 999 : 0; + } + + @Override + public int maxProgresstime() { + return 1000; + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setInteger("mFrequency", this.mFrequency); + if (mOwner != null) aNBT.setString("mOwner", mOwner.toString()); + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + this.mFrequency = aNBT.getInteger("mFrequency"); + try { + this.mOwner = UUID.fromString(aNBT.getString("mOnwer")); + } catch (IllegalArgumentException i) { + + } + } + + @Override + public void onConfigLoad(final GT_Config aConfig) { + int J = 4; + TESSERACT_ENERGY_COST = 128 * J; + TESSERACT_ENERGY_COST_DIMENSIONAL = 512 * J; + } + + @Override + public void onServerStart() { + sTesseractGeneratorOwnershipMap.clear(); + sTesseractTerminalOwnershipMap.clear(); + } + + public void onServerStop() { + sTesseractGeneratorOwnershipMap.clear(); + sTesseractTerminalOwnershipMap.clear(); + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer, + final ForgeDirection side, final float aX, final float aY, final float aZ) { + + if (this.mOwner == null) { + if (this.getBaseMetaTileEntity() + .getOwnerName() != null + && !this.getBaseMetaTileEntity() + .getOwnerName() + .equals("")) { + if (this.getBaseMetaTileEntity() + .getOwnerName() + .toLowerCase() + .equals( + aPlayer.getDisplayName() + .toLowerCase())) { + this.mOwner = PlayerUtils.getPlayersUUIDByName( + this.getBaseMetaTileEntity() + .getOwnerName()); + } + } + } + + if (side == this.getBaseMetaTileEntity() + .getFrontFacing()) { + if (aPlayer.getUniqueID() + .compareTo(this.mOwner) == 0) { + final float[] tCoords = GT_Utility.getClickedFacingCoords(side, aX, aY, aZ); + switch ((byte) ((byte) (int) (tCoords[0] * 2.0F) + (2 * (byte) (int) (tCoords[1] * 2.0F)))) { + case 0: + Logger.WARNING("Freq. -1 | " + this.mFrequency); + try { + CORE.sTesseractGeneratorOwnershipMap.get(mOwner) + .remove(this.mFrequency); + } catch (Throwable t) {} + this.mFrequency -= 1; + + break; + case 1: + Logger.WARNING("Freq. +1 | " + this.mFrequency); + try { + CORE.sTesseractGeneratorOwnershipMap.get(mOwner) + .remove(this.mFrequency); + } catch (Throwable t) {} + this.mFrequency += 1; + default: + // Utils.LOG_WARNING("Did not click the correct place."); + break; + } + if (getGeneratorEntity(this.mFrequency) != null && getGeneratorEntity(this.mFrequency) != this) { + GT_Utility.sendChatToPlayer( + aPlayer, + "Frequency: " + this.mFrequency + EnumChatFormatting.RED + " (Occupied)"); + } else { + GT_Utility.sendChatToPlayer(aPlayer, "Frequency: " + this.mFrequency); + } + } else if (aPlayer.getUniqueID() + .compareTo(this.mOwner) != 0) { + GT_Utility.sendChatToPlayer(aPlayer, "This is not your Tesseract Generator to configure."); + } + } + + return true; + } + + @Override + public void onScrewdriverRightClick(final ForgeDirection side, final EntityPlayer aPlayer, final float aX, + final float aY, final float aZ) { + if (aPlayer.getUniqueID() + .compareTo(this.mOwner) == 0) { + if (side == this.getBaseMetaTileEntity() + .getFrontFacing()) { + final float[] tCoords = GT_Utility.getClickedFacingCoords(side, aX, aY, aZ); + switch ((byte) ((byte) (int) (tCoords[0] * 2.0F) + (2 * (byte) (int) (tCoords[1] * 2.0F)))) { + case 0 -> { + try { + CORE.sTesseractGeneratorOwnershipMap.get(mOwner) + .remove(this.mFrequency); + } catch (Throwable t) {} + this.mFrequency -= 64; + } + case 1 -> { + try { + CORE.sTesseractGeneratorOwnershipMap.get(mOwner) + .remove(this.mFrequency); + } catch (Throwable t) {} + this.mFrequency += 64; + } + case 2 -> { + try { + CORE.sTesseractGeneratorOwnershipMap.get(mOwner) + .remove(this.mFrequency); + } catch (Throwable t) {} + this.mFrequency -= 512; + } + case 3 -> { + try { + CORE.sTesseractGeneratorOwnershipMap.get(mOwner) + .remove(this.mFrequency); + } catch (Throwable t) {} + this.mFrequency += 512; + } + } + if (getGeneratorEntity(this.mFrequency) != null && getGeneratorEntity(this.mFrequency) != this) { + GT_Utility.sendChatToPlayer( + aPlayer, + "Frequency: " + this.mFrequency + EnumChatFormatting.RED + " (Occupied)"); + } else { + GT_Utility.sendChatToPlayer(aPlayer, "Frequency: " + this.mFrequency); + } + } + } else { + GT_Utility.sendChatToPlayer(aPlayer, "This is not your Tesseract Generator to configure."); + } + } + + public boolean allowCoverOnSide(final ForgeDirection side, final int aCoverID) { + return side != this.getBaseMetaTileEntity() + .getFrontFacing(); + } + + @Override + public String[] getInfoData() { + final TileEntity tTileEntity = this.getBaseMetaTileEntity() + .getTileEntityAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity != null) && (this.getBaseMetaTileEntity() + .isAllowedToWork()) + && ((tTileEntity instanceof IGregTechDeviceInformation)) + && (((IGregTechDeviceInformation) tTileEntity).isGivingInformation())) { + return ((IGregTechDeviceInformation) tTileEntity).getInfoData(); + } + return new String[] { "Tesseract Generator", "Freqency:", "" + this.mFrequency, + (getGeneratorEntity() == this) && (this.isWorking >= 20) ? "Active" : "Inactive" }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + public boolean isSendingInformation() { + final TileEntity tTileEntity = this.getBaseMetaTileEntity() + .getTileEntityAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity != null) && (this.getBaseMetaTileEntity() + .isAllowedToWork()) && ((tTileEntity instanceof IGregTechDeviceInformation))) { + return ((IGregTechDeviceInformation) tTileEntity).isGivingInformation(); + } + return false; + } + + @Override + public boolean isDigitalChest() { + final TileEntity tTileEntity = this.getBaseMetaTileEntity() + .getTileEntityAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity != null) && (this.getBaseMetaTileEntity() + .isAllowedToWork()) && ((tTileEntity instanceof IDigitalChest))) { + return ((IDigitalChest) tTileEntity).isDigitalChest(); + } + return false; + } + + @Override + public ItemStack[] getStoredItemData() { + final TileEntity tTileEntity = this.getBaseMetaTileEntity() + .getTileEntityAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity != null) && (this.getBaseMetaTileEntity() + .isAllowedToWork()) && ((tTileEntity instanceof IDigitalChest))) { + return ((IDigitalChest) tTileEntity).getStoredItemData(); + } + return new ItemStack[] {}; + } + + @Override + public void setItemCount(final int aCount) { + final TileEntity tTileEntity = this.getBaseMetaTileEntity() + .getTileEntityAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity != null) && (this.getBaseMetaTileEntity() + .isAllowedToWork()) && ((tTileEntity instanceof IDigitalChest))) { + ((IDigitalChest) tTileEntity).setItemCount(aCount); + } + } + + @Override + public int getMaxItemCount() { + final TileEntity tTileEntity = this.getBaseMetaTileEntity() + .getTileEntityAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity != null) && (this.getBaseMetaTileEntity() + .isAllowedToWork()) && ((tTileEntity instanceof IDigitalChest))) { + return ((IDigitalChest) tTileEntity).getMaxItemCount(); + } + return 0; + } + + @Override + public boolean isItemValidForSlot(final int aIndex, final ItemStack aStack) { + final IInventory tTileEntity = this.getBaseMetaTileEntity() + .getIInventoryAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return false; + } + return tTileEntity.isItemValidForSlot(aIndex, aStack); + } + + @Override + public int[] getAccessibleSlotsFromSide(final int ordinalSide) { + final IInventory tTileEntity = this.getBaseMetaTileEntity() + .getIInventoryAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return new int[0]; + } + if ((tTileEntity instanceof ISidedInventory)) { + return ((ISidedInventory) tTileEntity).getAccessibleSlotsFromSide(ordinalSide); + } + final int[] rArray = new int[this.getSizeInventory()]; + for (int i = 0; i < this.getSizeInventory(); i++) { + rArray[i] = i; + } + return rArray; + } + + @Override + public boolean canInsertItem(final int aIndex, final ItemStack aStack, final int ordinalSide) { + final IInventory tTileEntity = this.getBaseMetaTileEntity() + .getIInventoryAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return false; + } + if ((tTileEntity instanceof ISidedInventory)) { + return ((ISidedInventory) tTileEntity).canInsertItem(aIndex, aStack, ordinalSide); + } + return true; + } + + @Override + public boolean canExtractItem(final int aIndex, final ItemStack aStack, final int ordinalSide) { + final IInventory tTileEntity = this.getBaseMetaTileEntity() + .getIInventoryAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return false; + } + if ((tTileEntity instanceof ISidedInventory)) { + return ((ISidedInventory) tTileEntity).canExtractItem(aIndex, aStack, ordinalSide); + } + return true; + } + + @Override + public int getSizeInventory() { + final IInventory tTileEntity = this.getBaseMetaTileEntity() + .getIInventoryAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return 0; + } + return tTileEntity.getSizeInventory(); + } + + @Override + public ItemStack getStackInSlot(final int aIndex) { + final IInventory tTileEntity = this.getBaseMetaTileEntity() + .getIInventoryAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return null; + } + return tTileEntity.getStackInSlot(aIndex); + } + + @Override + public void setInventorySlotContents(final int aIndex, final ItemStack aStack) { + final IInventory tTileEntity = this.getBaseMetaTileEntity() + .getIInventoryAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return; + } + tTileEntity.setInventorySlotContents(aIndex, aStack); + } + + @Override + public ItemStack decrStackSize(final int aIndex, final int aAmount) { + final IInventory tTileEntity = this.getBaseMetaTileEntity() + .getIInventoryAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return null; + } + return tTileEntity.decrStackSize(aIndex, aAmount); + } + + @Override + public String getInventoryName() { + final IInventory tTileEntity = this.getBaseMetaTileEntity() + .getIInventoryAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return ""; + } + return tTileEntity.getInventoryName(); + } + + @Override + public int getInventoryStackLimit() { + final IInventory tTileEntity = this.getBaseMetaTileEntity() + .getIInventoryAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return 0; + } + return tTileEntity.getInventoryStackLimit(); + } + + @Override + public boolean canFill(final ForgeDirection aSide, final Fluid aFluid) { + final IFluidHandler tTileEntity = this.getBaseMetaTileEntity() + .getITankContainerAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return false; + } + return tTileEntity.canFill(aSide, aFluid); + } + + @Override + public boolean canDrain(final ForgeDirection aSide, final Fluid aFluid) { + final IFluidHandler tTileEntity = this.getBaseMetaTileEntity() + .getITankContainerAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return false; + } + return tTileEntity.canDrain(aSide, aFluid); + } + + @Override + public FluidTankInfo[] getTankInfo(final ForgeDirection aSide) { + final IFluidHandler tTileEntity = this.getBaseMetaTileEntity() + .getITankContainerAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return new FluidTankInfo[0]; + } + return tTileEntity.getTankInfo(aSide); + } + + @Override + public int fill_default(final ForgeDirection aDirection, final FluidStack aFluid, final boolean doFill) { + final IFluidHandler tTileEntity = this.getBaseMetaTileEntity() + .getITankContainerAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return 0; + } + return tTileEntity.fill(aDirection, aFluid, doFill); + } + + @Override + public FluidStack drain(final ForgeDirection aDirection, final int maxDrain, final boolean doDrain) { + final IFluidHandler tTileEntity = this.getBaseMetaTileEntity() + .getITankContainerAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return null; + } + return tTileEntity.drain(aDirection, maxDrain, doDrain); + } + + @Override + public FluidStack drain(final ForgeDirection aSide, final FluidStack aFluid, final boolean doDrain) { + final IFluidHandler tTileEntity = this.getBaseMetaTileEntity() + .getITankContainerAtSide( + this.getBaseMetaTileEntity() + .getBackFacing()); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return null; + } + return tTileEntity.drain(aSide, aFluid, doDrain); + } + + public boolean addEnergyConsumption(final GT_MetaTileEntity_TesseractTerminal aTerminal) { + if (!this.getBaseMetaTileEntity() + .isAllowedToWork()) { + return false; + } + int J = (aTerminal.getBaseMetaTileEntity() + .getWorld() + == this.getBaseMetaTileEntity() + .getWorld() ? TESSERACT_ENERGY_COST : TESSERACT_ENERGY_COST_DIMENSIONAL); + + J *= 4; + + this.mNeededEnergy += J; + + return true; + } + + public boolean isValidTesseractGenerator(final String aOwnerName, final boolean aWorkIrrelevant) { + return (this.getBaseMetaTileEntity() != null) && (!this.getBaseMetaTileEntity() + .isInvalidTileEntity()) + && (this.getBaseMetaTileEntity() + .isAllowedToWork()) + && ((aOwnerName == null) || (this.getBaseMetaTileEntity() + .getOwnerName() + .equals(aOwnerName))) + && ((aWorkIrrelevant) || (this.isWorking >= 20)); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + // TODO Auto-generated method stub + super.onPreTick(aBaseMetaTileEntity, aTick); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + // Utils.LOG_WARNING("Ticking Generator. 0"); + if (this.getBaseMetaTileEntity() + .isServerSide()) { + // Utils.LOG_WARNING("Ticking Generator."); + // Set owner + if (PlayerUtils.getPlayersUUIDByName( + this.getBaseMetaTileEntity() + .getOwnerName()) + != null) { + if (this.mOwner == null) { + Logger.WARNING("Setting Generators Owner. 1"); + this.mOwner = PlayerUtils.getPlayersUUIDByName( + this.getBaseMetaTileEntity() + .getOwnerName()); + } + } + + if (this.mFrequency != this.oFrequency) { + + Logger.WARNING("mFreq != oFreq"); + + if (getGeneratorEntity() == this) { + getGeneratorEntity(this.oFrequency); + this.getBaseMetaTileEntity() + .issueBlockUpdate(); + Logger.WARNING("this Gen == oFreq on map - do block update"); + } + Logger.WARNING("mFreq will be set to oFreq"); + this.oFrequency = this.mFrequency; + } + if ((this.getBaseMetaTileEntity() + .isAllowedToWork()) + && (this.getBaseMetaTileEntity() + .decreaseStoredEnergyUnits(this.mNeededEnergy, false))) { + // Utils.LOG_WARNING("Can Work & Has Energy"); + if ((getGeneratorEntity(Integer.valueOf(this.mFrequency)) == null) + || (!getGeneratorEntity(Integer.valueOf(this.mFrequency)).isValidTesseractGenerator(null, true))) { + // Utils.LOG_WARNING("storing TE I think to mFreq map?"); + TesseractHelper.setGeneratorOwnershipByPlayer( + PlayerUtils.getPlayerOnServerFromUUID(mOwner), + this.mFrequency, + this); + } + } else { + if (getGeneratorEntity(Integer.valueOf(this.mFrequency)) == this) { + Logger.WARNING("this gen == mFreq on map - do block update"); + TesseractHelper.removeGenerator(PlayerUtils.getPlayerOnServerFromUUID(mOwner), this.mFrequency); + this.getBaseMetaTileEntity() + .issueBlockUpdate(); + } + this.isWorking = 0; + } + if (getGeneratorEntity(Integer.valueOf(this.mFrequency)) == this) { + // Utils.LOG_WARNING("mFreq == this - do work related things"); + if (this.isWorking < 20) { + this.isWorking = ((byte) (this.isWorking + 1)); + } + if (this.isWorking == 20) { + this.getBaseMetaTileEntity() + .issueBlockUpdate(); + this.isWorking = ((byte) (this.isWorking + 1)); + } + } else { + this.isWorking = 0; + } + this.mNeededEnergy = 0; + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public String[] getDescription() { + return ArrayUtils.addAll( + this.mDescriptionArray, + "Generates a Tesseract for the attached Inventory", + "Connect with pipes to insert items", + "Consumes " + TESSERACT_ENERGY_COST + "EU/t for same dimension transfers", + "Consumes " + TESSERACT_ENERGY_COST_DIMENSIONAL + "EU/t for cross dimensional transfers", + CORE.GT_Tooltip.get()); + } + + @Override + public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + return false; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + return new ITexture[0][0][0]; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + return side == facing + ? new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Dimensional), + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_Frequency) } + : new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Dimensional), + new GT_RenderedTexture(Textures.BlockIcons.VOID) }; + } + + // To-Do? + @Override + public boolean doesFillContainers() { + return false; + } + + @Override + public boolean doesEmptyContainers() { + return false; + } + + @Override + public boolean canTankBeFilled() { + return false; + } + + @Override + public boolean canTankBeEmptied() { + return false; + } + + @Override + public boolean displaysItemStack() { + return false; + } + + @Override + public boolean displaysStackSize() { + return false; + } + + private GT_MetaTileEntity_TesseractGenerator getGeneratorEntity() { + GT_MetaTileEntity_TesseractGenerator thisGenerator = TesseractHelper + .getGeneratorByFrequency(PlayerUtils.getPlayerOnServerFromUUID(mOwner), this.mFrequency); + if (thisGenerator != null) { + return thisGenerator; + } + return null; + } + + private GT_MetaTileEntity_TesseractGenerator getGeneratorEntity(int frequency) { + GT_MetaTileEntity_TesseractGenerator thisGenerator = TesseractHelper + .getGeneratorByFrequency(PlayerUtils.getPlayerOnServerFromUUID(mOwner), frequency); + if (thisGenerator != null) { + return thisGenerator; + } + return null; + } + + @Override + public void onCreated(ItemStack aStack, World aWorld, EntityPlayer aPlayer) { + if (this.getBaseMetaTileEntity() + .getOwnerName() != null + && !this.getBaseMetaTileEntity() + .getOwnerName() + .equals("")) { + this.mOwner = PlayerUtils.getPlayersUUIDByName( + this.getBaseMetaTileEntity() + .getOwnerName()); + Logger.WARNING("Setting Generators Owner. 2"); + } + super.onCreated(aStack, aWorld, aPlayer); + } + + @Override + public void onRemoval() { + try { + CORE.sTesseractGeneratorOwnershipMap.get(mOwner) + .remove(this.mFrequency); + } catch (Throwable t) {} + super.onRemoval(); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_TesseractTerminal.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_TesseractTerminal.java new file mode 100644 index 0000000000..659f34e0d8 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/automation/GT_MetaTileEntity_TesseractTerminal.java @@ -0,0 +1,644 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.automation; + +import java.util.UUID; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; + +import org.apache.commons.lang3.ArrayUtils; + +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Config; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.common.helpers.tesseract.TesseractHelper; + +public class GT_MetaTileEntity_TesseractTerminal extends GT_MetaTileEntity_BasicTank { + + public int mFrequency = 0; + public UUID mOwner; + public boolean mDidWork = false; + public static boolean sInterDimensionalTesseractAllowed = true; + private static int TESSERACT_ENERGY_COST = 128; + private static int TESSERACT_ENERGY_COST_DIMENSIONAL = 512; + + public GT_MetaTileEntity_TesseractTerminal(final int aID, final String aName, final String aNameRegional, + final int aTier) { + super(aID, aName, aNameRegional, aTier, 3, ""); + } + + public GT_MetaTileEntity_TesseractTerminal(final String aName, final int aTier, final String[] aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, 3, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_TesseractTerminal(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); + } + + @Override + public boolean isTransformerUpgradable() { + return false; + } + + @Override + public boolean isOverclockerUpgradable() { + return false; + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isFacingValid(final ForgeDirection facing) { + return true; + } + + @Override + public boolean isOutputFacing(final ForgeDirection side) { + return side == this.getBaseMetaTileEntity() + .getBackFacing(); + } + + @Override + public boolean isValidSlot(final int aIndex) { + return false; + } + + @Override + public long getMinimumStoredEU() { + return (this.getBaseMetaTileEntity() + .getEUCapacity() / 100); + } + + @Override + public long maxEUInput() { + return TESSERACT_ENERGY_COST_DIMENSIONAL; + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public long maxEUStore() { + return TESSERACT_ENERGY_COST_DIMENSIONAL * 8 * 32; + } + + @Override + public long maxSteamStore() { + return this.maxEUStore(); + } + + @Override + public boolean ownerControl() { + return true; + } + + @Override + public int getProgresstime() { + return this.getTesseract(this.mFrequency, false) != null ? 999 : 0; + } + + @Override + public int maxProgresstime() { + return 1000; + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setInteger("mFrequency", this.mFrequency); + aNBT.setString("mOwner", mOwner.toString()); + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + this.mFrequency = aNBT.getInteger("mFrequency"); + this.mOwner = UUID.fromString(aNBT.getString("mOnwer")); + } + + @Override + public void onConfigLoad(final GT_Config aConfig) { + sInterDimensionalTesseractAllowed = true; + TESSERACT_ENERGY_COST = 512; + TESSERACT_ENERGY_COST_DIMENSIONAL = 2048; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer, + final ForgeDirection side, final float aX, final float aY, final float aZ) { + + if (this.mOwner == null) { + if (this.getBaseMetaTileEntity() + .getOwnerName() != null + && !this.getBaseMetaTileEntity() + .getOwnerName() + .equals("")) { + if (this.getBaseMetaTileEntity() + .getOwnerName() + .toLowerCase() + .equals( + aPlayer.getDisplayName() + .toLowerCase())) { + this.mOwner = PlayerUtils.getPlayersUUIDByName( + this.getBaseMetaTileEntity() + .getOwnerName()); + } + } + } + + if (aPlayer.getUniqueID() + .compareTo(this.mOwner) == 0) { + if (side == this.getBaseMetaTileEntity() + .getFrontFacing()) { + final float[] tCoords = GT_Utility.getClickedFacingCoords(side, aX, aY, aZ); + switch ((byte) ((byte) (int) (tCoords[0] * 2.0F) + (2 * (byte) (int) (tCoords[1] * 2.0F)))) { + case 0: + // Utils.LOG_WARNING("Freq. -1 | " + this.mFrequency); + try { + CORE.sTesseractTerminalOwnershipMap.get(mOwner) + .remove(this.mFrequency); + } catch (Throwable t) {} + this.mFrequency -= 1; + break; + case 1: + // Utils.LOG_WARNING("Freq. +1 | " + this.mFrequency); + try { + CORE.sTesseractTerminalOwnershipMap.get(mOwner) + .remove(this.mFrequency); + } catch (Throwable t) {} + this.mFrequency += 1; + default: + // Utils.LOG_WARNING("Did not click the correct place."); + try { + CORE.sTesseractTerminalOwnershipMap.get(mOwner) + .remove(this.mFrequency); + } catch (Throwable t) {} + break; + } + PlayerUtils.messagePlayer(aPlayer, "Frequency: " + this.mFrequency); + if (this.getTesseract(this.mFrequency, false) != null) { + PlayerUtils.messagePlayer( + aPlayer, + new StringBuilder().append(EnumChatFormatting.GREEN) + .append(" (Connected)") + .toString()); + } + } + } else if (aPlayer.getUniqueID() + .compareTo(this.mOwner) != 0) { + GT_Utility.sendChatToPlayer(aPlayer, "This is not your Tesseract Terminal to configure."); + } + return true; + } + + @Override + public void onScrewdriverRightClick(final ForgeDirection side, final EntityPlayer aPlayer, final float aX, + final float aY, final float aZ) { + if (aPlayer.getUniqueID() + .compareTo(this.mOwner) == 0) { + if (side == this.getBaseMetaTileEntity() + .getFrontFacing()) { + final float[] tCoords = GT_Utility.getClickedFacingCoords(side, aX, aY, aZ); + switch ((byte) ((byte) (int) (tCoords[0] * 2.0F) + (2 * (byte) (int) (tCoords[1] * 2.0F)))) { + case 0 -> { + try { + CORE.sTesseractTerminalOwnershipMap.get(mOwner) + .remove(this.mFrequency); + } catch (Throwable t) {} + this.mFrequency -= 64; + } + case 1 -> { + try { + CORE.sTesseractTerminalOwnershipMap.get(mOwner) + .remove(this.mFrequency); + } catch (Throwable t) {} + this.mFrequency += 64; + } + case 2 -> { + try { + CORE.sTesseractTerminalOwnershipMap.get(mOwner) + .remove(this.mFrequency); + } catch (Throwable t) {} + this.mFrequency -= 512; + } + case 3 -> { + try { + CORE.sTesseractTerminalOwnershipMap.get(mOwner) + .remove(this.mFrequency); + } catch (Throwable t) {} + this.mFrequency += 512; + } + } + GT_Utility.sendChatToPlayer( + aPlayer, + "Frequency: " + this.mFrequency + + (this.getTesseract(this.mFrequency, false) == null ? "" + : new StringBuilder().append(EnumChatFormatting.GREEN) + .append(" (Connected)") + .toString())); + } + } else if (aPlayer.getUniqueID() + .compareTo(this.mOwner) != 0) { + GT_Utility.sendChatToPlayer(aPlayer, "This is not your Tesseract Terminal to configure."); + } + } + + public boolean allowCoverOnSide(final ForgeDirection side, final int aCoverID) { + return side != this.getBaseMetaTileEntity() + .getFrontFacing(); + } + + public GT_MetaTileEntity_TesseractGenerator getTesseract(final int aFrequency, final boolean aWorkIrrelevant) { + final GT_MetaTileEntity_TesseractGenerator rTesseract = TesseractHelper + .getGeneratorByFrequency(PlayerUtils.getPlayerOnServerFromUUID(mOwner), aFrequency); + if (rTesseract == null) { + return null; + } + if (!TesseractHelper.isGeneratorOwnedByPlayer(PlayerUtils.getPlayerOnServerFromUUID(mOwner), rTesseract)) { + return null; + } + if (rTesseract.mFrequency != aFrequency) { + TesseractHelper.setTerminalOwnershipByPlayer( + PlayerUtils.getPlayerOnServerFromUUID(mOwner), + Integer.valueOf(aFrequency), + null); + return null; + } + if (!rTesseract.isValidTesseractGenerator( + this.getBaseMetaTileEntity() + .getOwnerName(), + aWorkIrrelevant)) { + return null; + } + if ((!sInterDimensionalTesseractAllowed) && (rTesseract.getBaseMetaTileEntity() + .getWorld() + != this.getBaseMetaTileEntity() + .getWorld())) { + return null; + } + return rTesseract; + } + + @Override + public String[] getInfoData() { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity != null) && (this.getBaseMetaTileEntity() + .isAllowedToWork()) && (tTileEntity.isSendingInformation())) { + return tTileEntity.getInfoData(); + } + return new String[] { "Tesseract Generator", "Freqency:", "" + this.mFrequency, + this.getTesseract(this.mFrequency, false) != null ? "Active" : "Inactive" }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public boolean isDigitalChest() { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return false; + } + return tTileEntity.isDigitalChest(); + } + + @Override + public ItemStack[] getStoredItemData() { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return null; + } + return tTileEntity.getStoredItemData(); + } + + @Override + public void setItemCount(final int aCount) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return; + } + tTileEntity.setItemCount(aCount); + } + + @Override + public int getMaxItemCount() { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return 0; + } + return tTileEntity.getMaxItemCount(); + } + + @Override + public boolean isItemValidForSlot(final int aIndex, final ItemStack aStack) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return false; + } + return tTileEntity.isItemValidForSlot(aIndex, aStack); + } + + @Override + public int[] getAccessibleSlotsFromSide(final int ordinalSide) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return new int[0]; + } + return tTileEntity.getAccessibleSlotsFromSide(ordinalSide); + } + + @Override + public boolean canInsertItem(final int aIndex, final ItemStack aStack, final int ordinalSide) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return false; + } + return tTileEntity.canInsertItem(aIndex, aStack, ordinalSide); + } + + @Override + public boolean canExtractItem(final int aIndex, final ItemStack aStack, final int ordinalSide) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return false; + } + return tTileEntity.canExtractItem(aIndex, aStack, ordinalSide); + } + + @Override + public int getSizeInventory() { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return 0; + } + return tTileEntity.getSizeInventory(); + } + + @Override + public ItemStack getStackInSlot(final int aIndex) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return null; + } + return tTileEntity.getStackInSlot(aIndex); + } + + @Override + public void setInventorySlotContents(final int aIndex, final ItemStack aStack) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return; + } + tTileEntity.setInventorySlotContents(aIndex, aStack); + } + + @Override + public ItemStack decrStackSize(final int aIndex, final int aAmount) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return null; + } + return tTileEntity.decrStackSize(aIndex, aAmount); + } + + @Override + public String getInventoryName() { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return ""; + } + return tTileEntity.getInventoryName(); + } + + @Override + public int getInventoryStackLimit() { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return 0; + } + return tTileEntity.getInventoryStackLimit(); + } + + @Override + public boolean canFill(final ForgeDirection aSide, final Fluid aFluid) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return false; + } + return tTileEntity.canFill(aSide, aFluid); + } + + @Override + public boolean canDrain(final ForgeDirection aSide, final Fluid aFluid) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return false; + } + return tTileEntity.canDrain(aSide, aFluid); + } + + @Override + public FluidTankInfo[] getTankInfo(final ForgeDirection aSide) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return new FluidTankInfo[0]; + } + return tTileEntity.getTankInfo(aSide); + } + + @Override + public int fill_default(final ForgeDirection aDirection, final FluidStack aFluid, final boolean doFill) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return 0; + } + return tTileEntity.fill(aDirection, aFluid, doFill); + } + + @Override + public FluidStack drain(final ForgeDirection aDirection, final int maxDrain, final boolean doDrain) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return null; + } + return tTileEntity.drain(aDirection, maxDrain, doDrain); + } + + @Override + public FluidStack drain(final ForgeDirection aSide, final FluidStack aFluid, final boolean doDrain) { + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, false); + if ((tTileEntity == null) || (!this.getBaseMetaTileEntity() + .isAllowedToWork())) { + return null; + } + return tTileEntity.drain(aSide, aFluid, doDrain); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if ((this.getBaseMetaTileEntity() + .isServerSide()) + && (this.getBaseMetaTileEntity() + .isAllowedToWork())) { + // Set owner + if (PlayerUtils.getPlayersUUIDByName( + this.getBaseMetaTileEntity() + .getOwnerName()) + != null) { + if (this.mOwner == null) { + this.mOwner = PlayerUtils.getPlayersUUIDByName( + this.getBaseMetaTileEntity() + .getOwnerName()); + } + } + final GT_MetaTileEntity_TesseractGenerator tTileEntity = this.getTesseract(this.mFrequency, true); + if (tTileEntity != null) { + tTileEntity.addEnergyConsumption(this); + if ((!this.mDidWork) && (this.getTesseract(this.mFrequency, false) != null)) { + this.mDidWork = true; + this.getBaseMetaTileEntity() + .issueBlockUpdate(); + this.getBaseMetaTileEntity() + .decreaseStoredEnergyUnits(128, false); + } + } else if (this.mDidWork == true) { + this.mDidWork = false; + this.getBaseMetaTileEntity() + .issueBlockUpdate(); + } + } + } + + @Override + public String[] getDescription() { + return ArrayUtils.addAll( + this.mDescriptionArray, + "Accesses Tesseract Generators remotely", + "Connect with pipes to extract items or fluids", + "Outputs from the back face", + "Consumes " + TESSERACT_ENERGY_COST + "EU/t for same dimension transfers", + "Consumes " + TESSERACT_ENERGY_COST_DIMENSIONAL + "EU/t for cross dimensional transfers", + CORE.GT_Tooltip.get()); + } + + @Override + public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + return false; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + return new ITexture[0][0][0]; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + return side == facing + ? new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Dimensional), + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_Frequency) } + : new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Dimensional), + new GT_RenderedTexture(Textures.BlockIcons.VOID) }; + } + + // To-Do? + @Override + public boolean doesFillContainers() { + return false; + } + + @Override + public boolean doesEmptyContainers() { + return false; + } + + @Override + public boolean canTankBeFilled() { + return false; + } + + @Override + public boolean canTankBeEmptied() { + return false; + } + + @Override + public boolean displaysItemStack() { + return false; + } + + @Override + public boolean displaysStackSize() { + return false; + } + + @Override + public void onCreated(ItemStack aStack, World aWorld, EntityPlayer aPlayer) { + if (this.getBaseMetaTileEntity() + .getOwnerName() != null + && !this.getBaseMetaTileEntity() + .getOwnerName() + .equals("")) { + this.mOwner = PlayerUtils.getPlayersUUIDByName( + this.getBaseMetaTileEntity() + .getOwnerName()); + } + super.onCreated(aStack, aWorld, aPlayer); + } + + @Override + public void onRemoval() { + try { + CORE.sTesseractTerminalOwnershipMap.get(mOwner) + .remove(this.mFrequency); + } catch (Throwable t) {} + super.onRemoval(); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_Base.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_Base.java new file mode 100644 index 0000000000..b27c1a759a --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_Base.java @@ -0,0 +1,333 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.generators; + +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntityFurnace; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidTankInfo; + +import org.apache.commons.lang3.ArrayUtils; + +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.drawable.UITexture; + +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.Textures; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.gui.modularui.GUITextureSet; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.objects.GT_ItemStack; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.common.tileentities.boilers.GT_MetaTileEntity_Boiler; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.gui.GTPP_UITextures; + +public class GT_MetaTileEntity_Boiler_Base extends GT_MetaTileEntity_Boiler { + + private final int steamPerSecond; + private final int tier; + + public GT_MetaTileEntity_Boiler_Base(int aID, String aNameRegional, int tier) { + super( + aID, + "electricboiler." + tier + ".tier.single", + aNameRegional, + "Produces " + (CORE.ConfigSwitches.boilerSteamPerSecond * tier) + "L of Steam per second"); + this.steamPerSecond = (CORE.ConfigSwitches.boilerSteamPerSecond * tier); + this.tier = tier; + } + + public GT_MetaTileEntity_Boiler_Base(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + this.steamPerSecond = (CORE.ConfigSwitches.boilerSteamPerSecond * aTier); + this.tier = aTier; + } + + @Override + public String[] getDescription() { + return ArrayUtils.addAll( + this.mDescriptionArray, + "Produces " + getPollution() + " pollution/sec", + "Consumes fuel only when temperature is less than 100C", + "Fuel with burn time greater than 500 is more efficient.", + "Doesn't explode if there's no water", + CORE.GT_Tooltip.get()); + } + + public ITexture getOverlayIcon() { + return new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT); + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + protected GT_RenderedTexture getCasingTexture() { + if (this.tier == 1) { + return new GT_RenderedTexture(Textures.BlockIcons.MACHINE_LV_SIDE); + } else if (this.tier == 2) { + return new GT_RenderedTexture(Textures.BlockIcons.MACHINE_MV_SIDE); + } else { + return new GT_RenderedTexture(Textures.BlockIcons.MACHINE_HV_SIDE); + } + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + return this.mTextures[(aActive ? 5 : 0) + (side == facing ? 0 + : side == facing.getOpposite() ? 1 + : side == ForgeDirection.DOWN ? 2 : side == ForgeDirection.UP ? 3 : 4)][aColorIndex + 1]; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.tier][aColor + 1], this.getCasingTexture() }; + } + + public ITexture[] getBack(final byte aColor) { + return this.getSides(aColor); + } + + public ITexture[] getBottom(final byte aColor) { + return this.getSides(aColor); + } + + public ITexture[] getTop(final byte aColor) { + return this.getSides(aColor); + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.tier][aColor + 1], this.getCasingTexture() }; + } + + public ITexture[] getFrontActive(final byte aColor) { + return this.getFront(aColor); + } + + public ITexture[] getBackActive(final byte aColor) { + return this.getSides(aColor); + } + + public ITexture[] getBottomActive(final byte aColor) { + return this.getBottom(aColor); + } + + public ITexture[] getTopActive(final byte aColor) { + return this.getTop(aColor); + } + + public ITexture[] getSidesActive(final byte aColor) { + return this.getSides(aColor); + } + + @Override + public boolean isOutputFacing(final ForgeDirection side) { + return side != this.getBaseMetaTileEntity() + .getFrontFacing(); + } + + @Override + public boolean isFacingValid(final ForgeDirection side) { + return side.offsetY == 0; + } + + // Please find out what I do. + // I do stuff within the GUI. + // this.mTemperature = Math.min(54, Math.max(0, this.mTemperature * 54 / (((GT_MetaTileEntity_Boiler) + // this.mTileEntity.getMetaTileEntity()).maxProgresstime() - 10))); + @Override + public int maxProgresstime() { + return 1000 + (250 * tier); + } + + @Override + public boolean isElectric() { + return false; + } + + @Override + public int getCapacity() { + return (16000 + (16000 * tier)); + } + + // This type of machine can have different water and steam capacities. + @Override + public int getSteamCapacity() { + return 2 * getCapacity(); + } + + @Override + protected int getProductionPerSecond() { + return steamPerSecond; + } + + @Override + protected int getMaxTemperature() { + return maxProgresstime(); + } + + @Override + protected int getEnergyConsumption() { + return 2; + } + + @Override + protected int getCooldownInterval() { + return 40; + } + + @Override + protected int getHeatUpRate() { + return 10; + } + + @Override + protected void updateFuel(IGregTechTileEntity tile, long ticks) { + ItemStack fuelStack = this.mInventory[2]; + if (fuelStack == null) return; + + int burnTime = getBurnTime(fuelStack); + if (burnTime > 0 && this.mTemperature <= 101) { + consumeFuel(tile, fuelStack, burnTime); + } + } + + @Override + // Since this type of machine can have different water and steam capacities, we need to override getTankInfo() to + // support returning those different capacities. + public FluidTankInfo[] getTankInfo(ForgeDirection aSide) { + return new FluidTankInfo[] { new FluidTankInfo(this.mFluid, getCapacity()), + new FluidTankInfo(this.mSteam, getSteamCapacity()) }; + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return aIndex == 1 || aIndex == 3; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return aIndex == 2; + } + + @Override + protected int getPollution() { + return (int) (CORE.ConfigSwitches.basePollutionPerSecondBoiler + * CORE.ConfigSwitches.pollutionReleasedByTierBoiler[this.tier]); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Boiler_Base(this.mName, tier, this.mDescriptionArray, this.mTextures); + } + + @Override + protected void onDangerousWaterLack(IGregTechTileEntity tile, long ticks) { + // Smart boilers don't explode! + } + + /** + * Returns burn time if the stack is a valid fuel, otherwise return 0. + */ + private static int getBurnTime(ItemStack stack) { + int burnTime = GameRegistry.getFuelValue(stack); + if (burnTime <= 0) { + burnTime = TileEntityFurnace.getItemBurnTime(stack); + } + + return burnTime; + } + + public void consumeFuel(IGregTechTileEntity tile, ItemStack fuel, int burnTime) { + this.mProcessingEnergy += burnTime / 10; + this.mTemperature += burnTime / 500; // will add bonus temperature points if the burn time is pretty high + + tile.decrStackSize(2, 1); + if (tile.getRandomNumber(3) == 0) { + if (fuel.getDisplayName() + .toLowerCase() + .contains("charcoal") + || fuel.getDisplayName() + .toLowerCase() + .contains("coke")) { + tile.addStackToSlot(3, GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.Ash, 1L)); + } else { + tile.addStackToSlot(3, GT_OreDictUnificator.get(OrePrefixes.dustTiny, Materials.DarkAsh, 1L)); + } + } + } + + @Override + public boolean allowCoverOnSide(ForgeDirection side, GT_ItemStack aCover) { + if (side != this.getBaseMetaTileEntity() + .getFrontFacing()) { + return true; + } + return super.allowCoverOnSide(side, aCover); + } + + @Override + public GUITextureSet getGUITextureSet() { + return GUITextureSet.DEFAULT; + } + + @Override + protected IDrawable[] getFuelSlotBackground() { + return new IDrawable[] { getGUITextureSet().getItemSlot(), GTPP_UITextures.OVERLAY_SLOT_COAL }; + } + + @Override + protected IDrawable[] getAshSlotBackground() { + return new IDrawable[] { getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_DUST }; + } + + @Override + public int getTitleColor() { + return COLOR_TITLE.get(); + } + + @Override + protected IDrawable getOverlaySlotIn() { + return GT_UITextures.OVERLAY_SLOT_IN; + } + + @Override + protected IDrawable getOverlaySlotOut() { + return GT_UITextures.OVERLAY_SLOT_OUT; + } + + @Override + protected IDrawable getOverlaySlotCanister() { + return GTPP_UITextures.OVERLAY_SLOT_CANISTER_DARK; + } + + @Override + protected UITexture getProgressbarEmpty() { + return GTPP_UITextures.PROGRESSBAR_BOILER_EMPTY; + } + + @Override + protected UITexture getProgressbarFuel() { + return GTPP_UITextures.PROGRESSBAR_FUEL; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_HV.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_HV.java new file mode 100644 index 0000000000..e77915aa01 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_HV.java @@ -0,0 +1,52 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.generators; + +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GT_MetaTileEntity_Boiler_HV extends GT_MetaTileEntity_Boiler_Base { + + public GT_MetaTileEntity_Boiler_HV(int aID, String aNameRegional, int aBoilerTier) { + super(aID, aNameRegional, aBoilerTier); + } + + public GT_MetaTileEntity_Boiler_HV(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Boiler_HV(this.mName, 3, this.mDescriptionArray, this.mTextures); + } + + @Override + protected GT_RenderedTexture getCasingTexture() { + return new GT_RenderedTexture(Textures.BlockIcons.MACHINE_HV_SIDE); + } + + @Override + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { super.getFront(aColor)[0], this.getCasingTexture(), + new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT) }; + } + + @Override + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { super.getTop(aColor)[0], this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Talonite) }; + } + + @Override + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { super.getFrontActive(aColor)[0], this.getCasingTexture(), + new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT_ACTIVE) }; + } + + @Override + public ITexture[] getTopActive(final byte aColor) { + return getTop(aColor); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_LV.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_LV.java new file mode 100644 index 0000000000..23abfe1e3f --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_LV.java @@ -0,0 +1,52 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.generators; + +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GT_MetaTileEntity_Boiler_LV extends GT_MetaTileEntity_Boiler_Base { + + public GT_MetaTileEntity_Boiler_LV(int aID, String aNameRegional, int aBoilerTier) { + super(aID, aNameRegional, aBoilerTier); + } + + public GT_MetaTileEntity_Boiler_LV(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Boiler_LV(this.mName, 1, this.mDescriptionArray, this.mTextures); + } + + @Override + protected GT_RenderedTexture getCasingTexture() { + return new GT_RenderedTexture(Textures.BlockIcons.MACHINE_LV_SIDE); + } + + @Override + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { super.getFront(aColor)[0], this.getCasingTexture(), + new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT) }; + } + + @Override + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { super.getTop(aColor)[0], this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Potin) }; + } + + @Override + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { super.getFrontActive(aColor)[0], this.getCasingTexture(), + new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT_ACTIVE) }; + } + + @Override + public ITexture[] getTopActive(final byte aColor) { + return getTop(aColor); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_MV.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_MV.java new file mode 100644 index 0000000000..379f67b55d --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_Boiler_MV.java @@ -0,0 +1,52 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.generators; + +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GT_MetaTileEntity_Boiler_MV extends GT_MetaTileEntity_Boiler_Base { + + public GT_MetaTileEntity_Boiler_MV(int aID, String aNameRegional, int aBoilerTier) { + super(aID, aNameRegional, aBoilerTier); + } + + public GT_MetaTileEntity_Boiler_MV(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_Boiler_MV(this.mName, 2, this.mDescriptionArray, this.mTextures); + } + + @Override + protected GT_RenderedTexture getCasingTexture() { + return new GT_RenderedTexture(Textures.BlockIcons.MACHINE_MV_SIDE); + } + + @Override + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { super.getFront(aColor)[0], this.getCasingTexture(), + new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT) }; + } + + @Override + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { super.getTop(aColor)[0], this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Casing_Material_Tumbaga) }; + } + + @Override + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { super.getFrontActive(aColor)[0], this.getCasingTexture(), + new GT_RenderedTexture(Textures.BlockIcons.BOILER_FRONT_ACTIVE) }; + } + + @Override + public ITexture[] getTopActive(final byte aColor) { + return getTop(aColor); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_SemiFluidGenerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_SemiFluidGenerator.java new file mode 100644 index 0000000000..993b0e9035 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GT_MetaTileEntity_SemiFluidGenerator.java @@ -0,0 +1,173 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.generators; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +import org.apache.commons.lang3.ArrayUtils; + +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.GregTech_API; +import gregtech.api.enums.ConfigCategories; +import gregtech.api.enums.ItemList; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicGenerator; +import gregtech.api.objects.GT_ItemStack; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.lib.CORE; + +public class GT_MetaTileEntity_SemiFluidGenerator extends GT_MetaTileEntity_BasicGenerator { + + public int mEfficiency; + + public GT_MetaTileEntity_SemiFluidGenerator(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, "Requires semi-fluid Fuel", new ITexture[0]); + onConfigLoad(); + } + + public GT_MetaTileEntity_SemiFluidGenerator(String aName, int aTier, String[] aDescription, + ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + onConfigLoad(); + } + + @Override + public int getPollution() { + return (int) (CORE.ConfigSwitches.basePollutionPerSecondSemiFluidGenerator + * CORE.ConfigSwitches.pollutionReleasedByTierSemiFluidGenerator[this.mTier]); + } + + @Override + public int getCapacity() { + return 16000; + } + + public void onConfigLoad() { + this.mEfficiency = GregTech_API.sMachineFile.get( + ConfigCategories.machineconfig, + "SemiFluidGenerator.efficiency.tier." + this.mTier, + 100 - (this.mTier * 5)); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_SemiFluidGenerator(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); + } + + @Override + public RecipeMap<?> getRecipeMap() { + // Logger.WARNING("Fuel Count: "+Gregtech_Recipe_Map.sSemiFluidLiquidFuels.mRecipeList.size()); + return GTPPRecipeMaps.semiFluidFuels; + } + + @Override + public String[] getDescription() { + return ArrayUtils.addAll( + this.mDescriptionArray, + "Produces " + (this.getPollution()) + " pollution/sec", + "Fuel Efficiency: " + this.getEfficiency() + "%", + CORE.GT_Tooltip.get()); + } + + @Override + public int getEfficiency() { + return this.mEfficiency; + } + + @Override + public boolean isOutputFacing(ForgeDirection side) { + return (side == getBaseMetaTileEntity().getFrontFacing()); + } + + @Override + public boolean allowCoverOnSide(ForgeDirection side, GT_ItemStack aCover) { + if (side != this.getBaseMetaTileEntity() + .getFrontFacing()) { + return true; + } + return super.allowCoverOnSide(side, aCover); + } + + @Override + public int getFuelValue(ItemStack aStack) { + if ((GT_Utility.isStackInvalid(aStack)) || (getRecipeMap() == null)) { + Logger.WARNING("Bad Fuel?"); + return 0; + } + int rValue = Math.max(GT_ModHandler.getFuelValue(aStack) * 6 / 5, super.getFuelValue(aStack)); + if (ItemList.Fuel_Can_Plastic_Filled.isStackEqual(aStack, false, true)) { + rValue = Math.max(rValue, GameRegistry.getFuelValue(aStack) * 3); + } + Logger.WARNING("Good Fuel: " + rValue); + return rValue; + } + + @Override + public ITexture[] getFront(byte aColor) { + return new ITexture[] { super.getFront(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_FRONT), + Textures.BlockIcons.OVERLAYS_ENERGY_OUT[this.mTier] }; + } + + @Override + public ITexture[] getBack(byte aColor) { + return new ITexture[] { super.getBack(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_TOP) }; + } + + @Override + public ITexture[] getBottom(byte aColor) { + return new ITexture[] { super.getBottom(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_BOTTOM) }; + } + + @Override + public ITexture[] getTop(byte aColor) { + return new ITexture[] { super.getTop(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_SIDE) }; + } + + @Override + public ITexture[] getSides(byte aColor) { + return new ITexture[] { super.getSides(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_TOP) }; + } + + @Override + public ITexture[] getFrontActive(byte aColor) { + return new ITexture[] { super.getFrontActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_FRONT_ACTIVE), + Textures.BlockIcons.OVERLAYS_ENERGY_OUT[this.mTier] }; + } + + @Override + public ITexture[] getBackActive(byte aColor) { + return new ITexture[] { super.getBackActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_TOP_ACTIVE) }; + } + + @Override + public ITexture[] getBottomActive(byte aColor) { + return new ITexture[] { super.getBottomActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_BOTTOM_ACTIVE) }; + } + + @Override + public ITexture[] getTopActive(byte aColor) { + return new ITexture[] { super.getTopActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_SIDE_ACTIVE) }; + } + + @Override + public ITexture[] getSidesActive(byte aColor) { + return new ITexture[] { super.getSidesActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_TOP_ACTIVE) }; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntityGeothermalGenerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntityGeothermalGenerator.java new file mode 100644 index 0000000000..e1f1c8a2e6 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntityGeothermalGenerator.java @@ -0,0 +1,176 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.generators; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +import org.apache.commons.lang3.ArrayUtils; + +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.GregTech_API; +import gregtech.api.enums.ConfigCategories; +import gregtech.api.enums.ItemList; +import gregtech.api.enums.Textures; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicGenerator; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.util.GT_ModHandler; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntityGeothermalGenerator extends GT_MetaTileEntity_BasicGenerator { + + public int mEfficiency; + + public GregtechMetaTileEntityGeothermalGenerator(final int aID, final String aName, final String aNameRegional, + final int aTier) { + super(aID, aName, aNameRegional, aTier, "Requires Pahoehoe Lava or Normal Lava as Fuel", new ITexture[0]); + this.onConfigLoad(); + } + + public GregtechMetaTileEntityGeothermalGenerator(final String aName, final int aTier, final String[] aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + this.onConfigLoad(); + } + + @Override + public String[] getDescription() { + String aPollution = "Causes " + this.getPollution() + " Pollution per second"; + return ArrayUtils.addAll( + this.mDescriptionArray, + "Generates power at " + this.getEfficiency() + "% Efficiency per tick", + aPollution, + CORE.GT_Tooltip.get()); + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + + @Override + public int getCapacity() { + // return MathUtils.roundToClosestMultiple(32000*(this.mTier/2), 25000); + return 5000 * this.mTier; + } + + public void onConfigLoad() { + this.mEfficiency = GregTech_API.sMachineFile.get( + ConfigCategories.machineconfig, + "ThermalGenerator.efficiency.tier." + this.mTier, + (100 - (this.mTier * 7))); + } + + @Override + public int getEfficiency() { + return this.mEfficiency; + } + + @Override + public int getFuelValue(final ItemStack aStack) { + int rValue = Math.max((GT_ModHandler.getFuelValue(aStack) * 6) / 5, super.getFuelValue(aStack)); + if (ItemList.Fuel_Can_Plastic_Filled.isStackEqual(aStack, false, true)) { + rValue = Math.max(rValue, GameRegistry.getFuelValue(aStack) * 3); + } + return rValue; + } + + @Override + public boolean isOutputFacing(final ForgeDirection side) { + return side == this.getBaseMetaTileEntity() + .getFrontFacing(); + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntityGeothermalGenerator( + this.mName, + this.mTier, + this.mDescriptionArray, + this.mTextures); + } + + @Override + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { super.getFront(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_SIDE), + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier] }; + } + + @Override + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { super.getBack(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_BACK), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Diesel_Vertical) }; + } + + @Override + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { super.getBottom(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_BOTTOM) }; + } + + @Override + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { super.getTop(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_SIDE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_ROCK_BREAKER) }; + } + + @Override + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { super.getSides(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.BOILER_LAVA_FRONT) }; + } + + @Override + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { super.getFrontActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_SIDE_ACTIVE), + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier] }; + } + + @Override + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { super.getBackActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_BACK_ACTIVE), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Diesel_Vertical_Active) }; + } + + @Override + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { super.getBottomActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_BOTTOM_ACTIVE) }; + } + + @Override + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { super.getTopActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.DIESEL_GENERATOR_SIDE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_ROCK_BREAKER_ACTIVE) }; + } + + @Override + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { super.getSidesActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.BOILER_LAVA_FRONT_ACTIVE) }; + } + + @Override + public RecipeMap<?> getRecipeMap() { + return RecipeMaps.hotFuels; + } + + @Override + public int getPollution() { + return (int) (CORE.ConfigSwitches.basePollutionPerSecondGeothermalGenerator + * CORE.ConfigSwitches.pollutionReleasedByTierGeothermalGenerator[mTier]); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntityRocketFuelGenerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntityRocketFuelGenerator.java new file mode 100644 index 0000000000..45d4177709 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntityRocketFuelGenerator.java @@ -0,0 +1,156 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.generators; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.GregTech_API; +import gregtech.api.enums.ConfigCategories; +import gregtech.api.enums.ItemList; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.util.GT_ModHandler; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.generators.GregtechRocketFuelGeneratorBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntityRocketFuelGenerator extends GregtechRocketFuelGeneratorBase { + + public int mEfficiency; + + public GregtechMetaTileEntityRocketFuelGenerator(final int aID, final String aName, final String aNameRegional, + final int aTier) { + super(aID, aName, aNameRegional, aTier, "Requires GT++ Rocket Fuels", new ITexture[0]); + this.onConfigLoad(); + } + + public GregtechMetaTileEntityRocketFuelGenerator(final String aName, final int aTier, final String[] aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + this.onConfigLoad(); + } + + @Override + public boolean isOutputFacing(final ForgeDirection side) { + return side == this.getBaseMetaTileEntity() + .getFrontFacing(); + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntityRocketFuelGenerator( + this.mName, + this.mTier, + this.mDescriptionArray, + this.mTextures); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.rocketFuels; + } + + @Override + public int getCapacity() { + return 32000; + } + + public void onConfigLoad() { + this.mEfficiency = GregTech_API.sMachineFile.get( + ConfigCategories.machineconfig, + "RocketEngine.efficiency.tier." + this.mTier, + 80 - (10 * (this.mTier - 4))); + } + + @Override + public int getEfficiency() { + int eff = 80 - (10 * (this.mTier - 4)); + return eff; + } + + @Override + public int getFuelValue(final ItemStack aStack) { + int rValue = Math.max((GT_ModHandler.getFuelValue(aStack) * 6) / 5, super.getFuelValue(aStack)); + if (ItemList.Fuel_Can_Plastic_Filled.isStackEqual(aStack, false, true)) { + rValue = Math.max(rValue, GameRegistry.getFuelValue(aStack) * 3); + } + return rValue; + } + + private GT_RenderedTexture getCasingTexture() { + if (this.mTier <= 4) { + return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top); + } else if (this.mTier == 5) { + + return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Advanced); + } else { + + return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Ultra); + } + // return new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top); + } + + @Override + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { super.getFront(aColor)[0], this.getCasingTexture(), + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier] }; + } + + @Override + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { super.getBack(aColor)[0], this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Vent) }; + } + + @Override + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { super.getBottom(aColor)[0], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + @Override + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { super.getTop(aColor)[0], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Redstone_Off) }; + } + + @Override + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { super.getSides(aColor)[0], this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Diesel_Horizontal) }; + } + + @Override + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { super.getFrontActive(aColor)[0], this.getCasingTexture(), + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier] }; + } + + @Override + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { super.getBackActive(aColor)[0], this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Vent_Fast) }; + } + + @Override + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { super.getBottomActive(aColor)[0], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + @Override + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { super.getTopActive(aColor)[0], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Redstone_On) }; + } + + @Override + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { super.getSidesActive(aColor)[0], this.getCasingTexture(), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Diesel_Horizontal_Active) }; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntity_RTG.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntity_RTG.java new file mode 100644 index 0000000000..32cf3a92cc --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/GregtechMetaTileEntity_RTG.java @@ -0,0 +1,379 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.generators; + +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +import org.apache.commons.lang3.ArrayUtils; + +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicGenerator; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; + +public class GregtechMetaTileEntity_RTG extends GT_MetaTileEntity_BasicGenerator { + + public int mEfficiency; + private long mTicksToBurnFor; + private int mVoltage = 0; + private GT_Recipe mCurrentRecipe; + private int mDaysRemaining = 0; + private int mDayTick = 0; + private byte mNewTier = 0; + + public int removeDayOfTime() { + if (this.mDaysRemaining > 0) { + return this.mDaysRemaining--; + } + return this.mDaysRemaining; + } + + // Generates fuel value based on MC days + public static int convertDaysToTicks(float days) { + int value = 0; + value = MathUtils.roundToClosestInt(20 * 86400 * days); + return value; + } + + public static long getTotalEUGenerated(int ticks, int voltage) { + return ticks * voltage; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setLong("mTicksToBurnFor", this.mTicksToBurnFor); + aNBT.setInteger("mVoltage", this.mVoltage); + aNBT.setInteger("mDaysRemaining", this.mDaysRemaining); + aNBT.setInteger("mDayTick", this.mDayTick); + aNBT.setByte("mNewTier", this.mNewTier); + + if (this.mCurrentRecipe != null) { + final NBTTagList list = new NBTTagList(); + final ItemStack stack = this.mCurrentRecipe.mInputs[0]; + if (stack != null) { + final NBTTagCompound data = new NBTTagCompound(); + stack.writeToNBT(data); + data.setInteger("mSlot", 0); + list.appendTag(data); + } + aNBT.setTag("mRecipeItem", list); + } + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.mTicksToBurnFor = aNBT.getLong("mTicksToBurnFor"); + this.mVoltage = aNBT.getInteger("mVoltage"); + this.mDaysRemaining = aNBT.getInteger("mDaysRemaining"); + this.mDayTick = aNBT.getInteger("mDayTick"); + this.mNewTier = aNBT.getByte("mNewTier"); + + try { + ReflectionUtils.setByte(this, "mTier", this.mNewTier); + } catch (Exception e) { + if (this.getBaseMetaTileEntity() != null) { + IGregTechTileEntity thisTile = this.getBaseMetaTileEntity(); + if (thisTile.isAllowedToWork() || thisTile.isActive()) { + thisTile.setActive(false); + } + } + } + + final NBTTagList list = aNBT.getTagList("mRecipeItem", 10); + final NBTTagCompound data = list.getCompoundTagAt(0); + ItemStack lastUsedFuel = ItemStack.loadItemStackFromNBT(data); + if (lastUsedFuel != null) { + this.mCurrentRecipe = getRecipeMap().findRecipe( + getBaseMetaTileEntity(), + false, + 9223372036854775807L, + null, + new ItemStack[] { lastUsedFuel }); + } + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + if (this.mDayTick < 24000) { + this.mDayTick++; + } else if (this.mDayTick >= 24000) { + this.mDayTick = 0; + this.mDaysRemaining = this.removeDayOfTime(); + } + } + + if ((aBaseMetaTileEntity.isServerSide()) && (aBaseMetaTileEntity.isAllowedToWork()) && (aTick % 10L == 0L)) { + long tProducedEU = 0L; + if (this.mFluid == null) { + if (aBaseMetaTileEntity.getUniversalEnergyStored() < maxEUOutput() + getMinimumStoredEU()) { + this.mInventory[getStackDisplaySlot()] = null; + } else { + if (this.mInventory[getStackDisplaySlot()] == null) + this.mInventory[getStackDisplaySlot()] = new ItemStack(Blocks.fire, 1); + this.mInventory[getStackDisplaySlot()].setStackDisplayName( + "Generating: " + + GT_Utility.formatNumbers( + aBaseMetaTileEntity.getUniversalEnergyStored() - getMinimumStoredEU()) + + " EU"); + } + } else { + int tFuelValue = getFuelValue(this.mFluid); + int tConsumed = consumedFluidPerOperation(this.mFluid); + if ((tFuelValue > 0) && (tConsumed > 0) && (this.mFluid.amount > tConsumed)) { + long tFluidAmountToUse = Math.min( + this.mFluid.amount / tConsumed, + (maxEUStore() - aBaseMetaTileEntity.getUniversalEnergyStored()) / tFuelValue); + if ((tFluidAmountToUse > 0L) + && (aBaseMetaTileEntity.increaseStoredEnergyUnits(tFluidAmountToUse * tFuelValue, true))) { + tProducedEU = tFluidAmountToUse * tFuelValue; + FluidStack tmp260_257 = this.mFluid; + tmp260_257.amount = (int) (tmp260_257.amount - (tFluidAmountToUse * tConsumed)); + } + } + } + if ((this.mInventory[getInputSlot()] != null) + && (aBaseMetaTileEntity.getUniversalEnergyStored() < maxEUOutput() * 20L + getMinimumStoredEU()) + && (GT_Utility.getFluidForFilledItem(this.mInventory[getInputSlot()], true) == null)) { + int tFuelValue = getFuelValue(this.mInventory[getInputSlot()]); + if (tFuelValue > 0) { + ItemStack tEmptyContainer = getEmptyContainer(this.mInventory[getInputSlot()]); + if (aBaseMetaTileEntity.addStackToSlot(getOutputSlot(), tEmptyContainer)) { + aBaseMetaTileEntity.increaseStoredEnergyUnits(tFuelValue, true); + aBaseMetaTileEntity.decrStackSize(getInputSlot(), 1); + tProducedEU = tFuelValue; + } + } + } + if ((tProducedEU > 0L) && (getPollution() > 0)) { + PollutionUtils + .addPollution(aBaseMetaTileEntity, (int) (tProducedEU * getPollution() / 500 * this.mTier + 1L)); + } + } + + if (aBaseMetaTileEntity.isServerSide()) aBaseMetaTileEntity.setActive( + (aBaseMetaTileEntity.isAllowedToWork()) + && (aBaseMetaTileEntity.getUniversalEnergyStored() >= maxEUOutput() + getMinimumStoredEU())); + } + + @Override + public String[] getDescription() { + return ArrayUtils.addAll( + this.mDescriptionArray, + "Fuel is measured in minecraft days (Check with Scanner)", + "RTG changes output voltage depending on fuel", + "Generates power at " + GT_Utility.formatNumbers(this.getEfficiency()) + "% Efficiency per tick", + "Output Voltage: " + GT_Utility.formatNumbers(this.getOutputTier()) + " EU/t", + CORE.GT_Tooltip.get()); + } + + public GregtechMetaTileEntity_RTG(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier, "Requires RTG Pellets", new ITexture[0]); + } + + private byte getTier() { + int voltage = this.mVoltage; + if (voltage >= 512) { + return 4; + } else if (voltage >= 128) { + return 3; + } else if (voltage >= 32) { + return 2; + } else if (voltage >= 8) { + return 1; + } + return 0; + } + + public GregtechMetaTileEntity_RTG(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public boolean isOutputFacing(ForgeDirection side) { + return ((side.offsetY == 0) && (side != getBaseMetaTileEntity().getFrontFacing()) + && (side != getBaseMetaTileEntity().getBackFacing())); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_RTG(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.rtgFuels; + } + + @Override + public int getCapacity() { + return 0; + } + + @Override + public int getEfficiency() { + return this.mEfficiency = 100; + } + + @Override + public ITexture[] getFront(byte aColor) { + return new ITexture[] { super.getFront(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_MASSFAB) }; + } + + @Override + public ITexture[] getBack(byte aColor) { + return new ITexture[] { super.getBack(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP) }; + } + + @Override + public ITexture[] getBottom(byte aColor) { + return new ITexture[] { super.getBottom(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP) }; + } + + @Override + public ITexture[] getTop(byte aColor) { + return new ITexture[] { super.getTop(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP), + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_FLUID_SIDE) }; + } + + @Override + public ITexture[] getSides(byte aColor) { + return new ITexture[] { gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS[this.mTier][(0)], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE), + gregtech.api.enums.Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[getTier()] }; + } + + @Override + public ITexture[] getFrontActive(byte aColor) { + return new ITexture[] { super.getFrontActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_MASSFAB_ACTIVE) }; + } + + @Override + public ITexture[] getBackActive(byte aColor) { + return new ITexture[] { super.getBackActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE) }; + } + + @Override + public ITexture[] getBottomActive(byte aColor) { + return new ITexture[] { super.getBottomActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE) }; + } + + @Override + public ITexture[] getTopActive(byte aColor) { + return new ITexture[] { super.getTopActive(aColor)[0], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_FLUID_SIDE_ACTIVE) }; + } + + @Override + public ITexture[] getSidesActive(byte aColor) { + return new ITexture[] { gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS[this.mTier][(0)], + new GT_RenderedTexture(Textures.BlockIcons.NAQUADAH_REACTOR_SOLID_TOP_ACTIVE), + gregtech.api.enums.Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[getTier()] }; + } + + @Override + public int getPollution() { + return 0; + } + + @Override + public int getFuelValue(ItemStack aStack) { + if ((GT_Utility.isStackInvalid(aStack)) || (getRecipeMap() == null)) return 0; + GT_Recipe tFuel = getRecipeMap() + .findRecipe(getBaseMetaTileEntity(), false, 9223372036854775807L, null, new ItemStack[] { aStack }); + if (tFuel != null) { + this.mCurrentRecipe = tFuel; + int voltage = tFuel.mEUt; + this.mVoltage = voltage; + // this.mDaysRemaining = tFuel.mSpecialValue*365; + + // Do some voodoo. + byte mTier2; + // mTier2 = ReflectionUtils.getField(this.getClass(), "mTier"); + try { + if (ItemStack.areItemStacksEqual(tFuel.mInputs[0], GregtechItemList.Pellet_RTG_AM241.get(1))) { + mTier2 = 1; + } else if (ItemStack.areItemStacksEqual(tFuel.mInputs[0], GregtechItemList.Pellet_RTG_PO210.get(1))) { + mTier2 = 3; + } else if (ItemStack.areItemStacksEqual(tFuel.mInputs[0], GregtechItemList.Pellet_RTG_PU238.get(1))) { + mTier2 = 2; + } else if (ItemStack.areItemStacksEqual(tFuel.mInputs[0], GregtechItemList.Pellet_RTG_SR90.get(1))) { + mTier2 = 1; + } else { + mTier2 = 0; + } + ReflectionUtils.setByte(this, "mTier", mTier2); + this.mNewTier = mTier2; + } catch (Exception e) { + Logger.WARNING("Failed setting mTier."); + e.printStackTrace(); + } + + this.mTicksToBurnFor = getTotalEUGenerated(convertDaysToTicks(tFuel.mSpecialValue), voltage); + if (mTicksToBurnFor >= Integer.MAX_VALUE) { + mTicksToBurnFor = Integer.MAX_VALUE; + Logger.WARNING("Fuel went over Int limit, setting to MAX_VALUE."); + } + this.mDaysRemaining = MathUtils.roundToClosestInt(mTicksToBurnFor / 20 / 60 / 3); + Logger.WARNING("step | " + (int) (mTicksToBurnFor * getEfficiency() / 100L)); + return (int) (mTicksToBurnFor * getEfficiency() / 100L); + } + Logger.WARNING("Not sure"); + return 0; + } + + @Override + public long maxEUOutput() { + return ((getBaseMetaTileEntity().isAllowedToWork()) ? this.mVoltage : 0L); + } + + @Override + public long getOutputTier() { + if (this.mCurrentRecipe != null) { + return this.mVoltage = this.mCurrentRecipe.mEUt; + } + return 0; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public String[] getInfoData() { + return new String[] { "RTG - Running at tier " + this.mTier, "Active: " + this.getBaseMetaTileEntity() + .isActive(), "Current Output: " + GT_Utility.formatNumbers(mVoltage) + " EU/t", + "Days of Fuel remaining: " + GT_Utility.formatNumbers(mTicksToBurnFor / 20 / 60 / 20), + "Hours of Fuel remaining: " + GT_Utility.formatNumbers(mTicksToBurnFor / 20 / 60 / 60), + "Ticks of " + this.mVoltage + "v remaining: " + mTicksToBurnFor, + this.mCurrentRecipe.mInputs[0].getDisplayName() + " x1" }; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/ULV/GT_MetaTileEntity_ULV_CombustionGenerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/ULV/GT_MetaTileEntity_ULV_CombustionGenerator.java new file mode 100644 index 0000000000..24770e9503 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/ULV/GT_MetaTileEntity_ULV_CombustionGenerator.java @@ -0,0 +1,59 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.generators.ULV; + +import static gregtech.api.enums.GT_Values.V; + +import org.apache.commons.lang3.ArrayUtils; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.ConfigCategories; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.common.tileentities.generators.GT_MetaTileEntity_DieselGenerator; +import gtPlusPlus.core.lib.CORE; + +public class GT_MetaTileEntity_ULV_CombustionGenerator extends GT_MetaTileEntity_DieselGenerator { + + public GT_MetaTileEntity_ULV_CombustionGenerator(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier); + } + + public GT_MetaTileEntity_ULV_CombustionGenerator(String aName, int aTier, String[] aDescription, + ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return ArrayUtils.addAll( + this.mDescriptionArray, + "Produces " + (this.getPollution() * 20) + " pollution/sec", + "Fuel Efficiency: " + this.getEfficiency() + "%", + CORE.GT_Tooltip.get()); + } + + @Override + public long maxEUStore() { + return Math.max(getEUVar(), V[1] * 80L + getMinimumStoredEU()); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_ULV_CombustionGenerator( + this.mName, + this.mTier, + this.mDescriptionArray, + this.mTextures); + } + + @Override + public int getCapacity() { + return 16000; + } + + @Override + public void onConfigLoad() { + this.mEfficiency = GregTech_API.sMachineFile + .get(ConfigCategories.machineconfig, "DieselGenerator.efficiency.tier." + this.mTier, 95); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/ULV/GT_MetaTileEntity_ULV_SteamTurbine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/ULV/GT_MetaTileEntity_ULV_SteamTurbine.java new file mode 100644 index 0000000000..26429b1486 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/generators/ULV/GT_MetaTileEntity_ULV_SteamTurbine.java @@ -0,0 +1,42 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.generators.ULV; + +import static gregtech.api.enums.GT_Values.V; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.ConfigCategories; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.common.tileentities.generators.GT_MetaTileEntity_SteamTurbine; + +public class GT_MetaTileEntity_ULV_SteamTurbine extends GT_MetaTileEntity_SteamTurbine { + + public GT_MetaTileEntity_ULV_SteamTurbine(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional, 0); + } + + public GT_MetaTileEntity_ULV_SteamTurbine(String aName, String[] aDescription, ITexture[][][] aTextures) { + super(aName, 0, aDescription, aTextures); + } + + @Override + public long maxEUStore() { + return Math.max(getEUVar(), V[1] * 80L + getMinimumStoredEU()); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_ULV_SteamTurbine(this.mName, this.mDescriptionArray, this.mTextures); + } + + @Override + public int getCapacity() { + return 16000; + } + + @Override + public void onConfigLoad() { + this.mEfficiency = GregTech_API.sMachineFile + .get(ConfigCategories.machineconfig, "SteamTurbine.efficiency.tier." + this.mTier, 6 + 1); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_CropHarvestor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_CropHarvestor.java new file mode 100644 index 0000000000..c592a68a40 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_CropHarvestor.java @@ -0,0 +1,716 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +import org.apache.commons.lang3.ArrayUtils; + +import com.gtnewhorizon.gtnhlib.util.map.ItemStackMap; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; +import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; +import com.gtnewhorizons.modularui.common.widget.ProgressBar; +import com.gtnewhorizons.modularui.common.widget.SlotGroup; + +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Textures; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; +import gregtech.api.objects.GT_ItemStack; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.api.gui.GTPP_UITextures; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import ic2.api.crops.CropCard; +import ic2.api.crops.ICropTile; +import ic2.core.item.DamageHandler; + +public class GT_MetaTileEntity_CropHarvestor extends GT_MetaTileEntity_BasicTank { + + private static final int SLOT_WEEDEX_1 = 1; + private static final int SLOT_WEEDEX_2 = 2; + private static final int SLOT_FERT_1 = 3; + private static final int SLOT_FERT_4 = 6; + private static final int SLOT_OUTPUT_START = 7; + + public boolean mModeAlternative = false; + public boolean mHarvestEnabled = true; + + public GT_MetaTileEntity_CropHarvestor(final int aID, final int aTier, final String aDescription) { + super( + aID, + "basicmachine.cropharvester.0" + aTier, + "Crop Manager (" + GT_Values.VN[aTier] + ")", + aTier, + 21, + aDescription); + } + + public GT_MetaTileEntity_CropHarvestor(final String aName, final int aTier, final String[] aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, 21, aDescription, aTextures); + } + + @Override + public boolean isTransformerUpgradable() { + return true; + } + + @Override + public boolean isOverclockerUpgradable() { + return true; + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isInputFacing(ForgeDirection side) { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isElectric() { + return true; + } + + @Override + public long maxAmperesIn() { + return 8; + } + + @Override + public long getMinimumStoredEU() { + return GT_Values.V[this.mTier]; + } + + @Override + public long maxEUStore() { + return GT_Values.V[this.mTier] * (this.mTier * GT_Values.V[this.mTier]); + } + + @Override + public long maxEUInput() { + return GT_Values.V[this.mTier]; + } + + @Override + public int getCapacity() { + return 32000 * this.mTier; + } + + @Override + public int getTankPressure() { + return -100; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_CropHarvestor(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); + } + + @Override + public int getSizeInventory() { + return 21; + } + + private static int getRange(int aTier) { + return switch (aTier) { + case 1 -> 1; + case 2 -> 5; + case 3 -> 9; + case 4 -> 13; + case 5 -> 17; + case 6 -> 21; + case 7 -> 25; + case 8 -> 29; + case 9 -> 33; + default -> 0; + }; + } + + private HashSet<ICropTile> mCropCache = new HashSet<>(); + private boolean mInvalidCache = false; + + public boolean doesInventoryHaveSpace() { + for (int i = SLOT_OUTPUT_START; i < this.getSizeInventory(); i++) { + if (this.mInventory[i] == null || this.mInventory[i].stackSize < 64) { + return true; + } + } + return false; + } + + public long powerUsage() { + return this.maxEUInput() / 8; + } + + public long powerUsageSecondary() { + return this.maxEUInput() / 32; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (!getBaseMetaTileEntity().isServerSide() || !getBaseMetaTileEntity().isAllowedToWork() + || (!getBaseMetaTileEntity().hasWorkJustBeenEnabled() && aTick % 100 != 0)) return; + + if (this.getBaseMetaTileEntity() + .getUniversalEnergyStored() < getMinimumStoredEU()) return; + + int aTileX = this.getBaseMetaTileEntity() + .getXCoord(); + int aTileY = this.getBaseMetaTileEntity() + .getXCoord(); + int aTileZ = this.getBaseMetaTileEntity() + .getXCoord(); + + int aRadius = 10 + getRange(this.mTier); + int aSide = (aRadius - 1) / 2; + Map<ItemStack, Integer> aAllDrops = new ItemStackMap<>(true); + + if (this.mCropCache.isEmpty() || aTick % 1200 == 0 || this.mInvalidCache) { + if (!this.mCropCache.isEmpty()) { + this.mCropCache.clear(); + } + // Logger.INFO("Looking for crops."); + for (int y = -2; y <= 2; y++) { + for (int x = (-aSide); x <= aSide; x++) { + for (int z = (-aSide); z <= aSide; z++) { + TileEntity tTileEntity = getBaseMetaTileEntity().getTileEntityOffset(x, y, z); + if (tTileEntity != null && tTileEntity instanceof ICropTile tCrop) { + this.mCropCache.add(tCrop); + } + } + } + } + } + + // Process Cache + if (!doesInventoryHaveSpace()) return; + + for (ICropTile tCrop : this.mCropCache) { + if (tCrop == null) { + this.mInvalidCache = true; + break; + } + CropCard aCrop = tCrop.getCrop(); + if (aCrop == null) continue; + + if (this.mModeAlternative) processSecondaryFunctions(tCrop); + if (!this.mHarvestEnabled) continue; + + if (aCrop.canBeHarvested(tCrop) && tCrop.getSize() == aCrop.getOptimalHavestSize(tCrop)) { + if (!getBaseMetaTileEntity().decreaseStoredEnergyUnits(powerUsage(), true)) continue; + ItemStack[] aHarvest = tCrop.harvest_automated(true); + if (aHarvest == null) continue; + + for (ItemStack aStack : aHarvest) { + if (!ItemUtils.checkForInvalidItems(aStack)) continue; + if (this.mTier * 5 > MathUtils.randInt(1, 100)) { + aStack.stackSize += Math.floor(tCrop.getGain() / 10); + Logger.INFO("Bonus output given for " + aCrop.displayName()); + } + Logger.INFO("Harvested " + aCrop.displayName()); + aAllDrops.merge(aStack, aStack.stackSize, Integer::sum); + } + } + } + + if (aAllDrops.isEmpty()) return; + + Logger.INFO("Handling " + aAllDrops.size() + " Harvests"); + for (int i = SLOT_OUTPUT_START; i < this.getSizeInventory() && !aAllDrops.isEmpty(); i++) { + ItemStack invStack = mInventory[i]; + if (invStack == null || GT_Utility.isStackInvalid(invStack) || invStack.stackSize == 0) { + Iterator<Entry<ItemStack, Integer>> iter = aAllDrops.entrySet() + .iterator(); + if (!iter.hasNext()) return; + Entry<ItemStack, Integer> e = iter.next(); + int toAdd = e.getValue(); + int toAddThisSlot = Math.min( + toAdd, + e.getKey() + .getMaxStackSize()); + getBaseMetaTileEntity().setInventorySlotContents(i, GT_Utility.copyAmount(toAddThisSlot, e.getKey())); + toAdd -= toAddThisSlot; + if (toAdd <= toAddThisSlot) { + iter.remove(); + } else { + e.setValue(toAdd); + } + } else { + Integer toAddMaybeNull = aAllDrops.get(invStack); + if (toAddMaybeNull != null) { + int toAdd = toAddMaybeNull; + int space = Math.min(invStack.getMaxStackSize(), getInventoryStackLimit()) - invStack.stackSize; + if (toAdd <= space) { + getBaseMetaTileEntity().addStackToSlot(i, invStack, toAdd); + aAllDrops.remove(invStack); + } else { + getBaseMetaTileEntity().addStackToSlot(i, invStack, space); + aAllDrops.put(invStack, toAdd - space); + } + } + } + } + } + + public boolean hasFertilizer() { + for (int i = SLOT_FERT_1; i <= SLOT_FERT_4; i++) { + if (this.mInventory[i] != null) { + return true; + } + } + return false; + } + + public boolean consumeFertilizer(boolean aSimulate) { + if (hasFertilizer()) { + for (int i = SLOT_FERT_1; i <= SLOT_FERT_4; i++) { + if (this.mInventory[i] != null) { + consume(i, 1, aSimulate); + return true; + } + } + } + return false; + } + + public boolean hasWeedEX() { + for (int i = SLOT_WEEDEX_1; i <= SLOT_WEEDEX_2; i++) { + if (this.mInventory[i] != null) { + return true; + } + } + return false; + } + + public boolean consumeWeedEX(boolean aSimulate) { + if (hasWeedEX()) { + for (int i = SLOT_WEEDEX_1; i <= SLOT_WEEDEX_2; i++) { + if (this.mInventory[i] != null) { + damage(i, 1, aSimulate); + return true; + } + } + } + return false; + } + + public void processSecondaryFunctions(ICropTile aCrop) { + if (!this.mModeAlternative) { + return; + } + if (hasFertilizer() && consumeFertilizer(true) + && this.getBaseMetaTileEntity() + .getUniversalEnergyStored() >= getMinimumStoredEU() + && getBaseMetaTileEntity().decreaseStoredEnergyUnits(powerUsageSecondary(), true) + && applyFertilizer(aCrop)) { + if (consumeFertilizer(false)) { + // Logger.INFO("Consumed Fert."); + } + } + if (this.getFluidAmount() > 0 && this.getBaseMetaTileEntity() + .getUniversalEnergyStored() >= getMinimumStoredEU() + && getBaseMetaTileEntity().decreaseStoredEnergyUnits(powerUsageSecondary(), true) + && applyHydration(aCrop)) { + // Logger.INFO("Consumed Water."); + } + if (hasWeedEX() && consumeWeedEX(true) + && this.getBaseMetaTileEntity() + .getUniversalEnergyStored() >= getMinimumStoredEU() + && getBaseMetaTileEntity().decreaseStoredEnergyUnits(powerUsageSecondary(), true) + && applyWeedEx(aCrop)) { + if (consumeWeedEX(false)) { + // Logger.INFO("Consumed Weed-EX."); + } + } + } + + public boolean applyWeedEx(ICropTile aCrop) { + if (aCrop.getWeedExStorage() < 150) { + aCrop.setWeedExStorage(aCrop.getWeedExStorage() + 50); + boolean triggerDecline; + triggerDecline = aCrop.getWorld().rand.nextInt(3) == 0; + if (aCrop.getCrop() != null && aCrop.getCrop() + .isWeed(aCrop) && aCrop.getWeedExStorage() >= 75 && triggerDecline) { + switch (aCrop.getWorld().rand.nextInt(5)) { + case 0: + if (aCrop.getGrowth() > 0) { + aCrop.setGrowth((byte) (aCrop.getGrowth() - 1)); + } + case 1: + if (aCrop.getGain() > 0) { + aCrop.setGain((byte) (aCrop.getGain() - 1)); + } + default: + if (aCrop.getResistance() > 0) { + aCrop.setResistance((byte) (aCrop.getResistance() - 1)); + } + } + } + return true; + } else { + return false; + } + } + + public boolean applyFertilizer(ICropTile aCrop) { + if (aCrop.getNutrientStorage() >= 100) { + return false; + } else { + // Logger.INFO("Current Nutrient: "+aCrop.getNutrientStorage()+" for "+aCrop.getCrop().displayName()); + aCrop.setNutrientStorage(aCrop.getNutrientStorage() + 100); + return true; + } + } + + public boolean applyHydration(ICropTile aCrop) { + if (aCrop.getHydrationStorage() >= 200 || this.getFluidAmount() == 0) { + // Logger.INFO("Hydration Max"); + return false; + } else { + int apply = 200 - aCrop.getHydrationStorage(); + if (this.getFluidAmount() >= 0) { + int drain = 0; + if (this.getFluidAmount() >= apply) { + drain = apply; + } else { + drain = this.getFluidAmount(); + } + this.mFluid.amount -= drain; + if (this.mFluid.amount <= 0) { + this.mFluid = null; + } + // Logger.INFO("Did Hydrate"); + aCrop.setHydrationStorage(aCrop.getHydrationStorage() + drain); + return true; + } else { + // Logger.INFO("No water?"); + return false; + } + } + } + + public boolean consume(int aSlot, int amount, boolean simulate) { + ItemStack stack = this.mInventory[aSlot]; + if (stack != null && stack.stackSize >= amount) { + int currentAmount = Math.min(amount, stack.stackSize); + amount -= currentAmount; + if (!simulate) { + if (stack.stackSize == currentAmount) { + this.mInventory[aSlot] = null; + } else { + stack.stackSize -= currentAmount; + } + } else { + return amount >= 0; + } + return true; + } + return false; + } + + public ItemStack damage(int aSlot, int amount, boolean simulate) { + ItemStack ret = null; + int damageApplied = 0; + ItemStack stack = this.mInventory[aSlot]; + Item item = stack.getItem(); + if (stack != null && item.isDamageable() + && (ret == null || stack.getItem() == ret.getItem() && ItemStack.areItemStackTagsEqual(stack, ret))) { + if (simulate) { + stack = stack.copy(); + } + int maxDamage = DamageHandler.getMaxDamage(stack); + while (amount > 0 && stack.stackSize > 0) { + int currentAmount = Math.min(amount, maxDamage - DamageHandler.getDamage(stack)); + DamageHandler.damage(stack, currentAmount, null); + damageApplied += currentAmount; + amount -= currentAmount; + if (DamageHandler.getDamage(stack) >= maxDamage) { + --stack.stackSize; + DamageHandler.setDamage(stack, 0); + } + + if (ret == null) { + ret = stack.copy(); + } + } + if (stack.stackSize == 0 && !simulate) { + this.mInventory[aSlot] = null; + } + } + + if (ret != null) { + int i = DamageHandler.getMaxDamage(ret); + ret.stackSize = damageApplied / i; + DamageHandler.setDamage(ret, damageApplied % i); + } + return ret; + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return aStack != null && aIndex >= SLOT_OUTPUT_START && aIndex < this.getSizeInventory(); + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + if (aStack != null) { + if (aStack.getItem() + .getUnlocalizedName() + .equals("ic2.itemFertilizer")) { + return aIndex >= SLOT_FERT_1 && aIndex <= SLOT_FERT_4; + } else if (aStack.getItem() + .getUnlocalizedName() + .equals("ic2.itemWeedEx")) { + return aIndex >= SLOT_WEEDEX_1 && aIndex <= SLOT_WEEDEX_2; + } + } + return false; + } + + @Override + public String[] getDescription() { + int aRadius = 10 + getRange(this.mTier); + int aSide = (aRadius - 1) / 2; + return ArrayUtils.addAll( + this.mDescriptionArray, + "Secondary mode can Hydrate/Fertilize/Weed-EX", + "Consumes " + powerUsage() + "eu per harvest", + "Consumes " + powerUsageSecondary() + "eu per secondary operation", + "Can harvest 1 block level above and below itself", + "Radius: " + aSide + " blocks each side (" + aRadius + "x3x" + aRadius + ")", + "Has " + (this.mTier * 5) + "% chance for extra drops", + "Holds " + this.getCapacity() + "L of Water", + CORE.GT_Tooltip.get()); + } + + @Override + public boolean allowCoverOnSide(ForgeDirection side, GT_ItemStack aStack) { + return true; + } + + /* + * @Override public int getTextureIndex(byte aSide, byte aFacing, boolean aActive, boolean aRedstone) { if (aSide == + * aFacing) return 118+(aRedstone?8:0); if (GT_Utility.getOppositeSide(aSide) == aFacing) return + * 113+(aRedstone?8:0); int tIndex = 128+(aRedstone?8:0); switch (aFacing) { case 0: return tIndex+64; case 1: + * return tIndex+32; case 2: switch (aSide) { case 0: return tIndex+32; case 1: return tIndex+32; case 4: return + * tIndex+16; case 5: return tIndex+48; } case 3: switch (aSide) { case 0: return tIndex+64; case 1: return + * tIndex+64; case 4: return tIndex+48; case 5: return tIndex+16; } case 4: switch (aSide) { case 0: return + * tIndex+16; case 1: return tIndex+16; case 2: return tIndex+48; case 3: return tIndex+16; } case 5: switch (aSide) + * { case 0: return tIndex+48; case 1: return tIndex+48; case 2: return tIndex+16; case 3: return tIndex+48; } } + * return tIndex; } + */ + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFront(i); + rTextures[6][i + 1] = this.getBack(i); + rTextures[7][i + 1] = this.getBottom(i); + rTextures[8][i + 1] = this.getTop(i); + rTextures[9][i + 1] = this.getSides(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + if (side == ForgeDirection.DOWN || side == ForgeDirection.UP) { + return this.mTextures[3][aColorIndex + 1]; + } else { + return this.mTextures[4][aColorIndex + 1]; + } + /* + * return this.mTextures[(aActive ? 5 : 0) + (side == facing ? 0 : aSide == GT_Utility.getOppositeSide(aFacing) + * ? 1 : side == ForgeDirection.DOWN ? 2 : side == ForgeDirection.UP ? 3 : 4)][aColorIndex + 1]; + */ + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_CropHarvester_Cutter) }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_CropHarvester_Cutter) }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_CropHarvester_Boxes) }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_CropHarvester_Boxes) }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_CropHarvester_Cutter) }; + } + + @Override + public boolean doesFillContainers() { + return false; + } + + @Override + public boolean doesEmptyContainers() { + return false; + } + + @Override + public boolean canTankBeFilled() { + return true; + } + + @Override + public boolean canTankBeEmptied() { + return false; + } + + @Override + public boolean displaysItemStack() { + return false; + } + + @Override + public boolean displaysStackSize() { + return false; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("mModeAlternative", this.mModeAlternative); + aNBT.setBoolean("mHarvestEnabled", this.mHarvestEnabled); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.mModeAlternative = aNBT.getBoolean("mModeAlternative"); + if (aNBT.hasKey("mHarvestEnabled")) { + this.mHarvestEnabled = aNBT.getBoolean("mHarvestEnabled"); + } + } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget( + new CycleButtonWidget().setToggle(() -> mModeAlternative, val -> mModeAlternative = val) + .setTexture(GTPP_UITextures.OVERLAY_BUTTON_HARVESTER_MODE) + .addTooltip(0, "Enable Hydration/Fertilizing/Weed-EX") + .addTooltip(1, "Disable Hydration/Fertilizing/Weed-EX") + .setBackground(GT_UITextures.BUTTON_STANDARD) + .setPos(47, 63) + .setSize(18, 18)); + builder.widget( + new CycleButtonWidget().setToggle(() -> mHarvestEnabled, val -> mHarvestEnabled = val) + .setTexture(GTPP_UITextures.OVERLAY_BUTTON_HARVESTER_TOGGLE) + .addTooltip(0, "Enable Harvest") + .addTooltip(1, "Disable Harvest") + .setBackground(GT_UITextures.BUTTON_STANDARD) + .setPos(67, 63) + .setSize(18, 18)); + builder.widget( + SlotGroup.ofItemHandler(inventoryHandler, 2) + .startFromSlot(SLOT_WEEDEX_1) + .endAtSlot(SLOT_WEEDEX_2) + .applyForWidget( + widget -> widget.setFilter( + stack -> stack != null && stack.getItem() + .getUnlocalizedName() + .equals("ic2.itemWeedEx")) + .setBackground(getGUITextureSet().getItemSlot(), GTPP_UITextures.OVERLAY_SLOT_WEED_EX)) + .build() + .setPos(7, 13)) + .widget( + SlotGroup.ofItemHandler(inventoryHandler, 2) + .startFromSlot(SLOT_FERT_1) + .endAtSlot(SLOT_FERT_4) + .applyForWidget( + widget -> widget.setFilter( + stack -> stack != null && stack.getItem() + .getUnlocalizedName() + .equals("ic2.itemFertilizer")) + .setBackground(getGUITextureSet().getItemSlot(), GTPP_UITextures.OVERLAY_SLOT_FERTILIZER)) + .build() + .setPos(7, 31)) + .widget( + SlotGroup.ofItemHandler(inventoryHandler, 6) + .startFromSlot(SLOT_OUTPUT_START) + .endAtSlot(SLOT_OUTPUT_START + 6 * 3) + .canInsert(false) + .build() + .setPos(61, 7)); + builder + .widget( + new ProgressBar() + .setTexture(GTPP_UITextures.PROGRESSBAR_BOILER_EMPTY, GT_UITextures.PROGRESSBAR_BOILER_WATER, 54) + .setDirection(ProgressBar.Direction.UP) + .setProgress(() -> (float) getFluidAmount() / getCapacity()) + .setSynced(false, false) + .dynamicTooltip( + () -> Collections.singletonList("Water: " + getFluidAmount() + "L / " + getCapacity() + "L")) + .setPos(47, 7) + .setSize(10, 54)) + .widget(new FakeSyncWidget.FluidStackSyncer(this::getDrainableStack, this::setDrainableStack)); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java new file mode 100644 index 0000000000..9f2789b520 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaAtmosphericReconditioner.java @@ -0,0 +1,893 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import static gregtech.api.enums.GT_Values.V; + +import java.util.Collections; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; +import net.minecraftforge.common.util.ForgeDirection; + +import org.apache.commons.lang3.ArrayUtils; + +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; + +import gregtech.api.enums.Materials; +import gregtech.api.enums.SoundResource; +import gregtech.api.enums.Textures; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.interfaces.ITexture; +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.objects.GT_ItemStack; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Utility; +import gregtech.common.items.GT_MetaGenerated_Tool_01; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.core.item.general.ItemAirFilter; +import gtPlusPlus.core.item.general.ItemBasicScrubberTurbine; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; +import gtPlusPlus.xmod.gregtech.api.gui.GTPP_UITextures; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaAtmosphericReconditioner extends GT_MetaTileEntity_BasicMachine { + + public int mPollutionReduction = 0; + protected int mBaseEff = 2500; + protected int mOptimalAirFlow = 0; + protected boolean mHasPollution = false; + protected int SLOT_ROTOR = 5; + protected int SLOT_FILTER = 6; + protected static boolean mPollutionEnabled = true; + + protected boolean mSaveRotor = false; + + public GregtechMetaAtmosphericReconditioner(int aID, String aName, String aNameRegional, int aTier) { + super( + aID, + aName, + aNameRegional, + aTier, + 2, + "Making sure you don't live in Gwalior - Uses 2A", + 3, + 0, + new ITexture[] { new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_MASSFAB_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_MASSFAB), + new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab_Active), + new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Vent_Fast), + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Vent), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_MASSFAB_ACTIVE), + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_MASSFAB) }); + mPollutionEnabled = PollutionUtils.isPollutionEnabled(); + } + + public GregtechMetaAtmosphericReconditioner(String aName, int aTier, String[] aDescription, + ITexture[][][] aTextures) { + super(aName, aTier, 2, aDescription, aTextures, 2, 0); + mPollutionEnabled = PollutionUtils.isPollutionEnabled(); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaAtmosphericReconditioner(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); + } + + @Override + public String[] getDescription() { + + boolean highTier = this.mTier >= 7; + + String[] A = ArrayUtils.addAll( + this.mDescriptionArray, + highTier ? "Will attempt to remove 1/4 pollution from 8 surrounding chunks" : "", + highTier ? "If these chunks are not loaded, they will be ignored" : "", + "Requires a turbine rotor and an Air Filter [T1/T2] to run.", + "The turbine rotor must be manually inserted/replaced", + "Can be configured with a soldering iron to change modes", + "Low Efficiency: Removes half pollution, Turbine takes 50% dmg", + "High Efficiency: Removes full pollution, Turbine takes 100% dmg", + "Turbine Rotor will not break in LE mode", + "Insert an equal tier Conveyor Module to enable automation"); + if (!mPollutionEnabled) { + String[] B = new String[] { "===============================================", + "Pollution is disabled, scrubbers will now have a bonus use", + "They are now able to remove ALL lingering pollution as GT ignores it", "and it will linger forever!", + "===============================================", }; + A = ArrayUtils.addAll(A, B); + } + return A; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mOptimalAirFlow", this.mOptimalAirFlow); + aNBT.setBoolean("mSaveRotor", mSaveRotor); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.mOptimalAirFlow = aNBT.getInteger("mOptimalAirFlow"); + this.mSaveRotor = aNBT.getBoolean("mSaveRotor"); + } + + @Override + public long maxAmperesIn() { + return 2; + } + + @Override + public long getMinimumStoredEU() { + return V[mTier] * 2; + } + + @Override + public long maxEUStore() { + return V[mTier] * 256; + } + + @Override + public long maxEUInput() { + return V[mTier]; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (aBaseMetaTileEntity.isServerSide()) { + + // Get Current Pollution Amount. + int mCurrentPollution = getCurrentChunkPollution(); + boolean isIdle = true; + + // Get Inventory Item + ItemStack stackRotor = this.mInventory[SLOT_ROTOR]; + ItemStack stackFilter = this.mInventory[SLOT_FILTER]; + + // Power Drain + long drainEU = maxEUInput() * maxAmperesIn(); + if (aBaseMetaTileEntity.isActive() && aBaseMetaTileEntity.getStoredEU() >= drainEU) { + if (aBaseMetaTileEntity.decreaseStoredEnergyUnits(drainEU, false)) { + isIdle = false; + } else { + aBaseMetaTileEntity.setActive(false); + this.sendSound((byte) -122); + } + } else if (!aBaseMetaTileEntity.isActive() && aBaseMetaTileEntity.getStoredEU() >= drainEU / 4) { + if (aBaseMetaTileEntity.decreaseStoredEnergyUnits((drainEU / 4), false)) { + isIdle = false; + } else { + aBaseMetaTileEntity.setActive(false); + this.sendSound((byte) -122); + } + } else { + aBaseMetaTileEntity.setActive(false); + this.sendSound((byte) -122); + } + + // Only try once/sec. + if (!isIdle && aTick % 20L == 0L) { + + for (int i = 0; i < this.mInventory.length; i++) { + ItemStack aSlotContent = this.mInventory[i]; + if (aSlotContent != null) { + Logger.INFO("Found " + aSlotContent.getDisplayName() + " in slot " + i); + } + } + + for (int i = 0; i < this.mInventory.length; i++) { + if (hasRotor(this.mInventory[i])) { + Logger.INFO("Found Rotor in slot " + i); + break; + } + } + for (int i = 0; i < this.mInventory.length; i++) { + if (hasAirFilter(this.mInventory[i])) { + Logger.INFO("Found Filter in slot " + i); + break; + } + } + + // Check if machine can work. + if ((aBaseMetaTileEntity.isAllowedToWork())) { + Logger.INFO("Can work."); + + // Enable machine animation/graphic + if (hasRotor(stackRotor) && hasAirFilter(stackFilter) && this.mHasPollution) { + if (!this.getBaseMetaTileEntity() + .isActive()) { + Logger.INFO("Set Active."); + aBaseMetaTileEntity.setActive(true); + } + } else if (!this.mHasPollution || mCurrentPollution <= 0 + || stackRotor == null + || stackFilter == null + || !hasRotor(stackRotor) + || !hasAirFilter(stackFilter)) { + if (!this.getBaseMetaTileEntity() + .isActive()) { + Logger.INFO("Set Inactive."); + aBaseMetaTileEntity.setActive(false); + this.sendSound((byte) -122); + } + } + + // If Active. + if (aBaseMetaTileEntity.isActive()) { + Logger.INFO("Doing something."); + + // Do nothing if there is no pollution. + if (this.mHasPollution && mCurrentPollution > 0) { + Logger + .INFO("Has Pollution? " + mHasPollution + ", Current Pollution: " + mCurrentPollution); + + // Only check every 30s. + if (!isIdle && aTick % (20L * 30) == 0L) { + mPollutionEnabled = PollutionUtils.isPollutionEnabled(); + // Clear out pollution if it's disabled, because I am a nice gal. + if (!PollutionUtils.isPollutionEnabled()) { + PollutionUtils.nullifyPollution(this.getBaseMetaTileEntity()); + } + } + + // Use a Turbine + if (hasRotor(stackRotor) && hasAirFilter(stackFilter)) { + Logger.INFO("Found Turbine."); + + mBaseEff = getBaseEfficiency(stackRotor); + mOptimalAirFlow = getOptimalAirFlow(stackRotor); + + // Make sure we have a valid Turbine and Eff/Airflow + if (this.mBaseEff > 0 && this.mOptimalAirFlow > 0) { + // Utils.LOG_WARNING("Pollution Cleaner [5]"); + + // Log Debug information. + Logger.INFO("mBaseEff[1]:" + mBaseEff); + Logger.INFO("mOptimalAirFlow[1]:" + mOptimalAirFlow); + + // Calculate The Voltage we are running + long tVoltage = drainEU; + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + + // Check Sides for Air, + // More air means more pollution processing. + int mAirSides = getFreeSpaces(); + + int reduction = 0; + + // If no sides are free, how will you process the atmosphere? + if (mAirSides > 0) { + reduction += (((Math.max((tTier - 2), 1) * 2) * 50) * mAirSides); // Was + // originally + // *100 + Logger.INFO("mPollutionReduction[1]:" + reduction); + + // I stole this code + reduction = (MathUtils.safeInt((long) reduction * this.mBaseEff) / 100000) + * mAirSides + * Math.max((tTier - 2), 1); + Logger.INFO("reduction[2]:" + reduction); + reduction = MathUtils.safeInt(((long) reduction / 100) * this.mOptimalAirFlow); + Logger.INFO("reduction[3]:" + reduction); + + mPollutionReduction = reduction; + + // Set a temp to remove variable to aleviate duplicate code. + int toRemove = 0; + + Logger.INFO("mCurrentPollution[4]:" + mCurrentPollution); + Logger.INFO("mCurrentPollution[5]:" + reduction); + if (reduction <= mCurrentPollution) { + // Clean some Air. + toRemove = reduction; + } else { + // Makes sure we don't get negative pollution. + toRemove = mCurrentPollution; + } + + toRemove = toRemove / 2; + Logger.INFO("mCurrentPollution[6]:" + toRemove); + + // We are good to clean + if (toRemove > 0) { + if (damageTurbineRotor() && damageAirFilter()) { + Logger.INFO("Removing " + toRemove + " pollution"); + removePollution(mSaveRotor ? (toRemove / 2) : toRemove); + Logger.INFO("mNewPollution[4]:" + getCurrentChunkPollution()); + } else { + Logger.INFO("Could not damage turbine rotor or Air Filter."); + aBaseMetaTileEntity.setActive(false); + } + } // End of pollution removal block. + } // End of valid air sides block. + } // End of valid toolstats block. + } // End of correct inventory item block. + else { + // Utils.LOG_WARNING("Wrong Tool metaitem Found."); + } + } + } else if (!aBaseMetaTileEntity.isActive()) { + return; + } + } // End of can work block. + else { // Disable Machine. + // aBaseMetaTileEntity.setActive(false); + } + } // End of 1/sec action block. + else { + + if (hasRotor(stackRotor) && hasAirFilter(stackFilter) + && this.mHasPollution + && !isIdle + && aBaseMetaTileEntity.isAllowedToWork()) { + aBaseMetaTileEntity.setActive(true); + } else if (isIdle || !this.mHasPollution + || mCurrentPollution <= 0 + || stackRotor == null + || stackFilter == null + || !hasRotor(stackRotor) + || !hasAirFilter(stackFilter)) { + aBaseMetaTileEntity.setActive(false); + } + } + if (this.getBaseMetaTileEntity() + .isActive()) { + if (MathUtils.randInt(0, 5) <= 2) { + this.sendSound((byte) -120); + } + } + } // End of is serverside block. + } + + public int getCurrentChunkPollution() { + int mCurrentChunkPollution = 0; + if (this.mTier < 7) { + mCurrentChunkPollution = PollutionUtils.getPollution(getBaseMetaTileEntity()); + } else { + AutoMap<Chunk> aSurrounding = new AutoMap<>(); + World aWorld = this.getBaseMetaTileEntity() + .getWorld(); + int xPos = this.getBaseMetaTileEntity() + .getXCoord(); + int zPos = this.getBaseMetaTileEntity() + .getZCoord(); + Chunk a1 = aWorld.getChunkFromBlockCoords(xPos - 32, zPos - 32); + Chunk a2 = aWorld.getChunkFromBlockCoords(xPos - 32, zPos); + Chunk a3 = aWorld.getChunkFromBlockCoords(xPos - 32, zPos + 32); + Chunk b1 = aWorld.getChunkFromBlockCoords(xPos, zPos - 32); + Chunk b2 = aWorld.getChunkFromBlockCoords(xPos, zPos); + Chunk b3 = aWorld.getChunkFromBlockCoords(xPos, zPos + 32); + Chunk c1 = aWorld.getChunkFromBlockCoords(xPos + 32, zPos - 32); + Chunk c2 = aWorld.getChunkFromBlockCoords(xPos + 32, zPos); + Chunk c3 = aWorld.getChunkFromBlockCoords(xPos + 32, zPos + 32); + aSurrounding.put(a1); + aSurrounding.put(a2); + aSurrounding.put(a3); + aSurrounding.put(b1); + aSurrounding.put(b2); + aSurrounding.put(b3); + aSurrounding.put(c1); + aSurrounding.put(c2); + aSurrounding.put(c3); + for (Chunk r : aSurrounding) { + mCurrentChunkPollution += getPollutionInChunk(r); + } + } + if (mCurrentChunkPollution > 0) { + mHasPollution = true; + } else { + mHasPollution = false; + } + return mCurrentChunkPollution; + } + + public int getPollutionInChunk(Chunk aChunk) { + int mCurrentChunkPollution = PollutionUtils.getPollution(aChunk); + if (mCurrentChunkPollution > 0) { + mHasPollution = true; + } else { + mHasPollution = false; + } + return mCurrentChunkPollution; + } + + public boolean hasRotor(ItemStack rotorStack) { + if (rotorStack != null) { + if (rotorStack.getItem() instanceof ItemBasicScrubberTurbine) { + // Logger.INFO("Found Basic Turbine Rotor."); + return true; + } else if (rotorStack.getItem() instanceof GT_MetaGenerated_Tool && rotorStack.getItemDamage() >= 170 + && rotorStack.getItemDamage() <= 179) { + // Logger.INFO("Found Turbine Rotor."); + return true; + } else { + // Logger.INFO("Found: "+rotorStack.getDisplayName()+":"+rotorStack.getItemDamage()); + } + } + // Logger.INFO("Found No Turbine Rotor."); + return false; + } + + public boolean damageTurbineRotor() { + try { + + boolean creativeRotor = false; + ItemStack rotorStack = this.mInventory[SLOT_ROTOR]; + if (rotorStack == null) { + return false; + } else if (rotorStack.getItem() instanceof ItemBasicScrubberTurbine) { + long currentUse = ItemBasicScrubberTurbine.getFilterDamage(rotorStack); + // Remove broken Filter + if (rotorStack.getItemDamage() == 0 && currentUse >= 2000 - 10) { + Logger.INFO("Depleting ItemBasicScrubberTurbine T1"); + this.mInventory[this.SLOT_FILTER] = null; + return false; + } else if (rotorStack.getItemDamage() == 1 && currentUse >= 4000 - 10) { + Logger.INFO("Depleting ItemBasicScrubberTurbine T2"); + this.mInventory[this.SLOT_FILTER] = null; + return false; + } else if (rotorStack.getItemDamage() == 2 && currentUse >= 6000 - 10) { + Logger.INFO("Depleting ItemBasicScrubberTurbine T3"); + this.mInventory[this.SLOT_FILTER] = null; + return false; + } else { + // Do Damage + Logger.INFO("Damaging ItemBasicScrubberTurbine"); + ItemBasicScrubberTurbine.setFilterDamage(rotorStack, currentUse + 10); + Logger.INFO("Rotor Damage: " + currentUse); + return true; + } + } else if (rotorStack.getItem() instanceof GT_MetaGenerated_Tool_01) { + Materials t1 = GT_MetaGenerated_Tool.getPrimaryMaterial(rotorStack); + Materials t2 = GT_MetaGenerated_Tool.getSecondaryMaterial(rotorStack); + if (t1 == Materials._NULL && t2 == Materials._NULL) { + Logger.INFO("Found creative rotor."); + creativeRotor = true; + } + } else { + Logger.INFO("Bad item in rotor slot."); + return false; + } + + if (mInventory[SLOT_ROTOR].getItem() instanceof GT_MetaGenerated_Tool_01 + && ((GT_MetaGenerated_Tool) mInventory[SLOT_ROTOR].getItem()).getToolStats(mInventory[SLOT_ROTOR]) + .getSpeedMultiplier() > 0 + && GT_MetaGenerated_Tool.getPrimaryMaterial(mInventory[SLOT_ROTOR]).mToolSpeed > 0) { + + long damageValue = (long) Math + .floor(Math.abs(MathUtils.randFloat(1, 2) - MathUtils.randFloat(1, 3)) * (1 + 3 - 1) + 1); + double fDam = Math + .floor(Math.abs(MathUtils.randFloat(1f, 2f) - MathUtils.randFloat(1f, 2f)) * (1f + 2f - 1f) + 1f); + damageValue -= fDam; + + // Logger.INFO("Trying to do "+damageValue+" damage to the rotor. ["+fDam+"]"); + /* + * Materials M1 = GT_MetaGenerated_Tool.getPrimaryMaterial(this.mInventory[this.SLOT_ROTOR]); Materials + * M2 = GT_MetaGenerated_Tool.getSecondaryMaterial(this.mInventory[this.SLOT_ROTOR]); + * Logger.INFO("Trying to do "+damageValue+" damage to the rotor. [2]"); + */ + + // Damage Rotor + // int rotorDurability = this.mInventory[this.SLOT_ROTOR].getItemDamage(); + long rotorDamage = creativeRotor ? 0 + : GT_MetaGenerated_Tool.getToolDamage(this.mInventory[this.SLOT_ROTOR]); + long rotorDurabilityMax = creativeRotor ? Integer.MAX_VALUE + : GT_MetaGenerated_Tool.getToolMaxDamage(this.mInventory[this.SLOT_ROTOR]); + long rotorDurability = (rotorDurabilityMax - rotorDamage); + Logger.INFO( + "Rotor Damage: " + rotorDamage + + " | Max Durability: " + + rotorDurabilityMax + + " | " + + " Remaining Durability: " + + rotorDurability); + if (rotorDurability >= damageValue) { + + if (!mSaveRotor) { + Logger.INFO("Damaging Rotor."); + + if (!creativeRotor) GT_ModHandler + .damageOrDechargeItem(this.mInventory[this.SLOT_ROTOR], (int) damageValue, 0, null); + + long tempDur = GT_MetaGenerated_Tool.getToolDamage(this.mInventory[this.SLOT_ROTOR]); + if (tempDur < rotorDurabilityMax) { + return true; + } else { + rotorDurability = 0; + } + } else { + Logger.INFO("Damaging Rotor."); + if (rotorDurability > 1000) { + if (!creativeRotor) GT_ModHandler + .damageOrDechargeItem(this.mInventory[this.SLOT_ROTOR], (int) damageValue / 2, 0, null); + long tempDur = GT_MetaGenerated_Tool.getToolDamage(this.mInventory[this.SLOT_ROTOR]); + if (tempDur < rotorDurabilityMax) { + return true; + } else { + rotorDurability = 0; + } + } + } + } + + if (rotorDurability <= 0 && !mSaveRotor && !creativeRotor) { + Logger.INFO("Destroying Rotor."); + this.mInventory[this.SLOT_ROTOR] = null; + return false; + } else if (rotorDurability <= 0 && mSaveRotor) { + Logger.INFO("Saving Rotor."); + return false; + } + + } else { + Logger.INFO("Bad Rotor."); + return false; + } + } catch (Throwable t) { + t.printStackTrace(); + } + return false; + } + + public int getFreeSpaces() { + int mAir = 0; + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + if (aBaseMetaTileEntity.getAirOffset(1, 0, 0)) { + mAir++; + } + if (aBaseMetaTileEntity.getAirOffset(-1, 0, 0)) { + mAir++; + } + if (aBaseMetaTileEntity.getAirOffset(0, 0, 1)) { + mAir++; + } + if (aBaseMetaTileEntity.getAirOffset(0, 0, -1)) { + mAir++; + } + if (aBaseMetaTileEntity.getAirOffset(0, 1, 0)) { + mAir++; + } + if (aBaseMetaTileEntity.getAirOffset(0, -1, 0)) { + mAir++; + } + return mAir; + } + + public boolean removePollution(int toRemove) { + + if (this == null || this.getBaseMetaTileEntity() == null + || this.getBaseMetaTileEntity() + .getWorld() == null) { + return false; + } + + if (this.mTier < 7) { + int startPollution = getCurrentChunkPollution(); + Logger.INFO("Current Chunk Pollution: " + startPollution); + PollutionUtils.removePollution(this.getBaseMetaTileEntity(), toRemove); + int after = getCurrentChunkPollution(); + Logger.INFO("Current Chunk Pollution: " + after); + return (after < startPollution); + } else { + int chunksWithRemoval = 0; + int totalRemoved = 0; + AutoMap<Chunk> aSurrounding = new AutoMap<>(); + Chunk aThisChunk = this.getBaseMetaTileEntity() + .getWorld() + .getChunkFromBlockCoords( + this.getBaseMetaTileEntity() + .getXCoord(), + this.getBaseMetaTileEntity() + .getZCoord()); + int mainChunkX = aThisChunk.xPosition; + int mainChunkZ = aThisChunk.zPosition; + + World aWorld = this.getBaseMetaTileEntity() + .getWorld(); + int xPos = this.getBaseMetaTileEntity() + .getXCoord(); + int zPos = this.getBaseMetaTileEntity() + .getZCoord(); + + Chunk a1 = aWorld.getChunkFromBlockCoords(xPos - 32, zPos - 32); + Chunk a2 = aWorld.getChunkFromBlockCoords(xPos - 32, zPos); + Chunk a3 = aWorld.getChunkFromBlockCoords(xPos - 32, zPos + 32); + Chunk b1 = aWorld.getChunkFromBlockCoords(xPos, zPos - 32); + Chunk b2 = aWorld.getChunkFromBlockCoords(xPos, zPos); + Chunk b3 = aWorld.getChunkFromBlockCoords(xPos, zPos + 32); + Chunk c1 = aWorld.getChunkFromBlockCoords(xPos + 32, zPos - 32); + Chunk c2 = aWorld.getChunkFromBlockCoords(xPos + 32, zPos); + Chunk c3 = aWorld.getChunkFromBlockCoords(xPos + 32, zPos + 32); + + aSurrounding.put(a1); + aSurrounding.put(a2); + aSurrounding.put(a3); + aSurrounding.put(b1); + aSurrounding.put(b2); + aSurrounding.put(b3); + aSurrounding.put(c1); + aSurrounding.put(c2); + aSurrounding.put(c3); + + for (Chunk r : aSurrounding) { + if (!r.isChunkLoaded) { + continue; + } + + int startPollution = getPollutionInChunk(r); + if (startPollution == 0) { + continue; + } + + Logger.INFO( + "Trying to remove pollution from chunk " + r.xPosition + + ", " + + r.zPosition + + " | " + + startPollution); + int after = 0; + boolean isMainChunk = r.isAtLocation(mainChunkX, mainChunkZ); + + int removal = Math.max(0, !isMainChunk ? (toRemove / 4) : toRemove); + if (removePollution(r, removal)) { + chunksWithRemoval++; + after = getPollutionInChunk(r); + } else { + after = 0; + } + if (startPollution - after > 0) { + totalRemoved += (startPollution - after); + } + Logger.INFO( + "Removed " + (startPollution - after) + + " pollution from chunk " + + r.xPosition + + ", " + + r.zPosition + + " | " + + after); + } + return totalRemoved > 0 && chunksWithRemoval > 0; + } + } + + public boolean removePollution(Chunk aChunk, int toRemove) { + int before = getCurrentChunkPollution(); + PollutionUtils.removePollution(aChunk, toRemove); + int after = getCurrentChunkPollution(); + return (after < before); + } + + public boolean hasAirFilter(ItemStack filter) { + if (filter == null) { + return false; + } + return filter.getItem() instanceof ItemAirFilter; + } + + public boolean damageAirFilter() { + ItemStack filter = this.mInventory[this.SLOT_FILTER]; + if (filter == null) { + return false; + } + + boolean creativeRotor = false; + ItemStack rotorStack = this.mInventory[SLOT_ROTOR]; + if (rotorStack != null) { + if (rotorStack.getItem() instanceof GT_MetaGenerated_Tool_01) { + Materials t1 = GT_MetaGenerated_Tool.getPrimaryMaterial(rotorStack); + Materials t2 = GT_MetaGenerated_Tool.getSecondaryMaterial(rotorStack); + if (t1 == Materials._NULL && t2 == Materials._NULL) { + creativeRotor = true; + } + } + } + + if (creativeRotor) { + return true; + } + + if (filter.getItem() instanceof ItemAirFilter) { + + long currentUse = ItemAirFilter.getFilterDamage(filter); + + // Remove broken Filter + if (filter.getItemDamage() == 0 && currentUse >= 50 - 1) { + this.mInventory[this.SLOT_FILTER] = null; + return false; + } else if (filter.getItemDamage() == 1 && currentUse >= 2500 - 1) { + this.mInventory[this.SLOT_FILTER] = null; + return false; + } else { + // Do Damage + ItemAirFilter.setFilterDamage(filter, currentUse + 1); + Logger.INFO("Filter Damage: " + currentUse); + return true; + } + } + return false; + } + + @Override + public boolean canInsertItem(int aIndex, ItemStack aStack, int ordinalSide) { + if (aIndex == SLOT_FILTER) { + if (aStack.getItem() instanceof ItemAirFilter) { + Logger.INFO("Inserting Air Filter into " + aIndex); + return true; + } + } + if (aIndex == SLOT_ROTOR) { + if (this.mInventory[7] != null) { + Logger.INFO("Found conveyor, can automate turbines. Inserting into " + aIndex); + if (aStack.getItem() instanceof ItemBasicScrubberTurbine) { + return true; + } + if (aStack.getItem() instanceof GT_MetaGenerated_Tool && aStack.getItemDamage() >= 170 + && aStack.getItemDamage() <= 179) { + return true; + } + } + } + return false; + } + + @Override + public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + super.onScrewdriverRightClick(side, aPlayer, aX, aY, aZ); + } + + @Override + public void doSound(byte aIndex, double aX, double aY, double aZ) { + if (aIndex == -120) { + GT_Utility + .doSoundAtClient(SoundResource.IC2_TOOLS_BATTERY_USE, MathUtils.randInt(5, 50), 0.05F, aX, aY, aZ); + } else { + super.doSound((byte) 0, aX, aY, aZ); + } + } + + @Override + public String[] getInfoData() { + AutoMap<String> aTooltipSuper = new AutoMap<>(); + for (String s : super.getInfoData()) { + aTooltipSuper.put(s); + } + int mAirSides = getFreeSpaces(); + int reduction = 0; + + try { + long tVoltage = maxEUInput(); + byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + reduction += (((Math.max((tTier - 2), 1) * 2) * 50) * mAirSides); + reduction = (MathUtils.safeInt((long) reduction * this.mBaseEff) / 100000) * mAirSides + * Math.max((tTier - 2), 1); + reduction = MathUtils.safeInt(((long) reduction / 100) * this.mOptimalAirFlow); + + aTooltipSuper.put("Maximum pollution removed per second: " + reduction); + } catch (Throwable t) { + aTooltipSuper.put("Maximum pollution removed per second: " + mPollutionReduction); + } + aTooltipSuper.put("Air Sides: " + mAirSides); + + String[] mBuiltOutput = new String[aTooltipSuper.size()]; + int aIndex = 0; + for (String i : aTooltipSuper) { + mBuiltOutput[aIndex++] = i; + } + + return mBuiltOutput; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public boolean allowCoverOnSide(ForgeDirection side, GT_ItemStack aCoverID) { + if (side.offsetY != 0) { + return false; + } + return super.allowCoverOnSide(side, aCoverID); + } + + @Override + public ITexture[] getTopFacingInactive(byte aColor) { + return super.getTopFacingInactive(aColor); + } + + @Override + public void setItemNBT(NBTTagCompound aNBT) { + aNBT.setInteger("mOptimalAirFlow", this.mOptimalAirFlow); + aNBT.setBoolean("mSaveRotor", mSaveRotor); + super.setItemNBT(aNBT); + } + + private static ItemStack[] sGregTurbines; + + public static ItemStack getTieredTurbine(int aTier) { + if (sGregTurbines == null) { + sGregTurbines = new ItemStack[3]; + sGregTurbines[0] = GT_MetaGenerated_Tool.sInstances.get("gt.metatool.01") + .getToolWithStats(GT_MetaGenerated_Tool_01.TURBINE_SMALL, 1, Materials.Iron, Materials.Iron, null); + sGregTurbines[1] = GT_MetaGenerated_Tool.sInstances.get("gt.metatool.01") + .getToolWithStats(GT_MetaGenerated_Tool_01.TURBINE_SMALL, 1, Materials.Bronze, Materials.Bronze, null); + sGregTurbines[2] = GT_MetaGenerated_Tool.sInstances.get("gt.metatool.01") + .getToolWithStats(GT_MetaGenerated_Tool_01.TURBINE_SMALL, 1, Materials.Steel, Materials.Steel, null); + } else { + return sGregTurbines[aTier]; + } + + return null; + } + + public int getBaseEfficiency(ItemStack aStackRotor) { + if (aStackRotor.getItem() instanceof ItemBasicScrubberTurbine) { + return getBaseEfficiency(getTieredTurbine(aStackRotor.getItemDamage())); + } + return (int) ((50.0F + + (10.0F * ((GT_MetaGenerated_Tool) aStackRotor.getItem()).getToolCombatDamage(aStackRotor))) * 100); + } + + public int getOptimalAirFlow(ItemStack aStackRotor) { + if (aStackRotor.getItem() instanceof ItemBasicScrubberTurbine) { + return getOptimalAirFlow(getTieredTurbine(aStackRotor.getItemDamage())); + } + return (int) Math.max( + Float.MIN_NORMAL, + ((GT_MetaGenerated_Tool) aStackRotor.getItem()).getToolStats(aStackRotor) + .getSpeedMultiplier() * GT_MetaGenerated_Tool.getPrimaryMaterial(aStackRotor).mToolSpeed * 50); + } + + @Override + public boolean useModularUI() { + return true; + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget(new SlotWidget(inventoryHandler, SLOT_ROTOR).setFilter(stack -> { + if (stack.getItem() instanceof ItemBasicScrubberTurbine) { + return true; + } + return stack.getItem() instanceof GT_MetaGenerated_Tool && stack.getItemDamage() >= 170 + && stack.getItemDamage() <= 179; + }) + .setBackground(getGUITextureSet().getItemSlot(), GTPP_UITextures.OVERLAY_SLOT_TURBINE) + .setPos(52, 24)) + .widget( + new SlotWidget(inventoryHandler, SLOT_FILTER) + .setFilter(stack -> stack.getItem() instanceof ItemAirFilter) + .setBackground(getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_RECYCLE) + .setPos(106, 24)) + .widget( + new SlotWidget(inventoryHandler, 7) + .setFilter(stack -> GT_Utility.areStacksEqual(stack, CI.getConveyor(mTier, 1), true)) + .setPos(124, 62)); + builder.widget( + new DrawableWidget().setDrawable(GT_UITextures.PICTURE_INFORMATION) + .dynamicTooltip(() -> Collections.singletonList("Reduction: " + mPollutionReduction + "/s")) + .attachSyncer( + new FakeSyncWidget.IntegerSyncer(() -> mPollutionReduction, val -> mPollutionReduction = val), + builder, + (widget, val) -> widget.notifyTooltipChange()) + .setPos(163, 5) + .setSize(7, 18)); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionCreator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionCreator.java new file mode 100644 index 0000000000..d7b6b8fffd --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionCreator.java @@ -0,0 +1,458 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +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.objects.GT_RenderedTexture; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMetaTileEntity; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaPollutionCreator extends GregtechMetaTileEntity { + + int mCurrentPollution; + int mAveragePollution; + int mAveragePollutionArray[] = new int[10]; + private int mArrayPos = 0; + private int mTickTimer = 0; + private int mSecondTimer = 0; + + public GregtechMetaPollutionCreator(final int aID, final String aName, final String aNameRegional, final int aTier, + final String aDescription, final int aSlotCount) { + super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); + } + + public GregtechMetaPollutionCreator(final String aName, final int aTier, final String aDescription, + final ITexture[][][] aTextures, final int aSlotCount) { + super(aName, aTier, aSlotCount, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] { this.mDescription, "A useful debug machine to create pollution.", CORE.GT_Tooltip.get() }; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + return this.mTextures[(aActive ? 5 : 0) + (side == facing ? 0 + : side == facing.getOpposite() ? 1 + : side == ForgeDirection.DOWN ? 2 : side == ForgeDirection.UP ? 3 : 4)][aColorIndex + 1]; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2) }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2) }; + } + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier + 3][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + @Override + public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (pollutionMultiplier > 99) { + pollutionMultiplier = 1; + } else { + pollutionMultiplier++; + } + PlayerUtils.messagePlayer(aPlayer, "Pollution Mutliplier is now " + pollutionMultiplier + "."); + super.onScrewdriverRightClick(side, aPlayer, aX, aY, aZ); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaPollutionCreator( + this.mName, + this.mTier, + this.mDescription, + this.mTextures, + this.mInventory.length); + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isElectric() { + return true; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return true; + } + + @Override + public boolean isFacingValid(final ForgeDirection facing) { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isEnetOutput() { + return false; + } + + @Override + public boolean isInputFacing(final ForgeDirection side) { + return side != this.getBaseMetaTileEntity() + .getFrontFacing(); + } + + @Override + public boolean isOutputFacing(final ForgeDirection side) { + return side == this.getBaseMetaTileEntity() + .getFrontFacing(); + } + + @Override + public boolean isTeleporterCompatible() { + return false; + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public long maxEUStore() { + return 0; + } + + @Override + public int getCapacity() { + return 0; + } + + @Override + public long maxEUInput() { + return 0; + } + + @Override + public long maxEUOutput() { + return 0; + } + + @Override + public long maxAmperesIn() { + return 0; + } + + @Override + public long maxAmperesOut() { + return 0; + } + + @Override + public int rechargerSlotStartIndex() { + return 0; + } + + @Override + public int dechargerSlotStartIndex() { + return 0; + } + + @Override + public int rechargerSlotCount() { + return 0; + } + + @Override + public int dechargerSlotCount() { + return 0; + } + + @Override + public int getProgresstime() { + return (int) this.getBaseMetaTileEntity() + .getUniversalEnergyStored(); + } + + @Override + public int maxProgresstime() { + return (int) this.getBaseMetaTileEntity() + .getUniversalEnergyCapacity(); + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + this.showPollution(aPlayer.getEntityWorld(), aPlayer); + return true; + } + + public int pollutionMultiplier = 1; + + private void showPollution(final World worldIn, final EntityPlayer playerIn) { + if (!PollutionUtils.isPollutionEnabled()) { + PlayerUtils.messagePlayer(playerIn, "This block is useless, Pollution is disabled."); + } else { + addPollution(); + PlayerUtils + .messagePlayer(playerIn, "This chunk now contains " + getCurrentChunkPollution() + " pollution."); + // PlayerUtils.messagePlayer(playerIn, "Average over last ten minutes: "+getAveragePollutionOverLastTen()+" + // pollution."); + } + } + + private boolean addPollution() { + PollutionUtils.addPollution(getBaseMetaTileEntity(), 100000 * pollutionMultiplier); + return true; + } + + @Override + public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + return false; + } + + public int getCurrentChunkPollution() { + return getCurrentChunkPollution(this.getBaseMetaTileEntity()); + } + + public int getCurrentChunkPollution(IGregTechTileEntity aBaseMetaTileEntity) { + return PollutionUtils.getPollution(aBaseMetaTileEntity); + } + + @Override + public String[] getInfoData() { + return new String[] { this.getLocalName(), "Current Pollution: " + this.mCurrentPollution, + "Average/10 minutes:" + getAveragePollutionOverLastTen() }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { + return new int[] {}; + } + + @Override + public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { + return false; + } + + @Override + public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { + return false; + } + + @Override + public int getSizeInventory() { + return 0; + } + + @Override + public ItemStack getStackInSlot(final int p_70301_1_) { + return null; + } + + @Override + public ItemStack decrStackSize(final int p_70298_1_, final int p_70298_2_) { + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(final int p_70304_1_) { + return null; + } + + @Override + public void setInventorySlotContents(final int p_70299_1_, final ItemStack p_70299_2_) {} + + @Override + public String getInventoryName() { + return null; + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public int getInventoryStackLimit() { + return 0; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { + return false; + } + + @Override + public void openInventory() {} + + @Override + public void closeInventory() {} + + @Override + public boolean isItemValidForSlot(final int p_94041_1_, final ItemStack p_94041_2_) { + return false; + } + + @Override + public boolean isOverclockerUpgradable() { + return false; + } + + @Override + public boolean isTransformerUpgradable() { + return false; + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setInteger("mCurrentPollution", this.mCurrentPollution); + aNBT.setInteger("mAveragePollution", this.mAveragePollution); + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + this.mCurrentPollution = aNBT.getInteger("mCurrentPollution"); + this.mAveragePollution = aNBT.getInteger("mAveragePollution"); + } + + @Override + public void onFirstTick(final IGregTechTileEntity aBaseMetaTileEntity) { + if (this.getBaseMetaTileEntity() + .isServerSide()) { + if (this.mCurrentPollution == 0) { + this.mCurrentPollution = getCurrentChunkPollution(); + } + if (this.mArrayPos < 0 || this.mArrayPos > 9) { + this.mArrayPos = 0; + } + this.mTickTimer = 0; + } + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (this.getBaseMetaTileEntity() + .isServerSide()) { + // TickTimer - 20 times a second + this.mTickTimer++; + if (mTickTimer % 20 == 0) { + this.mCurrentPollution = getCurrentChunkPollution(); + } + } + } + + public int getAveragePollutionOverLastTen() { + int counter = 0; + int total = 0; + + for (int j : this.mAveragePollutionArray) { + if (j != 0) { + total += j; + counter++; + } + } + int returnValue = 0; + if (total > 0 && counter > 0) { + returnValue = (total / counter); + this.mAveragePollution = returnValue; + } else { + returnValue = getCurrentChunkPollution(); + } + // Logger.INFO("| DEBUG: "+returnValue +" | ArrayPos:"+this.mArrayPos+" | Counter:"+counter+" | Total:"+total+" + // |"); + return returnValue; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionDetector.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionDetector.java new file mode 100644 index 0000000000..92443d2658 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaPollutionDetector.java @@ -0,0 +1,502 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +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.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMetaTileEntity; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaPollutionDetector extends GregtechMetaTileEntity { + + int mCurrentPollution; + int mAveragePollution; + int mAveragePollutionArray[] = new int[10]; + private int mArrayPos = 0; + private int mTickTimer = 0; + private int mSecondTimer = 0; + private long mRedstoneLevel = 0; + + public GregtechMetaPollutionDetector(final int aID, final String aName, final String aNameRegional, final int aTier, + final String aDescription, final int aSlotCount) { + super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); + } + + public GregtechMetaPollutionDetector(final String aName, final int aTier, final String aDescription, + final ITexture[][][] aTextures, final int aSlotCount) { + super(aName, aTier, aSlotCount, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] { this.mDescription, "Right click to check pollution levels.", + "Configure with screwdriver to set redstone output amount.", "Does not use power.", CORE.GT_Tooltip.get() }; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + return side == facing + ? new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Dimensional), + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_Frequency) } + : new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Dimensional), + new GT_RenderedTexture(Textures.BlockIcons.VOID) }; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + /* + * @Override public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final byte aSide, final + * byte aFacing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { return + * this.mTextures[(aActive ? 5 : 0) + (side == facing ? 0 : side == facing.getOpposite() ? 1 : side == + * ForgeDirection.DOWN ? 2 : side == ForgeDirection.UP ? 3 : 4)][aColorIndex + 1]; } + */ + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2) }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2) }; + } + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaPollutionDetector( + this.mName, + this.mTier, + this.mDescription, + this.mTextures, + this.mInventory.length); + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isElectric() { + return true; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return true; + } + + @Override + public boolean isFacingValid(final ForgeDirection facing) { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isEnetOutput() { + return false; + } + + @Override + public boolean isInputFacing(final ForgeDirection side) { + return side != this.getBaseMetaTileEntity() + .getFrontFacing(); + } + + @Override + public boolean isOutputFacing(final ForgeDirection side) { + return side == this.getBaseMetaTileEntity() + .getFrontFacing(); + } + + @Override + public boolean isTeleporterCompatible() { + return false; + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public long maxEUStore() { + return 0; + } + + @Override + public int getCapacity() { + return 0; + } + + @Override + public long maxEUInput() { + return 0; + } + + @Override + public long maxEUOutput() { + return 0; + } + + @Override + public long maxAmperesIn() { + return 0; + } + + @Override + public long maxAmperesOut() { + return 0; + } + + @Override + public int rechargerSlotStartIndex() { + return 0; + } + + @Override + public int dechargerSlotStartIndex() { + return 0; + } + + @Override + public int rechargerSlotCount() { + return 0; + } + + @Override + public int dechargerSlotCount() { + return 0; + } + + @Override + public int getProgresstime() { + return (int) this.getBaseMetaTileEntity() + .getUniversalEnergyStored(); + } + + @Override + public int maxProgresstime() { + return (int) this.getBaseMetaTileEntity() + .getUniversalEnergyCapacity(); + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + this.showPollution(aPlayer.getEntityWorld(), aPlayer); + return true; + } + + private void showPollution(final World worldIn, final EntityPlayer playerIn) { + if (!PollutionUtils.isPollutionEnabled()) { + PlayerUtils.messagePlayer(playerIn, "This block is useless, Pollution is disabled."); + } else { + PlayerUtils.messagePlayer(playerIn, "This chunk contains " + getCurrentChunkPollution() + " pollution."); + PlayerUtils.messagePlayer(playerIn, "Emit Redstone at pollution level: " + this.mRedstoneLevel); + } + } + + @Override + public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + return false; + } + + public int getCurrentChunkPollution() { + return getCurrentChunkPollution(this.getBaseMetaTileEntity()); + } + + public int getCurrentChunkPollution(IGregTechTileEntity aBaseMetaTileEntity) { + return PollutionUtils.getPollution(aBaseMetaTileEntity); + } + + @Override + public String[] getInfoData() { + return new String[] { this.getLocalName(), "Current Pollution: " + this.mCurrentPollution, + "Average/10 Sec: " + this.mAveragePollution, "Emit Redstone at pollution level: " + this.mRedstoneLevel }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { + return new int[] {}; + } + + @Override + public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { + return false; + } + + @Override + public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { + return false; + } + + @Override + public int getSizeInventory() { + return 0; + } + + @Override + public ItemStack getStackInSlot(final int p_70301_1_) { + return null; + } + + @Override + public ItemStack decrStackSize(final int p_70298_1_, final int p_70298_2_) { + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(final int p_70304_1_) { + return null; + } + + @Override + public void setInventorySlotContents(final int p_70299_1_, final ItemStack p_70299_2_) {} + + @Override + public String getInventoryName() { + return null; + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public int getInventoryStackLimit() { + return 0; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { + return false; + } + + @Override + public void openInventory() {} + + @Override + public void closeInventory() {} + + @Override + public boolean isItemValidForSlot(final int p_94041_1_, final ItemStack p_94041_2_) { + return false; + } + + @Override + public boolean isOverclockerUpgradable() { + return false; + } + + @Override + public boolean isTransformerUpgradable() { + return false; + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setInteger("mCurrentPollution", this.mCurrentPollution); + aNBT.setInteger("mAveragePollution", this.mAveragePollution); + aNBT.setLong("mRedstoneLevel", this.mRedstoneLevel); + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + this.mCurrentPollution = aNBT.getInteger("mCurrentPollution"); + this.mAveragePollution = aNBT.getInteger("mAveragePollution"); + this.mRedstoneLevel = aNBT.getLong("mRedstoneLevel"); + } + + @Override + public void onFirstTick(final IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + } + + public boolean allowCoverOnSide(final ForgeDirection side, final int aCoverID) { + return side != this.getBaseMetaTileEntity() + .getFrontFacing(); + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + + // Only Calc server-side + if (!this.getBaseMetaTileEntity() + .isServerSide()) { + return; + } + // Emit Redstone + if (this.getCurrentChunkPollution() >= this.mRedstoneLevel) { + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + this.getBaseMetaTileEntity() + .setStrongOutputRedstoneSignal(side, (byte) 16); + } + this.markDirty(); + } else { + for (final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { + this.getBaseMetaTileEntity() + .setStrongOutputRedstoneSignal(side, (byte) 0); + } + this.markDirty(); + } + + // Do Math for stats + if (this.mTickTimer % 20 == 0) { + mCurrentPollution = this.getCurrentChunkPollution(); + if (mArrayPos > mAveragePollutionArray.length - 1) { + mArrayPos = 0; + } + mAveragePollutionArray[mArrayPos] = mCurrentPollution; + mAveragePollution = getAveragePollutionOverLastTen(); + mArrayPos++; + } + this.mTickTimer++; + } + + public int getAveragePollutionOverLastTen() { + return MathUtils.getIntAverage(mAveragePollutionArray); + } + + @Override + public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + + if (side == this.getBaseMetaTileEntity() + .getFrontFacing()) { + final float[] tCoords = GT_Utility.getClickedFacingCoords(side, aX, aY, aZ); + switch ((byte) ((byte) (int) (tCoords[0] * 2.0F) + (2 * (byte) (int) (tCoords[1] * 2.0F)))) { + case 0 -> this.mRedstoneLevel -= 5000; + case 1 -> this.mRedstoneLevel += 5000; + case 2 -> this.mRedstoneLevel -= 50000; + case 3 -> this.mRedstoneLevel += 50000; + } + this.markDirty(); + GT_Utility.sendChatToPlayer(aPlayer, "Emit Redstone at Pollution Level: " + this.mRedstoneLevel); + } + + super.onScrewdriverRightClick(side, aPlayer, aX, aY, aZ); + } + + @Override + public boolean allowGeneralRedstoneOutput() { + if (this.getCurrentChunkPollution() >= this.mRedstoneLevel) { + this.markDirty(); + return true; + } + return false; + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, ForgeDirection side, + float aX, float aY, float aZ) { + return super.onRightclick(aBaseMetaTileEntity, aPlayer, side, aX, aY, aZ); + } + + @Override + public void onMachineBlockUpdate() { + super.onMachineBlockUpdate(); + } + + @Override + public boolean hasSidedRedstoneOutputBehavior() { + if (this.getCurrentChunkPollution() >= this.mRedstoneLevel) { + this.markDirty(); + return true; + } + return false; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_AutoChisel.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_AutoChisel.java new file mode 100644 index 0000000000..751771f2b4 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_AutoChisel.java @@ -0,0 +1,190 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +import org.apache.commons.lang3.ArrayUtils; + +import com.gtnewhorizons.modularui.api.drawable.FallbackableUITexture; +import com.gtnewhorizons.modularui.api.drawable.IDrawable; +import com.gtnewhorizons.modularui.api.math.Pos2d; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; + +import gregtech.api.enums.Textures.BlockIcons; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.recipe.BasicUIProperties; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import team.chisel.carving.Carving; + +public class GregtechMetaTileEntity_AutoChisel extends GT_MetaTileEntity_BasicMachine { + + private ItemStack mInputCache; + private ItemStack mOutputCache; + + public GregtechMetaTileEntity_AutoChisel(int aID, String aName, String aNameRegional, int aTier) { + super( + aID, + aName, + aNameRegional, + aTier, + 1, + "Chisels things, Gregtech style", + 1, + 1, + new ITexture[] { new GT_RenderedTexture(BlockIcons.OVERLAY_SIDE_MASSFAB_ACTIVE), + new GT_RenderedTexture(BlockIcons.OVERLAY_SIDE_MASSFAB), + new GT_RenderedTexture(BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_ACTIVE), + new GT_RenderedTexture(BlockIcons.OVERLAY_FRONT_MULTI_SMELTER), + new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab_Active), + new GT_RenderedTexture(TexturesGtBlock.Overlay_MatterFab), + new GT_RenderedTexture(BlockIcons.OVERLAY_BOTTOM_MASSFAB_ACTIVE), + new GT_RenderedTexture(BlockIcons.OVERLAY_BOTTOM_MASSFAB) }); + } + + public GregtechMetaTileEntity_AutoChisel(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, 1, aDescription, aTextures, 1, 1); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_AutoChisel(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); + } + + @Override + public String[] getDescription() { + return ArrayUtils.addAll( + this.mDescriptionArray, + "What you want to chisel goes in slot 1", + "What you want to get goes in the special slot (bottom right)", + "If special slot is empty, first chisel result is used"); + } + + private boolean hasValidCache(ItemStack aStack, ItemStack aSpecialSlot, boolean aClearOnFailure) { + if (mInputCache != null && mOutputCache != null) { + if (GT_Utility.areStacksEqual(aStack, mInputCache) + && GT_Utility.areStacksEqual(aSpecialSlot, mOutputCache)) { + return true; + } + } + // clear cache if it was invalid + if (aClearOnFailure) { + mInputCache = null; + mOutputCache = null; + } + return false; + } + + private void cacheItem(ItemStack mInputItem, ItemStack mOutputItem) { + mOutputCache = mOutputItem.copy(); + mInputCache = mInputItem.copy(); + } + + @Override + protected boolean allowPutStackValidated(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return hasValidCache(aStack, this.getSpecialSlot(), false) ? true + : super.allowPutStackValidated(aBaseMetaTileEntity, aIndex, side, aStack) && hasChiselResults(aStack); + } + + // lets make sure the user isn't trying to make something from a block that doesn't have this as a valid target + private static boolean canBeMadeFrom(ItemStack from, ItemStack to) { + List<ItemStack> results = getItemsForChiseling(from); + for (ItemStack s : results) { + if (s.getItem() == to.getItem() && s.getItemDamage() == to.getItemDamage()) { + return true; + } + } + return false; + } + + // lets make sure the user isn't trying to make something from a block that doesn't have this as a valid target + private static boolean hasChiselResults(ItemStack from) { + List<ItemStack> results = getItemsForChiseling(from); + return results.size() > 0; + } + + private static List<ItemStack> getItemsForChiseling(ItemStack aStack) { + return Carving.chisel.getItemsForChiseling(aStack); + } + + private static ItemStack getChiselOutput(ItemStack aInput, ItemStack aTarget) { + ItemStack tOutput = null; + if (aTarget != null && canBeMadeFrom(aInput, aTarget)) { + tOutput = aTarget; + } else if (aTarget != null && !canBeMadeFrom(aInput, aTarget)) { + tOutput = null; + } else { + tOutput = getItemsForChiseling(aInput).get(0); + } + return tOutput; + } + + @Override + public int checkRecipe() { + ItemStack tOutput = null; + ItemStack aInput = getInputAt(0); + ItemStack aTarget = getSpecialSlot(); + boolean tIsCached = hasValidCache(aInput, aTarget, true); + if (aInput != null && hasChiselResults(aInput) && aInput.stackSize > 0) { + tOutput = tIsCached ? mOutputCache.copy() : getChiselOutput(aInput, aTarget); + if (tOutput != null) { + tOutput = tOutput.copy(); + tOutput.stackSize = 1; + // We can chisel this + if (canOutput(tOutput)) { + getInputAt(0).stackSize -= 1; + calculateOverclockedNess(16, 20); + // In case recipe is too OP for that machine + if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) { + return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; + } + if (!tIsCached) { + cacheItem(ItemUtils.getSimpleStack(aInput, 1), ItemUtils.getSimpleStack(tOutput, 1)); + } + this.mOutputItems[0] = tOutput.copy(); + return FOUND_AND_SUCCESSFULLY_USED_RECIPE; + } else { + mOutputBlocked++; + return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS; + } + } + } + return DID_NOT_FIND_RECIPE; + } + + @Override + public boolean useModularUI() { + return true; + } + + private static final FallbackableUITexture progressBarTexture = GT_UITextures + .fallbackableProgressbar("auto_chisel", GT_UITextures.PROGRESSBAR_COMPRESS); + + @Override + protected BasicUIProperties getUIProperties() { + return super.getUIProperties().toBuilder() + .progressBarTexture(progressBarTexture) + .build(); + } + + @Override + protected SlotWidget createItemInputSlot(int index, IDrawable[] backgrounds, Pos2d pos) { + return (SlotWidget) super.createItemInputSlot(index, backgrounds, pos) + .setBackground(getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_COMPRESSOR); + } + + @Override + protected SlotWidget createSpecialSlot(IDrawable[] backgrounds, Pos2d pos, BasicUIProperties uiProperties) { + return (SlotWidget) super.createSpecialSlot(backgrounds, pos, uiProperties) + .setGTTooltip(() -> mTooltipCache.getData("GTPP.machines.chisel_slot.tooltip")); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaWirelessCharger.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaWirelessCharger.java new file mode 100644 index 0000000000..b1289958a9 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaWirelessCharger.java @@ -0,0 +1,672 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.basic; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.enums.GT_Values; +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.metatileentity.BaseMetaTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.EntityUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMetaTileEntity; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.common.helpers.ChargingHelper; + +public class GregtechMetaWirelessCharger extends GregtechMetaTileEntity { + + private int mCurrentDimension = 0; + public int mMode = 0; + public boolean mLocked = true; + + public GregtechMetaWirelessCharger(final int aID, final String aName, final String aNameRegional, final int aTier, + final String aDescription, final int aSlotCount) { + super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); + } + + public GregtechMetaWirelessCharger(final String aName, final int aTier, final String aDescription, + final ITexture[][][] aTextures, final int aSlotCount) { + super(aName, aTier, aSlotCount, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] { this.mDescription, "Can be locked to the owner by sneaking with a screwdriver", + "Can also be locked with a lock upgrade", "", "3 Modes, Long-Range, Local and Mixed.", + "Long-Range: Can supply 2A of power to a single player up to " + (GT_Values.V[this.mTier] * 4) + "m away.", + "Local: Can supply several Amps to each player within " + this.mTier * 20 + "m.", + "Mixed: Provides both 2A of long range and 1A per player locally.", + "Mixed mode is more conservative of power and as a result only", + "Gets half the distances each singular mode gets.", CORE.GT_Tooltip.get() }; + } + + public int getTier() { + return this.mTier; + } + + public int getMode() { + return this.mMode; + } + + public int getDimensionID() { + return this.mCurrentDimension; + } + + public Map<String, UUID> getLocalMap() { + return this.mLocalChargingMap; + } + + public Map<String, UUID> getLongRangeMap() { + return this.mWirelessChargingMap; + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + return this.mTextures[(aActive ? 5 : 0) + (side == facing ? 0 + : side == facing.getOpposite() ? 1 + : side == ForgeDirection.DOWN ? 2 : side == ForgeDirection.UP ? 3 : 4)][aColorIndex + 1]; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2) }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Screen_2) }; + } + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + @Override + public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + + if (aPlayer.isSneaking()) { + mLocked = !mLocked; + PlayerUtils.messagePlayer(aPlayer, mLocked ? "Locked to owner." : "Unlocked."); + return; + } + + mWirelessChargingMap.clear(); + mLocalChargingMap.clear(); + if (!this.getBaseMetaTileEntity() + .getWorld().playerEntities.isEmpty()) { + for (Object mTempPlayer : this.getBaseMetaTileEntity() + .getWorld().playerEntities) { + if (mTempPlayer instanceof EntityPlayer || mTempPlayer instanceof EntityPlayerMP) { + EntityPlayer mTemp = (EntityPlayer) mTempPlayer; + ChargingHelper.removeValidPlayer(mTemp, this); + } + } + } + + if (this.mMode >= 2) { + this.mMode = 0; + } else { + this.mMode++; + } + if (this.mMode == 0) { + PlayerUtils.messagePlayer(aPlayer, "Now in Long-Range Charge Mode."); + } else if (this.mMode == 1) { + PlayerUtils.messagePlayer(aPlayer, "Now in Local Charge Mode."); + } else { + PlayerUtils.messagePlayer(aPlayer, "Now in Mixed Charge Mode."); + } + super.onScrewdriverRightClick(side, aPlayer, aX, aY, aZ); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaWirelessCharger( + this.mName, + this.mTier, + this.mDescription, + this.mTextures, + this.mInventory.length); + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isElectric() { + return true; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return true; + } + + @Override + public boolean isFacingValid(final ForgeDirection facing) { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isEnetOutput() { + return false; + } + + @Override + public boolean isInputFacing(final ForgeDirection side) { + return side != this.getBaseMetaTileEntity() + .getFrontFacing(); + } + + @Override + public boolean isOutputFacing(final ForgeDirection side) { + return side == this.getBaseMetaTileEntity() + .getFrontFacing(); + } + + @Override + public boolean isTeleporterCompatible() { + return false; + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public long maxEUStore() { + return GT_Values.V[this.mTier] * 128; + } + + @Override + public int getCapacity() { + return (int) (GT_Values.V[this.mTier] * 32); + } + + @Override + public long maxEUInput() { + return GT_Values.V[this.mTier]; + } + + @Override + public long maxEUOutput() { + return 0; + } + + @Override + public long maxAmperesIn() { + if (this.mMode == 0) { + return 2; + } else if (this.mMode == 1) { + return this.mLocalChargingMap.size() * 8; + } else { + return ((this.mLocalChargingMap.size() * 4) + this.mWirelessChargingMap.size()); + } + } + + @Override + public long maxAmperesOut() { + return 0; + } + + @Override + public int rechargerSlotStartIndex() { + return 0; + } + + @Override + public int dechargerSlotStartIndex() { + return 0; + } + + @Override + public int rechargerSlotCount() { + return 0; + } + + @Override + public int dechargerSlotCount() { + return 0; + } + + @Override + public int getProgresstime() { + return (int) this.getBaseMetaTileEntity() + .getUniversalEnergyStored(); + } + + @Override + public int maxProgresstime() { + return (int) this.getBaseMetaTileEntity() + .getUniversalEnergyCapacity(); + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + return true; + } + + @Override + public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + return false; + } + + @Override + public String[] getInfoData() { + return new String[] { this.getLocalName() }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { + return new int[] {}; + } + + @Override + public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { + return false; + } + + @Override + public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { + return false; + } + + @Override + public int getSizeInventory() { + return 0; + } + + @Override + public ItemStack getStackInSlot(final int p_70301_1_) { + return null; + } + + @Override + public ItemStack decrStackSize(final int p_70298_1_, final int p_70298_2_) { + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(final int p_70304_1_) { + return null; + } + + @Override + public void setInventorySlotContents(final int p_70299_1_, final ItemStack p_70299_2_) {} + + @Override + public String getInventoryName() { + return null; + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public int getInventoryStackLimit() { + return 0; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { + return false; + } + + @Override + public void openInventory() {} + + @Override + public void closeInventory() {} + + @Override + public boolean isItemValidForSlot(final int p_94041_1_, final ItemStack p_94041_2_) { + return false; + } + + @Override + public boolean isOverclockerUpgradable() { + return false; + } + + @Override + public boolean isTransformerUpgradable() { + return false; + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setBoolean("mLocked", this.mLocked); + aNBT.setInteger("mMode", this.mMode); + aNBT.setInteger("mCurrentDimension", this.mCurrentDimension); + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + this.mLocked = aNBT.getBoolean("mLocked"); + this.mMode = aNBT.getInteger("mMode"); + this.mCurrentDimension = aNBT.getInteger("mCurrentDimension"); + } + + @Override + public void onFirstTick(final IGregTechTileEntity aBaseMetaTileEntity) { + super.onFirstTick(aBaseMetaTileEntity); + } + + private Map<String, UUID> mWirelessChargingMap = new HashMap<>(); + private Map<String, UUID> mLocalChargingMap = new HashMap<>(); + + private boolean isValidPlayer(EntityPlayer aPlayer) { + BaseMetaTileEntity aTile = (BaseMetaTileEntity) this.getBaseMetaTileEntity(); + if (mLocked || (aTile != null && aTile.privateAccess())) { + if (aPlayer.getUniqueID() + .equals(getBaseMetaTileEntity().getOwnerUuid())) { + return true; + } else { + return false; + } + } + return true; + } + + @Override + public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (this.getBaseMetaTileEntity() + .isServerSide()) { + + if (this.mCurrentDimension != aBaseMetaTileEntity.getWorld().provider.dimensionId) { + this.mCurrentDimension = aBaseMetaTileEntity.getWorld().provider.dimensionId; + } + + if (aTick % 20 == 0) { + boolean mHasBeenMapped = this.equals(ChargingHelper.getEntry(getTileEntityPosition())); + if (!mHasBeenMapped) { + mHasBeenMapped = ChargingHelper.addEntry(getTileEntityPosition(), this); + } + + if (mHasBeenMapped && !aBaseMetaTileEntity.getWorld().playerEntities.isEmpty()) { + for (Object mTempPlayer : aBaseMetaTileEntity.getWorld().playerEntities) { + if (mTempPlayer instanceof EntityPlayer || mTempPlayer instanceof EntityPlayerMP) { + EntityPlayer mTemp = (EntityPlayer) mTempPlayer; + + if (this.mMode == 1 || this.mMode == 2) { + int tempRange = (this.mMode == 1 ? this.mTier * 20 : this.mTier * 10); + if (getDistanceBetweenTwoPositions(getTileEntityPosition(), getPositionOfEntity(mTemp)) + < tempRange) { + if (isValidPlayer(mTemp) + && !mLocalChargingMap.containsKey(mTemp.getDisplayName())) { + mLocalChargingMap.put(mTemp.getDisplayName(), mTemp.getPersistentID()); + ChargingHelper.addValidPlayer(mTemp, this); + // PlayerUtils.messagePlayer(mTemp, "You have entered charging range. + // ["+tempRange+"m - Local]."); + } + } else { + if (mLocalChargingMap.containsKey(mTemp.getDisplayName())) { + if (mLocalChargingMap.remove(mTemp.getDisplayName()) != null) { + // PlayerUtils.messagePlayer(mTemp, "You have left charging range. + // ["+tempRange+"m - Local]."); + ChargingHelper.removeValidPlayer(mTemp, this); + } + } + } + } + if (this.mMode == 0 || this.mMode == 2) { + int tempRange = (int) (this.mMode == 0 ? 4 * GT_Values.V[this.mTier] + : 2 * GT_Values.V[this.mTier]); + if (getDistanceBetweenTwoPositions(getTileEntityPosition(), getPositionOfEntity(mTemp)) + <= tempRange) { + if (!mWirelessChargingMap.containsKey(mTemp.getDisplayName())) { + if (isValidPlayer(mTemp)) { + mWirelessChargingMap.put(mTemp.getDisplayName(), mTemp.getPersistentID()); + ChargingHelper.addValidPlayer(mTemp, this); + PlayerUtils.messagePlayer( + mTemp, + "You have entered charging range. [" + tempRange + "m - Long-Range]."); + } + } + } else { + if (mWirelessChargingMap.containsKey(mTemp.getDisplayName())) { + if (mWirelessChargingMap.remove(mTemp.getDisplayName()) != null) { + PlayerUtils.messagePlayer( + mTemp, + "You have left charging range. [" + tempRange + "m - Long Range]."); + ChargingHelper.removeValidPlayer(mTemp, this); + } + } + } + } + /* + * if (this.mMode == 0 || this.mMode == 2){ int tempRange = (int) (this.mMode == 0 ? + * 4*GT_Values.V[this.mTier] : 2*GT_Values.V[this.mTier]); if + * (getDistanceBetweenTwoPositions(getTileEntityPosition(), getPositionOfEntity(mTemp)) < + * tempRange){ if (!mWirelessChargingMap.containsKey(mTemp)){ + * mWirelessChargingMap.put(mTemp, mTemp.getPersistentID()); + * PlayerUtils.messagePlayer(mTemp, "You have entered charging range. ["+tempRange+"m]."); + * ChargingHelper.addValidPlayer(mTemp, this); } } else { if + * (mWirelessChargingMap.containsKey(mTemp)){ if (mWirelessChargingMap.remove(mTemp) != + * null){ PlayerUtils.messagePlayer(mTemp, + * "You have left charging range. ["+tempRange+"m]."); + * ChargingHelper.removeValidPlayer(mTemp, this); } } } } + */ + + } + } + } + } + } + } + + public BlockPos getTileEntityPosition() { + return new BlockPos( + this.getBaseMetaTileEntity() + .getXCoord(), + this.getBaseMetaTileEntity() + .getYCoord(), + this.getBaseMetaTileEntity() + .getZCoord(), + this.getBaseMetaTileEntity() + .getWorld()); + } + + public BlockPos getPositionOfEntity(Entity mEntity) { + if (mEntity == null) { + return null; + } + return EntityUtils.findBlockPosUnderEntity(mEntity); + } + + public double getDistanceBetweenTwoPositions(BlockPos objectA, BlockPos objectB) { + if (objectA == null || objectB == null) { + return 0f; + } + int[] objectArray1 = new int[] { objectA.xPos, objectA.yPos, objectA.zPos }; + int[] objectArray2 = new int[] { objectB.xPos, objectB.yPos, objectB.zPos }; + + final double distance = Math.sqrt( + (objectArray2[0] - objectArray1[0]) * (objectArray2[0] - objectArray1[0]) + + (objectArray2[1] - objectArray1[1]) * (objectArray2[1] - objectArray1[1]) + + (objectArray2[2] - objectArray1[2]) * (objectArray2[2] - objectArray1[2])); + return distance; + } + + @Override + public void onRemoval() { + + ChargingHelper.removeEntry(getTileEntityPosition(), this); + + mWirelessChargingMap.clear(); + mLocalChargingMap.clear(); + if (!this.getBaseMetaTileEntity() + .getWorld().playerEntities.isEmpty()) { + for (Object mTempPlayer : this.getBaseMetaTileEntity() + .getWorld().playerEntities) { + if (mTempPlayer instanceof EntityPlayer || mTempPlayer instanceof EntityPlayerMP) { + EntityPlayer mTemp = (EntityPlayer) mTempPlayer; + ChargingHelper.removeValidPlayer(mTemp, this); + } + } + } + + super.onRemoval(); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, ForgeDirection side, + float aX, float aY, float aZ) { + + int tempRange; + + if (this.mMode == 0 || this.mMode == 2) { + tempRange = (int) (this.mMode == 0 ? 4 * GT_Values.V[this.mTier] : 2 * GT_Values.V[this.mTier]); + } else { + tempRange = this.mMode == 1 ? this.mTier * 20 : this.mTier * 10; + } + + if (this.mMode == 2) { + PlayerUtils + .messagePlayer(aPlayer, "Mixed Mode | Local: " + this.mTier * 10 + "m | Long: " + tempRange + "m"); + PlayerUtils.messagePlayer(aPlayer, "Players with access:"); + for (String name : this.getLocalMap() + .keySet()) { + PlayerUtils.messagePlayer(aPlayer, "Local: " + name); + } + for (String name : this.getLongRangeMap() + .keySet()) { + PlayerUtils.messagePlayer(aPlayer, "Long: " + name); + } + } else if (this.mMode == 1) { + PlayerUtils.messagePlayer(aPlayer, "Local Mode: " + this.mTier * 20 + "m"); + PlayerUtils.messagePlayer(aPlayer, "Players with access:"); + for (String name : this.getLocalMap() + .keySet()) { + PlayerUtils.messagePlayer(aPlayer, "" + name); + } + + } else { + PlayerUtils.messagePlayer(aPlayer, "Long-range Mode: " + tempRange + "m"); + PlayerUtils.messagePlayer(aPlayer, "Players with access:"); + for (String name : this.getLongRangeMap() + .keySet()) { + PlayerUtils.messagePlayer(aPlayer, "" + name); + } + } + + return super.onRightclick(aBaseMetaTileEntity, aPlayer, side, aX, aY, aZ); + } + + @Override + public void onServerStart() { + mWirelessChargingMap.clear(); + mLocalChargingMap.clear(); + super.onServerStart(); + } + + @Override + public void onExplosion() { + ChargingHelper.removeEntry(getTileEntityPosition(), this); + super.onExplosion(); + } + + @Override + public void doExplosion(long aExplosionPower) { + ChargingHelper.removeEntry(getTileEntityPosition(), this); + super.doExplosion(aExplosionPower); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GMTE_AmazonPackager.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GMTE_AmazonPackager.java new file mode 100644 index 0000000000..0e71c3b9b1 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/misc/GMTE_AmazonPackager.java @@ -0,0 +1,168 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.misc; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import net.minecraft.item.ItemStack; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GMTE_AmazonPackager extends GregtechMeta_MultiBlockBase<GMTE_AmazonPackager> + implements ISurvivalConstructable { + + private int mCasing; + + private static IStructureDefinition<GMTE_AmazonPackager> STRUCTURE_DEFINITION = null; + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GMTE_AmazonPackager(mName); + } + + public GMTE_AmazonPackager(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GMTE_AmazonPackager(String aName) { + super(aName); + } + + @Override + public String getMachineType() { + return "Packager"; + } + + @Override + public IStructureDefinition<GMTE_AmazonPackager> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GMTE_AmazonPackager>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "C~C", "C-C", "CCC" }, { "CCC", "CCC", "CCC" }, })) + .addElement( + 'C', + buildHatchAdder(GMTE_AmazonPackager.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(TAE.getIndexFromPage(2, 9)) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings3Misc, 9)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Amazon Warehouse") + .addInfo("This Multiblock is used for EXTREME packaging requirements") + .addInfo("Dust Schematics are inserted into the input busses") + .addInfo("If inserted into the controller, it is shared across all busses") + .addInfo("1x, 2x, 3x & Other Schematics are to be placed into the controller GUI slot") + .addInfo("500% faster than using single block machines of the same voltage") + .addInfo("Only uses 75% of the EU/t normally required") + .addInfo("Processes 16 items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front center") + .addCasingInfoMin("Supply Depot Casings", 10, false) + .addInputBus("Any casing", 1) + .addOutputBus("Any casing", 1) + .addEnergyHatch("Any casing", 1) + .addMaintenanceHatch("Any casing", 1) + .addMufflerHatch("Any casing", 1) + .toolTipFinisher("GT++"); + return tt; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return TAE.getIndexFromPage(2, 9); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return RecipeMaps.packagerRecipes; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setSpeedBonus(1F / 6F) + .setEuModifier(0.75F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); + } + + @Override + public int getMaxEfficiency(ItemStack p0) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack arg0) { + return CORE.ConfigSwitches.pollutionPerSecondMultiPackager; + } + + @Override + public int getMaxParallelRecipes() { + return (16 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean supportsInputSeparation() { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialAlloySmelter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialAlloySmelter.java new file mode 100644 index 0000000000..e5d138dfda --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialAlloySmelter.java @@ -0,0 +1,223 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_StructureUtility.ofCoil; + +import net.minecraft.item.ItemStack; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.HeatingCoilLevel; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_OverclockCalculator; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; + +public class GregtechMetaTileEntity_IndustrialAlloySmelter extends + GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialAlloySmelter> implements ISurvivalConstructable { + + public static int CASING_TEXTURE_ID; + private HeatingCoilLevel mHeatingCapacity; + private int mLevel = 0; + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialAlloySmelter> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialAlloySmelter(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 1); + } + + public GregtechMetaTileEntity_IndustrialAlloySmelter(String aName) { + super(aName); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 1); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialAlloySmelter(this.mName); + } + + @Override + protected IIconContainer getActiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_ACTIVE; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER; + } + + @Override + protected int getCasingTextureId() { + return CASING_TEXTURE_ID; + } + + @Override + public RecipeMap<?> getRecipeMap() { + return RecipeMaps.alloySmelterRecipes; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialAlloySmelter; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public String getMachineType() { + return "Alloy Smelter"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Alloy Smelter") + .addInfo("Gains one parallel per voltage tier") + .addInfo("Gains one multiplier per coil tier") + .addInfo("Parallel = Tier * Coil Tier") + .addInfo("Gains 5% speed bonus per coil tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 5, 3, true) + .addController("Bottom center") + .addCasingInfoMin("Inconel Reinforced Casings", 8, false) + .addOtherStructurePart("Integral Encasement V", "Middle Layer") + .addOtherStructurePart("Heating Coils", "Above and below Integral Encasements") + .addInputBus("Any Inconel Reinforced Casing", 1) + .addOutputBus("Any Inconel Reinforced Casing", 1) + .addEnergyHatch("Any Inconel Reinforced Casing", 1) + .addMaintenanceHatch("Any Inconel Reinforced Casing", 1) + .addMufflerHatch("Any Inconel Reinforced Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialAlloySmelter> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialAlloySmelter>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "HHH", "H-H", "HHH" }, { "VVV", "V-V", "VVV" }, + { "HHH", "H-H", "HHH" }, { "C~C", "CCC", "CCC" }, })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialAlloySmelter.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(CASING_TEXTURE_ID) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings3Misc, 1)))) + .addElement( + 'H', + ofCoil( + GregtechMetaTileEntity_IndustrialAlloySmelter::setCoilLevel, + GregtechMetaTileEntity_IndustrialAlloySmelter::getCoilLevel)) + .addElement('V', ofBlock(ModBlocks.blockCasingsTieredGTPP, 4)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 4, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 4, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mLevel = 0; + setCoilLevel(HeatingCoilLevel.None); + return checkPiece(mName, 1, 4, 0) && mCasing >= 8 + && getCoilLevel() != HeatingCoilLevel.None + && (mLevel = getCoilLevel().getTier() + 1) > 0 + && checkHatch(); + } + + @Override + public int getMaxParallelRecipes() { + return (this.mLevel * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic() { + + @NotNull + @Override + protected GT_OverclockCalculator createOverclockCalculator(@NotNull GT_Recipe recipe) { + return super.createOverclockCalculator(recipe).setSpeedBoost(100F / (100F + 5F * mLevel)) + .setHeatOC(true) + .setRecipeHeat(0) + // Need to multiply by 2 because heat OC is done only once every 1800 and this one does it once + // every + // 900 + .setMachineHeat((int) (getCoilLevel().getHeat() * 2)); + } + }.setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + public HeatingCoilLevel getCoilLevel() { + return mHeatingCapacity; + } + + public void setCoilLevel(HeatingCoilLevel aCoilLevel) { + mHeatingCapacity = aCoilLevel; + } + + @Override + public boolean isInputSeparationEnabled() { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialArcFurnace.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialArcFurnace.java new file mode 100644 index 0000000000..c27422fb93 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialArcFurnace.java @@ -0,0 +1,337 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import java.util.Arrays; +import java.util.Collection; + +import javax.annotation.Nonnull; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.common.util.ForgeDirection; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.SoundResource; +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_IndustrialArcFurnace + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialArcFurnace> implements ISurvivalConstructable { + + // 862 + private static final int mCasingTextureID = TAE.getIndexFromPage(3, 3); + public static String mCasingName = "Tempered Arc Furnace Casing"; + private boolean mPlasmaMode = false; + private int mSize = 0; + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialArcFurnace> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialArcFurnace(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialArcFurnace(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialArcFurnace(this.mName); + } + + @Override + public String getMachineType() { + return "(Plasma/Electric) Arc Furnace"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for Industrial Arc Furnace") + .addInfo("250% faster than using single block machines of the same voltage") + .addInfo("Processes 8 items per voltage tier * W/L") + .addInfo("Right-click controller with a Screwdriver to change modes") + .addInfo("Max Size required to process Plasma recipes") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .addController("Top center") + .addStructureInfo("Size: nxnx3 [WxHxL] (Hollow)") + .addStructureInfo("n can be 3, 5 or 7") + .addCasingInfoMin(mCasingName, 10, false) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + /** + * The front part of multi. Used to determine the tier, or in other words, determine the size of multi. + */ + private static final String STRUCTURE_PIECE_FRONT = "front"; + /** + * The rest part of multi. + */ + private static final String STRUCTURE_PIECE_REST = "rest"; + private static final int MAX_TIER = 3; + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialArcFurnace> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialArcFurnace>builder() + .addShape(STRUCTURE_PIECE_FRONT + 1, new String[][] { { "CCC", "C~C", "CCC" } }) + .addShape(STRUCTURE_PIECE_FRONT + 2, new String[][] { { "CCCCC", "C C", "C C", "C C", "CCCCC" } }) + .addShape( + STRUCTURE_PIECE_FRONT + 3, + new String[][] { { "CCCCCCC", "C C", "C C", "C C", "C C", "C C", "CCCCCCC" }, }) + .addShape(STRUCTURE_PIECE_REST + 1, new String[][] { { "CCC", "C-C", "CCC" }, { "CCC", "CCC", "CCC" } }) + .addShape( + STRUCTURE_PIECE_REST + 2, + new String[][] { { "CCCCC", "C---C", "C---C", "C---C", "CCCCC" }, + { "CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC" } }) + .addShape( + STRUCTURE_PIECE_REST + 3, + new String[][] { { "CCCCCCC", "C-----C", "C-----C", "C-----C", "C-----C", "C-----C", "CCCCCCC" }, + { "CCCCCCC", "CCCCCCC", "CCCCCCC", "CCCCCCC", "CCCCCCC", "CCCCCCC", "CCCCCCC" }, }) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialArcFurnace.class) + .atLeast(InputBus, InputHatch, OutputBus, OutputHatch, Maintenance, Energy, Muffler) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .allowOnly(ForgeDirection.NORTH) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings4Misc, 3)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + private int getTierFromHint(ItemStack stackSize) { + if (stackSize.stackSize <= 0 || stackSize.stackSize >= MAX_TIER) { + return MAX_TIER; + } + return stackSize.stackSize; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + int maxTier = getTierFromHint(stackSize); + for (int tier = 1; tier <= maxTier; tier++) { + buildPiece(STRUCTURE_PIECE_FRONT + tier, stackSize, hintsOnly, tier, tier, 0); + } + buildPiece(STRUCTURE_PIECE_REST + maxTier, stackSize, hintsOnly, maxTier, maxTier, -1); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + int maxTier = getTierFromHint(stackSize); + int built; + for (int tier = 1; tier <= maxTier; tier++) { + built = survivialBuildPiece( + STRUCTURE_PIECE_FRONT + tier, + stackSize, + tier, + tier, + 0, + elementBudget, + env, + false, + true); + if (built >= 0) return built; + } + + return survivialBuildPiece( + STRUCTURE_PIECE_REST + maxTier, + stackSize, + maxTier, + maxTier, + -1, + elementBudget, + env, + false, + true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mSize = 0; + int tier = 0; + while (tier < MAX_TIER && checkPiece(STRUCTURE_PIECE_FRONT + (tier + 1), (tier + 1), (tier + 1), 0)) { + tier++; + } + if (tier <= 0) return false; + if (checkPiece(STRUCTURE_PIECE_REST + tier, tier, tier, -1)) { + mSize = 2 * tier + 1; + return mCasing >= 10 && checkHatch(); + } + return false; + } + + @Override + protected SoundResource getProcessStartSound() { + return SoundResource.IC2_MACHINES_ELECTROFURNACE_LOOP; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return mCasingTextureID; + } + + @Override + public RecipeMap<?> getRecipeMap() { + return mPlasmaMode ? RecipeMaps.plasmaArcFurnaceRecipes : RecipeMaps.arcFurnaceRecipes; + } + + @Nonnull + @Override + public Collection<RecipeMap<?>> getAvailableRecipeMaps() { + return Arrays.asList(RecipeMaps.arcFurnaceRecipes, RecipeMaps.plasmaArcFurnaceRecipes); + } + + @Override + public int getRecipeCatalystPriority() { + return -1; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setSpeedBonus(1F / 3.5F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public int getMaxParallelRecipes() { + return (this.mSize * 8 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialArcFurnace; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings4Misc; + } + + public byte getCasingMeta() { + return 3; + } + + public byte getCasingTextureIndex() { + return (byte) mCasingTextureID; + } + + @Override + public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (this.mSize > 5) { + this.mPlasmaMode = !mPlasmaMode; + if (mPlasmaMode) { + PlayerUtils.messagePlayer( + aPlayer, + "[" + EnumChatFormatting.RED + + "MODE" + + EnumChatFormatting.RESET + + "] " + + EnumChatFormatting.LIGHT_PURPLE + + "Plasma" + + EnumChatFormatting.RESET); + } else { + PlayerUtils.messagePlayer( + aPlayer, + "[" + EnumChatFormatting.RED + + "MODE" + + EnumChatFormatting.RESET + + "] " + + EnumChatFormatting.YELLOW + + "Electric" + + EnumChatFormatting.RESET); + } + } else { + PlayerUtils.messagePlayer( + aPlayer, + "[" + EnumChatFormatting.RED + + "MODE" + + EnumChatFormatting.RESET + + "] " + + EnumChatFormatting.GRAY + + "Cannot change mode, structure not large enough." + + EnumChatFormatting.RESET); + } + mLastRecipe = null; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("mPlasmaMode", mPlasmaMode); + aNBT.setInteger("mSize", mSize); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mPlasmaMode = aNBT.getBoolean("mPlasmaMode"); + mSize = aNBT.getInteger("mSize"); + } + + @Override + public void onMachineBlockUpdate() { + mUpdate = 100; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCentrifuge.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCentrifuge.java new file mode 100644 index 0000000000..c04620d4b4 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCentrifuge.java @@ -0,0 +1,228 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.CustomIcon; + +public class GregtechMetaTileEntity_IndustrialCentrifuge + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialCentrifuge> implements ISurvivalConstructable { + + private boolean mIsAnimated; + private static final CustomIcon frontFaceActive = new CustomIcon("iconsets/LARGECENTRIFUGE_ACTIVE5"); + private static final CustomIcon frontFace = new CustomIcon("iconsets/LARGECENTRIFUGE5"); + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialCentrifuge> STRUCTURE_DEFINITION = null; + // public static double recipesComplete = 0; + + public GregtechMetaTileEntity_IndustrialCentrifuge(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + mIsAnimated = true; + } + + public GregtechMetaTileEntity_IndustrialCentrifuge(final String aName) { + super(aName); + mIsAnimated = true; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialCentrifuge(this.mName); + } + + @Override + public String getMachineType() { + return "Centrifuge"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Centrifuge") + .addInfo("125% faster than using single block machines of the same voltage") + .addInfo("Disable animations with a screwdriver") + .addInfo("Only uses 90% of the EU/t normally required") + .addInfo("Processes six items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfoMin("Centrifuge Casings", 6, false) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialCentrifuge> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialCentrifuge>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "C~C", "C-C", "CCC" }, { "CCC", "CCC", "CCC" }, })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialCentrifuge.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 0)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 6 && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + if (usingAnimations()) { + return frontFaceActive; + } else { + return frontFace; + } + } + + @Override + protected IIconContainer getInactiveOverlay() { + return frontFace; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(0); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.centrifugeNonCellRecipes; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setEuModifier(0.9F) + .setSpeedBonus(1F / 2.25F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public int getMaxParallelRecipes() { + return (6 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + public Block getCasingBlock() { + return ModBlocks.blockCasingsMisc; + } + + public byte getCasingMeta() { + return 0; + } + + public byte getCasingTextureIndex() { + return (byte) TAE.GTPP_INDEX(0); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialCentrifuge; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + this.mIsAnimated = !mIsAnimated; + Logger.INFO("Is Centrifuge animated " + this.mIsAnimated); + if (this.mIsAnimated) { + PlayerUtils.messagePlayer(aPlayer, "Using Animated Turbine Texture. "); + } else { + PlayerUtils.messagePlayer(aPlayer, "Using Static Turbine Texture. "); + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("mIsAnimated", mIsAnimated); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + if (aNBT.hasKey("mIsAnimated")) { + mIsAnimated = aNBT.getBoolean("mIsAnimated"); + } else { + mIsAnimated = true; + } + } + + public boolean usingAnimations() { + // Logger.INFO("Is animated? "+this.mIsAnimated); + return this.mIsAnimated; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialChisel.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialChisel.java new file mode 100644 index 0000000000..a9f18dfce8 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialChisel.java @@ -0,0 +1,342 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import java.util.List; +import java.util.stream.Stream; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fluids.FluidStack; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.SoundResource; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_StreamUtil; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_ChiselBus; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import team.chisel.carving.Carving; + +public class GregtechMetaTileEntity_IndustrialChisel + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialChisel> implements ISurvivalConstructable { + + private int mCasing; + + private ItemStack target; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialChisel> STRUCTURE_DEFINITION = null; + private ItemStack mInputCache; + private ItemStack mOutputCache; + private GT_Recipe mCachedRecipe; + + public GregtechMetaTileEntity_IndustrialChisel(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialChisel(String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialChisel(this.mName); + } + + @Override + public String getMachineType() { + return "Chisel"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Factory Grade Auto Chisel") + .addInfo("Target block goes in Controller slot for common Input Buses") + .addInfo("You can also set a target block in each Chisel Input Bus and use them as an Input Bus") + .addInfo("If no target is provided for common buses, the result of the first chisel is used") + .addInfo("Speed: +200% | EU Usage: 75% | Parallel: Tier x 16") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front center") + .addCasingInfoMin("Sturdy Printer Casing", 6, false) + .addInputBus("Any casing", 1) + .addOutputBus("Any casing", 1) + .addEnergyHatch("Any casing", 1) + .addMaintenanceHatch("Any casing", 1) + .addMufflerHatch("Any casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialChisel> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialChisel>builder() + .addShape( + mName, + transpose( + // spotless:off + new String[][] { + { "CCC", "CCC", "CCC" }, + { "C~C", "C-C", "CCC" }, + { "CCC", "CCC", "CCC" }, + })) + // spotless:on + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialChisel.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(90) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings5Misc, 5)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 6 && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return 90; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + private boolean hasValidCache(ItemStack aStack, ItemStack aSpecialSlot, boolean aClearOnFailure) { + if (mInputCache != null && mOutputCache != null && mCachedRecipe != null) { + if (GT_Utility.areStacksEqual(aStack, mInputCache) + && GT_Utility.areStacksEqual(aSpecialSlot, mOutputCache)) { + return true; + } + } + // clear cache if it was invalid + if (aClearOnFailure) { + mInputCache = null; + mOutputCache = null; + mCachedRecipe = null; + } + return false; + } + + private void cacheItem(ItemStack aInputItem, ItemStack aOutputItem, GT_Recipe aRecipe) { + mInputCache = aInputItem.copy(); + mOutputCache = aOutputItem.copy(); + mCachedRecipe = aRecipe; + } + + // lets make sure the user isn't trying to make something from a block that doesn't have this as a valid target + private static boolean canBeMadeFrom(ItemStack from, ItemStack to) { + List<ItemStack> results = getItemsForChiseling(from); + for (ItemStack s : results) { + if (s.getItem() == to.getItem() && s.getItemDamage() == to.getItemDamage()) { + return true; + } + } + return false; + } + + // lets make sure the user isn't trying to make something from a block that doesn't have this as a valid target + private static boolean hasChiselResults(ItemStack from) { + List<ItemStack> results = getItemsForChiseling(from); + return results.size() > 0; + } + + private static List<ItemStack> getItemsForChiseling(ItemStack aStack) { + return Carving.chisel.getItemsForChiseling(aStack); + } + + private static ItemStack getChiselOutput(ItemStack aInput, ItemStack aTarget) { + ItemStack tOutput; + if (aTarget != null && canBeMadeFrom(aInput, aTarget)) { + tOutput = aTarget; + } else if (aTarget != null && !canBeMadeFrom(aInput, aTarget)) { + tOutput = null; + } else { + tOutput = getItemsForChiseling(aInput).get(0); + } + return tOutput; + } + + private GT_Recipe generateChiselRecipe(ItemStack aInput) { + boolean tIsCached = hasValidCache(aInput, this.target, true); + if (tIsCached || aInput != null && hasChiselResults(aInput)) { + ItemStack tOutput = tIsCached ? mOutputCache.copy() : getChiselOutput(aInput, this.target); + if (tOutput != null) { + if (mCachedRecipe != null && GT_Utility.areStacksEqual(aInput, mInputCache) + && GT_Utility.areStacksEqual(tOutput, mOutputCache)) { + return mCachedRecipe; + } + // We can chisel this + GT_Recipe aRecipe = new GT_Recipe( + false, + new ItemStack[] { ItemUtils.getSimpleStack(aInput, 1) }, + new ItemStack[] { ItemUtils.getSimpleStack(tOutput, 1) }, + null, + new int[] { 10000 }, + new FluidStack[] {}, + new FluidStack[] {}, + 20, + 16, + 0); + + // Cache it + cacheItem(aInput, tOutput, aRecipe); + return aRecipe; + } + } + return null; + } + + private GT_Recipe getRecipe() { + for (GT_MetaTileEntity_Hatch_InputBus bus : this.mInputBusses) { + if (bus instanceof GT_MetaTileEntity_ChiselBus) { // Chisel buses + if (bus.mInventory[bus.getSizeInventory() - 1] == null) continue; + this.target = bus.mInventory[bus.getSizeInventory() - 1]; + + for (int i = bus.getSizeInventory() - 2; i >= 0; i--) { + ItemStack itemsInSlot = bus.mInventory[i]; + if (itemsInSlot != null) { + GT_Recipe tRecipe = generateChiselRecipe(itemsInSlot); + if (tRecipe != null) { + return tRecipe; + } + } + } + } else { + target = this.getControllerSlot(); // Common buses + for (int i = bus.getSizeInventory() - 1; i >= 0; i--) { + ItemStack itemsInSlot = bus.mInventory[i]; + if (itemsInSlot != null) { + GT_Recipe tRecipe = generateChiselRecipe(itemsInSlot); + if (tRecipe != null) { + return tRecipe; + } + } + } + } + + } + return null; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic() { + + @Nonnull + @Override + protected Stream<GT_Recipe> findRecipeMatches(@Nullable RecipeMap<?> map) { + return GT_StreamUtil.ofNullable(getRecipe()); + } + }.setSpeedBonus(1F / 3F) + .setEuModifier(0.75F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + protected void sendStartMultiBlockSoundLoop() { + sendLoopStart(PROCESS_START_SOUND_INDEX); + } + + @Override + public int getMaxParallelRecipes() { + return (16 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + private static ResourceLocation sChiselSound = null; + + private static ResourceLocation getChiselSound() { + if (sChiselSound == null) { + sChiselSound = new ResourceLocation(Carving.chisel.getVariationSound(Blocks.stone, 0)); + } + return sChiselSound; + } + + @Override + public void doSound(byte aIndex, double aX, double aY, double aZ) { + switch (aIndex) { + case PROCESS_START_SOUND_INDEX -> GT_Utility + .doSoundAtClient(getChiselSound(), getTimeBetweenProcessSounds(), 1.0F, 1.0F, aX, aY, aZ); + case INTERRUPT_SOUND_INDEX -> GT_Utility + .doSoundAtClient(SoundResource.IC2_MACHINES_INTERRUPT_ONE, 100, 1.0F, aX, aY, aZ); + } + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialChisel; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCokeOven.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCokeOven.java new file mode 100644 index 0000000000..b71600e3fd --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCokeOven.java @@ -0,0 +1,209 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import net.minecraft.item.ItemStack; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.SoundResource; +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_IndustrialCokeOven + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialCokeOven> implements ISurvivalConstructable { + + private int mLevel = 0; + private int mCasing; + private int mCasing1; + private int mCasing2; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialCokeOven> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialCokeOven(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialCokeOven(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialCokeOven(this.mName); + } + + @Override + public String getMachineType() { + return "Coke Oven"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Processes Logs and Coal into Charcoal and Coal Coke.") + .addInfo("Controller Block for the Industrial Coke Oven") + .addInfo("Gain 4% energy discount per voltage tier") + .addInfo("Process 12x materials with Heat Resistant Casings") + .addInfo("Or 24x materials with Heat Proof Casings") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front middle at bottom") + .addCasingInfoMin("Structural Coke Oven Casings", 8, false) + .addCasingInfoMin("Heat Resistant/Proof Coke Oven Casings", 8, false) + .addInputBus("Any Structural Coke Oven Casing", 1) + .addOutputBus("Any Structural Coke Oven Casing", 1) + .addInputHatch("Any Structural Coke Oven Casing", 1) + .addOutputHatch("Any Structural Coke Oven Casing", 1) + .addEnergyHatch("Any Structural Coke Oven Casing", 1) + .addMaintenanceHatch("Any Structural Coke Oven Casing", 1) + .addMufflerHatch("Any Structural Coke Oven Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialCokeOven> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialCokeOven>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "HHH", "H-H", "HHH" }, { "C~C", "CCC", "CCC" }, })) + .addShape( + mName + "1", + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "aaa", "a-a", "aaa" }, { "C~C", "CCC", "CCC" }, })) + .addShape( + mName + "2", + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "bbb", "b-b", "bbb" }, { "C~C", "CCC", "CCC" }, })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialCokeOven.class) + .atLeast(InputBus, OutputBus, InputHatch, OutputHatch, Maintenance, Energy, Muffler) + .casingIndex(TAE.GTPP_INDEX(1)) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 1)))) + .addElement( + 'H', + ofChain( + onElementPass(x -> ++x.mCasing1, ofBlock(ModBlocks.blockCasingsMisc, 2)), + onElementPass(x -> ++x.mCasing2, ofBlock(ModBlocks.blockCasingsMisc, 3)))) + .addElement('a', ofBlock(ModBlocks.blockCasingsMisc, 2)) + .addElement('b', ofBlock(ModBlocks.blockCasingsMisc, 3)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + if (stackSize.stackSize == 1) buildPiece(mName + "1", stackSize, hintsOnly, 1, 2, 0); + else buildPiece(mName + "2", stackSize, hintsOnly, 1, 2, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + if (stackSize.stackSize == 1) + return survivialBuildPiece(mName + "1", stackSize, 1, 2, 0, elementBudget, env, false, true); + else return survivialBuildPiece(mName + "2", stackSize, 1, 2, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mCasing1 = 0; + mCasing2 = 0; + mLevel = 0; + if (checkPiece(mName, 1, 2, 0)) { + if (mCasing1 == 8) mLevel = 1; + if (mCasing2 == 8) mLevel = 2; + return mLevel > 0 && mCasing >= 8 && checkHatch(); + } + return false; + } + + @Override + protected SoundResource getProcessStartSound() { + return SoundResource.IC2_MACHINES_ELECTROFURNACE_LOOP; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(1); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.cokeOvenRecipes; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + protected void setupProcessingLogic(ProcessingLogic logic) { + super.setupProcessingLogic(logic); + logic.setEuModifier((100F - (GT_Utility.getTier(getMaxInputVoltage()) * 4)) / 100F); + } + + @Override + public int getMaxParallelRecipes() { + return this.mLevel * 12; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialCokeOven; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCuttingMachine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCuttingMachine.java new file mode 100644 index 0000000000..295f195d55 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialCuttingMachine.java @@ -0,0 +1,230 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import java.util.Arrays; +import java.util.Collection; + +import javax.annotation.Nonnull; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_IndustrialCuttingMachine extends + GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialCuttingMachine> implements ISurvivalConstructable { + + private boolean mCuttingMode = true; + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialCuttingMachine> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialCuttingMachine(final int aID, final String aName, + final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialCuttingMachine(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialCuttingMachine(this.mName); + } + + @Override + public String getMachineType() { + return "Cutting Machine / Slicing Machine"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Cutting Factory") + .addInfo("200% faster than using single block machines of the same voltage") + .addInfo("Only uses 75% of the EU/t normally required") + .addInfo("Processes four items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 5, true) + .addController("Front Center") + .addCasingInfoMin("Cutting Factory Frames", 14, false) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialCuttingMachine> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialCuttingMachine>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC", "CCC", "CCC" }, { "C~C", "C-C", "C-C", "C-C", "CCC" }, + { "CCC", "CCC", "CCC", "CCC", "CCC" }, })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialCuttingMachine.class) + .atLeast(InputBus, InputHatch, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 13)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 14 && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(29); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return mCuttingMode ? RecipeMaps.cutterRecipes : RecipeMaps.slicerRecipes; + } + + @Nonnull + @Override + public Collection<RecipeMap<?>> getAvailableRecipeMaps() { + return Arrays.asList(RecipeMaps.cutterRecipes, RecipeMaps.slicerRecipes); + } + + @Override + public int getRecipeCatalystPriority() { + return -1; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setSpeedBonus(1F / 3F) + .setEuModifier(0.75F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public int getMaxParallelRecipes() { + return (4 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialCuttingMachine; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public boolean isInputSeparationEnabled() { + return true; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings2Misc; + } + + public byte getCasingMeta() { + return 13; + } + + public byte getCasingTextureIndex() { + return (byte) TAE.GTPP_INDEX(29); + } + + @Override + public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mCuttingMode = !mCuttingMode; + String aMode = mCuttingMode ? "Cutting" : "Slicing"; + PlayerUtils.messagePlayer(aPlayer, "Mode: " + aMode); + mLastRecipe = null; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("mCuttingMode", mCuttingMode); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + if (aNBT.hasKey("mCuttingMode")) { + mCuttingMode = aNBT.getBoolean("mCuttingMode"); + } else { + mCuttingMode = true; + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialDehydrator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialDehydrator.java new file mode 100644 index 0000000000..9122090f89 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialDehydrator.java @@ -0,0 +1,250 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_StructureUtility.ofCoil; + +import java.util.Arrays; +import java.util.Collection; + +import javax.annotation.Nonnull; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.HeatingCoilLevel; +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_OverclockCalculator; +import gregtech.api.util.GT_Recipe; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_IndustrialDehydrator + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialDehydrator> implements ISurvivalConstructable { + + private static int CASING_TEXTURE_ID; + private static String mCasingName = "Vacuum Casing"; + private HeatingCoilLevel mHeatingCapacity; + private boolean mDehydratorMode = false; + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialDehydrator> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialDehydrator(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + CASING_TEXTURE_ID = TAE.getIndexFromPage(3, 10); + } + + public GregtechMetaTileEntity_IndustrialDehydrator(String aName) { + super(aName); + CASING_TEXTURE_ID = TAE.getIndexFromPage(3, 10); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialDehydrator(mName); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Factory Grade Vacuum Furnace") + .addInfo("Can toggle the operation temperature with a Screwdriver") + .addInfo("All Dehydrator recipes are Low Temp recipes") + .addInfo("Speed: +120% | EU Usage: 50% | Parallel: 4") + .addInfo("Each 900K over the min. Heat Capacity grants 5% speedup (multiplicatively)") + .addInfo("Each 1800K over the min. Heat Capacity allows for one upgraded overclock") + .addInfo("Upgraded overclocks reduce recipe time to 25% and increase EU/t to 400%") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 5, 3, true) + .addController("Bottom Center") + .addCasingInfoMin(mCasingName, 5, false) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialDehydrator> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialDehydrator>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "HHH", "H-H", "HHH" }, { "HHH", "H-H", "HHH" }, + { "HHH", "H-H", "HHH" }, { "C~C", "CCC", "CCC" }, })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialDehydrator.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) + .casingIndex(CASING_TEXTURE_ID) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings4Misc, 10)))) + .addElement( + 'H', + ofCoil( + GregtechMetaTileEntity_IndustrialDehydrator::setCoilLevel, + GregtechMetaTileEntity_IndustrialDehydrator::getCoilLevel)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 4, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 4, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + setCoilLevel(HeatingCoilLevel.None); + return checkPiece(mName, 1, 4, 0) && mCasing >= 5 && getCoilLevel() != HeatingCoilLevel.None && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return CASING_TEXTURE_ID; + } + + @Override + public RecipeMap<?> getRecipeMap() { + return mDehydratorMode ? GTPPRecipeMaps.chemicalDehydratorNonCellRecipes : GTPPRecipeMaps.vacuumFurnaceRecipes; + } + + @Nonnull + @Override + public Collection<RecipeMap<?>> getAvailableRecipeMaps() { + return Arrays.asList(GTPPRecipeMaps.chemicalDehydratorNonCellRecipes, GTPPRecipeMaps.vacuumFurnaceRecipes); + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialDehydrator; + } + + @Override + public String getMachineType() { + return "Vacuum Furnace / Dehydrator"; + } + + @Override + public int getMaxParallelRecipes() { + return 4; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic() { + + @NotNull + @Override + protected CheckRecipeResult validateRecipe(@NotNull GT_Recipe recipe) { + return recipe.mSpecialValue <= getCoilLevel().getHeat() ? CheckRecipeResultRegistry.SUCCESSFUL + : CheckRecipeResultRegistry.insufficientHeat(recipe.mSpecialValue); + } + + @NotNull + @Override + protected GT_OverclockCalculator createOverclockCalculator(@NotNull GT_Recipe recipe) { + return super.createOverclockCalculator(recipe).setHeatOC(true) + .setHeatDiscount(true) + .setRecipeHeat(recipe.mSpecialValue) + .setMachineHeat((int) getCoilLevel().getHeat()); + } + }.setSpeedBonus(1F / 2.2F) + .setEuModifier(0.5F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mDehydratorMode = !mDehydratorMode; + String aMode = mDehydratorMode ? "Dehydrator" : "Vacuum Furnace"; + PlayerUtils.messagePlayer(aPlayer, "Mode: " + aMode); + mLastRecipe = null; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("mDehydratorMode", mDehydratorMode); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mDehydratorMode = aNBT.getBoolean("mDehydratorMode"); + } + + public HeatingCoilLevel getCoilLevel() { + return mHeatingCapacity; + } + + public void setCoilLevel(HeatingCoilLevel aCoilLevel) { + mHeatingCapacity = aCoilLevel; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialElectrolyzer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialElectrolyzer.java new file mode 100644 index 0000000000..f12007b952 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialElectrolyzer.java @@ -0,0 +1,169 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import net.minecraft.item.ItemStack; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_IndustrialElectrolyzer extends + GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialElectrolyzer> implements ISurvivalConstructable { + + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialElectrolyzer> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialElectrolyzer(final int aID, final String aName, + final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialElectrolyzer(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialElectrolyzer(this.mName); + } + + @Override + public String getMachineType() { + return "Electrolyzer"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Electrolyzer") + .addInfo("180% faster than using single block machines of the same voltage") + .addInfo("Only uses 90% of the EU/t normally required") + .addInfo("Processes two items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfoMin("Electrolyzer Casings", 6, false) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialElectrolyzer> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialElectrolyzer>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "C~C", "C-C", "CCC" }, { "CCC", "CCC", "CCC" }, })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialElectrolyzer.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) + .casingIndex(TAE.GTPP_INDEX(5)) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 5)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 6 && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(5); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.electrolyzerNonCellRecipes; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setSpeedBonus(1F / 2.8F) + .setEuModifier(0.9F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialElectrolyzer; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public int getMaxParallelRecipes() { + return 2 * GT_Utility.getTier(this.getMaxInputVoltage()); + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialExtruder.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialExtruder.java new file mode 100644 index 0000000000..ea61048f33 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialExtruder.java @@ -0,0 +1,194 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.SoundResource; +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_IndustrialExtruder + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialExtruder> implements ISurvivalConstructable { + + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialExtruder> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialExtruder(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialExtruder(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialExtruder(this.mName); + } + + @Override + public String getMachineType() { + return "Extruder"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Material Extruder") + .addInfo("250% faster than using single block machines of the same voltage") + .addInfo("Processes four items per voltage tier") + .addInfo("Extrusion Shape for recipe goes in the Input Bus") + .addInfo("Each Input Bus can have a different shape!") + .addInfo("You can use several input buses per multiblock") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 5, true) + .addController("Front Center") + .addCasingInfoMin("Inconel Reinforced Casings", 14, false) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialExtruder> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialExtruder>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC", "CCC", "CCC" }, { "C~C", "C-C", "C-C", "C-C", "CCC" }, + { "CCC", "CCC", "CCC", "CCC", "CCC" }, })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialExtruder.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 14 && checkHatch(); + } + + @Override + protected SoundResource getProcessStartSound() { + return SoundResource.IC2_MACHINES_COMPRESSOR_OP; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(33); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return RecipeMaps.extruderRecipes; + } + + @Override + public int getRecipeCatalystPriority() { + return -1; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setSpeedBonus(1F / 3.5F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public int getMaxParallelRecipes() { + return (4 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialExtruder; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings3Misc; + } + + public byte getCasingMeta() { + return 1; + } + + public byte getCasingTextureIndex() { + return (byte) TAE.GTPP_INDEX(33); + } + + @Override + public boolean isInputSeparationEnabled() { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialFluidHeater.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialFluidHeater.java new file mode 100644 index 0000000000..a34532ee83 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialFluidHeater.java @@ -0,0 +1,204 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_IndustrialFluidHeater extends + GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialFluidHeater> implements ISurvivalConstructable { + + private int mCasing1; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialFluidHeater> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialFluidHeater(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialFluidHeater(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialFluidHeater(this.mName); + } + + @Override + public String getMachineType() { + return "Fluid Heater"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Fluid Heater") + .addInfo("120% faster than using single block machines of the same voltage") + .addInfo("Only uses 90% of the EU/t normally required") + .addInfo("Processes eight items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(5, 6, 5, true) + .addController("Front Center") + .addCasingInfoMin("Top/Bottom layer: Multi-use Casings", 34, false) + .addCasingInfoMin("Middle layers: Thermal Containment Casing", 47, false) + .addInputBus("Bottom Layer (optional)", 1) + .addInputHatch("Bottom Layer", 1) + .addOutputBus("Top Layer (optional)", 1) + .addOutputHatch("Top Layer", 1) + .addEnergyHatch("Any Multi-use Casing", 1) + .addMaintenanceHatch("Any Multi-use Casing", 1) + .addMufflerHatch("Any Multi-use Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialFluidHeater> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialFluidHeater>builder() + .addShape( + mName, + transpose( + new String[][] { { " TTT ", "TTTTT", "TTTTT", "TTTTT", " TTT " }, + { " XXX ", "X---X", "X---X", "X---X", " XXX " }, + { " XXX ", "X---X", "X---X", "X---X", " XXX " }, + { " XXX ", "X---X", "X---X", "X---X", " XXX " }, + { " X~X ", "X---X", "X---X", "X---X", " XXX " }, + { " BBB ", "BBBBB", "BBBBB", "BBBBB", " BBB " }, })) + .addElement( + 'B', + buildHatchAdder(GregtechMetaTileEntity_IndustrialFluidHeater.class) + .atLeast(InputBus, InputHatch, Maintenance, Energy, Muffler) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing1, ofBlock(getCasingBlock2(), getCasingMeta2())))) + .addElement('X', ofBlock(getCasingBlock1(), getCasingMeta1())) + .addElement( + 'T', + buildHatchAdder(GregtechMetaTileEntity_IndustrialFluidHeater.class) + .atLeast(OutputBus, OutputHatch, Maintenance, Energy, Muffler) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing1, ofBlock(getCasingBlock2(), getCasingMeta2())))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 2, 4, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 2, 4, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing1 = 0; + boolean didBuild = checkPiece(mName, 2, 4, 0); + log("Built? " + didBuild + ", " + mCasing1); + return didBuild && mCasing1 >= 34 && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return TAE.getIndexFromPage(0, 1); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return RecipeMaps.fluidHeaterRecipes; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setSpeedBonus(1F / 2.2F) + .setEuModifier(0.9F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public int getMaxParallelRecipes() { + return (8 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialThermalCentrifuge; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock1() { + return ModBlocks.blockCasings2Misc; + } + + public byte getCasingMeta1() { + return 11; + } + + public Block getCasingBlock2() { + return ModBlocks.blockCasings3Misc; + } + + public byte getCasingMeta2() { + return 2; + } + + public byte getCasingTextureIndex() { + return (byte) TAE.getIndexFromPage(2, 2); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialForgeHammer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialForgeHammer.java new file mode 100644 index 0000000000..8e2f040d75 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialForgeHammer.java @@ -0,0 +1,244 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlocksTiered; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.enums.Mods.EnderIO; +import static gregtech.api.enums.Mods.Railcraft; +import static gregtech.api.enums.Mods.ThaumicBases; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; + +import org.apache.commons.lang3.tuple.Pair; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.ITierConverter; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import cpw.mods.fml.common.registry.GameRegistry; +import gregtech.api.enums.SoundResource; +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +@SuppressWarnings("SpellCheckingInspection") +public class GregtechMetaTileEntity_IndustrialForgeHammer extends + GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialForgeHammer> implements ISurvivalConstructable { + + private int mCasing; + private int mAnvilTier = 0; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialForgeHammer> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialForgeHammer(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialForgeHammer(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialForgeHammer(this.mName); + } + + @Override + public String getMachineType() { + return "Forge Hammer"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Forge Hammer") + .addInfo("Speed: +100% | EU Usage: 100% | Parallel: Tier x Anvil Tier x 8") + .addInfo("T1 - Vanilla Anvil"); + if (Railcraft.isModLoaded()) { + tt.addInfo("T2 - Steel Anvil"); + } + if (EnderIO.isModLoaded()) { + tt.addInfo("T3 - Dark Steel Anvil"); + } + if (ThaumicBases.isModLoaded()) { + tt.addInfo("T3 - Thaumium Anvil"); + tt.addInfo("T4 - Void Metal Anvil"); + } + + tt.addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfoMin("Forge Casing", 6, false) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .addOtherStructurePart("Anvil", "In the center of 3x3x3 structure", 2) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialForgeHammer> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + Map<Block, Integer> anvilTiers = new HashMap<>(); + + anvilTiers.put(Blocks.anvil, 1); + + if (Railcraft.isModLoaded()) { + anvilTiers.put(GameRegistry.findBlock(Railcraft.ID, "anvil"), 2); + } + + if (EnderIO.isModLoaded()) { + anvilTiers.put(GameRegistry.findBlock(EnderIO.ID, "blockDarkSteelAnvil"), 3); + } + + if (ThaumicBases.isModLoaded()) { + anvilTiers.put(GameRegistry.findBlock(ThaumicBases.ID, "thaumicAnvil"), 3); + anvilTiers.put(GameRegistry.findBlock(ThaumicBases.ID, "voidAnvil"), 4); + } + + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialForgeHammer>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "C~C", "CAC", "CCC" }, { "CCC", "CCC", "CCC" }, })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialForgeHammer.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) + .casingIndex(TAE.getIndexFromPage(1, 11)) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings5Misc, 6)))) + .addElement( + 'A', + ofBlocksTiered( + anvilTierConverter(anvilTiers), + getAllAnvilTiers(anvilTiers), + 0, + GregtechMetaTileEntity_IndustrialForgeHammer::setAnvilTier, + GregtechMetaTileEntity_IndustrialForgeHammer::getAnvilTier)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + private static List<Pair<Block, Integer>> getAllAnvilTiers(Map<Block, Integer> anvilTiers) { + return anvilTiers.entrySet() + .stream() + .map(e -> Pair.of(e.getKey(), e.getValue())) + .collect(Collectors.toList()); + } + + private static ITierConverter<Integer> anvilTierConverter(Map<Block, Integer> anvilTiers) { + return (block, meta) -> block == null ? 0 : anvilTiers.getOrDefault(block, 0); + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 6 && checkHatch(); + } + + @Override + protected SoundResource getProcessStartSound() { + return SoundResource.RANDOM_ANVIL_USE; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return TAE.getIndexFromPage(1, 11); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return RecipeMaps.hammerRecipes; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setSpeedBonus(1 / 2F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public int getMaxParallelRecipes() { + return (8 * getAnvilTier() * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialForgeHammer; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + private void setAnvilTier(int tier) { + mAnvilTier = tier; + } + + private int getAnvilTier() { + return mAnvilTier; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMacerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMacerator.java new file mode 100644 index 0000000000..5591b9fbe8 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMacerator.java @@ -0,0 +1,458 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import java.util.List; +import java.util.Random; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; +import net.minecraftforge.common.util.Constants.NBT; +import net.minecraftforge.common.util.ForgeDirection; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.SoundResource; +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; + +public class GregtechMetaTileEntity_IndustrialMacerator + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialMacerator> implements ISurvivalConstructable { + + private int controllerTier = 1; + private int mCasing; + private int mPerLayer; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialMacerator> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialMacerator(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialMacerator(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialMacerator(this.mName); + } + + @Override + public String getMachineType() { + return "Macerator/Pulverizer"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller block for the Industrial Maceration Stack") + .addInfo("60% faster than using single block machines of the same voltage") + .addInfo("Maximum of n*tier parallels, LV = Tier 1, MV = Tier 2, etc.") + .addInfo("n=2 initially. n=8 after inserting Maceration Upgrade Chip.") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 6, 3, true) + .addController("Bottom center") + .addCasingInfoMin("Maceration Stack Casings (After upgrade)", 26, false) + .addCasingInfoMin("Stable Titanium Casings (Before upgrade)", 26, false) + .addInputBus("Bottom casing", 1) + .addEnergyHatch("Any casing", 1) + .addMaintenanceHatch("Any casing", 1) + .addOutputBus("One per layer except bottom layer", 2) + .addMufflerHatch("Any casing except bottom layer", 2) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialMacerator> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialMacerator>builder() + .addShape(mName + "top1", transpose(new String[][] { { "ccc", "ccc", "ccc" }, })) + .addShape(mName + "mid1", transpose(new String[][] { { "ccc", "c-c", "ccc" }, })) + .addShape(mName + "bottom1", transpose(new String[][] { { "b~b", "bbb", "bbb" }, })) + .addShape(mName + "top2", transpose(new String[][] { { "CCC", "CCC", "CCC" }, })) + .addShape(mName + "mid2", transpose(new String[][] { { "CCC", "C-C", "CCC" }, })) + .addShape(mName + "bottom2", transpose(new String[][] { { "B~B", "BBB", "BBB" }, })) + .addElement( + 'C', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_IndustrialMacerator.class).anyOf(OutputBus) + .shouldReject(t -> t.mPerLayer + 1 == t.mOutputBusses.size()) + .disallowOnly(ForgeDirection.UP, ForgeDirection.DOWN) + .casingIndex(TAE.GTPP_INDEX(7)) + .dot(2) + .build(), + buildHatchAdder(GregtechMetaTileEntity_IndustrialMacerator.class) + .atLeast(Energy, Maintenance, Muffler) + .disallowOnly(ForgeDirection.UP, ForgeDirection.DOWN) + .casingIndex(TAE.GTPP_INDEX(7)) + .dot(2) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 7)))) + .addElement( + 'B', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_IndustrialMacerator.class) + .atLeast(Energy, Maintenance, InputBus) + .disallowOnly(ForgeDirection.UP) + .casingIndex(TAE.GTPP_INDEX(7)) + .dot(2) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 7)))) + .addElement( + 'c', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_IndustrialMacerator.class).anyOf(OutputBus) + .shouldReject(t -> t.mPerLayer + 1 == t.mOutputBusses.size()) + .disallowOnly(ForgeDirection.UP, ForgeDirection.DOWN) + .casingIndex(GT_Utility.getCasingTextureIndex(GregTech_API.sBlockCasings4, 2)) + .dot(2) + .build(), + buildHatchAdder(GregtechMetaTileEntity_IndustrialMacerator.class) + .atLeast(Energy, Maintenance, Muffler) + .disallowOnly(ForgeDirection.UP, ForgeDirection.DOWN) + .casingIndex(GT_Utility.getCasingTextureIndex(GregTech_API.sBlockCasings4, 2)) + .dot(2) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(GregTech_API.sBlockCasings4, 2)))) + .addElement( + 'b', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_IndustrialMacerator.class) + .atLeast(Energy, Maintenance, InputBus) + .disallowOnly(ForgeDirection.UP) + .casingIndex(GT_Utility.getCasingTextureIndex(GregTech_API.sBlockCasings4, 2)) + .dot(2) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(GregTech_API.sBlockCasings4, 2)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName + "bottom" + controllerTier, stackSize, hintsOnly, 1, 0, 0); + buildPiece(mName + "mid" + controllerTier, stackSize, hintsOnly, 1, 1, 0); + buildPiece(mName + "mid" + controllerTier, stackSize, hintsOnly, 1, 2, 0); + buildPiece(mName + "mid" + controllerTier, stackSize, hintsOnly, 1, 3, 0); + buildPiece(mName + "mid" + controllerTier, stackSize, hintsOnly, 1, 4, 0); + buildPiece(mName + "top" + controllerTier, stackSize, hintsOnly, 1, 5, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + int built; + built = survivialBuildPiece( + mName + "bottom" + controllerTier, + stackSize, + 1, + 0, + 0, + elementBudget, + env, + false, + true); + mPerLayer = 0; + if (built >= 0) return built; + built = survivialBuildPiece( + mName + "mid" + controllerTier, + stackSize, + 1, + 1, + 0, + elementBudget, + env, + false, + true); + mPerLayer = 1; + if (built >= 0) return built; + built = survivialBuildPiece( + mName + "mid" + controllerTier, + stackSize, + 1, + 2, + 0, + elementBudget, + env, + false, + true); + if (built >= 0) return built; + mPerLayer = 2; + built = survivialBuildPiece( + mName + "mid" + controllerTier, + stackSize, + 1, + 3, + 0, + elementBudget, + env, + false, + true); + if (built >= 0) return built; + mPerLayer = 3; + built = survivialBuildPiece( + mName + "mid" + controllerTier, + stackSize, + 1, + 4, + 0, + elementBudget, + env, + false, + true); + if (built >= 0) return built; + mPerLayer = 4; + return survivialBuildPiece(mName + "top" + controllerTier, stackSize, 1, 5, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mPerLayer = 0; + if (checkPiece(mName + "bottom" + controllerTier, 1, 0, 0)) { + while (mPerLayer < 4) { + if (!checkPiece(mName + "mid" + controllerTier, 1, mPerLayer + 1, 0) + || mPerLayer + 1 != mOutputBusses.size()) return false; + mPerLayer++; + } + return checkPiece(mName + "top" + controllerTier, 1, 5, 0) && mOutputBusses.size() == 5 + && mCasing >= 26 + && checkHatch(); + } + return false; + } + + @Override + protected SoundResource getProcessStartSound() { + return SoundResource.IC2_MACHINES_MACERATOR_OP; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_MatterFab_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_MatterFab; + } + + @Override + protected int getCasingTextureId() { + return switch (controllerTier) { + case 2 -> TAE.GTPP_INDEX(7); + default -> GT_Utility.getCasingTextureIndex(GregTech_API.sBlockCasings4, 2); + }; + } + + @Override + public RecipeMap<?> getRecipeMap() { + return RecipeMaps.maceratorRecipes; + } + + @Override + public int getRecipeCatalystPriority() { + return -10; + } + + @Override + public void onPreTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive()) + && (aBaseMetaTileEntity.getFrontFacing() != ForgeDirection.UP) + && (aBaseMetaTileEntity.getCoverIDAtSide(ForgeDirection.UP) == 0) + && (!aBaseMetaTileEntity.getOpacityAtSide(ForgeDirection.UP))) { + final Random tRandom = aBaseMetaTileEntity.getWorld().rand; + aBaseMetaTileEntity.getWorld() + .spawnParticle( + "smoke", + (aBaseMetaTileEntity.getXCoord() + 0.8F) - (tRandom.nextFloat() * 0.6F), + aBaseMetaTileEntity.getYCoord() + 0.3f + (tRandom.nextFloat() * 0.2F), + (aBaseMetaTileEntity.getZCoord() + 1.2F) - (tRandom.nextFloat() * 1.6F), + 0.0D, + 0.0D, + 0.0D); + } + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (aBaseMetaTileEntity.isServerSide() && aTick % 20 == 0 && controllerTier == 1) { + ItemStack aGuiStack = this.getControllerSlot(); + if (GregtechItemList.Maceration_Upgrade_Chip.isStackEqual(aGuiStack, false, true)) { + controllerTier = 2; + mInventory[1] = ItemUtils.depleteStack(aGuiStack); + markDirty(); + // schedule a structure check + mUpdated = true; + } + } + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, ForgeDirection side, + float aX, float aY, float aZ) { + if (controllerTier == 1 && !aPlayer.isSneaking()) { + ItemStack heldItem = aPlayer.getHeldItem(); + if (GregtechItemList.Maceration_Upgrade_Chip.isStackEqual(heldItem, false, true)) { + controllerTier = 2; + aPlayer.setCurrentItemOrArmor(0, ItemUtils.depleteStack(heldItem)); + if (getBaseMetaTileEntity().isServerSide()) { + markDirty(); + aPlayer.inventory.markDirty(); + // schedule a structure check + mUpdated = true; + } + return true; + } + } + return super.onRightclick(aBaseMetaTileEntity, aPlayer, side, aX, aY, aZ); + } + + @Override + public void onValueUpdate(byte aValue) { + controllerTier = aValue; + } + + @Override + public byte getUpdateData() { + return (byte) controllerTier; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setByte("mTier", (byte) controllerTier); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + if (!aNBT.hasKey("mTier", NBT.TAG_BYTE)) + // we assume old macerators are all T2 variants, as they were made before price reduction and shouldn't need + // to worry about upgrading + controllerTier = 2; + else controllerTier = aNBT.getByte("mTier"); + } + + @Override + public void initDefaultModes(NBTTagCompound aNBT) { + super.initDefaultModes(aNBT); + if (aNBT == null || !aNBT.hasKey("mTier")) { + controllerTier = 1; + } else { + controllerTier = aNBT.getByte("mTier"); + } + } + + @Override + public void setItemNBT(NBTTagCompound aNBT) { + super.setItemNBT(aNBT); + aNBT.setByte("mTier", (byte) controllerTier); + } + + @Override + public void addAdditionalTooltipInformation(ItemStack stack, List<String> tooltip) { + super.addAdditionalTooltipInformation(stack, tooltip); + NBTTagCompound aNBT = stack.getTagCompound(); + int tier; + if (aNBT == null || !aNBT.hasKey("mTier")) { + tier = 1; + } else { + tier = aNBT.getInteger("mTier"); + } + tooltip.add(StatCollector.translateToLocalFormatted("tooltip.large_macerator.tier", tier)); + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setSpeedBonus(1F / 1.6F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public int getMaxParallelRecipes() { + final long tVoltage = getMaxInputVoltage(); + final byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); + return Math.max(1, (controllerTier == 1 ? 2 : 8) * tTier); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialMacerator; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public boolean isOverclockerUpgradable() { + return true; + } + + @Override + public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompound tag, World world, int x, int y, + int z) { + super.getWailaNBTData(player, tile, tag, world, x, y, z); + tag.setInteger("tier", controllerTier); + } + + @Override + public void getWailaBody(ItemStack itemStack, List<String> currentTip, IWailaDataAccessor accessor, + IWailaConfigHandler config) { + super.getWailaBody(itemStack, currentTip, accessor, config); + final NBTTagCompound tag = accessor.getNBTData(); + if (tag.hasKey("tier")) { + currentTip.add( + "Tier: " + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(tag.getInteger("tier")) + + EnumChatFormatting.RESET); + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMixer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMixer.java new file mode 100644 index 0000000000..3f4c4ccfa4 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMixer.java @@ -0,0 +1,213 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.StatCollector; +import net.minecraftforge.common.util.ForgeDirection; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.SoundResource; +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_IndustrialMixer + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialMixer> implements ISurvivalConstructable { + + public static int CASING_TEXTURE_ID; + public static String mCasingName = "Multi-Use Casing"; + public static String mCasingName2 = "Titanium Turbine Casing"; + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialMixer> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialMixer(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 2); + inputSeparation = true; + } + + public GregtechMetaTileEntity_IndustrialMixer(final String aName) { + super(aName); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 2); + inputSeparation = true; + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + if (!aNBT.hasKey(INPUT_SEPARATION_NBT_KEY)) { + if (aNBT.hasKey("isBussesSeparate")) { + inputSeparation = aNBT.getBoolean("isBussesSeparate"); + } + // Fallback for existing mixers + else { + inputSeparation = true; + } + } + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialMixer(this.mName); + } + + @Override + public String getMachineType() { + return "Mixer"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Mixer") + .addInfo("250% faster than using single block machines of the same voltage") + .addInfo("Processes eight recipes per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 4, 3, false) + .addController("Second Layer Center") + .addCasingInfoMin(mCasingName, 6, false) + .addCasingInfoMin(mCasingName2, 2, false) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialMixer> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialMixer>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "CCC", "CMC", "CCC" }, { "C~C", "CMC", "CCC" }, + { "CCC", "CCC", "CCC" }, })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialMixer.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) + .casingIndex(CASING_TEXTURE_ID) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings3Misc, 2)))) + .addElement('M', ofBlock(GregTech_API.sBlockCasings4, 11)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 2, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 2, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 2, 0) && mCasing >= 6 && checkHatch(); + } + + @Override + protected SoundResource getProcessStartSound() { + return SoundResource.IC2_MACHINES_COMPRESSOR_OP; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return CASING_TEXTURE_ID; + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.mixerNonCellRecipes; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setSpeedBonus(1F / 3.5F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public int getMaxParallelRecipes() { + return (8 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialMixer; + } + + @Override + public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + inputSeparation = !inputSeparation; + GT_Utility.sendChatToPlayer( + aPlayer, + StatCollector.translateToLocal("GT5U.machines.separatebus") + " " + inputSeparation); + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public boolean supportsInputSeparation() { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMolecularTransformer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMolecularTransformer.java new file mode 100644 index 0000000000..02b0bcf978 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMolecularTransformer.java @@ -0,0 +1,241 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.GregTech_API; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_IndustrialMolecularTransformer + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialMolecularTransformer> + implements ISurvivalConstructable { + + private static final int CASING_TEXTURE_ID = 48; + private int mCasing = 0; + + public GregtechMetaTileEntity_IndustrialMolecularTransformer(final int aID, final String aName, + final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialMolecularTransformer(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialMolecularTransformer(this.mName); + } + + @Override + public String getMachineType() { + return "Molecular Transformer"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Changes the structure of items to produce new ones") + .addInfo("Maximum 1x of each bus/hatch.") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(7, 7, 7, false) + .addController("Top Center") + .addCasingInfoMin("Robust Tungstensteel Machine Casing", 40, false) + .addCasingInfoMin("Tungstensteel Coils", 16, false) + .addCasingInfoMin("Molecular Containment Casing", 52, false) + .addCasingInfoMin("High Voltage Current Capacitor", 32, false) + .addCasingInfoMin("Particle Containment Casing", 4, false) + .addCasingInfoMin("Resonance Chamber I", 5, false) + .addCasingInfoMin("Modulator I", 4, false) + .addInputBus("Any Robust Tungstensteel Machine Casing", 1) + .addOutputBus("Any Robust Tungstensteel Machine Casing", 1) + .addEnergyHatch("Any Robust Tungstensteel Machine Casing", 1) + .addMaintenanceHatch("Any Robust Tungstensteel Machine Casing", 1) + .addMufflerHatch("Any Robust Tungstensteel Machine Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + private static final String STRUCTURE_PIECE_MAIN = "main"; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialMolecularTransformer> STRUCTURE_DEFINITION = null; + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialMolecularTransformer> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialMolecularTransformer>builder() + .addShape( + STRUCTURE_PIECE_MAIN, + (new String[][] { { " ", " ", " xxx ", " x~x ", " xxx ", " ", " " }, + { " ", " xxx ", " xyyyx ", " xyzyx ", " xyyyx ", " xxx ", " " }, + { " ", " xxx ", " xyyyx ", " xyzyx ", " xyyyx ", " xxx ", " " }, + { " ", " xxx ", " xyyyx ", " xyzyx ", " xyyyx ", " xxx ", " " }, + { " t ", " ttxtt ", " tyyyt ", "txyzyxt", " tyyyt ", " ttxtt ", " t " }, + { " c ", " ccecc ", " cxfxc ", "cefefec", " cxfxc ", " ccecc ", " c " }, + { " h ", " hhhhh ", " hhhhh ", "hhhhhhh", " hhhhh ", " hhhhh ", " h " }, })) + .addElement('x', ofBlock(getCasingBlock(), getCasingMeta())) + .addElement('y', ofBlock(getCasingBlock(), getCasingMeta2())) + .addElement('z', ofBlock(getCasingBlock(), getCasingMeta3())) + .addElement('e', ofBlock(getCasingBlock2(), 0)) + .addElement('f', ofBlock(getCasingBlock2(), 4)) + .addElement('c', ofBlock(getCoilBlock(), 3)) + .addElement('t', ofBlock(getCasingBlock3(), getTungstenCasingMeta())) + .addElement( + 'h', + buildHatchAdder(GregtechMetaTileEntity_IndustrialMolecularTransformer.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain( + onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock3(), getTungstenCasingMeta())))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(STRUCTURE_PIECE_MAIN, stackSize, hintsOnly, 3, 3, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(STRUCTURE_PIECE_MAIN, stackSize, 3, 3, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + boolean aDidBuild = checkPiece(STRUCTURE_PIECE_MAIN, 3, 3, 0); + if (this.mInputBusses.size() != 1 || this.mOutputBusses.size() != 1 || this.mEnergyHatches.size() != 1) { + return false; + } + // there are 16 slot that only allow casing, so we subtract this from the grand total required + return aDidBuild && mCasing >= 40 - 16 && checkHatch(); + } + + protected static int getCasingTextureIndex() { + return CASING_TEXTURE_ID; + } + + protected static Block getCasingBlock() { + return ModBlocks.blockSpecialMultiCasings; + } + + protected static Block getCasingBlock2() { + return ModBlocks.blockSpecialMultiCasings2; + } + + protected static Block getCasingBlock3() { + return GregTech_API.sBlockCasings4; + } + + protected static Block getCoilBlock() { + return GregTech_API.sBlockCasings5; + } + + protected static int getCasingMeta() { + return 11; + } + + protected static int getCasingMeta2() { + return 12; + } + + protected static int getCasingMeta3() { + return 13; + } + + protected static int getTungstenCasingMeta() { + return 0; + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + return (d, r, f) -> d == ForgeDirection.UP; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return 44; + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.molecularTransformerRecipes; + } + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + return true; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic(); + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiMolecularTransformer; + } + + @Override + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMultiMachine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMultiMachine.java new file mode 100644 index 0000000000..52c7736ae3 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialMultiMachine.java @@ -0,0 +1,514 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_Utility.filterValidMTEs; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.stream.Stream; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_MultiInput; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_CraftingInput_ME; +import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_Input_ME; +import gregtech.common.tileentities.machines.IDualInputHatch; +import gregtech.common.tileentities.machines.IDualInputInventory; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Solidifier; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; + +public class GregtechMetaTileEntity_IndustrialMultiMachine extends + GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialMultiMachine> implements ISurvivalConstructable { + + protected int mInternalMode = 0; + private static final int MODE_COMPRESSOR = 0; + private static final int MODE_LATHE = 1; + private static final int MODE_MAGNETIC = 2; + private static final int MODE_FERMENTER = 3; + private static final int MODE_FLUIDEXTRACT = 4; + private static final int MODE_EXTRACTOR = 5; + private static final int MODE_LASER = 6; + private static final int MODE_AUTOCLAVE = 7; + private static final int MODE_FLUIDSOLIDIFY = 8; + private static final int[][] MODE_MAP = new int[][] { { 0, 1, 2 }, { 3, 4, 5 }, { 6, 7, 8 } }; + public static final String[] aToolTipNames = new String[9]; + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialMultiMachine> STRUCTURE_DEFINITION = null; + + static { + for (int id = 0; id < 9; id++) { + RecipeMap<?> recipeMap = getRecipeMap(id); + if (recipeMap != null) { + String aNEI = GT_LanguageManager.getTranslation(getRecipeMap(id).unlocalizedName); + aToolTipNames[id] = aNEI != null ? aNEI : "BAD NEI NAME (Report to Github)"; + } + } + } + + public GregtechMetaTileEntity_IndustrialMultiMachine(final int aID, final String aName, + final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialMultiMachine(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialMultiMachine(this.mName); + } + + @Override + public String getMachineType() { + return "Nine in One"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + String[] aBuiltStrings = new String[3]; + aBuiltStrings[0] = aToolTipNames[0] + ", " + aToolTipNames[1] + ", " + aToolTipNames[2]; + aBuiltStrings[1] = aToolTipNames[3] + ", " + aToolTipNames[4] + ", " + aToolTipNames[5]; + aBuiltStrings[2] = aToolTipNames[6] + ", " + aToolTipNames[7] + ", " + aToolTipNames[8]; + + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Multi-Machine") + .addInfo("250% faster than using single block machines of the same voltage") + .addInfo("Only uses 80% of the EU/t normally required") + .addInfo("Processes two items per voltage tier") + .addInfo("Machine Type: Metal - " + EnumChatFormatting.YELLOW + aBuiltStrings[0] + EnumChatFormatting.RESET) + .addInfo("Machine Type: Fluid - " + EnumChatFormatting.YELLOW + aBuiltStrings[1] + EnumChatFormatting.RESET) + .addInfo("Machine Type: Misc - " + EnumChatFormatting.YELLOW + aBuiltStrings[2] + EnumChatFormatting.RESET) + .addInfo("Read Multi-Machine Manual for extra information") + .addInfo( + EnumChatFormatting.AQUA + "You can use Solidifier Hatch to solidify multiple liquids." + + EnumChatFormatting.RESET) + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfoMin("Multi-Use Casings", 6, false) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialMultiMachine> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialMultiMachine>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "C~C", "C-C", "CCC" }, { "CCC", "CCC", "CCC" }, })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialMultiMachine.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) + .casingIndex(getTextureIndex()) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings3Misc, 2)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 6 && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return getTextureIndex(); + } + + @Override + public int getMaxParallelRecipes() { + return (2 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + if (mInternalMode == 0) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialMultiMachine_ModeMetal; + } else if (mInternalMode == 1) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialMultiMachine_ModeFluid; + } else { // config 2 + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialMultiMachine_ModeMisc; + } + } + + public int getTextureIndex() { + return TAE.getIndexFromPage(2, 2); + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + private ItemStack getCircuit(ItemStack[] t) { + for (ItemStack j : t) { + if (j.getItem() == CI.getNumberedCircuit(0) + .getItem()) { + if (j.getItemDamage() >= 20 && j.getItemDamage() <= 22) { + return j; + } + } + } + return null; + } + + private int getCircuitID(ItemStack circuit) { + int H = circuit.getItemDamage(); + int T = (H == 20 ? 0 : (H == 21 ? 1 : (H == 22 ? 2 : -1))); + return MODE_MAP[this.mInternalMode][T]; + } + + @Override + public RecipeMap<?> getRecipeMap() { + return null; + } + + @Nonnull + @Override + public Collection<RecipeMap<?>> getAvailableRecipeMaps() { + return Arrays.asList( + RecipeMaps.compressorRecipes, + RecipeMaps.latheRecipes, + RecipeMaps.polarizerRecipes, + RecipeMaps.fermentingRecipes, + RecipeMaps.fluidExtractionRecipes, + RecipeMaps.extractorRecipes, + RecipeMaps.laserEngraverRecipes, + RecipeMaps.autoclaveRecipes, + RecipeMaps.fluidSolidifierRecipes); + } + + @Override + public int getRecipeCatalystPriority() { + return -10; + } + + private static RecipeMap<?> getRecipeMap(int aMode) { + if (aMode == MODE_COMPRESSOR) { + return RecipeMaps.compressorRecipes; + } else if (aMode == MODE_LATHE) { + return RecipeMaps.latheRecipes; + } else if (aMode == MODE_MAGNETIC) { + return RecipeMaps.polarizerRecipes; + } else if (aMode == MODE_FERMENTER) { + return RecipeMaps.fermentingRecipes; + } else if (aMode == MODE_FLUIDEXTRACT) { + return RecipeMaps.fluidExtractionRecipes; + } else if (aMode == MODE_EXTRACTOR) { + return RecipeMaps.extractorRecipes; + } else if (aMode == MODE_LASER) { + return RecipeMaps.laserEngraverRecipes; + } else if (aMode == MODE_AUTOCLAVE) { + return RecipeMaps.autoclaveRecipes; + } else if (aMode == MODE_FLUIDSOLIDIFY) { + return RecipeMaps.fluidSolidifierRecipes; + } else { + return null; + } + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic() { + + private ItemStack lastCircuit = null; + + @Nonnull + @Override + protected Stream<GT_Recipe> findRecipeMatches(@Nullable RecipeMap<?> map) { + ItemStack circuit = getCircuit(inputItems); + if (circuit == null) { + return Stream.empty(); + } + if (!GT_Utility.areStacksEqual(circuit, lastCircuit)) { + lastRecipe = null; + lastCircuit = circuit; + } + RecipeMap<?> foundMap = getRecipeMap(getCircuitID(circuit)); + if (foundMap == null) { + return Stream.empty(); + } + return super.findRecipeMatches(foundMap); + } + }.setSpeedBonus(1F / 3.5F) + .setEuModifier(0.8F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (mInternalMode < 2) { + mInternalMode++; + } else { + mInternalMode = 0; + } + String mModeString = (mInternalMode == 0 ? "Metal" + : mInternalMode == 1 ? "Fluid" : mInternalMode == 2 ? "Misc." : "null"); + PlayerUtils.messagePlayer(aPlayer, "Multi-Machine is now in " + mModeString + " mode."); + mLastRecipe = null; + } + + @Override + public String[] getInfoData() { + String[] data = super.getInfoData(); + ArrayList<String> mInfo = new ArrayList<>(Arrays.asList(data)); + String mode; + if (mInternalMode == 0) { + mode = StatCollector.translateToLocal("GTPP.multiblock.multimachine.metal"); + } else if (mInternalMode == 1) { + mode = StatCollector.translateToLocal("GTPP.multiblock.multimachine.fluid"); + } else { + mode = StatCollector.translateToLocal("GTPP.multiblock.multimachine.misc"); + } + mInfo.add(mode); + return mInfo.toArray(new String[0]); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mInternalMode", mInternalMode); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + this.mInternalMode = aNBT.getInteger("mInternalMode"); + super.loadNBTData(aNBT); + } + + @Override + public boolean isInputSeparationEnabled() { + return true; + } + + @Override + public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompound tag, World world, int x, int y, + int z) { + super.getWailaNBTData(player, tile, tag, world, x, y, z); + tag.setInteger("mode", mInternalMode); + } + + @Override + protected CheckRecipeResult doCheckRecipe() { + + if (mInternalMode != 2 || !isInputSeparationEnabled()) { + return super.doCheckRecipe(); + } else { + CheckRecipeResult result = CheckRecipeResultRegistry.NO_RECIPE; + + // check crafting input hatches first + if (supportsCraftingMEBuffer()) { + for (IDualInputHatch dualInputHatch : mDualInputHatches) { + for (var it = dualInputHatch.inventories(); it.hasNext();) { + IDualInputInventory slot = it.next(); + processingLogic.setInputItems(slot.getItemInputs()); + processingLogic.setInputFluids(slot.getFluidInputs()); + CheckRecipeResult foundResult = processingLogic.process(); + if (foundResult.wasSuccessful()) { + return foundResult; + } + if (foundResult != CheckRecipeResultRegistry.NO_RECIPE) { + // Recipe failed in interesting way, so remember that and continue searching + result = foundResult; + } + } + } + } + + // Logic for GT_MetaTileEntity_Hatch_Solidifier + for (GT_MetaTileEntity_Hatch_Input solidifierHatch : mInputHatches) { + if (solidifierHatch instanceof GT_MetaTileEntity_Hatch_Solidifier) { + ItemStack mold = ((GT_MetaTileEntity_Hatch_Solidifier) solidifierHatch).getMold(); + FluidStack fluid = solidifierHatch.getFluid(); + + if (mold != null && fluid != null) { + List<ItemStack> inputItems = new ArrayList<>(); + inputItems.add(mold); + inputItems.add(ItemUtils.getGregtechCircuit(22)); + + processingLogic.setInputItems(inputItems.toArray(new ItemStack[0])); + processingLogic.setInputFluids(fluid); + + CheckRecipeResult foundResult = processingLogic.process(); + if (foundResult.wasSuccessful()) { + return foundResult; + } + if (foundResult != CheckRecipeResultRegistry.NO_RECIPE) { + // Recipe failed in interesting way, so remember that and continue searching + result = foundResult; + } + } + } + } + processingLogic.clear(); + processingLogic.setInputFluids(getStoredFluids()); + // Default logic + for (GT_MetaTileEntity_Hatch_InputBus bus : mInputBusses) { + if (bus instanceof GT_MetaTileEntity_Hatch_CraftingInput_ME) { + continue; + } + List<ItemStack> inputItems = new ArrayList<>(); + for (int i = bus.getSizeInventory() - 1; i >= 0; i--) { + ItemStack stored = bus.getStackInSlot(i); + if (stored != null) { + inputItems.add(stored); + } + } + if (canUseControllerSlotForRecipe() && getControllerSlot() != null) { + inputItems.add(getControllerSlot()); + } + processingLogic.setInputItems(inputItems.toArray(new ItemStack[0])); + CheckRecipeResult foundResult = processingLogic.process(); + if (foundResult.wasSuccessful()) { + return foundResult; + } + if (foundResult != CheckRecipeResultRegistry.NO_RECIPE) { + // Recipe failed in interesting way, so remember that and continue searching + result = foundResult; + } + } + + return result; + } + } + + @Override + public ArrayList<FluidStack> getStoredFluids() { + ArrayList<FluidStack> rList = new ArrayList<>(); + for (GT_MetaTileEntity_Hatch_Input tHatch : filterValidMTEs(mInputHatches)) { + if (tHatch instanceof GT_MetaTileEntity_Hatch_Solidifier) { + continue; + } + + setHatchRecipeMap(tHatch); + if (tHatch instanceof GT_MetaTileEntity_Hatch_MultiInput) { + for (FluidStack tFluid : ((GT_MetaTileEntity_Hatch_MultiInput) tHatch).getStoredFluid()) { + if (tFluid != null) { + rList.add(tFluid); + } + } + } else if (tHatch instanceof GT_MetaTileEntity_Hatch_Input_ME) { + if (tHatch.isValid()) { + for (FluidStack fluidStack : ((GT_MetaTileEntity_Hatch_Input_ME) tHatch).getStoredFluids()) { + if (fluidStack == null) continue; + rList.add(fluidStack); + } + } + } else { + if (tHatch.getFillableStack() != null) { + rList.add(tHatch.getFillableStack()); + } + } + } + + return rList; + } + + @Override + public void getWailaBody(ItemStack itemStack, List<String> currentTip, IWailaDataAccessor accessor, + IWailaConfigHandler config) { + super.getWailaBody(itemStack, currentTip, accessor, config); + final NBTTagCompound tag = accessor.getNBTData(); + if (tag.hasKey("mode")) { + currentTip.add("Mode: " + EnumChatFormatting.YELLOW + switch (tag.getInteger("mode")) { + case 1 -> "Fluid"; + case 2 -> "Misc"; + default -> "Metal"; + } + EnumChatFormatting.RESET); + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialPlatePress.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialPlatePress.java new file mode 100644 index 0000000000..972cf492b6 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialPlatePress.java @@ -0,0 +1,218 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import java.util.Arrays; +import java.util.Collection; + +import javax.annotation.Nonnull; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.SoundResource; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_IndustrialPlatePress + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialPlatePress> implements ISurvivalConstructable { + + private boolean mFormingMode = false; + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialPlatePress> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialPlatePress(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialPlatePress(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialPlatePress(this.mName); + } + + @Override + public String getMachineType() { + return "Bending Machine, Forming Press"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for Advanced Bending & Forming") + .addInfo("500% faster than using single block machines of the same voltage") + .addInfo("Processes four items per voltage tier") + .addInfo("Circuit for recipe goes in the Input Bus") + .addInfo("Each Input Bus can have a different Circuit/Shape!") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfoMin("Material Press Machine Casings", 6, false) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialPlatePress> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialPlatePress>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "C~C", "C-C", "CCC" }, { "CCC", "CCC", "CCC" }, })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialPlatePress.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(50) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 4)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 6 && checkHatch(); + } + + @Override + protected SoundResource getProcessStartSound() { + return SoundResource.IC2_MACHINES_COMPRESSOR_OP; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return 50; + } + + @Override + public RecipeMap<?> getRecipeMap() { + return mFormingMode ? RecipeMaps.formingPressRecipes : RecipeMaps.benderRecipes; + } + + @Nonnull + @Override + public Collection<RecipeMap<?>> getAvailableRecipeMaps() { + return Arrays.asList(RecipeMaps.formingPressRecipes, RecipeMaps.benderRecipes); + } + + @Override + public int getRecipeCatalystPriority() { + return -1; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setSpeedBonus(1F / 6F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public int getMaxParallelRecipes() { + return (4 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + if (this.mFormingMode) return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialPlatePress_ModeForming; + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialPlatePress_ModeBending; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("mFormingMode", mFormingMode); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + mFormingMode = aNBT.getBoolean("mFormingMode"); + super.loadNBTData(aNBT); + } + + @Override + public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mFormingMode = !mFormingMode; + if (mFormingMode) { + PlayerUtils.messagePlayer(aPlayer, "Now running in Forming Press Mode."); + } else { + PlayerUtils.messagePlayer(aPlayer, "Now running in Bending Mode."); + } + mLastRecipe = null; + } + + @Override + public boolean isInputSeparationEnabled() { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialSifter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialSifter.java new file mode 100644 index 0000000000..e4dd3d11ba --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialSifter.java @@ -0,0 +1,209 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import java.util.Random; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_IndustrialSifter + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialSifter> implements ISurvivalConstructable { + + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialSifter> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialSifter(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialSifter(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialSifter(this.mName); + } + + @Override + public String getMachineType() { + return "Sifter"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Sifter") + .addInfo("400% faster than single-block machines of the same voltage") + .addInfo("Only uses 75% of the EU/t normally required") + .addInfo("Processes four items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(5, 3, 5, false) + .addController("Bottom Center") + .addCasingInfoMin("Sieve Grate", 18, false) + .addCasingInfoMin("Sieve Casings", 35, false) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialSifter> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialSifter>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCCCC", "CMMMC", "CMMMC", "CMMMC", "CCCCC" }, + { "CCCCC", "CMMMC", "CMMMC", "CMMMC", "CCCCC" }, + { "CC~CC", "CCCCC", "CCCCC", "CCCCC", "CCCCC" }, })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialSifter.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) + .casingIndex(TAE.GTPP_INDEX(21)) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 5)))) + .addElement('M', ofBlock(ModBlocks.blockCasings2Misc, 6)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 2, 2, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 2, 2, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 2, 2, 0) && mCasing >= 35 && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(21); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return RecipeMaps.sifterRecipes; + } + + @Override + public int getRecipeCatalystPriority() { + return -1; + } + + @Override + public void onPreTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive()) + && (aBaseMetaTileEntity.getFrontFacing() != ForgeDirection.UP) + && (aBaseMetaTileEntity.getCoverIDAtSide(ForgeDirection.UP) == 0) + && (!aBaseMetaTileEntity.getOpacityAtSide(ForgeDirection.UP))) { + final Random tRandom = aBaseMetaTileEntity.getWorld().rand; + if (tRandom.nextFloat() > 0.4) return; + + final int xDir = aBaseMetaTileEntity.getBackFacing().offsetX * 2; + final int zDir = aBaseMetaTileEntity.getBackFacing().offsetZ * 2; + + aBaseMetaTileEntity.getWorld() + .spawnParticle( + "smoke", + (aBaseMetaTileEntity.getXCoord() + xDir + 2.1F) - (tRandom.nextFloat() * 3.2F), + aBaseMetaTileEntity.getYCoord() + 2.5f + (tRandom.nextFloat() * 1.2F), + (aBaseMetaTileEntity.getZCoord() + zDir + 2.1F) - (tRandom.nextFloat() * 3.2F), + 0.0, + 0.0, + 0.0); + } + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setSpeedBonus(1F / 5F) + .setEuModifier(0.75F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public int getMaxParallelRecipes() { + return (4 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialSifter; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public boolean isOverclockerUpgradable() { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialThermalCentrifuge.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialThermalCentrifuge.java new file mode 100644 index 0000000000..14ff4ebb6d --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialThermalCentrifuge.java @@ -0,0 +1,184 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_IndustrialThermalCentrifuge extends + GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialThermalCentrifuge> implements ISurvivalConstructable { + + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialThermalCentrifuge> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialThermalCentrifuge(final int aID, final String aName, + final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialThermalCentrifuge(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialThermalCentrifuge(this.mName); + } + + @Override + public String getMachineType() { + return "Thermal Centrifuge"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Thermal Centrifuge") + .addInfo("150% faster than using single block machines of the same voltage") + .addInfo("Only uses 80% of the EU/t normally required") + .addInfo("Processes eight items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 2, 3, false) + .addController("Front Center") + .addCasingInfoMin("Thermal Processing Casings/Noise Hazard Sign Blocks", 8, false) + .addInputBus("Bottom Casing", 1) + .addOutputBus("Bottom Casing", 1) + .addEnergyHatch("Bottom Casing", 1) + .addMaintenanceHatch("Bottom Casing", 1) + .addMufflerHatch("Bottom Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialThermalCentrifuge> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialThermalCentrifuge>builder() + .addShape(mName, transpose(new String[][] { { "X~X", "XXX", "XXX" }, { "CCC", "CCC", "CCC" }, })) + .addElement( + 'C', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_IndustrialThermalCentrifuge.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 0)), + onElementPass(x -> ++x.mCasing, ofBlock(GregTech_API.sBlockCasings3, 9)))) + .addElement( + 'X', + ofChain( + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 0)), + onElementPass(x -> ++x.mCasing, ofBlock(GregTech_API.sBlockCasings3, 9)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 0, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 0, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 0, 0) && mCasing >= 8 && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return getCasingTextureIndex(); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return RecipeMaps.thermalCentrifugeRecipes; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setSpeedBonus(1F / 2.5F) + .setEuModifier(0.8F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public int getMaxParallelRecipes() { + return (8 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialThermalCentrifuge; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings2Misc; + } + + public byte getCasingMeta() { + return 0; + } + + public byte getCasingTextureIndex() { + return (byte) TAE.GTPP_INDEX(16); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java new file mode 100644 index 0000000000..aba508e183 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialVacuumFreezer.java @@ -0,0 +1,261 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_Utility.filterValidMTEs; + +import java.util.ArrayList; +import java.util.Objects; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.shutdown.ShutDownReasonRegistry; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GT_MetaTileEntity_Hatch_CustomFluidBase; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_IndustrialVacuumFreezer extends + GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialVacuumFreezer> implements ISurvivalConstructable { + + public static int CASING_TEXTURE_ID; + public static String mCryoFuelName = "Gelid Cryotheum"; + public static String mCasingName = "Advanced Cryogenic Casing"; + public static String mHatchName = "Cryotheum Hatch"; + public static FluidStack mFuelStack; + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialVacuumFreezer> STRUCTURE_DEFINITION = null; + + private final ArrayList<GT_MetaTileEntity_Hatch_CustomFluidBase> mCryotheumHatches = new ArrayList<>(); + + public GregtechMetaTileEntity_IndustrialVacuumFreezer(final int aID, final String aName, + final String aNameRegional) { + super(aID, aName, aNameRegional); + mFuelStack = FluidUtils.getFluidStack("cryotheum", 1); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 10); + } + + public GregtechMetaTileEntity_IndustrialVacuumFreezer(final String aName) { + super(aName); + mFuelStack = FluidUtils.getFluidStack("cryotheum", 1); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 10); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return (IMetaTileEntity) new GregtechMetaTileEntity_IndustrialVacuumFreezer(this.mName); + } + + @Override + public String getMachineType() { + return "Vacuum Freezer"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Factory Grade Advanced Vacuum Freezer") + .addInfo("Speed: +100% | EU Usage: 100% | Parallel: 4") + .addInfo("Consumes 20L of " + mCryoFuelName + "/s during operation") + .addInfo("Constructed exactly the same as a normal Vacuum Freezer") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfoMin(mCasingName, 10, false) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addOtherStructurePart(mHatchName, "Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialVacuumFreezer> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialVacuumFreezer>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "C~C", "C-C", "CCC" }, { "CCC", "CCC", "CCC" }, })) + .addElement( + 'C', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_IndustrialVacuumFreezer.class) + .adder(GregtechMetaTileEntity_IndustrialVacuumFreezer::addCryotheumHatch) + .hatchId(967) + .shouldReject(t -> !t.mCryotheumHatches.isEmpty()) + .casingIndex(CASING_TEXTURE_ID) + .dot(1) + .build(), + buildHatchAdder(GregtechMetaTileEntity_IndustrialVacuumFreezer.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) + .casingIndex(CASING_TEXTURE_ID) + .dot(1) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings3Misc, 10)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mCryotheumHatches.clear(); + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); + } + + @Override + public boolean checkHatch() { + return super.checkHatch() && !mCryotheumHatches.isEmpty(); + } + + private boolean addCryotheumHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_CustomFluidBase + && aMetaTileEntity.getBaseMetaTileEntity() + .getMetaTileID() == 967) { + return addToMachineListInternal(mCryotheumHatches, aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public void updateSlots() { + for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : filterValidMTEs(mCryotheumHatches)) tHatch.updateSlots(); + super.updateSlots(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return CASING_TEXTURE_ID; + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.advancedFreezerRecipes; + } + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + return true; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setSpeedBonus(1F / 2F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public int getMaxParallelRecipes() { + return 4; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialVacuumFreezer; + } + + @Override + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + private int mGraceTimer = 2; + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + /* + * if (this.getBaseMetaTileEntity().isActive()) { if (!this.depleteInput(mFuelStack.copy())) { + * this.getBaseMetaTileEntity().setActive(false); } } + */ + super.onPostTick(aBaseMetaTileEntity, aTick); + + if (this.mStartUpCheck < 0) { + if (this.mMaxProgresstime > 0 && this.mProgresstime != 0 || this.getBaseMetaTileEntity() + .hasWorkJustBeenEnabled()) { + if (aTick % 10 == 0 || this.getBaseMetaTileEntity() + .hasWorkJustBeenEnabled()) { + if (!this.depleteInputFromRestrictedHatches(this.mCryotheumHatches, 10)) { + if (mGraceTimer-- == 0) { + this.causeMaintenanceIssue(); + this.stopMachine( + ShutDownReasonRegistry + .outOfFluid(Objects.requireNonNull(FluidUtils.getFluidStack("cryotheum", 20)))); + mGraceTimer = 2; + } + } + } + } + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialWashPlant.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialWashPlant.java new file mode 100644 index 0000000000..a12db63f4e --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialWashPlant.java @@ -0,0 +1,372 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.isAir; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlockAnyMeta; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import java.util.Arrays; +import java.util.Collection; + +import javax.annotation.Nonnull; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.recipe.check.SimpleCheckRecipeResult; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import ic2.core.init.BlocksItems; +import ic2.core.init.InternalName; + +public class GregtechMetaTileEntity_IndustrialWashPlant + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialWashPlant> implements ISurvivalConstructable { + + private int mMode = 0; + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialWashPlant> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialWashPlant(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialWashPlant(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialWashPlant(this.mName); + } + + @Override + public String getMachineType() { + return "Ore Washer, Simple Washer, Chemical Bath"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Wash Plant") + .addInfo("Can be configured with a screwdriver to also do Simple Washer and process Chemical Bathing") + .addInfo("400% faster than using single block machines of the same voltage") + .addInfo("Processes four item per voltage tier") + .addInfo("Always requires an Input Hatch full of water to refill structure") + .addInfo("Need to be filled with water.") + .addInfo("Will automatically fill water from input hatch.") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(5, 3, 7, true) + .addController("Front Center") + .addCasingInfoMin("Wash Plant Casings", 40, false) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialWashPlant> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialWashPlant>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCCCC", "CwwwC", "CwwwC", "CwwwC", "CwwwC", "CwwwC", "CCCCC" }, + { "CC~CC", "CwwwC", "CwwwC", "CwwwC", "CwwwC", "CwwwC", "CCCCC" }, + { "CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC" }, })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialWashPlant.class) + .atLeast(InputBus, InputHatch, OutputHatch, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) + .addElement( + 'w', + ofChain( + isAir(), + ofBlockAnyMeta(Blocks.water), + ofBlockAnyMeta(Blocks.flowing_water), + ofBlockAnyMeta(BlocksItems.getFluidBlock(InternalName.fluidDistilledWater)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 2, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 2, 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 2, 1, 0) && mCasing >= 40 && checkHatch(); + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + // don't rotate a washer, water will flow out. + return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return getCasingTextureIndex(); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return mMode == 0 ? RecipeMaps.oreWasherRecipes + : mMode == 1 ? GTPPRecipeMaps.simpleWasherRecipes : RecipeMaps.chemicalBathRecipes; + } + + @Nonnull + @Override + public Collection<RecipeMap<?>> getAvailableRecipeMaps() { + return Arrays + .asList(RecipeMaps.oreWasherRecipes, GTPPRecipeMaps.simpleWasherRecipes, RecipeMaps.chemicalBathRecipes); + } + + @Override + public int getRecipeCatalystPriority() { + return -10; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic() { + + @NotNull + @Override + protected CheckRecipeResult validateRecipe(@NotNull GT_Recipe recipe) { + if (checkForWater()) { + return CheckRecipeResultRegistry.SUCCESSFUL; + } + return SimpleCheckRecipeResult.ofFailure("no_water"); + } + }.setSpeedBonus(1F / 5F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public int getMaxParallelRecipes() { + return (4 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + if (mMode == 2) return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialWashPlant_ModeChemBath; + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialWashPlant_ModeWasher; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings2Misc; + } + + public byte getCasingMeta() { + return 4; + } + + public byte getCasingTextureIndex() { + return (byte) TAE.GTPP_INDEX(11); + } + + public boolean checkForWater() { + + // Get Facing direction + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + int mDirectionX = aBaseMetaTileEntity.getBackFacing().offsetX; + int mCurrentDirectionX; + int mCurrentDirectionZ; + int mOffsetX_Lower = 0; + int mOffsetX_Upper = 0; + int mOffsetZ_Lower = 0; + int mOffsetZ_Upper = 0; + + if (mDirectionX == 0) { + mCurrentDirectionX = 2; + mCurrentDirectionZ = 3; + mOffsetX_Lower = -2; + mOffsetX_Upper = 2; + mOffsetZ_Lower = -3; + mOffsetZ_Upper = 3; + } else { + mCurrentDirectionX = 3; + mCurrentDirectionZ = 2; + mOffsetX_Lower = -3; + mOffsetX_Upper = 3; + mOffsetZ_Lower = -2; + mOffsetZ_Upper = 2; + } + + // if (aBaseMetaTileEntity.fac) + + final int xDir = aBaseMetaTileEntity.getBackFacing().offsetX * mCurrentDirectionX; + final int zDir = aBaseMetaTileEntity.getBackFacing().offsetZ * mCurrentDirectionZ; + + int tAmount = 0; + for (int i = mOffsetX_Lower + 1; i <= mOffsetX_Upper - 1; ++i) { + for (int j = mOffsetZ_Lower + 1; j <= mOffsetZ_Upper - 1; ++j) { + for (int h = 0; h < 2; ++h) { + Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); + byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); + if (tBlock == Blocks.air || tBlock == Blocks.flowing_water || tBlock == Blocks.water) { + if (this.getStoredFluids() != null) { + for (FluidStack stored : this.getStoredFluids()) { + if (stored.isFluidEqual(FluidUtils.getFluidStack("water", 1))) { + if (stored.amount >= 1000) { + // Utils.LOG_WARNING("Going to try swap an air block for water from inut bus."); + stored.amount -= 1000; + Block fluidUsed = null; + if (tBlock == Blocks.air || tBlock == Blocks.flowing_water) { + fluidUsed = Blocks.water; + } + if (tBlock == Blocks.water) { + fluidUsed = BlocksItems.getFluidBlock(InternalName.fluidDistilledWater); + } + aBaseMetaTileEntity.getWorld() + .setBlock( + aBaseMetaTileEntity.getXCoord() + xDir + i, + aBaseMetaTileEntity.getYCoord() + h, + aBaseMetaTileEntity.getZCoord() + zDir + j, + fluidUsed); + } + } + } + } + } + if (tBlock == Blocks.water) { + ++tAmount; + // Utils.LOG_WARNING("Found Water"); + } else if (tBlock == BlocksItems.getFluidBlock(InternalName.fluidDistilledWater)) { + ++tAmount; + ++tAmount; + // Utils.LOG_WARNING("Found Distilled Water"); + } + } + } + } + + boolean isValidWater = tAmount >= 45; + if (isValidWater) { + Logger.WARNING("Filled structure."); + } else { + Logger.WARNING("Did not fill structure."); + } + return isValidWater; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mMode", mMode); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + if (aNBT.hasKey("mChemicalMode")) { + boolean aTempMode = aNBT.getBoolean("mChemicalMode"); + if (aTempMode) { + mMode = 2; + } else { + mMode = 0; + } + aNBT.removeTag("mChemicalMode"); + } + if (aNBT.hasKey("mMode")) { + mMode = aNBT.getInteger("mMode"); + } + super.loadNBTData(aNBT); + } + + @Override + public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mMode++; + if (mMode > 2) { + mMode = 0; + } + if (mMode == 0) { + PlayerUtils.messagePlayer(aPlayer, "Wash Plant is now running in Ore Washer Mode."); + } else if (mMode == 1) { + PlayerUtils.messagePlayer(aPlayer, "Wash Plant is now running in Simple Washer Mode."); + } else { + PlayerUtils.messagePlayer(aPlayer, "Wash Plant is now running in Chemical Bath Mode."); + } + mLastRecipe = null; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialWireMill.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialWireMill.java new file mode 100644 index 0000000000..15ae5a96f8 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialWireMill.java @@ -0,0 +1,215 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ChatComponentTranslation; +import net.minecraftforge.common.util.ForgeDirection; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.SoundResource; +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_IndustrialWireMill + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialWireMill> implements ISurvivalConstructable { + + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialWireMill> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialWireMill(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + inputSeparation = true; + } + + public GregtechMetaTileEntity_IndustrialWireMill(final String aName) { + super(aName); + inputSeparation = true; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialWireMill(this.mName); + } + + @Override + public String getMachineType() { + return "Wiremill"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Wire Factory") + .addInfo("200% faster than using single block machines of the same voltage") + .addInfo("Only uses 75% of the EU/t normally required") + .addInfo("Processes four items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 5, true) + .addController("Front Center") + .addCasingInfoMin("Wire Factory Casings", 14, false) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialWireMill> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialWireMill>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC", "CCC", "CCC" }, { "C~C", "C-C", "C-C", "C-C", "CCC" }, + { "CCC", "CCC", "CCC", "CCC", "CCC" }, })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialWireMill.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 14 && checkHatch(); + } + + @Override + protected SoundResource getProcessStartSound() { + return SoundResource.IC2_MACHINES_RECYCLER_OP; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(6); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return RecipeMaps.wiremillRecipes; + } + + @Override + public int getRecipeCatalystPriority() { + return -1; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setSpeedBonus(1F / 3F) + .setEuModifier(0.75F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + inputSeparation = !inputSeparation; + aPlayer.addChatMessage( + new ChatComponentTranslation( + inputSeparation ? "interaction.separateBusses.enabled" : "interaction.separateBusses.disabled")); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + if (!aNBT.hasKey(INPUT_SEPARATION_NBT_KEY)) { + inputSeparation = aNBT.getBoolean("isBussesSeparate"); + } + } + + @Override + public int getMaxParallelRecipes() { + return (4 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialWireMill; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasingsMisc; + } + + public byte getCasingMeta() { + return 6; + } + + public byte getCasingTextureIndex() { + return (byte) TAE.GTPP_INDEX(6); + } + + @Override + public boolean supportsInputSeparation() { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IsaMill.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IsaMill.java new file mode 100644 index 0000000000..c14cae9b88 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IsaMill.java @@ -0,0 +1,529 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_Utility.filterValidMTEs; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.DamageSource; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; +import net.minecraftforge.common.util.ForgeDirection; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.recipe.check.SimpleCheckRecipeResult; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.item.chemistry.general.ItemGenericChemBase; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.EntityUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.nbthandlers.GT_MetaTileEntity_Hatch_MillingBalls; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock.CustomIcon; + +public class GregtechMetaTileEntity_IsaMill extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IsaMill> + implements ISurvivalConstructable { + + protected boolean boostEu = false; + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_IsaMill> STRUCTURE_DEFINITION = null; + + private static final IIconContainer frontFaceActive = new CustomIcon("iconsets/Grinder/GRINDER_ACTIVE5"); + private static final IIconContainer frontFace = new CustomIcon("iconsets/Grinder/GRINDER5"); + + private final ArrayList<GT_MetaTileEntity_Hatch_MillingBalls> mMillingBallBuses = new ArrayList<>(); + private static final DamageSource mIsaMillDamageSource = new DamageSource("gtpp.grinder").setDamageBypassesArmor(); + + public GregtechMetaTileEntity_IsaMill(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IsaMill(String aName) { + super(aName); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Large Grinding Machine") + .addInfo("Grind ores.") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 7, false) + .addController("Front Center") + .addCasingInfoMin("IsaMill Exterior Casing", 40, false) + .addOtherStructurePart("IsaMill Gearbox", "5x, Inner Blocks") + .addOtherStructurePart("IsaMill Piping", "8x, ring around controller") + .addStructureInfo("IsaMill Pipings must not be obstructed in front (only air blocks)") + .addOtherStructurePart("Milling Ball Hatch", "Any Casing") + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IsaMill> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IsaMill>builder() + .addShape( + mName, + transpose( + new String[][] { { "DDD", "CCC", "CCC", "CCC", "CCC", "CCC", "CCC" }, + { "D~D", "CGC", "CGC", "CGC", "CGC", "CGC", "CCC" }, + { "DDD", "CCC", "CCC", "CCC", "CCC", "CCC", "CCC" }, })) + .addElement( + 'C', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_IsaMill.class) + .adder(GregtechMetaTileEntity_IsaMill::addMillingBallsHatch) + .hatchClass(GT_MetaTileEntity_Hatch_MillingBalls.class) + .shouldReject(t -> !t.mMillingBallBuses.isEmpty()) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .build(), + buildHatchAdder(GregtechMetaTileEntity_IsaMill.class) + .atLeast(InputBus, OutputBus, InputHatch, OutputHatch, Maintenance, Energy, Muffler) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) + .addElement('D', ofBlock(getIntakeBlock(), getIntakeMeta())) + .addElement('G', ofBlock(getGearboxBlock(), getGearboxMeta())) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mMillingBallBuses.clear(); + return checkPiece(mName, 1, 1, 0) && mCasing >= 48 - 8 && checkHatch(); + } + + @Override + public boolean checkHatch() { + return super.checkHatch() && mMillingBallBuses.size() == 1; + } + + @Override + protected IIconContainer getActiveOverlay() { + return frontFaceActive; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return frontFace; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(2); + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return getMaxEfficiency(aStack) > 0; + } + + private boolean addMillingBallsHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_MillingBalls) { + return addToMachineListInternal(mMillingBallBuses, aMetaTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public boolean addToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_MillingBalls) { + log("Found GT_MetaTileEntity_Hatch_MillingBalls"); + return addToMachineListInternal(mMillingBallBuses, aMetaTileEntity, aBaseCasingIndex); + } + return super.addToMachineList(aTileEntity, aBaseCasingIndex); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.millingRecipes; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + if (this.mUpdate == 1 || this.mStartUpCheck == 1) { + this.mMillingBallBuses.clear(); + } + } + if (aTick % 20 == 0 && isMachineRunning()) { + checkForEntities(aBaseMetaTileEntity, aTick); + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + private final AutoMap<BlockPos> mFrontBlockPosCache = new AutoMap<>(); + + public void checkForEntities(IGregTechTileEntity aBaseMetaTileEntity, long aTime) { + + if (aTime % 100 == 0) { + mFrontBlockPosCache.clear(); + } + if (mFrontBlockPosCache.isEmpty()) { + ForgeDirection tSide = aBaseMetaTileEntity.getBackFacing(); + int aTileX = aBaseMetaTileEntity.getXCoord(); + int aTileY = aBaseMetaTileEntity.getYCoord(); + int aTileZ = aBaseMetaTileEntity.getZCoord(); + boolean xFacing = tSide.offsetX != 0; + boolean zFacing = tSide.offsetZ != 0; + + // Check Casings + int aDepthOffset = (tSide == ForgeDirection.NORTH || tSide == ForgeDirection.WEST) ? 1 : -1; + for (int aHorizontalOffset = -1; aHorizontalOffset < 2; aHorizontalOffset++) { + for (int aVerticalOffset = -1; aVerticalOffset < 2; aVerticalOffset++) { + int aX = !xFacing ? (aTileX + aHorizontalOffset) : (aTileX + aDepthOffset); + int aY = aTileY + aVerticalOffset; + int aZ = !zFacing ? (aTileZ + aHorizontalOffset) : (aTileZ + aDepthOffset); + mFrontBlockPosCache.add(new BlockPos(aX, aY, aZ, aBaseMetaTileEntity.getWorld())); + } + } + } + + AutoMap<EntityLivingBase> aEntities = getEntities(mFrontBlockPosCache, aBaseMetaTileEntity.getWorld()); + if (!aEntities.isEmpty()) { + for (EntityLivingBase aFoundEntity : aEntities) { + if (aFoundEntity instanceof EntityPlayer aPlayer) { + if (PlayerUtils.isCreative(aPlayer) || !PlayerUtils.canTakeDamage(aPlayer)) { + continue; + } else { + if (aFoundEntity.getHealth() > 0) { + EntityUtils.doDamage(aFoundEntity, mIsaMillDamageSource, getPlayerDamageValue(aPlayer, 10)); + if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive())) { + generateParticles(aFoundEntity); + } + } + } + } else if (aFoundEntity.getHealth() > 0) { + EntityUtils.doDamage( + aFoundEntity, + mIsaMillDamageSource, + Math.max(1, (int) (aFoundEntity.getMaxHealth() / 3))); + if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive())) { + generateParticles(aFoundEntity); + } + } + } + } + } + + // 20 armor points add 80% damage reduction, more points add more damage reduction + private int getPlayerDamageValue(EntityPlayer player, int damage) { + int armorValue = player.getTotalArmorValue(); + int reducedDamage = (int) (damage - damage * (armorValue * 0.04)); + return Math.max(reducedDamage, 0); + } + + private static AutoMap<EntityLivingBase> getEntities(AutoMap<BlockPos> aPositionsToCheck, World aWorld) { + AutoMap<EntityLivingBase> aEntities = new AutoMap<>(); + HashSet<Chunk> aChunksToCheck = new HashSet<>(); + if (!aPositionsToCheck.isEmpty()) { + Chunk aLocalChunk; + for (BlockPos aPos : aPositionsToCheck) { + aLocalChunk = aWorld.getChunkFromBlockCoords(aPos.xPos, aPos.zPos); + aChunksToCheck.add(aLocalChunk); + } + } + if (!aChunksToCheck.isEmpty()) { + AutoMap<EntityLivingBase> aEntitiesFound = new AutoMap<>(); + for (Chunk aChunk : aChunksToCheck) { + if (aChunk.isChunkLoaded) { + List[] aEntityLists = aChunk.entityLists; + for (List aEntitySubList : aEntityLists) { + for (Object aEntity : aEntitySubList) { + if (aEntity instanceof EntityLivingBase aPlayer) { + aEntitiesFound.add(aPlayer); + } + } + } + } + } + if (!aEntitiesFound.isEmpty()) { + for (EntityLivingBase aEntity : aEntitiesFound) { + BlockPos aPlayerPos = EntityUtils.findBlockPosOfEntity(aEntity); + for (BlockPos aBlockSpaceToCheck : aPositionsToCheck) { + if (aBlockSpaceToCheck.equals(aPlayerPos)) { + aEntities.add(aEntity); + } + } + } + } + } + return aEntities; + } + + private static void generateParticles(EntityLivingBase aEntity) { + BlockPos aPlayerPosBottom = EntityUtils.findBlockPosOfEntity(aEntity); + BlockPos aPlayerPosTop = aPlayerPosBottom.getUp(); + AutoMap<BlockPos> aEntityPositions = new AutoMap<>(); + aEntityPositions.add(aPlayerPosBottom); + aEntityPositions.add(aPlayerPosTop); + for (int i = 0; i < 64; i++) { + BlockPos aEffectPos = aEntityPositions.get(aEntity.height > 1f ? MathUtils.randInt(0, 1) : 0); + float aOffsetX = MathUtils.randFloat(-0.35f, 0.35f); + float aOffsetY = MathUtils.randFloat(-0.25f, 0.35f); + float aOffsetZ = MathUtils.randFloat(-0.35f, 0.35f); + aEntity.worldObj.spawnParticle( + "reddust", + aEffectPos.xPos + aOffsetX, + aEffectPos.yPos + 0.3f + aOffsetY, + aEffectPos.zPos + aOffsetZ, + 0.0D, + 0.0D, + 0.0D); + } + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings5Misc; + } + + public byte getCasingMeta() { + return 0; + } + + public Block getIntakeBlock() { + return ModBlocks.blockCasings5Misc; + } + + public byte getIntakeMeta() { + return 1; + } + + public Block getGearboxBlock() { + return ModBlocks.blockCasings5Misc; + } + + public byte getGearboxMeta() { + return 2; + } + + public byte getCasingTextureIndex() { + return 66; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IsaMill(this.mName); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 1; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIsaMill; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public String[] getExtraInfoData() { + return new String[] { "IsaMill Grinding Machine", "Current Efficiency: " + (mEfficiency / 100) + "%", + getIdealStatus() == getRepairStatus() ? "No Maintainance issues" : "Needs Maintainance" }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public String getMachineType() { + return "Grinding Machine"; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + /* + * Milling Ball Handling + */ + + @Override + public ArrayList<ItemStack> getStoredInputs() { + ArrayList<ItemStack> tItems = super.getStoredInputs(); + for (GT_MetaTileEntity_Hatch_MillingBalls tHatch : filterValidMTEs(mMillingBallBuses)) { + AutoMap<ItemStack> aHatchContent = tHatch.getContentUsageSlots(); + if (!aHatchContent.isEmpty()) { + tItems.addAll(aHatchContent); + } + } + return tItems; + } + + public int getMaxBallDurability(ItemStack aStack) { + return ItemGenericChemBase.getMaxBallDurability(aStack); + } + + private ItemStack findMillingBall(ItemStack[] aItemInputs) { + if (mMillingBallBuses.size() != 1) { + return null; + } else { + GT_MetaTileEntity_Hatch_MillingBalls aBus = mMillingBallBuses.get(0); + if (aBus != null) { + AutoMap<ItemStack> aAvailableItems = aBus.getContentUsageSlots(); + if (!aAvailableItems.isEmpty()) { + for (final ItemStack aInput : aItemInputs) { + if (ItemUtils.isMillingBall(aInput)) { + for (ItemStack aBall : aAvailableItems) { + if (GT_Utility.areStacksEqual(aBall, aInput, true)) { + Logger.INFO("Found a valid milling ball to use."); + return aBall; + } + } + } + } + } + } + } + return null; + } + + private void damageMillingBall(ItemStack aStack) { + if (MathUtils.randFloat(0, 10000000) / 10000000f < (1.2f - (0.2 * 1))) { + int damage = getMillingBallDamage(aStack) + 1; + log("damage milling ball " + damage); + if (damage >= getMaxBallDurability(aStack)) { + log("consuming milling ball"); + aStack.stackSize -= 1; + } else { + setDamage(aStack, damage); + } + } else { + log("not damaging milling ball"); + } + } + + private int getMillingBallDamage(ItemStack aStack) { + return ItemGenericChemBase.getMillingBallDamage(aStack); + } + + private void setDamage(ItemStack aStack, int aAmount) { + ItemGenericChemBase.setMillingBallDamage(aStack, aAmount); + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic() { + + ItemStack millingBall; + + @NotNull + @Override + protected CheckRecipeResult validateRecipe(@NotNull GT_Recipe recipe) { + millingBall = findMillingBall(inputItems); + if (millingBall == null) { + return SimpleCheckRecipeResult.ofFailure("no_milling_ball"); + } + return CheckRecipeResultRegistry.SUCCESSFUL; + } + + @NotNull + @Override + public CheckRecipeResult process() { + CheckRecipeResult result = super.process(); + if (result.wasSuccessful()) { + damageMillingBall(millingBall); + } + return result; + } + }.enablePerfectOverclock(); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_NuclearSaltProcessingPlant.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_NuclearSaltProcessingPlant.java new file mode 100644 index 0000000000..6d1593bec9 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_NuclearSaltProcessingPlant.java @@ -0,0 +1,224 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import net.minecraft.item.ItemStack; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; + +public class GregtechMetaTileEntity_NuclearSaltProcessingPlant extends + GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_NuclearSaltProcessingPlant> implements ISurvivalConstructable { + + protected GT_Recipe lastRecipeToBuffer; + private int casing; + private static IStructureDefinition<GregtechMetaTileEntity_NuclearSaltProcessingPlant> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_NuclearSaltProcessingPlant(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_NuclearSaltProcessingPlant(String mName) { + super(mName); + } + + @Override + public String getMachineType() { + return "Reactor Processing Unit, Cold Trap"; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity tileEntity) { + return new GregtechMetaTileEntity_NuclearSaltProcessingPlant(this.mName); + } + + @Override + public int getMaxEfficiency(ItemStack itemStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiAutoCrafter; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Nuclear Salt Processing Plant") + .addInfo("Processes depleted nuclear salts that come from the LFTR") + .addInfo("Handles the recipes of the Reactor Processor Unit and Cold Trap") + .addInfo("Only Thermally Insulated Casings can be replaced with hatches") + .addInfo("Mufflers on top, Energy Hatches on bottom, exactly 2 of each are required") + .addInfo("Maintenance Hatch goes on the back, opposite of the controller block") + .addInfo("Inputs go on the left side of the multi, outputs on the right side") + .addInfo("150% faster than using single block machines of the same voltage") + .addInfo("Processes two items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfoMin("IV Machine Casing", 58, false) + .addCasingInfoMin("Thermally Insulated Casing", 1, false) + .addInputBus("Left Half", 2) + .addInputHatch("Left Half", 2) + .addOutputBus("Right Half", 3) + .addOutputHatch("Right Half", 3) + .addMufflerHatch("Top Side, 2 Required", 4) + .addEnergyHatch("Bottom Side, 2 Required", 5) + .addMaintenanceHatch("Back Side, Opposite of Controller", 6) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + protected IIconContainer getActiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER_ACTIVE; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER; + } + + @Override + protected int getCasingTextureId() { + return TAE.getIndexFromPage(0, 10); + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_NuclearSaltProcessingPlant> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_NuclearSaltProcessingPlant>builder() + .addShape( + mName, + transpose( + new String[][] { { "AAA AAA", "ADA ADA", "AAA AAA" }, + { "ABBA ACCA", "B AAA C", "ABBA ACCA" }, { "ABBB~CCCA", "B C", "ABBBFCCCA" }, + { "ABBA ACCA", "B AAA C", "ABBA ACCA" }, { "AAA AAA", "AEA AEA", "AAA AAA" } })) + .addElement('A', ofBlock(GregTech_API.sBlockCasings1, 5)) + .addElement( + 'B', + buildHatchAdder(GregtechMetaTileEntity_NuclearSaltProcessingPlant.class) + .atLeast(InputBus, InputHatch) + .casingIndex(TAE.getIndexFromPage(0, 10)) + .dot(2) + .buildAndChain(onElementPass(x -> ++x.casing, ofBlock(ModBlocks.blockSpecialMultiCasings, 8)))) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_NuclearSaltProcessingPlant.class) + .atLeast(OutputBus, OutputHatch) + .casingIndex(TAE.getIndexFromPage(0, 10)) + .dot(3) + .buildAndChain(onElementPass(x -> ++x.casing, ofBlock(ModBlocks.blockSpecialMultiCasings, 8)))) + .addElement( + 'D', + buildHatchAdder(GregtechMetaTileEntity_NuclearSaltProcessingPlant.class).atLeast(Muffler) + .casingIndex(TAE.getIndexFromPage(0, 10)) + .dot(4) + .buildAndChain(onElementPass(x -> ++x.casing, ofBlock(ModBlocks.blockSpecialMultiCasings, 8)))) + .addElement( + 'E', + buildHatchAdder(GregtechMetaTileEntity_NuclearSaltProcessingPlant.class).atLeast(Energy) + .casingIndex(TAE.getIndexFromPage(0, 10)) + .dot(5) + .buildAndChain(onElementPass(x -> ++x.casing, ofBlock(ModBlocks.blockSpecialMultiCasings, 8)))) + .addElement( + 'F', + buildHatchAdder(GregtechMetaTileEntity_NuclearSaltProcessingPlant.class).atLeast(Maintenance) + .casingIndex(TAE.getIndexFromPage(0, 10)) + .dot(6) + .buildAndChain(onElementPass(x -> ++x.casing, ofBlock(ModBlocks.blockSpecialMultiCasings, 8)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack itemStack, boolean hintsOnly) { + buildPiece(mName, itemStack, hintsOnly, 4, 2, 0); + } + + @Override + public int survivalConstruct(ItemStack itemStack, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, itemStack, 4, 2, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity baseMetaTileEntity, ItemStack itemStack) { + casing = 0; + return checkPiece(mName, 4, 2, 0) && checkHatch(); + } + + @Override + public boolean checkHatch() { + return mEnergyHatches.size() == 2 && mMufflerHatches.size() == 2 && super.checkHatch(); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.nuclearSaltProcessingPlantRecipes; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setSpeedBonus(1F / 2.5F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public int getMaxParallelRecipes() { + return 2 * (Math.max(1, GT_Utility.getTier(getMaxInputVoltage()))); + } + + @Override + public String[] getExtraInfoData() { + final String running = (this.mMaxProgresstime > 0 ? "Salt Plant running" : "Salt Plant stopped"); + final String maintenance = (this.getIdealStatus() == this.getRepairStatus() ? "No Maintenance issues" + : "Needs Maintenance"); + String tSpecialText; + + if (lastRecipeToBuffer != null && lastRecipeToBuffer.mOutputs[0].getDisplayName() != null) { + tSpecialText = "Currently processing: " + lastRecipeToBuffer.mOutputs[0].getDisplayName(); + } else { + tSpecialText = "Currently processing: Nothing"; + } + + return new String[] { "Nuclear Salt Processing Plant", running, maintenance, tSpecialText }; + } + + @Override + public boolean supportsInputSeparation() { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_SpargeTower.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_SpargeTower.java new file mode 100644 index 0000000000..5f4203b99e --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_SpargeTower.java @@ -0,0 +1,507 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.isAir; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.interfaces.IHatchElement; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.fluid.IFluidStore; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.GasSpargingRecipe; +import gregtech.api.util.GasSpargingRecipeMap; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_SpargeTower extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_SpargeTower> + implements ISurvivalConstructable { + + protected static final String STRUCTURE_PIECE_BASE = "base"; + protected static final String STRUCTURE_PIECE_LAYER = "layer"; + protected static final String STRUCTURE_PIECE_LAYER_HINT = "layerHint"; + protected static final String STRUCTURE_PIECE_TOP_HINT = "topHint"; + private static final IStructureDefinition<GregtechMetaTileEntity_SpargeTower> STRUCTURE_DEFINITION; + + static { + IHatchElement<GregtechMetaTileEntity_SpargeTower> layeredOutputHatch = OutputHatch + .withCount(GregtechMetaTileEntity_SpargeTower::getCurrentLayerOutputHatchCount) + .withAdder(GregtechMetaTileEntity_SpargeTower::addLayerOutputHatch); + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_SpargeTower>builder() + .addShape(STRUCTURE_PIECE_BASE, transpose(new String[][] { { "b~b", "bbb", "bbb" }, })) + .addShape(STRUCTURE_PIECE_LAYER, transpose(new String[][] { { "lll", "lcl", "lll" } })) + .addShape(STRUCTURE_PIECE_LAYER_HINT, transpose(new String[][] { { "lll", "l-l", "lll" } })) + .addShape(STRUCTURE_PIECE_TOP_HINT, transpose(new String[][] { { "lll", "lll", "lll" } })) + .addElement( + 'b', + buildHatchAdder(GregtechMetaTileEntity_SpargeTower.class) + .atLeast(Energy, InputHatch, InputBus, Maintenance) + .disallowOnly(ForgeDirection.UP) + .casingIndex(getCasingIndex()) + .dot(1) + .buildAndChain( + onElementPass( + GregtechMetaTileEntity_SpargeTower::onCasingFound, + ofBlock(ModBlocks.blockCasings5Misc, 4)))) + .addElement( + 'l', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_SpargeTower.class).atLeast(layeredOutputHatch) + .disallowOnly(ForgeDirection.UP, ForgeDirection.DOWN) + .casingIndex(getCasingIndex()) + .dot(2) + .build(), + ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addEnergyInputToMachineList, getCasingIndex(), 2), + ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addMaintenanceToMachineList, getCasingIndex(), 2), + onElementPass( + GregtechMetaTileEntity_SpargeTower::onCasingFound, + ofBlock(ModBlocks.blockCasings5Misc, 4)))) + .addElement( + 'c', + ofChain( + onElementPass( + t -> t.onTopLayerFound(false), + ofHatchAdder(GregtechMetaTileEntity_SpargeTower::addOutputToMachineList, getCasingIndex(), 3)), + onElementPass( + t -> t.onTopLayerFound(false), + ofHatchAdder( + GregtechMetaTileEntity_SpargeTower::addMaintenanceToMachineList, + getCasingIndex(), + 3)), + onElementPass(t -> t.onTopLayerFound(true), ofBlock(ModBlocks.blockCasings5Misc, 4)), + isAir())) + .build(); + } + + protected final List<List<GT_MetaTileEntity_Hatch_Output>> mOutputHatchesByLayer = new ArrayList<>(); + protected int mHeight; + protected int mCasing; + protected boolean mTopLayerFound; + + public GregtechMetaTileEntity_SpargeTower(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_SpargeTower(String aName) { + super(aName); + } + + public static int getCasingIndex() { + return 68; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_SpargeTower(this.mName); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType("Gas Sparge Tower") + .addInfo("Controller block for the Sparging Tower") + .addInfo("Runs gases through depleted molten salts to extract precious fluids") + .addInfo("Works the same way as the Distillation Tower, but with a fixed height of 8") + .addInfo("Fluids are only put out at the correct height") + .addInfo("The correct height equals the slot number in the NEI recipe") + .addSeparator() + .beginStructureBlock(3, 8, 3, true) + .addController("Front bottom") + .addOtherStructurePart("Sparge Tower Exterior Casing", "45 (minimum)") + .addEnergyHatch("Any casing", 1, 2) + .addMaintenanceHatch("Any casing", 1, 2, 3) + .addInputHatch("2x Input Hatches (Any bottom layer casing)", 1) + .addOutputHatch("6x Output Hatches (At least one per layer except bottom layer)", 2, 3) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return getCasingIndex(); + } + + @Override + public RecipeMap<?> getRecipeMap() { + if (GTPPRecipeMaps.spargeTowerFakeRecipes.getAllRecipes() + .isEmpty()) { + generateRecipes(); + } + return GTPPRecipeMaps.spargeTowerFakeRecipes; + } + + private static boolean generateRecipes() { + for (GasSpargingRecipe aRecipe : GasSpargingRecipeMap.mRecipes) { + GT_Recipe newRecipe = new GT_Recipe( + false, + new ItemStack[] {}, + new ItemStack[] {}, + null, + null, + aRecipe.mFluidInputs.clone(), + new FluidStack[] {}, + aRecipe.mDuration, + aRecipe.mEUt, + 0); + GTPPRecipeMaps.spargeTowerFakeRecipes.add(newRecipe); + } + return !GTPPRecipeMaps.spargeTowerFakeRecipes.getAllRecipes() + .isEmpty(); + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + public @NotNull CheckRecipeResult checkProcessing() { + ArrayList<FluidStack> tFluidList = getStoredFluids(); + long tVoltage = GT_Utility.roundUpVoltage(this.getMaxInputVoltage()); + byte tTier = (byte) Math.max(0, GT_Utility.getTier(tVoltage)); + FluidStack[] tFluids = tFluidList.toArray(new FluidStack[0]); + if (tFluids.length > 0) { + GT_Recipe tRecipe = getRecipeMap() + .findRecipe(getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluids); + if (tRecipe != null) { + FluidStack[] possibleOutputs = getPossibleByproductsOfSparge( + tRecipe.mFluidInputs[0], + tRecipe.mFluidInputs[1]).toArray(new FluidStack[0]); + if (canOutputAll(possibleOutputs) && tRecipe.isRecipeInputEqual(true, tFluids)) { + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + calculateOverclockedNessMulti((long) tRecipe.mEUt, tRecipe.mDuration, 1, tVoltage); + mMaxProgresstime = Math.max(1, mMaxProgresstime); + ArrayList<FluidStack> aFluidOutputs = getByproductsOfSparge( + tRecipe.mFluidInputs[0], + tRecipe.mFluidInputs[1]); + this.mOutputFluids = aFluidOutputs.toArray(new FluidStack[0]); + updateSlots(); + + if (lEUt > 0) { + lEUt = (-lEUt); + } + + return CheckRecipeResultRegistry.SUCCESSFUL; + } + } + } + this.lEUt = 0; + this.mEfficiency = 0; + return CheckRecipeResultRegistry.NO_RECIPE; + } + + private static List<FluidStack> getPossibleByproductsOfSparge(final FluidStack aSpargeGas, + final FluidStack aSpentFuel) { + GasSpargingRecipe aSpargeRecipe = GasSpargingRecipeMap.findRecipe(aSpargeGas, aSpentFuel); + ArrayList<FluidStack> aOutputGases = new ArrayList<>(); + if (aSpargeRecipe == null) { + return aOutputGases; + } + + aOutputGases.add(aSpargeRecipe.mOutputSpargedFuel.copy()); + ArrayList<FluidStack> aTempMap = new ArrayList<>(); + for (int i = 2; i < aSpargeRecipe.mFluidOutputs.length; i++) { + int aGasAmount = aSpargeRecipe.mMaxOutputQuantity[i - 2] / 100; + FluidStack aOutput = aSpargeRecipe.mFluidOutputs[i].copy(); + FluidStack aSpargeOutput = null; + if (aGasAmount > 0) { + aSpargeOutput = new FluidStack(aOutput.getFluid(), aGasAmount); + } + aTempMap.add(aSpargeOutput); + } + aOutputGases.add(new FluidStack(aSpargeRecipe.mInputGas.getFluid(), aSpargeRecipe.mInputGas.amount)); + aOutputGases.addAll(aTempMap); + return aOutputGases; + } + + private static ArrayList<FluidStack> getByproductsOfSparge(final FluidStack aSpargeGas, + final FluidStack aSpentFuel) { + GasSpargingRecipe aSpargeRecipe = GasSpargingRecipeMap.findRecipe(aSpargeGas, aSpentFuel); + ArrayList<FluidStack> aOutputGases = new ArrayList<>(); + if (aSpargeRecipe == null) { + Logger.INFO("Did not find sparge recipe!"); + return aOutputGases; + } + int aSpargeGasAmount = aSpargeRecipe.mInputGas.amount; + + aOutputGases.add(aSpargeRecipe.mOutputSpargedFuel.copy()); + ArrayList<FluidStack> aTempMap = new ArrayList<>(); + for (int i = 2; i < aSpargeRecipe.mFluidOutputs.length; i++) { + int aGasAmount = MathUtils.randInt(0, (aSpargeRecipe.mMaxOutputQuantity[i - 2] / 100)); + FluidStack aOutput = aSpargeRecipe.mFluidOutputs[i].copy(); + aSpargeGasAmount -= aGasAmount; + FluidStack aSpargeOutput = null; + if (aGasAmount > 0) { + aSpargeOutput = new FluidStack(aOutput.getFluid(), aGasAmount); + } + aTempMap.add(aSpargeOutput); + } + Logger.INFO("Sparge gas left: " + aSpargeGasAmount); + if (aSpargeGasAmount > 0) { + aOutputGases.add(new FluidStack(aSpargeRecipe.mInputGas.getFluid(), aSpargeGasAmount)); + } + // Logger.INFO("Sparge Outputs: "+ItemUtils.getArrayStackNames(aTempMap)); + aOutputGases.addAll(aTempMap); + Logger.INFO("Sparge output size: " + aOutputGases.size()); + // Logger.INFO("Output of sparging: "+ItemUtils.getArrayStackNames(aOutputGases)); + return aOutputGases; + } + + protected void onCasingFound() { + mCasing++; + } + + protected void onTopLayerFound(boolean aIsCasing) { + mTopLayerFound = true; + if (aIsCasing) { + onCasingFound(); + } + } + + protected int getCurrentLayerOutputHatchCount() { + return mOutputHatchesByLayer.size() < mHeight || mHeight <= 0 ? 0 + : mOutputHatchesByLayer.get(mHeight - 1) + .size(); + } + + protected boolean addLayerOutputHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null || aTileEntity.isDead() + || !(aTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_Hatch_Output tHatch)) { + Logger.INFO("Bad Output Hatch"); + return false; + } + while (mOutputHatchesByLayer.size() < mHeight) { + mOutputHatchesByLayer.add(new ArrayList<>()); + } + tHatch.updateTexture(aBaseCasingIndex); + boolean addedHatch = mOutputHatchesByLayer.get(mHeight - 1) + .add(tHatch); + Logger.INFO("Added Hatch: " + addedHatch); + return addedHatch; + } + + @Override + public List<? extends IFluidStore> getFluidOutputSlots(FluidStack[] toOutput) { + return getFluidOutputSlotsByLayer(toOutput, mOutputHatchesByLayer); + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + // don't rotate a freaking tower, it won't work + return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_SpargeTower> getStructureDefinition() { + return STRUCTURE_DEFINITION; + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + // reset + mOutputHatchesByLayer.forEach(List::clear); + mHeight = 1; + mTopLayerFound = false; + mCasing = 0; + + // check base + if (!checkPiece(STRUCTURE_PIECE_BASE, 1, 0, 0)) { + Logger.INFO("Bad Base. Height: " + mHeight); + return false; + } + + // check each layer + while (mHeight < 8 && checkPiece(STRUCTURE_PIECE_LAYER, 1, mHeight, 0) && !mTopLayerFound) { + if (mOutputHatchesByLayer.get(mHeight - 1) + .isEmpty()) { + // layer without output hatch + Logger.INFO("Height: " + mHeight + " - Missing output on " + (mHeight - 1)); + return false; + } + // not top + mHeight++; + } + + // validate final invariants... + Logger.INFO("Height: " + mHeight); + Logger.INFO("Casings: " + mCasing); + Logger.INFO("Required: " + (7 * mHeight - 5)); + Logger.INFO("Found Top: " + mTopLayerFound); + return mCasing >= 45 && mTopLayerFound && mMaintenanceHatches.size() == 1; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(ItemStack aStack) { + return 0; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + protected void addFluidOutputs(FluidStack[] mOutputFluids2) { + for (int i = 0; i < mOutputFluids2.length && i < mOutputHatchesByLayer.size(); i++) { + FluidStack tStack = mOutputFluids2[i] != null ? mOutputFluids2[i].copy() : null; + if (tStack == null) { + continue; + } + if (!dumpFluid(mOutputHatchesByLayer.get(i), tStack, true)) { + dumpFluid(mOutputHatchesByLayer.get(i), tStack, false); + } + } + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(STRUCTURE_PIECE_BASE, stackSize, hintsOnly, 1, 0, 0); + int tTotalHeight = 8; // min 2 output layer, so at least 1 + 2 height + for (int i = 1; i < tTotalHeight - 1; i++) { + buildPiece(STRUCTURE_PIECE_LAYER_HINT, stackSize, hintsOnly, 1, i, 0); + } + buildPiece(STRUCTURE_PIECE_TOP_HINT, stackSize, hintsOnly, 1, tTotalHeight - 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + mHeight = 0; + int built = survivialBuildPiece(STRUCTURE_PIECE_BASE, stackSize, 1, 0, 0, elementBudget, env, false, true); + if (built >= 0) return built; + int tTotalHeight = 8; // min 2 output layer, so at least 1 + 2 height + for (int i = 1; i < tTotalHeight - 1; i++) { + mHeight = i; + built = survivialBuildPiece( + STRUCTURE_PIECE_LAYER_HINT, + stackSize, + 1, + i, + 0, + elementBudget, + env, + false, + true); + if (built >= 0) return built; + } + mHeight = tTotalHeight - 1; + return survivialBuildPiece( + STRUCTURE_PIECE_TOP_HINT, + stackSize, + 1, + tTotalHeight - 1, + 0, + elementBudget, + env, + false, + true); + } + + @Override + public String getMachineType() { + return "Gas Sparger"; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public boolean onPlungerRightClick(EntityPlayer aPlayer, ForgeDirection side, float aX, float aY, float aZ) { + int aLayerIndex = 0; + PlayerUtils + .messagePlayer(aPlayer, "Trying to clear " + mOutputHatchesByLayer.size() + " layers of output hatches."); + for (List<GT_MetaTileEntity_Hatch_Output> layer : this.mOutputHatchesByLayer) { + int aHatchIndex = 0; + for (GT_MetaTileEntity_Hatch_Output hatch : layer) { + if (hatch.mFluid != null) { + PlayerUtils.messagePlayer( + aPlayer, + "Clearing " + hatch.mFluid.amount + + "L of " + + hatch.mFluid.getLocalizedName() + + " from hatch " + + aHatchIndex + + " on layer " + + aLayerIndex + + "."); + hatch.mFluid = null; + } + aHatchIndex++; + } + aLayerIndex++; + } + return aLayerIndex > 0; + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + // Ensure that lEUt is negative from loaded NBT data, since this multi consumes EU + if (lEUt > 0) { + lEUt = (-lEUt); + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_DistillationTower.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_DistillationTower.java new file mode 100644 index 0000000000..8296b8e7cb --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_DistillationTower.java @@ -0,0 +1,491 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.advanced; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.isAir; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import javax.annotation.Nonnull; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.StatCollector; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.IHatchElement; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.fluid.IFluidStore; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_Output_ME; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; + +public class GregtechMetaTileEntity_Adv_DistillationTower extends + GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Adv_DistillationTower> implements ISurvivalConstructable { + + private Mode mMode = Mode.DistillationTower; + private boolean mUpgraded = false; + + protected static final String STRUCTURE_PIECE_BASE = "base"; + protected static final String STRUCTURE_PIECE_LAYER = "layer"; + protected static final String STRUCTURE_PIECE_LAYER_HINT = "layerHint"; + protected static final String STRUCTURE_PIECE_TOP_HINT = "topHint"; + + protected final List<List<GT_MetaTileEntity_Hatch_Output>> mOutputHatchesByLayer = new ArrayList<>(); + protected int mHeight; + protected int mCasing; + protected boolean mTopLayerFound; + + private static IStructureDefinition<GregtechMetaTileEntity_Adv_DistillationTower> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_Adv_DistillationTower(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_Adv_DistillationTower(String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Adv_DistillationTower(this.mName); + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_Adv_DistillationTower> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + IHatchElement<GregtechMetaTileEntity_Adv_DistillationTower> layeredOutputHatch = OutputHatch + .withCount(GregtechMetaTileEntity_Adv_DistillationTower::getCurrentLayerOutputHatchCount) + .withAdder(GregtechMetaTileEntity_Adv_DistillationTower::addLayerOutputHatch); + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Adv_DistillationTower>builder() + .addShape(STRUCTURE_PIECE_BASE, transpose(new String[][] { { "b~b", "bbb", "bbb" }, })) + .addShape(STRUCTURE_PIECE_LAYER, transpose(new String[][] { { "lll", "lcl", "lll" }, })) + .addShape(STRUCTURE_PIECE_LAYER_HINT, transpose(new String[][] { { "lll", "l-l", "lll" }, })) + .addShape(STRUCTURE_PIECE_TOP_HINT, transpose(new String[][] { { "ttt", "ttt", "ttt" }, })) + .addElement( + 'b', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_Adv_DistillationTower.class) + .atLeast(Energy, OutputBus, InputHatch, InputBus, Maintenance) + .disallowOnly(ForgeDirection.UP) + .casingIndex(getCasingTextureId()) + .dot(1) + .build(), + ofBlock(GregTech_API.sBlockCasings4, 1))) + .addElement( + 'l', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_Adv_DistillationTower.class) + .atLeast(layeredOutputHatch, Energy, Maintenance) + .disallowOnly(ForgeDirection.UP, ForgeDirection.DOWN) + .casingIndex(getCasingTextureId()) + .dot(2) + .build(), + ofHatchAdder( + GregtechMetaTileEntity_Adv_DistillationTower::addMufflerToMachineList, + getCasingTextureId(), + 3), + ofBlock(GregTech_API.sBlockCasings4, 1))) + .addElement( + 'c', + ofChain( + onElementPass( + GregtechMetaTileEntity_Adv_DistillationTower::onTopLayerFound, + ofHatchAdder( + GregtechMetaTileEntity_Adv_DistillationTower::addMufflerToMachineList, + getCasingTextureId(), + 3)), + onElementPass( + GregtechMetaTileEntity_Adv_DistillationTower::onTopLayerFound, + ofHatchAdder( + GregtechMetaTileEntity_Adv_DistillationTower::addOutputToMachineList, + getCasingTextureId(), + 3)), + onElementPass( + GregtechMetaTileEntity_Adv_DistillationTower::onTopLayerFound, + ofHatchAdder( + GregtechMetaTileEntity_Adv_DistillationTower::addMaintenanceToMachineList, + getCasingTextureId(), + 3)), + onElementPass( + GregtechMetaTileEntity_Adv_DistillationTower::onTopLayerFound, + ofBlock(GregTech_API.sBlockCasings4, 1)), + isAir())) + .addElement( + 't', + buildHatchAdder(GregtechMetaTileEntity_Adv_DistillationTower.class) + .atLeast(layeredOutputHatch, Muffler) + .disallowOnly(ForgeDirection.DOWN) + .casingIndex(getCasingTextureId()) + .dot(2) + .buildAndChain(GregTech_API.sBlockCasings4, 1)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + protected int getCurrentLayerOutputHatchCount() { + return mOutputHatchesByLayer.size() < mHeight || mHeight <= 0 ? 0 + : mOutputHatchesByLayer.get(mHeight - 1) + .size(); + } + + protected boolean addLayerOutputHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null || aTileEntity.isDead() + || !(aTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_Hatch_Output tHatch)) return false; + while (mOutputHatchesByLayer.size() < mHeight) mOutputHatchesByLayer.add(new ArrayList<>()); + tHatch.updateTexture(aBaseCasingIndex); + return mOutputHatchesByLayer.get(mHeight - 1) + .add(tHatch) && mOutputHatches.add(tHatch); + } + + protected void onTopLayerFound() { + mTopLayerFound = true; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Advanced Distillation Tower") + .addInfo("Use 85% less energy in distillery mode") + .addInfo("250%/100% faster in DT/distillery mode") + .addInfo("Right click the controller with screwdriver to change mode.") + .addInfo("Max parallel dictated by tower tier and mode") + .addInfo("DTower Mode: T1=4, T2=12") + .addInfo("Distilery Mode: Tower Tier * (4*InputTier)") + .addInfo("Distilery Mode require a full height tower") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .addCasingInfoMin("Clean Stainless Steel Machine Casing", 7, false) + .addInputBus("Bottom Casing", 1) + .addOutputBus("Bottom Casing", 1) + .addInputHatch("Bottom Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addOutputHatch("One per layer except bottom", 2) + .addMufflerHatch("Top Casing", 3) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(STRUCTURE_PIECE_BASE, stackSize, hintsOnly, 1, 0, 0); + int tTotalHeight = Math.min(12, stackSize.stackSize + 2); // min 2 output layer, so at least 1 + 2 height + for (int i = 1; i < tTotalHeight - 1; i++) { + buildPiece(STRUCTURE_PIECE_LAYER_HINT, stackSize, hintsOnly, 1, i, 0); + } + buildPiece(STRUCTURE_PIECE_TOP_HINT, stackSize, hintsOnly, 1, tTotalHeight - 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + mHeight = 0; + int built = survivialBuildPiece(STRUCTURE_PIECE_BASE, stackSize, 1, 0, 0, elementBudget, env, false, true); + if (built >= 0) return built; + int tTotalHeight = Math.min(12, stackSize.stackSize + 2); // min 2 output layer, so at least 1 + 2 height + for (int i = 1; i < tTotalHeight - 1; i++) { + mHeight = i; + built = survivialBuildPiece( + STRUCTURE_PIECE_LAYER_HINT, + stackSize, + 1, + i, + 0, + elementBudget, + env, + false, + true); + if (built >= 0) return built; + } + mHeight = tTotalHeight - 1; + return survivialBuildPiece( + STRUCTURE_PIECE_TOP_HINT, + stackSize, + 1, + tTotalHeight - 1, + 0, + elementBudget, + env, + false, + true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + // reset + mOutputHatchesByLayer.forEach(List::clear); + mHeight = 1; + mTopLayerFound = false; + + // check base + if (!checkPiece(STRUCTURE_PIECE_BASE, 1, 0, 0)) return false; + + // check each layer + while (mHeight < 12) { + if (!checkPiece(STRUCTURE_PIECE_LAYER, 1, mHeight, 0)) { + return false; + } + if (mOutputHatchesByLayer.size() < mHeight || mOutputHatchesByLayer.get(mHeight - 1) + .isEmpty()) + // layer without output hatch + return false; + if (mTopLayerFound || !mMufflerHatches.isEmpty()) { + break; + } + // not top + mHeight++; + } + boolean check = mTopLayerFound && mHeight >= 2 && checkHatch(); + if (check && mHeight < 11) { + // force the mode to DT if not in full height + mMode = Mode.DistillationTower; + mLastRecipe = null; + } + return check; + } + + @Override + public RecipeMap<?> getRecipeMap() { + return mMode.getRecipeMap(); + } + + @Nonnull + @Override + public Collection<RecipeMap<?>> getAvailableRecipeMaps() { + return Arrays.asList(RecipeMaps.distilleryRecipes, RecipeMaps.distillationTowerRecipes); + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + // don't rotate a freaking tower, it won't work + return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + if (this.mMode == Mode.Distillery) + return CORE.ConfigSwitches.pollutionPerSecondMultiAdvDistillationTower_ModeDistillery; + return CORE.ConfigSwitches.pollutionPerSecondMultiAdvDistillationTower_ModeDT; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setByte("mMode", (byte) mMode.ordinal()); + aNBT.setBoolean("mUpgraded", mUpgraded); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + mMode = Mode.values()[aNBT.getByte("mMode")]; + mUpgraded = aNBT.getBoolean("mUpgraded"); + super.loadNBTData(aNBT); + } + + @Override + public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (mHeight < 11) { + PlayerUtils.messagePlayer(aPlayer, "Cannot switch mode if not in full height."); + return; + } + mMode = mMode.next(); + PlayerUtils.messagePlayer(aPlayer, "Now running in " + mMode + " Mode."); + mLastRecipe = null; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public boolean addOutput(FluidStack aLiquid) { + if (aLiquid == null) return false; + FluidStack copiedFluidStack = aLiquid.copy(); + for (List<GT_MetaTileEntity_Hatch_Output> hatches : mOutputHatchesByLayer) { + if (dumpFluid(hatches, copiedFluidStack, true)) return true; + } + for (List<GT_MetaTileEntity_Hatch_Output> hatches : mOutputHatchesByLayer) { + if (dumpFluid(hatches, copiedFluidStack, false)) return true; + } + return false; + } + + @Override + protected void addFluidOutputs(FluidStack[] mOutputFluids2) { + if (mMode == Mode.DistillationTower) { + // dt mode + for (int i = 0; i < mOutputFluids2.length && i < mOutputHatchesByLayer.size(); i++) { + FluidStack tStack = mOutputFluids2[i].copy(); + if (!dumpFluid(mOutputHatchesByLayer.get(i), tStack, true)) + dumpFluid(mOutputHatchesByLayer.get(i), tStack, false); + } + } else { + // distillery mode + for (FluidStack outputFluidStack : mOutputFluids2) { + addOutput(outputFluidStack); + } + } + } + + @Override + public List<? extends IFluidStore> getFluidOutputSlots(FluidStack[] toOutput) { + return getFluidOutputSlotsByLayer(toOutput, mOutputHatchesByLayer); + } + + @Override + public String getMachineType() { + return "Distillery, Distillation Tower"; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + protected void setupProcessingLogic(ProcessingLogic logic) { + super.setupProcessingLogic(logic); + logic.setEuModifier(mMode == Mode.Distillery ? 0.15F : 1F); + logic.setSpeedBonus(mMode == Mode.Distillery ? 1F / 2F : 1F / 3.5F); + } + + @Override + public int getMaxParallelRecipes() { + return switch (mMode) { + case DistillationTower -> getTierOfTower() == 1 ? 4 : getTierOfTower() == 2 ? 12 : 0; + case Distillery -> getTierOfTower() * (4 * GT_Utility.getTier(this.getMaxInputVoltage())); + default -> 0; + }; + } + + private int getTierOfTower() { + return mUpgraded ? 2 : 1; + } + + @Override + protected IIconContainer getActiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER_ACTIVE; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_DISTILLATION_TOWER; + } + + @Override + protected int getCasingTextureId() { + return 49; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (aTick % 20 == 0 && !mUpgraded) { + ItemStack aGuiStack = this.getControllerSlot(); + if (aGuiStack != null) { + if (GT_Utility.areStacksEqual(aGuiStack, GregtechItemList.Distillus_Upgrade_Chip.get(1))) { + this.mUpgraded = true; + mInventory[1] = ItemUtils.depleteStack(aGuiStack); + } + } + } + } + + @Override + public boolean canDumpFluidToME() { + // All fluids can be dumped to ME only if each layer contains a ME Output Hatch. + return this.mOutputHatchesByLayer.stream() + .allMatch( + tLayerOutputHatches -> tLayerOutputHatches.stream() + .anyMatch(tHatch -> tHatch instanceof GT_MetaTileEntity_Hatch_Output_ME)); + } + + @Override + public void setItemNBT(NBTTagCompound aNBT) { + aNBT.setBoolean("mUpgraded", mUpgraded); + super.setItemNBT(aNBT); + } + + @Override + public void addAdditionalTooltipInformation(ItemStack stack, List<String> tooltip) { + super.addAdditionalTooltipInformation(stack, tooltip); + NBTTagCompound aNBT = stack.getTagCompound(); + if (aNBT != null && aNBT.hasKey("mUpgraded")) { + tooltip.add(StatCollector.translateToLocal("tooltip.large_distill_tower.upgraded")); + } + } + + private enum Mode { + + DistillationTower(RecipeMaps.distillationTowerRecipes), + Distillery(RecipeMaps.distilleryRecipes),; + + static final Mode[] VALUES = values(); + private final RecipeMap<?> recipeMap; + + Mode(RecipeMap<?> recipeMap) { + this.recipeMap = recipeMap; + } + + public RecipeMap<?> getRecipeMap() { + return recipeMap; + } + + public Mode next() { + return VALUES[(ordinal() + 1) % VALUES.length]; + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java new file mode 100644 index 0000000000..89c219c14e --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_EBF.java @@ -0,0 +1,333 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.advanced; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_StructureUtility.ofCoil; +import static gregtech.api.util.GT_Utility.filterValidMTEs; + +import java.util.ArrayList; +import java.util.Objects; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; +import net.minecraftforge.common.util.ForgeDirection; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.HeatingCoilLevel; +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_OverclockCalculator; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.shutdown.ShutDownReasonRegistry; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GT_MetaTileEntity_Hatch_CustomFluidBase; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_Adv_EBF extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Adv_EBF> + implements ISurvivalConstructable { + + public static int CASING_TEXTURE_ID; + public static String mHotFuelName = "Blazing Pyrotheum"; + public static String mCasingName = "Volcanus Casing"; + public static String mHatchName = "Pyrotheum Hatch"; + private static IStructureDefinition<GregtechMetaTileEntity_Adv_EBF> STRUCTURE_DEFINITION = null; + private int mCasing; + private final ArrayList<GT_MetaTileEntity_Hatch_CustomFluidBase> mPyrotheumHatches = new ArrayList<>(); + + private HeatingCoilLevel mHeatingCapacity = HeatingCoilLevel.None; + + public GregtechMetaTileEntity_Adv_EBF(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 11); + } + + public GregtechMetaTileEntity_Adv_EBF(String aName) { + super(aName); + CASING_TEXTURE_ID = TAE.getIndexFromPage(2, 11); + } + + @Override + public String getMachineType() { + return "Blast Furnace"; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Adv_EBF(this.mName); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Factory Grade Advanced Blast Furnace") + .addInfo("Speed: +120% | EU Usage: 90% | Parallel: 8") + .addInfo("Consumes 10L of " + mHotFuelName + " per second during operation") + .addInfo("Constructed exactly the same as a normal EBF") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .addController("Bottom center") + .addCasingInfoMin(mCasingName, 8, false) + .addInputHatch("Any Casing", 1) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addOtherStructurePart(mHatchName, "Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public String[] getExtraInfoData() { + return new String[] { StatCollector.translateToLocal("GT5U.EBF.heat") + ": " + + EnumChatFormatting.GREEN + + GT_Utility.formatNumbers(mHeatingCapacity.getHeat()) + + EnumChatFormatting.RESET + + " K" }; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_Adv_EBF> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Adv_EBF>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "HHH", "H-H", "HHH" }, { "HHH", "H-H", "HHH" }, + { "C~C", "CCC", "CCC" }, })) + .addElement( + 'C', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_Adv_EBF.class) + .adder(GregtechMetaTileEntity_Adv_EBF::addPyrotheumHatch) + .hatchId(968) + .shouldReject(x -> !x.mPyrotheumHatches.isEmpty()) + .casingIndex(CASING_TEXTURE_ID) + .dot(1) + .build(), + buildHatchAdder(GregtechMetaTileEntity_Adv_EBF.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) + .casingIndex(CASING_TEXTURE_ID) + .dot(1) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings3Misc, 11)))) + .addElement( + 'H', + ofCoil(GregtechMetaTileEntity_Adv_EBF::setCoilLevel, GregtechMetaTileEntity_Adv_EBF::getCoilLevel)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 3, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 3, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mPyrotheumHatches.clear(); + setCoilLevel(HeatingCoilLevel.None); + return checkPiece(mName, 1, 3, 0) && mCasing >= 8 && getCoilLevel() != HeatingCoilLevel.None && checkHatch(); + } + + @Override + public boolean checkHatch() { + return super.checkHatch() && !mPyrotheumHatches.isEmpty(); + } + + private boolean addPyrotheumHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_CustomFluidBase + && aMetaTileEntity.getBaseMetaTileEntity() + .getMetaTileID() == 968) { + return addToMachineListInternal(mPyrotheumHatches, aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public void updateSlots() { + for (GT_MetaTileEntity_Hatch_CustomFluidBase tHatch : filterValidMTEs(mPyrotheumHatches)) tHatch.updateSlots(); + super.updateSlots(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return CASING_TEXTURE_ID; + } + + @Override + public RecipeMap<?> getRecipeMap() { + return RecipeMaps.blastFurnaceRecipes; + } + + @Override + public int getRecipeCatalystPriority() { + return -1; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic() { + + @NotNull + @Override + protected CheckRecipeResult validateRecipe(@NotNull GT_Recipe recipe) { + return recipe.mSpecialValue <= getCoilLevel().getHeat() ? CheckRecipeResultRegistry.SUCCESSFUL + : CheckRecipeResultRegistry.insufficientHeat(recipe.mSpecialValue); + } + + @NotNull + @Override + protected GT_OverclockCalculator createOverclockCalculator(@NotNull GT_Recipe recipe) { + return super.createOverclockCalculator(recipe).setHeatOC(true) + .setHeatDiscount(true) + .setRecipeHeat(recipe.mSpecialValue) + .setMachineHeat((int) getCoilLevel().getHeat()); + } + }.setSpeedBonus(1F / 2.2F) + .setEuModifier(0.9F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiAdvEBF; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + private int mGraceTimer = 2; + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + // Try dry Pyrotheum after all other logic + if (this.mStartUpCheck < 0) { + if (this.mMaxProgresstime > 0 && this.mProgresstime != 0 || this.getBaseMetaTileEntity() + .hasWorkJustBeenEnabled()) { + if (aTick % 10 == 0 || this.getBaseMetaTileEntity() + .hasWorkJustBeenEnabled()) { + if (!this.depleteInputFromRestrictedHatches(this.mPyrotheumHatches, 5)) { + if (mGraceTimer-- == 0) { + this.causeMaintenanceIssue(); + this.stopMachine( + ShutDownReasonRegistry + .outOfFluid(Objects.requireNonNull(FluidUtils.getFluidStack("pyrotheum", 10)))); + mGraceTimer = 2; + } + } + } + } + } + } + + @Override + public int getMaxParallelRecipes() { + return 8; + } + + @Override + public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + inputSeparation = !inputSeparation; + aPlayer.addChatMessage( + new ChatComponentTranslation( + inputSeparation ? "interaction.separateBusses.enabled" : "interaction.separateBusses.disabled")); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + if (!aNBT.hasKey(INPUT_SEPARATION_NBT_KEY)) { + inputSeparation = aNBT.getBoolean("isBussesSeparate"); + } + } + + public HeatingCoilLevel getCoilLevel() { + return mHeatingCapacity; + } + + public void setCoilLevel(HeatingCoilLevel aCoilLevel) { + mHeatingCapacity = aCoilLevel; + } + + @Override + public boolean supportsInputSeparation() { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Fusion_MK4.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Fusion_MK4.java new file mode 100644 index 0000000000..0981a34b85 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Fusion_MK4.java @@ -0,0 +1,200 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.advanced; + +import java.lang.reflect.Method; + +import net.minecraft.block.Block; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.enums.Dyes; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.objects.overclockdescriber.OverclockDescriber; +import gregtech.api.render.TextureFactory; +import gregtech.api.util.AdvancedFusionOverclockDescriber; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_FusionComputer; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_Adv_Fusion_MK4 extends GT_MetaTileEntity_FusionComputer { + + public static final Method mUpdateHatchTexture; + + static { + mUpdateHatchTexture = ReflectionUtils.getMethod(GT_MetaTileEntity_Hatch.class, "updateTexture", int.class); + } + + public GregtechMetaTileEntity_Adv_Fusion_MK4(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_Adv_Fusion_MK4(String aName) { + super(aName); + } + + @Override + protected OverclockDescriber createOverclockDescriber() { + return new AdvancedFusionOverclockDescriber((byte) tier(), capableStartupCanonical()); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType("Fusion Reactor") + .addInfo("HARNESSING THE POWER OF A BLUE GIANT") + .addInfo("Controller block for the Fusion Reactor Mk IV") + .addInfo("131072EU/t and 320M EU capacity per Energy Hatch") + .addInfo("If the recipe has a startup cost greater than the") + .addInfo("number of energy hatches * cap, you can't do it") + .addInfo("Performs 4/4 overclocks") + .addSeparator() + .beginStructureBlock(15, 3, 15, false) + .addController("See diagram when placed") + .addCasingInfoMin("Fusion Machine Casings MK III", 79, false) + .addStructureInfo("Cover the coils with casing") + .addOtherStructurePart("Advanced Fusion Coils", "Center part of the ring") + .addEnergyHatch("1-16, Specified casings", 2) + .addInputHatch("2-16, Specified casings", 1) + .addOutputHatch("1-16, Specified casings", 3) + .addStructureInfo("ALL Hatches must be UHV or better") + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public int tier() { + return 9; + } + + @Override + public long maxEUStore() { + return (640010000L * 4) * (Math.min(16, this.mEnergyHatches.size())) / 8L; + } + + @Override + public long capableStartupCanonical() { + return 5_120_000_000L; + } + + @Override + public int getRecipeCatalystPriority() { + return -1; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Adv_Fusion_MK4(mName); + } + + @Override + public Block getCasing() { + return getFusionCoil(); + } + + @Override + public int getCasingMeta() { + return 12; + } + + @Override + public Block getFusionCoil() { + return ModBlocks.blockCasings3Misc; + } + + @Override + public int getFusionCoilMeta() { + return 13; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return super.createProcessingLogic().setOverclock(2, 2); + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + if (side == facing) { + return new ITexture[] { + new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS, + Dyes.getModulation(-1, Dyes._NULL.mRGBa)), + TextureFactory.builder() + .addIcon(this.getIconOverlay()) + .extFacing() + .build() }; + } else if (!aActive) { + return new ITexture[] { new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS, + Dyes.getModulation(-1, Dyes._NULL.mRGBa)) }; + } else { + return new ITexture[] { new GT_RenderedTexture( + TexturesGtBlock.TEXTURE_CASING_FUSION_CASING_ULTRA, + Dyes.getModulation(-1, Dyes._NULL.mRGBa)) }; + } + } + + @Override + public ITexture getTextureOverlay() { + return new GT_RenderedTexture( + this.getBaseMetaTileEntity() + .isActive() ? TexturesGtBlock.Casing_Machine_Screen_3 : TexturesGtBlock.Casing_Machine_Screen_1); + } + + public IIconContainer getIconOverlay() { + return this.getBaseMetaTileEntity() + .isActive() ? TexturesGtBlock.Casing_Machine_Screen_3 : TexturesGtBlock.Casing_Machine_Screen_1; + } + + @Override + public boolean turnCasingActive(final boolean status) { + try { + if (this.mEnergyHatches != null) { + for (final GT_MetaTileEntity_Hatch_Energy hatch : this.mEnergyHatches) { + mUpdateHatchTexture.invoke(hatch, (status ? TAE.getIndexFromPage(2, 14) : 53)); + } + } + if (this.mOutputHatches != null) { + for (final GT_MetaTileEntity_Hatch_Output hatch2 : this.mOutputHatches) { + mUpdateHatchTexture.invoke(hatch2, (status ? TAE.getIndexFromPage(2, 14) : 53)); + } + } + if (this.mInputHatches != null) { + for (final GT_MetaTileEntity_Hatch_Input hatch3 : this.mInputHatches) { + mUpdateHatchTexture.invoke(hatch3, (status ? TAE.getIndexFromPage(2, 14) : 53)); + } + } + } catch (Throwable t) { + return false; + } + return true; + } + + @Override + public String[] getInfoData() { + String tier = "IV"; + float plasmaOut = 0; + int powerRequired = 0; + if (this.mLastRecipe != null) { + powerRequired = this.mLastRecipe.mEUt; + if (this.mLastRecipe.getFluidOutput(0) != null) { + plasmaOut = (float) this.mLastRecipe.getFluidOutput(0).amount / (float) this.mLastRecipe.mDuration; + } + } + + return new String[] { "Fusion Reactor MK " + tier, "EU Required: " + powerRequired + "EU/t", + "Stored EU: " + mEUStore + " / " + maxEUStore(), "Plasma Output: " + plasmaOut + "L/t" }; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Fusion_MK5.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Fusion_MK5.java new file mode 100644 index 0000000000..b2c2e5eb27 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Fusion_MK5.java @@ -0,0 +1,200 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.advanced; + +import java.lang.reflect.Method; + +import net.minecraft.block.Block; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.enums.Dyes; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.objects.overclockdescriber.OverclockDescriber; +import gregtech.api.render.TextureFactory; +import gregtech.api.util.AdvancedFusionOverclockDescriber; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.common.tileentities.machines.multi.GT_MetaTileEntity_FusionComputer; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_Adv_Fusion_MK5 extends GT_MetaTileEntity_FusionComputer { + + public static final Method mUpdateHatchTexture; + + static { + mUpdateHatchTexture = ReflectionUtils.getMethod(GT_MetaTileEntity_Hatch.class, "updateTexture", int.class); + } + + public GregtechMetaTileEntity_Adv_Fusion_MK5(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_Adv_Fusion_MK5(String aName) { + super(aName); + } + + @Override + protected OverclockDescriber createOverclockDescriber() { + return new AdvancedFusionOverclockDescriber((byte) tier(), capableStartupCanonical()); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType("Fusion Reactor") + .addInfo("HARNESSING THE POWER OF A NEUTRON STAR") + .addInfo("Controller block for the Fusion Reactor Mk V") + .addInfo("524,288EU/t and 1.28B EU capacity per Energy Hatch") + .addInfo("If the recipe has a startup cost greater than the") + .addInfo("number of energy hatches * cap, you can't do it") + .addInfo("Performs 4/4 overclocks") + .addSeparator() + .beginStructureBlock(15, 3, 15, false) + .addController("See diagram when placed") + .addCasingInfoMin("Fusion Machine Casings MK IV", 79, false) + .addStructureInfo("Cover the coils with casing") + .addOtherStructurePart("Advanced Fusion Coils II", "Center part of the ring") + .addEnergyHatch("1-16, Specified casings", 2) + .addInputHatch("2-16, Specified casings", 1) + .addOutputHatch("1-16, Specified casings", 3) + .addStructureInfo("ALL Hatches must be UEV or better") + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public int tier() { + return 10; + } + + @Override + public long maxEUStore() { + return (640010000L * 16) * (Math.min(16, this.mEnergyHatches.size())) / 8L; + } + + @Override + public long capableStartupCanonical() { + return 20_480_000_000L; + } + + @Override + public int getRecipeCatalystPriority() { + return -1; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Adv_Fusion_MK5(mName); + } + + @Override + public Block getCasing() { + return getFusionCoil(); + } + + @Override + public int getCasingMeta() { + return 0; + } + + @Override + public Block getFusionCoil() { + return ModBlocks.blockCasings6Misc; + } + + @Override + public int getFusionCoilMeta() { + return 1; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return super.createProcessingLogic().setOverclock(2, 2); + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + if (side == facing) { + return new ITexture[] { + new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS, + Dyes.getModulation(-1, Dyes._NULL.mRGBa)), + TextureFactory.builder() + .addIcon(this.getIconOverlay()) + .extFacing() + .build() }; + } else if (!aActive) { + return new ITexture[] { new GT_RenderedTexture( + Textures.BlockIcons.MACHINE_CASING_FUSION_GLASS, + Dyes.getModulation(-1, Dyes._NULL.mRGBa)) }; + } else { + return new ITexture[] { new GT_RenderedTexture( + TexturesGtBlock.TEXTURE_CASING_FUSION_CASING_HYPER, + Dyes.getModulation(-1, Dyes._NULL.mRGBa)) }; + } + } + + @Override + public ITexture getTextureOverlay() { + return new GT_RenderedTexture( + this.getBaseMetaTileEntity() + .isActive() ? TexturesGtBlock.Casing_Machine_Screen_Rainbow : TexturesGtBlock.Casing_Machine_Screen_1); + } + + public IIconContainer getIconOverlay() { + return this.getBaseMetaTileEntity() + .isActive() ? TexturesGtBlock.Casing_Machine_Screen_Rainbow : TexturesGtBlock.Casing_Machine_Screen_1; + } + + @Override + public boolean turnCasingActive(final boolean status) { + try { + if (this.mEnergyHatches != null) { + for (final GT_MetaTileEntity_Hatch_Energy hatch : this.mEnergyHatches) { + mUpdateHatchTexture.invoke(hatch, (status ? TAE.getIndexFromPage(3, 6) : 53)); + } + } + if (this.mOutputHatches != null) { + for (final GT_MetaTileEntity_Hatch_Output hatch2 : this.mOutputHatches) { + mUpdateHatchTexture.invoke(hatch2, (status ? TAE.getIndexFromPage(3, 6) : 53)); + } + } + if (this.mInputHatches != null) { + for (final GT_MetaTileEntity_Hatch_Input hatch3 : this.mInputHatches) { + mUpdateHatchTexture.invoke(hatch3, (status ? TAE.getIndexFromPage(3, 6) : 53)); + } + } + } catch (Throwable t) { + return false; + } + return true; + } + + @Override + public String[] getInfoData() { + String tier = "V"; + float plasmaOut = 0; + int powerRequired = 0; + if (this.mLastRecipe != null) { + powerRequired = this.mLastRecipe.mEUt; + if (this.mLastRecipe.getFluidOutput(0) != null) { + plasmaOut = (float) this.mLastRecipe.getFluidOutput(0).amount / (float) this.mLastRecipe.mDuration; + } + } + + return new String[] { "Fusion Reactor MK " + tier, "EU Required: " + powerRequired + "EU/t", + "Stored EU: " + mEUStore + " / " + maxEUStore(), "Plasma Output: " + plasmaOut + "L/t" }; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_HeatExchanger.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_HeatExchanger.java new file mode 100644 index 0000000000..e4340c4d28 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_HeatExchanger.java @@ -0,0 +1,414 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.advanced; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdder; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.util.GT_Log; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.block.base.BasicBlock.BlockTypes; +import gtPlusPlus.core.block.base.BlockBaseModular; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.ALLOY; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_Adv_HeatExchanger + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Adv_HeatExchanger> { + + private static final int CASING_INDEX = TAE.getIndexFromPage(1, 12); + private static final String STRUCTURE_PIECE_MAIN = "main"; + + private static final IStructureDefinition<GregtechMetaTileEntity_Adv_HeatExchanger> STRUCTURE_DEFINITION = StructureDefinition + .<GregtechMetaTileEntity_Adv_HeatExchanger>builder() + .addShape( + STRUCTURE_PIECE_MAIN, + transpose( + new String[][] { { " ccc ", "cCCCc", "cCCCc", "cCCCc", " ccc " }, + { " ccc ", "cPPPc", "cPPPc", "cPPPc", " ccc " }, { " ccc ", "cPPPc", "cPPPc", "cPPPc", " ccc " }, + { " ccc ", "cPPPc", "cPPPc", "cPPPc", " ccc " }, { " ccc ", "cPPPc", "cPPPc", "cPPPc", " ccc " }, + { " c~c ", "cPPPc", "cPPPc", "cPPPc", " ccc " }, { " hhh ", "hHHHh", "hHHHh", "hHHHh", " hhh " }, + { " f f ", "f f", " ", "f f", " f f " }, + { " f f ", "f f", " ", "f f", " f f " }, })) + .addElement('P', ofBlock(GregTech_API.sBlockCasings2, 15)) + .addElement('f', ofBlock(getFrame(), 0)) + .addElement( + 'C', + ofChain( + ofHatchAdder( + GregtechMetaTileEntity_Adv_HeatExchanger::addColdFluidOutputToMachineList, + CASING_INDEX, + 2), + onElementPass( + GregtechMetaTileEntity_Adv_HeatExchanger::onCasingAdded, + ofBlock(ModBlocks.blockSpecialMultiCasings, 14)))) + .addElement( + 'H', + ofChain( + ofHatchAdder(GregtechMetaTileEntity_Adv_HeatExchanger::addHotFluidInputToMachineList, CASING_INDEX, 3), + onElementPass( + GregtechMetaTileEntity_Adv_HeatExchanger::onCasingAdded, + ofBlock(ModBlocks.blockSpecialMultiCasings, 14)))) + .addElement( + 'h', + ofChain( + ofHatchAdder(GregtechMetaTileEntity_Adv_HeatExchanger::addInputToMachineList, CASING_INDEX, 1), + ofHatchAdder(GregtechMetaTileEntity_Adv_HeatExchanger::addOutputToMachineList, CASING_INDEX, 1), + ofHatchAdder(GregtechMetaTileEntity_Adv_HeatExchanger::addMaintenanceToMachineList, CASING_INDEX, 1), + onElementPass( + GregtechMetaTileEntity_Adv_HeatExchanger::onCasingAdded, + ofBlock(ModBlocks.blockSpecialMultiCasings, 14)))) + .addElement( + 'c', + ofChain( + onElementPass( + GregtechMetaTileEntity_Adv_HeatExchanger::onCasingAdded, + ofBlock(ModBlocks.blockSpecialMultiCasings, 14)))) + .build(); + public static float penalty_per_config = 0.015f; // penalize 1.5% efficiency per circuitry level (1-25) + + private GT_MetaTileEntity_Hatch_Input mInputHotFluidHatch; + private GT_MetaTileEntity_Hatch_Output mOutputColdFluidHatch; + private boolean superheated = false; + private int superheated_threshold = 0; + private float water; + private int mCasingAmount; + + public GregtechMetaTileEntity_Adv_HeatExchanger(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_Adv_HeatExchanger(String aName) { + super(aName); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + final GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the XL Heat Exchanger") + .addInfo("More complicated than a Fusion Reactor. Seriously") + .addInfo("But you know this by now, right?") + .addInfo("Works as fast as 32 Large Heat Exchangers") + .addSeparator() + .addInfo("Inputs are Hot Coolant or Lava") + .addInfo("Outputs Coolant or Pahoehoe Lava and SH Steam/Steam") + .addInfo("Outputs SH Steam if input flow is equal to or above a certain value:") + .addInfo("Hot Coolant: 25,600 L/s, maximum 51,200 L/s, max output 10,240,000 SH Steam/s") + .addInfo("Lava: 32,000 L/s, maximum 64,000 L/s, max output 5,120,000 SH Steam/s") + .addInfo("A circuit in the controller lowers the SH Steam threshold and efficiency") + .addInfo("3.75% reduction and 1.5% efficiency loss per circuit config over 1") + .addSeparator() + .beginStructureBlock(5, 9, 5, false) + .addController("Front bottom") + .addCasingInfoMin("Reinforced Heat Exchanger Casing", 90, false) + .addOtherStructurePart("Tungstensteel Pipe Casing", "Center 3x5x3 (45 blocks)") + .addMaintenanceHatch("Any casing", 1) + .addInputHatch("Hot fluid, bottom center", 2) + .addInputHatch("Distilled water, any bottom layer casing", 1) + .addOutputHatch("Cold fluid, top center", 3) + .addOutputHatch("Steam/SH Steam, any bottom layer casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + superheated = aNBT.getBoolean("superheated"); + super.loadNBTData(aNBT); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("superheated", superheated); + super.saveNBTData(aNBT); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return CASING_INDEX; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + return (d, r, f) -> !r.isUpsideDown() && !f.isVerticallyFliped(); + } + + @Override + public @NotNull CheckRecipeResult checkProcessing() { + if (mInputHotFluidHatch.getFluid() == null) return CheckRecipeResultRegistry.SUCCESSFUL; + + int fluidAmountToConsume = mInputHotFluidHatch.getFluidAmount(); // how much fluid is in hatch + + // The XL LHE works as fast as 32 regular LHEs. These are the comments from the original LHE, + // with changes where the values needed to change for the 32x speed multiplier + superheated_threshold = 128000; // default: must have 4000L -> 128000L per second to generate superheated steam + float efficiency = 1f; // default: operate at 100% efficiency with no integrated circuitry + int shs_reduction_per_config = 4800; // reduce threshold 150L -> 4800L per second per circuitry level (1-25) + float steam_output_multiplier = 20f; // default: multiply output by 4 * 10 (boosted x5) + float penalty = 0.0f; // penalty to apply to output based on circuitry level (1-25). + boolean do_lava = false; + + // Do we have an integrated circuit with a valid configuration? + if (mInventory[1] != null && mInventory[1].getUnlocalizedName() + .startsWith("gt.integrated_circuit")) { + int circuit_config = mInventory[1].getItemDamage(); + if (circuit_config >= 1 && circuit_config <= 25) { + // If so, apply the penalty and reduced threshold. + penalty = (circuit_config - 1) * penalty_per_config; + superheated_threshold -= (shs_reduction_per_config * (circuit_config - 1)); + } + } + efficiency -= penalty; + + // If we're working with lava, adjust the threshold and multipliers accordingly. + if (GT_ModHandler.isLava(mInputHotFluidHatch.getFluid())) { + steam_output_multiplier /= 5f; // lava is not boosted + superheated_threshold /= 4f; // unchanged + do_lava = true; + } else if (mInputHotFluidHatch.getFluid() + .isFluidEqual(FluidRegistry.getFluidStack("ic2hotcoolant", 1))) { + steam_output_multiplier /= 2f; // was boosted x2 on top of x5 -> total x10 -> nerf with this code back + // to 5x + superheated_threshold /= 5f; // 10x smaller since the Hot Things production in reactor is the same. + } else { + // If we're working with neither, fail out + superheated_threshold = 0; + return CheckRecipeResultRegistry.NO_RECIPE; + } + + superheated = fluidAmountToConsume >= superheated_threshold; // set the internal superheated flag if we have + // enough hot fluid. Used in the + // onRunningTick method. + fluidAmountToConsume = Math.min(fluidAmountToConsume, superheated_threshold * 2); // Don't consume too much hot + // fluid per second, maximum + // is 2x SH threshold. + mInputHotFluidHatch.drain(fluidAmountToConsume, true); + this.mMaxProgresstime = 20; + this.lEUt = (long) (fluidAmountToConsume * steam_output_multiplier * efficiency); + if (do_lava) { + mOutputColdFluidHatch.fill(FluidRegistry.getFluidStack("ic2pahoehoelava", fluidAmountToConsume), true); + } else { + mOutputColdFluidHatch.fill(FluidRegistry.getFluidStack("ic2coolant", fluidAmountToConsume), true); + } + this.mEfficiencyIncrease = 80; + return CheckRecipeResultRegistry.SUCCESSFUL; + } + + private int useWater(float input) { + water = water + input; + int usage = (int) water; + water = water - usage; + return usage; + } + + @Override + public boolean onRunningTick(ItemStack aStack) { + if (this.lEUt > 0) { + int tGeneratedEU = (int) (this.lEUt * 2L * this.mEfficiency / 10000L); // APPROXIMATELY how much steam to + // generate. + if (tGeneratedEU > 0) { + + if (superheated) tGeneratedEU /= 2; // We produce half as much superheated steam if necessary + + int distilledConsumed = useWater(tGeneratedEU / 160f); // how much distilled water to consume + // tGeneratedEU = distilledConsumed * 160; // EXACTLY how much steam to generate, producing a perfect + // 1:160 ratio with distilled water consumption + + FluidStack distilledStack = GT_ModHandler.getDistilledWater(distilledConsumed); + if (depleteInput(distilledStack)) // Consume the distilled water + { + if (superheated) { + addOutput(FluidRegistry.getFluidStack("ic2superheatedsteam", tGeneratedEU)); // Generate + // superheated + // steam + } else { + addOutput(GT_ModHandler.getSteam(tGeneratedEU)); // Generate regular steam + } + } else { + GT_Log.exp.println(this.mName + " had no more Distilled water!"); + explodeMultiblock(); // Generate crater + } + } + return true; + } + return true; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_Adv_HeatExchanger> getStructureDefinition() { + return STRUCTURE_DEFINITION; + } + + private void onCasingAdded() { + mCasingAmount++; + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mOutputColdFluidHatch = null; + mInputHotFluidHatch = null; + mCasingAmount = 0; + return checkPiece(STRUCTURE_PIECE_MAIN, 2, 5, 0) && mCasingAmount >= 90 && mMaintenanceHatches.size() == 1; + } + + public boolean addColdFluidOutputToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) return false; + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) return false; + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); + mOutputColdFluidHatch = (GT_MetaTileEntity_Hatch_Output) aMetaTileEntity; + return true; + } + return false; + } + + public boolean addHotFluidInputToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) return false; + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) return false; + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); + ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = getRecipeMap(); + mInputHotFluidHatch = (GT_MetaTileEntity_Hatch_Input) aMetaTileEntity; + return true; + } + return false; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Adv_HeatExchanger(this.mName); + } + + @Override + public boolean isGivingInformation() { + return super.isGivingInformation(); + } + + @Override + public String[] getExtraInfoData() { + return new String[] { + StatCollector.translateToLocal("GT5U.multiblock.Progress") + ": " + + EnumChatFormatting.GREEN + + GT_Utility.formatNumbers(mProgresstime / 20) + + EnumChatFormatting.RESET + + " s / " + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(mMaxProgresstime / 20) + + EnumChatFormatting.RESET + + " s", + StatCollector.translateToLocal("GT5U.multiblock.usage") + " " + + StatCollector.translateToLocal("GT5U.LHE.steam") + + ": " + + (superheated ? EnumChatFormatting.RED : EnumChatFormatting.YELLOW) + + GT_Utility.formatNumbers(superheated ? -2 * lEUt : -lEUt) + + EnumChatFormatting.RESET + + " EU/t", + StatCollector.translateToLocal("GT5U.multiblock.problems") + ": " + + EnumChatFormatting.RED + + (getIdealStatus() - getRepairStatus()) + + EnumChatFormatting.RESET + + " " + + StatCollector.translateToLocal("GT5U.multiblock.efficiency") + + ": " + + EnumChatFormatting.YELLOW + + mEfficiency / 100.0F + + EnumChatFormatting.RESET + + " %", + StatCollector.translateToLocal("GT5U.LHE.superheated") + ": " + + (superheated ? EnumChatFormatting.RED : EnumChatFormatting.BLUE) + + superheated + + EnumChatFormatting.RESET, + StatCollector.translateToLocal("GT5U.LHE.superheated") + " " + + StatCollector.translateToLocal("GT5U.LHE.threshold") + + ": " + + EnumChatFormatting.GREEN + + GT_Utility.formatNumbers(superheated_threshold) + + EnumChatFormatting.RESET }; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(STRUCTURE_PIECE_MAIN, stackSize, hintsOnly, 2, 5, 0); + } + + @Override + public String getMachineType() { + return "Heat Exchanger"; + } + + @Override + public int getMaxParallelRecipes() { + return 0; + } + + private static Block sFrame; + + public static Block getFrame() { + if (sFrame == null) { + sFrame = BlockBaseModular.getMaterialBlock(ALLOY.TALONITE, BlockTypes.FRAME); + } + return sFrame; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Implosion.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Implosion.java new file mode 100644 index 0000000000..432ce23e74 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/advanced/GregtechMetaTileEntity_Adv_Implosion.java @@ -0,0 +1,177 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.advanced; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.GregTech_API.sBlockCasings4; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import net.minecraft.item.ItemStack; + +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.SoundResource; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_Adv_Implosion + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Adv_Implosion> { + + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_Adv_Implosion> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_Adv_Implosion(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_Adv_Implosion(String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Adv_Implosion(this.mName); + } + + @Override + public String getMachineType() { + return "Implosion Compressor"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Factory Grade Advanced Implosion Compressor") + .addInfo("Speed: +100% | EU Usage: 100% | Parallel: ((Tier/2)+1)") + .addInfo("Constructed exactly the same as a normal Implosion Compressor") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front center") + .addCasingInfoMin("Robust TungstenSteel Casing", 10, false) + .addInputBus("Any casing", 1) + .addOutputBus("Any casing", 1) + .addEnergyHatch("Any casing", 1) + .addMaintenanceHatch("Any casing", 1) + .addMufflerHatch("Any casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_Adv_Implosion> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Adv_Implosion>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "C~C", "C-C", "CCC" }, { "CCC", "CCC", "CCC" }, })) + .addElement( + 'C', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_Adv_Implosion.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(48) + .dot(1) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(sBlockCasings4, 0)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return 48; + } + + @Override + public RecipeMap<?> getRecipeMap() { + return RecipeMaps.implosionRecipes; + } + + @Override + public int getRecipeCatalystPriority() { + return -1; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setSpeedBonus(1F / 2F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + protected SoundResource getProcessStartSound() { + return SoundResource.RANDOM_EXPLODE; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiAdvImplosion; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public int getMaxParallelRecipes() { + return (GT_Utility.getTier(this.getMaxInputVoltage()) / 2 + 1); + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamCompressor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamCompressor.java new file mode 100644 index 0000000000..0845c7f061 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamCompressor.java @@ -0,0 +1,156 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.steam; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.GregTech_API.sBlockCasings1; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import javax.annotation.Nonnull; + +import net.minecraft.item.ItemStack; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_OverclockCalculator; +import gregtech.api.util.GT_Recipe; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_SteamMultiBase; + +public class GregtechMetaTileEntity_SteamCompressor + extends GregtechMeta_SteamMultiBase<GregtechMetaTileEntity_SteamCompressor> implements ISurvivalConstructable { + + private String mCasingName = "Bronze Plated Bricks"; + private static IStructureDefinition<GregtechMetaTileEntity_SteamCompressor> STRUCTURE_DEFINITION = null; + private int mCasing; + + public GregtechMetaTileEntity_SteamCompressor(String aName) { + super(aName); + } + + public GregtechMetaTileEntity_SteamCompressor(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity arg0) { + return new GregtechMetaTileEntity_SteamCompressor(this.mName); + } + + @Override + protected GT_RenderedTexture getFrontOverlay() { + return new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_STEAM_COMPRESSOR); + } + + @Override + protected GT_RenderedTexture getFrontOverlayActive() { + return new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_STEAM_COMPRESSOR_ACTIVE); + } + + @Override + public String getMachineType() { + return "Compressor"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Steam Compressor") + .addInfo("33.3% faster than using a single block Steam Compressor.") + .addInfo("Uses only 66.6% of the steam/s compared to a single block Steam Compressor.") + .addInfo("Compresses up to " + getMaxParallelRecipes() + " things at a time") + .addSeparator() + .beginStructureBlock(3, 3, 4, true) + .addController("Front center") + .addCasingInfoMin(mCasingName, 28, false) + .addOtherStructurePart(TT_steaminputbus, "Any casing", 1) + .addOtherStructurePart(TT_steamoutputbus, "Any casing", 1) + .addOtherStructurePart(TT_steamhatch, "Any casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_SteamCompressor> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_SteamCompressor>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC", "CCC" }, { "C~C", "C-C", "C-C", "CCC" }, + { "CCC", "CCC", "CCC", "CCC" }, })) + .addElement( + 'C', + ofChain( + buildSteamInput(GregtechMetaTileEntity_SteamCompressor.class).casingIndex(10) + .dot(1) + .build(), + buildHatchAdder(GregtechMetaTileEntity_SteamCompressor.class) + .atLeast(SteamHatchElement.InputBus_Steam, SteamHatchElement.OutputBus_Steam) + .casingIndex(10) + .dot(1) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(sBlockCasings1, 10)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + fixAllMaintenanceIssue(); + return checkPiece(mName, 1, 1, 0) && mCasing >= 28; + } + + @Override + public int getMaxParallelRecipes() { + return 8; + } + + @Override + public RecipeMap<?> getRecipeMap() { + return RecipeMaps.compressorRecipes; + } + + // note that a basic steam machine has .setEUtDiscount(2F).setSpeedBoost(2F). So these are bonuses. + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic() { + + @Override + @Nonnull + protected GT_OverclockCalculator createOverclockCalculator(@NotNull GT_Recipe recipe) { + return GT_OverclockCalculator.ofNoOverclock(recipe) + .setEUtDiscount(1.33F) + .setSpeedBoost(1.5F); + } + }.setMaxParallel(getMaxParallelRecipes()); + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamMacerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamMacerator.java new file mode 100644 index 0000000000..dce362fa14 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/GregtechMetaTileEntity_SteamMacerator.java @@ -0,0 +1,165 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.steam; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.GregTech_API.sBlockCasings1; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import javax.annotation.Nonnull; + +import net.minecraft.item.ItemStack; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.ItemList; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_OverclockCalculator; +import gregtech.api.util.GT_Recipe; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_SteamMultiBase; + +public class GregtechMetaTileEntity_SteamMacerator + extends GregtechMeta_SteamMultiBase<GregtechMetaTileEntity_SteamMacerator> implements ISurvivalConstructable { + + private String mCasingName = "Bronze Plated Bricks"; + private static IStructureDefinition<GregtechMetaTileEntity_SteamMacerator> STRUCTURE_DEFINITION = null; + private int mCasing; + + public GregtechMetaTileEntity_SteamMacerator(String aName) { + super(aName); + } + + public GregtechMetaTileEntity_SteamMacerator(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity arg0) { + return new GregtechMetaTileEntity_SteamMacerator(this.mName); + } + + @Override + protected GT_RenderedTexture getFrontOverlay() { + return new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_STEAM_MACERATOR); + } + + @Override + protected GT_RenderedTexture getFrontOverlayActive() { + return new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_STEAM_MACERATOR_ACTIVE); + } + + @Override + public String getMachineType() { + return "Macerator"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + if (mCasingName.contains("gt.blockcasings")) { + mCasingName = ItemList.Casing_BronzePlatedBricks.get(1) + .getDisplayName(); + } + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Steam Macerator") + .addInfo("33.3% faster than using a single block Steam Macerator.") + .addInfo("Uses only 66.6% of the steam/s required compared to a single block Steam Macerator.") + .addInfo("Macerates up to " + getMaxParallelRecipes() + " things at a time") + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front center") + .addCasingInfoMin(mCasingName, 14, false) + .addOtherStructurePart(TT_steaminputbus, "Any casing", 1) + .addOtherStructurePart(TT_steamoutputbus, "Any casing", 1) + .addOtherStructurePart(TT_steamhatch, "Any casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_SteamMacerator> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_SteamMacerator>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "C~C", "C-C", "CCC" }, { "CCC", "CCC", "CCC" }, })) + .addElement( + 'C', + ofChain( + buildSteamInput(GregtechMetaTileEntity_SteamMacerator.class).casingIndex(10) + .dot(1) + .build(), + buildHatchAdder(GregtechMetaTileEntity_SteamMacerator.class) + .atLeast(SteamHatchElement.InputBus_Steam, SteamHatchElement.OutputBus_Steam) + .casingIndex(10) + .dot(1) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(sBlockCasings1, 10)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + fixAllMaintenanceIssue(); + return checkPiece(mName, 1, 1, 0) && mCasing >= 14; + } + + @Override + public int getMaxParallelRecipes() { + return 8; + } + + @Override + public RecipeMap<?> getRecipeMap() { + return RecipeMaps.maceratorRecipes; + } + + // note that a basic steam machine has .setEUtDiscount(2F).setSpeedBoost(2F). So these are bonuses. + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic() { + + @Override + @Nonnull + protected GT_OverclockCalculator createOverclockCalculator(@NotNull GT_Recipe recipe) { + return GT_OverclockCalculator.ofNoOverclock(recipe) + .setEUtDiscount(1.33F) + .setSpeedBoost(1.5F); + } + + }.setMaxParallel(getMaxParallelRecipes()); + } + + @Override + public int getItemOutputLimit() { + return 1; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_AutoCrafter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_AutoCrafter.java new file mode 100644 index 0000000000..6cae5e4bcd --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_AutoCrafter.java @@ -0,0 +1,196 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import net.minecraft.item.ItemStack; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; + +public class GT4Entity_AutoCrafter extends GregtechMeta_MultiBlockBase<GT4Entity_AutoCrafter> + implements ISurvivalConstructable { + + protected GT_Recipe lastRecipeToBuffer; + private int casing; + private static IStructureDefinition<GT4Entity_AutoCrafter> STRUCTURE_DEFINITION = null; + + public GT4Entity_AutoCrafter(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GT4Entity_AutoCrafter(String mName) { + super(mName); + } + + @Override + public String getMachineType() { + return "Assembler"; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity tileEntity) { + return new GT4Entity_AutoCrafter(this.mName); + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public int getMaxEfficiency(ItemStack itemStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiAutoCrafter; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Highly Advanced Assembling Machine") + .addInfo("200% faster than using single block machines of the same voltage") + .addInfo("Processes two items per voltage tier") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfoRange("Bulk Production Frame", 10, 25, false) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + protected IIconContainer getActiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER_ACTIVE; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER; + } + + @Override + protected int getCasingTextureId() { + return TAE.getIndexFromPage(0, 10); + } + + @Override + public IStructureDefinition<GT4Entity_AutoCrafter> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GT4Entity_AutoCrafter>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "C~C", "C-C", "CCC" }, { "CCC", "CCC", "CCC" }, })) + .addElement( + 'C', + buildHatchAdder(GT4Entity_AutoCrafter.class) + .atLeast(InputBus, OutputBus, InputHatch, Maintenance, Energy, Muffler) + .casingIndex(TAE.getIndexFromPage(0, 10)) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.casing, ofBlock(ModBlocks.blockCasings2Misc, 12)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack itemStack, boolean hintsOnly) { + buildPiece(mName, itemStack, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack itemStack, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, itemStack, 1, 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity baseMetaTileEntity, ItemStack itemStack) { + casing = 0; + return checkPiece(mName, 1, 1, 0) && casing >= 10 && checkHatch(); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return RecipeMaps.assemblerRecipes; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setSpeedBonus(1F / 3F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public int getMaxParallelRecipes() { + return 2 * (Math.max(1, GT_Utility.getTier(getMaxInputVoltage()))); + } + + @Override + public String[] getExtraInfoData() { + final String running = (this.mMaxProgresstime > 0 ? "Auto-Crafter running" : "Auto-Crafter stopped"); + final String maintenance = (this.getIdealStatus() == this.getRepairStatus() ? "No Maintenance issues" + : "Needs Maintenance"); + String tSpecialText; + + if (lastRecipeToBuffer != null && lastRecipeToBuffer.mOutputs[0].getDisplayName() != null) { + tSpecialText = "Currently processing: " + lastRecipeToBuffer.mOutputs[0].getDisplayName(); + } else { + tSpecialText = "Currently processing: Nothing"; + } + + return new String[] { "Large Scale Auto-Assembler v1.01c", running, maintenance, tSpecialText }; + } + + @Override + public boolean supportsInputSeparation() { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_ThermalBoiler.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_ThermalBoiler.java new file mode 100644 index 0000000000..b7a4afb878 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GT4Entity_ThermalBoiler.java @@ -0,0 +1,353 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import java.util.stream.Stream; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.ItemList; +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.util.GT_Log; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_ParallelHelper; +import gregtech.api.util.GT_Recipe; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GT4Entity_ThermalBoiler extends GregtechMeta_MultiBlockBase<GT4Entity_ThermalBoiler> + implements ISurvivalConstructable { + + private int mCasing; + private static IStructureDefinition<GT4Entity_ThermalBoiler> STRUCTURE_DEFINITION = null; + + private static final int lavaFilterResilience = 30; // Damage lava filter with 1/n probability every operation. + private int dryHeatCounter = 0; // Counts up to dryHeatMaximum to check for explosion conditions. + private static final int dryHeatMaximum = 10; // 10 consecutive operations without water = BOOM + + private static final Item itemLavaFilter = ItemList.Component_LavaFilter.getItem(); + private static final Item itemObsidian = Item.getItemFromBlock(Blocks.obsidian); + private static final Fluid fluidWater = FluidRegistry.WATER; + private static final Fluid fluidDistilledWater = FluidUtils.getDistilledWater(1) + .getFluid(); + private static final Fluid fluidSteam = FluidUtils.getSteam(1) + .getFluid(); + private static final Fluid fluidSHSteam = FluidUtils.getSuperHeatedSteam(1) + .getFluid(); + + public GT4Entity_ThermalBoiler(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GT4Entity_ThermalBoiler(String mName) { + super(mName); + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT4Entity_ThermalBoiler(this.mName); + } + + @Override + public String getMachineType() { + return "Boiler"; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return (aStack != null && aStack.getItem() == itemLavaFilter) ? 1 : 0; + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.thermalBoilerRecipes; + } + + @Override + protected boolean filtersFluid() { + return false; + } + + @Override + public boolean supportsVoidProtection() { + return true; + } + + @Override + public boolean supportsBatchMode() { + return false; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic() { + + // Only test against the first fluid input in the recipe. + // We still want to run if we lack water (and subsequently explode). + @NotNull + @Override + protected Stream<GT_Recipe> findRecipeMatches(@Nullable RecipeMap<?> map) { + if (lastRecipe != null && depleteInput(lastRecipe.mFluidInputs[0], true)) { + return Stream.of(lastRecipe); + } + if (map == null) { + return Stream.empty(); + } + return map.getAllRecipes() + .stream() + .filter(recipe -> depleteInput(recipe.mFluidInputs[0], true)); + } + + @NotNull + @Override + protected GT_ParallelHelper createParallelHelper(@Nonnull GT_Recipe recipe) { + GT_Recipe adjustedRecipe = recipe.copy(); + + // Hack the recipe logic to not consume water, so that we can explode. + for (FluidStack inputFluid : adjustedRecipe.mFluidInputs) { + if (inputFluid != null + && (inputFluid.getFluid() == fluidWater || inputFluid.getFluid() == fluidDistilledWater)) { + inputFluid.amount = 0; + } + } + + // If we don't have a lava filter, remove non-obsidian outputs + // so that output space for them is not required if void protection is on. + if (!findLavaFilter()) { + for (ItemStack outputItem : adjustedRecipe.mOutputs) { + if (outputItem != null && outputItem.getItem() != itemObsidian) { + outputItem.stackSize = 0; + } + } + } + return super.createParallelHelper(adjustedRecipe); + } + }; + } + + @Override + public @NotNull CheckRecipeResult checkProcessing() { + // super.checkProcessing() instantly sets efficiency to maximum, override this. + int efficiency = mEfficiency; + CheckRecipeResult result = super.checkProcessing(); + if (result.wasSuccessful()) { + mEfficiency = efficiency; + mEfficiencyIncrease = mMaxProgresstime * getEfficiencyIncrease(); + + // Adjust steam output based on efficiency. + if (mOutputFluids != null) { + for (FluidStack outputFluid : mOutputFluids) { + if (outputFluid != null + && (outputFluid.getFluid() == fluidSteam || outputFluid.getFluid() == fluidSHSteam)) { + + // Purely for display reasons, we don't actually make any EU. + if (outputFluid.getFluid() == fluidSteam) { + lEUt = outputFluid.amount / mMaxProgresstime / 2; + } else { + lEUt = outputFluid.amount / mMaxProgresstime; + } + + // Adjust steam output based on efficiency. + // TODO: This is not reflected in the GUI while the player has it open?? + if (mEfficiency < getMaxEfficiency(null)) { + outputFluid.amount = Math + .max(1, (outputFluid.amount * mEfficiency) / getMaxEfficiency(null)); + } + + // Consume water to run recipe. + if (!useWater(outputFluid.amount)) { + outputFluid.amount = 0; + lEUt = 0; + } + } + } + } + + // Remove non-obsidian outputs if we can't damage lava filter. + if (mOutputItems != null && mOutputItems.length > 0) { + if (!damageLavaFilter()) { + for (ItemStack outputItem : mOutputItems) { + if (outputItem != null && outputItem.getItem() != itemObsidian) { + outputItem.stackSize = 0; + } + } + } + } + } + return result; + } + + private boolean findLavaFilter() { + if (getControllerSlot() == null) { + for (var bus : mInputBusses) { + for (ItemStack stack : bus.mInventory) { + if (stack != null && stack.getItem() == itemLavaFilter) { + setGUIItemStack(stack); + return true; + } + } + } + return false; + } else { + return getControllerSlot().getItem() == itemLavaFilter; + } + } + + private boolean damageLavaFilter() { + if (!findLavaFilter()) return false; + if (getBaseMetaTileEntity().getRandomNumber(lavaFilterResilience) > 0) return true; + + ItemStack filter = getControllerSlot(); + if (filter.attemptDamageItem(1, getBaseMetaTileEntity().getWorld().rand)) { + mInventory[1] = null; + } + return true; + } + + private boolean useWater(int steamAmount) { + // Round up to not dupe decimal amounts of water. + int waterAmount = Math.floorDiv(steamAmount + GT_Values.STEAM_PER_WATER - 1, GT_Values.STEAM_PER_WATER); + if (depleteInput(FluidUtils.getWater(waterAmount)) || depleteInput(FluidUtils.getDistilledWater(waterAmount))) { + dryHeatCounter = 0; + return true; + } else { + // Add some leniency with explosions. + if (dryHeatCounter < dryHeatMaximum) { + ++dryHeatCounter; + } else { + GT_Log.exp.println(this.mName + " was too hot and had no more Water!"); + explodeMultiblock(); // Generate crater + } + return false; + } + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + public int getEfficiencyIncrease() { + return 12; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiThermalBoiler; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Thermal Boiler Controller") + .addInfo("Converts Water & Heat into Steam") + .addInfo("Filters raw materials from lava") + .addInfo("Explodes if water is not supplied") + .addInfo("Consult user manual for more information") + .addPollutionAmount(getPollutionPerSecond(null)) + .beginStructureBlock(3, 3, 3, true) + .addController("Front Center") + .addCasingInfoMin("Thermal Containment Casings", 10, false) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(1); + } + + @Override + public IStructureDefinition<GT4Entity_ThermalBoiler> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GT4Entity_ThermalBoiler>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "C~C", "C-C", "CCC" }, { "CCC", "CCC", "CCC" }, })) + .addElement( + 'C', + buildHatchAdder(GT4Entity_ThermalBoiler.class) + .atLeast(InputBus, OutputBus, InputHatch, OutputHatch, Maintenance, Muffler) + .casingIndex(TAE.getIndexFromPage(0, 1)) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 11)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 10 && checkHatch(); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java new file mode 100644 index 0000000000..d835d9be4c --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_ElementalDuplicator.java @@ -0,0 +1,352 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_Utility.filterValidMTEs; + +import java.util.ArrayList; +import java.util.Collections; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_ElementalDataOrbHolder; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMTE_ElementalDuplicator extends GregtechMeta_MultiBlockBase<GregtechMTE_ElementalDuplicator> + implements ISurvivalConstructable { + + private final ArrayList<GT_MetaTileEntity_Hatch_ElementalDataOrbHolder> mReplicatorDataOrbHatches = new ArrayList<>(); + private static final int CASING_TEXTURE_ID = TAE.getIndexFromPage(0, 3); + private int mCasing = 0; + + public GregtechMTE_ElementalDuplicator(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMTE_ElementalDuplicator(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMTE_ElementalDuplicator(this.mName); + } + + @Override + public String getMachineType() { + return "Replicator"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Produces Elemental Material from UU Matter") + .addInfo("Speed: +100% | EU Usage: 100% | Parallel: 8 * Tier") + .addInfo("Maximum 1x of each bus/hatch.") + .addInfo("Requires circuit 1-16 in your Data Orb Repository") + .addInfo("depending on what Data Orb you want to prioritize") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(9, 6, 9, true) + .addController("Top Center") + .addCasingInfoMin("Elemental Confinement Shell", 138, false) + .addCasingInfoMin("Matter Fabricator Casing", 24, false) + .addCasingInfoMin("Particle Containment Casing", 24, false) + .addCasingInfoMin("Matter Generation Coil", 24, false) + .addCasingInfoMin("High Voltage Current Capacitor", 20, false) + .addCasingInfoMin("Resonance Chamber III", 24, false) + .addCasingInfoMin("Modulator III", 16, false) + .addOtherStructurePart("Data Orb Repository", "1x", 1) + .addInputHatch("Any 1 dot hint", 1) + .addOutputBus("Any 1 dot hint", 1) + .addOutputHatch("Any 1 dot hint", 1) + .addEnergyHatch("Any 1 dot hint", 1) + .addMaintenanceHatch("Any 1 dot hint", 1) + .addMufflerHatch("Any 1 dot hint", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + private static final String STRUCTURE_PIECE_MAIN = "main"; + private static IStructureDefinition<GregtechMTE_ElementalDuplicator> STRUCTURE_DEFINITION = null; + + @Override + public IStructureDefinition<GregtechMTE_ElementalDuplicator> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMTE_ElementalDuplicator>builder() + + // h = Hatch + // c = Casing + + // a = MF Casing 1 + // b = Matter Gen Coil + + // d = Current Capacitor + // e = Particle + + // f = Resonance III + // g = Modulator III + + .addShape( + STRUCTURE_PIECE_MAIN, + (new String[][] { + { " ccc ", " ccccc ", " ccccccc ", "ccchhhccc", "ccch~hccc", "ccchhhccc", " ccccccc ", + " ccccc ", " ccc " }, + { " cac ", " abfba ", " abfgfba ", "cbfgdgfbc", "afgdddgfa", "cbfgdgfbc", " abfgfba ", + " abfba ", " cac " }, + { " cec ", " e e ", " e e ", "c d c", "e ddd e", "c d c", " e e ", + " e e ", " cec " }, + { " cec ", " e e ", " e e ", "c d c", "e ddd e", "c d c", " e e ", + " e e ", " cec " }, + { " cac ", " abfba ", " abfgfba ", "cbfgdgfbc", "afgdddgfa", "cbfgdgfbc", " abfgfba ", + " abfba ", " cac " }, + { " ccc ", " ccccc ", " ccccccc ", "ccchhhccc", "ccchhhccc", "ccchhhccc", " ccccccc ", + " ccccc ", " ccc " }, })) + .addElement('a', ofBlock(getCasingBlock4(), getCasingMeta6())) + .addElement('b', ofBlock(getCasingBlock4(), getCasingMeta7())) + .addElement('d', ofBlock(getCasingBlock2(), getCasingMeta2())) + .addElement('e', ofBlock(getCasingBlock2(), getCasingMeta3())) + .addElement('f', ofBlock(getCasingBlock3(), getCasingMeta4())) + .addElement('g', ofBlock(getCasingBlock3(), getCasingMeta5())) + .addElement('c', lazy(t -> onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) + .addElement( + 'h', + lazy( + t -> ofChain( + buildHatchAdder(GregtechMTE_ElementalDuplicator.class) + .atLeast(InputHatch, OutputBus, OutputHatch, Maintenance, Muffler, Energy) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .build(), + buildHatchAdder(GregtechMTE_ElementalDuplicator.class) + .hatchClass(GT_MetaTileEntity_Hatch_ElementalDataOrbHolder.class) + .shouldReject(x -> x.mReplicatorDataOrbHatches.size() >= 1) + .adder(GregtechMTE_ElementalDuplicator::addDataOrbHatch) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta()))))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(STRUCTURE_PIECE_MAIN, stackSize, hintsOnly, 4, 4, 0); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + boolean aDidBuild = checkPiece(STRUCTURE_PIECE_MAIN, 4, 4, 0); + if (this.mInputHatches.size() != 1 || (this.mOutputBusses.size() != 1 && this.mOutputHatches.size() != 0) + || this.mEnergyHatches.size() != 1 + || this.mReplicatorDataOrbHatches.size() != 1) { + return false; + } + log("Casings: " + mCasing); + return aDidBuild && mCasing >= 138 && checkHatch(); + } + + @Override + public int survivalConstruct(ItemStack itemStack, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(STRUCTURE_PIECE_MAIN, itemStack, 4, 4, 0, elementBudget, env, false, true); + } + + protected static int getCasingTextureIndex() { + return CASING_TEXTURE_ID; + } + + protected static Block getCasingBlock() { + return ModBlocks.blockCasings5Misc; + } + + protected static Block getCasingBlock2() { + return ModBlocks.blockSpecialMultiCasings; + } + + protected static Block getCasingBlock3() { + return ModBlocks.blockSpecialMultiCasings2; + } + + protected static Block getCasingBlock4() { + return ModBlocks.blockCasingsMisc; + } + + protected static int getCasingMeta() { + return 3; + } + + protected static int getCasingMeta2() { + return 12; + } + + protected static int getCasingMeta3() { + return 13; + } + + protected static int getCasingMeta4() { + return 2; + } + + protected static int getCasingMeta5() { + return 6; + } + + protected static int getCasingMeta6() { + return 9; + } + + protected static int getCasingMeta7() { + return 8; + } + + private boolean addDataOrbHatch(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_ElementalDataOrbHolder) { + try { + return addToMachineListInternal(mReplicatorDataOrbHatches, aMetaTileEntity, aBaseCasingIndex); + } catch (Throwable t) { + t.printStackTrace(); + } + } + } + return false; + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + return (d, r, f) -> d == ForgeDirection.UP; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return CASING_TEXTURE_ID; + } + + @Override + public RecipeMap<?> getRecipeMap() { + return RecipeMaps.replicatorRecipes; + } + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + return true; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic().setSpeedBonus(1F / 2F) + .enablePerfectOverclock() + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + protected void setupProcessingLogic(ProcessingLogic logic) { + super.setupProcessingLogic(logic); + for (GT_MetaTileEntity_Hatch_ElementalDataOrbHolder hatch : filterValidMTEs(mReplicatorDataOrbHatches)) { + ItemStack orb = hatch.getOrbByCircuit(); + logic.setSpecialSlotItem(orb); + break; + } + } + + @Override + public int getMaxParallelRecipes() { + return (8 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiMolecularTransformer; + } + + @Override + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.isServerSide()) { + if (this.mUpdate == 1 || this.mStartUpCheck == 1) { + this.mReplicatorDataOrbHatches.clear(); + } + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public ArrayList<ItemStack> getStoredInputs() { + ArrayList<ItemStack> tItems = super.getStoredInputs(); + for (GT_MetaTileEntity_Hatch_ElementalDataOrbHolder tHatch : filterValidMTEs(mReplicatorDataOrbHatches)) { + tItems.add(tHatch.getOrbByCircuit()); + } + tItems.removeAll(Collections.singleton(null)); + return tItems; + } + + @Override + public boolean doesBindPlayerInventory() { + return false; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FrothFlotationCell.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FrothFlotationCell.java new file mode 100644 index 0000000000..8f807b94fd --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_FrothFlotationCell.java @@ -0,0 +1,287 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import java.util.List; +import java.util.Objects; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.StatCollector; +import net.minecraftforge.common.util.Constants; +import net.minecraftforge.common.util.ForgeDirection; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; + +import gregtech.api.enums.SoundResource; +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.recipe.check.SimpleCheckRecipeResult; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.Material; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.common.helpers.FlotationRecipeHandler; + +public class GregtechMTE_FrothFlotationCell extends GregtechMeta_MultiBlockBase<GregtechMTE_FrothFlotationCell> + implements ISurvivalConstructable { + + private int mCasing; + private static IStructureDefinition<GregtechMTE_FrothFlotationCell> STRUCTURE_DEFINITION = null; + + public GregtechMTE_FrothFlotationCell(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMTE_FrothFlotationCell(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMTE_FrothFlotationCell(this.mName); + } + + @Override + public String getMachineType() { + return "Flotation Cell"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Process that milled ore!") + .addInfo("You can only ever process one type of material per controller") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(7, 9, 7, true) + .addController("Front Center") + .addCasingInfoMin("Inconel Reinforced Casing", 68, false) + .addCasingInfoMin("Flotation Casing", 52, false) + .addInputBus("Bottom Casing", 1) + .addInputHatch("Bottom Casing", 1) + .addOutputHatch("Bottom Casing", 1) + .addEnergyHatch("Bottom Casing", 1) + .addMaintenanceHatch("Bottom Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + protected SoundResource getProcessStartSound() { + return SoundResource.IC2_MACHINES_ELECTROFURNACE_LOOP; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + return TAE.getIndexFromPage(2, 1); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.flotationCellRecipes; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public IStructureDefinition<GregtechMTE_FrothFlotationCell> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMTE_FrothFlotationCell>builder() + .addShape( + mName, + new String[][] { { " ", " ", " X ", " X~X ", " X ", " ", " " }, + { " ", " F ", " FFF ", " FF FF ", " FFF ", " F ", " " }, + { " ", " F ", " F F ", " F F ", " F F ", " F ", " " }, + { " ", " F ", " F F ", " F F ", " F F ", " F ", " " }, + { " ", " F ", " F F ", " F F ", " F F ", " F ", " " }, + { " ", " F ", " F F ", " F F ", " F F ", " F ", " " }, + { " ", " F ", " F F ", " F F ", " F F ", " F ", " " }, + { " CCC ", " CCCCC ", "CCCCCCC", "CCCCCCC", "CCCCCCC", " CCCCC ", " CCC " }, + { " CCC ", " CCCCC ", "CCCCCCC", "CCCCCCC", "CCCCCCC", " CCCCC ", " CCC " }, }) + .addElement( + 'C', + buildHatchAdder(GregtechMTE_FrothFlotationCell.class) + .atLeast(InputBus, InputHatch, OutputHatch, Maintenance, Energy) + .casingIndex(getCasingTextureId()) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings3Misc, 1)))) + .addElement('F', ofBlock(ModBlocks.blockSpecialMultiCasings, 9)) + .addElement('X', ofBlock(ModBlocks.blockCasings3Misc, 1)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 3, 3, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 3, 3, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 3, 3, 0) && mCasing >= 68 - 4 && checkHatch(); + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + return (d, r, f) -> d == ForgeDirection.UP; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiFrothFlotationCell; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic() { + + @NotNull + @Override + protected CheckRecipeResult validateRecipe(@NotNull GT_Recipe recipe) { + /* + * Material checks Makes sure we can only ever use one type of material in this flotation cell. We used + * to depend on Alk's hash, but it's unreliable and user-hostile So we're using unlocalized name of + * material now. + */ + Material foundMaterial = FlotationRecipeHandler + .getMaterialOfMilledProduct(FlotationRecipeHandler.findMilledStack(recipe)); + String foundMaterialName = null; + if (foundMaterial != null) { + foundMaterialName = foundMaterial.getUnlocalizedName(); + } + + if (foundMaterialName == null) { + return CheckRecipeResultRegistry.NO_RECIPE; + } + + // Set material locked for this controller + if (lockedMaterialName == null) { + lockedMaterialName = foundMaterialName; + } + + // Check material match + if (!Objects.equals(lockedMaterialName, foundMaterialName)) { + return SimpleCheckRecipeResult.ofFailure("machine_locked_to_different_recipe"); + } + return CheckRecipeResultRegistry.SUCCESSFUL; + } + }.enablePerfectOverclock(); + } + + /* + * Handle NBT + */ + + private String lockedMaterialName = null; + + @Override + public void setItemNBT(NBTTagCompound aNBT) { + if (lockedMaterialName != null) { + aNBT.setString("lockedMaterialName", lockedMaterialName); + } + super.setItemNBT(aNBT); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + if (lockedMaterialName != null) { + aNBT.setString("lockedMaterialName", lockedMaterialName); + } + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + if (aNBT.hasKey("lockedMaterialName", Constants.NBT.TAG_STRING)) { + lockedMaterialName = aNBT.getString("lockedMaterialName"); + } + } + + @Override + public void addAdditionalTooltipInformation(ItemStack stack, List<String> tooltip) { + if (stack.hasTagCompound() && stack.getTagCompound() + .hasKey("lockedMaterialName")) { + tooltip.add( + StatCollector.translateToLocal("tooltip.flotationCell.lockedTo") + " " + + StatCollector.translateToLocal( + stack.getTagCompound() + .getString("lockedMaterialName"))); + } + } + + @Override + public String[] getExtraInfoData() { + return new String[] { "Locked material: " + lockedMaterialName }; + } + + @Override + public boolean isRecipeLockingEnabled() { + return lockedMaterialName != null && !lockedMaterialName.equals(""); + } + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + super.addUIWidgets(builder, buildContext); + builder.widget(new FakeSyncWidget.StringSyncer(() -> lockedMaterialName, val -> lockedMaterialName = val)); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_NuclearReactor.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_NuclearReactor.java new file mode 100644 index 0000000000..2faccc9697 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMTE_NuclearReactor.java @@ -0,0 +1,524 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Dynamo; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_StructureUtility.filterByMTETier; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.TAE; +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.logic.ProcessingLogic; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Dynamo; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Maintenance; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffler; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; +import gregtech.api.objects.GT_ItemStack; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.recipe.check.SimpleCheckRecipeResult; +import gregtech.api.render.TextureFactory; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_OverclockCalculator; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.shutdown.ShutDownReasonRegistry; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.ELEMENT; +import gtPlusPlus.core.material.nuclear.NUCLIDE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; + +public class GregtechMTE_NuclearReactor extends GregtechMeta_MultiBlockBase<GregtechMTE_NuclearReactor> + implements ISurvivalConstructable { + + protected int mFuelRemaining = 0; + + private int mCasing; + private static IStructureDefinition<GregtechMTE_NuclearReactor> STRUCTURE_DEFINITION = null; + + public GregtechMTE_NuclearReactor(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMTE_NuclearReactor(final String aName) { + super(aName); + } + + @Override + public long maxEUStore() { + return (640000000L * (Math.min(16, this.mEnergyHatches.size()))) / 16L; + } + + @Override + public String getMachineType() { + return "Reactor"; + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.liquidFluorineThoriumReactorRecipes; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Liquid Fluoride Thorium Reactor.") + .addInfo("Produces energy and new elements from Radioactive Beta Decay!") + .addInfo("Input LFTB and a molten salt as fuel, and match the 4 Buffered Dynamo Hatches:") + .addInfo("LFTR Fuel 1 (4 EV Hatches), LFTR Fuel 2 (4 IV Hatches), LFTR Fuel 3 (4 LuV Hatches)") + .addInfo("If using better hatches for a worse fuel, only 1 hatch will output EU") + .addInfo("Outputs U233 every 10 seconds, on average, while the reactor is running") + .addInfo("Check NEI to see the other 3 outputs - they differ between fuels") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(7, 4, 7, true) + .addController("Bottom Center") + .addCasingInfoMin("Hastelloy-N Reactor Casing", 27, false) + .addCasingInfoMin("Zeron-100 Reactor Shielding", 26, false) + .addInputHatch("Top or bottom layer edges", 1) + .addOutputHatch("Top or bottom layer edges", 1) + .addDynamoHatch("Top or bottom layer edges", 1) + .addMaintenanceHatch("Top or bottom layer edges", 1) + .addMufflerHatch("Top 3x3", 2) + .addStructureInfo("All dynamos must be between EV and LuV tier.") + .addStructureInfo("All other hatches must be IV+ tier.") + .addStructureInfo("4x Output Hatches or 1x Output Hatch (ME), 1+ Input Hatches, 4x Dynamo Hatches") + .addStructureInfo("2x Maintenance Hatches, 4x Mufflers") + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public String[] getExtraInfoData() { + final String tRunning = (this.mMaxProgresstime > 0 ? "Reactor running" : "Reactor stopped"); + final String tMaintainance = (this.getIdealStatus() == this.getRepairStatus() ? "No Maintainance issues" + : "Needs Maintainance"); + + return new String[] { "Liquid Fluoride Thorium Reactor", tRunning, tMaintainance, + "Current Output: " + this.lEUt + " EU/t", "Fuel Remaining: " + this.mFuelRemaining + " Litres", + "Current Efficiency: " + (this.mEfficiency / 5) + "%", "Current Efficiency (Raw): " + (this.mEfficiency), + "It requires you to have 100% Efficiency." }; + } + + @Override + public boolean allowCoverOnSide(final ForgeDirection side, final GT_ItemStack aStack) { + return side != this.getBaseMetaTileEntity() + .getFrontFacing(); + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + boolean aWarmedUp = this.mEfficiency == this.getMaxEfficiency(null); + if (!aBaseMetaTileEntity.isActive() || !aWarmedUp) { + if (side == facing) { + if (aActive) return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12)), + TextureFactory.builder() + .addIcon(Textures.BlockIcons.OVERLAY_FRONT_REPLICATOR_ACTIVE) + .extFacing() + .build() }; + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12)), + TextureFactory.builder() + .addIcon(Textures.BlockIcons.OVERLAY_FRONT_REPLICATOR) + .extFacing() + .build() }; + } + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12)) }; + } else if (aBaseMetaTileEntity.isActive() && aWarmedUp) { + if (side == facing) { + if (aActive) return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(13)), + TextureFactory.builder() + .addIcon(Textures.BlockIcons.OVERLAY_FRONT_REPLICATOR_ACTIVE) + .extFacing() + .build() }; + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(13)), + TextureFactory.builder() + .addIcon(Textures.BlockIcons.OVERLAY_FRONT_REPLICATOR) + .extFacing() + .build() }; + } + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(13)) }; + } + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12)) }; + } + + public final boolean addNuclearReactorEdgeList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo dynamo + && dynamo.getTierForStructure() >= 4 + && dynamo.getTierForStructure() <= 6) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input hatch + && hatch.getTierForStructure() >= 5) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output hatch + && hatch.getTierForStructure() >= 5) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + public final boolean addNuclearReactorTopList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler hatch && hatch.getTierForStructure() >= 5) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public IStructureDefinition<GregtechMTE_NuclearReactor> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMTE_NuclearReactor>builder() + .addShape( + mName, + transpose( + new String[][] { + { "CCCCCCC", "COOOOOC", "COXXXOC", "COXXXOC", "COXXXOC", "COOOOOC", "CCCCCCC" }, + { "GGGGGGG", "G-----G", "G-----G", "G-----G", "G-----G", "G-----G", "GGGGGGG" }, + { "GGGGGGG", "G-----G", "G-----G", "G-----G", "G-----G", "G-----G", "GGGGGGG" }, + { "CCC~CCC", "COOOOOC", "COOOOOC", "COOOOOC", "COOOOOC", "COOOOOC", "CCCCCCC" }, })) + .addElement( + 'C', + ofChain( + buildHatchAdder(GregtechMTE_NuclearReactor.class).atLeast(Maintenance) + .casingIndex(TAE.GTPP_INDEX(12)) + .dot(1) + .build(), + buildHatchAdder(GregtechMTE_NuclearReactor.class).atLeast(InputHatch, OutputHatch) + .adder(GregtechMTE_NuclearReactor::addNuclearReactorEdgeList) + .hatchItemFilterAnd(t -> filterByMTETier(5, Integer.MAX_VALUE)) + .casingIndex(TAE.GTPP_INDEX(12)) + .dot(1) + .build(), + buildHatchAdder(GregtechMTE_NuclearReactor.class).atLeast(Dynamo) + .adder(GregtechMTE_NuclearReactor::addNuclearReactorEdgeList) + .hatchItemFilterAnd(t -> filterByMTETier(4, 6)) + .casingIndex(TAE.GTPP_INDEX(12)) + .dot(1) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 12)))) + .addElement( + 'X', + buildHatchAdder(GregtechMTE_NuclearReactor.class).atLeast(Muffler) + .adder(GregtechMTE_NuclearReactor::addNuclearReactorTopList) + .hatchItemFilterAnd(t -> filterByMTETier(5, Integer.MAX_VALUE)) + .casingIndex(TAE.GTPP_INDEX(12)) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 12)))) + .addElement('O', ofBlock(ModBlocks.blockCasingsMisc, 12)) + .addElement('G', ofBlock(ModBlocks.blockCasingsMisc, 13)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 3, 3, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 3, 3, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + if (checkPiece(mName, 3, 3, 0) && mCasing >= 27) { + if ((mOutputHatches.size() >= 3 || canDumpFluidToME()) && mInputHatches.size() >= 1 + && mDynamoHatches.size() == 4 + && mMufflerHatches.size() == 4 + && mMaintenanceHatches.size() == 2) { + fixAllMaintenanceIssue(); + this.turnCasingActive(false); + return true; + } + } + return false; + } + + // Alk's Life Lessons from Greg. + /* + * [23:41:15] <GregoriusTechneticies> xdir and zdir are x2 and not x3 [23:41:26] <GregoriusTechneticies> thats you + * issue [23:44:33] <Alkalus> mmm? [23:44:49] <Alkalus> Should they be x3? [23:44:50] <GregoriusTechneticies> you + * just do a x2, what is for a 5x5 multiblock [23:45:01] <GregoriusTechneticies> x3 is for a 7x7 one [23:45:06] + * <Alkalus> I have no idea what that value does, tbh.. [23:45:15] <GregoriusTechneticies> its the offset [23:45:23] + * <Alkalus> Debugging checkMachine has been a pain and I usually trash designs that don't work straight up.. + * [23:45:28] <GregoriusTechneticies> it determines the horizontal middle of the multiblock [23:45:47] + * <GregoriusTechneticies> which is in your case THREE blocks away from the controller [23:45:51] <Alkalus> Ahh + * [23:45:57] <GregoriusTechneticies> and not 2 [23:46:06] <Alkalus> Noted, thanks :D + */ + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + return true; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(final ItemStack aStack) { + return 0; + } + + @Override + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return true; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMTE_NuclearReactor(this.mName); + } + + public boolean turnCasingActive(final boolean status) { + // TODO + if (this.mDynamoHatches != null) { + for (final GT_MetaTileEntity_Hatch_Dynamo hatch : this.mDynamoHatches) { + hatch.updateTexture(status ? TAE.GTPP_INDEX(13) : TAE.GTPP_INDEX(12)); + } + } + if (this.mMufflerHatches != null) { + for (final GT_MetaTileEntity_Hatch_Muffler hatch : this.mMufflerHatches) { + hatch.updateTexture(status ? TAE.GTPP_INDEX(13) : TAE.GTPP_INDEX(12)); + } + } + if (this.mOutputHatches != null) { + for (final GT_MetaTileEntity_Hatch_Output hatch : this.mOutputHatches) { + hatch.updateTexture(status ? TAE.GTPP_INDEX(13) : TAE.GTPP_INDEX(12)); + } + } + if (this.mInputHatches != null) { + for (final GT_MetaTileEntity_Hatch_Input hatch : this.mInputHatches) { + hatch.updateTexture(status ? TAE.GTPP_INDEX(13) : TAE.GTPP_INDEX(12)); + } + } + if (this.mMaintenanceHatches != null) { + for (final GT_MetaTileEntity_Hatch_Maintenance hatch : this.mMaintenanceHatches) { + hatch.updateTexture(status ? TAE.GTPP_INDEX(13) : TAE.GTPP_INDEX(12)); + } + } + return true; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic() { + + @NotNull + @Override + protected GT_OverclockCalculator createOverclockCalculator(@NotNull GT_Recipe recipe) { + return GT_OverclockCalculator.ofNoOverclock(recipe.mSpecialValue * 4L, recipe.mDuration); + } + + @NotNull + @Override + public CheckRecipeResult process() { + CheckRecipeResult result = super.process(); + if (!result.wasSuccessful()) { + resetMultiProcessing(); + } + return result; + } + + @NotNull + @Override + protected CheckRecipeResult validateRecipe(@NotNull GT_Recipe recipe) { + mFuelRemaining = 0; + int li2bef4 = 0; + FluidStack aFuelFluid = null; + for (FluidStack aFluidInput : recipe.mFluidInputs) { + if (!aFluidInput.getFluid() + .equals(NUCLIDE.Li2BeF4.getFluid())) { + aFuelFluid = aFluidInput; + break; + } + } + if (aFuelFluid != null) { + for (FluidStack fluidStack : getStoredFluids()) { + if (fluidStack.isFluidEqual(aFuelFluid)) { + mFuelRemaining += fluidStack.amount; + } else if (fluidStack.getFluid() + .equals(NUCLIDE.Li2BeF4.getFluid())) { + li2bef4 += fluidStack.amount; + } + } + } + if (mFuelRemaining < 100) { + return CheckRecipeResultRegistry.NO_FUEL_FOUND; + } + if (li2bef4 < 200) { + return SimpleCheckRecipeResult.ofFailure("no_li2bef4"); + } + return CheckRecipeResultRegistry.SUCCESSFUL; + } + }; + } + + protected void resetMultiProcessing() { + this.mEfficiency = 0; + this.mLastRecipe = null; + stopMachine(ShutDownReasonRegistry.NONE); + } + + @Override + public @NotNull CheckRecipeResult checkProcessing() { + // Warm up for 4~ minutes + if (mEfficiency < this.getMaxEfficiency(null)) { + this.mMaxProgresstime = 1; + this.mEfficiencyIncrease = 2; + return SimpleCheckRecipeResult.ofSuccess("warm_up"); + } + CheckRecipeResult result = super.checkProcessing(); + if (result.wasSuccessful()) { + // We produce EU, so we negate the value, if negative + if (lEUt < 0) { + lEUt = -lEUt; + } + } + return result; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public void explodeMultiblock() { + this.mInventory[1] = null; + long explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + for (final MetaTileEntity tTileEntity : this.mInputBusses) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity() + .doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mOutputBusses) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity() + .doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mInputHatches) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity() + .doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mOutputHatches) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity() + .doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mDynamoHatches) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity() + .doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mMufflerHatches) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity() + .doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mEnergyHatches) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity() + .doExplosion(explodevalue); + } + for (final MetaTileEntity tTileEntity : this.mMaintenanceHatches) { + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + tTileEntity.getBaseMetaTileEntity() + .doExplosion(explodevalue); + } + explodevalue = MathUtils.randLong(Integer.MAX_VALUE, 8589934588L); + this.getBaseMetaTileEntity() + .doExplosion(explodevalue); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (aBaseMetaTileEntity.getWorld().isRemote) { + if (aBaseMetaTileEntity.isActive()) { + // Set casings active if we're warmed up. + if (this.mEfficiency == this.getMaxEfficiency(null)) { + this.turnCasingActive(true); + } else { + this.turnCasingActive(false); + } + } else { + this.turnCasingActive(false); + } + } + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public boolean onRunningTick(ItemStack aStack) { + // See if we're warmed up. + if (this.mEfficiency == this.getMaxEfficiency(null)) { + // Try output some Uranium-233 + if (MathUtils.randInt(1, 300) == 1) { + this.addOutput(ELEMENT.getInstance().URANIUM233.getFluidStack(MathUtils.randInt(1, 10))); + } + } + return super.onRunningTick(aStack); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mFuelRemaining", this.mFuelRemaining); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + this.mFuelRemaining = aNBT.getInteger("mFuelRemaining"); + super.loadNBTData(aNBT); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java new file mode 100644 index 0000000000..0441907f40 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntityTreeFarm.java @@ -0,0 +1,809 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_Utility.filterValidMTEs; +import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTEnergy; + +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.List; + +import javax.annotation.Nonnull; + +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemShears; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.fluids.FluidStack; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import forestry.api.arboriculture.IToolGrafter; +import forestry.api.arboriculture.ITree; +import forestry.api.arboriculture.TreeManager; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Mods; +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.items.GT_MetaGenerated_Tool; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.recipe.check.SimpleCheckRecipeResult; +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 gregtech.api.util.VoidProtectionHelper; +import gregtech.common.items.GT_MetaGenerated_Tool_01; +import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_InputBus_ME; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.common.items.MetaGeneratedGregtechTools; + +public class GregtechMetaTileEntityTreeFarm extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntityTreeFarm> + implements ISurvivalConstructable { + + public static int CASING_TEXTURE_ID; + private static final int TICKS_PER_OPERATION = 100; + private static final int TOOL_DAMAGE_PER_OPERATION = 1; + private static final int TOOL_CHARGE_PER_OPERATION = 32; + + private int mCasing; + public static String mCasingName = "Sterile Farm Casing"; + private static IStructureDefinition<GregtechMetaTileEntityTreeFarm> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntityTreeFarm(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + CASING_TEXTURE_ID = TAE.getIndexFromPage(1, 15); + } + + public GregtechMetaTileEntityTreeFarm(final String aName) { + super(aName); + CASING_TEXTURE_ID = TAE.getIndexFromPage(1, 15); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntityTreeFarm(this.mName); + } + + @Override + public String getMachineType() { + return "Tree Farm"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller block for the Tree Growth Simulator") + .addInfo("Farms and harvests trees using EU") + .addInfo("Place a sapling in the controller slot") + .addInfo("Place a tool in an input bus") + .addInfo("Different tools are required for different outputs") + .addInfo("Advanced tools multiply output amount") + .addInfo(" Logs: Saw (1x), Buzzsaw (2x), Chainsaw (4x)") + .addInfo(" Saplings: Branch Cutter (1x), Grafter (3x)") + .addInfo(" Leaves: Shears (1x), Wire Cutter (2x), Automatic Snips (4x)") + .addInfo(" Fruit: Knife (1x)") + .addInfo("Multiple tools can be used at the same time") + .addSeparator() + .addInfo("Work time is fixed at 5 seconds") + .addInfo("Energy input tier multiplies output further") + .addInfo("Output multiplier is equal to: 2*tier^2 - 2*tier + 5") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 3, true) + .addController("Front center") + .addCasingInfoMin(mCasingName, 8, false) + .addInputBus("Any casing", 1) + .addStructureInfo( + EnumChatFormatting.YELLOW + "Stocking Input Busses and Crafting Input Busses/Buffers are not allowed!") + .addOutputBus("Any casing", 1) + .addEnergyHatch("Any casing", 1) + .addMaintenanceHatch("Any casing", 1) + .addMufflerHatch("Any casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return CASING_TEXTURE_ID; + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 1, 0) && mCasing >= 8 && checkHatch(); + } + + @Override + public boolean addInputBusToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + // Tools from a stocking inout bus can not be damaged, this would cause an infinite durability exploit. + // Therefore disallow ME input bus. + if (aTileEntity == null) return false; + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) return false; + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus_ME) return false; + return super.addInputBusToMachineList(aTileEntity, aBaseCasingIndex); + } + + @Override + public boolean supportsCraftingMEBuffer() { + return false; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public boolean supportsBatchMode() { + // Batch mode would not do anything, processing time is fixed at 100 ticks. + return false; + } + + @Override + public boolean isBatchModeEnabled() { + return false; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiTreeFarm; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntityTreeFarm> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntityTreeFarm>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "C~C", "C-C", "CCC" }, { "CCC", "CCC", "CCC" }, })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntityTreeFarm.class) + .atLeast( + InputHatch, + OutputHatch, + InputBus, + OutputBus, + Maintenance, + Energy.or(TTEnergy), + Muffler) + .casingIndex(CASING_TEXTURE_ID) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 15)))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, env, false, true); + } + + /* Processing logic. */ + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + if (aStack == null) return false; + if (isValidSapling(aStack)) return true; + /* + * In previous versions, a saw used to go in the controller slot. We do not want an update to stop processing of + * a machine set up like this. Instead, a sapling is placed in this slot at the start of the next operation. + */ + if (aStack.getItem() instanceof GT_MetaGenerated_Tool_01) return true; + return false; + } + + @Override + public RecipeMap<?> getRecipeMap() { + // Only for NEI, not used in processing logic. + return GTPPRecipeMaps.treeGrowthSimulatorFakeRecipes; + } + + /** + * Valid processing modes (types of output) for the Tree Growth Simulator. + */ + public enum Mode { + LOG, + SAPLING, + LEAVES, + FRUIT + } + + /** + * Edit this to change relative yields for different modes. For example, logs are output at 5 times the rate of + * saplings. + */ + private static final EnumMap<Mode, Integer> modeMultiplier = new EnumMap<>(Mode.class); + static { + modeMultiplier.put(Mode.LOG, 5); + modeMultiplier.put(Mode.SAPLING, 1); + modeMultiplier.put(Mode.LEAVES, 2); + modeMultiplier.put(Mode.FRUIT, 1); + } + + /** + * Return the output multiplier for a given power tier. + * + * @param tier Power tier the machine runs on. + * @return Factor to multiply all outputs by. + */ + private static int getTierMultiplier(int tier) { + /* + * Where does this formula come from? [12:57 AM] boubou_19: i did. Basically Pandoro measured the output of a + * WA-ed farming station for each tier of WA, then i computed the Lagrange interpolating polynomial of his + * dataset, which gave this + */ + return (2 * (tier * tier)) - (2 * tier) + 5; + } + + /** + * Key of this map is the registry name of the sapling, followed by ":", and the sapling's metadata value. + * <p> + * The value of the map is a list of products by {@link Mode}. Products for some modes can be null if the tree does + * not produce anything in that mode (for example, it has no fruit). + */ + public static final HashMap<String, EnumMap<Mode, ItemStack>> treeProductsMap = new HashMap<>(); + + @Override + public ProcessingLogic createProcessingLogic() { + return new ProcessingLogic() { + + @Override + @Nonnull + public CheckRecipeResult process() { + if (inputItems == null) { + inputItems = new ItemStack[0]; + } + if (inputFluids == null) { + inputFluids = new FluidStack[0]; + } + + ItemStack sapling = findSapling(); + if (sapling == null) return SimpleCheckRecipeResult.ofFailure("no_sapling"); + + EnumMap<Mode, ItemStack> outputPerMode = getOutputsForSapling(sapling); + if (outputPerMode == null) { + // This should usually not be possible, outputs for all valid saplings should be defined. + Logger.INFO("No output found for sapling: " + sapling.getDisplayName()); + return SimpleCheckRecipeResult.ofFailure("no_output_for_sapling"); + } + + int tier = Math.max(1, GT_Utility.getTier(availableVoltage * availableAmperage)); + int tierMultiplier = getTierMultiplier(tier); + + List<ItemStack> outputs = new ArrayList<>(); + for (Mode mode : Mode.values()) { + ItemStack output = outputPerMode.get(mode); + if (output == null) continue; // This sapling has no output in this mode. + + // Find a tool to use in this mode. + int toolMultiplier = useToolForMode(mode); + if (toolMultiplier < 0) continue; // No valid tool for this mode found. + + // Increase output by the relevant multipliers. + ItemStack out = output.copy(); + out.stackSize *= tierMultiplier * modeMultiplier.get(mode) * toolMultiplier; + outputs.add(out); + } + + if (outputs.isEmpty()) { + // No outputs can be produced using the tools we have available. + return SimpleCheckRecipeResult.ofFailure("no_tools"); + } + + outputItems = outputs.toArray(new ItemStack[0]); + + VoidProtectionHelper voidProtection = new VoidProtectionHelper().setMachine(machine) + .setItemOutputs(outputItems) + .build(); + if (voidProtection.isItemFull()) { + return CheckRecipeResultRegistry.ITEM_OUTPUT_FULL; + } + + duration = TICKS_PER_OPERATION; + calculatedEut = GT_Values.VP[tier]; + + return SimpleCheckRecipeResult.ofSuccess("growing_trees"); + } + }; + } + + /* Handling tools. */ + + /** + * Attempts to find a tool appropriate for the given mode, and damage/discharge it by one use. + * + * @param mode The mode to use. This specifies which tools are valid. + * @return Production multiplier based on the tool used, or -1 if no appropriate tool was found. + */ + private int useToolForMode(Mode mode) { + for (ItemStack stack : getStoredInputs()) { + int toolMultiplier = getToolMultiplier(stack, mode); + if (toolMultiplier < 0) continue; + boolean canDamage = GT_ModHandler + .damageOrDechargeItem(stack, TOOL_DAMAGE_PER_OPERATION, TOOL_CHARGE_PER_OPERATION, null); + if (canDamage) { + // Tool was used. + if (GT_ModHandler.isElectricItem(stack) + && !GT_ModHandler.canUseElectricItem(stack, TOOL_CHARGE_PER_OPERATION)) { + // Tool is out of charge, move it to output. + depleteInput(stack); + addOutput(stack); + } + return toolMultiplier; + } else { + // Correct item type, but the tool could not be used. + depleteInput(stack); + addOutput(stack); + } + + } + return -1; + } + + /** + * Calculate output multiplier for a given tool and mode. + * + * @param toolStack The tool to use. + * @param mode The mode to use. + * @return Output multiplier for the given tool used in the given mode. If the tool is not appropriate for this + * mode, returns -1. + */ + public static int getToolMultiplier(ItemStack toolStack, Mode mode) { + Item tool = toolStack.getItem(); + switch (mode) { + case LOG: + if (tool instanceof GT_MetaGenerated_Tool_01) { + switch (toolStack.getItemDamage()) { + case GT_MetaGenerated_Tool_01.SAW: + case GT_MetaGenerated_Tool_01.POCKET_SAW: + case GT_MetaGenerated_Tool_01.POCKET_MULTITOOL: + return 1; + case GT_MetaGenerated_Tool_01.BUZZSAW_LV: + case GT_MetaGenerated_Tool_01.BUZZSAW_MV: + case GT_MetaGenerated_Tool_01.BUZZSAW_HV: + return 2; + case GT_MetaGenerated_Tool_01.CHAINSAW_LV: + case GT_MetaGenerated_Tool_01.CHAINSAW_MV: + case GT_MetaGenerated_Tool_01.CHAINSAW_HV: + return 4; + } + } + break; + + case SAPLING: + if (tool instanceof GT_MetaGenerated_Tool_01) { + switch (toolStack.getItemDamage()) { + case GT_MetaGenerated_Tool_01.BRANCHCUTTER: + case GT_MetaGenerated_Tool_01.POCKET_BRANCHCUTTER: + case GT_MetaGenerated_Tool_01.POCKET_MULTITOOL: + return 1; + } + } + if (tool instanceof IToolGrafter && tool.isDamageable()) { + return 3; + } + break; + + case LEAVES: + // Do not allow unbreakable tools. Operation should have a running cost. + if (tool instanceof ItemShears && tool.isDamageable()) { + return 1; + } + if (tool instanceof GT_MetaGenerated_Tool_01) { + switch (toolStack.getItemDamage()) { + case GT_MetaGenerated_Tool_01.POCKET_MULTITOOL: + return 1; + case GT_MetaGenerated_Tool_01.WIRECUTTER: + case GT_MetaGenerated_Tool_01.POCKET_WIRECUTTER: + return 2; + } + } + if (tool instanceof MetaGeneratedGregtechTools) { + if (toolStack.getItemDamage() == MetaGeneratedGregtechTools.ELECTRIC_SNIPS) { + return 4; + } + } + break; + + case FRUIT: + if (tool instanceof GT_MetaGenerated_Tool_01) { + switch (toolStack.getItemDamage()) { + case GT_MetaGenerated_Tool_01.KNIFE: + case GT_MetaGenerated_Tool_01.POCKET_KNIFE: + case GT_MetaGenerated_Tool_01.POCKET_MULTITOOL: + return 1; + } + } + break; + } + + // No valid tool was found. + return -1; + } + + /* Handling saplings. */ + + /** + * Finds a valid sapling from input buses, and places it into the controller slot. + * + * @return The sapling that was found (now in the controller slot). + */ + private ItemStack findSapling() { + ItemStack controllerSlot = getControllerSlot(); + + if (isValidSapling(controllerSlot)) { + return controllerSlot; + } + + if (controllerSlot != null) { + // Non-sapling item in controller slot. This could be a saw from an older version of the TGS. + // We first try to swap it with a sapling from an input bus to not interrupt existing setups. + if (!legacyToolSwap()) { + // Swap failed, output whatever is blocking the slot. + addOutput(controllerSlot); + mInventory[1] = null; + } + } + + // Here controller slot is empty, find a valid sapling to use. + for (ItemStack stack : getStoredInputs()) { + if (isValidSapling(stack)) { + mInventory[1] = stack.splitStack(1); + return mInventory[1]; + } + } + + // No saplings were found. + return null; + } + + /** + * In previous versions, the saw used to be placed in the controller slot and the sapling into an input bus. We do + * not want to break existing setups like this, so we attempt to swap the two if possible. + * + * @return True on success, false otherwise. + */ + private boolean legacyToolSwap() { + ItemStack controllerSlot = getControllerSlot(); + if (controllerSlot == null || !(controllerSlot.getItem() instanceof GT_MetaGenerated_Tool_01)) return false; + + for (GT_MetaTileEntity_Hatch_InputBus inputBus : filterValidMTEs(mInputBusses)) { + ItemStack[] inventory = inputBus.getRealInventory(); + for (int slot = 0; slot < inventory.length; ++slot) { + if (isValidSapling(inventory[slot])) { + // Do the swap. + mInventory[1] = inventory[slot]; + inventory[slot] = controllerSlot; + inputBus.updateSlots(); + return true; + } + } + } + return false; + } + + /** + * Check if an ItemStack is a sapling that can be farmed. + * + * @param stack An ItemStack. + * @return True if stack is a valid sapling that can be farmed. + */ + private boolean isValidSapling(ItemStack stack) { + if (stack == null) return false; + String registryName = Item.itemRegistry.getNameForObject(stack.getItem()); + return treeProductsMap.containsKey(registryName + ":" + stack.getItemDamage()) + || "Forestry:sapling".equals(registryName); + } + + /** + * Get a list of possible outputs for a sapling, for each mode. This is either recovered from + * {@link #treeProductsMap}, or generated from stats of Forestry saplings. + * + * @param sapling A sapling to farm. + * @return A map of outputs for each mode. Outputs for some modes might be null. + */ + private static EnumMap<Mode, ItemStack> getOutputsForSapling(ItemStack sapling) { + String registryName = Item.itemRegistry.getNameForObject(sapling.getItem()); + if ("Forestry:sapling".equals(registryName)) { + return getOutputsForForestrySapling(sapling); + } else { + return treeProductsMap.get(registryName + ":" + sapling.getItemDamage()); + } + } + + /** + * Calculate outputs for Forestry saplings. Default amounts stored in {@link #treeProductsMap} are adjusted based + * the genetics of the input sapling. + * <p> + * Relevant stats: + * <ul> + * <li>height, girth: Affects log output.</li> + * <li>fertility (called Saplings in game): Affects sapling output.</li> + * <li>yield: Affects fruit output.</li> + * </ul> + * See {@link forestry.core.genetics.alleles.EnumAllele} for detailed numeric values for each allele. + * + * @param sapling A sapling to farm. Must be a Forestry sapling with a valid genome. + * @return A map of outputs for each mode. Outputs for some modes might be null. + */ + private static EnumMap<Mode, ItemStack> getOutputsForForestrySapling(ItemStack sapling) { + ITree tree = TreeManager.treeRoot.getMember(sapling); + if (tree == null) return null; + + String speciesUUID = tree.getIdent(); + + EnumMap<Mode, ItemStack> defaultMap = treeProductsMap.get("Forestry:sapling:" + speciesUUID); + if (defaultMap == null) return null; + + // We need to make a new map so that we don't modify the stored amounts of outputs. + EnumMap<Mode, ItemStack> adjustedMap = new EnumMap<>(Mode.class); + + ItemStack log = defaultMap.get(Mode.LOG); + if (log != null) { + double height = Math.max( + 3 * (tree.getGenome() + .getHeight() - 1), + 0) + 1; + double girth = tree.getGenome() + .getGirth(); + + log = log.copy(); + log.stackSize = (int) (log.stackSize * height * girth); + adjustedMap.put(Mode.LOG, log); + } + + ItemStack saplingOut = defaultMap.get(Mode.SAPLING); + if (saplingOut != null) { + // Lowest = 0.01 ... Average = 0.05 ... Highest = 0.3 + double fertility = tree.getGenome() + .getFertility() * 10; + + // Return a copy of the *input* sapling, retaining its genetics. + int stackSize = Math.max(1, (int) (saplingOut.stackSize * fertility)); + saplingOut = sapling.copy(); + saplingOut.stackSize = stackSize; + adjustedMap.put(Mode.SAPLING, saplingOut); + } + + ItemStack leaves = defaultMap.get(Mode.LEAVES); + if (leaves != null) { + adjustedMap.put(Mode.LEAVES, leaves.copy()); + } + + ItemStack fruit = defaultMap.get(Mode.FRUIT); + if (fruit != null) { + // Lowest = 0.025 ... Average = 0.2 ... Highest = 0.4 + double yield = tree.getGenome() + .getYield() * 10; + + fruit = fruit.copy(); + fruit.stackSize = (int) (fruit.stackSize * yield); + adjustedMap.put(Mode.FRUIT, fruit); + } + + return adjustedMap; + } + + /* Recipe registration. */ + + /** + * Registers outputs for a sapling. This method assumes that output in mode SAPLING is the same as the input + * sapling. Output amount is further modified by mode, machine tier, and tool used. Recipes are added in + * {@link gtPlusPlus.xmod.gregtech.loaders.recipe.RecipeLoader_TreeFarm}. + * + * @param sapling The input sapling to farm, and also the output in mode SAPLING. + * @param log ItemStack to output in mode LOG. + * @param leaves ItemStack to output in mode LEAVES. + * @param fruit ItemStack to output in mode FRUIT. + */ + public static void registerTreeProducts(ItemStack sapling, ItemStack log, ItemStack leaves, ItemStack fruit) { + registerTreeProducts(sapling, log, sapling, leaves, fruit); + } + + /** + * Registers outputs for a sapling. Output amount is further modified by mode, machine tier, and tool used. Recipes + * are added in {@link gtPlusPlus.xmod.gregtech.loaders.recipe.RecipeLoader_TreeFarm}. + * + * @param saplingIn The input sapling to farm. + * @param log ItemStack to output in mode LOG. + * @param saplingOut ItemStack to output in mode SAPLING. + * @param leaves ItemStack to output in mode LEAVES. + * @param fruit ItemStack to output in mode FRUIT. + */ + public static void registerTreeProducts(ItemStack saplingIn, ItemStack log, ItemStack saplingOut, ItemStack leaves, + ItemStack fruit) { + String key = Item.itemRegistry.getNameForObject(saplingIn.getItem()) + ":" + saplingIn.getItemDamage(); + EnumMap<Mode, ItemStack> map = new EnumMap<>(Mode.class); + if (log != null) map.put(Mode.LOG, log); + if (saplingOut != null) map.put(Mode.SAPLING, saplingOut); + if (leaves != null) map.put(Mode.LEAVES, leaves); + if (fruit != null) map.put(Mode.FRUIT, fruit); + treeProductsMap.put(key, map); + + if (!addFakeRecipeToNEI(saplingIn, log, saplingOut, leaves, fruit)) { + Logger.INFO("Registering NEI fake recipe for " + key + " failed!"); + } + } + + /** + * For Forestry trees, the output amounts depend on the genetics of the sapling. Here we register only the types of + * items to output. In {@link #getOutputsForForestrySapling(ItemStack)} these outputs are then multiplied according + * to the stats of the real sapling that is in the controller slot. + */ + public static void registerForestryTree(String speciesUID, ItemStack sapling, ItemStack log, ItemStack leaves, + ItemStack fruit) { + String key = "Forestry:sapling:" + speciesUID; + EnumMap<Mode, ItemStack> map = new EnumMap<>(Mode.class); + map.put(Mode.LOG, log); + map.put(Mode.SAPLING, sapling); + map.put(Mode.LEAVES, leaves); + map.put(Mode.FRUIT, fruit); + treeProductsMap.put(key, map); + + // In the NEI recipe we want to display outputs adjusted for the default genetics of this tree type. + // To do this we use the same method as when calculating real outputs. + map = getOutputsForForestrySapling(sapling); + if (map == null) { + Logger.INFO("Could not create Forestry tree output map for " + speciesUID); + return; + } + addFakeRecipeToNEI( + sapling, + map.get(Mode.LOG), + map.get(Mode.SAPLING), + map.get(Mode.LEAVES), + map.get(Mode.FRUIT)); + } + + /** + * This array is used to get the rotating display of items in NEI showing all possible tools for a given mode. + */ + private static final ItemStack[][] altToolsForNEI; + static { + GT_MetaGenerated_Tool toolInstance = GT_MetaGenerated_Tool_01.INSTANCE; + altToolsForNEI = new ItemStack[][] { + // Mode.LOG + { toolInstance.getToolWithStats(GT_MetaGenerated_Tool_01.SAW, 1, null, null, null), + toolInstance.getToolWithStats(GT_MetaGenerated_Tool_01.POCKET_SAW, 1, null, null, null), + toolInstance.getToolWithStats(GT_MetaGenerated_Tool_01.BUZZSAW_LV, 1, null, null, null), + toolInstance.getToolWithStats(GT_MetaGenerated_Tool_01.CHAINSAW_LV, 1, null, null, null), + toolInstance.getToolWithStats(GT_MetaGenerated_Tool_01.BUZZSAW_MV, 1, null, null, null), + toolInstance.getToolWithStats(GT_MetaGenerated_Tool_01.CHAINSAW_MV, 1, null, null, null), + toolInstance.getToolWithStats(GT_MetaGenerated_Tool_01.BUZZSAW_HV, 1, null, null, null), + toolInstance.getToolWithStats(GT_MetaGenerated_Tool_01.CHAINSAW_HV, 1, null, null, null), }, + // Mode.SAPLING + { toolInstance.getToolWithStats(GT_MetaGenerated_Tool_01.BRANCHCUTTER, 1, null, null, null), + toolInstance.getToolWithStats(GT_MetaGenerated_Tool_01.POCKET_BRANCHCUTTER, 1, null, null, null), + GT_ModHandler.getModItem(Mods.Forestry.ID, "grafter", 1, 0), }, + // Mode.LEAVES + { new ItemStack(Items.shears), + toolInstance.getToolWithStats(GT_MetaGenerated_Tool_01.WIRECUTTER, 1, null, null, null), + toolInstance.getToolWithStats(GT_MetaGenerated_Tool_01.POCKET_WIRECUTTER, 1, null, null, null), + MetaGeneratedGregtechTools.getInstance() + .getToolWithStats(MetaGeneratedGregtechTools.ELECTRIC_SNIPS, 1, null, null, null), }, + // Mode.FRUIT + { toolInstance.getToolWithStats(GT_MetaGenerated_Tool_01.KNIFE, 1, null, null, null), + toolInstance.getToolWithStats(GT_MetaGenerated_Tool_01.POCKET_KNIFE, 1, null, null, null), } }; + } + + /** + * Add a recipe for this tree to NEI. These recipes are only used in NEI, they are never used for processing logic. + * + * @return True if the recipe was added successfully. + */ + public static boolean addFakeRecipeToNEI(ItemStack saplingIn, ItemStack log, ItemStack saplingOut, ItemStack leaves, + ItemStack fruit) { + int recipeCount = GTPPRecipeMaps.treeGrowthSimulatorFakeRecipes.getAllRecipes() + .size(); + + // Sapling goes into the "special" slot. + ItemStack specialStack = saplingIn.copy(); + specialStack.stackSize = 0; + + /* + * Calculate the correct amount of outputs for each mode. The amount displayed in NEI should take into account + * the mode multiplier, but not tool/tier multipliers as those can change dynamically. If the sapling has an + * output in this mode, also add the tools usable for this mode as inputs. + */ + ItemStack[][] inputStacks = new ItemStack[Mode.values().length][]; + ItemStack[] outputStacks = new ItemStack[Mode.values().length]; + + for (Mode mode : Mode.values()) { + ItemStack output = switch (mode) { + case LOG -> log; + case SAPLING -> saplingOut; + case LEAVES -> leaves; + case FRUIT -> fruit; + }; + if (output != null) { + int ordinal = mode.ordinal(); + inputStacks[ordinal] = altToolsForNEI[ordinal]; + outputStacks[ordinal] = output.copy(); + outputStacks[ordinal].stackSize *= modeMultiplier.get(mode); + } + } + + Logger.INFO( + "Adding Tree Growth Simulation NEI recipe for " + specialStack.getDisplayName() + + " -> " + + ItemUtils.getArrayStackNames(outputStacks)); + + GTPPRecipeMaps.treeGrowthSimulatorFakeRecipes.addFakeRecipe( + false, + new GT_Recipe.GT_Recipe_WithAlt( + false, + null, // All inputs are taken from aAtl argument. + outputStacks, + specialStack, + null, + null, + null, + TICKS_PER_OPERATION, + 0, + recipeCount, // special value, also sorts recipes correctly in order of addition. + inputStacks)); + + return GTPPRecipeMaps.treeGrowthSimulatorFakeRecipes.getAllRecipes() + .size() > recipeCount; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_AlloyBlastSmelter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_AlloyBlastSmelter.java new file mode 100644 index 0000000000..580efdcdab --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_AlloyBlastSmelter.java @@ -0,0 +1,235 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.StatCollector; +import net.minecraftforge.common.util.ForgeDirection; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.SoundResource; +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_AlloyBlastSmelter + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_AlloyBlastSmelter> implements ISurvivalConstructable { + + private int mMode = 0; + private boolean isUsingControllerCircuit = false; + private static Item circuit; + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_AlloyBlastSmelter> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_AlloyBlastSmelter(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_AlloyBlastSmelter(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_AlloyBlastSmelter(this.mName); + } + + @Override + public String getMachineType() { + return "Fluid Alloy Cooker"; + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + if (aNBT.hasKey("isBussesSeparate")) { + inputSeparation = aNBT.getBoolean("isBussesSeparate"); + } + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Alloy Blast Smelter") + .addInfo("20% Faster than the Electric Blast Furnace") + .addInfo("Allows Complex GT++ alloys to be created") + .addInfo("Accepts only one Energy Hatch") + .addInfo("Circuit for recipe goes in the Input Bus or GUI slot") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 4, 3, true) + .addController("Bottom Center") + .addCasingInfoMin("Blast Smelter Casings", 5, false) + .addCasingInfoMin("Blast Smelter Heat Containment Coils", 16, false) + .addInputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_AlloyBlastSmelter> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_AlloyBlastSmelter>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "HHH", "H-H", "HHH" }, { "HHH", "H-H", "HHH" }, + { "C~C", "CCC", "CCC" }, })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_AlloyBlastSmelter.class) + .atLeast(InputBus, InputHatch, OutputBus, OutputHatch, Maintenance, Energy, Muffler) + .casingIndex(TAE.GTPP_INDEX(15)) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 15)))) + .addElement('H', ofBlock(ModBlocks.blockCasingsMisc, 14)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 3, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 3, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 1, 3, 0) && mCasing >= 5 && mEnergyHatches.size() == 1 && checkHatch(); + } + + @Override + protected SoundResource getProcessStartSound() { + return SoundResource.IC2_MACHINES_INDUCTION_LOOP; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(15); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.alloyBlastSmelterRecipes; + } + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + if (this.getBaseMetaTileEntity() + .isServerSide()) { + // Get Controller Circuit + if (circuit == null) { + circuit = CI.getNumberedCircuit(0) + .getItem(); + } + if (aStack != null && aStack.getItem() == circuit) { + this.mMode = aStack.getItemDamage(); + return this.isUsingControllerCircuit = true; + } else { + if (aStack == null) { + this.isUsingControllerCircuit = false; + return true; // Allowed empty + } + Logger.WARNING("Not circuit in GUI inputs."); + return this.isUsingControllerCircuit = false; + } + } + Logger.WARNING("No Circuit, clientside."); + return this.isUsingControllerCircuit = false; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic(); + } + + @Override + public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + inputSeparation = !inputSeparation; + GT_Utility.sendChatToPlayer( + aPlayer, + StatCollector.translateToLocal("GT5U.machines.separatebus") + " " + inputSeparation); + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiABS; + } + + @Override + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public boolean supportsInputSeparation() { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Cyclotron.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Cyclotron.java new file mode 100644 index 0000000000..5861885bd0 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Cyclotron.java @@ -0,0 +1,331 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.SoundResource; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_OutputBus; +import gregtech.api.objects.GT_ItemStack; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.item.chemistry.IonParticles; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_Cyclotron extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Cyclotron> + implements ISurvivalConstructable { + + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_Cyclotron> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_Cyclotron(int aID, String aName, String aNameRegional, int tier) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_Cyclotron(String aName) { + super(aName); + } + + @Override + public String getMachineType() { + return "Particle Accelerator"; + } + + public int tier() { + return 5; + } + + @Override + public long maxEUStore() { + return 1800000000L; + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Cyclotron(this.mName); + } + + @Override + public boolean allowCoverOnSide(ForgeDirection side, GT_ItemStack aStack) { + return side != getBaseMetaTileEntity().getFrontFacing(); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_Cyclotron> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Cyclotron>builder() + .addShape( + mName, + transpose( + new String[][] { + { " ", " hhh ", " hh hh ", " h h ", + " h h ", " h h ", " h h ", " h h ", + " h h ", " h h ", " h h ", " h h ", + " hh hh ", " hhh ", " ", }, + { " hhh ", " hhccchh ", " hcchhhcch ", " hchh hhch ", + " hch hch ", " hch hch ", "hch hch", "hch hch", + "hch hch", " hch hch ", " hch hch ", " hchh hhch ", + " hcch~hcch ", " hhccchh ", " hhh ", }, + { " ", " hhh ", " hh hh ", " h h ", + " h h ", " h h ", " h h ", " h h ", + " h h ", " h h ", " h h ", " h h ", + " hh hh ", " hhh ", " ", } })) + .addElement( + 'h', + buildHatchAdder(GregtechMetaTileEntity_Cyclotron.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch, OutputHatch) + .casingIndex(44) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) + .addElement('c', ofBlock(getCyclotronCoil(), getCyclotronCoilMeta())) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 7, 1, 12); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 7, 1, 12, elementBudget, env, false, true); + } + + @Override + protected SoundResource getProcessStartSound() { + return SoundResource.GT_MACHINES_FUSION_LOOP; + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 7, 1, 12) && mCasing >= 40 && checkHatch(); + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings2Misc; + } + + public int getCasingMeta() { + return 10; + } + + public Block getCyclotronCoil() { + return ModBlocks.blockCasings2Misc; + } + + public int getCyclotronCoilMeta() { + return 9; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Super Magnetic Speed Shooter") + .addSeparator() + .addInfo("Particles are accelerated over 186 revolutions to 80% light speed") + .addInfo("Can produce a continuous beam current of 2.2 mA at 590 MeV") + .addInfo("Which will be extracted from the Isochronous Cyclotron") + .addSeparator() + .addInfo("Consists of the same layout as a Fusion Reactor") + .addInfo("Any external casing can be a hatch/bus, unlike Fusion") + .addInfo("Cyclotron Machine Casings around Cyclotron Coil Blocks") + .addInfo("All Hatches must be IV or better") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .addCasingInfoMin("Cyclotron Machine Casings", 40, false) + .addCasingInfoMin("Cyclotron Coil", 32, false) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + protected IIconContainer getActiveOverlay() { + return getIconOverlay(); + } + + @Override + protected IIconContainer getInactiveOverlay() { + return getIconOverlay(); + } + + @Override + protected int getCasingTextureId() { + return 44; + } + + public IIconContainer getIconOverlay() { + if (this.getBaseMetaTileEntity() + .isActive()) { + return TexturesGtBlock.Overlay_MatterFab_Active_Animated; + } + return TexturesGtBlock.Overlay_MatterFab_Animated; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.cyclotronRecipes; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic() { + + @NotNull + @Override + public CheckRecipeResult process() { + fixAllMaintenanceIssue(); + CheckRecipeResult result = super.process(); + if (result.wasSuccessful()) { + for (ItemStack s : outputItems) { + if (s != null) { + if (s.getItem() instanceof IonParticles) { + long aCharge = IonParticles.getChargeState(s); + if (aCharge == 0) { + IonParticles.setChargeState( + s, + MathUtils.getRandomFromArray( + new int[] { -5, -5, -4, -4, -4, -3, -3, -3, -3, -3, -2, -2, -2, -2, -2, -2, + -2, -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, + 5, 5, 5, 6, 6 })); + } + } + } + } + } + return result; + } + }; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public boolean onRunningTick(ItemStack aStack) { + if (this.mOutputBusses.size() > 0) { + for (GT_MetaTileEntity_Hatch_OutputBus g : this.mOutputBusses) { + if (g != null) { + for (ItemStack s : g.mInventory) { + if (s != null) { + if (s.getItem() instanceof IonParticles) { + long aCharge = IonParticles.getChargeState(s); + if (aCharge == 0) { + IonParticles.setChargeState( + s, + MathUtils.getRandomFromArray( + new int[] { -5, -5, -4, -4, -4, -3, -3, -3, -3, -3, -2, -2, -2, -2, -2, -2, + -2, -1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, + 5, 5, 5, 6, 6 })); + } + } + } + } + } + } + } + this.fixAllMaintenanceIssue(); + return super.onRunningTick(aStack); + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiCyclotron; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + @Override + public String[] getExtraInfoData() { + String tier = tier() == 5 ? "I" : "II"; + float plasmaOut = 0; + int powerRequired = 0; + if (this.mLastRecipe != null) { + powerRequired = this.mLastRecipe.mEUt; + if (this.mLastRecipe.getFluidOutput(0) != null) { + plasmaOut = (float) this.mLastRecipe.getFluidOutput(0).amount / (float) this.mLastRecipe.mDuration; + } + } + + return new String[] { "COMET - Compact Cyclotron MK " + tier, "EU Required: " + powerRequired + "EU/t", + "Stored EU: " + this.getEUVar() + " / " + maxEUStore() }; + } + + @Override + public boolean doesBindPlayerInventory() { + return false; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialFishingPond.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialFishingPond.java new file mode 100644 index 0000000000..78e4a17274 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialFishingPond.java @@ -0,0 +1,489 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gtPlusPlus.core.util.data.ArrayUtils.removeNulls; + +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.WeightedRandomFishable; +import net.minecraftforge.fluids.FluidStack; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.recipe.check.SimpleCheckRecipeResult; +import gregtech.api.util.FishPondFakeRecipe; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_OverclockCalculator; +import gregtech.api.util.GT_ParallelHelper; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import ic2.core.init.BlocksItems; +import ic2.core.init.InternalName; + +public class GregtechMetaTileEntity_IndustrialFishingPond extends + GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialFishingPond> implements ISurvivalConstructable { + + private boolean isUsingControllerCircuit = false; + private static final Item circuit = CI.getNumberedCircuit(0) + .getItem(); + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialFishingPond> STRUCTURE_DEFINITION = null; + private static final Class<?> cofhWater; + + static { + cofhWater = ReflectionUtils.getClass("cofh.asmhooks.block.BlockWater"); + } + + public GregtechMetaTileEntity_IndustrialFishingPond(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialFishingPond(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialFishingPond(this.mName); + } + + @Override + public String getMachineType() { + return "Fish Trap"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Fishing Pond") + .addInfo("Can process (Tier + 1) * 2 recipes") + .addInfo("Put a numbered circuit into the input bus.") + .addInfo("Circuit 14 for Fish") + .addInfo("Circuit 15 for Junk") + .addInfo("Circuit 16 for Treasure") + .addInfo("Need to be filled with water.") + .addInfo("Will automatically fill water from input hatch.") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(9, 3, 9, true) + .addController("Front Center") + .addCasingInfoMin("Aquatic Casings", 64, false) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialFishingPond> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialFishingPond>builder() + .addShape( + mName, + transpose( + new String[][] { + { "XXXXXXXXX", "X X", "X X", "X X", "X X", "X X", "X X", + "X X", "XXXXXXXXX" }, + { "XXXX~XXXX", "X X", "X X", "X X", "X X", "X X", "X X", + "X X", "XXXXXXXXX" }, + { "XXXXXXXXX", "XXXXXXXXX", "XXXXXXXXX", "XXXXXXXXX", "XXXXXXXXX", "XXXXXXXXX", "XXXXXXXXX", + "XXXXXXXXX", "XXXXXXXXX" }, })) + .addElement( + 'X', + buildHatchAdder(GregtechMetaTileEntity_IndustrialFishingPond.class) + .atLeast(InputBus, OutputBus, Maintenance, Energy, Muffler, InputHatch) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 4, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 4, 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 4, 1, 0) && mCasing >= 64 && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_VACUUM_FREEZER_ACTIVE; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_VACUUM_FREEZER; + } + + @Override + protected int getCasingTextureId() { + return getCasingTextureIndex(); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.fishPondRecipes; + } + + @Override + protected boolean filtersFluid() { + return false; + } + + @Override + public @NotNull CheckRecipeResult checkProcessing() { + ItemStack controllerStack = getControllerSlot(); + if (controllerStack != null) { + if (controllerStack.getItem() == circuit) { + this.isUsingControllerCircuit = true; + this.mMode = controllerStack.getItemDamage(); + } else { + this.isUsingControllerCircuit = false; + } + } else { + this.isUsingControllerCircuit = false; + } + if (!hasGenerateRecipes) { + generateRecipes(); + } + if (!checkForWater()) { + return SimpleCheckRecipeResult.ofFailure("no_water"); + } + ItemStack[] tItemInputs = getStoredInputs().toArray(new ItemStack[0]); + FluidStack[] tFluidInputs = getStoredFluids().toArray(new FluidStack[0]); + + if (!isUsingControllerCircuit && tItemInputs.length == 0) { + return CheckRecipeResultRegistry.NO_RECIPE; + } + + long tEnergy = getMaxInputEnergy(); + + getCircuit(tItemInputs); + + ItemStack[] mFishOutput = generateLoot(this.mMode); + mFishOutput = removeNulls(mFishOutput); + GT_Recipe g = new GT_Recipe( + true, + new ItemStack[] {}, + mFishOutput, + null, + new int[] {}, + tFluidInputs, + null, + 200, + 16, + 0); + GT_OverclockCalculator calculator = new GT_OverclockCalculator().setRecipeEUt(g.mEUt) + .setEUt(tEnergy) + .setDuration(g.mDuration); + GT_ParallelHelper helper = new GT_ParallelHelper().setRecipe(g) + .setItemInputs(tItemInputs) + .setFluidInputs(tFluidInputs) + .setAvailableEUt(tEnergy) + .setMaxParallel(getMaxParallelRecipes()) + .setConsumption(true) + .setOutputCalculation(true) + .setMachine(this) + .enableBatchMode(batchMode ? 128 : 1) + .setCalculator(calculator); + + helper.build(); + + if (helper.getCurrentParallel() == 0) { + return CheckRecipeResultRegistry.ITEM_OUTPUT_FULL; + } + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + lEUt = -calculator.getConsumption(); + mMaxProgresstime = (int) Math.ceil(calculator.getDuration() * helper.getDurationMultiplierDouble()); + + mOutputItems = helper.getItemOutputs(); + mOutputFluids = null; + updateSlots(); + + return CheckRecipeResultRegistry.SUCCESSFUL; + } + + @Override + public int getMaxParallelRecipes() { + return (2 * (GT_Utility.getTier(this.getMaxInputVoltage()) + 1)); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialFishingPond; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings3Misc; + } + + public byte getCasingMeta() { + return 0; + } + + public int getCasingTextureIndex() { + return TAE.GTPP_INDEX(32); + } + + public boolean checkForWater() { + + // Get Facing direction + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + int mDirectionX = aBaseMetaTileEntity.getBackFacing().offsetX; + int mCurrentDirectionX; + int mCurrentDirectionZ; + int mOffsetX_Lower = 0; + int mOffsetX_Upper = 0; + int mOffsetZ_Lower = 0; + int mOffsetZ_Upper = 0; + + mCurrentDirectionX = 4; + mCurrentDirectionZ = 4; + + mOffsetX_Lower = -4; + mOffsetX_Upper = 4; + mOffsetZ_Lower = -4; + mOffsetZ_Upper = 4; + + // if (aBaseMetaTileEntity.fac) + + final int xDir = aBaseMetaTileEntity.getBackFacing().offsetX * mCurrentDirectionX; + final int zDir = aBaseMetaTileEntity.getBackFacing().offsetZ * mCurrentDirectionZ; + + int tAmount = 0; + for (int i = mOffsetX_Lower + 1; i <= mOffsetX_Upper - 1; ++i) { + for (int j = mOffsetZ_Lower + 1; j <= mOffsetZ_Upper - 1; ++j) { + for (int h = 0; h < 2; h++) { + Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); + byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); + if (isNotStaticWater(tBlock, tMeta)) { + if (this.getStoredFluids() != null) { + for (FluidStack stored : this.getStoredFluids()) { + if (stored.isFluidEqual(FluidUtils.getFluidStack("water", 1))) { + if (stored.amount >= 1000) { + // Utils.LOG_WARNING("Going to try swap an air block for water from inut bus."); + stored.amount -= 1000; + Block fluidUsed = Blocks.water; + aBaseMetaTileEntity.getWorld() + .setBlock( + aBaseMetaTileEntity.getXCoord() + xDir + i, + aBaseMetaTileEntity.getYCoord() + h, + aBaseMetaTileEntity.getZCoord() + zDir + j, + fluidUsed); + } + } + } + } + } + tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); + if (tBlock == Blocks.water || tBlock == Blocks.flowing_water) { + ++tAmount; + } + } + } + } + + return tAmount >= 60; + } + + private boolean isNotStaticWater(Block block, byte meta) { + return block == Blocks.air || block == Blocks.flowing_water + || block == BlocksItems.getFluidBlock(InternalName.fluidDistilledWater) + || (cofhWater != null && cofhWater.isAssignableFrom(block.getClass()) && meta != 0); + } + + private static AutoMap<AutoMap<WeightedRandomFishable>> categories = new AutoMap<>(); + private static AutoMap<WeightedRandomFishable> categoryFish = new AutoMap<>(); + private static AutoMap<WeightedRandomFishable> categoryJunk = new AutoMap<>(); + private static AutoMap<WeightedRandomFishable> categoryLoot = new AutoMap<>(); + private static boolean hasGenerateRecipes = false; + private int mMode = 14; + private int mMax = 8; + + private void generateRecipes() { + if (hasGenerateRecipes) return; + + categories.put(categoryFish); + categories.put(categoryJunk); + categories.put(categoryLoot); + for (WeightedRandomFishable h : FishPondFakeRecipe.fish) { + categoryFish.put(h); + } + for (WeightedRandomFishable h : FishPondFakeRecipe.junk) { + categoryJunk.put(h); + } + for (WeightedRandomFishable h : FishPondFakeRecipe.treasure) { + categoryLoot.put(h); + } + hasGenerateRecipes = true; + } + + private int getCircuit(ItemStack[] t) { + if (!this.isUsingControllerCircuit) { + for (ItemStack j : t) { + if (j.getItem() == CI.getNumberedCircuit(0) + .getItem()) { + // Fish + if (j.getItemDamage() == 14) { + mMax = 8 + (this.getMaxParallelRecipes() - 2); + this.mMode = 14; + break; + } + // Junk + else if (j.getItemDamage() == 15) { + this.mMode = 15; + mMax = 4; + break; + } + // Loot + else if (j.getItemDamage() == 16) { + this.mMode = 16; + mMax = 4; + break; + } else { + this.mMode = 0; + mMax = 0; + break; + } + } else { + this.mMode = 0; + mMax = 0; + break; + } + } + } + return this.mMode; + } + + // reflection map + private static Map<WeightedRandomFishable, ItemStack> reflectiveFishMap = new HashMap<>(); + + private ItemStack reflectiveFish(WeightedRandomFishable y) { + if (reflectiveFishMap.containsKey(y)) { + return reflectiveFishMap.get(y); + } + ItemStack t; + try { + t = (ItemStack) ReflectionUtils.getField(WeightedRandomFishable.class, "field_150711_b") + .get(y); + ItemStack k = ItemUtils.getSimpleStack(t, 1); + reflectiveFishMap.put(y, k); + return t; + } catch (IllegalArgumentException | IllegalAccessException e) {} + return null; + } + + private ItemStack[] generateLoot(int mode) { + ItemStack[] mFishOutput = new ItemStack[this.mMax]; + if (this.mMode == 14) { + for (int k = 0; k < this.mMax; k++) { + if (mFishOutput[k] == null) for (WeightedRandomFishable g : categoryFish.values()) { + if (MathUtils.randInt(0, (65 - getMaxParallelRecipes())) <= 2) { + ItemStack t = reflectiveFish(g); + if (t != null) { + mFishOutput[k] = ItemUtils.getSimpleStack(t, 1); + } + } + } + } + } else if (this.mMode == 15) { + for (int k = 0; k < this.mMax; k++) { + if (mFishOutput[k] == null) for (WeightedRandomFishable g : categoryJunk.values()) { + if (MathUtils.randInt(0, 100) <= 1) { + ItemStack t = reflectiveFish(g); + if (t != null) { + mFishOutput[k] = ItemUtils.getSimpleStack(t, 1); + } + } + } + } + } else if (this.mMode == 16) { + for (int k = 0; k < this.mMax; k++) { + if (mFishOutput[k] == null) for (WeightedRandomFishable g : categoryLoot.values()) { + if (MathUtils.randInt(0, 1000) <= 2) { + ItemStack t = reflectiveFish(g); + if (t != null) { + mFishOutput[k] = ItemUtils.getSimpleStack(t, 1); + } + } + } + } + } else { + mFishOutput = null; + } + return mFishOutput; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialRockBreaker.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialRockBreaker.java new file mode 100644 index 0000000000..e7e74ac061 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_IndustrialRockBreaker.java @@ -0,0 +1,367 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import java.util.ArrayList; + +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.Materials; +import gregtech.api.enums.OrePrefixes; +import gregtech.api.enums.SoundResource; +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.recipe.check.SimpleCheckRecipeResult; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_OreDictUnificator; +import gregtech.api.util.GT_OverclockCalculator; +import gregtech.api.util.GT_ParallelHelper; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_IndustrialRockBreaker extends + GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_IndustrialRockBreaker> implements ISurvivalConstructable { + + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_IndustrialRockBreaker> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_IndustrialRockBreaker(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_IndustrialRockBreaker(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_IndustrialRockBreaker(this.mName); + } + + @Override + public String getMachineType() { + return "Rock Breaker"; + } + + private static final String casingBaseName = GT_LanguageManager.getTranslation("gtplusplus.blockcasings.2.0.name"); + private static final String casingMiddleName = GT_LanguageManager + .getTranslation("gtplusplus.blockcasings.2.11.name"); + private static final String anyBaseCasing = "Any " + casingBaseName; + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Industrial Rock Breaker") + .addInfo("Speed: +200% | EU Usage: 75% | Parallel: Tier x 8") + .addInfo("Circuit goes in the GUI slot") + .addInfo("1 = cobble, 2 = stone, 3 = obsidian") + .addInfo("Supply Water/Lava") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 4, 3, true) + .addController("Bottom Center") + .addCasingInfoMin(casingBaseName, 9, false) + .addCasingInfoExactly(casingMiddleName, 16, false) + .addInputBus(anyBaseCasing, 1) + .addInputHatch(anyBaseCasing, 1) + .addOutputBus(anyBaseCasing, 1) + .addEnergyHatch(anyBaseCasing, 1) + .addMaintenanceHatch(anyBaseCasing, 1) + .addMufflerHatch(anyBaseCasing, 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_IndustrialRockBreaker> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialRockBreaker>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCC", "CCC", "CCC" }, { "HHH", "H-H", "HHH" }, { "HHH", "H-H", "HHH" }, + { "C~C", "CCC", "CCC" }, })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_IndustrialRockBreaker.class) + .atLeast(InputBus, InputHatch, OutputBus, Maintenance, Energy, Muffler) + .casingIndex(TAE.GTPP_INDEX(16)) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 0)))) + .addElement('H', ofBlock(ModBlocks.blockCasings2Misc, 11)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 3, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 3, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + boolean aCheckPiece = checkPiece(mName, 1, 3, 0); + boolean aCasingCount = mCasing >= 9; + boolean aCheckHatch = checkHatch(); + log("" + aCheckPiece + ", " + aCasingCount + ", " + aCheckHatch); + return aCheckPiece && aCasingCount && aCheckHatch; + } + + @Override + protected SoundResource getProcessStartSound() { + return SoundResource.IC2_MACHINES_INDUCTION_LOOP; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(16); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return RecipeMaps.rockBreakerFakeRecipes; + } + + @Override + protected boolean filtersFluid() { + return false; + } + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + return true; + } + + private static GT_Recipe sRecipe_Cobblestone; + private static GT_Recipe sRecipe_SmoothStone; + private static GT_Recipe sRecipe_Redstone; + + private static void generateRecipes() { + sRecipe_Cobblestone = new GT_Recipe( + false, + new ItemStack[] { CI.getNumberedCircuit(1) }, + new ItemStack[] { ItemUtils.getSimpleStack(Blocks.cobblestone) }, + null, + new int[] { 10000 }, + null, + null, + 16, + 32, + 0); + sRecipe_SmoothStone = new GT_Recipe( + false, + new ItemStack[] { CI.getNumberedCircuit(2) }, + new ItemStack[] { ItemUtils.getSimpleStack(Blocks.stone) }, + null, + new int[] { 10000 }, + null, + null, + 16, + 32, + 0); + sRecipe_Redstone = new GT_Recipe( + false, + new ItemStack[] { CI.getNumberedCircuit(3), + GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Redstone, 1L) }, + new ItemStack[] { ItemUtils.getSimpleStack(Blocks.obsidian) }, + null, + new int[] { 10000 }, + null, + null, + 128, + 32, + 0); + } + + @Override + public @NotNull CheckRecipeResult checkProcessing() { + ArrayList<FluidStack> aFluids = this.getStoredFluids(); + if (aFluids.isEmpty()) { + return CheckRecipeResultRegistry.NO_RECIPE; + } + + boolean aHasWater = false; + boolean aHasLava = false; + for (FluidStack aFluid : aFluids) { + if (aFluid.getFluid() == FluidRegistry.WATER) { + aHasWater = true; + } else if (aFluid.getFluid() == FluidRegistry.LAVA) { + aHasLava = true; + } + } + ArrayList<ItemStack> aItems = this.getStoredInputs(); + boolean aHasRedstone = false; + if (!aItems.isEmpty()) { + for (ItemStack aItem : aItems) { + if (GT_Utility + .areStacksEqual(aItem, GT_OreDictUnificator.get(OrePrefixes.dust, Materials.Redstone, 1L))) { + aHasRedstone = true; + break; + } + } + } + + if (!aHasWater) { + return SimpleCheckRecipeResult.ofFailure("no_water"); + } + if (!aHasLava) { + return SimpleCheckRecipeResult.ofFailure("no_lava"); + } + ItemStack aGuiCircuit = this.getControllerSlot(); + if (!ItemUtils.isControlCircuit(aGuiCircuit)) { + return CheckRecipeResultRegistry.NO_RECIPE; + } + + if (sRecipe_Cobblestone == null || sRecipe_SmoothStone == null || sRecipe_Redstone == null) { + generateRecipes(); + } + + int aCircuit = aGuiCircuit.getItemDamage(); + + GT_Recipe tRecipe = null; + switch (aCircuit) { + case 1 -> tRecipe = sRecipe_Cobblestone; + case 2 -> tRecipe = sRecipe_SmoothStone; + case 3 -> { + if (aHasRedstone) { + tRecipe = sRecipe_Redstone; + } + } + } + + if (tRecipe == null) { + return CheckRecipeResultRegistry.NO_RECIPE; + } + + ItemStack[] aItemInputs = aItems.toArray(new ItemStack[0]); + FluidStack[] aFluidInputs = new FluidStack[] {}; + + long tEnergy = getMaxInputEnergy(); + // Remember last recipe - an optimization for findRecipe() + this.mLastRecipe = tRecipe; + + GT_ParallelHelper helper = new GT_ParallelHelper().setRecipe(tRecipe) + .setItemInputs(aItemInputs) + .setFluidInputs(aFluidInputs) + .setAvailableEUt(tEnergy) + .setMaxParallel(getMaxParallelRecipes()) + .setConsumption(true) + .setOutputCalculation(true) + .setEUtModifier(0.75F) + .setMachine(this); + + if (batchMode) { + helper.enableBatchMode(128); + } + + helper.build(); + + if (helper.getCurrentParallel() == 0) { + return CheckRecipeResultRegistry.ITEM_OUTPUT_FULL; + } + + this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000); + this.mEfficiencyIncrease = 10000; + + GT_OverclockCalculator calculator = new GT_OverclockCalculator().setRecipeEUt(tRecipe.mEUt) + .setEUt(tEnergy) + .setDuration(tRecipe.mDuration) + .setEUtDiscount(0.75F) + .setSpeedBoost(1F / 3F) + .setParallel((int) Math.floor(helper.getCurrentParallel() / helper.getDurationMultiplierDouble())) + .calculate(); + lEUt = -calculator.getConsumption(); + mMaxProgresstime = (int) Math.ceil(calculator.getDuration() * helper.getDurationMultiplierDouble()); + + mOutputItems = helper.getItemOutputs(); + mOutputFluids = helper.getFluidOutputs(); + updateSlots(); + return CheckRecipeResultRegistry.SUCCESSFUL; + + } + + @Override + public int getMaxParallelRecipes() { + return (8 * GT_Utility.getTier(this.getMaxInputVoltage())); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiIndustrialRockBreaker; + } + + @Override + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public ArrayList<ItemStack> getStoredInputs() { + ArrayList<ItemStack> aInputs = super.getStoredInputs(); + if (this.getControllerSlot() != null) { + aInputs.add(this.getControllerSlot()); + } + return aInputs; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeRocketEngine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeRocketEngine.java new file mode 100644 index 0000000000..e77ac454ee --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeRocketEngine.java @@ -0,0 +1,524 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Dynamo; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_Utility.filterValidMTEs; +import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.AirIntake; +import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTDynamo; + +import java.util.ArrayList; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +import org.jetbrains.annotations.NotNull; + +import com.google.common.collect.ImmutableMap; +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.recipe.check.SimpleCheckRecipeResult; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.shutdown.ShutDownReasonRegistry; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.item.chemistry.RocketFuels; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.MISC_MATERIALS; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_AirIntake; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_LargeRocketEngine + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_LargeRocketEngine> implements ISurvivalConstructable { + + protected int fuelConsumption; + protected int fuelValue; + protected int fuelRemaining; + protected int freeFuelTicks = 0; + protected int euProduction = 0; + protected boolean boostEu; + + public static String mLubricantName = "Carbon Dioxide"; + public static String mCoolantName = "Liquid Hydrogen"; + + public static String mCasingName = "Turbodyne Casing"; + public static String mIntakeHatchName = "Tungstensteel Turbine Casing"; + public static String mGearboxName = "Inconel Reinforced Casing"; + + private static Fluid sAirFluid = null; + private static FluidStack sAirFluidStack = null; + + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_LargeRocketEngine> STRUCTURE_DEFINITION = null; + + private static final int CASING_ID = TAE.getIndexFromPage(3, 11); + + public GregtechMetaTileEntity_LargeRocketEngine(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + this.fuelConsumption = 0; + this.fuelValue = 0; + this.fuelRemaining = 0; + this.boostEu = false; + setAir(); + } + + public GregtechMetaTileEntity_LargeRocketEngine(final String aName) { + super(aName); + this.fuelConsumption = 0; + this.fuelValue = 0; + this.fuelRemaining = 0; + this.boostEu = false; + setAir(); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Large Rocket Engine") + .addInfo("Generating Power from Rocket Fuels - Supports TecTech Multi-Amp Dynamos!") + .addInfo("Supply GT++ Rocket Fuels and 1000L of " + mLubricantName + " per hour") + .addInfo("Produces as much energy as you put fuel in, with optional boosting") + .addInfo("This multi doesn't accept fluids if not enabled - enable it first!") + .addInfo("Consumes 2000L/s of air and pollutes 1500 gibbl/s per 16384 eu/t produced") + .addInfo("Place 1-8 Air Intake Hatches on the sides to maintain Air input") + .addInfo("If it runs out of air, it will shut down and have to be manually restarted") + .addInfo("Supply 3L of " + mCoolantName + " per second, per 1000 EU/t to boost") + .addInfo("Takes 3x the amount of " + mLubricantName + " and maintains efficiency") + .addInfo("Fuel efficiency starts at ~160%, falls more slowly at higher EU/t if boosted") + .addInfo("If producing more than 30k EU/t, fuel efficiency will be lower:") + .addInfo("(These thresholds are 3x higher when boosted, boosted values displayed second)") + .addInfo("- 75% of max fuel efficiency at 53k or 159k EU/t output energy") + .addInfo("- 50% of max fuel efficiency at 69k or 207k EU/t output energy") + .addInfo("- 25% of max fuel efficiency at 98k or 294k EU/t output energy") + .addInfo("formula: x = input of energy (30000^(1/3)/ x^(1/3)) * (80000^(1/3)/ x^(1/3))") + .addSeparator() + .beginStructureBlock(3, 3, 10, false) + .addController("Front Center") + .addCasingInfoMin(mCasingName, 64, false) + .addCasingInfoMin(mGearboxName, 8, false) + .addStructureHint("Air Intake Hatch", 1) + .addInputBus("Side center line", 1) + .addInputHatch("Side center line", 1) + .addMaintenanceHatch("Any Block Touching Inconel Reinforced Casing", 1) + .addDynamoHatch("Top center line", 2) + .addMufflerHatch("Back Center", 3) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_LargeRocketEngine> getStructureDefinition() { + if (this.STRUCTURE_DEFINITION == null) { + this.STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_LargeRocketEngine>builder() + .addShape( + this.mName, + transpose( + new String[][] { { "CTC", "CTC", "CTC", "CTC", "CTC", "CTC", "CTC", "CTC", "CTC", "CTC" }, + { "C~C", "SIS", "SIS", "SIS", "SIS", "SIS", "SIS", "SIS", "SIS", "CMC" }, + { "CCC", "CSC", "CSC", "CSC", "CSC", "CSC", "CSC", "CSC", "CSC", "CCC" }, })) + .addElement('C', ofBlock(getCasingBlock(), getCasingMeta())) + .addElement('I', ofBlock(getGearboxBlock(), getGearboxMeta())) + // side + .addElement( + 'S', + buildHatchAdder(GregtechMetaTileEntity_LargeRocketEngine.class) + .atLeast(ImmutableMap.of(AirIntake, 8, InputBus, 1, InputHatch, 3, Maintenance, 1)) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) + // top + .addElement( + 'T', + buildHatchAdder(GregtechMetaTileEntity_LargeRocketEngine.class) + .atLeast(ImmutableMap.of(AirIntake, 8, Dynamo.or(TTDynamo), 1, Maintenance, 1)) + .casingIndex(getCasingTextureIndex()) + .dot(2) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) + .addElement('M', Muffler.newAny(getCasingTextureIndex(), 3)) + .build(); + } + return this.STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(this.mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + this.mCasing = 0; + this.mTecTechDynamoHatches.clear(); + this.mAllDynamoHatches.clear(); + this.mAirIntakes.clear(); + return checkPiece(this.mName, 1, 1, 0) && this.mCasing >= 64 - 48 + && this.mAirIntakes.size() >= 1 + && checkHatch(); + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return CASING_ID; + } + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + return this.getMaxEfficiency(aStack) > 0; + } + + public static void setAir() { + if (sAirFluidStack == null) { + sAirFluidStack = FluidUtils.getFluidStack("air", 1); + } + if (sAirFluid == null && sAirFluidStack != null) { + sAirFluid = sAirFluidStack.getFluid(); + } + } + + public int getAir() { + setAir(); + if (this.mAirIntakes.isEmpty() || this.mAirIntakes.size() <= 0) { + return 0; + } else { + int totalAir = 0; + for (GT_MetaTileEntity_Hatch_AirIntake u : this.mAirIntakes) { + if (u != null && u.mFluid != null) { + FluidStack f = u.mFluid; + if (f.isFluidEqual(sAirFluidStack)) { + totalAir += f.amount; + } + } + } + return totalAir; + } + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.rocketFuels; + } + + @Override + public @NotNull CheckRecipeResult checkProcessing() { + final ArrayList<FluidStack> tFluids = this.getStoredFluids(); + this.clearRecipeMapForAllInputHatches(); + int aircount = getAir(); + int aAirToConsume = this.euProduction / 100; + if (aircount < aAirToConsume) { + stopMachine(ShutDownReasonRegistry.outOfFluid(new FluidStack(sAirFluid, aAirToConsume))); + return SimpleCheckRecipeResult.ofFailure("no_air"); + } else { + int aTotalAir = 0; + for (GT_MetaTileEntity_Hatch_AirIntake aAirHatch : this.mAirIntakes) { + if (aAirHatch.mFluid != null) { + aTotalAir += aAirHatch.getFluidAmount(); + } + } + if (aTotalAir >= aAirToConsume) { + int aSplitAmount = (aAirToConsume / this.mAirIntakes.size()); + if (aSplitAmount > 0) { + for (GT_MetaTileEntity_Hatch_AirIntake aAirHatch : mAirIntakes) { + boolean hasIntakeAir = aAirHatch.drain(aSplitAmount, true) != null; + if (!hasIntakeAir) { + this.freeFuelTicks = 0; + return SimpleCheckRecipeResult.ofFailure("no_air"); + } + } + } + } + } + // reset fuel ticks in case it does not reset when it stops + if (this.freeFuelTicks != 0 && this.mProgresstime == 0 && this.mEfficiency == 0) this.freeFuelTicks = 0; + + if (tFluids.size() > 0 && getRecipeMap() != null) { + if (this.mRuntime % 72 == 0) { + if (!consumeCO2()) { + this.freeFuelTicks = 0; + return SimpleCheckRecipeResult.ofFailure("no_co2"); + } + } + if (this.freeFuelTicks == 0) { + this.boostEu = consumeLOH(); + } + for (final FluidStack hatchFluid1 : tFluids) { + if (hatchFluid1.isFluidEqual(sAirFluidStack)) { + continue; + } + if (this.freeFuelTicks == 0) { + for (final GT_Recipe aFuel : getRecipeMap().getAllRecipes()) { + final FluidStack tLiquid; + tLiquid = aFuel.mFluidInputs[0]; + if (hatchFluid1.isFluidEqual(tLiquid)) { + if (!consumeFuel(aFuel, hatchFluid1.amount)) { + continue; + } + this.fuelValue = aFuel.mSpecialValue * 3; + this.fuelRemaining = hatchFluid1.amount; + this.lEUt = ((this.mEfficiency < 2000) ? 0 : GT_Values.V[5] << 1); + this.mProgresstime = 1; + this.mMaxProgresstime = 1; + this.mEfficiencyIncrease = this.euProduction / 2000; + return CheckRecipeResultRegistry.GENERATING; + } + } + } else { + this.mEfficiencyIncrease = this.euProduction / 2000; + this.freeFuelTicks--; + this.lEUt = ((this.mEfficiency < 1000) ? 0 : GT_Values.V[5] << 1); + this.mProgresstime = 1; + this.mMaxProgresstime = 1; + return CheckRecipeResultRegistry.GENERATING; + } + } + } + this.lEUt = 0; + this.mEfficiency = 0; + this.freeFuelTicks = 0; + return CheckRecipeResultRegistry.NO_FUEL_FOUND; + } + + /** + * Consumes Fuel if required. Free Fuel Ticks are handled here. + * + * @param aFuel + * @return + */ + public boolean consumeFuel(GT_Recipe aFuel, int amount) { + amount *= this.boostEu ? 0.3 : 0.9; + this.freeFuelTicks = 0; + int value = aFuel.mSpecialValue * 3; + int energy = value * amount; + if (amount < 5) return false; + FluidStack tLiquid = FluidUtils.getFluidStack(aFuel.mFluidInputs[0], (this.boostEu ? amount * 3 : amount)); + if (!this.depleteInput(tLiquid)) { + return false; + } else { + this.fuelConsumption = this.boostEu ? amount * 3 : amount; + this.freeFuelTicks = 20; + setEUProduction(energy); + return true; + } + } + + public void setEUProduction(int energy) { + energy /= 20; + double energyEfficiency; + double tDivideEnergy = Math.cbrt(energy); + if (energy > 30000) { + // cbrt(30 000) / + energyEfficiency = (31.072325 / tDivideEnergy); + if (energy >= 80000) + // cbrt(80 000) / + energyEfficiency *= (43.0886938 / tDivideEnergy); + energyEfficiency *= energy; + } else { + energyEfficiency = energy; + } + this.euProduction = (int) (energyEfficiency); + if (this.boostEu) this.euProduction *= 3; + } + + public boolean consumeCO2() { + return this.depleteInput(MISC_MATERIALS.CARBON_DIOXIDE.getFluidStack(this.boostEu ? 3 : 1)) + || this.depleteInput(FluidUtils.getFluidStack("carbondioxide", (this.boostEu ? 3 : 1))); + } + + public boolean consumeLOH() { + int LOHamount = (3 * this.euProduction) / 1000; + return this.depleteInput(FluidUtils.getFluidStack(RocketFuels.Liquid_Hydrogen, LOHamount)); // (40 * ((long) + // euProduction / + // 10000)) + } + + @Override + public boolean addEnergyOutput(long aEU) { + if (aEU <= 0) { + return true; + } + if (this.mAllDynamoHatches.size() > 0) { + return addEnergyOutputMultipleDynamos(aEU, true); + } + return false; + } + + @Override + public boolean addEnergyOutputMultipleDynamos(long aEU, boolean aAllowMixedVoltageDynamos) { + int injected = 0; + long totalOutput = 0; + long aFirstVoltageFound = -1; + boolean aFoundMixedDynamos = false; + for (GT_MetaTileEntity_Hatch aDynamo : filterValidMTEs(this.mAllDynamoHatches)) { + long aVoltage = aDynamo.maxEUOutput(); + long aTotal = aDynamo.maxAmperesOut() * aVoltage; + // Check against voltage to check when hatch mixing + if (aFirstVoltageFound == -1) { + aFirstVoltageFound = aVoltage; + } else { + if (aFirstVoltageFound != aVoltage) { + aFoundMixedDynamos = true; + } + } + totalOutput += aTotal; + } + + if (totalOutput < aEU || (aFoundMixedDynamos && !aAllowMixedVoltageDynamos)) { + explodeMultiblock(); + return false; + } + + long leftToInject; + long aVoltage; + int aAmpsToInject; + int aRemainder; + + for (GT_MetaTileEntity_Hatch aDynamo : filterValidMTEs(this.mAllDynamoHatches)) { + leftToInject = aEU - injected; + aVoltage = aDynamo.maxEUOutput(); + aAmpsToInject = (int) (leftToInject / aVoltage); + aRemainder = (int) (leftToInject - (aAmpsToInject * aVoltage)); + long powerGain; + for (int i = 0; i < Math.min(aDynamo.maxAmperesOut(), aAmpsToInject + 1); i++) { + if (i == Math.min(aDynamo.maxAmperesOut(), aAmpsToInject)) { + powerGain = aRemainder; + } else { + powerGain = aVoltage; + } + aDynamo.getBaseMetaTileEntity() + .increaseStoredEnergyUnits(powerGain, false); + injected += powerGain; + } + } + return injected > 0; + } + + public Block getCasingBlock() { + return ModBlocks.blockCasings4Misc; + } + + public byte getCasingMeta() { + return 11; + } + + public Block getGearboxBlock() { + return ModBlocks.blockCasings3Misc; + } + + public byte getGearboxMeta() { + return 1; + } + + public byte getCasingTextureIndex() { + return (byte) CASING_ID; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_LargeRocketEngine(this.mName); + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setInteger("freeFuelTicks", this.freeFuelTicks); + aNBT.setInteger("euProduction", this.euProduction); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.freeFuelTicks = aNBT.getInteger("freeFuelTicks"); + this.euProduction = aNBT.getInteger("euProduction"); + } + + @Override + public int getDamageToComponent(final ItemStack aStack) { + return 1; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return this.euProduction; + } + + @Override + public int getPollutionPerTick(final ItemStack aStack) { + return 75 * (this.euProduction / 10000); + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return true; + } + + @Override + public String[] getExtraInfoData() { + return new String[] { "Rocket Engine", "Current Air: " + getAir(), + "Current Pollution: " + getPollutionPerTick(null), + "Time until next fuel consumption: " + this.freeFuelTicks, + "Current Output: " + this.lEUt * this.mEfficiency / 10000 + " EU/t", + "Fuel Consumption: " + (this.fuelConsumption) + "L/s", "Fuel Value: " + this.fuelValue + " EU/L", + "Fuel Remaining: " + this.fuelRemaining + " Litres", "Current Efficiency: " + this.mEfficiency / 100 + "%", + (this.getIdealStatus() == this.getRepairStatus()) ? "No Maintainance issues" : "Needs Maintainance" }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public String getMachineType() { + return "Rocket Engine"; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public boolean doesBindPlayerInventory() { + return false; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeSemifluidGenerator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeSemifluidGenerator.java new file mode 100644 index 0000000000..4403779d09 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_LargeSemifluidGenerator.java @@ -0,0 +1,332 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Dynamo; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTDynamo; + +import java.util.ArrayList; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.FluidStack; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.Materials; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Dynamo; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Maintenance; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffler; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.recipe.check.SimpleCheckRecipeResult; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; + +public class GregtechMetaTileEntity_LargeSemifluidGenerator extends + GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_LargeSemifluidGenerator> implements ISurvivalConstructable { + + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_LargeSemifluidGenerator> STRUCTURE_DEFINITION = null; + + protected int fuelConsumption = 0; + protected int fuelValue = 0; + protected int fuelRemaining = 0; + protected boolean boostEu = false; + + public GregtechMetaTileEntity_LargeSemifluidGenerator(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_LargeSemifluidGenerator(String aName) { + super(aName); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Large Semifluid Generator") + .addInfo("Engine Intake Casings must not be obstructed in front (only air blocks)") + .addInfo("Supply Semifluid Fuels and 2000L of Lubricant per hour to run.") + .addInfo("Supply 80L of Oxygen per second to boost output (optional).") + .addInfo("Default: Produces 2048EU/t at 100% efficiency") + .addInfo("Boosted: Produces 6144EU/t at 150% efficiency") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 3, 4, false) + .addController("Front Center") + .addCasingInfoMin("Stable Titanium Machine Casing", 16, false) + .addCasingInfoMin("Steel Gear Box Machine Casing", 2, false) + .addCasingInfoMin("Engine Intake Machine Casing", 8, false) + .addInputHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .addDynamoHatch("Back Center", 2) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + protected IIconContainer getActiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_DIESEL_ENGINE_ACTIVE; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_DIESEL_ENGINE; + } + + @Override + protected int getCasingTextureId() { + return 50; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return getMaxEfficiency(aStack) > 0; + } + + @Override + public @NotNull CheckRecipeResult checkProcessing() { + ArrayList<FluidStack> tFluids = getStoredFluids(); + + // Check for lubricant and oxygen first, so we can compute costs ahead of time. + // This will allow us to check costs without needing to actually try to deplete fluids + // (wasting earlier fluids in the check if later fluids turn out to be insufficient). + FluidStack lubricant = Materials.Lubricant.getFluid(0L); + FluidStack oxygen = Materials.Oxygen.getGas(0L); + for (FluidStack hatchFluid : tFluids) { + if (hatchFluid.isFluidEqual(lubricant)) { + lubricant.amount = Math.max(lubricant.amount, hatchFluid.amount); + } else if (hatchFluid.isFluidEqual(oxygen)) { + oxygen.amount = Math.max(oxygen.amount, hatchFluid.amount); + } + } + boostEu = oxygen.amount >= 4L; + long lubricantCost = boostEu ? 2L : 1L; + if (lubricant.amount < lubricantCost) { + return SimpleCheckRecipeResult.ofFailure("no_lubricant"); + } + + for (FluidStack hatchFluid : tFluids) { // Loops through hatches + GT_Recipe aFuel = GTPPRecipeMaps.semiFluidFuels.getBackend() + .findFuel(hatchFluid); + if (aFuel == null) { + // Not a valid semi-fluid fuel. + continue; + } + + int newEUt = boostEu ? 4096 : 2048; + fuelConsumption = newEUt / aFuel.mSpecialValue; // Calc fuel consumption + FluidStack tLiquid = new FluidStack(hatchFluid.getFluid(), fuelConsumption); + if (depleteInput(tLiquid)) { // Deplete that amount + // We checked beforehand, so both of these depletions should succeed. + // But check the return values anyway just to be safe. + if (boostEu) { + if (!depleteInput(Materials.Oxygen.getGas(4L))) { + return SimpleCheckRecipeResult.ofFailure("no_oxygen"); + } + } + // Deplete Lubricant. 2000L should = 1 hour of runtime (if baseEU = 2048) + if (mRuntime % 72 == 0 || mRuntime == 0) { + if (!depleteInput(Materials.Lubricant.getFluid(lubricantCost))) { + return SimpleCheckRecipeResult.ofFailure("no_lubricant"); + } + } + + fuelValue = aFuel.mSpecialValue; + fuelRemaining = hatchFluid.amount; // Record available fuel + this.lEUt = mEfficiency < 2000 ? 0 : newEUt; // Output 0 if startup is less than 20% + this.mProgresstime = 1; + this.mMaxProgresstime = 1; + this.mEfficiencyIncrease = 15; + return CheckRecipeResultRegistry.GENERATING; + } + } + + this.lEUt = 0; + this.mEfficiency = 0; + return CheckRecipeResultRegistry.NO_FUEL_FOUND; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_LargeSemifluidGenerator> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_LargeSemifluidGenerator>builder() + .addShape( + mName, + transpose( + new String[][] { { "III", "CCC", "CCC", "CCC" }, { "I~I", "CGC", "CGC", "CMC" }, + { "III", "CCC", "CCC", "CCC" }, })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_LargeSemifluidGenerator.class) + .atLeast(Muffler, InputHatch, Maintenance) + .casingIndex(getCasingTextureIndex()) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(getCasingBlock(), getCasingMeta())))) + .addElement('G', ofBlock(getGearboxBlock(), getGearboxMeta())) + .addElement('I', ofBlock(getIntakeBlock(), getIntakeMeta())) + .addElement( + 'M', + Dynamo.or(TTDynamo) + .newAny(getCasingTextureIndex(), 2)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 1, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mDynamoHatches.clear(); + return checkPiece(mName, 1, 1, 0) && mCasing >= 16 && checkHatch(); + } + + public final boolean addLargeSemifluidGeneratorList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + public final boolean addLargeSemifluidGeneratorBackList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo || this.isThisHatchMultiDynamo(aTileEntity)) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + public Block getCasingBlock() { + return GregTech_API.sBlockCasings4; + } + + public byte getCasingMeta() { + return 2; + } + + public Block getIntakeBlock() { + return GregTech_API.sBlockCasings4; + } + + public byte getIntakeMeta() { + return 13; + } + + public Block getGearboxBlock() { + return GregTech_API.sBlockCasings2; + } + + public byte getGearboxMeta() { + return 3; + } + + public byte getCasingTextureIndex() { + return 50; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_LargeSemifluidGenerator(this.mName); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 1; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return boostEu ? 15000 : 10000; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiLargeSemiFluidGenerator; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return true; + } + + @Override + public String[] getExtraInfoData() { + return new String[] { "Large Semifluid Generator", "Current Output: " + lEUt * mEfficiency / 10000 + " EU/t", + "Fuel Consumption: " + fuelConsumption + "L/t", "Fuel Value: " + fuelValue + " EU/L", + "Fuel Remaining: " + fuelRemaining + " Litres", "Current Efficiency: " + (mEfficiency / 100) + "%", + getIdealStatus() == getRepairStatus() ? "No Maintainance issues" : "Needs Maintainance" }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public String getMachineType() { + return "Semifluid Generator"; + } + + @Override + public int getMaxParallelRecipes() { + return 0; + } + +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java new file mode 100644 index 0000000000..69042b7982 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_MassFabricator.java @@ -0,0 +1,337 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import java.util.Arrays; +import java.util.Collection; +import java.util.stream.Stream; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.ConfigCategories; +import gregtech.api.enums.Materials; +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.recipe.check.SimpleCheckRecipeResult; +import gregtech.api.util.GT_Config; +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 gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.minecraft.MaterialUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaTileEntity_MassFabricator + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_MassFabricator> implements ISurvivalConstructable { + + public static int sUUAperUUM = 1; + public static int sUUASpeedBonus = 4; + public static int sDurationMultiplier = 3200; + + public static String mCasingName1 = "Matter Fabricator Casing"; + public static String mCasingName2 = "Containment Casing"; + public static String mCasingName3 = "Matter Generation Coil"; + + private int mMode = 0; + + private static final int MODE_SCRAP = 1; + private static final int MODE_UU = 0; + + public static boolean sRequiresUUA = false; + private static final FluidStack[] mUU = new FluidStack[2]; + private static final ItemStack[] mScrap = new ItemStack[2]; + + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_MassFabricator> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_MassFabricator(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_MassFabricator(final String aName) { + super(aName); + } + + @Override + public String getMachineType() { + return "Mass Fabricator / Recycler"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Matter Fabricator") + .addInfo("Speed: +0% | EU Usage: 80%") + .addInfo("Parallel: Scrap = 64 | UU = 8 * Tier") + .addInfo("Produces UU-A, UU-M & Scrap") + .addInfo("Change mode with screwdriver") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(5, 4, 5, true) + .addController("Front Center") + .addCasingInfoMin(mCasingName3, 9, false) + .addCasingInfoMin(mCasingName2, 24, false) + .addCasingInfoMin(mCasingName1, 36, false) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .addOutputHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addMaintenanceHatch("Any Casing", 1) + .addMufflerHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_MatterFab_Active_Animated; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_MatterFab_Animated; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(9); + } + + @Override + public void onConfigLoad(final GT_Config aConfig) { + super.onConfigLoad(aConfig); + sDurationMultiplier = aConfig + .get(ConfigCategories.machineconfig, "Massfabricator.UUM_Duration_Multiplier", sDurationMultiplier); + sUUAperUUM = aConfig.get(ConfigCategories.machineconfig, "Massfabricator.UUA_per_UUM", sUUAperUUM); + sUUASpeedBonus = aConfig.get(ConfigCategories.machineconfig, "Massfabricator.UUA_Speed_Bonus", sUUASpeedBonus); + sRequiresUUA = aConfig.get(ConfigCategories.machineconfig, "Massfabricator.UUA_Requirement", sRequiresUUA); + // Materials.UUAmplifier.mChemicalFormula = ("Mass Fabricator Eff/Speed Bonus: x" + sUUASpeedBonus); + } + + public static boolean sInit = false; + + public static void init() { + if (!sInit) { + if (mScrap[0] == null) { + mScrap[0] = ItemUtils.getSimpleStack(ItemUtils.getItemFromFQRN("IC2:itemScrap")); + } + if (mScrap[1] == null) { + mScrap[1] = ItemUtils.getSimpleStack(ItemUtils.getItemFromFQRN("IC2:itemScrapbox")); + } + if (mUU[0] == null) { + mUU[0] = Materials.UUAmplifier.getFluid(100); + } + if (mUU[1] == null) { + mUU[1] = Materials.UUMatter.getFluid(100); + } + sInit = true; + } + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_MassFabricator> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_MassFabricator>builder() + .addShape( + mName, + transpose( + new String[][] { { "CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC" }, + { "CGGGC", "G---G", "G---G", "G---G", "CGGGC" }, + { "CGGGC", "G---G", "G---G", "G---G", "CGGGC" }, + { "CC~CC", "CHHHC", "CHHHC", "CHHHC", "CCCCC" }, })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_MassFabricator.class) + .atLeast(InputBus, OutputBus, InputHatch, OutputHatch, Maintenance, Energy, Muffler) + .casingIndex(TAE.GTPP_INDEX(9)) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasingsMisc, 9)))) + .addElement('H', ofBlock(ModBlocks.blockCasingsMisc, 8)) + .addElement('G', ofBlock(ModBlocks.blockCasings3Misc, 15)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 2, 3, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 2, 3, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + return checkPiece(mName, 2, 3, 0) && mCasing >= 36 && checkHatch(); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiMassFabricator; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_MassFabricator(this.mName); + } + + /** + * Special Recipe Handling + */ + @Override + public RecipeMap<?> getRecipeMap() { + return this.mMode == MODE_SCRAP ? RecipeMaps.recyclerRecipes : GTPPRecipeMaps.multiblockMassFabricatorRecipes; + } + + @Nonnull + @Override + public Collection<RecipeMap<?>> getAvailableRecipeMaps() { + return Arrays.asList(RecipeMaps.recyclerRecipes, GTPPRecipeMaps.multiblockMassFabricatorRecipes); + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic() { + + @NotNull + @Override + public CheckRecipeResult process() { + init(); + return super.process(); + } + + @NotNull + @Override + protected CheckRecipeResult validateRecipe(@NotNull GT_Recipe recipe) { + if (mMode == MODE_SCRAP) { + if (recipe.mOutputs == null) { + return SimpleCheckRecipeResult.ofSuccess("no_scrap"); + } + } + return CheckRecipeResultRegistry.SUCCESSFUL; + } + + @Nonnull + @Override + protected Stream<GT_Recipe> findRecipeMatches(@Nullable RecipeMap<?> map) { + if (mMode == MODE_SCRAP) { + if (inputItems != null) { + for (ItemStack item : inputItems) { + if (item == null || item.stackSize == 0) continue; + ItemStack aPotentialOutput = GT_ModHandler + .getRecyclerOutput(GT_Utility.copyAmount(1, item), 0); + GT_Recipe recipe = new GT_Recipe( + false, + new ItemStack[] { GT_Utility.copyAmount(1, item) }, + aPotentialOutput == null ? null : new ItemStack[] { aPotentialOutput }, + null, + new int[] { 2000 }, + null, + null, + 40, + MaterialUtils.getVoltageForTier(1), + 0); + return Stream.of(recipe); + } + } + return Stream.empty(); + } + return super.findRecipeMatches(map); + } + }.setEuModifier(0.8F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + protected void setupProcessingLogic(ProcessingLogic logic) { + super.setupProcessingLogic(logic); + logic.enablePerfectOverclock(); + } + + @Override + public int getMaxParallelRecipes() { + return this.mMode == MODE_SCRAP ? 64 : 8 * (Math.max(1, GT_Utility.getTier(getMaxInputVoltage()))); + } + + @Override + public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + int aMode = this.mMode + 1; + if (aMode > 1) { + this.mMode = MODE_UU; + PlayerUtils.messagePlayer(aPlayer, "Mode [" + this.mMode + "]: Matter/AmpliFabricator"); + } else if (aMode == 1) { + this.mMode = MODE_SCRAP; + PlayerUtils.messagePlayer(aPlayer, "Mode [" + this.mMode + "]: Recycler"); + } else { + this.mMode = MODE_SCRAP; + PlayerUtils.messagePlayer(aPlayer, "Mode [" + this.mMode + "]: Recycler"); + } + mLastRecipe = null; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mMode", mMode); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + mMode = aNBT.getInteger("mMode"); + super.loadNBTData(aNBT); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_QuantumForceTransformer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_QuantumForceTransformer.java new file mode 100644 index 0000000000..bd5e579cd2 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_QuantumForceTransformer.java @@ -0,0 +1,939 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.withChannel; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.ExoticEnergy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_OreDictUnificator.getAssociation; +import static gregtech.api.util.GT_ParallelHelper.addFluidsLong; +import static gregtech.api.util.GT_ParallelHelper.addItemsLong; +import static gregtech.api.util.GT_ParallelHelper.calculateChancedOutputMultiplier; +import static gregtech.api.util.GT_RecipeBuilder.BUCKETS; +import static gregtech.api.util.GT_RecipeBuilder.INGOTS; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.annotation.Nonnull; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; +import net.minecraft.util.StatCollector; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +import org.apache.commons.lang3.tuple.Pair; +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.ITierConverter; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureUtility; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Materials; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_ExtendedPowerMultiBlockBase; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.objects.ItemData; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.recipe.check.SimpleCheckRecipeResult; +import gregtech.api.render.TextureFactory; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_ParallelHelper; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.shutdown.ShutDownReasonRegistry; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.material.ELEMENT; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +@SuppressWarnings("SpellCheckingInspection") +public class GregtechMetaTileEntity_QuantumForceTransformer + extends GT_MetaTileEntity_ExtendedPowerMultiBlockBase<GregtechMetaTileEntity_QuantumForceTransformer> + implements ISurvivalConstructable { + + private int mCasing; + protected int mCraftingTier = 0; + protected int mFocusingTier = 0; + protected int mMaxParallel = 0; + private boolean mFluidMode = false, doFermium = false, doNeptunium = false; + private static final Fluid mNeptunium = ELEMENT.getInstance().NEPTUNIUM.getPlasma(); + private static final Fluid mFermium = ELEMENT.getInstance().FERMIUM.getPlasma(); + private static final String MAIN_PIECE = "main"; + private GT_MetaTileEntity_Hatch_Input mNeptuniumHatch; + private GT_MetaTileEntity_Hatch_Input mFermiumHatch; + private static final IStructureDefinition<GregtechMetaTileEntity_QuantumForceTransformer> STRUCTURE_DEFINITION = StructureDefinition + .<GregtechMetaTileEntity_QuantumForceTransformer>builder() + .addShape( + MAIN_PIECE, + new String[][] { // A - 142, B - 234, C - 177, D - 96, E - 224, H - 36, M - 21 + { " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", + " ", " ", " ", " BAB ", " BBBBABBBB ", + " BAAAAAAAB ", " BABBABBAB ", " BA AB ", " A A ", " A A ", + " A A " }, + { " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", + " ", " ", " BAB ", " AAABBBAAA ", " BAAAAAAAAAB ", + " B B ", " A A ", " A A ", " ", " ", + " " }, + { " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", + " ", " BAB ", " AA AA ", " AA AA ", " BAA AAB ", + " B B ", " A A ", " A A ", " ", " ", + " " }, + { " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", + " ", " BAAAB ", " AA AA ", " AA AA ", "BAA AAB", + "B B", "A A", "A A", "A A", "A A", + "A A" }, + { " TTT ", " EEE ", " EEE ", " EEE ", " DDD ", + " EEE ", " DDD ", " EEE ", " EEE ", " EEE ", + " DDD ", " BAEEEAB ", " AA EEE AA ", " A EEE A ", "BA DDD AB", + "B EEE B", "B DDD B", " EEE ", " EEE ", " EEE ", + " Z~X " }, + { " TTTTT ", " ECCCE ", " ECCCE ", " ECCCE ", " D D ", + " ECCCE ", " D D ", " ECCCE ", " ECCCE ", " ECCCE ", + " D D ", " BAECCCEAB ", " A ECCCE A ", " A ECCCE A ", "BA D D AB", + "B ECCCE B", "B D D B", "B ECCCE B", " ECCCE ", " ECCCE ", + " HHHHH " }, + { " TTTTTTT ", " ECCCCCE ", " EC CE ", " EC CE ", " D D ", + " EC CE ", " D D ", " EC CE ", " EC CE ", " EC CE ", + " D D ", " BAEC CEAB ", " B EC CE B ", "BB EC CE BB", "BA D D AB", + "A EC CE A", "A D D A", "A EC CE A", " EC CE ", " EC CE ", + " HHHHHHH " }, + { " TTTTTTT ", " ECCCCCE ", " EC CE ", " EC CE ", " D D ", + " EC CE ", " D D ", " EC CE ", " EC CE ", " EC CE ", + " D D ", " AAEC CEAA ", " A EC CE A ", "AB EC CE BA", "AA D D AA", + "A EC CE A", "A D D A", " EC CE ", " EC CE ", " EC CE ", + " HHHHHHH " }, + { " TTTTTTT ", " ECCCCCE ", " EC CE ", " EC CE ", " D D ", + " EC CE ", " D D ", " EC CE ", " EC CE ", " EC CE ", + " D D ", " BAEC CEAB ", " B EC CE B ", "BB EC CE BB", "BA D D AB", + "A EC CE A", "A D D A", "A EC CE A", " EC CE ", " EC CE ", + " HHHHHHH " }, + { " TTTTT ", " ECCCE ", " ECCCE ", " ECCCE ", " D D ", + " ECCCE ", " D D ", " ECCCE ", " ECCCE ", " ECCCE ", + " D D ", " BAECCCEAB ", " A ECCCE A ", " A ECCCE A ", "BA D D AB", + "B ECCCE B", "B D D B", "B ECCCE B", " ECCCE ", " ECCCE ", + " HHHHH " }, + { " TTT ", " EEE ", " EEE ", " EEE ", " DDD ", + " EEE ", " DDD ", " EEE ", " EEE ", " EEE ", + " DDD ", " BAEEEAB ", " AA EEE AA ", " A EEE A ", "BA DDD AB", + "B EEE B", "B DDD B", " EEE ", " EEE ", " EEE ", + " HHH " }, + { " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", + " ", " BAAAB ", " AA AA ", " AA AA ", "BAA AAB", + "B B", "A A", "A A", "A A", "A A", + "A A" }, + { " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", + " ", " BAB ", " AA AA ", " AA AA ", " BAA AAB ", + " B B ", " A A ", " A A ", " ", " ", + " " }, + { " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", + " ", " ", " BAB ", " AAABBBAAA ", " BAAAAAAAAAB ", + " B B ", " A A ", " A A ", " ", " ", + " " }, + { " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", + " ", " ", " ", " BAB ", " BBBBABBBB ", + " BBBAAABBB ", " ABBAAABBA ", " A BA AB A ", " A A ", " A A ", + " A A " }, }) + .addElement( + 'A', + withChannel( + "manipulator", + StructureUtility.ofBlocksTiered( + craftingTierConverter(), + getAllCraftingTiers(), + 0, + GregtechMetaTileEntity_QuantumForceTransformer::setCraftingTier, + GregtechMetaTileEntity_QuantumForceTransformer::getCraftingTier))) + .addElement( + 'B', + withChannel( + "shielding", + StructureUtility.ofBlocksTiered( + focusingTierConverter(), + getAllFocusingTiers(), + 0, + GregtechMetaTileEntity_QuantumForceTransformer::setFocusingTier, + GregtechMetaTileEntity_QuantumForceTransformer::getFocusingTier))) + .addElement('C', ofBlock(ModBlocks.blockCasings4Misc, 4)) + .addElement('D', ofBlock(ModBlocks.blockCasings2Misc, 12)) + .addElement('E', lazy(t -> ofBlock(t.getCasingBlock1(), t.getCasingMeta1()))) + .addElement( + 'H', + buildHatchAdder(GregtechMetaTileEntity_QuantumForceTransformer.class) + .atLeast(InputBus, InputHatch, Maintenance, Energy.or(ExoticEnergy)) + .casingIndex(TAE.getIndexFromPage(0, 10)) + .dot(4) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 12)))) + .addElement( + 'T', + buildHatchAdder(GregtechMetaTileEntity_QuantumForceTransformer.class) + .atLeast(OutputBus, OutputHatch, Maintenance) + .casingIndex(TAE.getIndexFromPage(0, 10)) + .dot(5) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 12)))) + .addElement( + 'Z', + buildHatchAdder(GregtechMetaTileEntity_QuantumForceTransformer.class) + .hatchClass(GT_MetaTileEntity_Hatch_Input.class) + .adder(GregtechMetaTileEntity_QuantumForceTransformer::addNeptuniumHatch) + .casingIndex(TAE.getIndexFromPage(0, 10)) + .dot(5) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 12)))) + .addElement( + 'X', + buildHatchAdder(GregtechMetaTileEntity_QuantumForceTransformer.class) + .hatchClass(GT_MetaTileEntity_Hatch_Input.class) + .adder(GregtechMetaTileEntity_QuantumForceTransformer::addFermiumHatch) + .casingIndex(TAE.getIndexFromPage(0, 10)) + .dot(5) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 12)))) + .build(); + + public GregtechMetaTileEntity_QuantumForceTransformer(final int aID, final String aName, + final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_QuantumForceTransformer(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_QuantumForceTransformer(this.mName); + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType("Quantum Force Transformer") + .addInfo("Controller Block for the Quantum Force Transformer") + .addInfo("Allows Complex chemical lines to be performed instantly in one step") + .addInfo("Every recipe requires a catalyst, each catalyst adds 1 parallel and lasts forever") + .addInfo("Accepts TecTech Energy and Laser Hatches") + .addInfo("All inputs go on the bottom, all outputs go on the top") + .addInfo("Put a circuit in the controller to specify the focused output") + .addInfo("Check NEI to see the order of outputs, and which circuit number you need.") + .addInfo("If separate input busses are enabled put the circuit in the circuit slot of the bus") + .addInfo("Uses FocusTier*4*sqrt(parallels) Neptunium Plasma if focusing") + .addInfo("Can use FocusTier*4*sqrt(parallels) Fermium Plasma for additional chance output") + .addInfo("Use a screwdriver to enable Fluid mode") + .addInfo( + "Fluid mode turns all possible outputs into their fluid variant, those which can't are left as they were.") + .addInfo("This multi gets improved when all casings of some types are upgraded") + .addInfo("Casing functions:") + .addInfo("Pulse Manipulators: Recipe Tier Allowed (check NEI for the tier of each recipe)") + .addInfo("Shielding Cores: Focusing Tier (equal to or higher than recipe tier to allow focus)") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(15, 21, 15, true) + .addController("Bottom Center") + .addCasingInfoMin("Bulk Production Frame", 80, false) + .addCasingInfoMin("Quantum Force Conductor", 177, false) + .addCasingInfoMin("Force Field Glass", 224, false) + .addCasingInfoMin("Pulse Manipulators", 236, true) + .addCasingInfoMin("Shielding Cores", 142, true) + .addInputBus(EnumChatFormatting.BLUE + "Bottom" + EnumChatFormatting.GRAY + " Layer", 4) + .addInputHatch(EnumChatFormatting.BLUE + "Bottom" + EnumChatFormatting.GRAY + " Layer", 4) + .addOutputHatch(EnumChatFormatting.AQUA + "Top" + EnumChatFormatting.GRAY + " Layer", 5) + .addOutputBus(EnumChatFormatting.AQUA + "Top" + EnumChatFormatting.GRAY + " Layer", 5) + .addEnergyHatch(EnumChatFormatting.BLUE + "Bottom" + EnumChatFormatting.GRAY + " Layer", 4) + .addMaintenanceHatch( + EnumChatFormatting.BLUE + "Bottom" + + EnumChatFormatting.GRAY + + " or " + + EnumChatFormatting.AQUA + + "Top" + + EnumChatFormatting.GRAY + + " Layer", + 4, + 5) + .addStructureInfo( + EnumChatFormatting.WHITE + "Neptunium Plasma Hatch: " + + EnumChatFormatting.GREEN + + "Left" + + EnumChatFormatting.GRAY + + " side of Controller") + .addStructureInfo( + EnumChatFormatting.WHITE + "Fermium Plasma Hatch: " + + EnumChatFormatting.DARK_GREEN + + "Right" + + EnumChatFormatting.GRAY + + " side of Controller") + .toolTipFinisher( + GT_Values.AuthorBlueWeabo + EnumChatFormatting.RESET + + EnumChatFormatting.GREEN + + " + Steelux" + + EnumChatFormatting.RESET + + " - [GT++]"); + return tt; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_QuantumForceTransformer> getStructureDefinition() { + return STRUCTURE_DEFINITION; + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + this.mCasing = 0; + this.mCraftingTier = 0; + this.mFocusingTier = 0; + if (!checkPiece(MAIN_PIECE, 7, 20, 4)) { + return false; + } + + if (mMaintenanceHatches.size() != 1 || mOutputBusses.isEmpty() || mOutputHatches.isEmpty()) { + return false; + } + + return checkExoticAndNormalEnergyHatches(); + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(MAIN_PIECE, stackSize, hintsOnly, 7, 20, 4); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(MAIN_PIECE, stackSize, 7, 20, 4, elementBudget, env, false, true); + } + + public static List<Pair<Block, Integer>> getAllCraftingTiers() { + return new ArrayList<>() { + + { + add(Pair.of(ModBlocks.blockCasings5Misc, 7)); + add(Pair.of(ModBlocks.blockCasings5Misc, 8)); + add(Pair.of(ModBlocks.blockCasings5Misc, 9)); + add(Pair.of(ModBlocks.blockCasings5Misc, 10)); + } + }; + } + + public static List<Pair<Block, Integer>> getAllFocusingTiers() { + return new ArrayList<>() { + + { + add(Pair.of(ModBlocks.blockCasings5Misc, 11)); + add(Pair.of(ModBlocks.blockCasings5Misc, 12)); + add(Pair.of(ModBlocks.blockCasings5Misc, 13)); + add(Pair.of(ModBlocks.blockCasings5Misc, 14)); + } + }; + } + + public static ITierConverter<Integer> craftingTierConverter() { + return (block, meta) -> { + if (block == null) { + return -1; + } else if (block == ModBlocks.blockCasings5Misc) { // Resonance Chambers + switch (meta) { + case 7 -> { + return 1; + } + case 8 -> { + return 2; + } + case 9 -> { + return 3; + } + case 10 -> { + return 4; + } + } + } + return -1; + }; + } + + public static ITierConverter<Integer> focusingTierConverter() { + return (block, meta) -> { + if (block == null) { + return -1; + } else if (block == ModBlocks.blockCasings5Misc) { // Generation Coils + switch (meta) { + case 11 -> { + return 1; + } + case 12 -> { + return 2; + } + case 13 -> { + return 3; + } + case 14 -> { + return 4; + } + } + } + return -1; + }; + } + + private void setCraftingTier(int tier) { + mCraftingTier = tier; + } + + private void setFocusingTier(int tier) { + mFocusingTier = tier; + } + + private int getCraftingTier() { + return mCraftingTier; + } + + private int getFocusingTier() { + return mFocusingTier; + } + + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + protected int getCasingTextureId() { + return TAE.getIndexFromPage(0, 10); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.quantumForceTransformerRecipes; + } + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + return true; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic() { + + private int[] chances; + private FluidStack[] fluidModeItems; + + @NotNull + @Override + protected CheckRecipeResult validateRecipe(@NotNull GT_Recipe recipe) { + if (recipe.mSpecialValue > getCraftingTier()) { + return CheckRecipeResultRegistry.insufficientMachineTier(recipe.mSpecialValue); + } + ItemStack catalyst = null; + for (ItemStack item : recipe.mInputs) { + if (ItemUtils.isCatalyst(item)) { + catalyst = item; + break; + } + } + + if (catalyst == null) { + return SimpleCheckRecipeResult.ofFailure("no_catalyst"); + } + + maxParallel = 0; + for (ItemStack item : inputItems) { + if (ItemUtils.isCatalyst(item) && item.isItemEqual(catalyst)) { + maxParallel += item.stackSize; + } + } + + mMaxParallel = maxParallel; + doFermium = false; + doNeptunium = false; + + if (recipe.mSpecialValue <= getFocusingTier()) { + if (drain(mFermiumHatch, new FluidStack(mFermium, 1), false)) { + doFermium = true; + } + if (drain(mNeptuniumHatch, new FluidStack(mNeptunium, 1), false)) { + doNeptunium = true; + } + } + + chances = getOutputChances(recipe, doNeptunium ? findProgrammedCircuitNumber() : -1); + + // Handle Fluid Mode. Add fluid that item can be turned into to fluidModeItems. + // null if Fluid Mode is disabled or item cannot be turned into fluid. + fluidModeItems = new FluidStack[recipe.mOutputs.length]; + if (mFluidMode) { + for (int i = 0; i < recipe.mOutputs.length; i++) { + ItemStack item = recipe.getOutput(i); + if (item == null) continue; + ItemData data = getAssociation(item); + Materials mat = data == null ? null : data.mMaterial.mMaterial; + if (mat != null) { + if (mat.mStandardMoltenFluid != null) { + fluidModeItems[i] = mat.getMolten(INGOTS); + } else if (mat.mFluid != null) { + fluidModeItems[i] = mat.getFluid(BUCKETS); + } + } + } + } + + return CheckRecipeResultRegistry.SUCCESSFUL; + } + + @NotNull + @Override + public GT_ParallelHelper createParallelHelper(@Nonnull GT_Recipe recipe) { + return super.createParallelHelper(recipe).setCustomItemOutputCalculation(parallel -> { + ArrayList<ItemStack> items = new ArrayList<>(); + + for (int i = 0; i < recipe.mOutputs.length; i++) { + ItemStack item = recipe.getOutput(i); + if (item == null || fluidModeItems[i] != null) continue; + ItemStack itemToAdd = item.copy(); + double outputMultiplier = calculateChancedOutputMultiplier(chances[i], parallel); + long itemAmount = (long) (item.stackSize * outputMultiplier); + addItemsLong(items, itemToAdd, itemAmount); + } + + return items.toArray(new ItemStack[0]); + }) + .setCustomFluidOutputCalculation(parallel -> { + ArrayList<FluidStack> fluids = new ArrayList<>(); + + if (mFluidMode) { + for (int i = 0; i < recipe.mOutputs.length; i++) { + FluidStack fluid = fluidModeItems[i]; + if (fluid == null) continue; + FluidStack fluidToAdd = fluid.copy(); + double outputMultiplier = calculateChancedOutputMultiplier(chances[i], parallel); + int itemAmount = recipe.mOutputs[i].stackSize; + long fluidAmount = (long) (fluidToAdd.amount * outputMultiplier * itemAmount); + addFluidsLong(fluids, fluidToAdd, fluidAmount); + } + } + + for (int i = 0; i < recipe.mFluidOutputs.length; i++) { + FluidStack fluid = recipe.getFluidOutput(i); + if (fluid == null) continue; + FluidStack fluidToAdd = fluid.copy(); + double outputMultiplier = calculateChancedOutputMultiplier( + chances[i + recipe.mOutputs.length], + parallel); + long fluidAmount = (long) (fluidToAdd.amount * outputMultiplier); + addFluidsLong(fluids, fluidToAdd, fluidAmount); + } + + return fluids.toArray(new FluidStack[0]); + }); + } + + private int findProgrammedCircuitNumber() { + if (isInputSeparationEnabled()) { + for (ItemStack stack : inputItems) { + if (GT_Utility.isAnyIntegratedCircuit(stack)) { + return stack.getItemDamage() - 1; + } + } + return -1; + } else { + final ItemStack controllerStack = getControllerSlot(); + return GT_Utility.isAnyIntegratedCircuit(controllerStack) ? controllerStack.getItemDamage() - 1 + : -1; + } + } + }; + } + + @Override + protected void setProcessingLogicPower(ProcessingLogic logic) { + logic.setAvailableVoltage(getAverageInputVoltage()); + logic.setAvailableAmperage(getMaxInputAmps()); + } + + private byte runningTick = 0; + + @Override + public boolean onRunningTick(ItemStack aStack) { + if (!super.onRunningTick(aStack)) { + return false; + } + + if (runningTick % 20 == 0) { + int amount = (int) (getFocusingTier() * 4 + * Math.sqrt(Math.min(mMaxParallel, processingLogic.getCurrentParallels()))); + if (doFermium) { + FluidStack fermiumToConsume = new FluidStack(mFermium, amount); + if (!drain(mFermiumHatch, fermiumToConsume, true)) { + doFermium = false; + stopMachine(ShutDownReasonRegistry.outOfFluid(fermiumToConsume)); + return false; + } + } + + if (doNeptunium) { + FluidStack neptuniumToConsume = new FluidStack(mNeptunium, amount); + if (!drain(mNeptuniumHatch, neptuniumToConsume, true)) { + doNeptunium = false; + stopMachine(ShutDownReasonRegistry.outOfFluid(neptuniumToConsume)); + return false; + } + } + + runningTick = 1; + } else { + runningTick++; + } + + return true; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (aBaseMetaTileEntity.isServerSide()) { + // TODO: Look for proper fix + // Updates every 30 sec + if (mUpdate <= -550) mUpdate = 50; + } + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return 0; + } + + @Override + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + private int[] getOutputChances(GT_Recipe tRecipe, int aChanceIncreased) { + int difference = getFocusingTier() - tRecipe.mSpecialValue; + int aOutputsAmount = tRecipe.mOutputs.length + tRecipe.mFluidOutputs.length; + int aChancePerOutput = 10000 / aOutputsAmount; + int[] tChances = new int[aOutputsAmount]; + Arrays.fill(tChances, aChancePerOutput); + + switch (difference) { + case 0 -> { + for (int i = 0; i < tChances.length; i++) { + if (doNeptunium) { + if (i == aChanceIncreased) { + tChances[i] += aChancePerOutput / 2 * (aOutputsAmount - 1); + } else { + tChances[i] /= 2; + } + } + + if (doFermium) { + tChances[i] += (10000 - tChances[i]) / 4; + } + } + } + case 1 -> { + for (int i = 0; i < tChances.length; i++) { + if (doNeptunium) { + if (i == aChanceIncreased) { + tChances[i] += aChancePerOutput * 3 / 4 * (aOutputsAmount - 1); + } else { + tChances[i] /= 4; + } + } + + if (doFermium) { + tChances[i] += (10000 - tChances[i]) / 3; + } + } + } + case 2, 3 -> { + for (int i = 0; i < tChances.length; i++) { + if (doNeptunium) { + if (i == aChanceIncreased) { + tChances[i] = 10000; + } else { + tChances[i] = 0; + } + } + + if (doFermium) { + tChances[i] += (10000 - tChances[i]) / 2; + } + } + } + } + return tChances; + } + + @Override + public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mFluidMode = !mFluidMode; + GT_Utility.sendChatToPlayer( + aPlayer, + StatCollector.translateToLocal("miscutils.machines.QFTFluidMode") + " " + mFluidMode); + } + + public boolean addNeptuniumHatch(IGregTechTileEntity aTileEntity, short aBaseCasingIndex) { + if (aTileEntity == null) return false; + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) return false; + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); + ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = null; + mNeptuniumHatch = (GT_MetaTileEntity_Hatch_Input) aMetaTileEntity; + return true; + } + return false; + } + + public boolean addFermiumHatch(IGregTechTileEntity aTileEntity, short aBaseCasingIndex) { + if (aTileEntity == null) return false; + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) return false; + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + ((GT_MetaTileEntity_Hatch) aMetaTileEntity).updateTexture(aBaseCasingIndex); + ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mRecipeMap = null; + mFermiumHatch = (GT_MetaTileEntity_Hatch_Input) aMetaTileEntity; + return true; + } + return false; + } + + public Block getCasingBlock1() { + return ModBlocks.blockCasings5Misc; + } + + public byte getCasingMeta1() { + return 15; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("mFluidMode", mFluidMode); + aNBT.setBoolean("doFermium", doFermium); + aNBT.setBoolean("doNeptunium", doNeptunium); + aNBT.setInteger("mMaxParallel", mMaxParallel); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + if (!aNBT.hasKey(INPUT_SEPARATION_NBT_KEY)) { + inputSeparation = aNBT.getBoolean("mSeparateInputBusses"); + } + if (!aNBT.hasKey(BATCH_MODE_NBT_KEY)) { + batchMode = aNBT.getBoolean("mBatchMode"); + } + mFluidMode = aNBT.getBoolean("mFluidMode"); + doFermium = aNBT.getBoolean("doFermium"); + doNeptunium = aNBT.getBoolean("doNeptunium"); + mMaxParallel = aNBT.getInteger("mMaxParallel"); + } + + @Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, ForgeDirection side, ForgeDirection facing, + int aColorIndex, boolean aActive, boolean aRedstone) { + if (side == facing) { + if (aActive) return new ITexture[] { getCasingTexture(), TextureFactory.builder() + .addIcon(getActiveOverlay()) + .extFacing() + .build() }; + return new ITexture[] { getCasingTexture(), TextureFactory.builder() + .addIcon(getInactiveOverlay()) + .extFacing() + .build() }; + } + return new ITexture[] { getCasingTexture() }; + } + + private ITexture getCasingTexture() { + return Textures.BlockIcons.getCasingTextureForId(getCasingTextureId()); + } + + @SideOnly(Side.CLIENT) + private void renderForceField(double x, double y, double z, int side, double minU, double maxU, double minV, + double maxV) { + // spotless:off + Tessellator tes = Tessellator.instance; + switch (side) { + case 0 -> { + tes.addVertexWithUV(x + 3, y, z + 7, maxU, maxV); + tes.addVertexWithUV(x + 3, y + 4, z + 7, maxU, minV); + tes.addVertexWithUV(x - 3, y + 4, z + 7, minU, minV); + tes.addVertexWithUV(x - 3, y, z + 7, minU, maxV); + tes.addVertexWithUV(x - 3, y, z + 7, minU, maxV); + tes.addVertexWithUV(x - 3, y + 4, z + 7, minU, minV); + tes.addVertexWithUV(x + 3, y + 4, z + 7, maxU, minV); + tes.addVertexWithUV(x + 3, y, z + 7, maxU, maxV); + } + case 1 -> { + tes.addVertexWithUV(x + 7, y, z + 4, maxU, maxV); + tes.addVertexWithUV(x + 7, y + 4, z + 4, maxU, minV); + tes.addVertexWithUV(x + 7, y + 4, z - 4, minU, minV); + tes.addVertexWithUV(x + 7, y, z - 4, minU, maxV); + tes.addVertexWithUV(x + 7, y, z - 4, minU, maxV); + tes.addVertexWithUV(x + 7, y + 4, z - 4, minU, minV); + tes.addVertexWithUV(x + 7, y + 4, z + 4, maxU, minV); + tes.addVertexWithUV(x + 7, y, z + 4, maxU, maxV); + } + case 2 -> { + tes.addVertexWithUV(x + 3, y, z - 7, maxU, maxV); + tes.addVertexWithUV(x + 3, y + 4, z - 7, maxU, minV); + tes.addVertexWithUV(x - 3, y + 4, z - 7, minU, minV); + tes.addVertexWithUV(x - 3, y, z - 7, minU, maxV); + tes.addVertexWithUV(x - 3, y, z - 7, minU, maxV); + tes.addVertexWithUV(x - 3, y + 4, z - 7, minU, minV); + tes.addVertexWithUV(x + 3, y + 4, z - 7, maxU, minV); + tes.addVertexWithUV(x + 3, y, z - 7, maxU, maxV); + } + case 3 -> { + tes.addVertexWithUV(x - 7, y, z + 4, maxU, maxV); + tes.addVertexWithUV(x - 7, y + 4, z + 4, maxU, minV); + tes.addVertexWithUV(x - 7, y + 4, z - 4, minU, minV); + tes.addVertexWithUV(x - 7, y, z - 4, minU, maxV); + tes.addVertexWithUV(x - 7, y, z - 4, minU, maxV); + tes.addVertexWithUV(x - 7, y + 4, z - 4, minU, minV); + tes.addVertexWithUV(x - 7, y + 4, z + 4, maxU, minV); + tes.addVertexWithUV(x - 7, y, z + 4, maxU, maxV); + } + case 4 -> { + tes.addVertexWithUV(x - 3, y, z + 7, maxU, maxV); + tes.addVertexWithUV(x - 3, y + 4, z + 7, maxU, minV); + tes.addVertexWithUV(x - 7, y + 4, z + 4, minU, minV); + tes.addVertexWithUV(x - 7, y, z + 4, minU, maxV); + tes.addVertexWithUV(x - 7, y, z + 4, minU, maxV); + tes.addVertexWithUV(x - 7, y + 4, z + 4, minU, minV); + tes.addVertexWithUV(x - 3, y + 4, z + 7, maxU, minV); + tes.addVertexWithUV(x - 3, y, z + 7, maxU, maxV); + } + case 5 -> { + tes.addVertexWithUV(x - 3, y, z - 7, maxU, maxV); + tes.addVertexWithUV(x - 3, y + 4, z - 7, maxU, minV); + tes.addVertexWithUV(x - 7, y + 4, z - 4, minU, minV); + tes.addVertexWithUV(x - 7, y, z - 4, minU, maxV); + tes.addVertexWithUV(x - 7, y, z - 4, minU, maxV); + tes.addVertexWithUV(x - 7, y + 4, z - 4, minU, minV); + tes.addVertexWithUV(x - 3, y + 4, z - 7, maxU, minV); + tes.addVertexWithUV(x - 3, y, z - 7, maxU, maxV); + } + case 6 -> { + tes.addVertexWithUV(x + 3, y, z + 7, maxU, maxV); + tes.addVertexWithUV(x + 3, y + 4, z + 7, maxU, minV); + tes.addVertexWithUV(x + 7, y + 4, z + 4, minU, minV); + tes.addVertexWithUV(x + 7, y, z + 4, minU, maxV); + tes.addVertexWithUV(x + 7, y, z + 4, minU, maxV); + tes.addVertexWithUV(x + 7, y + 4, z + 4, minU, minV); + tes.addVertexWithUV(x + 3, y + 4, z + 7, maxU, minV); + tes.addVertexWithUV(x + 3, y, z + 7, maxU, maxV); + } + case 7 -> { + tes.addVertexWithUV(x + 3, y, z - 7, maxU, maxV); + tes.addVertexWithUV(x + 3, y + 4, z - 7, maxU, minV); + tes.addVertexWithUV(x + 7, y + 4, z - 4, minU, minV); + tes.addVertexWithUV(x + 7, y, z - 4, minU, maxV); + tes.addVertexWithUV(x + 7, y, z - 4, minU, maxV); + tes.addVertexWithUV(x + 7, y + 4, z - 4, minU, minV); + tes.addVertexWithUV(x + 3, y + 4, z - 7, maxU, minV); + tes.addVertexWithUV(x + 3, y, z - 7, maxU, maxV); + } + } + } + + @SideOnly(Side.CLIENT) + @Override + public boolean renderInWorld(IBlockAccess aWorld, int x, int y, int z, Block block, RenderBlocks renderer) { + Tessellator tes = Tessellator.instance; + IIcon forceField = TexturesGtBlock.ForceField.getIcon(); + if (getBaseMetaTileEntity().isActive()) { + double minU = forceField.getMinU(); + double maxU = forceField.getMaxU(); + double minV = forceField.getMinV(); + double maxV = forceField.getMaxV(); + double xBaseOffset = 3 * getExtendedFacing().getRelativeBackInWorld().offsetX; + double zBaseOffset = 3 * getExtendedFacing().getRelativeBackInWorld().offsetZ; + tes.setColorOpaque_F(1f, 1f, 1f); + tes.setBrightness(15728880); + //Center O: 0, 0 1 ------- 8 + //Corner 1: 7, -2 / \ + //Corner 2: 3, -6 2 / \ 7 + //Corner 3: -2, -6 | | + //Corner 4: -6, -2 | O | + //Corner 5: -6, 3 | | + //Corner 6: -2, 7 3 \ / 6 + //Corner 7: 3, 7 \ / + //Corner 8: 7, 3 4 ------- 5 + renderForceField(x + xBaseOffset + 0.5, y, z + zBaseOffset + 0.5, 0, minU, maxU, minV, maxV); + renderForceField(x + xBaseOffset + 0.5, y, z + zBaseOffset + 0.5, 1, minU, maxU, minV, maxV); + renderForceField(x + xBaseOffset + 0.5, y, z + zBaseOffset + 0.5, 2, minU, maxU, minV, maxV); + renderForceField(x + xBaseOffset + 0.5, y, z + zBaseOffset + 0.5, 3, minU, maxU, minV, maxV); + renderForceField(x + xBaseOffset + 0.5, y, z + zBaseOffset + 0.5, 4, minU, maxU, minV, maxV); + renderForceField(x + xBaseOffset + 0.5, y, z + zBaseOffset + 0.5, 5, minU, maxU, minV, maxV); + renderForceField(x + xBaseOffset + 0.5, y, z + zBaseOffset + 0.5, 6, minU, maxU, minV, maxV); + renderForceField(x + xBaseOffset + 0.5, y, z + zBaseOffset + 0.5, 7, minU, maxU, minV, maxV); + } + // Needs to be false to render the controller + return false; + //spotless:on + } + + @Override + public boolean supportsInputSeparation() { + return true; + } + + @Override + public boolean supportsBatchMode() { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Refinery.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Refinery.java new file mode 100644 index 0000000000..8a6564858e --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_Refinery.java @@ -0,0 +1,220 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_StructureUtility.filterByMTETier; + +import net.minecraft.item.ItemStack; + +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffler; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; + +public class GregtechMetaTileEntity_Refinery extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_Refinery> + implements ISurvivalConstructable { + + private int mCasing; + private static IStructureDefinition<GregtechMetaTileEntity_Refinery> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_Refinery(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_Refinery(final String aName) { + super(aName); + } + + @Override + public String getMachineType() { + return "Fuel Refinery"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Fission Fuel Processing Unit") + .addInfo("Refines fluorides and Uranium into nuclear fuel for the LFTR") + .addInfo("LFTR Fuel 2 and Fuel 3 have alternative, much more efficient recipes") + .addInfo("However, they require fission breeding outputs from the LFTR itself") + .addInfo("Only one Energy Hatch is allowed per Processing Unit") + .addInfo("All recipe times in this multi are very long, watch out!") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(3, 9, 3, false) + .addController("Bottom Center") + .addCasingInfoMin("Hastelloy-X Structural Block", 7, false) + .addCasingInfoMin("Incoloy-DS Fluid Containment Block", 5, false) + .addCasingInfoMin("Zeron-100 Reactor Shielding", 4, false) + .addCasingInfoMin("Hastelloy-N Sealant Blocks", 17, false) + .addInputHatch("Base platform", 1) + .addOutputHatch("Base platform", 1) + .addMufflerHatch("Base platform", 1) + .addMaintenanceHatch("Base platform", 1) + .addEnergyHatch("Base platform", 1) + .addStructureInfo("Muffler's Tier must be IV+") + .addStructureInfo("2-4x Input Hatches, 1-2x Output Hatches") + .addStructureInfo("1x Muffler, 1x Maintenance Hatch, 1x Energy Hatch") + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + protected IIconContainer getActiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER_ACTIVE; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return Textures.BlockIcons.OVERLAY_FRONT_MULTI_SMELTER; + } + + @Override + protected int getCasingTextureId() { + return TAE.GTPP_INDEX(18); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.fissionFuelProcessingRecipes; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic(); + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public boolean addMufflerToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Muffler + && ((GT_MetaTileEntity_Hatch_Muffler) aMetaTileEntity).mTier >= 5) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_Refinery> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_Refinery>builder() + .addShape( + mName, + transpose( + new String[][] { { " ", " N ", " " }, { " N ", "NIN", " N " }, { " N ", "NIN", " N " }, + { " N ", "NIN", " N " }, { " Z ", "ZIZ", " Z " }, { " N ", "NIN", " N " }, + { "XXX", "XXX", "XXX" }, { "X~X", "XXX", "XXX" }, })) + .addElement( + 'X', + ofChain( + buildHatchAdder(GregtechMetaTileEntity_Refinery.class) + .atLeast(Energy, Maintenance, OutputHatch, OutputBus, InputHatch) + .casingIndex(TAE.GTPP_INDEX(18)) + .dot(1) + .build(), + buildHatchAdder(GregtechMetaTileEntity_Refinery.class).atLeast(Muffler) + .adder(GregtechMetaTileEntity_Refinery::addMufflerToMachineList) + .hatchItemFilterAnd(t -> filterByMTETier(6, Integer.MAX_VALUE)) + .casingIndex(TAE.GTPP_INDEX(18)) + .dot(1) + .build(), + onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 2)))) + .addElement('I', ofBlock(ModBlocks.blockCasings2Misc, 3)) + .addElement('N', ofBlock(ModBlocks.blockCasings2Misc, 1)) + .addElement('Z', ofBlock(ModBlocks.blockCasingsMisc, 13)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 1, 7, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 1, 7, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + if (checkPiece(mName, 1, 7, 0) && mCasing >= 7) { + if (this.mInputHatches.size() >= 2 && this.mInputHatches.size() <= 4 + && this.mOutputHatches.size() >= 1 + && this.mOutputHatches.size() <= 2 + && this.mMufflerHatches.size() == 1 + && this.mMaintenanceHatches.size() == 1 + && this.mEnergyHatches.size() == 1) { + this.resetRecipeMapForAllInputHatches(this.getRecipeMap()); + return true; + } + } + return false; + } + + @Override + public boolean isCorrectMachinePart(final ItemStack aStack) { + return true; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiRefinery; + } + + @Override + public int getDamageToComponent(final ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_Refinery(this.mName); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_SolarTower.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_SolarTower.java new file mode 100644 index 0000000000..0395ab5a01 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/GregtechMetaTileEntity_SolarTower.java @@ -0,0 +1,675 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import java.util.ArrayList; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.SoundResource; +import gregtech.api.enums.TAE; +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.recipe.RecipeMap; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.render.TextureFactory; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.material.MISC_MATERIALS; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.common.tileentities.misc.TileEntitySolarHeater; + +public class GregtechMetaTileEntity_SolarTower extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_SolarTower> + implements ISurvivalConstructable { + + // 862 + private static final int mCasingTextureID = TAE.getIndexFromPage(3, 9); + private int mHeatLevel = 0; + private int mCasing1; + private int mCasing2; + private int mCasing3; + private int mCasing4; + + public ArrayList<TileEntitySolarHeater> mSolarHeaters = new ArrayList<>(); + + public GregtechMetaTileEntity_SolarTower(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_SolarTower(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_SolarTower(this.mName); + } + + @Override + public String getMachineType() { + return "Solar Tower"; + } + + @Override + protected final GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Contributing Green Energy towards the future") + .addInfo("Surround with rings of Solar Reflectors") + .addInfo("The Reflectors increase the internal heat value of the Tower (see below for formula)") + .addInfo("Each Reflector ring increases tier, the first ring is required for the Tower to work") + .addInfo("Input: " + MISC_MATERIALS.SOLAR_SALT_COLD.getLocalizedName()) + .addInfo("Output: " + MISC_MATERIALS.SOLAR_SALT_HOT.getLocalizedName()) + .addInfo("Every cycle (10 seconds), heat increases and all the Cold Solar Salt is heated") + .addInfo("Converting Cold to Hot Solar Salt reduces heat, equal to the amount converted") + .addInfo("This conversion only happens if heat >= 30000 and controller efficiency = 100%") + .addInfo("If there's more Cold Salt than heat, all the heat is used up and returns to 0") + .addInfo("The heat increase is most efficient at exactly half of maximum heat") + .addInfo("Minimum efficiency at 0 or 100000 heat, maximum efficiency at 50000") + .addInfo("Heat Efficiency formula: ( 7000 - [|currentHeat - 50000| ^ 0.8]) / 7000") + .addInfo("Heat gain per cycle: numberHeaters * heatEfficiency * (10 + bonus)") + .addInfo("Bonus: 1 ring = +1, 2 rings = +2, 3 rings = +4, 4 rings = +8, 5 rings = +16") + .addInfo("Total number of reflectors based on how many rings are built:") + .addInfo("1 ring = 36, 2 rings = 88, 3 rings = 156, 4 rings = 240, 5 rings = 340") + .addSeparator() + .beginVariableStructureBlock(15, 31, 28, 28, 15, 31, false) + .addController("Top Middle") + .addCasingInfoMin("Structural Solar Casing", 229, false) + .addCasingInfoMin("Thermally Insulated Casing", 60, false) + .addCasingInfoMin("Salt Containment Casing", 66, false) + .addCasingInfoMin("Thermal Containment Casing", 60, false) + .addInputHatch("Any 2 dot hint(min 1)", 2) + .addOutputHatch("Any 2 dot hint(min 1)", 2) + .addMaintenanceHatch("Any 2 dot hint", 2) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + private static final String STRUCTURE_PIECE_BASE = "base"; + private static final String STRUCTURE_PIECE_TOWER = "tower"; + private static final String STRUCTURE_PIECE_TOP = "top"; + + private static final String[] STRUCTURE_PIECE_SOLAR_HEATER_RING = { "ring1", "ring2", "ring3", "ring4", "ring5" }; + private static final String SOLAR_HEATER_RING_1 = STRUCTURE_PIECE_SOLAR_HEATER_RING[0]; + private static final String SOLAR_HEATER_RING_2 = STRUCTURE_PIECE_SOLAR_HEATER_RING[1]; + private static final String SOLAR_HEATER_RING_3 = STRUCTURE_PIECE_SOLAR_HEATER_RING[2]; + private static final String SOLAR_HEATER_RING_4 = STRUCTURE_PIECE_SOLAR_HEATER_RING[3]; + private static final String SOLAR_HEATER_RING_5 = STRUCTURE_PIECE_SOLAR_HEATER_RING[4]; + + private static final ClassValue<IStructureDefinition<GregtechMetaTileEntity_SolarTower>> STRUCTURE_DEFINITION = new ClassValue<>() { + + @Override + protected IStructureDefinition<GregtechMetaTileEntity_SolarTower> computeValue(Class<?> type) { + return StructureDefinition.<GregtechMetaTileEntity_SolarTower>builder() + + // s = salt + // c = thermal containment + // i = thermal insulated + // t = solar structural + // h = hatch + // g = solar heater + + .addShape( + STRUCTURE_PIECE_TOP, + (new String[][] { { " ", " ", " ~ ", " ", " " }, + { " ", " s ", " sss ", " s ", " " }, + { " c ", " ccc ", "ccscc", " ccc ", " c " }, + { " c ", " ccc ", "ccscc", " ccc ", " c " }, + { " c ", " ccc ", "ccscc", " ccc ", " c " }, + { " c ", " ccc ", "ccscc", " ccc ", " c " }, + { " c ", " ccc ", "ccscc", " ccc ", " c " }, })) + .addShape( + STRUCTURE_PIECE_TOWER, + (new String[][] { { " i ", "isi", " i " }, { " i ", "isi", " i " }, { " i ", "isi", " i " }, + { " i ", "isi", " i " }, { " i ", "isi", " i " }, { " i ", "isi", " i " }, + { " i ", "isi", " i " }, { " i ", "isi", " i " }, { " i ", "isi", " i " }, + { " i ", "isi", " i " }, { " i ", "isi", " i " }, { " i ", "isi", " i " }, + { " i ", "isi", " i " }, { " i ", "isi", " i " }, { " i ", "isi", " i " }, })) + .addShape( + STRUCTURE_PIECE_BASE, + (new String[][] { + { " ", " ", " t ", " ttt ", " ttstt ", " ttssstt ", + " ttstt ", " ttt ", " t ", " ", " " }, + { " ", " ", " t ", " ttt ", " tssst ", " ttssstt ", + " tssst ", " ttt ", " t ", " ", " " }, + { " ", " t ", " ttt ", " ttttt ", " ttssstt ", " tttsssttt ", + " ttssstt ", " ttttt ", " ttt ", " t ", " " }, + { " ", " t ", " ttt ", " ttttt ", " ttssstt ", " tttsssttt ", + " ttssstt ", " ttttt ", " ttt ", " t ", " " }, + { " hhh ", " ttttt ", " ttttttt ", " ttttttttt ", "htttsssttth", "htttsssttth", + "htttsssttth", " ttttttttt ", " ttttttt ", " ttttt ", " hhh " }, + { " hhh ", " ttttt ", " ttttttt ", " ttttttttt ", "httttttttth", "httttttttth", + "httttttttth", " ttttttttt ", " ttttttt ", " ttttt ", " hhh " }, })) + .addShape( + SOLAR_HEATER_RING_1, + (new String[][] { { " ggggg ", " g g ", " g g ", " g g ", + " g g ", "g g", "g g", "g g", "g g", + "g g", " g g ", " g g ", " g g ", " g g ", + " ggggg ", } })) + .addShape( + SOLAR_HEATER_RING_2, + (new String[][] { + { " ggggggggg ", " g g ", " g g ", " g g ", + " g g ", "g g", "g g", "g g", + "g g", "g g", "g g", "g g", + "g g", "g g", " g g ", " g g ", + " g g ", " g g ", " ggggggggg ", } })) + .addShape( + SOLAR_HEATER_RING_3, + (new String[][] { { " ggggggggggggg ", " g g ", " g g ", + " g g ", " g g ", "g g", + "g g", "g g", "g g", + "g g", "g g", "g g", + "g g", "g g", "g g", + "g g", "g g", "g g", + " g g ", " g g ", " g g ", + " g g ", " ggggggggggggg ", } })) + .addShape( + SOLAR_HEATER_RING_4, + (new String[][] { { " ggggggggggggggggg ", " g g ", + " g g ", " g g ", " g g ", + "g g", "g g", "g g", + "g g", "g g", "g g", + "g g", "g g", "g g", + "g g", "g g", "g g", + "g g", "g g", "g g", + "g g", "g g", " g g ", + " g g ", " g g ", " g g ", + " ggggggggggggggggg ", } })) + .addShape( + SOLAR_HEATER_RING_5, + (new String[][] { { " ggggggggggggggggggggg ", " g g ", + " g g ", " g g ", + " g g ", "g g", + "g g", "g g", + "g g", "g g", + "g g", "g g", + "g g", "g g", + "g g", "g g", + "g g", "g g", + "g g", "g g", + "g g", "g g", + "g g", "g g", + "g g", "g g", + " g g ", " g g ", + " g g ", " g g ", + " ggggggggggggggggggggg ", } })) + .addElement( + 'g', + lazy( + t -> buildHatchAdder(GregtechMetaTileEntity_SolarTower.class) + .hatchClass(TileEntitySolarHeater.class) + .adder(GregtechMetaTileEntity_SolarTower::addSolarHeater) + // Use a positive casing index to make adder builder happy + .casingIndex(1) + .dot(1) + .continueIfSuccess() + .build())) + .addElement( + 't', + lazy(t -> onElementPass(x -> ++x.mCasing1, ofBlock(t.getCasingBlock(), t.getCasingMeta())))) + .addElement( + 'i', + lazy(t -> onElementPass(x -> ++x.mCasing2, ofBlock(t.getCasingBlock(), t.getCasingMeta2())))) + .addElement( + 's', + lazy(t -> onElementPass(x -> ++x.mCasing3, ofBlock(t.getCasingBlock(), t.getCasingMeta3())))) + .addElement( + 'c', + lazy(t -> onElementPass(x -> ++x.mCasing4, ofBlock(t.getCasingBlock2(), t.getCasingMeta4())))) + .addElement( + 'h', + lazy( + t -> buildHatchAdder(GregtechMetaTileEntity_SolarTower.class) + .atLeast(InputHatch, OutputHatch, Maintenance) + .casingIndex(t.getCasingTextureIndex()) + .dot(2) + .buildAndChain( + onElementPass(x -> ++x.mCasing1, ofBlock(t.getCasingBlock(), t.getCasingMeta()))))) + .build(); + } + }; + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + resetSolarHeaters(); + this.mMaintenanceHatches.clear(); + this.mInputHatches.clear(); + this.mOutputHatches.clear(); + mCasing1 = 0; + mCasing2 = 0; + mCasing3 = 0; + mCasing4 = 0; + + boolean aStructureTop = checkPiece(STRUCTURE_PIECE_TOP, 2, 2, 0); + log("Top Check: " + aStructureTop); + boolean aStructureTower = checkPiece(STRUCTURE_PIECE_TOWER, 1, 1, -7); + log("Tower Check: " + aStructureTower); + boolean aStructureBase = checkPiece(STRUCTURE_PIECE_BASE, 5, 5, -22); + log("Base Check: " + aStructureBase); + boolean aCasingCount1 = mCasing1 >= 229; + boolean aCasingCount2 = mCasing2 == 60; + boolean aCasingCount3 = mCasing3 == 66; + boolean aCasingCount4 = mCasing4 == 60; + boolean aAllStructure = aStructureTop && aStructureTower && aStructureBase; + boolean aAllCasings = aCasingCount1 && aCasingCount2 && aCasingCount3 && aCasingCount4; + if (!aAllCasings || !aAllStructure + || mMaintenanceHatches.size() != 1 + || mInputHatches.size() < 1 + || mOutputHatches.size() < 1) { + log( + "Bad Hatches - Solar Heaters: " + mSolarHeaters.size() + + ", Maint: " + + mMaintenanceHatches.size() + + ", Input Hatches: " + + mInputHatches.size() + + ", Output Hatches: " + + mOutputHatches.size() + + ", Top: " + + aStructureTop + + ", Tower: " + + aStructureTower + + ", Base: " + + aStructureBase + + ", Casing Count: " + + aCasingCount1 + + " | Found: " + + mCasing1 + + ", Casing Count: " + + aCasingCount2 + + " | Found: " + + mCasing2 + + ", Casing Count: " + + aCasingCount3 + + " | Found: " + + mCasing3 + + ", Casing Count: " + + aCasingCount4 + + " | Found: " + + mCasing4); + return false; + } + log( + "Built " + this.getLocalName() + + " with " + + mCasing1 + + " Structural Solar casings, " + + mCasing2 + + " Thermally Insulated casings, " + + mCasing3 + + " Salt Containment casings, " + + mCasing4 + + " Thermal Containment casings."); + return aAllCasings && aAllStructure; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + // Tower + buildPiece(STRUCTURE_PIECE_TOP, stackSize, hintsOnly, 2, 2, 0); + buildPiece(STRUCTURE_PIECE_TOWER, stackSize, hintsOnly, 1, 1, -7); + buildPiece(STRUCTURE_PIECE_BASE, stackSize, hintsOnly, 5, 5, -22); + + // Solar Heaters + if (stackSize.stackSize >= 1) { + buildPiece(SOLAR_HEATER_RING_1, stackSize, hintsOnly, 7, 7, -27); + if (stackSize.stackSize >= 2) { + buildPiece(SOLAR_HEATER_RING_2, stackSize, hintsOnly, 9, 9, -27); + if (stackSize.stackSize >= 3) { + buildPiece(SOLAR_HEATER_RING_3, stackSize, hintsOnly, 11, 11, -27); + if (stackSize.stackSize >= 4) { + buildPiece(SOLAR_HEATER_RING_4, stackSize, hintsOnly, 13, 13, -27); + if (stackSize.stackSize >= 5) { + buildPiece(SOLAR_HEATER_RING_5, stackSize, hintsOnly, 15, 15, -27); + } + } + } + } + } + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + int built; + int realBudget = elementBudget >= 200 ? elementBudget : Math.min(200, elementBudget * 2); + // Tower + built = survivialBuildPiece(STRUCTURE_PIECE_TOP, stackSize, 2, 2, 0, realBudget, env, false, true); + if (built >= 0) return built; + built = survivialBuildPiece(STRUCTURE_PIECE_TOWER, stackSize, 1, 1, -7, realBudget, env, false, true); + if (built >= 0) return built; + built = survivialBuildPiece(STRUCTURE_PIECE_BASE, stackSize, 5, 5, -22, realBudget, env, false, true); + if (built >= 0) return built; + + // Solar Heaters + if (stackSize.stackSize < 1) return -1; + built = survivialBuildPiece(SOLAR_HEATER_RING_1, stackSize, 7, 7, -27, realBudget, env, false, true); + if (built >= 0) return built; + if (stackSize.stackSize < 2) return -1; + built = survivialBuildPiece(SOLAR_HEATER_RING_2, stackSize, 9, 9, -27, realBudget, env, false, true); + if (built >= 0) return built; + if (stackSize.stackSize < 3) return -1; + built = survivialBuildPiece(SOLAR_HEATER_RING_3, stackSize, 11, 11, -27, realBudget, env, false, true); + if (built >= 0) return built; + if (stackSize.stackSize < 4) return -1; + built = survivialBuildPiece(SOLAR_HEATER_RING_4, stackSize, 13, 13, -27, realBudget, env, false, true); + if (built >= 0) return built; + if (stackSize.stackSize < 5) return -1; + return survivialBuildPiece(SOLAR_HEATER_RING_5, stackSize, 15, 15, -27, realBudget, env, false, true); + } + + @Override + public IStructureDefinition<GregtechMetaTileEntity_SolarTower> getStructureDefinition() { + return STRUCTURE_DEFINITION.get(getClass()); + } + + @Override + protected SoundResource getProcessStartSound() { + return SoundResource.IC2_MACHINES_MAGNETIZER_LOOP; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + if (side == ForgeDirection.DOWN || side == ForgeDirection.UP) { + if (aActive) return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12)), + TextureFactory.builder() + .addIcon(TexturesGtBlock.Overlay_Machine_Controller_Default_Active) + .extFacing() + .build() }; + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12)), + TextureFactory.builder() + .addIcon(TexturesGtBlock.Overlay_Machine_Controller_Default) + .extFacing() + .build() }; + } + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(12)) }; + } + + @Override + public RecipeMap<?> getRecipeMap() { + // Only for visual + return GTPPRecipeMaps.solarTowerRecipes; + } + + private int getHeaterTier() { + int aSolarHeaterCounter = this.mSolarHeaters.size(); + if (aSolarHeaterCounter > 0) { + if (aSolarHeaterCounter == 36) { + return 1; + } else if (aSolarHeaterCounter == 88) { + return 2; + } else if (aSolarHeaterCounter == 156) { + return 4; + } else if (aSolarHeaterCounter == 240) { + return 8; + } else if (aSolarHeaterCounter == 340) { + return 16; + } + } + return 0; + } + + private int getHeaterCountForTier(int aTier) { + return switch (aTier) { + case 1 -> 36; + case 2 -> 88; + case 4 -> 156; + case 8 -> 240; + case 16 -> 340; + default -> 0; + }; + } + + public boolean getConnectedSolarReflectors() { + + resetSolarHeaters(); + int aRing = 1; + + if (this.mSolarHeaters.size() < 36) { + // 15x15 + boolean aRing1 = checkPiece(SOLAR_HEATER_RING_1, 7, 7, -27); + if (aRing1) { + // log("Found Ring: "+(aRing++)+", Total: "+this.mSolarHeaters.size()); + } + } + if (this.mSolarHeaters.size() < 88) { + // 17x17 + boolean aRing2 = checkPiece(SOLAR_HEATER_RING_2, 9, 9, -27); + if (aRing2) { + // log("Found Ring: "+(aRing++)+", Total: "+this.mSolarHeaters.size()); + } + } + if (this.mSolarHeaters.size() < 156) { + // 19x19 + boolean aRing3 = checkPiece(SOLAR_HEATER_RING_3, 11, 11, -27); + if (aRing3) { + // log("Found Ring: "+(aRing++)+", Total: "+this.mSolarHeaters.size()); + } + } + if (this.mSolarHeaters.size() < 240) { + // 21x21 + boolean aRing4 = checkPiece(SOLAR_HEATER_RING_4, 13, 13, -27); + if (aRing4) { + // log("Found Ring: "+(aRing++)+", Total: "+this.mSolarHeaters.size()); + } + } + if (this.mSolarHeaters.size() < 340) { + // 23x23 + boolean aRing5 = checkPiece(SOLAR_HEATER_RING_5, 15, 15, -27); + if (aRing5) { + // log("Found Ring: "+(aRing++)+", Total: "+this.mSolarHeaters.size()); + } + } + return mSolarHeaters.size() > 0; + } + + private boolean addSolarHeater(IGregTechTileEntity aTileEntity, int a) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof TileEntitySolarHeater mTile) { + if (!mTile.hasSolarTower() && mTile.canSeeSky()) { + // Logger.INFO("Found Solar Reflector, Injecting Data."); + mTile.setSolarTower(this); + return this.mSolarHeaters.add(mTile); + } + } + } + return false; + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + return (d, r, f) -> d == ForgeDirection.UP; + } + + private Fluid mColdSalt = null; + private Fluid mHotSalt = null; + + @Override + public @NotNull CheckRecipeResult checkProcessing() { + this.mEfficiencyIncrease = 100; + this.mMaxProgresstime = 200; + + if (this.mSolarHeaters.isEmpty() || this.mSolarHeaters.size() < 340 + || this.getTotalRuntimeInTicks() % 200 == 0) { + getConnectedSolarReflectors(); + } + + int aTier = getHeaterTier(); + int aHeaters = getHeaterCountForTier(aTier); + + // Original formula was (-Math.pow(this.mHeatLevel - 50000, 0.8) + 7000) / 7000 + // However, negative numbers to the power of a non-integer result in NaN, by default + // Max efficiency is 1, at mHeatLevel = 50000, and it lowers at the same rate if going above or below this heat + // Min efficiency is 0.179, at mHeatLevel = 0 or 100000 + double aEfficiency = (-Math.pow(Math.abs(this.mHeatLevel - 50000), 0.8) + 7000) / 7000; + + World w = this.getBaseMetaTileEntity() + .getWorld(); + + // Manage Heat every 10s + // Add Heat First, if sources available and it's daytime, heat gain is halved if raining + if (w != null) { + if (aHeaters > 0 && w.isDaytime()) { + if (w.isRaining() && this.getBaseMetaTileEntity() + .getBiome().rainfall > 0.0F) { + this.mHeatLevel += GT_Utility.safeInt((long) ((aHeaters / 2) * aEfficiency * (10 + aTier))); + } else { + this.mHeatLevel += GT_Utility.safeInt((long) (aHeaters * aEfficiency * (10 + aTier))); + } + } + + // Remove Heat, based on time of day + if (mHeatLevel > 0) { + if (mHeatLevel > 100000) { + this.mHeatLevel = 100000; + } else { + this.mHeatLevel -= 10; + } + } + } + + if (this.mEfficiency == this.getMaxEfficiency(null) && this.mHeatLevel >= 30000) { + if (mColdSalt == null) { + mColdSalt = MISC_MATERIALS.SOLAR_SALT_COLD.getFluid(); + } + if (mHotSalt == null) { + mHotSalt = MISC_MATERIALS.SOLAR_SALT_HOT.getFluid(); + } + ArrayList<FluidStack> aFluids = this.getStoredFluids(); + for (FluidStack aFluid : aFluids) { + if (aFluid.getFluid() + .equals(mColdSalt)) { + int aFluidAmount = Math.min(aFluid.amount, this.mHeatLevel); + + this.mHeatLevel -= aFluidAmount; + this.depleteInput(FluidUtils.getFluidStack(mColdSalt, aFluidAmount)); + this.addOutput(FluidUtils.getFluidStack(mHotSalt, aFluidAmount)); + this.mHeatLevel = Math.max(this.mHeatLevel, 0); + + break; + } + } + } + + return CheckRecipeResultRegistry.GENERATING; + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(final ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public Block getCasingBlock() { + return ModBlocks.blockSpecialMultiCasings; + } + + public Block getCasingBlock2() { + return ModBlocks.blockCasings2Misc; + } + + public byte getCasingMeta() { + return 6; + } + + public byte getCasingMeta2() { + return 8; + } + + public byte getCasingMeta3() { + return 7; + } + + public byte getCasingMeta4() { + return 11; + } + + public byte getCasingTextureIndex() { + return (byte) mCasingTextureID; + } + + @Override + public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) {} + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mHeatLevel", mHeatLevel); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mHeatLevel = aNBT.getInteger("mHeatLevel"); + } + + @Override + public void onRemoval() { + resetSolarHeaters(); + super.onRemoval(); + } + + private void resetSolarHeaters() { + for (TileEntitySolarHeater aTile : this.mSolarHeaters) { + aTile.clearSolarTower(); + } + this.mSolarHeaters.clear(); + } + + @Override + public String[] getExtraInfoData() { + return new String[] { "Internal Heat Level: " + this.mHeatLevel, + "Connected Solar Reflectors: " + this.mSolarHeaters.size() }; + } + + @Override + public boolean doesBindPlayerInventory() { + return false; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java new file mode 100644 index 0000000000..8a3442b5e7 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/algae/GregtechMTE_AlgaePondBase.java @@ -0,0 +1,376 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.algae; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; + +import java.util.stream.Stream; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.SoundResource; +import gregtech.api.enums.TAE; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.recipe.check.SimpleCheckRecipeResult; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_StreamUtil; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.item.chemistry.AgriculturalChem; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.loaders.recipe.RecipeLoader_AlgaeFarm; +import ic2.core.init.BlocksItems; +import ic2.core.init.InternalName; + +public class GregtechMTE_AlgaePondBase extends GregtechMeta_MultiBlockBase<GregtechMTE_AlgaePondBase> + implements ISurvivalConstructable { + + private int mLevel = -1; + private int mCasing; + private static IStructureDefinition<GregtechMTE_AlgaePondBase> STRUCTURE_DEFINITION = null; + private int checkMeta; + private int minTierOfHatch; + private static final Class<?> cofhWater; + + static { + cofhWater = ReflectionUtils.getClass("cofh.asmhooks.block.BlockWater"); + } + + public GregtechMTE_AlgaePondBase(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMTE_AlgaePondBase(final String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMTE_AlgaePondBase(this.mName); + } + + @Override + public String getMachineType() { + return "Algae Pond"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Grows Algae!") + .addInfo("Controller Block for the Algae Farm") + .addInfo("Provide compost to boost production by one tier") + .addInfo("Does not require power or maintenance") + .addInfo("All Machine Casings must be the same tier, this dictates machine speed.") + .addInfo("All Buses/Hatches must, at least, match the tier of the Casings") + .addInfo("Fill Input Hatch with Water to fill the inside of the multiblock.") + .addPollutionAmount(getPollutionPerSecond(null)) + .addSeparator() + .beginStructureBlock(9, 3, 9, true) + .addController("Front Center") + .addCasingInfoMin("Machine Casings", 64, true) + .addCasingInfoMin("Sterile Farm Casings", 64, false) + .addInputBus("Any Casing", 1) + .addOutputBus("Any Casing", 1) + .addInputHatch("Any Casing", 1) + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + public void setMeta(int meta) { + checkMeta = meta; + } + + public int getMeta() { + return checkMeta; + } + + @Override + public IStructureDefinition<GregtechMTE_AlgaePondBase> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMTE_AlgaePondBase>builder() + .addShape( + mName, + transpose( + new String[][] { + { "XXXXXXXXX", "X X", "X X", "X X", "X X", "X X", "X X", + "X X", "XXXXXXXXX" }, + { "XXXXXXXXX", "X X", "X X", "X X", "X X", "X X", "X X", + "X X", "XXXXXXXXX" }, + { "CCCC~CCCC", "CCCCCCCCC", "CCCCCCCCC", "CCCCCCCCC", "CCCCCCCCC", "CCCCCCCCC", "CCCCCCCCC", + "CCCCCCCCC", "CCCCCCCCC" }, })) + .addElement( + 'C', + ofChain( + buildHatchAdder(GregtechMTE_AlgaePondBase.class).atLeast(InputHatch, InputBus, OutputBus) + .casingIndex(TAE.getIndexFromPage(1, 15)) + .dot(1) + .build(), + onElementPass( + x -> ++x.mCasing, + addTieredBlock( + GregTech_API.sBlockCasings1, + GregtechMTE_AlgaePondBase::setMeta, + GregtechMTE_AlgaePondBase::getMeta, + 10)))) + .addElement('X', ofBlock(ModBlocks.blockCasings2Misc, 15)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 4, 2, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 4, 2, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mLevel = 0; + checkMeta = 0; + minTierOfHatch = 100; + if (checkPiece(mName, 4, 2, 0) && mCasing >= 64 && checkMeta > 0) { + mLevel = checkMeta - 1; + return mLevel <= minTierOfHatch; + } + return false; + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + return (d, r, f) -> d.offsetY == 0 && r.isNotRotated() && !f.isVerticallyFliped(); + } + + @Override + protected SoundResource getProcessStartSound() { + return SoundResource.IC2_MACHINES_ELECTROFURNACE_LOOP; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Default; + } + + @Override + protected int getCasingTextureId() { + int aID = TAE.getIndexFromPage(1, 15); + if (mLevel > -1) { + aID = mLevel; + } + return aID; + } + + @Override + public int getMaxParallelRecipes() { + return 2; + } + + public boolean checkForWater() { + + // Get Facing direction + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + int mDirectionX = aBaseMetaTileEntity.getBackFacing().offsetX; + int mCurrentDirectionX; + int mCurrentDirectionZ; + int mOffsetX_Lower = 0; + int mOffsetX_Upper = 0; + int mOffsetZ_Lower = 0; + int mOffsetZ_Upper = 0; + + mCurrentDirectionX = 4; + mCurrentDirectionZ = 4; + + mOffsetX_Lower = -4; + mOffsetX_Upper = 4; + mOffsetZ_Lower = -4; + mOffsetZ_Upper = 4; + + // if (aBaseMetaTileEntity.fac) + + final int xDir = aBaseMetaTileEntity.getBackFacing().offsetX * mCurrentDirectionX; + final int zDir = aBaseMetaTileEntity.getBackFacing().offsetZ * mCurrentDirectionZ; + + int tAmount = 0; + for (int i = mOffsetX_Lower + 1; i <= mOffsetX_Upper - 1; ++i) { + for (int j = mOffsetZ_Lower + 1; j <= mOffsetZ_Upper - 1; ++j) { + for (int h = 0; h < 2; h++) { + Block tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); + byte tMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir + i, h, zDir + j); + if (isNotStaticWater(tBlock, tMeta)) { + if (this.getStoredFluids() != null) { + for (FluidStack stored : this.getStoredFluids()) { + if (stored.isFluidEqual(FluidUtils.getFluidStack("water", 1))) { + if (stored.amount >= 1000) { + // Utils.LOG_WARNING("Going to try swap an air block for water from inut bus."); + stored.amount -= 1000; + Block fluidUsed = Blocks.water; + aBaseMetaTileEntity.getWorld() + .setBlock( + aBaseMetaTileEntity.getXCoord() + xDir + i, + aBaseMetaTileEntity.getYCoord() + h, + aBaseMetaTileEntity.getZCoord() + zDir + j, + fluidUsed); + } + } + } + } + } + tBlock = aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j); + if (tBlock == Blocks.water || tBlock == Blocks.flowing_water) { + ++tAmount; + // Logger.INFO("Found Water"); + } + } + } + } + + boolean isValidWater = tAmount >= 49; + + if (isValidWater) { + Logger.INFO("Filled structure."); + return true; + } else { + return false; + } + } + + private boolean isNotStaticWater(Block block, byte meta) { + return block == Blocks.air || block == Blocks.flowing_water + || block == BlocksItems.getFluidBlock(InternalName.fluidDistilledWater) + || (cofhWater != null && cofhWater.isAssignableFrom(block.getClass()) && meta != 0); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerSecond(final ItemStack aStack) { + return CORE.ConfigSwitches.pollutionPerSecondMultiAlgaePond; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPreTick(aBaseMetaTileEntity, aTick); + this.fixAllMaintenanceIssue(); + // Silly Client Syncing + if (aBaseMetaTileEntity.isClientSide()) { + this.mLevel = getCasingTier(); + } + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic() { + + @Nonnull + @Override + protected Stream<GT_Recipe> findRecipeMatches(@Nullable RecipeMap<?> map) { + return GT_StreamUtil + .ofNullable(RecipeLoader_AlgaeFarm.getTieredRecipeFromCache(mLevel, isUsingCompost(inputItems))); + } + + @NotNull + @Override + protected CheckRecipeResult validateRecipe(@NotNull GT_Recipe recipe) { + if (!checkForWater()) { + return SimpleCheckRecipeResult.ofFailure("no_water"); + } + return CheckRecipeResultRegistry.SUCCESSFUL; + } + }.setEuModifier(0F) + .setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + private boolean isUsingCompost(ItemStack[] aItemInputs) { + ItemStack aCompost = ItemUtils.getSimpleStack(AgriculturalChem.mCompost, 1); + for (ItemStack i : aItemInputs) { + if (GT_Utility.areStacksEqual(aCompost, i)) { + if (i.stackSize >= RecipeLoader_AlgaeFarm.compostForTier(mLevel)) { + return true; + } + } + } + return false; + } + + private int getCasingTier() { + if (this.getBaseMetaTileEntity() + .getWorld() == null) { + return 0; + } + try { + Block aInitStructureCheck; + int aInitStructureCheckMeta; + IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity(); + int xDir = aBaseMetaTileEntity.getBackFacing().offsetX; + int zDir = aBaseMetaTileEntity.getBackFacing().offsetZ; + aInitStructureCheck = aBaseMetaTileEntity.getBlockOffset(xDir, -1, zDir); + aInitStructureCheckMeta = aBaseMetaTileEntity.getMetaIDOffset(xDir, -1, zDir); + if (aInitStructureCheck == GregTech_API.sBlockCasings1) { + return aInitStructureCheckMeta; + } + return 0; + } catch (Throwable t) { + t.printStackTrace(); + return 0; + } + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java new file mode 100644 index 0000000000..30d2f75457 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/chemplant/GregtechMTE_ChemicalPlant.java @@ -0,0 +1,676 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.chemplant; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.withChannel; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_StructureUtility.filterByMTETier; +import static gregtech.api.util.GT_StructureUtility.ofCoil; +import static gregtech.api.util.GT_Utility.filterValidMTEs; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.StructureLibAPI; +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.AutoPlaceEnvironment; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.IStructureElement; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureUtility; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.HeatingCoilLevel; +import gregtech.api.enums.SoundResource; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; +import gregtech.api.metatileentity.GregTechTileClientEvents; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Maintenance; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Output; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_OutputBus; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.recipe.check.SimpleCheckRecipeResult; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.common.tileentities.machines.IDualInputHatch; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.objects.data.Triplet; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.item.chemistry.general.ItemGenericChemBase; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.recipe.common.CI; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.ItemUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.nbthandlers.GT_MetaTileEntity_Hatch_Catalysts; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMTE_ChemicalPlant extends GregtechMeta_MultiBlockBase<GregtechMTE_ChemicalPlant> + implements ISurvivalConstructable { + + private int mSolidCasingTier = 0; + private int mMachineCasingTier = 0; + private int mPipeCasingTier = 0; + private int mCoilTier = 0; + private HeatingCoilLevel checkCoil; + private int[] checkCasing = new int[8]; + private int checkMachine; + private int checkPipe; + private int maxTierOfHatch; + private int mCasing; + private static IStructureDefinition<GregtechMTE_ChemicalPlant> STRUCTURE_DEFINITION = null; + + private final ArrayList<GT_MetaTileEntity_Hatch_Catalysts> mCatalystBuses = new ArrayList<>(); + + private static final HashMap<Integer, Triplet<Block, Integer, Integer>> mTieredBlockRegistry = new HashMap<>(); + + public GregtechMTE_ChemicalPlant(final int aID, final String aName, final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMTE_ChemicalPlant(final String aName) { + super(aName); + } + + public static boolean registerMachineCasingForTier(int aTier, Block aBlock, int aMeta, int aCasingTextureID) { + Triplet<Block, Integer, Integer> aCasingData = new Triplet<>(aBlock, aMeta, aCasingTextureID); + if (mTieredBlockRegistry.containsKey(aTier)) { + CORE.crash( + "Tried to register a Machine casing for tier " + aTier + + " to the Chemical Plant, however this tier already contains one."); + } + mTieredBlockRegistry.put(aTier, aCasingData); + return true; + } + + private static int getCasingTextureIdForTier(int aTier) { + if (!mTieredBlockRegistry.containsKey(aTier)) { + return 10; + } + int aCasingID = mTieredBlockRegistry.get(aTier) + .getValue_3(); + // Logger.INFO("Found casing texture ID "+aCasingID+" for tier "+aTier); + return aCasingID; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMTE_ChemicalPlant(this.mName); + } + + @Override + public String getMachineType() { + return "Chemical Plant"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the Chemical Plant") + .addInfo("Heavy Industry, now right at your doorstep!") + .addInfo("Please read the user manual for more information on construction and usage") + .addSeparator() + .addController("Bottom Center") + .addStructureHint("Catalyst Housing", 1) + .addInputBus("Bottom Casing", 1) + .addOutputBus("Bottom Casing", 1) + .addInputHatch("Bottom Casing", 1) + .addOutputHatch("Bottom Casing", 1) + .addEnergyHatch("Bottom Casing", 1) + .addMaintenanceHatch("Bottom Casing", 1) + .addSubChannelUsage("casing", "metal machine casing") + .addSubChannelUsage("machine", "tier machine casing") + .addSubChannelUsage("coil", "heating coil blocks") + .addSubChannelUsage("pipe", "pipe casing blocks") + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + public void setMachineMeta(int meta) { + checkMachine = meta; + } + + public int getMachineMeta() { + return checkMachine; + } + + public void setPipeMeta(int meta) { + checkPipe = meta; + } + + public int getPipeMeta() { + return checkPipe; + } + + public void setCoilMeta(HeatingCoilLevel meta) { + checkCoil = meta; + } + + public HeatingCoilLevel getCoilMeta() { + return checkCoil; + } + + @Override + public IStructureDefinition<GregtechMTE_ChemicalPlant> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + IStructureElement<GregtechMTE_ChemicalPlant> allCasingsElement = withChannel( + "casing", + ofChain( + IntStream.range(0, 8) + .mapToObj(GregtechMTE_ChemicalPlant::ofSolidCasing) + .collect(Collectors.toList()))); + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMTE_ChemicalPlant>builder() + .addShape( + mName, + transpose( + new String[][] { + { "XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX", "XXXXXXX" }, + { "X X", " MMMMM ", " MHHHM ", " MHHHM ", " MHHHM ", " MMMMM ", "X X" }, + { "X X", " ", " PPP ", " PPP ", " PPP ", " ", "X X" }, + { "X X", " ", " HHH ", " HHH ", " HHH ", " ", "X X" }, + { "X X", " ", " PPP ", " PPP ", " PPP ", " ", "X X" }, + { "X X", " MMMMM ", " MHHHM ", " MHHHM ", " MHHHM ", " MMMMM ", "X X" }, + { "CCC~CCC", "CMMMMMC", "CMMMMMC", "CMMMMMC", "CMMMMMC", "CMMMMMC", "CCCCCCC" }, })) + .addElement( + 'C', + ofChain( + buildHatchAdder(GregtechMTE_ChemicalPlant.class).atLeast(Maintenance) + .casingIndex(getCasingTextureID()) + .dot(1) + .build(), + buildHatchAdder(GregtechMTE_ChemicalPlant.class) + .atLeast(InputHatch, OutputHatch, InputBus, OutputBus) + .adder(GregtechMTE_ChemicalPlant::addChemicalPlantList) + .hatchItemFilterAnd( + (t, s) -> filterByMTETier( + Integer.MIN_VALUE, + s.stackSize >= 10 ? Integer.MAX_VALUE : s.stackSize)) + .casingIndex(getCasingTextureID()) + .dot(1) + .build(), + buildHatchAdder(GregtechMTE_ChemicalPlant.class) + .hatchClass(GT_MetaTileEntity_Hatch_Catalysts.class) + .shouldReject(t -> t.mCatalystBuses.size() >= 1) + .adder(GregtechMTE_ChemicalPlant::addChemicalPlantList) + .casingIndex(getCasingTextureID()) + .dot(1) + .build(), + allCasingsElement)) + .addElement('X', allCasingsElement) + .addElement( + 'M', + withChannel( + "machine", + addTieredBlock( + GregTech_API.sBlockCasings1, + GregtechMTE_ChemicalPlant::setMachineMeta, + GregtechMTE_ChemicalPlant::getMachineMeta, + 10))) + .addElement( + 'H', + withChannel( + "coil", + ofCoil(GregtechMTE_ChemicalPlant::setCoilMeta, GregtechMTE_ChemicalPlant::getCoilMeta))) + .addElement( + 'P', + withChannel( + "pipe", + addTieredBlock( + GregTech_API.sBlockCasings2, + GregtechMTE_ChemicalPlant::setPipeMeta, + GregtechMTE_ChemicalPlant::getPipeMeta, + 12, + 16))) + .build(); + } + return STRUCTURE_DEFINITION; + } + + private static IStructureElement<GregtechMTE_ChemicalPlant> ofSolidCasing(int aIndex) { + return new IStructureElement<GregtechMTE_ChemicalPlant>() { + + @Override + public boolean check(GregtechMTE_ChemicalPlant t, World world, int x, int y, int z) { + if (check(aIndex, world, x, y, z)) { + t.checkCasing[aIndex]++; + t.mCasing++; + return true; + } else return false; + } + + private boolean check(int aIndex, World world, int x, int y, int z) { + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + Block target = mTieredBlockRegistry.get(aIndex) + .getValue_1(); + int targetMeta = mTieredBlockRegistry.get(aIndex) + .getValue_2(); + return target.equals(block) && meta == targetMeta; + } + + int getIndex(int size) { + if (size > 8) size = 8; + return size - 1; + } + + @Override + public boolean spawnHint(GregtechMTE_ChemicalPlant t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle( + world, + x, + y, + z, + mTieredBlockRegistry.get(getIndex(trigger.stackSize)) + .getValue_1(), + mTieredBlockRegistry.get(getIndex(trigger.stackSize)) + .getValue_2()); + return true; + } + + @Override + public boolean placeBlock(GregtechMTE_ChemicalPlant t, World world, int x, int y, int z, + ItemStack trigger) { + return world.setBlock( + x, + y, + z, + mTieredBlockRegistry.get(getIndex(trigger.stackSize)) + .getValue_1(), + mTieredBlockRegistry.get(getIndex(trigger.stackSize)) + .getValue_2(), + 3); + } + + @Nullable + @Override + public BlocksToPlace getBlocksToPlace(GregtechMTE_ChemicalPlant gregtechMTE_chemicalPlant, World world, + int x, int y, int z, ItemStack trigger, AutoPlaceEnvironment env) { + return BlocksToPlace.create( + mTieredBlockRegistry.get(getIndex(trigger.stackSize)) + .getValue_1(), + mTieredBlockRegistry.get(getIndex(trigger.stackSize)) + .getValue_2()); + } + + @Override + public PlaceResult survivalPlaceBlock(GregtechMTE_ChemicalPlant t, World world, int x, int y, int z, + ItemStack trigger, AutoPlaceEnvironment env) { + if (check(getIndex(trigger.stackSize), world, x, y, z)) return PlaceResult.SKIP; + return StructureUtility.survivalPlaceBlock( + mTieredBlockRegistry.get(getIndex(trigger.stackSize)) + .getValue_1(), + mTieredBlockRegistry.get(getIndex(trigger.stackSize)) + .getValue_2(), + world, + x, + y, + z, + env.getSource(), + env.getActor(), + env.getChatter()); + } + }; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(mName, stackSize, hintsOnly, 3, 6, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + return survivialBuildPiece(mName, stackSize, 3, 6, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + for (int i = 0; i < 8; i++) { + checkCasing[i] = 0; + } + checkPipe = 0; + checkMachine = 0; + mSolidCasingTier = 0; + mMachineCasingTier = 0; + mPipeCasingTier = 0; + mCoilTier = 0; + maxTierOfHatch = 0; + mCatalystBuses.clear(); + setCoilMeta(HeatingCoilLevel.None); + if (checkPiece(mName, 3, 6, 0) && mCasing >= 70) { + for (int i = 0; i < 8; i++) { + if (checkCasing[i] == mCasing) { + mSolidCasingTier = i; + } else if (checkCasing[i] > 0) return false; + } + mMachineCasingTier = checkMachine - 1; + mPipeCasingTier = checkPipe - 12; + mCoilTier = checkCoil.getTier(); + getBaseMetaTileEntity().sendBlockEvent(GregTechTileClientEvents.CHANGE_CUSTOM_DATA, getUpdateData()); + updateHatchTexture(); + return (mMachineCasingTier >= 9 || mMachineCasingTier >= maxTierOfHatch) && mCatalystBuses.size() <= 1; + } + return false; + } + + public void updateHatchTexture() { + for (GT_MetaTileEntity_Hatch h : mCatalystBuses) h.updateTexture(getCasingTextureID()); + for (IDualInputHatch h : mDualInputHatches) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mInputBusses) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mMaintenanceHatches) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mEnergyHatches) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mOutputBusses) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mInputHatches) h.updateTexture(getCasingTextureID()); + for (GT_MetaTileEntity_Hatch h : mOutputHatches) h.updateTexture(getCasingTextureID()); + } + + public final boolean addChemicalPlantList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Catalysts) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_InputBus) { + maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_InputBus) aMetaTileEntity).mTier); + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy) { + maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_Energy) aMetaTileEntity).mTier); + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_OutputBus) { + maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_OutputBus) aMetaTileEntity).mTier); + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Input) { + maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_Input) aMetaTileEntity).mTier); + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Output) { + maxTierOfHatch = Math.max(maxTierOfHatch, ((GT_MetaTileEntity_Hatch_Output) aMetaTileEntity).mTier); + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + return false; + } + + @Override + protected SoundResource getProcessStartSound() { + return SoundResource.IC2_MACHINES_ELECTROFURNACE_LOOP; + } + + @Override + protected IIconContainer getActiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active; + } + + @Override + protected IIconContainer getInactiveOverlay() { + return TexturesGtBlock.Overlay_Machine_Controller_Advanced; + } + + @Override + protected int getCasingTextureId() { + return getCasingTextureID(); + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.chemicalPlantRecipes; + } + + @Override + public int getMaxParallelRecipes() { + return 2 * getPipeCasingTier(); + } + + private int getSolidCasingTier() { + return this.mSolidCasingTier; + } + + private int getMachineCasingTier() { + return mMachineCasingTier; + } + + private int getPipeCasingTier() { + return mPipeCasingTier; + } + + private int getCasingTextureID() { + // Check the Tier Client Side + int aTier = mSolidCasingTier; + return getCasingTextureIdForTier(aTier); + } + + public boolean addToMachineList(IGregTechTileEntity aTileEntity) { + int aMaxTier = getMachineCasingTier(); + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_TieredMachineBlock aMachineBlock) { + int aTileTier = aMachineBlock.mTier; + if (aTileTier > aMaxTier) { + log("Hatch tier too high."); + return false; + } else { + return addToMachineList(aTileEntity, getCasingTextureID()); + } + } else { + log("Bad Tile Entity being added to hatch map."); // Shouldn't ever happen, but.. ya know.. + return false; + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("mSolidCasingTier", this.mSolidCasingTier); + aNBT.setInteger("mMachineCasingTier", this.mMachineCasingTier); + aNBT.setInteger("mPipeCasingTier", this.mPipeCasingTier); + aNBT.setInteger("mCoilTier", this.mCoilTier); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + mSolidCasingTier = aNBT.getInteger("mSolidCasingTier"); + mMachineCasingTier = aNBT.getInteger("mMachineCasingTier"); + mPipeCasingTier = aNBT.getInteger("mPipeCasingTier"); + mCoilTier = aNBT.getInteger("mCoilTier"); + } + + @Override + public boolean addToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Catalysts) { + log("Found GT_MetaTileEntity_Hatch_Catalysts"); + return addToMachineListInternal(mCatalystBuses, aMetaTileEntity, aBaseCasingIndex); + } + return super.addToMachineList(aTileEntity, aBaseCasingIndex); + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public int getPollutionPerTick(final ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + public int getMaxCatalystDurability() { + return 50; + } + + @Override + public byte getUpdateData() { + return (byte) mSolidCasingTier; + } + + @Override + public void receiveClientEvent(byte aEventID, byte aValue) { + super.receiveClientEvent(aEventID, aValue); + if (aEventID == GregTechTileClientEvents.CHANGE_CUSTOM_DATA && (aValue & 0x80) == 0) { + // received an update data from above method + // if no &0x80 clause it might catch the noop texture page event + mSolidCasingTier = aValue; + } + } + + private void damageCatalyst(@Nonnull ItemStack aStack, int minParallel) { + // Awakened Draconium Coils with Tungstensteel Pipe Casings (or above) no longer consume catalysts. + if (!isCatalystDamageable()) return; + for (int i = 0; i < minParallel; i++) { + if (MathUtils.randFloat(0, 10000000) / 10000000f < (1.2f - (0.2 * this.mPipeCasingTier))) { + int damage = getDamage(aStack) + 1; + if (damage >= getMaxCatalystDurability()) { + addOutput(CI.getEmptyCatalyst(1)); + aStack.stackSize -= 1; + return; + } else { + setDamage(aStack, damage); + } + } + } + } + + private boolean isCatalystDamageable() { + return this.mCoilTier < 10 || this.mPipeCasingTier < 4; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic() { + + ItemStack catalyst; + + @NotNull + @Override + protected CheckRecipeResult validateRecipe(@NotNull GT_Recipe recipe) { + if (recipe.mSpecialValue > mSolidCasingTier) { + return CheckRecipeResultRegistry.insufficientMachineTier(recipe.mSpecialValue + 1); + } + // checks if it has a catalyst + ItemStack catalystInRecipe = null; + for (ItemStack item : recipe.mInputs) { + if (ItemUtils.isCatalyst(item)) { + catalystInRecipe = item; + break; + } + } + + if (catalystInRecipe != null) { + catalyst = findCatalyst(getCatalystInputs().toArray(new ItemStack[0]), catalystInRecipe); + if (catalyst == null) { + return SimpleCheckRecipeResult.ofFailure("no_catalyst"); + } + } + return CheckRecipeResultRegistry.SUCCESSFUL; + } + + @NotNull + @Override + public CheckRecipeResult process() { + ArrayList<ItemStack> inputItemsList = new ArrayList<>(Arrays.asList(inputItems)); + inputItemsList.addAll(getCatalystInputs()); + inputItems = inputItemsList.toArray(new ItemStack[0]); + return super.process(); + } + + @NotNull + @Override + protected CheckRecipeResult onRecipeStart(@NotNull GT_Recipe recipe) { + if (catalyst != null) { + damageCatalyst(catalyst, getCurrentParallels()); + } + return super.onRecipeStart(recipe); + } + }.setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + protected void setupProcessingLogic(ProcessingLogic logic) { + super.setupProcessingLogic(logic); + // Same speed bonus as pyro oven + logic.setSpeedBonus(2F / (1 + this.mCoilTier)); + } + + @Override + public void updateSlots() { + super.updateSlots(); + for (GT_MetaTileEntity_Hatch_Catalysts h : mCatalystBuses) { + h.updateSlots(); + h.tryFillUsageSlots(); + } + } + + private ItemStack findCatalyst(ItemStack[] aItemInputs, ItemStack catalyst) { + if (aItemInputs != null) { + for (ItemStack item : aItemInputs) { + if (GT_Utility.areStacksEqual(item, catalyst, true)) { + return item; + } + } + } + return null; + } + + private int getDamage(@Nonnull ItemStack aStack) { + return ItemGenericChemBase.getCatalystDamage(aStack); + } + + private void setDamage(@Nonnull ItemStack aStack, int aAmount) { + ItemGenericChemBase.setCatalystDamage(aStack, aAmount); + } + + /* + * Catalyst Handling + */ + public ArrayList<ItemStack> getCatalystInputs() { + ArrayList<ItemStack> tItems = new ArrayList<>(); + for (GT_MetaTileEntity_Hatch_Catalysts tHatch : filterValidMTEs(mCatalystBuses)) { + AutoMap<ItemStack> aHatchContent = tHatch.getContentUsageSlots(); + if (!aHatchContent.isEmpty()) { + tItems.addAll(aHatchContent); + } + } + return tItems; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/mega/GregTechMetaTileEntity_MegaAlloyBlastSmelter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/mega/GregTechMetaTileEntity_MegaAlloyBlastSmelter.java new file mode 100644 index 0000000000..1679629c88 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/mega/GregTechMetaTileEntity_MegaAlloyBlastSmelter.java @@ -0,0 +1,468 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.mega; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.withChannel; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.ExoticEnergy; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputBus; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_StructureUtility.ofCoil; +import static gregtech.api.util.GT_Utility.filterValidMTEs; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; +import net.minecraftforge.common.util.ForgeDirection; + +import org.jetbrains.annotations.NotNull; + +import com.github.bartimaeusnek.bartworks.API.BorosilicateGlass; +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.HeatingCoilLevel; +import gregtech.api.enums.TAE; +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.logic.ProcessingLogic; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_ExtendedPowerMultiBlockBase; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.render.TextureFactory; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_OverclockCalculator; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.recipe.GTPPRecipeMaps; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregTechMetaTileEntity_MegaAlloyBlastSmelter + extends GT_MetaTileEntity_ExtendedPowerMultiBlockBase<GregTechMetaTileEntity_MegaAlloyBlastSmelter> + implements ISurvivalConstructable { + + private static final int MAX_PARALLELS = 256; + private HeatingCoilLevel coilLevel; + private byte glassTier = -1; + private boolean hasNormalCoils; + + private static final IStructureDefinition<GregTechMetaTileEntity_MegaAlloyBlastSmelter> STRUCTURE_DEFINITION = StructureDefinition + .<GregTechMetaTileEntity_MegaAlloyBlastSmelter>builder() + .addShape( + "main", + new String[][] { + { " ", " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", " ", + " ", " DDDDD ", " CCCCC ", " AEEEA ", " AE~EA ", " AEEEA ", + " CCCCC ", " ZZZZZ " }, + { " DDDDD ", " AAAAA ", " AAAAA ", " AAAAA ", " AAAAA ", " AAAAA ", + " AAAAA ", " AAAAA ", " AAAAA ", " AAAAA ", " AAAAA ", " AAAAA ", + " DDDDD ", " D D ", " C C ", " A A ", " A A ", " A A ", + " C C ", " ZZZZZZZ " }, + { " DDDDDDD ", " ABBBBBA ", " ABBBBBA ", " ABBBBBA ", " ABBBBBA ", " ABBBBBA ", + " ABBBBBA ", " ABBBBBA ", " ABBBBBA ", " ABBBBBA ", " ABBBBBA ", " ABBBBBA ", + " DBBBBBD ", " D BBBBB D ", " C BBBBB C ", " A BBBBB A ", " A BBBBB A ", " A BBBBB A ", + " C BBBBB C ", " ZZZZZZZZZ " }, + { " DDDDDDDDD ", " AB BA ", " AB BA ", " AB BA ", " AB BA ", " AB BA ", + " AB BA ", " AB BA ", " AB BA ", " AB BA ", " AB BA ", " AB BA ", + " DB BD ", "D B B D", "C B B C", "A B B A", "A B B A", "A B B A", + "C B B C", "ZZZZZZZZZZZ" }, + { " DDDDDDDDD ", " AB BA ", " AB BA ", " AB BA ", " AB BA ", " AB BA ", + " AB BA ", " AB BA ", " AB BA ", " AB BA ", " AB BA ", " AB BA ", + " DB BD ", "D B B D", "C B B C", "A B B A", "A B B A", "A B B A", + "C B B C", "ZZZZZZZZZZZ" }, + { " DDDDFDDDD ", " AB BA ", " AB BA ", " AB BA ", " AB BA ", " AB BA ", + " AB BA ", " AB BA ", " AB BA ", " AB BA ", " AB BA ", " AB BA ", + " DB BD ", "D B B D", "C B B C", "A B B A", "A B B A", "A B B A", + "C B B C", "ZZZZZZZZZZZ" }, + { " DDDDDDDDD ", " AB BA ", " AB BA ", " AB BA ", " AB BA ", " AB BA ", + " AB BA ", " AB BA ", " AB BA ", " AB BA ", " AB BA ", " AB BA ", + " DB BD ", "D B B D", "C B B C", "A B B A", "A B B A", "A B B A", + "C B B C", "ZZZZZZZZZZZ" }, + { " DDDDDDDDD ", " AB BA ", " AB BA ", " AB BA ", " AB BA ", " AB BA ", + " AB BA ", " AB BA ", " AB BA ", " AB BA ", " AB BA ", " AB BA ", + " DB BD ", "D B B D", "C B B C", "A B B A", "A B B A", "A B B A", + "C B B C", "ZZZZZZZZZZZ" }, + { " DDDDDDD ", " ABBBBBA ", " ABBBBBA ", " ABBBBBA ", " ABBBBBA ", " ABBBBBA ", + " ABBBBBA ", " ABBBBBA ", " ABBBBBA ", " ABBBBBA ", " ABBBBBA ", " ABBBBBA ", + " DBBBBBD ", " D BBBBB D ", " C BBBBB C ", " A BBBBB A ", " A BBBBB A ", " A BBBBB A ", + " C BBBBB C ", " ZZZZZZZZZ " }, + { " DDDDD ", " AAAAA ", " AAAAA ", " AAAAA ", " AAAAA ", " AAAAA ", + " AAAAA ", " AAAAA ", " AAAAA ", " AAAAA ", " AAAAA ", " AAAAA ", + " DDDDD ", " D D ", " C C ", " A A ", " A A ", " A A ", + " C C ", " ZZZZZZZ " }, + { " ", " ", " ", " ", " ", " ", + " ", " ", " ", " ", " ", " ", + " ", " DDDDD ", " CCCCC ", " AAAAA ", " AAAAA ", " AAAAA ", + " CCCCC ", " ZZZZZ " } }) + .addElement( + 'B', + withChannel( + "coil", + ofChain( + onElementPass( + te -> te.hasNormalCoils = false, + ofCoil( + GregTechMetaTileEntity_MegaAlloyBlastSmelter::setCoilLevel, + GregTechMetaTileEntity_MegaAlloyBlastSmelter::getCoilLevel)), + onElementPass(te -> te.hasNormalCoils = true, ofBlock(ModBlocks.blockCasingsMisc, 14))))) + + .addElement( + 'Z', + buildHatchAdder(GregTechMetaTileEntity_MegaAlloyBlastSmelter.class) + .atLeast(InputHatch, OutputHatch, InputBus, OutputBus, Energy, ExoticEnergy) + .casingIndex(TAE.GTPP_INDEX(15)) + .dot(1) + .buildAndChain(ofBlock(ModBlocks.blockCasingsMisc, 15))) + .addElement( + 'E', + buildHatchAdder(GregTechMetaTileEntity_MegaAlloyBlastSmelter.class).atLeast(Maintenance) + .casingIndex(TAE.GTPP_INDEX(15)) + .dot(2) + .buildAndChain(ofBlock(ModBlocks.blockCasingsMisc, 15))) + .addElement('D', ofBlock(ModBlocks.blockCasingsMisc, 15)) + .addElement('C', ofBlock(ModBlocks.blockCasingsMisc, 14)) + .addElement( + 'A', + withChannel( + "glass", + BorosilicateGlass.ofBoroGlass((byte) -1, (te, t) -> te.glassTier = t, te -> te.glassTier))) + .addElement('F', Muffler.newAny(TAE.GTPP_INDEX(15), 3)) + .build(); + + public GregTechMetaTileEntity_MegaAlloyBlastSmelter(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregTechMetaTileEntity_MegaAlloyBlastSmelter(String aName) { + super(aName); + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return true; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic() { + + @NotNull + @Override + protected CheckRecipeResult validateRecipe(@NotNull GT_Recipe recipe) { + if (glassTier < GT_Utility.getTier(recipe.mEUt)) { + return CheckRecipeResultRegistry.insufficientMachineTier(GT_Utility.getTier(recipe.mEUt)); + } + return CheckRecipeResultRegistry.SUCCESSFUL; + } + + @NotNull + @Override + protected GT_OverclockCalculator createOverclockCalculator(@NotNull GT_Recipe recipe) { + return super.createOverclockCalculator(recipe) + .setSpeedBoost((float) (1.0 - getCoilDiscount(coilLevel))); + } + }.setMaxParallel(MAX_PARALLELS); + } + + @Override + protected void setProcessingLogicPower(ProcessingLogic logic) { + logic.setAvailableVoltage(getMaxInputEu()); + logic.setAvailableAmperage(1); + } + + @Override + public boolean addOutputToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + boolean exotic = addExoticEnergyInputToMachineList(aTileEntity, aBaseCasingIndex); + return super.addToMachineList(aTileEntity, aBaseCasingIndex) || exotic; + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + glassTier = -1; + coilLevel = HeatingCoilLevel.None; + if (!checkPiece("main", 5, 16, 0)) return false; + if (hasNormalCoils) coilLevel = HeatingCoilLevel.None; + if (mMaintenanceHatches.size() != 1) return false; + if (mMufflerHatches.size() != 1) return false; + if (this.glassTier < 10 && !getExoticAndNormalEnergyHatchList().isEmpty()) { + for (GT_MetaTileEntity_Hatch hatchEnergy : getExoticAndNormalEnergyHatchList()) { + if (this.glassTier < hatchEnergy.mTier) { + return false; + } + } + } + // Disallow lasers if the glass is below UV tier + if (glassTier < 8) { + for (GT_MetaTileEntity_Hatch hatchEnergy : getExoticEnergyHatches()) { + if (hatchEnergy.getConnectionType() == GT_MetaTileEntity_Hatch.ConnectionType.LASER) { + return false; + } + } + } + return true; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return 10000; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + public double getCoilDiscount(HeatingCoilLevel lvl) { + // Since there are only 14 tiers (starting from 0), this is what the function is. + double unRounded = (lvl != null ? lvl.getTier() : 0) / 130.0D; + if (unRounded < 0) return 1F; + double rounded = Math.floor(unRounded * 1000) / 1000; + + return Math.max(0, rounded); + } + + @Override + public void explodeMultiblock() { + super.explodeMultiblock(); + } + + @Override + public List<GT_MetaTileEntity_Hatch> getExoticAndNormalEnergyHatchList() { + List<GT_MetaTileEntity_Hatch> tHatches = new ArrayList<>(); + tHatches.addAll(mExoticEnergyHatches); + tHatches.addAll(mEnergyHatches); + return tHatches; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece("main", stackSize, hintsOnly, 5, 16, 0); + } + + @Override + public IStructureDefinition<GregTechMetaTileEntity_MegaAlloyBlastSmelter> getStructureDefinition() { + return STRUCTURE_DEFINITION; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType("Fluid Alloy Cooker") + .addInfo("Controller block for the Mega Alloy Blast Smelter") + .addInfo( + "Runs the same recipes as the normal ABS, except with up to " + EnumChatFormatting.BOLD + + EnumChatFormatting.UNDERLINE + + MAX_PARALLELS + + EnumChatFormatting.RESET + + EnumChatFormatting.GRAY + + " parallels.") + .addInfo("Every coil tier above cupronickel grants a speed bonus, based on this function:") + .addInfo("Bonus = TIER / 150, rounded to the nearest thousandth.") + .addInfo( + EnumChatFormatting.ITALIC + + "Can also use normal ABS coils in their place instead, if you don't like the bonuses :)" + + EnumChatFormatting.RESET + + EnumChatFormatting.GRAY) + .addInfo("The glass limits the tier of the energy hatch. UEV glass unlocks all tiers.") + .addInfo("UV glass required for TecTech laser hatches.") + .addInfo( + EnumChatFormatting.ITALIC + "\"all it does is make metals hot\"" + + EnumChatFormatting.RESET + + EnumChatFormatting.GRAY) + .beginStructureBlock(11, 20, 11, false) + .addStructureInfo("This structure is too complex! See schematic for details.") + .addMaintenanceHatch("Around the controller", 2) + .addOtherStructurePart("Input Bus, Output Bus, Input Hatch, Output Bus, Energy Hatch", "Bottom Casing", 1) + .addMufflerHatch("1 in the center of the top layer", 3) + .toolTipFinisher( + EnumChatFormatting.AQUA + "MadMan310 " + + EnumChatFormatting.GRAY + + "via " + + EnumChatFormatting.RED + + "GT++"); + return tt; + } + + @Override + public String[] getInfoData() { + long storedEnergy = 0; + long maxEnergy = 0; + int paras = getBaseMetaTileEntity().isActive() ? processingLogic.getCurrentParallels() : 0; + int discountP = (int) (getCoilDiscount(coilLevel) * 1000) / 10; + + for (GT_MetaTileEntity_Hatch tHatch : filterValidMTEs(mExoticEnergyHatches)) { + storedEnergy += tHatch.getBaseMetaTileEntity() + .getStoredEU(); + maxEnergy += tHatch.getBaseMetaTileEntity() + .getEUCapacity(); + } + + return new String[] { "------------ Critical Information ------------", + StatCollector.translateToLocal("GT5U.multiblock.Progress") + ": " + + EnumChatFormatting.GREEN + + GT_Utility.formatNumbers(mProgresstime) + + EnumChatFormatting.RESET + + "t / " + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(mMaxProgresstime) + + EnumChatFormatting.RESET + + "t", + StatCollector.translateToLocal("GT5U.multiblock.energy") + ": " + + EnumChatFormatting.GREEN + + GT_Utility.formatNumbers(storedEnergy) + + EnumChatFormatting.RESET + + " EU / " + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(maxEnergy) + + EnumChatFormatting.RESET + + " EU", + StatCollector.translateToLocal("GT5U.multiblock.usage") + ": " + + EnumChatFormatting.RED + + GT_Utility.formatNumbers(-lEUt) + + EnumChatFormatting.RESET + + " EU/t", + StatCollector.translateToLocal("GT5U.multiblock.mei") + ": " + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(getAverageInputVoltage()) + + EnumChatFormatting.RESET + + " EU/t(*" + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(getMaxInputAmps()) + + EnumChatFormatting.RESET + + "A) " + + StatCollector.translateToLocal("GT5U.machines.tier") + + ": " + + EnumChatFormatting.YELLOW + + GT_Values.VN[GT_Utility.getTier(getAverageInputVoltage())] + + EnumChatFormatting.RESET, + "Parallels: " + EnumChatFormatting.BLUE + paras + EnumChatFormatting.RESET, + "Coil Discount: " + EnumChatFormatting.BLUE + discountP + "%" + EnumChatFormatting.RESET, + "-----------------------------------------" }; + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GregTechMetaTileEntity_MegaAlloyBlastSmelter(this.mName); + } + + @Override + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, ForgeDirection side, ForgeDirection facing, + int aColorIndex, boolean aActive, boolean aRedstone) { + if (side == facing) { + if (aActive) { + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(15)), + TextureFactory.builder() + .addIcon(TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active) + .extFacing() + .build() }; + } + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(15)), + TextureFactory.builder() + .addIcon(TexturesGtBlock.Overlay_Machine_Controller_Advanced) + .extFacing() + .build() }; + } + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(15)) }; + } + + @Override + public RecipeMap<?> getRecipeMap() { + return GTPPRecipeMaps.alloyBlastSmelterRecipes; + } + + public HeatingCoilLevel getCoilLevel() { + return coilLevel; + } + + public void setCoilLevel(HeatingCoilLevel coilLevel) { + this.coilLevel = coilLevel; + } + + @Override + public final void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + if (aPlayer.isSneaking()) { + // Lock to single recipe + super.onScrewdriverRightClick(side, aPlayer, aX, aY, aZ); + } else { + inputSeparation = !inputSeparation; + GT_Utility.sendChatToPlayer( + aPlayer, + StatCollector.translateToLocal("GT5U.machines.separatebus") + " " + inputSeparation); + } + } + + @Override + public boolean onWireCutterRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer aPlayer, + float aX, float aY, float aZ, ItemStack aTool) { + if (aPlayer.isSneaking()) { + batchMode = !batchMode; + if (batchMode) { + GT_Utility.sendChatToPlayer(aPlayer, "Batch recipes."); + } else { + GT_Utility.sendChatToPlayer(aPlayer, "Don't batch recipes."); + } + } + + return true; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return 102400; + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + return survivialBuildPiece("main", stackSize, 5, 16, 0, elementBudget, env, false, true); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + this.glassTier = aNBT.getByte("glassTier"); + if (!aNBT.hasKey(INPUT_SEPARATION_NBT_KEY)) { + inputSeparation = aNBT.getBoolean("separateBusses"); + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setByte("glassTier", glassTier); + super.saveNBTData(aNBT); + } + + @Override + public boolean supportsInputSeparation() { + return true; + } + + @Override + public boolean supportsBatchMode() { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Gas.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Gas.java new file mode 100644 index 0000000000..84fac40265 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Gas.java @@ -0,0 +1,208 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.turbines; + +import static gtPlusPlus.core.lib.CORE.RANDOM; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +import org.jetbrains.annotations.NotNull; + +import gregtech.api.enums.Materials; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.SimpleCheckRecipeResult; +import gregtech.api.recipe.maps.FuelBackend; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +@SuppressWarnings("deprecation") +public class GT_MTE_LargeTurbine_Gas extends GregtechMetaTileEntity_LargerTurbineBase { + + private static final HashSet<Fluid> BLACKLIST = new HashSet<>(); + + static { + BLACKLIST.add( + Materials.Benzene.getFluid(0) + .getFluid()); + } + + public GT_MTE_LargeTurbine_Gas(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GT_MTE_LargeTurbine_Gas(String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MTE_LargeTurbine_Gas(mName); + } + + @Override + public int getCasingMeta() { + return 3; + } + + @Override + public int getCasingTextureIndex() { + return 58; + } + + @Override + protected boolean requiresOutputHatch() { + return false; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return 4000; + } + + @Override + public int getFuelValue(FluidStack aLiquid) { + if (aLiquid == null) { + return 0; + } + GT_Recipe tFuel = getRecipeMap().getBackend() + .findFuel(aLiquid); + if (tFuel != null) { + return tFuel.mSpecialValue; + } + return 0; + } + + @Override + public RecipeMap<FuelBackend> getRecipeMap() { + return RecipeMaps.gasTurbineFuels; + } + + @Override + public int getRecipeCatalystPriority() { + return -20; + } + + @Override + protected boolean filtersFluid() { + return false; + } + + @Override + public @NotNull CheckRecipeResult checkProcessing() { + List<FluidStack> fluids = getStoredFluids(); + for (FluidStack fluid : fluids) { + if (fluid != null && BLACKLIST.contains(fluid.getFluid())) { + return SimpleCheckRecipeResult.ofFailure("fuel_blacklisted"); + } + } + return super.checkProcessing(); + } + + @Override + long fluidIntoPower(ArrayList<FluidStack> aFluids, long aOptFlow, int aBaseEff, float[] flowMultipliers) { + if (aFluids.size() >= 1) { + int tEU = 0; + int actualOptimalFlow = 0; + FluidStack firstFuelType = new FluidStack(aFluids.get(0), 0); // Identify a SINGLE type of fluid to process. + // Doesn't matter which one. Ignore the rest! + int fuelValue = getFuelValue(firstFuelType); + // log("Fuel Value of "+aFluids.get(0).getLocalizedName()+" is "+fuelValue+"eu"); + if (aOptFlow < fuelValue) { + // turbine too weak and/or fuel too powerful + // at least consume 1L + this.realOptFlow = 1; + // wastes the extra fuel and generate aOptFlow directly + depleteInput(new FluidStack(firstFuelType, 1)); + this.storedFluid += 1; + return GT_Utility.safeInt((long) aOptFlow * (long) aBaseEff / 10000L); + } + + actualOptimalFlow = GT_Utility.safeInt((long) (aOptFlow * (double) flowMultipliers[1] / fuelValue)); + this.realOptFlow = actualOptimalFlow; + + int remainingFlow = GT_Utility.safeInt((long) (actualOptimalFlow * 1.25f)); // Allowed to use up to 125% of + // optimal flow. Variable + // required outside of loop for + // multi-hatch scenarios. + int flow = 0; + int totalFlow = 0; + + storedFluid = 0; + for (FluidStack aFluid : aFluids) { + if (aFluid.isFluidEqual(firstFuelType)) { + flow = Math.min(aFluid.amount, remainingFlow); // try to use up to 125% of optimal flow w/o + // exceeding remainingFlow + depleteInput(new FluidStack(aFluid, flow)); // deplete that amount + this.storedFluid += aFluid.amount; + remainingFlow -= flow; // track amount we're allowed to continue depleting from hatches + totalFlow += flow; // track total input used + } + } + if (totalFlow <= 0) return 0; + tEU = GT_Utility.safeInt((long) totalFlow * fuelValue); + + if (totalFlow == actualOptimalFlow) { + tEU = GT_Utility.safeInt((long) tEU * (long) aBaseEff / 10000L); + } else { + float efficiency = 1.0f - Math.abs((totalFlow - actualOptimalFlow) / (float) actualOptimalFlow); + tEU *= efficiency; + tEU = GT_Utility.safeInt((long) tEU * (long) aBaseEff / 10000L); + } + + return tEU; + } + return 0; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return (RANDOM.nextInt(4) == 0) ? 0 : 1; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + } + + @Override + public String getMachineType() { + return "Large Gas Turbine"; + } + + @Override + protected String getTurbineType() { + return "Gas"; + } + + @Override + protected String getCasingName() { + return "Reinforced Gas Turbine Casing"; + } + + @Override + protected ITexture getTextureFrontFace() { + return new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Controller_Advanced); + } + + @Override + protected ITexture getTextureFrontFaceActive() { + return new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Plasma.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Plasma.java new file mode 100644 index 0000000000..db99b52be1 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Plasma.java @@ -0,0 +1,314 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.turbines; + +import java.util.ArrayList; +import java.util.HashSet; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import org.jetbrains.annotations.NotNull; + +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.objects.GT_RenderedTexture; +import gregtech.api.recipe.RecipeMap; +import gregtech.api.recipe.RecipeMaps; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.recipe.check.SimpleCheckRecipeResult; +import gregtech.api.recipe.maps.FuelBackend; +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.shutdown.ShutDownReasonRegistry; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Turbine; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +@SuppressWarnings("deprecation") +public class GT_MTE_LargeTurbine_Plasma extends GregtechMetaTileEntity_LargerTurbineBase { + + private static final HashSet<Fluid> BLACKLIST = new HashSet<>(); + + public GT_MTE_LargeTurbine_Plasma(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GT_MTE_LargeTurbine_Plasma(String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MTE_LargeTurbine_Plasma(mName); + } + + @Override + public int getCasingMeta() { + return 4; + } + + @Override + public int getCasingTextureIndex() { + return 60; + } + + @Override + protected boolean requiresOutputHatch() { + return true; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return 0; + } + + @Override + public int getFuelValue(FluidStack aLiquid) { + if (aLiquid == null) { + return 0; + } + GT_Recipe tFuel = getRecipeMap().getBackend() + .findFuel(aLiquid); + if (tFuel != null) { + return tFuel.mSpecialValue; + } + return 0; + } + + @Override + public RecipeMap<FuelBackend> getRecipeMap() { + return RecipeMaps.plasmaFuels; + } + + @Override + public int getRecipeCatalystPriority() { + return -20; + } + + @Override + protected boolean filtersFluid() { + return false; + } + + @Override + public @NotNull CheckRecipeResult checkProcessing() { + + try { + ArrayList<GT_MetaTileEntity_Hatch_Turbine> aEmptyTurbineRotorHatches = getEmptyTurbineAssemblies(); + if (aEmptyTurbineRotorHatches.size() > 0) { + hatch: for (GT_MetaTileEntity_Hatch_Turbine aHatch : aEmptyTurbineRotorHatches) { + ArrayList<ItemStack> aTurbines = getAllBufferedTurbines(); + for (ItemStack aTurbineItem : aTurbines) { + if (aTurbineItem == null) { + continue; + } + if (aHatch.insertTurbine(aTurbineItem.copy())) { + depleteTurbineFromStock(aTurbineItem); + continue hatch; + } + } + } + } + + if (getEmptyTurbineAssemblies().size() > 0 || !areAllTurbinesTheSame()) { + stopMachine(ShutDownReasonRegistry.NO_TURBINE); + return CheckRecipeResultRegistry.NO_TURBINE_FOUND; + } + + ArrayList<FluidStack> tFluids = getStoredFluids(); + + if (tFluids.size() > 0) { + for (FluidStack fluid : tFluids) { + if (fluid != null && BLACKLIST.contains(fluid.getFluid())) { + return SimpleCheckRecipeResult.ofFailure("fuel_blacklisted"); + } + } + if (baseEff == 0 || optFlow == 0 + || counter >= 512 + || this.getBaseMetaTileEntity() + .hasWorkJustBeenEnabled() + || this.getBaseMetaTileEntity() + .hasInventoryBeenModified()) { + counter = 0; + + float aTotalBaseEff = 0; + float aTotalOptimalFlow = 0; + + ItemStack aStack = getFullTurbineAssemblies().get(0) + .getTurbine(); + aTotalBaseEff += GT_Utility.safeInt( + (long) ((5F + ((GT_MetaGenerated_Tool) aStack.getItem()).getToolCombatDamage(aStack)) * 1000F)); + aTotalOptimalFlow += GT_Utility.safeInt( + (long) Math.max( + Float.MIN_NORMAL, + ((GT_MetaGenerated_Tool) aStack.getItem()).getToolStats(aStack) + .getSpeedMultiplier() * GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mToolSpeed + * 50)); + + // Calculate total EU/t (as shown on turbine tooltip (Fast mode doesn't affect)) + double aEUPerTurbine = aTotalOptimalFlow * 40 + * 0.0105 + * GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mPlasmaMultiplier + * (50.0f + (10.0f * ((GT_MetaGenerated_Tool) aStack.getItem()).getToolCombatDamage(aStack))); + aTotalOptimalFlow *= getSpeedMultiplier(); + + if (aTotalOptimalFlow < 0) { + aTotalOptimalFlow = 100; + } + + flowMultipliers[0] = GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mSteamMultiplier; + flowMultipliers[1] = GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mGasMultiplier; + flowMultipliers[2] = GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mPlasmaMultiplier; + baseEff = MathUtils.roundToClosestInt(aTotalBaseEff); + optFlow = MathUtils.roundToClosestInt(aTotalOptimalFlow); + euPerTurbine = MathUtils.roundToClosestInt(aEUPerTurbine); + if (optFlow <= 0 || baseEff <= 0) { + stopMachine(ShutDownReasonRegistry.NONE); // in case the turbine got removed + return CheckRecipeResultRegistry.NO_FUEL_FOUND; + } + } else { + counter++; + } + } + + // How much the turbine should be producing with this flow + long newPower = fluidIntoPower(tFluids, optFlow, baseEff, flowMultipliers); + + // Reduce produced power depending on the ratio between fuel value and turbine EU/t with the following + // formula: + // EU/t = EU/t * MIN(1, ( ( (FuelValue / 200) ^ 2 ) / EUPerTurbine)) + int fuelValue = 0; + if (tFluids.size() > 0) { + fuelValue = getFuelValue(new FluidStack(tFluids.get(0), 0)); + } + float magicValue = (fuelValue * 0.005f) * (fuelValue * 0.005f); + float efficiencyLoss = Math.min(1.0f, magicValue / euPerTurbine); + newPower *= efficiencyLoss; + + long difference = newPower - this.lEUt; // difference between current output and new output + + // Magic numbers: can always change by at least 10 eu/t, but otherwise by at most 1 percent of the + // difference in power level (per tick) + // This is how much the turbine can actually change during this tick + int maxChangeAllowed = Math.max(10, GT_Utility.safeInt((long) Math.abs(difference) / 100)); + + if (Math.abs(difference) > maxChangeAllowed) { // If this difference is too big, use the maximum allowed + // change + int change = maxChangeAllowed * (difference > 0 ? 1 : -1); // Make the change positive or negative. + this.lEUt += change; // Apply the change + } else { + this.lEUt = newPower; + } + if (this.lEUt <= 0) { + this.lEUt = 0; + this.mEfficiency = 0; + return CheckRecipeResultRegistry.NO_FUEL_FOUND; + } else { + this.mMaxProgresstime = 20; + this.mEfficiencyIncrease = 10; + // Overvoltage is handled inside the MultiBlockBase when pushing out to dynamos. no need to do it here. + // Play sounds (GT++ addition - GT multiblocks play no sounds) + enableAllTurbineHatches(); + return CheckRecipeResultRegistry.GENERATING; + } + } catch (Throwable t) { + t.printStackTrace(); + } + return CheckRecipeResultRegistry.NO_FUEL_FOUND; + } + + @Override + long fluidIntoPower(ArrayList<FluidStack> aFluids, long aOptFlow, int aBaseEff, float[] flowMultipliers) { + if (aFluids.size() >= 1) { + aOptFlow *= 800; // CHANGED THINGS HERE, check recipe runs once per 20 ticks + int tEU = 0; + + int actualOptimalFlow = 0; + + FluidStack firstFuelType = new FluidStack(aFluids.get(0), 0); // Identify a SINGLE type of fluid to process. + // Doesn't matter which one. Ignore the rest! + int fuelValue = getFuelValue(firstFuelType); + actualOptimalFlow = GT_Utility + .safeInt((long) Math.ceil((double) aOptFlow * (double) flowMultipliers[2] / (double) fuelValue)); + this.realOptFlow = actualOptimalFlow; // For scanner info + + int remainingFlow = GT_Utility.safeInt((long) (actualOptimalFlow * 1.25f)); // Allowed to use up to 125% of + // optimal flow. Variable + // required outside of loop for + // multi-hatch scenarios. + int flow = 0; + int totalFlow = 0; + + storedFluid = 0; + for (FluidStack aFluid : aFluids) { + if (aFluid.isFluidEqual(firstFuelType)) { + flow = Math.min(aFluid.amount, remainingFlow); // try to use up w/o exceeding remainingFlow + depleteInput(new FluidStack(aFluid, flow)); // deplete that amount + this.storedFluid += aFluid.amount; + remainingFlow -= flow; // track amount we're allowed to continue depleting from hatches + totalFlow += flow; // track total input used + } + } + String fn = FluidRegistry.getFluidName(firstFuelType); + String[] nameSegments = fn.split("\\.", 2); + if (nameSegments.length == 2) { + String outputName = nameSegments[1]; + FluidStack output = FluidRegistry.getFluidStack(outputName, totalFlow); + if (output == null) { + output = FluidRegistry.getFluidStack("molten." + outputName, totalFlow); + } + if (output != null) { + addOutput(output); + } + } + if (totalFlow <= 0) return 0; + tEU = GT_Utility.safeInt((long) ((fuelValue / 20D) * (double) totalFlow)); + + if (totalFlow == actualOptimalFlow) { + tEU = GT_Utility.safeInt((long) (aBaseEff / 10000D * tEU)); + } else { + double efficiency = 1.0D - Math.abs((totalFlow - actualOptimalFlow) / (float) actualOptimalFlow); + + tEU = (int) (tEU * efficiency); + tEU = GT_Utility.safeInt((long) (aBaseEff / 10000D * tEU)); + } + + return tEU; + } + return 0; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 1; + } + + @Override + public String getMachineType() { + return "Large Plasma Turbine"; + } + + @Override + protected String getTurbineType() { + return "Plasma"; + } + + @Override + protected String getCasingName() { + return "Reinforced Plasma Turbine Casing"; + } + + @Override + protected ITexture getTextureFrontFace() { + return new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Controller_Advanced); + } + + @Override + protected ITexture getTextureFrontFaceActive() { + return new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_SCSteam.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_SCSteam.java new file mode 100644 index 0000000000..7ee40757fd --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_SCSteam.java @@ -0,0 +1,126 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.turbines; + +import java.util.ArrayList; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.render.TextureFactory; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GT_MTE_LargeTurbine_SCSteam extends GregtechMetaTileEntity_LargerTurbineBase { + + public GT_MTE_LargeTurbine_SCSteam(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GT_MTE_LargeTurbine_SCSteam(String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MTE_LargeTurbine_SCSteam(mName); + } + + @Override + public int getCasingMeta() { + return 15; + } + + @Override + public int getCasingTextureIndex() { + return 1538; + } + + @Override + protected boolean requiresOutputHatch() { + return true; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return 0; + } + + @Override + public int getFuelValue(FluidStack aLiquid) { + return 0; + } + + @Override + long fluidIntoPower(ArrayList<FluidStack> aFluids, long aOptFlow, int aBaseEff, float[] flowMultipliers) { + int tEU = 0; + int totalFlow = 0; // Byproducts are based on actual flow + int flow = 0; + // Variable required outside of loop for + // multi-hatch scenarios. + this.realOptFlow = aOptFlow; + // this.realOptFlow = (double) aOptFlow * (double) flowMultipliers[0]; + // Will there be an multiplier for SC? + int remainingFlow = MathUtils.safeInt((long) (realOptFlow * 1.25f)); // Allowed to use up to + // 125% of optimal flow. + + storedFluid = 0; + FluidStack tSCSteam = FluidRegistry.getFluidStack("supercriticalsteam", 1); + for (int i = 0; i < aFluids.size() && remainingFlow > 0; i++) { + if (GT_Utility.areFluidsEqual(aFluids.get(i), tSCSteam, true)) { + flow = Math.min(aFluids.get(i).amount, remainingFlow); // try to use up w/o exceeding remainingFlow + depleteInput(new FluidStack(aFluids.get(i), flow)); // deplete that amount + this.storedFluid += aFluids.get(i).amount; + remainingFlow -= flow; // track amount we're allowed to continue depleting from hatches + totalFlow += flow; // track total input used + } + } + if (totalFlow <= 0) return 0; + tEU = totalFlow; + addOutput(GT_ModHandler.getSteam(totalFlow)); + if (totalFlow != realOptFlow) { + float efficiency = 1.0f - Math.abs((totalFlow - (float) realOptFlow) / (float) realOptFlow); + // if(totalFlow>aOptFlow){efficiency = 1.0f;} + tEU *= efficiency; + tEU = Math.max(1, MathUtils.safeInt((long) tEU * (long) aBaseEff / 10000L)); + } else { + tEU = MathUtils.safeInt((long) tEU * (long) aBaseEff / 10000L); + } + + return tEU * 100L; + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 8; + } + + @Override + public String getMachineType() { + return "Large Supercritical Steam Turbine"; + } + + @Override + protected String getTurbineType() { + return "Supercritical Steam"; + } + + @Override + protected String getCasingName() { + return "Reinforced SC Turbine Casing"; + } + + @Override + protected ITexture getTextureFrontFace() { + return TextureFactory.of(TexturesGtBlock.Overlay_Machine_Controller_Advanced); + } + + @Override + protected ITexture getTextureFrontFaceActive() { + return TextureFactory.of(TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_SHSteam.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_SHSteam.java new file mode 100644 index 0000000000..d1346d3a51 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_SHSteam.java @@ -0,0 +1,204 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.turbines; + +import java.util.ArrayList; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +import gregtech.GT_Mod; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +@SuppressWarnings("deprecation") +public class GT_MTE_LargeTurbine_SHSteam extends GregtechMetaTileEntity_LargerTurbineBase { + + public boolean achievement = false; + private boolean looseFit = false; + + public GT_MTE_LargeTurbine_SHSteam(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GT_MTE_LargeTurbine_SHSteam(String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MTE_LargeTurbine_SHSteam(mName); + } + + @Override + public int getCasingMeta() { + return 2; + } + + @Override + public int getCasingTextureIndex() { + return 59; + } + + @Override + protected boolean requiresOutputHatch() { + return true; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return 0; + } + + @Override + public int getFuelValue(FluidStack aLiquid) { + return 0; + } + + @Override + long fluidIntoPower(ArrayList<FluidStack> aFluids, long aOptFlow, int aBaseEff, float[] flowMultipliers) { + if (looseFit) { + aOptFlow *= 4; + if (aBaseEff > 10000) { + aOptFlow *= Math.pow(1.1f, ((aBaseEff - 7500) / 10000F) * 20f); + aBaseEff = 7500; + } else if (aBaseEff > 7500) { + aOptFlow *= Math.pow(1.1f, ((aBaseEff - 7500) / 10000F) * 20f); + aBaseEff *= 0.75f; + } else { + aBaseEff *= 0.75f; + } + } + // prevent overflow like that in SC Steam + long tEU = 0; + int totalFlow = 0; // Byproducts are based on actual flow + int flow = 0; + + // Variable required outside of loop for + // multi-hatch scenarios. + this.realOptFlow = aOptFlow * flowMultipliers[0]; + + int remainingFlow = MathUtils.safeInt((long) (realOptFlow * 1.25f)); // Allowed to use up to + // 125% of optimal flow. + + storedFluid = 0; + for (int i = 0; i < aFluids.size() && remainingFlow > 0; i++) { + String fluidName = aFluids.get(i) + .getFluid() + .getUnlocalizedName(aFluids.get(i)); + if (fluidName.equals("ic2.fluidSuperheatedSteam")) { + flow = Math.min(aFluids.get(i).amount, remainingFlow); // try to use up w/o exceeding remainingFlow + depleteInput(new FluidStack(aFluids.get(i), flow)); // deplete that amount + this.storedFluid += aFluids.get(i).amount; + remainingFlow -= flow; // track amount we're allowed to continue depleting from hatches + totalFlow += flow; // track total input used + if (!achievement) { + try { + GT_Mod.achievements.issueAchievement( + this.getBaseMetaTileEntity() + .getWorld() + .getPlayerEntityByName( + this.getBaseMetaTileEntity() + .getOwnerName()), + "efficientsteam"); + } catch (Exception e) {} + achievement = true; + } + } else if (fluidName.equals("fluid.steam") || fluidName.equals("ic2.fluidSteam") + || fluidName.equals("fluid.mfr.steam.still.name")) { + depleteInput(new FluidStack(aFluids.get(i), aFluids.get(i).amount)); + } + } + if (totalFlow <= 0) return 0; + tEU = totalFlow; + addOutput(GT_ModHandler.getSteam(totalFlow)); + if (totalFlow != realOptFlow) { + float efficiency = 1.0f - Math.abs((totalFlow - (float) realOptFlow) / (float) realOptFlow); + // if(totalFlow>aOptFlow){efficiency = 1.0f;} + tEU *= efficiency; + tEU = Math.max(1L, tEU * aBaseEff / 10000L); + } else { + tEU = tEU * aBaseEff / 10000L; + } + + return tEU; + } + + @Override + public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + // Using a screwdriver to change modes should allow for any combination of Slow/Fast and Tight/Loose Mode + // Whenever there's a mode switch, there will be two messages on the player chat + // The two messages specify which two modes the turbine is on after the change + // (Tight/Loose changes on every action, Slow/Fast changes every other action, all pairs are cycled this way) + if (side == getBaseMetaTileEntity().getFrontFacing()) { + looseFit ^= true; + GT_Utility.sendChatToPlayer( + aPlayer, + looseFit ? "Fitting is Loose (Higher Flow)" : "Fitting is Tight (Higher Efficiency)"); + } + + if (looseFit) { + super.onModeChangeByScrewdriver(side, aPlayer, aX, aY, aZ); + } else if (mFastMode) { + PlayerUtils.messagePlayer(aPlayer, "Running in Fast (48x) Mode."); + } else { + PlayerUtils.messagePlayer(aPlayer, "Running in Slow (16x) Mode."); + } + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return (looseFit && CORE.RANDOM.nextInt(4) == 0) ? 0 : 1; + } + + @Override + public boolean isLooseMode() { + return looseFit; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("turbineFitting", looseFit); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + looseFit = aNBT.getBoolean("turbineFitting"); + } + + @Override + public String getMachineType() { + return "Large Super-heated Steam Turbine"; + } + + @Override + protected String getTurbineType() { + return "Super-heated Steam"; + } + + @Override + protected String getCasingName() { + return "Reinforced HP Steam Turbine Casing"; + } + + @Override + protected ITexture getTextureFrontFace() { + return new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Controller_Advanced); + } + + @Override + protected ITexture getTextureFrontFaceActive() { + return new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Steam.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Steam.java new file mode 100644 index 0000000000..c882b84aab --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GT_MTE_LargeTurbine_Steam.java @@ -0,0 +1,215 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.turbines; + +import static gtPlusPlus.core.lib.CORE.RANDOM; + +import java.util.ArrayList; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +import gregtech.GT_Mod; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_ModHandler; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +@SuppressWarnings("deprecation") +public class GT_MTE_LargeTurbine_Steam extends GregtechMetaTileEntity_LargerTurbineBase { + + private float water; + private boolean achievement = false; + private boolean looseFit = false; + + public GT_MTE_LargeTurbine_Steam(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GT_MTE_LargeTurbine_Steam(String aName) { + super(aName); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MTE_LargeTurbine_Steam(mName); + } + + @Override + public int getCasingMeta() { + return 1; + } + + @Override + public int getCasingTextureIndex() { + return 16; + } + + @Override + protected boolean requiresOutputHatch() { + return true; + } + + @Override + public int getPollutionPerSecond(ItemStack aStack) { + return 0; + } + + private int useWater(float input) { + water = water + input; + int usage = (int) water; + water = water - usage; + return usage; + } + + @Override + public int getFuelValue(FluidStack aLiquid) { + return 0; + } + + @Override + long fluidIntoPower(ArrayList<FluidStack> aFluids, long aOptFlow, int aBaseEff, float[] flowMultipliers) { + if (looseFit) { + aOptFlow *= 4; + if (aBaseEff > 10000) { + aOptFlow *= Math.pow(1.1f, ((aBaseEff - 7500) / 10000F) * 20f); + aBaseEff = 7500; + } else if (aBaseEff > 7500) { + aOptFlow *= Math.pow(1.1f, ((aBaseEff - 7500) / 10000F) * 20f); + aBaseEff *= 0.75f; + } else { + aBaseEff *= 0.75f; + } + } + // prevent overflow like that in SC Steam + long tEU = 0; + int totalFlow = 0; // Byproducts are based on actual flow + int flow = 0; + + // Variable required outside of loop for + // multi-hatch scenarios. + this.realOptFlow = aOptFlow * flowMultipliers[0]; + + int remainingFlow = MathUtils.safeInt((long) (realOptFlow * 1.25f)); // Allowed to + // use up to + // 125% of + // optimal flow. + + storedFluid = 0; + for (int i = 0; i < aFluids.size() && remainingFlow > 0; i++) { // loop through each hatch; extract inputs and + // track totals. + String fluidName = aFluids.get(i) + .getFluid() + .getUnlocalizedName(aFluids.get(i)); + if (fluidName.equals("fluid.steam") || fluidName.equals("ic2.fluidSteam") + || fluidName.equals("fluid.mfr.steam.still.name")) { + flow = Math.min(aFluids.get(i).amount, remainingFlow); // try to use up w/o exceeding remainingFlow + depleteInput(new FluidStack(aFluids.get(i), flow)); // deplete that amount + this.storedFluid += aFluids.get(i).amount; + remainingFlow -= flow; // track amount we're allowed to continue depleting from hatches + totalFlow += flow; // track total input used + if (!achievement) { + GT_Mod.achievements.issueAchievement( + this.getBaseMetaTileEntity() + .getWorld() + .getPlayerEntityByName( + this.getBaseMetaTileEntity() + .getOwnerName()), + "muchsteam"); + achievement = true; + } + } else if (fluidName.equals("ic2.fluidSuperheatedSteam")) { + depleteInput(new FluidStack(aFluids.get(i), aFluids.get(i).amount)); + } + } + if (totalFlow <= 0) return 0; + tEU = totalFlow; + int waterToOutput = useWater(totalFlow / 160.0f); + addOutput(GT_ModHandler.getDistilledWater(waterToOutput)); + if (totalFlow != realOptFlow) { + float efficiency = 1.0f - Math.abs((totalFlow - (float) realOptFlow) / (float) realOptFlow); + // if(totalFlow>aOptFlow){efficiency = 1.0f;} + tEU *= efficiency; + tEU = Math.max(1L, tEU * aBaseEff / 20000L); + } else { + tEU = tEU * aBaseEff / 20000L; + } + + return tEU; + } + + @Override + public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + // Using a screwdriver to change modes should allow for any combination of Slow/Fast and Tight/Loose Mode + // Whenever there's a mode switch, there will be two messages on the player chat + // The two messages specify which two modes the turbine is on after the change + // (Tight/Loose changes on every action, Slow/Fast changes every other action, all pairs are cycled this way) + if (side == getBaseMetaTileEntity().getFrontFacing()) { + looseFit ^= true; + GT_Utility.sendChatToPlayer( + aPlayer, + looseFit ? "Fitting: Loose - More Flow" : "Fitting: Tight - More Efficiency"); + } + + if (looseFit) { + super.onModeChangeByScrewdriver(side, aPlayer, aX, aY, aZ); + } else if (mFastMode) { + PlayerUtils.messagePlayer(aPlayer, "Running in Fast (48x) Mode."); + } else { + PlayerUtils.messagePlayer(aPlayer, "Running in Slow (16x) Mode."); + } + } + + @Override + public int getDamageToComponent(ItemStack aStack) { + return (looseFit && RANDOM.nextInt(4) == 0) ? 0 : 1; + } + + @Override + public boolean isLooseMode() { + return looseFit; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setBoolean("turbineFitting", looseFit); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + looseFit = aNBT.getBoolean("turbineFitting"); + } + + @Override + public String getMachineType() { + return "Large Steam Turbine"; + } + + @Override + protected String getTurbineType() { + return "Steam"; + } + + @Override + protected String getCasingName() { + return "Reinforced Steam Turbine Casing"; + } + + @Override + protected ITexture getTextureFrontFace() { + return new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Controller_Advanced); + } + + @Override + protected ITexture getTextureFrontFaceActive() { + return new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Controller_Advanced_Active); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GregtechMetaTileEntity_LargerTurbineBase.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GregtechMetaTileEntity_LargerTurbineBase.java new file mode 100644 index 0000000000..eec137cea2 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/production/turbines/GregtechMetaTileEntity_LargerTurbineBase.java @@ -0,0 +1,893 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.turbines; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.lazy; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static gregtech.api.enums.GT_HatchElement.Dynamo; +import static gregtech.api.enums.GT_HatchElement.InputBus; +import static gregtech.api.enums.GT_HatchElement.InputHatch; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.GT_HatchElement.Muffler; +import static gregtech.api.enums.GT_HatchElement.OutputHatch; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_Utility.filterValidMTEs; +import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTDynamo; + +import java.util.ArrayList; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits; +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; + +import gregtech.api.enums.Materials; +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.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Dynamo; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Muffler; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.CheckRecipeResultRegistry; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gregtech.api.util.shutdown.ShutDownReason; +import gregtech.api.util.shutdown.ShutDownReasonRegistry; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.data.AutoMap; +import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Turbine; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; + +public abstract class GregtechMetaTileEntity_LargerTurbineBase + extends GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_LargerTurbineBase> implements ISurvivalConstructable { + + protected int baseEff = 0; + protected long optFlow = 0; + protected long euPerTurbine = 0; + protected double realOptFlow = 0; + protected int storedFluid = 0; + protected int counter = 0; + protected boolean mFastMode = false; + protected double mufflerReduction = 1; + protected float[] flowMultipliers = new float[] { 1, 1, 1 }; + + public ITexture frontFace; + public ITexture frontFaceActive; + + public ArrayList<GT_MetaTileEntity_Hatch_Turbine> mTurbineRotorHatches = new ArrayList<>(); + + public GregtechMetaTileEntity_LargerTurbineBase(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + frontFace = getTextureFrontFace(); + frontFaceActive = getTextureFrontFaceActive(); + } + + public GregtechMetaTileEntity_LargerTurbineBase(String aName) { + super(aName); + frontFace = getTextureFrontFace(); + frontFaceActive = getTextureFrontFaceActive(); + } + + protected abstract ITexture getTextureFrontFace(); + + protected abstract ITexture getTextureFrontFaceActive(); + + protected abstract String getTurbineType(); + + protected abstract String getCasingName(); + + protected abstract boolean requiresOutputHatch(); + + @Override + protected final GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Controller Block for the XL " + getTurbineType() + " Turbine") + .addInfo("Runs as fast as 16 Large Turbines of the same type, takes the space of 12") + .addInfo("Right-click with screwdriver to enable Fast Mode, to run it even faster") + .addInfo("Optimal flow will increase or decrease accordingly on mode switch") + .addInfo("Fast Mode increases speed to 48x instead of 16x, with some penalties") + .addInfo("Maintenance problems and turbine damage happen 12x as often in Fast Mode"); + if (getTurbineType().contains("Steam")) { + tt.addInfo("XL Steam Turbines can use Loose Mode with either Slow or Fast Mode"); + } + if (getTurbineType().equals("Plasma")) { + tt.addInfo("Plasma fuel efficiency is lower for high tier turbines when using low-grade plasmas") + .addInfo("Efficiency = ((FuelValue / 200,000)^2) / (EU per Turbine)"); + } + tt.addPollutionAmount(getPollutionPerSecond(null)) + .addInfo("Pollution is 3x higher in Fast Mode") + .addSeparator() + .beginStructureBlock(7, 9, 7, false) + .addController("Top Middle") + .addCasingInfoMin(getCasingName(), 360, false) + .addCasingInfoMin("Rotor Shaft", 30, false) + .addOtherStructurePart("Rotor Assembly", "Any 1 dot hint", 1) + .addInputBus("Any 4 dot hint (min 1)", 4) + .addInputHatch("Any 4 dot hint(min 1)", 4); + if (requiresOutputHatch()) { + tt.addOutputHatch("Any 4 dot hint(min 1)", 4); + } + tt.addDynamoHatch("Any 4 dot hint(min 1)", 4) + .addMaintenanceHatch("Any 4 dot hint(min 1)", 4); + if (requiresMufflers()) { + tt.addMufflerHatch("Any 7 dot hint (x4)", 7); + } + tt.toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + private static final String STRUCTURE_PIECE_MAIN = "main"; + private static final ClassValue<IStructureDefinition<GregtechMetaTileEntity_LargerTurbineBase>> STRUCTURE_DEFINITION = new ClassValue<>() { + + @Override + @SuppressWarnings("SpellCheckingInspection") + protected IStructureDefinition<GregtechMetaTileEntity_LargerTurbineBase> computeValue(Class<?> type) { + return StructureDefinition.<GregtechMetaTileEntity_LargerTurbineBase>builder() + // c = turbine casing + // s = turbine shaft + // t = turbine housing + // h = dynamo/maint + // m = muffler + .addShape( + STRUCTURE_PIECE_MAIN, + (new String[][] { { "ccchccc", "ccccccc", "ccmmmcc", "ccm~mcc", "ccmmmcc", "ccccccc", "ccchccc" }, + { "ctchctc", "cscccsc", "cscccsc", "cscccsc", "cscccsc", "cscccsc", "ctchctc" }, + { "ccchccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccchccc" }, + { "ccchccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccchccc" }, + { "ctchctc", "cscccsc", "cscccsc", "cscccsc", "cscccsc", "cscccsc", "ctchctc" }, + { "ccchccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccchccc" }, + { "ccchccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccchccc" }, + { "ctchctc", "cscccsc", "cscccsc", "cscccsc", "cscccsc", "cscccsc", "ctchctc" }, + { "ccchccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccccccc", "ccchccc" }, })) + .addElement('c', lazy(t -> ofBlock(t.getCasingBlock(), t.getCasingMeta()))) + .addElement('s', lazy(t -> ofBlock(t.getShaftBlock(), t.getTurbineShaftMeta()))) + .addElement( + 't', + lazy( + t -> buildHatchAdder(GregtechMetaTileEntity_LargerTurbineBase.class) + .adder(GregtechMetaTileEntity_LargerTurbineBase::addTurbineHatch) + .hatchClass(GT_MetaTileEntity_Hatch_Turbine.class) + .casingIndex(t.getCasingTextureIndex()) + .dot(1) + .build())) + .addElement( + 'h', + lazy( + t -> buildHatchAdder(GregtechMetaTileEntity_LargerTurbineBase.class) + .atLeast(InputBus, InputHatch, OutputHatch, Dynamo.or(TTDynamo), Maintenance) + .casingIndex(t.getCasingTextureIndex()) + .dot(4) + .buildAndChain(t.getCasingBlock(), t.getCasingMeta()))) + .addElement( + 'm', + lazy( + t -> buildHatchAdder(GregtechMetaTileEntity_LargerTurbineBase.class).atLeast(Muffler) + .casingIndex(t.getCasingTextureIndex()) + .dot(7) + .buildAndChain(t.getCasingBlock(), t.getCasingMeta()))) + .build(); + } + }; + + @Override + public IStructureDefinition<GregtechMetaTileEntity_LargerTurbineBase> getStructureDefinition() { + return STRUCTURE_DEFINITION.get(getClass()); + } + + private boolean requiresMufflers() { + if (!PollutionUtils.isPollutionEnabled()) { + return false; + } + return getPollutionPerSecond(null) > 0; + } + + public final double getMufflerReduction() { + double totalReduction = 0; + for (GT_MetaTileEntity_Hatch_Muffler tHatch : filterValidMTEs(mMufflerHatches)) { + totalReduction += ((double) tHatch.calculatePollutionReduction(100)) / 100; + } + return totalReduction / 4; + } + + @Override + public void clearHatches() { + super.clearHatches(); + mTurbineRotorHatches.clear(); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + // we do not check for casing count here. the bare minimal is 372 but we only require 360 + boolean aStructure = checkPiece(STRUCTURE_PIECE_MAIN, 3, 3, 0); + log("Structure Check: " + aStructure); + if (mTurbineRotorHatches.size() != 12 || mMaintenanceHatches.size() != 1 + || (mDynamoHatches.size() < 1 && mTecTechDynamoHatches.size() < 1) + || (requiresMufflers() && mMufflerHatches.size() != 4) + || mInputBusses.size() < 1 + || mInputHatches.size() < 1 + || (requiresOutputHatch() && mOutputHatches.size() < 1)) { + log( + "Bad Hatches - Turbine Housings: " + mTurbineRotorHatches.size() + + ", Maint: " + + mMaintenanceHatches.size() + + ", Dynamo: " + + mDynamoHatches.size() + + ", Muffler: " + + mMufflerHatches.size() + + ", Input Buses: " + + mInputBusses.size() + + ", Input Hatches: " + + mInputHatches.size() + + ", Output Hatches: " + + mOutputHatches.size()); + return false; + } + mufflerReduction = getMufflerReduction(); + return aStructure; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(STRUCTURE_PIECE_MAIN, stackSize, hintsOnly, 3, 3, 0); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + int realBudget = elementBudget >= 200 ? elementBudget : Math.min(200, elementBudget * 2); + return survivialBuildPiece(STRUCTURE_PIECE_MAIN, stackSize, 3, 3, 0, realBudget, env, false, true); + } + + public boolean addTurbineHatch(final IGregTechTileEntity aTileEntity, final int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } + final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity == null) { + return false; + } + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Turbine aTurbineHatch) { + log("Found GT_MetaTileEntity_Hatch_Turbine"); + updateTexture(aTileEntity, aBaseCasingIndex); + IGregTechTileEntity g = this.getBaseMetaTileEntity(); + if (aTurbineHatch.setController(new BlockPos(g.getXCoord(), g.getYCoord(), g.getZCoord(), g.getWorld()))) { + boolean aDidAdd = this.mTurbineRotorHatches.add(aTurbineHatch); + Logger.INFO("Injected Controller into Turbine Assembly. Found: " + this.mTurbineRotorHatches.size()); + return aDidAdd; + } else { + Logger.INFO("Failed to inject controller into Turbine Assembly Hatch."); + } + } + log("Bad Turbine Housing"); + return false; + } + + @Override + public boolean isCorrectMachinePart(ItemStack aStack) { + return getMaxEfficiency(aStack) > 0; + } + + public Block getCasingBlock() { + return ModBlocks.blockSpecialMultiCasings; + } + + public final Block getShaftBlock() { + return ModBlocks.blockSpecialMultiCasings; + } + + public abstract int getCasingMeta(); + + public byte getTurbineShaftMeta() { + return 0; + } + + public abstract int getCasingTextureIndex(); + + public abstract int getFuelValue(FluidStack aLiquid); + + public static boolean isValidTurbine(ItemStack aTurbine) { + return (aTurbine != null && aTurbine.getItem() instanceof GT_MetaGenerated_Tool + && aTurbine.getItemDamage() >= 170 + && aTurbine.getItemDamage() <= 176); + } + + protected ArrayList<ItemStack> getAllBufferedTurbines() { + startRecipeProcessing(); + ArrayList<ItemStack> aTurbinesInStorage = new ArrayList<>(); + for (ItemStack aStack : getStoredInputs()) { + if (isValidTurbine(aStack)) { + int stackSize = aStack.stackSize; + while (stackSize > 0) { + int tmpStackSize = Math.min(stackSize, aStack.getMaxStackSize()); + ItemStack copy = aStack.copy(); + copy.stackSize = tmpStackSize; + aTurbinesInStorage.add(copy); + stackSize -= tmpStackSize; + } + } + } + endRecipeProcessing(); + return aTurbinesInStorage; + } + + public boolean areAllTurbinesTheSame() { + ArrayList<GT_MetaTileEntity_Hatch_Turbine> aTurbineAssemblies = getFullTurbineAssemblies(); + if (aTurbineAssemblies.size() < 12) { + log("Found " + aTurbineAssemblies.size() + ", expected 12."); + return false; + } + AutoMap<Materials> aTurbineMats = new AutoMap<>(); + AutoMap<Integer> aTurbineSizes = new AutoMap<>(); + for (GT_MetaTileEntity_Hatch_Turbine aHatch : aTurbineAssemblies) { + aTurbineMats.add(GT_MetaGenerated_Tool.getPrimaryMaterial(aHatch.getTurbine())); + aTurbineSizes.add(getTurbineSize(aHatch.getTurbine())); + } + Materials aBaseMat = aTurbineMats.get(0); + int aBaseSize = aTurbineSizes.get(0); + for (int aSize : aTurbineSizes) { + if (aBaseSize != aSize) { + return false; + } + } + for (Materials aMat : aTurbineMats) { + if (aBaseMat != aMat) { + return false; + } + } + return true; + } + + public static int getTurbineSize(ItemStack aTurbine) { + if (isValidTurbine(aTurbine)) { + if (aTurbine.getItemDamage() >= 170 && aTurbine.getItemDamage() < 172) { + return 1; + } else if (aTurbine.getItemDamage() >= 172 && aTurbine.getItemDamage() < 174) { + return 2; + } else if (aTurbine.getItemDamage() >= 174 && aTurbine.getItemDamage() < 176) { + return 3; + } else if (aTurbine.getItemDamage() >= 176 && aTurbine.getItemDamage() < 178) { + return 4; + } + } + return 0; + } + + public static String getTurbineSizeString(int aSize) { + return switch (aSize) { + case 1 -> "Small Turbine"; + case 2 -> "Turbine"; + case 3 -> "Large Turbine"; + case 4 -> "Huge Turbine"; + default -> ""; + }; + } + + protected ArrayList<GT_MetaTileEntity_Hatch_Turbine> getEmptyTurbineAssemblies() { + ArrayList<GT_MetaTileEntity_Hatch_Turbine> aEmptyTurbineRotorHatches = new ArrayList<>(); + // log("Checking "+mTurbineRotorHatches.size()+" Assemblies for empties."); + for (GT_MetaTileEntity_Hatch_Turbine aTurbineHatch : this.mTurbineRotorHatches) { + if (!aTurbineHatch.hasTurbine()) { + aEmptyTurbineRotorHatches.add(aTurbineHatch); + } + } + return aEmptyTurbineRotorHatches; + } + + protected ArrayList<GT_MetaTileEntity_Hatch_Turbine> getFullTurbineAssemblies() { + ArrayList<GT_MetaTileEntity_Hatch_Turbine> aTurbineRotorHatches = new ArrayList<>(); + // log("Checking "+mTurbineRotorHatches.size()+" Assemblies for Turbines."); + for (GT_MetaTileEntity_Hatch_Turbine aTurbineHatch : this.mTurbineRotorHatches) { + if (aTurbineHatch.hasTurbine()) { + // log("Found Assembly with Turbine."); + aTurbineRotorHatches.add(aTurbineHatch); + } + } + return aTurbineRotorHatches; + } + + protected void depleteTurbineFromStock(ItemStack aTurbine) { + if (aTurbine == null) { + return; + } + startRecipeProcessing(); + for (GT_MetaTileEntity_Hatch_InputBus aInputBus : this.mInputBusses) { + for (int slot = aInputBus.getSizeInventory() - 1; slot >= 0; slot--) { + ItemStack aStack = aInputBus.getStackInSlot(slot); + if (aStack != null && GT_Utility.areStacksEqual(aStack, aTurbine)) { + aStack.stackSize -= aTurbine.stackSize; + updateSlots(); + endRecipeProcessing(); + return; + } + } + } + endRecipeProcessing(); + } + + @Override + public @NotNull CheckRecipeResult checkProcessing() { + try { + ArrayList<GT_MetaTileEntity_Hatch_Turbine> aEmptyTurbineRotorHatches = getEmptyTurbineAssemblies(); + if (aEmptyTurbineRotorHatches.size() > 0) { + hatch: for (GT_MetaTileEntity_Hatch_Turbine aHatch : aEmptyTurbineRotorHatches) { + ArrayList<ItemStack> aTurbines = getAllBufferedTurbines(); + for (ItemStack aTurbineItem : aTurbines) { + if (aTurbineItem == null) { + continue; + } + if (aHatch.insertTurbine(aTurbineItem.copy())) { + depleteTurbineFromStock(aTurbineItem); + continue hatch; + } + } + } + } + + if (getEmptyTurbineAssemblies().size() > 0 || !areAllTurbinesTheSame()) { + stopMachine(ShutDownReasonRegistry.NO_TURBINE); + return CheckRecipeResultRegistry.NO_TURBINE_FOUND; + } + + ArrayList<FluidStack> tFluids = getStoredFluids(); + + if (tFluids.size() > 0) { + if (baseEff == 0 || optFlow == 0 + || counter >= 512 + || this.getBaseMetaTileEntity() + .hasWorkJustBeenEnabled() + || this.getBaseMetaTileEntity() + .hasInventoryBeenModified()) { + counter = 0; + float aTotalBaseEff = 0; + float aTotalOptimalFlow = 0; + + ItemStack aStack = getFullTurbineAssemblies().get(0) + .getTurbine(); + aTotalBaseEff += GT_Utility.safeInt( + (long) ((5F + ((GT_MetaGenerated_Tool) aStack.getItem()).getToolCombatDamage(aStack)) * 1000F)); + aTotalOptimalFlow += GT_Utility.safeInt( + (long) Math.max( + Float.MIN_NORMAL, + ((GT_MetaGenerated_Tool) aStack.getItem()).getToolStats(aStack) + .getSpeedMultiplier() * GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mToolSpeed + * 50) + * getSpeedMultiplier()); + if (aTotalOptimalFlow < 0) { + aTotalOptimalFlow = 100; + } + + flowMultipliers[0] = GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mSteamMultiplier; + flowMultipliers[1] = GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mGasMultiplier; + flowMultipliers[2] = GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mPlasmaMultiplier; + baseEff = MathUtils.roundToClosestInt(aTotalBaseEff); + optFlow = MathUtils.roundToClosestInt(aTotalOptimalFlow); + if (optFlow <= 0 || baseEff <= 0) { + stopMachine(ShutDownReasonRegistry.NONE); // in case the turbine got removed + return CheckRecipeResultRegistry.NO_FUEL_FOUND; + } + } else { + counter++; + } + } + + // How much the turbine should be producing with this flow + long newPower = fluidIntoPower(tFluids, optFlow, baseEff, flowMultipliers); + long difference = newPower - this.lEUt; // difference between current output and new output + + // Magic numbers: can always change by at least 10 eu/t, but otherwise by at most 1 percent of the + // difference in power level (per tick) + // This is how much the turbine can actually change during this tick + int maxChangeAllowed = Math.max(10, GT_Utility.safeInt(Math.abs(difference) / 100)); + + if (Math.abs(difference) > maxChangeAllowed) { // If this difference is too big, use the maximum allowed + // change + int change = maxChangeAllowed * (difference > 0 ? 1 : -1); // Make the change positive or negative. + this.lEUt += change; // Apply the change + } else { + this.lEUt = newPower; + } + if (this.lEUt <= 0) { + this.lEUt = 0; + this.mEfficiency = 0; + return CheckRecipeResultRegistry.NO_FUEL_FOUND; + } else { + this.mMaxProgresstime = 1; + this.mEfficiencyIncrease = 10; + // Overvoltage is handled inside the MultiBlockBase when pushing out to dynamos. no need to do it here. + // Play sounds (GT++ addition - GT multiblocks play no sounds) + enableAllTurbineHatches(); + return CheckRecipeResultRegistry.GENERATING; + } + } catch (Throwable t) { + t.printStackTrace(); + } + return CheckRecipeResultRegistry.NO_FUEL_FOUND; + } + + @Override + public boolean doRandomMaintenanceDamage() { + if (getMaxParallelRecipes() == 0) { + stopMachine(ShutDownReasonRegistry.NO_TURBINE); + return false; + } + + if (mRuntime++ > 1000) { + mRuntime = 0; + + if (getBaseMetaTileEntity().getRandomNumber(6000) < getMaintenanceThreshold()) { + switch (getBaseMetaTileEntity().getRandomNumber(6)) { + case 0 -> mWrench = false; + case 1 -> mScrewdriver = false; + case 2 -> mSoftHammer = false; + case 3 -> mHardHammer = false; + case 4 -> mSolderingTool = false; + case 5 -> mCrowbar = false; + } + } + for (GT_MetaTileEntity_Hatch_Turbine aHatch : getFullTurbineAssemblies()) { + // This cycle depletes durability from the turbine rotors. + // The amount of times it is run depends on turbineDamageMultiplier + // In XL turbines, durability loss is around 5.2-5.3x faster than in singles + // To compensate for that, the mEU/t scaling is divided by 5 to make it only slightly faster + for (int i = 0; i < getTurbineDamageMultiplier(); i++) { + aHatch.damageTurbine(lEUt / 5, damageFactorLow, damageFactorHigh); + } + } + } + return true; + } + + @Override + public int getMaxParallelRecipes() { + return (getFullTurbineAssemblies().size()); + } + + abstract long fluidIntoPower(ArrayList<FluidStack> aFluids, long aOptFlow, int aBaseEff, float[] flowMultipliers); + + @Override + public int getDamageToComponent(ItemStack aStack) { + return 1; + } + + @Override + public int getMaxEfficiency(ItemStack aStack) { + return this.getMaxParallelRecipes() == 12 ? 10000 : 0; + } + + @Override + public boolean explodesOnComponentBreak(ItemStack aStack) { + return false; + } + + public boolean isLooseMode() { + return false; + } + + @Override + public String[] getExtraInfoData() { + int mPollutionReduction = (int) (100 * mufflerReduction); + + String tRunning = mMaxProgresstime > 0 + ? EnumChatFormatting.GREEN + StatCollector.translateToLocal("GT5U.turbine.running.true") + + EnumChatFormatting.RESET + : EnumChatFormatting.RED + StatCollector.translateToLocal("GT5U.turbine.running.false") + + EnumChatFormatting.RESET; + + String tMaintenance = getIdealStatus() == getRepairStatus() + ? EnumChatFormatting.GREEN + StatCollector.translateToLocal("GT5U.turbine.maintenance.false") + + EnumChatFormatting.RESET + : EnumChatFormatting.RED + StatCollector.translateToLocal("GT5U.turbine.maintenance.true") + + EnumChatFormatting.RESET; + int tDura; + + StringBuilder aTurbineDamage = new StringBuilder(); + for (GT_MetaTileEntity_Hatch_Turbine aHatch : this.getFullTurbineAssemblies()) { + ItemStack aTurbine = aHatch.getTurbine(); + tDura = MathUtils.safeInt( + (long) (100.0f / GT_MetaGenerated_Tool.getToolMaxDamage(aTurbine) + * (GT_MetaGenerated_Tool.getToolDamage(aTurbine)) + 1)); + aTurbineDamage.append(EnumChatFormatting.RED) + .append(GT_Utility.formatNumbers(tDura)) + .append(EnumChatFormatting.RESET) + .append("% | "); + } + + long storedEnergy = 0; + long maxEnergy = 0; + for (GT_MetaTileEntity_Hatch_Dynamo tHatch : filterValidMTEs(mDynamoHatches)) { + storedEnergy += tHatch.getBaseMetaTileEntity() + .getStoredEU(); + maxEnergy += tHatch.getBaseMetaTileEntity() + .getEUCapacity(); + } + + boolean aIsSteam = this.getClass() + .getName() + .toLowerCase() + .contains("steam"); + + String[] ret = new String[] { + // 8 Lines available for information panels + tRunning + ": " + + EnumChatFormatting.RED + + GT_Utility.formatNumbers(((lEUt * mEfficiency) / 10000)) + + EnumChatFormatting.RESET + + " EU/t", + tMaintenance, + StatCollector.translateToLocal("GT5U.turbine.efficiency") + ": " + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers((mEfficiency / 100F)) + + EnumChatFormatting.RESET + + "%", + StatCollector.translateToLocal("GT5U.multiblock.energy") + ": " + + EnumChatFormatting.GREEN + + GT_Utility.formatNumbers(storedEnergy) + + EnumChatFormatting.RESET + + " EU / " + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(maxEnergy) + + EnumChatFormatting.RESET + + " EU", + StatCollector.translateToLocal("GT5U.turbine.flow") + ": " + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(MathUtils.safeInt((long) realOptFlow)) + + EnumChatFormatting.RESET + + " L/s" + + EnumChatFormatting.YELLOW + + " (" + + (isLooseMode() ? StatCollector.translateToLocal("GT5U.turbine.loose") + : StatCollector.translateToLocal("GT5U.turbine.tight")) + + ")", + StatCollector.translateToLocal("GT5U.turbine.fuel") + ": " + + EnumChatFormatting.GOLD + + GT_Utility.formatNumbers(storedFluid) + + EnumChatFormatting.RESET + + "L", + StatCollector.translateToLocal("GT5U.turbine.dmg") + ": " + aTurbineDamage, + StatCollector.translateToLocal("GT5U.multiblock.pollution") + ": " + + EnumChatFormatting.GREEN + + GT_Utility.formatNumbers(mPollutionReduction) + + EnumChatFormatting.RESET + + " %" }; + if (!aIsSteam) ret[4] = StatCollector.translateToLocal("GT5U.turbine.flow") + ": " + + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(MathUtils.safeInt((long) realOptFlow)) + + EnumChatFormatting.RESET + + " L/t"; + return ret; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public boolean polluteEnvironment(int aPollutionLevel) { + if (this.requiresMufflers()) { + mPollution += aPollutionLevel * getPollutionMultiplier() * mufflerReduction; + for (GT_MetaTileEntity_Hatch_Muffler tHatch : filterValidMTEs(mMufflerHatches)) { + if (mPollution >= 10000) { + if (PollutionUtils.addPollution(this.getBaseMetaTileEntity(), 10000)) { + mPollution -= 10000; + } + } else { + break; + } + } + return mPollution < 10000; + } + return true; + } + + @Override + public long maxAmperesOut() { + // This should not be a hard limit, due to TecTech dynamos + if (mFastMode) { + return 64; + } else { + return 16; + } + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setBoolean("mFastMode", mFastMode); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + mFastMode = aNBT.getBoolean("mFastMode"); + super.loadNBTData(aNBT); + } + + @Override + public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mFastMode = !mFastMode; + if (mFastMode) { + PlayerUtils.messagePlayer(aPlayer, "Running in Fast (48x) Mode."); + } else { + PlayerUtils.messagePlayer(aPlayer, "Running in Slow (16x) Mode."); + } + } + + public final ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, ForgeDirection side, + ForgeDirection facing, int aColorIndex, boolean aActive, boolean aRedstone) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[1][aColorIndex + 1], + facing == side ? getFrontFacingTurbineTexture(aActive) + : Textures.BlockIcons.getCasingTextureForId(getCasingTextureIndex()) }; + } + + protected ITexture getFrontFacingTurbineTexture(boolean isActive) { + if (isActive) { + return frontFaceActive; + } + return frontFace; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + if (aBaseMetaTileEntity.isServerSide()) { + if (this.maxProgresstime() > 0 || this.getBaseMetaTileEntity() + .hasWorkJustBeenEnabled()) { + enableAllTurbineHatches(); + } + if (this.maxProgresstime() <= 0) { + stopMachine(ShutDownReasonRegistry.NONE); + } + } + } + + @Override + public void stopMachine(@NotNull ShutDownReason reason) { + baseEff = 0; + optFlow = 0; + disableAllTurbineHatches(); + super.stopMachine(reason); + } + + @Override + public void onRemoval() { + super.onRemoval(); + for (GT_MetaTileEntity_Hatch_Turbine h : this.mTurbineRotorHatches) { + h.clearController(); + } + disableAllTurbineHatches(); + this.mTurbineRotorHatches.clear(); + } + + public void enableAllTurbineHatches() { + updateTurbineHatches(this.isMachineRunning()); + } + + public void disableAllTurbineHatches() { + updateTurbineHatches(false); + } + + private Long mLastHatchUpdate; + + public void updateTurbineHatches(boolean aState) { + if (mLastHatchUpdate == null) { + mLastHatchUpdate = System.currentTimeMillis() / 1000; + } + if (this.mTurbineRotorHatches.isEmpty() || ((System.currentTimeMillis() / 1000) - mLastHatchUpdate) <= 2) { + return; + } + for (GT_MetaTileEntity_Hatch_Turbine h : filterValidMTEs(this.mTurbineRotorHatches)) { + h.setActive(aState); + } + + mLastHatchUpdate = System.currentTimeMillis() / 1000; + } + + @Override + protected IAlignmentLimits getInitialAlignmentLimits() { + return (d, r, f) -> d == ForgeDirection.UP; + } + + /** + * Called every tick the Machine runs + */ + @Override + public boolean onRunningTick(ItemStack aStack) { + if (lEUt > 0) { + addEnergyOutput((lEUt * mEfficiency) / 10000); + return true; + } + return false; + } + + @Override + public boolean addEnergyOutput(long aEU) { + if (aEU <= 0) { + return true; + } + if (this.mAllDynamoHatches.size() > 0) { + return addEnergyOutputMultipleDynamos(aEU, true); + } + return false; + } + + @Override + public boolean addEnergyOutputMultipleDynamos(long aEU, boolean aAllowMixedVoltageDynamos) { + int injected = 0; + long aFirstVoltageFound = -1; + for (GT_MetaTileEntity_Hatch aDynamo : filterValidMTEs(mAllDynamoHatches)) { + long aVoltage = aDynamo.maxEUOutput(); + // Check against voltage to check when hatch mixing + if (aFirstVoltageFound == -1) { + aFirstVoltageFound = aVoltage; + } + } + + long leftToInject; + long aVoltage; + int aAmpsToInject; + int aRemainder; + int ampsOnCurrentHatch; + for (GT_MetaTileEntity_Hatch aDynamo : filterValidMTEs(mAllDynamoHatches)) { + leftToInject = aEU - injected; + aVoltage = aDynamo.maxEUOutput(); + aAmpsToInject = (int) (leftToInject / aVoltage); + aRemainder = (int) (leftToInject - (aAmpsToInject * aVoltage)); + ampsOnCurrentHatch = (int) Math.min(aDynamo.maxAmperesOut(), aAmpsToInject); + + // add full amps + aDynamo.getBaseMetaTileEntity() + .increaseStoredEnergyUnits(aVoltage * ampsOnCurrentHatch, false); + injected += aVoltage * ampsOnCurrentHatch; + + // add reminder + if (aRemainder > 0 && ampsOnCurrentHatch < aDynamo.maxAmperesOut()) { + aDynamo.getBaseMetaTileEntity() + .increaseStoredEnergyUnits(aRemainder, false); + injected += aRemainder; + } + } + return injected > 0; + } + + public int getSpeedMultiplier() { + return mFastMode ? 48 : 16; + } + + public int getMaintenanceThreshold() { + return mFastMode ? 12 : 1; + } + + public int getPollutionMultiplier() { + return mFastMode ? 3 : 1; + } + + public int getTurbineDamageMultiplier() { + return mFastMode ? 3 : 1; + } + + @Override + public boolean supportsBatchMode() { + return false; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java new file mode 100644 index 0000000000..67244cb399 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/storage/GregtechMetaTileEntity_PowerSubStationController.java @@ -0,0 +1,939 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.storage; + +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.onlyIf; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.withChannel; +import static gregtech.api.enums.GT_HatchElement.Dynamo; +import static gregtech.api.enums.GT_HatchElement.Energy; +import static gregtech.api.enums.GT_HatchElement.Maintenance; +import static gregtech.api.enums.Mods.TecTech; +import static gregtech.api.util.GT_StructureUtility.buildHatchAdder; +import static gregtech.api.util.GT_StructureUtility.ofHatchAdderOptional; +import static gregtech.api.util.GT_Utility.filterValidMTEs; +import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTDynamo; +import static gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase.GTPPHatchElement.TTEnergy; + +import javax.annotation.Nullable; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.world.World; +import net.minecraftforge.common.util.Constants.NBT; +import net.minecraftforge.common.util.ForgeDirection; + +import org.jetbrains.annotations.NotNull; + +import com.gtnewhorizon.structurelib.StructureLibAPI; +import com.gtnewhorizon.structurelib.alignment.constructable.ChannelDataAccessor; +import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; +import com.gtnewhorizon.structurelib.structure.AutoPlaceEnvironment; +import com.gtnewhorizon.structurelib.structure.IStructureDefinition; +import com.gtnewhorizon.structurelib.structure.IStructureElement; +import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment; +import com.gtnewhorizon.structurelib.structure.StructureDefinition; +import com.gtnewhorizon.structurelib.structure.StructureUtility; +import com.gtnewhorizons.modularui.api.NumberFormatMUI; +import com.gtnewhorizons.modularui.api.drawable.Text; +import com.gtnewhorizons.modularui.api.forge.PlayerMainInvWrapper; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; +import com.gtnewhorizons.modularui.common.widget.ProgressBar; +import com.gtnewhorizons.modularui.common.widget.SlotGroup; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; + +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.TAE; +import gregtech.api.enums.Textures; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.metatileentity.IMetaTileEntity; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Dynamo; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Energy; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Maintenance; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.recipe.check.CheckRecipeResult; +import gregtech.api.recipe.check.SimpleCheckRecipeResult; +import gregtech.api.util.GT_Multiblock_Tooltip_Builder; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.MovingAverageLong; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.math.MathUtils; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.preloader.asm.AsmConfig; +import gtPlusPlus.xmod.gregtech.api.gui.GTPP_UITextures; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMeta_MultiBlockBase; + +public class GregtechMetaTileEntity_PowerSubStationController extends + GregtechMeta_MultiBlockBase<GregtechMetaTileEntity_PowerSubStationController> implements ISurvivalConstructable { + + private static enum TopState { + MayBeTop, + Top, + NotTop + } + + protected long mAverageEuUsage = 0; + protected final MovingAverageLong mAverageEuAdded = new MovingAverageLong(20); + protected final MovingAverageLong mAverageEuConsumed = new MovingAverageLong(20); + protected long mTotalEnergyAdded = 0; + protected long mTotalEnergyConsumed = 0; + protected long mTotalEnergyLost = 0; + protected boolean mIsOutputtingPower = false; + protected long mBatteryCapacity = 0; + + private final int ENERGY_TAX = 5; + + private int mCasing; + private int[] cellCount = new int[6]; + private TopState topState = TopState.MayBeTop; + private static IStructureDefinition<GregtechMetaTileEntity_PowerSubStationController> STRUCTURE_DEFINITION = null; + + public GregtechMetaTileEntity_PowerSubStationController(final int aID, final String aName, + final String aNameRegional) { + super(aID, aName, aNameRegional); + } + + public GregtechMetaTileEntity_PowerSubStationController(final String aName) { + super(aName); + } + + @Override + public String getMachineType() { + return "Energy Buffer"; + } + + @Override + protected GT_Multiblock_Tooltip_Builder createTooltip() { + GT_Multiblock_Tooltip_Builder tt = new GT_Multiblock_Tooltip_Builder(); + tt.addMachineType(getMachineType()) + .addInfo("Consumes " + this.ENERGY_TAX + "% of the average voltage of all energy type hatches") + .addInfo("Does not require maintenance") + .addInfo( + "Can be built with variable height between " + (CELL_HEIGHT_MIN + 2) + "-" + (CELL_HEIGHT_MAX + 2) + "") + .addInfo("Hatches can be placed nearly anywhere") + .addInfo("HV Energy/Dynamo Hatches are the lowest tier you can use") + .addInfo("Supports voltages >= UHV using MAX tier components.") + .addSeparator() + .addController("Bottom Center") + .addCasingInfoMin("Sub-Station External Casings", 10, false) + .addDynamoHatch("Any Casing", 1) + .addEnergyHatch("Any Casing", 1) + .addSubChannelUsage("capacitor", "Vanadium Capacitor Cell Tier") + .addSubChannelUsage("height", "Height of structure") + .toolTipFinisher(CORE.GT_Tooltip_Builder.get()); + return tt; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + if (side == facing) { + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(24)), + new GT_RenderedTexture( + aActive ? Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER_ACTIVE + : Textures.BlockIcons.OVERLAY_FRONT_DISASSEMBLER) }; + } + if (side == this.getBaseMetaTileEntity() + .getBackFacing()) { + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(24)), + mIsOutputtingPower ? Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[(int) this.getOutputTier()] + : Textures.BlockIcons.OVERLAYS_ENERGY_IN_MULTI[(int) this.getInputTier()] }; + } + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(TAE.GTPP_INDEX(23)) }; + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + // if (mBatteryCapacity <= 0) return false; + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + + private void checkMachineProblem(String msg, int xOff, int yOff, int zOff) { + final IGregTechTileEntity te = this.getBaseMetaTileEntity(); + final Block tBlock = te.getBlockOffset(xOff, yOff, zOff); + final byte tMeta = te.getMetaIDOffset(xOff, yOff, zOff); + String name = tBlock.getLocalizedName(); + String problem = msg + ": (" + xOff + ", " + yOff + ", " + zOff + ") " + name + ":" + tMeta; + checkMachineProblem(problem); + } + + private void checkMachineProblem(String msg) { + if (!AsmConfig.disableAllLogging) { + Logger.INFO("Power Sub-Station problem: " + msg); + } + } + + public static int getCellTier(Block aBlock, int aMeta) { + if (aBlock == ModBlocks.blockCasings2Misc && aMeta == 7) { + return 4; + } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 4) { + return 5; + } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 5) { + return 6; + } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 6) { + return 7; + } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 7) { + return 8; + } else if (aBlock == ModBlocks.blockCasings3Misc && aMeta == 8) { + return 9; + } else { + return -1; + } + } + + public static int getMetaFromTier(int tier) { + if (tier == 4) return 7; + if (tier >= 5 && tier <= 9) return tier - 1; + return 0; + } + + public static Block getBlockFromTier(int tier) { + return switch (tier) { + case 4 -> ModBlocks.blockCasings2Misc; + case 5, 6, 7, 8, 9 -> ModBlocks.blockCasings3Misc; + default -> null; + }; + } + + public static int getMaxHatchTier(int aCellTier) { + switch (aCellTier) { + case 9 -> { + return GT_Values.VOLTAGE_NAMES[9].equals("Ultimate High Voltage") ? 15 : 9; + } + default -> { + if (aCellTier < 4) { + return 0; + } else { + return aCellTier; + } + } + } + } + + public static final int CELL_HEIGHT_MAX = 16; + public static final int CELL_HEIGHT_MIN = 2; + + @Override + public IStructureDefinition<GregtechMetaTileEntity_PowerSubStationController> getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_PowerSubStationController>builder() + .addShape( + mName + "bottom", + transpose(new String[][] { { "BB~BB", "BBBBB", "BBBBB", "BBBBB", "BBBBB" } })) + .addShape( + mName + "layer", + transpose(new String[][] { { "CCCCC", "CIIIC", "CIIIC", "CIIIC", "CCCCC" } })) + .addShape(mName + "mid", transpose(new String[][] { { "CCCCC", "CHHHC", "CHHHC", "CHHHC", "CCCCC" } })) + .addShape(mName + "top", transpose(new String[][] { { "TTTTT", "TTTTT", "TTTTT", "TTTTT", "TTTTT" } })) + .addElement( + 'C', + buildHatchAdder(GregtechMetaTileEntity_PowerSubStationController.class) + .atLeast(Energy.or(TTEnergy), Dynamo.or(TTDynamo), Maintenance) + .disallowOnly(ForgeDirection.UP, ForgeDirection.DOWN) + .casingIndex(TAE.GTPP_INDEX(24)) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 8)))) + .addElement( + 'B', + buildHatchAdder(GregtechMetaTileEntity_PowerSubStationController.class) + .atLeast(Energy.or(TTEnergy), Dynamo.or(TTDynamo), Maintenance) + .disallowOnly(ForgeDirection.UP) + .casingIndex(TAE.GTPP_INDEX(24)) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 8)))) + .addElement( + 'T', + buildHatchAdder(GregtechMetaTileEntity_PowerSubStationController.class) + .atLeast(Energy.or(TTEnergy), Dynamo.or(TTDynamo), Maintenance) + .disallowOnly(ForgeDirection.DOWN) + .casingIndex(TAE.GTPP_INDEX(24)) + .dot(1) + .buildAndChain(onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings2Misc, 8)))) + .addElement( + 'I', + withChannel( + "cell", + ofChain( + onlyIf( + x -> x.topState != TopState.NotTop, + onElementPass( + x -> x.topState = TopState.Top, + ofHatchAdderOptional( + GregtechMetaTileEntity_PowerSubStationController::addPowerSubStationList, + TAE.GTPP_INDEX(24), + 1, + ModBlocks.blockCasings2Misc, + 8))), + onlyIf( + x -> x.topState != TopState.Top, + onElementPass( + x -> x.topState = TopState.NotTop, + ofChain( + onElementPass(x -> ++x.cellCount[0], ofCell(4)), + onElementPass(x -> ++x.cellCount[1], ofCell(5)), + onElementPass(x -> ++x.cellCount[2], ofCell(6)), + onElementPass(x -> ++x.cellCount[3], ofCell(7)), + onElementPass(x -> ++x.cellCount[4], ofCell(8)), + onElementPass(x -> ++x.cellCount[5], ofCell(9)))))))) + .addElement('H', ofCell(4)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + public static <T> IStructureElement<T> ofCell(int aIndex) { + return new IStructureElement<T>() { + + @Override + public boolean check(T t, World world, int x, int y, int z) { + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + int tier = getCellTier(block, meta); + return aIndex == tier; + } + + public int getIndex(int size) { + if (size > 6) size = 6; + return size + 3; + } + + @Override + public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) { + StructureLibAPI.hintParticle( + world, + x, + y, + z, + getBlockFromTier(getIndex(trigger.stackSize)), + getMetaFromTier(getIndex(trigger.stackSize))); + return true; + } + + @Override + public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) { + return world.setBlock( + x, + y, + z, + getBlockFromTier(getIndex(trigger.stackSize)), + getMetaFromTier(getIndex(trigger.stackSize)), + 3); + } + + @Nullable + @Override + public BlocksToPlace getBlocksToPlace(T t, World world, int x, int y, int z, ItemStack trigger, + AutoPlaceEnvironment env) { + return BlocksToPlace.create(getBlockFromTier(trigger.stackSize), getMetaFromTier(trigger.stackSize)); + } + + @Override + public PlaceResult survivalPlaceBlock(T t, World world, int x, int y, int z, ItemStack trigger, + AutoPlaceEnvironment env) { + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + int tier = getCellTier(block, meta); + if (tier >= 0) return PlaceResult.SKIP; + return StructureUtility.survivalPlaceBlock( + getBlockFromTier(getIndex(trigger.stackSize)), + getMetaFromTier(getIndex(trigger.stackSize)), + world, + x, + y, + z, + env.getSource(), + env.getActor(), + env.getChatter()); + } + }; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + int layer = Math.min(stackSize.stackSize + 3, 18); + log("Layer: " + layer); + log("Building 0"); + buildPiece(mName + "bottom", stackSize, hintsOnly, 2, 0, 0); + log("Built 0"); + for (int i = 1; i < layer - 1; i++) { + log("Building " + i); + buildPiece(mName + "mid", stackSize, hintsOnly, 2, i, 0); + log("Built " + i); + } + log("Building " + (layer - 1)); + buildPiece(mName + "top", stackSize, hintsOnly, 2, layer - 1, 0); + log("Built " + (layer - 1)); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + if (mMachine) return -1; + int layer = Math.min(ChannelDataAccessor.getChannelData(stackSize, "height") + 3, 18); + int built; + built = survivialBuildPiece(mName + "bottom", stackSize, 2, 0, 0, elementBudget, env, false, true); + if (built >= 0) return built; + for (int i = 1; i < layer - 1; i++) { + built = survivialBuildPiece(mName + "mid", stackSize, 2, i, 0, elementBudget, env, false, true); + if (built >= 0) return built; + } + return survivialBuildPiece(mName + "top", stackSize, 2, layer - 1, 0, elementBudget, env, false, true); + } + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + mCasing = 0; + mEnergyHatches.clear(); + mDynamoHatches.clear(); + mTecTechEnergyHatches.clear(); + mTecTechDynamoHatches.clear(); + mAllEnergyHatches.clear(); + mAllDynamoHatches.clear(); + for (int i = 0; i < 6; i++) { + cellCount[i] = 0; + } + log("Checking 0"); + if (!checkPiece(mName + "bottom", 2, 0, 0)) { + log("Failed on Layer 0"); + return false; + } + log("Pass 0"); + int layer = 1; + topState = TopState.MayBeTop; + while (true) { + if (!checkPiece(mName + "layer", 2, layer, 0)) return false; + layer++; + if (topState == TopState.Top) break; // top found, break out + topState = TopState.MayBeTop; + if (layer > 18) return false; // too many layers + } + int level = 0; + for (int i = 0; i < 6; i++) { + if (cellCount[i] != 0) { + if (level == 0) { + level = i + 4; + } else { + return false; + } + } + } + int tier = getMaxHatchTier(level); + long volSum = 0; + for (GT_MetaTileEntity_Hatch hatch : mAllDynamoHatches) { + if (hatch.mTier > tier || hatch.mTier < 3) { + return false; + } + volSum += (8L << (hatch.mTier * 2)); + } + for (GT_MetaTileEntity_Hatch hatch : mAllEnergyHatches) { + if (hatch.mTier > tier || hatch.mTier < 3) { + return false; + } + volSum += (8L << (hatch.mTier * 2)); + } + mBatteryCapacity = getCapacityFromCellTier(level) * cellCount[level - 4]; + if (mAllEnergyHatches.size() + mAllDynamoHatches.size() > 0) { + mAverageEuUsage = volSum / (mAllEnergyHatches.size() + mAllDynamoHatches.size()); + } else mAverageEuUsage = 0; + fixAllMaintenanceIssue(); + return true; + } + + public final boolean addPowerSubStationList(IGregTechTileEntity aTileEntity, int aBaseCasingIndex) { + if (aTileEntity == null) { + return false; + } else { + IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity(); + if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Energy) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Dynamo) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (aMetaTileEntity instanceof GT_MetaTileEntity_Hatch_Maintenance) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (TecTech.isModLoaded()) { + if (isThisHatchMultiDynamo(aMetaTileEntity)) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } else if (isThisHatchMultiEnergy(aMetaTileEntity)) { + return addToMachineList(aTileEntity, aBaseCasingIndex); + } + } + } + return false; + } + + // Define storage capacity of smallest cell tier (EV) and compute higher tiers from it + private static final long CELL_TIER_EV_CAPACITY = 100 * 1000 * 1000; + private static final long CELL_TIER_MULTIPLIER = 4; // each tier's capacity is this many times the previous tier + + public static long getCapacityFromCellTier(int aOverallCellTier) { + // Use integer math instead of `Math.pow` to avoid range/precision errors + if (aOverallCellTier < 4) return 0; + aOverallCellTier -= 4; + long capacity = CELL_TIER_EV_CAPACITY; + while (aOverallCellTier > 0) { + capacity *= CELL_TIER_MULTIPLIER; + aOverallCellTier--; + } + return capacity; + } + + @Override + public int getMaxEfficiency(final ItemStack aStack) { + return 10000; + } + + @Override + public boolean explodesOnComponentBreak(final ItemStack aStack) { + return false; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaTileEntity_PowerSubStationController(this.mName); + } + + // mTotalEnergyAdded + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setLong("mAverageEuUsage", this.mAverageEuUsage); + this.mAverageEuAdded.write(aNBT, "mAverageEuAdded"); + this.mAverageEuConsumed.write(aNBT, "mAverageEuConsumed"); + + // Usage Stats + aNBT.setLong("mTotalEnergyAdded", this.mTotalEnergyAdded); + aNBT.setLong("mTotalEnergyLost", this.mTotalEnergyLost); + aNBT.setLong("mTotalEnergyConsumed", this.mTotalEnergyConsumed); + aNBT.setLong("mTotalRunTime", this.mTotalRunTime); + aNBT.setBoolean("mIsOutputtingPower", this.mIsOutputtingPower); + aNBT.setLong("mBatteryCapacity", this.mBatteryCapacity); + super.saveNBTData(aNBT); + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + + // Best not to get a long if the Tag Map is holding an int + if (aNBT.hasKey("mAverageEuUsage")) { + this.mAverageEuUsage = aNBT.getLong("mAverageEuUsage"); + } + switch (aNBT.func_150299_b("mAverageEuAdded")) { + case NBT.TAG_BYTE_ARRAY -> this.mAverageEuAdded.read(aNBT, "mAverageEuAdded"); + case NBT.TAG_LONG -> this.mAverageEuAdded.set(aNBT.getLong("mAverageEuAdded")); + } + switch (aNBT.func_150299_b("mAverageEuConsumed")) { + case NBT.TAG_BYTE_ARRAY -> this.mAverageEuConsumed.read(aNBT, "mAverageEuConsumed"); + case NBT.TAG_LONG -> this.mAverageEuConsumed.set(aNBT.getLong("mAverageEuConsumed")); + } + + // Usage Stats + this.mTotalEnergyAdded = aNBT.getLong("mTotalEnergyAdded"); + this.mTotalEnergyLost = aNBT.getLong("mTotalEnergyLost"); + this.mTotalEnergyConsumed = aNBT.getLong("mTotalEnergyConsumed"); + this.mTotalRunTime = aNBT.getLong("mTotalRunTime"); + + this.mIsOutputtingPower = aNBT.getBoolean("mIsOutputtingPower"); + + this.mBatteryCapacity = aNBT.getLong("mBatteryCapacity"); + + super.loadNBTData(aNBT); + } + + @Override + public @NotNull CheckRecipeResult checkProcessing() { + this.mProgresstime = 0; + this.mMaxProgresstime = 200; + this.lEUt = 0; + this.mEfficiencyIncrease = 10000; + this.fixAllMaintenanceIssue(); + return SimpleCheckRecipeResult.ofSuccess("managing_power"); + } + + @Override + public int getMaxParallelRecipes() { + return 1; + } + + private long drawEnergyFromHatch(MetaTileEntity aHatch) { + long stored = aHatch.getEUVar(); + long voltage = aHatch.maxEUInput() * aHatch.maxAmperesIn(); + + if (voltage > stored || (voltage + this.getEUVar() > this.mBatteryCapacity)) { + return 0; + } + + if (this.getBaseMetaTileEntity() + .increaseStoredEnergyUnits(voltage, false)) { + aHatch.setEUVar((stored - voltage)); + this.mTotalEnergyAdded += voltage; + return voltage; + } + return 0; + } + + private long addEnergyToHatch(MetaTileEntity aHatch) { + long voltage = aHatch.maxEUOutput() * aHatch.maxAmperesOut(); + + if (aHatch.getEUVar() > aHatch.maxEUStore() - voltage) { + return 0; + } + + if (this.getBaseMetaTileEntity() + .decreaseStoredEnergyUnits(voltage, false)) { + aHatch.getBaseMetaTileEntity() + .increaseStoredEnergyUnits(voltage, false); + this.mTotalEnergyConsumed += voltage; + return voltage; + } + return 0; + } + + private long computeEnergyTax() { + float mTax = mAverageEuUsage * (ENERGY_TAX / 100f); + + // Increase tax up to 2x if machine is not fully repaired (does not actually work at the moment, mEfficiency is + // always 0) + // mTax = mTax * (1f + (10000f - mEfficiency) / 10000f); + + return MathUtils.roundToClosestLong(mTax); + } + + @Override + public void onPreTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + this.fixAllMaintenanceIssue(); + } + + @Override + public boolean onRunningTick(ItemStack aStack) { + // First, decay overcharge (1% of stored energy plus 1000 EU per tick) + if (this.getEUVar() > this.mBatteryCapacity) { + long energy = (long) (this.getEUVar() * 0.990f) - 1000; + this.setEUVar(energy); + } + + // Pay Tax + long mDecrease = computeEnergyTax(); + this.mTotalEnergyLost += Math.min(mDecrease, this.getEUVar()); + this.setEUVar(Math.max(0, this.getEUVar() - mDecrease)); + + long aInputAverage = 0; + long aOutputAverage = 0; + // Input Power + for (GT_MetaTileEntity_Hatch THatch : filterValidMTEs(this.mDischargeHatches)) { + aInputAverage += drawEnergyFromHatch(THatch); + } + for (GT_MetaTileEntity_Hatch tHatch : filterValidMTEs(this.mAllEnergyHatches)) { + aInputAverage += drawEnergyFromHatch(tHatch); + } + + // Output Power + for (GT_MetaTileEntity_Hatch THatch : filterValidMTEs(this.mChargeHatches)) { + aOutputAverage += addEnergyToHatch(THatch); + } + for (GT_MetaTileEntity_Hatch tHatch : filterValidMTEs(this.mAllDynamoHatches)) { + aOutputAverage += addEnergyToHatch(tHatch); + } + // reset progress time + mProgresstime = 0; + + this.mAverageEuAdded.sample(aInputAverage); + this.mAverageEuConsumed.sample(aOutputAverage); + + return true; + } + + @Override + public boolean drainEnergyInput(long aEU) { + // Not applicable to this machine + return true; + } + + @Override + public boolean addEnergyOutput(long aEU) { + // Not applicable to this machine + return true; + } + + @Override + public long maxEUStore() { + return mBatteryCapacity; + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public String[] getExtraInfoData() { + String mode; + if (mIsOutputtingPower) { + mode = EnumChatFormatting.GOLD + "Output" + EnumChatFormatting.RESET; + } else { + mode = EnumChatFormatting.BLUE + "Input" + EnumChatFormatting.RESET; + } + + String storedEnergyText; + if (this.getEUVar() > this.mBatteryCapacity) { + storedEnergyText = EnumChatFormatting.RED + GT_Utility.formatNumbers(this.getEUVar()) + + EnumChatFormatting.RESET; + } else { + storedEnergyText = EnumChatFormatting.GREEN + GT_Utility.formatNumbers(this.getEUVar()) + + EnumChatFormatting.RESET; + } + + int errorCode = this.getBaseMetaTileEntity() + .getErrorDisplayID(); + boolean mMaint = (errorCode != 0); + + return new String[] { "Ergon Energy - District Sub-Station", "Stored EU: " + storedEnergyText, + "Capacity: " + EnumChatFormatting.YELLOW + + GT_Utility.formatNumbers(this.maxEUStore()) + + EnumChatFormatting.RESET, + "Running Costs: " + EnumChatFormatting.RED + + GT_Utility.formatNumbers(this.computeEnergyTax()) + + EnumChatFormatting.RESET + + " EU/t", + "Controller Mode: " + mode, + "Requires Maintenance: " + (!mMaint ? EnumChatFormatting.GREEN : EnumChatFormatting.RED) + + mMaint + + EnumChatFormatting.RESET + + " | Code: [" + + (!mMaint ? EnumChatFormatting.GREEN : EnumChatFormatting.RED) + + errorCode + + EnumChatFormatting.RESET + + "]", + "----------------------", "Stats for Nerds", + "Average Input: " + EnumChatFormatting.BLUE + + GT_Utility.formatNumbers(this.getAverageEuAdded()) + + EnumChatFormatting.RESET + + " EU", + "Average Output: " + EnumChatFormatting.GOLD + + GT_Utility.formatNumbers(this.getAverageEuConsumed()) + + EnumChatFormatting.RESET + + " EU", + "Total Input: " + EnumChatFormatting.BLUE + + GT_Utility.formatNumbers(this.mTotalEnergyAdded) + + EnumChatFormatting.RESET + + " EU", + "Total Output: " + EnumChatFormatting.GOLD + + GT_Utility.formatNumbers(this.mTotalEnergyConsumed) + + EnumChatFormatting.RESET + + " EU", + "Total Costs: " + EnumChatFormatting.RED + + GT_Utility.formatNumbers(this.mTotalEnergyLost) + + EnumChatFormatting.RESET + + " EU", }; + } + + @Override + public void explodeMultiblock() { + // TODO Auto-generated method stub + super.explodeMultiblock(); + } + + @Override + public void doExplosion(long aExplosionPower) { + // TODO Auto-generated method stub + super.doExplosion(aExplosionPower); + } + + @Override + public long getMaxInputVoltage() { + return 32768; + } + + @Override + public boolean isElectric() { + return true; + } + + @Override + public boolean isEnetInput() { + return !mIsOutputtingPower; + } + + @Override + public boolean isEnetOutput() { + return mIsOutputtingPower; + } + + @Override + public boolean isInputFacing(ForgeDirection side) { + return (side == this.getBaseMetaTileEntity() + .getBackFacing() && !mIsOutputtingPower); + } + + @Override + public boolean isOutputFacing(ForgeDirection side) { + return (side == this.getBaseMetaTileEntity() + .getBackFacing() && mIsOutputtingPower); + } + + @Override + public long maxAmperesIn() { + return 32; + } + + @Override + public long maxAmperesOut() { + return 32; + } + + @Override + public long maxEUInput() { + return 32768; + } + + @Override + public long maxEUOutput() { + return 32768; + } + + public final long getAverageEuAdded() { + return this.mAverageEuAdded.get(); + } + + public final long getAverageEuConsumed() { + return this.mAverageEuConsumed.get(); + } + + @Override + public void onModeChangeByScrewdriver(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + mIsOutputtingPower = !mIsOutputtingPower; + if (mIsOutputtingPower) { + PlayerUtils.messagePlayer(aPlayer, "Sub-Station is now outputting power from the controller."); + } else { + PlayerUtils.messagePlayer(aPlayer, "Sub-Station is now inputting power into the controller."); + } + } + + @Override + public boolean doesBindPlayerInventory() { + return false; + } + + @Override + public int getGUIWidth() { + return 196; + } + + @Override + public int getGUIHeight() { + return 191; + } + + @Override + public void addGregTechLogo(ModularWindow.Builder builder) { + builder.widget( + new DrawableWidget().setDrawable(getGUITextureSet().getGregTechLogo()) + .setSize(17, 17) + .setPos(175, 166)); + } + + private long clientEUIn, clientEUOut, clientEULoss, clientEUStored; + private float clientProgress; + + protected static final NumberFormatMUI numberFormat = new NumberFormatMUI(); + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget( + new DrawableWidget().setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK) + .setPos(4, 4) + .setSize(149, 149)) + .widget(new SlotWidget(inventoryHandler, 0).setPos(154, 4)) + .widget( + new SlotWidget(inventoryHandler, 1).setAccess(true, false) + .setPos(154, 22)) + .widget( + SlotGroup.ofItemHandler(new PlayerMainInvWrapper(buildContext.getPlayer().inventory), 9) + .endAtSlot(8) + .build() + .setPos(7, 166)) + .widget( + TextWidget + .dynamicString( + () -> getBaseMetaTileEntity().getErrorDisplayID() == 0 + ? getBaseMetaTileEntity().isActive() ? "Running perfectly" : "Turn on with Mallet" + : "") + .setSynced(false) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(10, 8)) + .widget( + new FakeSyncWidget.BooleanSyncer( + () -> getBaseMetaTileEntity().isActive(), + val -> getBaseMetaTileEntity().setActive(val))) + .widget( + new FakeSyncWidget.IntegerSyncer( + () -> getBaseMetaTileEntity().getErrorDisplayID(), + val -> getBaseMetaTileEntity().setErrorDisplayID(val))) + .widget( + new TextWidget("In").setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(178, 10)) + .widget( + new TextWidget("Out").setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(176, 28)) + .widget(new FakeSyncWidget.LongSyncer(this::getAverageEuAdded, val -> clientEUIn = val)) + .widget( + new TextWidget().setStringSupplier(() -> "Avg In: " + numberFormat.format(clientEUIn) + " EU") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(10, 20)) + .widget(new FakeSyncWidget.LongSyncer(this::getAverageEuConsumed, val -> clientEUOut = val)) + .widget( + new TextWidget().setStringSupplier(() -> "Avg Out: " + numberFormat.format(clientEUOut) + " EU") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(10, 30)) + .widget(new FakeSyncWidget.LongSyncer(this::computeEnergyTax, val -> clientEULoss = val)) + .widget( + new TextWidget() + .setStringSupplier(() -> "Powerloss: " + numberFormat.format(clientEULoss) + " EU per tick") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(10, 40)) + .widget( + new DrawableWidget().setDrawable(GTPP_UITextures.PICTURE_ENERGY_FRAME) + .setPos(4, 155) + .setSize(149, 7)) + .widget(new FakeSyncWidget.FloatSyncer(this::getProgress, val -> clientProgress = val)) + .widget( + new ProgressBar().setProgress(this::getProgress) + .setTexture(GTPP_UITextures.PROGRESSBAR_PSS_ENERGY, 147) + .setDirection(ProgressBar.Direction.RIGHT) + .setPos(5, 156) + .setSize(147, 5)) + .widget( + new TextWidget("Stored:").setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(10, 132)) + .widget( + new FakeSyncWidget.LongSyncer(() -> getBaseMetaTileEntity().getStoredEU(), val -> clientEUStored = val)) + .widget(new TextWidget().setTextSupplier(() -> { + int colorScale = (int) (clientProgress * 100 * 2.55); + return new Text(numberFormat.format(clientEUStored) + " EU") + .color(Utils.rgbtoHexValue((255 - colorScale), colorScale, 0)); + }) + .setPos(10, 142)) + .widget( + new TextWidget().setStringSupplier(() -> numberFormat.format(clientProgress * 100) + "%") + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(70, 155)); + } + + private float getProgress() { + return (float) getBaseMetaTileEntity().getStoredEU() / getBaseMetaTileEntity().getEUCapacity(); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/misc/TileEntitySolarHeater.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/misc/TileEntitySolarHeater.java new file mode 100644 index 0000000000..141f4bbc43 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/misc/TileEntitySolarHeater.java @@ -0,0 +1,343 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.misc; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +import org.apache.commons.lang3.ArrayUtils; + +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.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; +import gregtech.api.objects.GT_ItemStack; +import gregtech.api.objects.GT_RenderedTexture; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; +import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.GregtechMetaTileEntity_SolarTower; + +public class TileEntitySolarHeater extends GT_MetaTileEntity_TieredMachineBlock { + + public boolean mHasTower = false; + private GregtechMetaTileEntity_SolarTower mTower = null; + + private int mTX, mTY, mTZ; + private Byte mRequiredFacing; + + public TileEntitySolarHeater(final int aID, final String aName, final String aNameRegional, final int aTier, + final String aDescription, final int aSlotCount) { + super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); + } + + public TileEntitySolarHeater(final String aName, final int aTier, final String[] aDescription, + final ITexture[][][] aTextures, final int aSlotCount) { + super(aName, aTier, aSlotCount, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return ArrayUtils.addAll(this.mDescriptionArray, "Point me at a Solar Tower", CORE.GT_Tooltip.get()); + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + return this.mTextures[(aActive ? 5 : 0) + (side == facing ? 0 + : side == facing.getOpposite() ? 1 + : side == ForgeDirection.DOWN ? 2 : side == ForgeDirection.UP ? 3 : 4)][aColorIndex + 1]; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_IV) }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top) }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_LuV) }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_IV) }; + } + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_IV) }; + } + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top) }; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Bottom) }; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_LuV) }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { new GT_RenderedTexture(TexturesGtBlock.Casing_Machine_Simple_Top), + new GT_RenderedTexture(Textures.BlockIcons.SOLARPANEL_IV) }; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new TileEntitySolarHeater(this.mName, this.mTier, this.mDescriptionArray, this.mTextures, 0); + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return false; + } + + @Override + public String[] getInfoData() { + return new String[] { this.getLocalName(), "Testificate" }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { + return false; + } + + public boolean allowCoverOnSide(final byte aSide, final int aCoverID) { + return false; + } + + @Override + public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { + return new int[] {}; + } + + @Override + public int getSizeInventory() { + return 0; + } + + @Override + public ItemStack getStackInSlot(final int p_70301_1_) { + return null; + } + + @Override + public long maxEUStore() { + return 0; + } + + @Override + public int getCapacity() { + return 0; + } + + @Override + public long maxEUInput() { + return 0; + } + + @Override + public long maxEUOutput() { + return 0; + } + + @Override + public long maxAmperesIn() { + return 0; + } + + @Override + public long maxAmperesOut() { + return 0; + } + + @Override + public boolean isElectric() { + return false; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return false; + } + + @Override + public boolean isFacingValid(final ForgeDirection facing) { + return facing.offsetY == 0; + } + + @Override + public boolean isEnetInput() { + return false; + } + + @Override + public boolean isEnetOutput() { + return false; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + /* + * aNBT.setBoolean("mHasTower", mHasTower); if (this.mHasTower) { aNBT.setInteger("mTX", mTX); + * aNBT.setInteger("mTY", mTY); aNBT.setInteger("mTZ", mTZ); } + */ + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + /* + * this.mHasTower = aNBT.getBoolean("mHasTower"); if (this.mHasTower) { if (aNBT.hasKey("mTX")) this.mTX = + * aNBT.getInteger("mTX"); if (aNBT.hasKey("mTY")) this.mTY = aNBT.getInteger("mTY"); if (aNBT.hasKey("mTZ")) + * this.mTZ = aNBT.getInteger("mTZ"); } + */ + } + + @Override + public long getInputTier() { + return 0; + } + + @Override + public long getOutputTier() { + return 0; + } + + @Override + public boolean allowCoverOnSide(ForgeDirection side, GT_ItemStack aStack) { + return false; + } + + @Override + public void onExplosion() {} + + public boolean hasSolarTower() { + return mHasTower; + } + + public GregtechMetaTileEntity_SolarTower getSolarTower() { + if (this.mHasTower) { + return mTower; + } + return null; + } + + public boolean canSeeSky() { + if (this.getBaseMetaTileEntity() + .getWorld() + .canBlockSeeTheSky( + this.getBaseMetaTileEntity() + .getXCoord(), + this.getBaseMetaTileEntity() + .getYCoord() + 1, + this.getBaseMetaTileEntity() + .getZCoord())) { + return true; + } + return false; + } + + public boolean setSolarTower(GregtechMetaTileEntity_SolarTower aTowerTile) { + if (!hasSolarTower()) { + this.mTX = aTowerTile.getBaseMetaTileEntity() + .getXCoord(); + this.mTY = (int) aTowerTile.getBaseMetaTileEntity() + .getYCoord(); + this.mTZ = aTowerTile.getBaseMetaTileEntity() + .getZCoord(); + this.mHasTower = true; + this.mTower = aTowerTile; + return true; + } + return false; + } + + public boolean clearSolarTower() { + if (mHasTower || mRequiredFacing != null || this.mTower != null) { + this.mTX = 0; + this.mTY = 0; + this.mTZ = 0; + this.mRequiredFacing = null; + this.mTower = null; + this.mHasTower = false; + return true; + } + return false; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + super.onPostTick(aBaseMetaTileEntity, aTick); + } + + @Override + public void onRemoval() { + super.onRemoval(); + } + + @Override + public boolean isOutputFacing(ForgeDirection side) { + return side.offsetY == 0; + } + + @Override + public boolean isInputFacing(ForgeDirection side) { + return false; + } + + @Override + public long getMinimumStoredEU() { + return 0; + } + + @Override + public void onFacingChange() { + super.onFacingChange(); + } + + @Override + public void doExplosion(long aExplosionPower) {} +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_TieredChest.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_TieredChest.java new file mode 100644 index 0000000000..07a63a6ba4 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_TieredChest.java @@ -0,0 +1,250 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.storage; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.ForgeDirection; + +import org.apache.commons.lang3.ArrayUtils; + +import com.gtnewhorizons.modularui.api.NumberFormatMUI; +import com.gtnewhorizons.modularui.api.screen.ModularWindow; +import com.gtnewhorizons.modularui.api.screen.UIBuildContext; +import com.gtnewhorizons.modularui.common.widget.DrawableWidget; +import com.gtnewhorizons.modularui.common.widget.SlotWidget; +import com.gtnewhorizons.modularui.common.widget.TextWidget; + +import gregtech.api.enums.Textures.BlockIcons; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.gui.modularui.GT_UITextures; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.modularui.IAddUIWidgets; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.core.lib.CORE; + +public class GT_MetaTileEntity_TieredChest extends GT_MetaTileEntity_TieredMachineBlock implements IAddUIWidgets { + + public int mItemCount = 0; + public ItemStack mItemStack = null; + private static final double mStorageFactor = (270000.0D / 16); + + public GT_MetaTileEntity_TieredChest(int aID, String aName, String aNameRegional, int aTier) { + super( + aID, + aName, + aNameRegional, + aTier, + 3, + "This Chest stores " + (int) (Math.pow(6.0D, (double) aTier) * mStorageFactor) + " Items", + new ITexture[0]); + } + + public GT_MetaTileEntity_TieredChest(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { + super(aName, aTier, 3, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return ArrayUtils.add(this.mDescriptionArray, CORE.GT_Tooltip.get()); + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + public boolean isFacingValid(ForgeDirection facing) { + return true; + } + + @Override + public boolean isAccessAllowed(EntityPlayer aPlayer) { + return true; + } + + @Override + public boolean isValidSlot(int aIndex) { + return true; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_TieredChest(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (this.getBaseMetaTileEntity() + .isServerSide() + && this.getBaseMetaTileEntity() + .isAllowedToWork()) { + if (this.getItemCount() <= 0) { + this.mItemStack = null; + this.mItemCount = 0; + } + + if (this.mItemStack == null && this.mInventory[0] != null) { + this.mItemStack = this.mInventory[0].copy(); + } + + if (this.mInventory[0] != null && this.mItemCount < this.getMaxItemCount() + && GT_Utility.areStacksEqual(this.mInventory[0], this.mItemStack)) { + this.mItemCount += this.mInventory[0].stackSize; + if (this.mItemCount > this.getMaxItemCount()) { + this.mInventory[0].stackSize = this.mItemCount - this.getMaxItemCount(); + this.mItemCount = this.getMaxItemCount(); + } else { + this.mInventory[0] = null; + } + } + + if (this.mInventory[1] == null && this.mItemStack != null) { + this.mInventory[1] = this.mItemStack.copy(); + this.mInventory[1].stackSize = Math.min(this.mItemStack.getMaxStackSize(), this.mItemCount); + this.mItemCount -= this.mInventory[1].stackSize; + } else if (this.mItemCount > 0 && GT_Utility.areStacksEqual(this.mInventory[1], this.mItemStack) + && this.mInventory[1].getMaxStackSize() > this.mInventory[1].stackSize) { + int tmp = Math + .min(this.mItemCount, this.mInventory[1].getMaxStackSize() - this.mInventory[1].stackSize); + this.mInventory[1].stackSize += tmp; + this.mItemCount -= tmp; + } + + if (this.mItemStack != null) { + this.mInventory[2] = this.mItemStack.copy(); + this.mInventory[2].stackSize = Math.min(this.mItemStack.getMaxStackSize(), this.mItemCount); + } else { + this.mInventory[2] = null; + } + } + } + + private int getItemCount() { + return this.mItemCount; + } + + @Override + public void setItemCount(int aCount) { + this.mItemCount = aCount; + } + + @Override + public int getProgresstime() { + return this.mItemCount + (this.mInventory[0] == null ? 0 : this.mInventory[0].stackSize) + + (this.mInventory[1] == null ? 0 : this.mInventory[1].stackSize); + } + + @Override + public int maxProgresstime() { + return this.getMaxItemCount(); + } + + @Override + public int getMaxItemCount() { + return (int) (Math.pow(6.0D, (double) this.mTier) * mStorageFactor - 128.0D); + } + + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return aIndex == 1; + } + + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return aIndex == 0 && (this.mInventory[0] == null || GT_Utility.areStacksEqual(this.mInventory[0], aStack)); + } + + @Override + public String[] getInfoData() { + return this.mItemStack == null + ? new String[] { "Super Storage Chest", "Stored Items:", "No Items", Integer.toString(0), + Integer.toString(this.getMaxItemCount()) } + : new String[] { "Super Storage Chest", "Stored Items:", this.mItemStack.getDisplayName(), + Integer.toString(this.mItemCount), Integer.toString(this.getMaxItemCount()) }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + aNBT.setInteger("mItemCount", this.mItemCount); + if (this.mItemStack != null) { + aNBT.setTag("mItemStack", this.mItemStack.writeToNBT(new NBTTagCompound())); + } + } + + @Override + public void loadNBTData(NBTTagCompound aNBT) { + if (aNBT.hasKey("mItemCount")) { + this.mItemCount = aNBT.getInteger("mItemCount"); + } + + if (aNBT.hasKey("mItemStack")) { + this.mItemStack = ItemStack.loadItemStackFromNBT((NBTTagCompound) aNBT.getTag("mItemStack")); + } + } + + public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, ForgeDirection side, ForgeDirection facing, + int aColorIndex, boolean aActive, boolean aRedstone) { + return aBaseMetaTileEntity.getFrontFacing() == ForgeDirection.DOWN && side == ForgeDirection.WEST + ? new ITexture[] { BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1], + new GT_RenderedTexture(BlockIcons.OVERLAY_QCHEST) } + : (side == aBaseMetaTileEntity.getFrontFacing() + ? new ITexture[] { BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1], + new GT_RenderedTexture(BlockIcons.OVERLAY_QCHEST) } + : new ITexture[] { BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1] }); + } + + @Override + public ITexture[][][] getTextureSet(ITexture[] aTextures) { + return new ITexture[0][0][0]; + } + + @Override + public boolean useModularUI() { + return true; + } + + protected static final NumberFormatMUI numberFormat = new NumberFormatMUI(); + + @Override + public void addUIWidgets(ModularWindow.Builder builder, UIBuildContext buildContext) { + builder.widget( + new DrawableWidget().setDrawable(GT_UITextures.PICTURE_SCREEN_BLACK) + .setPos(7, 16) + .setSize(71, 45)) + .widget( + new SlotWidget(inventoryHandler, 0) + .setBackground(getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_IN) + .setPos(79, 16)) + .widget( + new SlotWidget(inventoryHandler, 1).setAccess(true, false) + .setBackground(getGUITextureSet().getItemSlot(), GT_UITextures.OVERLAY_SLOT_OUT) + .setPos(79, 52)) + .widget( + SlotWidget.phantom(inventoryHandler, 2) + .disableInteraction() + .setBackground(GT_UITextures.TRANSPARENT) + .setPos(59, 42)) + .widget( + new TextWidget("Item Amount").setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(10, 20)) + .widget( + new TextWidget().setStringSupplier(() -> numberFormat.format(mItemCount)) + .setDefaultColor(COLOR_TEXT_WHITE.get()) + .setPos(10, 30)); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_TieredTank.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_TieredTank.java new file mode 100644 index 0000000000..a9fc7a3fd4 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GT_MetaTileEntity_TieredTank.java @@ -0,0 +1,194 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.storage; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.FluidStack; + +import gregtech.api.GregTech_API; +import gregtech.api.enums.GT_Values; +import gregtech.api.enums.Textures; +import gregtech.api.gui.modularui.GT_UIInfos; +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.lib.CORE; + +public class GT_MetaTileEntity_TieredTank extends GT_MetaTileEntity_BasicTank { + + public GT_MetaTileEntity_TieredTank(final int aID, final String aName, final String aNameRegional, + final int aTier) { + super( + aID, + aName, + aNameRegional, + aTier, + 3, + "Stores " + GT_Utility.formatNumbers(((int) (Math.pow(2, aTier) * 32000))) + "L of fluid"); + } + + public GT_MetaTileEntity_TieredTank(final String aName, final int aTier, final String[] aDescription, + final ITexture[][][] aTextures) { + super(aName, aTier, 3, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + List<String> description = new ArrayList<>(Arrays.asList(this.mDescriptionArray)); + description.add("A portable tank."); + if (this.mFluid != null) { + description.add("Fluid: " + mFluid.getLocalizedName() + " " + mFluid.amount + "L"); + } + description.add(CORE.GT_Tooltip.get()); + return description.toArray(new String[0]); + } + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + return new ITexture[0][0][0]; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + return side == ForgeDirection.UP + ? new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1], + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_POTIONBREWER_ACTIVE) } + : new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColorIndex + 1], + new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_POTIONBREWER) }; + } + + @Override + public void addAdditionalTooltipInformation(ItemStack stack, List<String> tooltip) { + if (stack.hasTagCompound() && stack.stackTagCompound.hasKey("mFluid")) { + final FluidStack tContents = FluidStack + .loadFluidStackFromNBT(stack.stackTagCompound.getCompoundTag("mFluid")); + if (tContents != null && tContents.amount > 0) { + tooltip.add( + GT_LanguageManager.addStringLocalization( + "TileEntity_TANK_INFO", + "Contains Fluid: ", + !GregTech_API.sPostloadFinished) + EnumChatFormatting.YELLOW + + tContents.getLocalizedName() + + EnumChatFormatting.GRAY); + tooltip.add( + GT_LanguageManager.addStringLocalization( + "TileEntity_TANK_AMOUNT", + "Fluid Amount: ", + !GregTech_API.sPostloadFinished) + EnumChatFormatting.GREEN + + GT_Utility.formatNumbers(tContents.amount) + + " L" + + EnumChatFormatting.GRAY); + } + } + } + + @Override + public boolean isSimpleMachine() { + return true; + } + + @Override + public boolean isFacingValid(final ForgeDirection facing) { + return true; + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public final byte getUpdateData() { + return 0x00; + } + + @Override + public boolean doesFillContainers() { + return true; + } + + @Override + public boolean doesEmptyContainers() { + return true; + } + + @Override + public boolean canTankBeFilled() { + return true; + } + + @Override + public boolean canTankBeEmptied() { + return true; + } + + @Override + public String[] getInfoData() { + + if (this.mFluid == null) { + return new String[] { GT_Values.VOLTAGE_NAMES[this.mTier] + " Fluid Tank", "Stored Fluid:", "No Fluid", + 0 + "L", this.getCapacity() + "L" }; + } + return new String[] { GT_Values.VOLTAGE_NAMES[this.mTier] + " Fluid Tank", "Stored Fluid:", + this.mFluid.getLocalizedName(), this.mFluid.amount + "L", this.getCapacity() + "L" }; + } + + @Override + public MetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_TieredTank(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); + } + + @Override + public int getCapacity() { + return (int) (Math.pow(2, this.mTier) * 32000); + } + + @Override + public int getTankPressure() { + return 100; + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer); + return true; + } + + @Override + public boolean displaysItemStack() { + return true; + } + + @Override + public boolean displaysStackSize() { + return false; + } + + @Override + public void setItemNBT(NBTTagCompound aNBT) { + if (mFluid != null) { + Logger.WARNING("Setting item fluid nbt"); + aNBT.setTag("mFluid", mFluid.writeToNBT(new NBTTagCompound())); + if (aNBT.hasKey("mFluid")) { + Logger.WARNING("Set mFluid to NBT."); + } + } + } + + @Override + public boolean useModularUI() { + return true; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GregtechMetaEnergyBuffer.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GregtechMetaEnergyBuffer.java new file mode 100644 index 0000000000..17b2d77756 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/GregtechMetaEnergyBuffer.java @@ -0,0 +1,439 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.storage; + +import static gregtech.api.enums.GT_Values.V; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +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.objects.GT_ItemStack; +import gregtech.api.objects.GT_RenderedTexture; +import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.GregtechMetaTileEntity; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; + +public class GregtechMetaEnergyBuffer extends GregtechMetaTileEntity { + + protected byte aCurrentOutputAmperage = 4; + + public GregtechMetaEnergyBuffer(final int aID, final String aName, final String aNameRegional, final int aTier, + final String aDescription, final int aSlotCount) { + super(aID, aName, aNameRegional, aTier, aSlotCount, aDescription); + } + + public GregtechMetaEnergyBuffer(final String aName, final int aTier, final String aDescription, + final ITexture[][][] aTextures, final int aSlotCount) { + super(aName, aTier, aSlotCount, aDescription, aTextures); + } + + @Override + public String[] getDescription() { + return new String[] { this.mDescription, "Defaults 4A In/Out", "Change output Amperage with a screwdriver", + "Now Portable!", CORE.GT_Tooltip.get() }; + } + + @Override + public boolean allowCoverOnSide(ForgeDirection side, GT_ItemStack aCover) { + if (side != this.getBaseMetaTileEntity() + .getFrontFacing()) { + return true; + } + return super.allowCoverOnSide(side, aCover); + } + + /* + * MACHINE_STEEL_SIDE + */ + + @Override + public ITexture[][][] getTextureSet(final ITexture[] aTextures) { + final ITexture[][][] rTextures = new ITexture[10][17][]; + for (byte i = -1; i < 16; i++) { + rTextures[0][i + 1] = this.getFront(i); + rTextures[1][i + 1] = this.getBack(i); + rTextures[2][i + 1] = this.getBottom(i); + rTextures[3][i + 1] = this.getTop(i); + rTextures[4][i + 1] = this.getSides(i); + rTextures[5][i + 1] = this.getFrontActive(i); + rTextures[6][i + 1] = this.getBackActive(i); + rTextures[7][i + 1] = this.getBottomActive(i); + rTextures[8][i + 1] = this.getTopActive(i); + rTextures[9][i + 1] = this.getSidesActive(i); + } + return rTextures; + } + + @Override + public ITexture[] getTexture(final IGregTechTileEntity aBaseMetaTileEntity, final ForgeDirection side, + final ForgeDirection facing, final int aColorIndex, final boolean aActive, final boolean aRedstone) { + return this.mTextures[(aActive ? 5 : 0) + (side == facing ? 0 + : side == facing.getOpposite() ? 1 + : side == ForgeDirection.DOWN ? 2 : side == ForgeDirection.UP ? 3 : 4)][aColorIndex + 1]; + } + + public ITexture[] getFront(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier] }; + } + + public ITexture[] getBack(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange) }; + } + + public ITexture[] getBottom(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange) }; + } + + public ITexture[] getTop(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Screen_Logo) }; + } + + public ITexture[] getSides(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange) }; + } + + public ITexture[] getFrontActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + Textures.BlockIcons.OVERLAYS_ENERGY_OUT_MULTI[this.mTier] }; + } + + public ITexture[] getBackActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange) }; + } + + public ITexture[] getBottomActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange) }; + } + + public ITexture[] getTopActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Screen_Logo) }; + } + + public ITexture[] getSidesActive(final byte aColor) { + return new ITexture[] { Textures.BlockIcons.MACHINE_CASINGS[this.mTier][aColor + 1], + new GT_RenderedTexture(TexturesGtBlock.Overlay_Machine_Dimensional_Orange) }; + } + + @Override + public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) { + return new GregtechMetaEnergyBuffer( + this.mName, + this.mTier, + this.mDescription, + this.mTextures, + this.mInventory.length); + } + + @Override + public boolean isSimpleMachine() { + return false; + } + + @Override + public boolean isElectric() { + return true; + } + + @Override + public boolean isValidSlot(final int aIndex) { + return true; + } + + @Override + public boolean isFacingValid(final ForgeDirection facing) { + return true; + } + + @Override + public boolean isEnetInput() { + return true; + } + + @Override + public boolean isEnetOutput() { + return true; + } + + @Override + public boolean isInputFacing(final ForgeDirection side) { + return side != this.getBaseMetaTileEntity() + .getFrontFacing(); + } + + @Override + public boolean isOutputFacing(final ForgeDirection side) { + return side == this.getBaseMetaTileEntity() + .getFrontFacing(); + } + + @Override + public boolean isTeleporterCompatible() { + return false; + } + + @Override + public long getMinimumStoredEU() { + return V[this.mTier] * 2; + } + + @Override + public long maxEUStore() { + return V[this.mTier] * 250000; + } + + @Override + public long maxEUInput() { + return V[this.mTier]; + } + + @Override + public long maxEUOutput() { + return V[this.mTier]; + } + + @Override + public long maxAmperesIn() { + return aCurrentOutputAmperage; + } + + @Override + public long maxAmperesOut() { + return aCurrentOutputAmperage; + } + + @Override + public int rechargerSlotStartIndex() { + return 0; + } + + @Override + public int dechargerSlotStartIndex() { + return 0; + } + + @Override + public int rechargerSlotCount() { + return 0; + } + + @Override + public int dechargerSlotCount() { + return 0; + } + + @Override + public int getProgresstime() { + return (int) this.getBaseMetaTileEntity() + .getUniversalEnergyStored(); + } + + @Override + public int maxProgresstime() { + return (int) this.getBaseMetaTileEntity() + .getUniversalEnergyCapacity(); + } + + @Override + public boolean isAccessAllowed(final EntityPlayer aPlayer) { + return true; + } + + @Override + public void saveNBTData(final NBTTagCompound aNBT) { + aNBT.setByte("aCurrentOutputAmperage", aCurrentOutputAmperage); + long aEU = this.getBaseMetaTileEntity() + .getStoredEU(); + if (aEU > 0) { + aNBT.setLong("aStoredEU", aEU); + if (aNBT.hasKey("aStoredEU")) { + Logger.WARNING("Set aStoredEU to NBT."); + } + } + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + aCurrentOutputAmperage = aNBT.getByte("aCurrentOutputAmperage"); + if (aNBT.hasKey("aStoredEU")) { + this.setEUVar(aNBT.getLong("aStoredEU")); + } + } + + @Override + public boolean onRightclick(final IGregTechTileEntity aBaseMetaTileEntity, final EntityPlayer aPlayer) { + Logger.WARNING("Right Click on MTE by Player"); + if (aBaseMetaTileEntity.isClientSide()) { + return true; + } + + Logger.WARNING("MTE is Client-side"); + this.showEnergy(aPlayer.getEntityWorld(), aPlayer); + return true; + } + + protected void showEnergy(final World worldIn, final EntityPlayer playerIn) { + final long tempStorage = this.getBaseMetaTileEntity() + .getStoredEU(); + final double c = ((double) tempStorage / this.maxEUStore()) * 100; + final double roundOff = Math.round(c * 100.00) / 100.00; + PlayerUtils.messagePlayer( + playerIn, + "Energy: " + GT_Utility.formatNumbers(tempStorage) + " EU at " + V[this.mTier] + "v (" + roundOff + "%)"); + PlayerUtils.messagePlayer(playerIn, "Amperage: " + GT_Utility.formatNumbers(maxAmperesOut()) + "A"); + } + // Utils.LOG_WARNING("Begin Show Energy"); + /* + * //Utils.LOG_INFO("getProgresstime: "+tempStorage+" maxProgresstime: "+maxEUStore()+" C: "+c); + * Utils.LOG_INFO("getProgressTime: "+getProgresstime()); Utils.LOG_INFO("maxProgressTime: "+maxProgresstime()); + * Utils.LOG_INFO("getMinimumStoredEU: "+getMinimumStoredEU()); Utils.LOG_INFO("maxEUStore: "+maxEUStore()); + */ + /* + * final long d = (tempStorage * 100L) / maxEUStore(); + * Utils.LOG_INFO("getProgresstime: "+tempStorage+" maxProgresstime: "+maxEUStore()+" D: "+d); final double + * roundOff2 = Math.round(d * 100.00) / 100.00; Utils.messagePlayer(playerIn, "Energy: " + tempStorage + + * " EU at "+V[mTier]+"v ("+roundOff2+"%)"); Utils.LOG_WARNING("Making new instance of Guihandler"); GuiHandler + * block = new GuiHandler(); Utils.LOG_WARNING("Guihandler.toString(): "+block.toString()); + * block.getClientGuiElement(1, playerIn, worldIn, (int) playerIn.posX, (int) playerIn.posY, (int) playerIn.posZ); + */ + + @Override + public boolean allowPullStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + return false; + } + + @Override + public boolean allowPutStack(final IGregTechTileEntity aBaseMetaTileEntity, final int aIndex, + final ForgeDirection side, final ItemStack aStack) { + return false; + } + + @Override + public String[] getInfoData() { + String cur = GT_Utility.formatNumbers( + this.getBaseMetaTileEntity() + .getStoredEU()); + String max = GT_Utility.formatNumbers( + this.getBaseMetaTileEntity() + .getEUCapacity()); + + // Right-align current storage with maximum storage + String fmt = String.format("%%%ds", max.length()); + cur = String.format(fmt, cur); + + return new String[] { cur + " EU stored", max + " EU capacity" }; + } + + @Override + public boolean isGivingInformation() { + return true; + } + + @Override + public int[] getAccessibleSlotsFromSide(final int p_94128_1_) { + return new int[] {}; + } + + @Override + public boolean canInsertItem(final int p_102007_1_, final ItemStack p_102007_2_, final int p_102007_3_) { + return false; + } + + @Override + public boolean canExtractItem(final int p_102008_1_, final ItemStack p_102008_2_, final int p_102008_3_) { + return false; + } + + @Override + public int getSizeInventory() { + return 0; + } + + @Override + public ItemStack getStackInSlot(final int p_70301_1_) { + return null; + } + + @Override + public ItemStack decrStackSize(final int p_70298_1_, final int p_70298_2_) { + return null; + } + + @Override + public ItemStack getStackInSlotOnClosing(final int p_70304_1_) { + return null; + } + + @Override + public void setInventorySlotContents(final int p_70299_1_, final ItemStack p_70299_2_) {} + + @Override + public String getInventoryName() { + return super.getInventoryName(); + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public int getInventoryStackLimit() { + return 0; + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer p_70300_1_) { + return false; + } + + @Override + public void openInventory() {} + + @Override + public void closeInventory() {} + + @Override + public boolean isItemValidForSlot(final int p_94041_1_, final ItemStack p_94041_2_) { + return false; + } + + @Override + public void setItemNBT(NBTTagCompound aNBT) { + aNBT.setByte("aCurrentOutputAmperage", aCurrentOutputAmperage); + long aEU = this.getBaseMetaTileEntity() + .getStoredEU(); + if (aEU > 0) { + aNBT.setLong("aStoredEU", aEU); + if (aNBT.hasKey("aStoredEU")) { + Logger.WARNING("Set aStoredEU to NBT."); + } + } + } + + @Override + public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) { + byte aTest = (byte) (aCurrentOutputAmperage + 1); + if (aTest > 16 || aTest <= 0) { + aTest = 1; + } + aCurrentOutputAmperage = aTest; + PlayerUtils.messagePlayer(aPlayer, "Now handling " + aCurrentOutputAmperage + " Amps."); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/creative/GT_MetaTileEntity_InfiniteItemHolder.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/creative/GT_MetaTileEntity_InfiniteItemHolder.java new file mode 100644 index 0000000000..2dca8d5c30 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/storage/creative/GT_MetaTileEntity_InfiniteItemHolder.java @@ -0,0 +1,92 @@ +package gtPlusPlus.xmod.gregtech.common.tileentities.storage.creative; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.util.ForgeDirection; + +import gregtech.api.interfaces.ITexture; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.metatileentity.MetaTileEntity; +import gtPlusPlus.core.util.minecraft.PlayerUtils; +import gtPlusPlus.core.util.sys.KeyboardUtils; +import gtPlusPlus.xmod.gregtech.common.tileentities.storage.GT_MetaTileEntity_TieredChest; + +public class GT_MetaTileEntity_InfiniteItemHolder extends GT_MetaTileEntity_TieredChest { + + public GT_MetaTileEntity_InfiniteItemHolder(int aID, String aName, String aNameRegional, int aTier) { + super(aID, aName, aNameRegional, aTier); + } + + public GT_MetaTileEntity_InfiniteItemHolder(String aName, int aTier, String[] aDescription, + ITexture[][][] aTextures) { + super(aName, aTier, aDescription, aTextures); + } + + @Override + public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) { + if (aBaseMetaTileEntity.getWorld().isRemote) { + return false; + } + + if (!KeyboardUtils.isShiftKeyDown()) { + if (this.mItemStack == null) { + if (aPlayer.getHeldItem() != null) { + this.mItemStack = aPlayer.getHeldItem() + .copy(); + this.mItemCount = Short.MAX_VALUE; + aPlayer.setCurrentItemOrArmor(0, null); + PlayerUtils.messagePlayer( + aPlayer, + "Now holding " + this.mItemStack.getDisplayName() + " x" + Short.MAX_VALUE + "."); + return true; + } + } else { + if (aPlayer.getHeldItem() == null) { + aPlayer.entityDropItem(mItemStack, 1); + this.mItemStack = null; + this.mItemCount = 0; + PlayerUtils.messagePlayer(aPlayer, "Emptying."); + return true; + } + } + } + + PlayerUtils.messagePlayer( + aPlayer, + "Currently holding: " + (this.mItemStack != null ? this.mItemStack.getDisplayName() : "Nothing") + + " x" + + this.mItemCount); + return true; + // return super.onRightclick(aBaseMetaTileEntity, aPlayer); + } + + @Override + public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) { + if (mItemStack != null) { + setItemCount(0); + } + super.onPostTick(aBaseMetaTileEntity, aTimer); + } + + @Override + public void setItemCount(int aCount) { + super.setItemCount(Short.MAX_VALUE); + } + + @Override + public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return true; + } + + @Override + public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, ForgeDirection side, + ItemStack aStack) { + return false; + } + + @Override + public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { + return new GT_MetaTileEntity_InfiniteItemHolder(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tools/TOOL_Gregtech_AngleGrinder.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tools/TOOL_Gregtech_AngleGrinder.java new file mode 100644 index 0000000000..6af3a61487 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tools/TOOL_Gregtech_AngleGrinder.java @@ -0,0 +1,175 @@ +package gtPlusPlus.xmod.gregtech.common.tools; + +import java.util.Arrays; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.monster.EntityIronGolem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.stats.AchievementList; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IChatComponent; +import net.minecraftforge.event.world.BlockEvent; + +import gregtech.GT_Mod; +import gregtech.api.enums.Materials; +import gregtech.api.enums.SoundResource; +import gregtech.api.enums.Textures.ItemIcons; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.items.GT_MetaGenerated_Tool; +import gregtech.common.items.behaviors.Behaviour_None; +import gregtech.common.tools.GT_Tool; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtTools; + +public class TOOL_Gregtech_AngleGrinder extends GT_Tool { + + public static final List<String> mEffectiveList = Arrays + .asList(new String[] { EntityIronGolem.class.getName(), "EntityTowerGuardian" }); + + @Override + public float getNormalDamageAgainstEntity(final float aOriginalDamage, final Entity aEntity, final ItemStack aStack, + final EntityPlayer aPlayer) { + String tName = aEntity.getClass() + .getName(); + tName = tName.substring(tName.lastIndexOf(".") + 1); + return (mEffectiveList.contains(tName)) || (tName.contains("Golem")) ? aOriginalDamage * 2.0F : aOriginalDamage; + } + + @Override + public int getToolDamagePerBlockBreak() { + return 50; + } + + @Override + public int getToolDamagePerDropConversion() { + return 100; + } + + @Override + public int getToolDamagePerContainerCraft() { + return 400; + } + + @Override + public int getToolDamagePerEntityAttack() { + return 100; + } + + @Override + public int getBaseQuality() { + return 0; + } + + @Override + public float getBaseDamage() { + return 8.0F; + } + + @Override + public float getSpeedMultiplier() { + return 2F; + } + + @Override + public float getMaxDurabilityMultiplier() { + return 1.8F; + } + + @Override + public String getCraftingSound() { + return SoundResource.RANDOM_ANVIL_USE.toString(); + } + + @Override + public String getEntityHitSound() { + return SoundResource.RANDOM_ANVIL_BREAK.toString(); + } + + @Override + public String getMiningSound() { + return null; + } + + @Override + public boolean canBlock() { + return false; + } + + @Override + public boolean isWrench() { + return false; + } + + @Override + public boolean isCrowbar() { + return false; + } + + @Override + public boolean isWeapon() { + return true; + } + + @Override + public boolean isMinableBlock(final Block aBlock, final byte aMetaData) { + final String tTool = aBlock.getHarvestTool(aMetaData); + return (tTool != null) && (tTool.equals("sword") || tTool.equals("file")); + } + + @Override + public int convertBlockDrops(final List<ItemStack> aDrops, final ItemStack aStack, final EntityPlayer aPlayer, + final Block aBlock, final int aX, final int aY, final int aZ, final byte aMetaData, final int aFortune, + final boolean aSilkTouch, final BlockEvent.HarvestDropsEvent aEvent) { + return 0; + } + + @Override + public ItemStack getBrokenItem(final ItemStack aStack) { + return null; + } + + @Override + public IIconContainer getIcon(boolean aIsToolHead, ItemStack aStack) { + return (IIconContainer) (aIsToolHead ? TexturesGtTools.ANGLE_GRINDER : ItemIcons.POWER_UNIT_HV); + } + + @Override + public short[] getRGBa(boolean aIsToolHead, ItemStack aStack) { + return aIsToolHead ? GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mRGBa : Materials.TungstenSteel.mRGBa; + } + + @Override + public void onToolCrafted(final ItemStack aStack, final EntityPlayer aPlayer) { + super.onToolCrafted(aStack, aPlayer); + aPlayer.triggerAchievement(AchievementList.buildSword); + try { + GT_Mod.achievements.issueAchievement(aPlayer, "tools"); + GT_Mod.achievements.issueAchievement(aPlayer, "unitool"); + } catch (final Exception e) {} + } + + @Override + public IChatComponent getDeathMessage(final EntityLivingBase aPlayer, final EntityLivingBase aEntity) { + return new ChatComponentText( + EnumChatFormatting.RED + aEntity.getCommandSenderName() + + EnumChatFormatting.WHITE + + " has been Ground out of existence by " + + EnumChatFormatting.GREEN + + aPlayer.getCommandSenderName() + + EnumChatFormatting.WHITE); + } + + @Override + public void onStatsAddedToTool(final GT_MetaGenerated_Tool aItem, final int aID) { + aItem.addItemBehavior(aID, new Behaviour_None()); + } + + @Override + public boolean isGrafter() { + return false; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tools/TOOL_Gregtech_ElectricSnips.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tools/TOOL_Gregtech_ElectricSnips.java new file mode 100644 index 0000000000..25ad03548a --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tools/TOOL_Gregtech_ElectricSnips.java @@ -0,0 +1,96 @@ +package gtPlusPlus.xmod.gregtech.common.tools; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.stats.AchievementList; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IChatComponent; + +import gregtech.GT_Mod; +import gregtech.api.enums.Materials; +import gregtech.api.enums.Textures.ItemIcons; +import gregtech.api.interfaces.IIconContainer; +import gregtech.api.items.GT_MetaGenerated_Tool; +import gregtech.common.tools.GT_Tool_WireCutter; +import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtTools; + +public class TOOL_Gregtech_ElectricSnips extends GT_Tool_WireCutter { + + @Override + public int getToolDamagePerBlockBreak() { + return 50; + } + + @Override + public int getToolDamagePerDropConversion() { + return 100; + } + + @Override + public int getToolDamagePerContainerCraft() { + return 400; + } + + @Override + public int getToolDamagePerEntityAttack() { + return 100; + } + + @Override + public int getBaseQuality() { + return 0; + } + + @Override + public float getBaseDamage() { + return 4.0F; + } + + @Override + public float getSpeedMultiplier() { + return 1F; + } + + @Override + public float getMaxDurabilityMultiplier() { + return 1.4F; + } + + @Override + public ItemStack getBrokenItem(final ItemStack aStack) { + return null; + } + + @Override + public IIconContainer getIcon(boolean aIsToolHead, ItemStack aStack) { + return (IIconContainer) (aIsToolHead ? TexturesGtTools.ELECTRIC_SNIPS : ItemIcons.POWER_UNIT_MV); + } + + @Override + public short[] getRGBa(boolean aIsToolHead, ItemStack aStack) { + return aIsToolHead ? GT_MetaGenerated_Tool.getPrimaryMaterial(aStack).mRGBa : Materials.TungstenSteel.mRGBa; + } + + @Override + public void onToolCrafted(final ItemStack aStack, final EntityPlayer aPlayer) { + super.onToolCrafted(aStack, aPlayer); + aPlayer.triggerAchievement(AchievementList.buildSword); + try { + GT_Mod.achievements.issueAchievement(aPlayer, "tools"); + GT_Mod.achievements.issueAchievement(aPlayer, "unitool"); + } catch (final Exception e) {} + } + + @Override + public IChatComponent getDeathMessage(final EntityLivingBase aPlayer, final EntityLivingBase aEntity) { + return new ChatComponentText( + EnumChatFormatting.RED + aEntity.getCommandSenderName() + + EnumChatFormatting.WHITE + + " has been Snipped out of existence by " + + EnumChatFormatting.GREEN + + aPlayer.getCommandSenderName() + + EnumChatFormatting.WHITE); + } +} |