-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f048206
commit 8da1028
Showing
4 changed files
with
370 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
360 changes: 360 additions & 0 deletions
360
...od/gregtech/common/tileentities/machines/multi/processing/steam/MTESteamAlloySmelter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<MTESteamAlloySmelter> 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<MTESteamAlloySmelter> 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<MTESteamAlloySmelter> getStructureDefinition() { | ||
if (STRUCTURE_DEFINITION == null) { | ||
STRUCTURE_DEFINITION = StructureDefinition.<MTESteamAlloySmelter>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<String> 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<String> 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; | ||
} | ||
} |
Oops, something went wrong.