Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Oct 14, 2024
1 parent f860ca3 commit 8d7c951
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.nomiceu.nomilabs.gregtech.mixinhelper;

public interface AccessibleSteamBoiler {

int labs$getCurrentTemperature();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.nomiceu.nomilabs.mixin.gregtech;

import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.nomiceu.nomilabs.gregtech.mixinhelper.AccessibleSteamBoiler;

import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.unification.material.Materials;
import gregtech.api.util.TextFormattingUtil;
import gregtech.common.metatileentities.steam.boiler.SteamBoiler;
import gregtech.integration.theoneprobe.provider.SteamBoilerInfoProvider;
import mcjty.theoneprobe.api.IProbeHitData;
import mcjty.theoneprobe.api.IProbeInfo;
import mcjty.theoneprobe.api.ProbeMode;
import mcjty.theoneprobe.api.TextStyleClass;

/**
* Improves Steam Boiler TOP Display.
*/
@Mixin(value = SteamBoilerInfoProvider.class, remap = false)
public class SteamBoilerInfoProviderMixin {

@Inject(method = "addProbeInfo", at = @At("HEAD"), cancellable = true)
private void replaceProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world,
IBlockState state, IProbeHitData data, CallbackInfo ci) {
ci.cancel();

if (!state.getBlock().hasTileEntity(state)) return;

TileEntity te = world.getTileEntity(data.getPos());
if (!(te instanceof IGregTechTileEntity igtte)) return;

MetaTileEntity mte = igtte.getMetaTileEntity();
if (!(mte instanceof SteamBoiler boiler)) return;

int steamOutput = boiler.getTotalSteamOutput();

// If we are not producing steam, and we have no fuel
if (steamOutput <= 0 && !boiler.isBurning()) return;

// Creating steam
if (steamOutput > 0 && boiler.hasWater()) {
probeInfo.text(TextStyleClass.INFO + "{*gregtech.top.energy_production*} " +
TextFormatting.AQUA + TextFormattingUtil.formatNumbers(steamOutput / 10) +
TextStyleClass.INFO + " L/t" + " {*" +
Materials.Steam.getUnlocalizedName() + "*}");
}

// Cooling Down
if (!boiler.isBurning()) {
probeInfo.text(TextStyleClass.INFO.toString() + TextFormatting.RED +
"{*nomilabs.top.steam_cooling_down*}");
}

// Initial Heat-Up
if (steamOutput <= 0 && ((AccessibleSteamBoiler) boiler).labs$getCurrentTemperature() > 0) {
// Current Temperature = the % until the boiler reaches 100
probeInfo.text(TextStyleClass.INFO.toString() + TextFormatting.RED +
"{*nomilabs.top.steam_heating_up*} " +
TextFormattingUtil
.formatNumbers(((AccessibleSteamBoiler) boiler).labs$getCurrentTemperature()) +
"%");
}

// No Water
if (!boiler.hasWater()) {
probeInfo.text(TextStyleClass.WARNING + "{*gregtech.top.steam_no_water*}");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.nomiceu.nomilabs.mixin.gregtech;

import net.minecraft.util.ResourceLocation;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.nomiceu.nomilabs.gregtech.mixinhelper.AccessibleSteamBoiler;

import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.common.metatileentities.steam.boiler.SteamBoiler;

/**
* Allows Accessing Steam Boiler Info, and Fixes Continuous Running.
*/
@Mixin(value = SteamBoiler.class, remap = false)
public abstract class SteamBoilerMixin extends MetaTileEntity implements AccessibleSteamBoiler {

@Shadow
private int currentTemperature;

@Shadow
private int fuelMaxBurnTime;

@Shadow
protected abstract int getCooldownInterval();

@Shadow
private int timeBeforeCoolingDown;

@Shadow
private boolean wasBurningAndNeedsUpdate;

@Shadow
private int fuelBurnTimeLeft;

/**
* Mandatory Ignored Constructor
*/
public SteamBoilerMixin(ResourceLocation metaTileEntityId) {
super(metaTileEntityId);
}

@Inject(method = "updateCurrentTemperature", at = @At("RETURN"))
private void checkForNegativeBurnTime(CallbackInfo ci) {
if (fuelMaxBurnTime > 0 && getOffsetTimer() % 12 == 0) {
if (fuelBurnTimeLeft < 0) {
fuelMaxBurnTime = 0;
timeBeforeCoolingDown = getCooldownInterval();
// boiler has no fuel now, so queue burning state update
wasBurningAndNeedsUpdate = true;
} else if (fuelBurnTimeLeft % 2 != 0) currentTemperature++;
}
}

@Override
@Unique
public int labs$getCurrentTemperature() {
return currentTemperature;
}
}
3 changes: 3 additions & 0 deletions src/main/resources/assets/nomilabs/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ config.nomilabs.advanced.difficulty.normal_override=Difficulty Override Normal
config.nomilabs.advanced.difficulty.expert_override=Difficulty Override Expert

# GUI
nomilabs.top.steam_heating_up=Heating Up:
nomilabs.top.steam_cooling_down=Cooling Down

nomilabs.gui.recipes.tooltip.ct_recipe=CraftTweaker Created Recipe
nomilabs.gui.recipes.tooltip.gs_recipe=GroovyScript Created Recipe

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/mixins.nomilabs.gregtech.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"RecipeMapMixin",
"RecipeMixin",
"RecyclingRecipesMixin",
"SteamBoilerInfoProviderMixin",
"SteamBoilerMixin",
"TileEntityPipeBaseMixin",
"VirtualizedRecipeMapMixin"
],
Expand Down

0 comments on commit 8d7c951

Please sign in to comment.