Skip to content

Commit

Permalink
HIP Unit mini rework (#3658)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Robertz <[email protected]>
  • Loading branch information
FourIsTheNumber and Dream-Master authored Dec 16, 2024
1 parent e910890 commit 96f74f8
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 44 deletions.
2 changes: 2 additions & 0 deletions src/main/java/gregtech/api/enums/Textures.java
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,8 @@ public enum BlockIcons implements IIconContainer, Runnable {
BLOCK_QUARK_CONTAINMENT_CASING,
COMPRESSOR_CASING,
COMPRESSOR_PIPE_CASING,
HEATING_DUCT_CASING,
COOLANT_DUCT_CASING,
NEUTRONIUM_CASING,
NEUTRONIUM_ACTIVE_CASING,
NEUTRONIUM_STABLE_CASING,
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gregtech/common/blocks/BlockCasings10.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public IIcon getIcon(int ordinalSide, int aMeta) {
case 6 -> Textures.BlockIcons.NEUTRONIUM_CASING.getIcon();
case 7 -> Textures.BlockIcons.NEUTRONIUM_ACTIVE_CASING.getIcon();
case 8 -> Textures.BlockIcons.NEUTRONIUM_STABLE_CASING.getIcon();
case 9 -> Textures.BlockIcons.MACHINE_CASING_PIPE_TUNGSTENSTEEL.getIcon();
case 10 -> Textures.BlockIcons.MACHINE_CASING_PIPE_BRONZE.getIcon();
case 9 -> Textures.BlockIcons.COOLANT_DUCT_CASING.getIcon();
case 10 -> Textures.BlockIcons.HEATING_DUCT_CASING.getIcon();
case 11 -> Textures.BlockIcons.EXTREME_DENSITY_CASING.getIcon();
case 12 -> Textures.BlockIcons.RADIATION_ABSORBENT_CASING.getIcon();
case 13 -> Textures.BlockIcons.MACHINE_CASING_MS160.getIcon();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public class MTEHIPCompressor extends MTEExtendedPowerMultiBlockBase<MTEHIPCompr
private int coilTier = 0;

private float heat = 0;
private boolean cooling = false;
private boolean overheated = false;

public MTEHIPCompressor(final int aID, final String aName, final String aNameRegional) {
super(aID, aName, aNameRegional);
Expand All @@ -133,22 +133,22 @@ public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {

@Override
public void onValueUpdate(byte aValue) {
boolean oCooling = cooling;
cooling = (aValue & 1) == 1;
if (oCooling != cooling) getBaseMetaTileEntity().issueTextureUpdate();
boolean oldOverheated = overheated;
overheated = (aValue & 1) == 1;
if (oldOverheated != overheated) getBaseMetaTileEntity().issueTextureUpdate();
}

@Override
public byte getUpdateData() {
return (byte) (cooling ? 1 : 0);
return (byte) (overheated ? 1 : 0);
}

@Override
public ITexture[] getTexture(IGregTechTileEntity baseMetaTileEntity, ForgeDirection side, ForgeDirection aFacing,
int colorIndex, boolean aActive, boolean redstoneLevel) {
ITexture[] rTexture;
if (side == aFacing) {
if (cooling) {
if (overheated) {
rTexture = new ITexture[] {
Textures.BlockIcons
.getCasingTextureForId(GTUtility.getCasingTextureIndex(GregTechAPI.sBlockCasings10, 4)),
Expand Down Expand Up @@ -218,10 +218,10 @@ protected MultiblockTooltipBuilder createTooltip() {
+ EnumChatFormatting.GRAY
+ " HIP")
.addInfo(
"If the machine " + EnumChatFormatting.DARK_RED
+ "overheats"
"If the machine is " + EnumChatFormatting.DARK_RED
+ "overheated"
+ EnumChatFormatting.GRAY
+ " during these recipes, recipe will be voided!")
+ " when one of these recipes starts, it will be voided!")
.addInfo("Read the current heat using Heat Sensor Hatches")
.addSeparator()
.addInfo("More advanced coils allow better heat control - the unit will take longer to overheat")
Expand All @@ -234,7 +234,12 @@ protected MultiblockTooltipBuilder createTooltip() {
"Unit cools by " + EnumChatFormatting.GREEN
+ "2%"
+ EnumChatFormatting.GRAY
+ " every second while not running")
+ " base every second while not running")
.addInfo(
"Cooling rate increases by an additional " + EnumChatFormatting.GREEN
+ "2%"
+ EnumChatFormatting.GRAY
+ " for each second since running")
.addSeparator()
.addInfo(
"250% " + EnumChatFormatting.RED
Expand Down Expand Up @@ -314,18 +319,18 @@ protected void setProcessingLogicPower(ProcessingLogic logic) {
@Override
public void saveNBTData(NBTTagCompound aNBT) {
aNBT.setFloat("heat", heat);
aNBT.setBoolean("cooling", cooling);
aNBT.setBoolean("cooling", overheated);
aNBT.setInteger("coilTier", coilTier);
aNBT.setBoolean("doingHIP", doingHIP);
aNBT.setInteger("coolingTimer", coolingTimer);
super.saveNBTData(aNBT);
}

@Override
public void loadNBTData(NBTTagCompound aNBT) {
if (aNBT.hasKey("heat")) heat = aNBT.getFloat("heat");
if (aNBT.hasKey("cooling")) cooling = aNBT.getBoolean("cooling");
if (aNBT.hasKey("cooling")) overheated = aNBT.getBoolean("cooling");
if (aNBT.hasKey("coilTier")) coilTier = aNBT.getInteger("coilTier");
if (aNBT.hasKey("doingHIP")) doingHIP = aNBT.getBoolean("doingHIP");
if (aNBT.hasKey("coolingTimer")) coolingTimer = aNBT.getInteger("coolingTimer");
super.loadNBTData(aNBT);
}

Expand All @@ -334,7 +339,7 @@ public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompou
int z) {
super.getWailaNBTData(player, tile, tag, world, x, y, z);
tag.setInteger("heat", Math.round(heat));
tag.setBoolean("cooling", cooling);
tag.setBoolean("cooling", overheated);
}

@Override
Expand All @@ -356,27 +361,31 @@ public void getWailaBody(ItemStack itemStack, List<String> currentTip, IWailaDat
+ EnumChatFormatting.RESET);
}

private boolean doingHIP = false;

@Override
protected ProcessingLogic createProcessingLogic() {
return new ProcessingLogic() {

@NotNull
@Override
protected CheckRecipeResult validateRecipe(@NotNull GTRecipe recipe) {
doingHIP = false;
setSpeedBonus(1F / 3.5F);
setEuModifier(0.75F);

if (cooling) {
int recipeReq = recipe.getMetadataOrDefault(CompressionTierKey.INSTANCE, 0);

// Nerf when heated
if (overheated) {
setSpeedBonus(2.5F);
setEuModifier(1.1F);
}

int recipeReq = recipe.getMetadataOrDefault(CompressionTierKey.INSTANCE, 0);
// If HIP required, check for overheat and potentially crash
// If Black Hole required, no recipe
if (recipeReq == 1) {
doingHIP = true;
if (overheated) {
stopMachine(SimpleShutDownReason.ofCritical("overheated"));
return CheckRecipeResultRegistry.NO_RECIPE;
}
} else if (recipeReq == 2) {
return CheckRecipeResultRegistry.NO_RECIPE;
}
Expand All @@ -385,35 +394,35 @@ protected CheckRecipeResult validateRecipe(@NotNull GTRecipe recipe) {
}.setMaxParallelSupplier(this::getMaxParallelRecipes);
}

@Override
public boolean onRunningTick(ItemStack aStack) {
if (cooling && doingHIP) {
stopMachine(SimpleShutDownReason.ofCritical("overheated"));
doingHIP = false;
}
return super.onRunningTick(aStack);
}
private int coolingTimer = 0;

@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
super.onPostTick(aBaseMetaTileEntity, aTick);

if (aTick % 20 == 0) {
if (aTick % 20 != 0 || aBaseMetaTileEntity.isClientSide()) return;

// Default to cooling by 2%
float heatMod = -2;
// Default to cooling by 2%
float heatMod = -2;

// If the machine is running, heat by 5% x 0.90 ^ (Coil Tier)
// Cupronickel is 0, so base will be 5% increase
if (this.maxProgresstime() != 0) {
heatMod = (float) (5 * Math.pow(0.9, coilTier));
}
// If the machine is running, heat by 5% x 0.90 ^ (Coil Tier)
// Cupronickel is 0, so base will be 5% increase
// Also reset cooling speed
if (this.maxProgresstime() != 0) {
heatMod = (float) (5 * Math.pow(0.9, coilTier));
coolingTimer = 0;
} else {
// If the machine isn't running, add and increment the cooling timer
heatMod -= coolingTimer;
coolingTimer += 2;
}

heat = MathUtils.clamp(heat + heatMod, 0, 100);
heat = MathUtils.clamp(heat + heatMod, 0, 100);

if ((cooling && heat <= 0) || (!cooling && heat >= 100)) {
cooling = !cooling;
}
// Switch overheated conditionally and reset the cooling speed
if ((overheated && heat <= 0) || (!overheated && heat >= 100)) {
overheated = !overheated;
coolingTimer = 0;
}

// Update all the sensors
Expand All @@ -424,7 +433,7 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
}

public int getMaxParallelRecipes() {
return cooling ? GTUtility.getTier(this.getMaxInputVoltage())
return overheated ? GTUtility.getTier(this.getMaxInputVoltage())
: (4 * GTUtility.getTier(this.getMaxInputVoltage()));
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 96f74f8

Please sign in to comment.