diff --git a/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java b/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java index 4f08bf49c95..45632a53e0d 100644 --- a/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java +++ b/src/main/java/gregtech/api/enums/MetaTileEntityIDs.java @@ -1890,6 +1890,7 @@ public enum MetaTileEntityIDs { Controller_SteamWasherMulti(31082), Controller_SteamForgeHammer(31083), Controller_SteamMixerMulti(31084), + Controller_SteamAlloySmelterMulti(31086), GT4_Electric_Auto_Workbench_LV(31091), GT4_Electric_Auto_Workbench_MV(31092), GT4_Electric_Auto_Workbench_HV(31093), diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java index 92b173a7e84..9d2887d20a7 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/enums/GregtechItemList.java @@ -456,6 +456,8 @@ public enum GregtechItemList implements IGregtechItemContainer { Controller_SteamMixerMulti, // Big Steam Mixer Controller_SteamCompressorMulti, + // Big Alloy Smelter + Controller_SteamAlloySmelterMulti, // Industrial Rock Breaker Controller_IndustrialRockBreaker, diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/MTESteamAlloySmelter.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/MTESteamAlloySmelter.java new file mode 100644 index 00000000000..46030e74db5 --- /dev/null +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/steam/MTESteamAlloySmelter.java @@ -0,0 +1,360 @@ +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.ofBlocksTiered; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; +import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; +import static gregtech.api.GregTechAPI.sBlockCasings1; +import static gregtech.api.GregTechAPI.sBlockCasings2; +import static gregtech.api.util.GTStructureUtility.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.entity.player.EntityPlayerMP; +import net.minecraft.init.Blocks; +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 org.apache.commons.lang3.tuple.Pair; +import org.jetbrains.annotations.NotNull; + +import com.google.common.collect.ImmutableList; +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 cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gregtech.api.GregTechAPI; +import gregtech.api.enums.SoundResource; +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.MTEHatch; +import gregtech.api.objects.GTRenderedTexture; +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.GTRecipe; +import gregtech.api.util.MultiblockTooltipBuilder; +import gregtech.api.util.OverclockCalculator; +import gregtech.common.blocks.BlockCasings1; +import gregtech.common.blocks.BlockCasings2; +import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.base.MTESteamMultiBase; +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; + +public class MTESteamAlloySmelter extends MTESteamMultiBase implements ISurvivalConstructable { + + public MTESteamAlloySmelter(String aName) { + super(aName); + } + + public MTESteamAlloySmelter(int aID, String aName, String aNameRegional) { + super(aID, aName, aNameRegional); + } + + @Override + public IMetaTileEntity newMetaEntity(IGregTechTileEntity arg0) { + return new MTESteamAlloySmelter(this.mName); + } + + @Override + public String getMachineType() { + return "Alloy Smelter"; + } + + private static final String STRUCTURE_PIECE_MAIN = "main"; + + private IStructureDefinition STRUCTURE_DEFINITION = null; + + private static final int HORIZONTAL_OFF_SET = 1; + private static final int VERTICAL_OFF_SET = 1; + private static final int DEPTH_OFF_SET = 0; + + private int mCounCasing = 0; + + private int tierMachine = 0; + + private int tierMachineCasing = -1; + + public int getTierMachineCasing(Block block, int meta) { + if (block == sBlockCasings1 && 10 == meta) { + mCounCasing++; + return 1; + } + if (block == sBlockCasings2 && 0 == meta) { + mCounCasing++; + return 2; + } + return 0; + } + + public static int getTierPipeCasing(Block block, int meta) { + if (block == sBlockCasings2 && 12 == meta) return 1; + if (block == sBlockCasings2 && 13 == meta) return 2; + return 0; + } + + protected void updateHatchTexture() { + for (MTEHatch h : mSteamInputs) h.updateTexture(getCasingTextureID()); + for (MTEHatch h : mSteamOutputs) h.updateTexture(getCasingTextureID()); + for (MTEHatch h : mSteamInputFluids) h.updateTexture(getCasingTextureID()); + } + + private int getCasingTextureID() { + if (tierMachineCasing == 2) return ((BlockCasings2) GregTechAPI.sBlockCasings2).getTextureIndex(0); + return ((BlockCasings1) GregTechAPI.sBlockCasings1).getTextureIndex(10); + } + + @Override + public void onValueUpdate(byte aValue) { + tierMachineCasing = aValue; + } + + @Override + public byte getUpdateData() { + return (byte) tierMachineCasing; + } + + @Override + protected GTRenderedTexture getFrontOverlay() { + return new GTRenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_STEAM_ALLOY_SMELTER); + } + + @Override + protected GTRenderedTexture getFrontOverlayActive() { + return new GTRenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_STEAM_ALLOY_SMELTER_ACTIVE); + } + + @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(getCasingTextureID()), + aActive ? getFrontOverlayActive() : getFrontOverlay() }; + } + return new ITexture[] { Textures.BlockIcons.getCasingTextureForId(getCasingTextureID()) }; + } + + private final String[][] shape = new String[][] { { "BBB", "BAB", "BAB", "BBB" }, { "B~B", "ACA", "ACA", "BBB" }, + { "BBB", "BAB", "BAB", "BBB" } }; + + @Override + public IStructureDefinition getStructureDefinition() { + if (STRUCTURE_DEFINITION == null) { + STRUCTURE_DEFINITION = StructureDefinition.builder() + .addShape(STRUCTURE_PIECE_MAIN, transpose(shape)) + .addElement( + 'B', + ofChain( + buildSteamInput(MTESteamAlloySmelter.class).casingIndex(10) + .dot(1) + .build(), + buildHatchAdder(MTESteamAlloySmelter.class) + .atLeast(SteamHatchElement.InputBus_Steam, SteamHatchElement.OutputBus_Steam) + .casingIndex(10) + .dot(1) + .buildAndChain(), + ofBlocksTiered( + this::getTierMachineCasing, + ImmutableList.of(Pair.of(sBlockCasings1, 10), Pair.of(sBlockCasings2, 0)), + -1, + (t, m) -> t.tierMachineCasing = m, + t -> t.tierMachineCasing))) + .addElement( + 'C', + ofBlocksTiered( + MTESteamForgeHammer::getTierPipeCasing, + ImmutableList.of(Pair.of(sBlockCasings2, 12), Pair.of(sBlockCasings2, 13)), + -1, + (t, m) -> t.tierPipeCasing = m, + t -> t.tierPipeCasing)) + .addElement('A', ofBlock(Blocks.glass, 0)) + .build(); + } + return STRUCTURE_DEFINITION; + } + + @Override + public void construct(ItemStack stackSize, boolean hintsOnly) { + buildPiece(STRUCTURE_PIECE_MAIN, stackSize, hintsOnly, HORIZONTAL_OFF_SET, VERTICAL_OFF_SET, DEPTH_OFF_SET); + } + + @Override + public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) { + return survivialBuildPiece( + STRUCTURE_PIECE_MAIN, + stackSize, + HORIZONTAL_OFF_SET, + VERTICAL_OFF_SET, + DEPTH_OFF_SET, + elementBudget, + env, + false, + true); + } + + private int tierPipeCasing = -1; + + @Override + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { + tierPipeCasing = -1; + tierMachineCasing = -1; + mCounCasing = 0; + if (!checkPiece(STRUCTURE_PIECE_MAIN, HORIZONTAL_OFF_SET, VERTICAL_OFF_SET, DEPTH_OFF_SET)) return false; + if (tierPipeCasing < 0 && tierMachineCasing < 0) return false; + if (tierPipeCasing == 1 && tierMachineCasing == 1 && mCounCasing >= 14 && checkHatches()) { + updateHatchTexture(); + tierMachine = 1; + return true; + } + if (tierPipeCasing == 2 && tierMachineCasing == 2 && mCounCasing >= 14 && checkHatches()) { + updateHatchTexture(); + tierMachine = 2; + return true; + } + return false; + } + + private boolean checkHatches() { + return !mSteamInputFluids.isEmpty() && !mSteamInputs.isEmpty() + && !mSteamOutputs.isEmpty() + && mOutputHatches.isEmpty() + && mInputHatches.isEmpty(); + } + + @Override + public int getMaxParallelRecipes() { + return 8; + } + + @Override + public RecipeMap getRecipeMap() { + return RecipeMaps.alloySmelterRecipes; + } + + @Override + protected ProcessingLogic createProcessingLogic() { + return new ProcessingLogic() { + + @Nonnull + @Override + protected CheckRecipeResult validateRecipe(@Nonnull GTRecipe recipe) { + if (availableVoltage < recipe.mEUt) { + return CheckRecipeResultRegistry.insufficientPower(recipe.mEUt); + } + return CheckRecipeResultRegistry.SUCCESSFUL; + } + + // note that a basic steam machine has .setEUtDiscount(2F).setSpeedBoost(2F). So these here are bonuses. + @Override + @Nonnull + protected OverclockCalculator createOverclockCalculator(@NotNull GTRecipe recipe) { + return OverclockCalculator.ofNoOverclock(recipe) + .setEUtDiscount(1.25 * tierMachine) + .setSpeedBoost(1.6 / tierMachine); + } + }.setMaxParallelSupplier(this::getMaxParallelRecipes); + } + + @Override + public int getTierRecipes() { + return 1; + } + + @Override + protected MultiblockTooltipBuilder createTooltip() { + MultiblockTooltipBuilder tt = new MultiblockTooltipBuilder(); + tt.addMachineType(getMachineType()) + .addInfo("25% faster than using single block steam machines of the same pressure") + .addInfo("Only consumes steam at 62.5% of the L/s normally required") + .addInfo("Processes up to 8 recipes at once") + .addInfo(HIGH_PRESSURE_TOOLTIP_NOTICE) + .beginStructureBlock(3, 3, 3, false) + .addInputBus(EnumChatFormatting.GOLD + "1" + EnumChatFormatting.GRAY + " Any casing", 1) + .addOutputBus(EnumChatFormatting.GOLD + "1" + EnumChatFormatting.GRAY + " Any casing", 1) + .addStructureInfo( + EnumChatFormatting.WHITE + "Steam Input Hatch " + + EnumChatFormatting.GOLD + + "1" + + EnumChatFormatting.GRAY + + " Any casing") + .addStructureInfo("") + .addStructureInfo(EnumChatFormatting.BLUE + "Basic " + EnumChatFormatting.DARK_PURPLE + "Tier") + .addStructureInfo(EnumChatFormatting.GOLD + "14-25x" + EnumChatFormatting.GRAY + " Bronze Plated Bricks") + .addStructureInfo(EnumChatFormatting.GOLD + "2x" + EnumChatFormatting.GRAY + " Bronze Pipe Casing") + .addStructureInfo("") + .addStructureInfo(EnumChatFormatting.BLUE + "High Pressure " + EnumChatFormatting.DARK_PURPLE + "Tier") + .addStructureInfo( + EnumChatFormatting.GOLD + "14-25x" + EnumChatFormatting.GRAY + " Solid Steel Machine Casing") + .addStructureInfo(EnumChatFormatting.GOLD + "2x" + EnumChatFormatting.GRAY + " Steel Pipe Casing") + .toolTipFinisher(); + return tt; + } + + @Override + public String[] getInfoData() { + ArrayList info = new ArrayList<>(Arrays.asList(super.getInfoData())); + info.add("Machine Tier: " + EnumChatFormatting.YELLOW + tierMachine); + info.add("Parallel: " + EnumChatFormatting.YELLOW + getMaxParallelRecipes()); + return info.toArray(new String[0]); + } + + @Override + public void getWailaBody(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, + IWailaConfigHandler config) { + super.getWailaBody(itemStack, currenttip, accessor, config); + NBTTagCompound tag = accessor.getNBTData(); + currenttip.add( + StatCollector.translateToLocal("GTPP.machines.tier") + ": " + + EnumChatFormatting.YELLOW + + getSteamTierTextForWaila(tag) + + EnumChatFormatting.RESET); + currenttip.add( + StatCollector.translateToLocal("GT5U.multiblock.curparallelism") + ": " + + EnumChatFormatting.BLUE + + tag.getInteger("parallel") + + EnumChatFormatting.RESET); + } + + @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("tierMachine", tierMachine); + tag.setInteger("parallel", getMaxParallelRecipes()); + } + + @Override + public void saveNBTData(NBTTagCompound aNBT) { + super.saveNBTData(aNBT); + aNBT.setInteger("tierMachine", tierMachine); + } + + @Override + public void loadNBTData(final NBTTagCompound aNBT) { + super.loadNBTData(aNBT); + tierMachine = aNBT.getInteger("tierMachine"); + } + + @SideOnly(Side.CLIENT) + @Override + protected SoundResource getActivitySoundLoop() { + return SoundResource.IC2_MACHINES_ELECTROFURNACE_LOOP; + } +} diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechSteamMultis.java b/src/main/java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechSteamMultis.java index a9a29b3c37c..4b351e7e903 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechSteamMultis.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/registration/gregtech/GregtechSteamMultis.java @@ -1,5 +1,6 @@ package gtPlusPlus.xmod.gregtech.registration.gregtech; +import static gregtech.api.enums.MetaTileEntityIDs.Controller_SteamAlloySmelterMulti; import static gregtech.api.enums.MetaTileEntityIDs.Controller_SteamCentrifugeMulti; import static gregtech.api.enums.MetaTileEntityIDs.Controller_SteamCompressorMulti; import static gregtech.api.enums.MetaTileEntityIDs.Controller_SteamForgeHammer; @@ -13,6 +14,7 @@ import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.MTEHatchSteamBusInput; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.MTEHatchSteamBusOutput; +import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.steam.MTESteamAlloySmelter; import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.steam.MTESteamCentrifuge; import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.steam.MTESteamCompressor; import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.steam.MTESteamForgeHammer; @@ -52,6 +54,11 @@ public static void run() { GregtechItemList.Controller_SteamMixerMulti.set( new MTESteamMixer(Controller_SteamMixerMulti.ID, "gtpp.multimachine.steam.mixer", "Steam Blender") .getStackForm(1)); + GregtechItemList.Controller_SteamAlloySmelterMulti.set( + new MTESteamAlloySmelter( + Controller_SteamAlloySmelterMulti.ID, + "gtpp.multimachine.steam.alloysmelter", + "Steam Fuser").getStackForm(1)); GregtechItemList.Hatch_Input_Bus_Steam.set( new MTEHatchSteamBusInput(Hatch_Input_Bus_Steam.ID, "hatch.input_bus.tier.steam", "Input Bus (Steam)", 0)