-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add steam boiler production to top/waila (#2126)
- Loading branch information
1 parent
d07731d
commit 2e247cd
Showing
8 changed files
with
156 additions
and
5 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
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
80 changes: 80 additions & 0 deletions
80
src/main/java/gregtech/integration/hwyla/provider/SteamBoilerDataProvider.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,80 @@ | ||
package gregtech.integration.hwyla.provider; | ||
|
||
import gregtech.api.GTValues; | ||
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; | ||
import gregtech.api.unification.material.Materials; | ||
import gregtech.common.metatileentities.steam.boiler.SteamBoiler; | ||
import mcp.mobius.waila.api.IWailaConfigHandler; | ||
import mcp.mobius.waila.api.IWailaDataAccessor; | ||
import mcp.mobius.waila.api.IWailaDataProvider; | ||
import mcp.mobius.waila.api.IWailaRegistrar; | ||
import net.minecraft.client.resources.I18n; | ||
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.math.BlockPos; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
|
||
public class SteamBoilerDataProvider implements IWailaDataProvider { | ||
|
||
public static final SteamBoilerDataProvider INSTANCE = new SteamBoilerDataProvider(); | ||
|
||
public void register(@NotNull IWailaRegistrar registrar) { | ||
registrar.registerBodyProvider(this, IGregTechTileEntity.class); | ||
registrar.registerNBTProvider(this, IGregTechTileEntity.class); | ||
registrar.addConfig(GTValues.MODID, "gregtech.steam_boiler"); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, BlockPos pos) { | ||
if (te instanceof IGregTechTileEntity gtte) { | ||
if (gtte.getMetaTileEntity() instanceof SteamBoiler boiler) { | ||
NBTTagCompound subTag = new NBTTagCompound(); | ||
subTag.setBoolean("IsBurning", boiler.isBurning()); | ||
subTag.setBoolean("HasWater", boiler.hasWater()); | ||
subTag.setInteger("SteamRate", boiler.getTotalSteamOutput()); | ||
tag.setTag("gregtech.SteamBoiler", subTag); | ||
} | ||
} | ||
return tag; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public List<String> getWailaBody(ItemStack itemStack, List<String> tooltip, IWailaDataAccessor accessor, IWailaConfigHandler config) { | ||
if (!config.getConfig("gregtech.steam_boiler") | ||
|| !(accessor.getTileEntity() instanceof IGregTechTileEntity gtte) | ||
|| !(gtte.getMetaTileEntity() instanceof SteamBoiler)) { | ||
return tooltip; | ||
} | ||
|
||
if (accessor.getNBTData().hasKey("gregtech.SteamBoiler")) { | ||
NBTTagCompound tag = accessor.getNBTData().getCompoundTag("gregtech.SteamBoiler"); | ||
if (tag.getBoolean("IsBurning")) { | ||
int steamRate = tag.getInteger("SteamRate"); | ||
boolean hasWater = tag.getBoolean("HasWater"); | ||
|
||
// Creating steam | ||
if (steamRate > 0 && hasWater) { | ||
tooltip.add(I18n.format("gregtech.top.energy_production") + ": " + (steamRate / 10) + " L/t " + I18n.format(Materials.Steam.getUnlocalizedName())); | ||
} | ||
|
||
// Initial heat-up | ||
if (steamRate <= 0) { | ||
tooltip.add(I18n.format("gregtech.top.steam_heating_up")); | ||
} | ||
|
||
// No water | ||
if (!hasWater) { | ||
tooltip.add(I18n.format("gregtech.top.steam_no_water")); | ||
} | ||
} | ||
} | ||
return tooltip; | ||
} | ||
} |
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
56 changes: 56 additions & 0 deletions
56
src/main/java/gregtech/integration/theoneprobe/provider/SteamBoilerInfoProvider.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,56 @@ | ||
package gregtech.integration.theoneprobe.provider; | ||
|
||
import gregtech.api.GTValues; | ||
import gregtech.api.metatileentity.MetaTileEntity; | ||
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity; | ||
import gregtech.api.unification.material.Materials; | ||
import gregtech.common.metatileentities.steam.boiler.SteamBoiler; | ||
import mcjty.theoneprobe.api.*; | ||
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; | ||
|
||
public class SteamBoilerInfoProvider implements IProbeInfoProvider { | ||
|
||
@Override | ||
public String getID() { | ||
return GTValues.MODID + ":steam_boiler_provider"; | ||
} | ||
|
||
@Override | ||
public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, IBlockState state, IProbeHitData data) { | ||
if (state.getBlock().hasTileEntity(state)) { | ||
TileEntity te = world.getTileEntity(data.getPos()); | ||
if (te instanceof IGregTechTileEntity igtte) { | ||
MetaTileEntity mte = igtte.getMetaTileEntity(); | ||
if (mte instanceof SteamBoiler boiler) { | ||
if (boiler.isBurning()) { | ||
// Boiler is active | ||
int steamOutput = boiler.getTotalSteamOutput(); | ||
|
||
// Creating steam | ||
if (steamOutput > 0 && boiler.hasWater()) { | ||
probeInfo.text(TextStyleClass.INFO | ||
+ "{*gregtech.top.energy_production*} " | ||
+ TextFormatting.AQUA + (steamOutput / 10) | ||
+ TextStyleClass.INFO + " L/t" | ||
+ " {*" + Materials.Steam.getUnlocalizedName() + "*}"); | ||
} | ||
|
||
// Initial heat-up | ||
if (steamOutput <= 0) { | ||
probeInfo.text(TextStyleClass.INFO.toString() + TextFormatting.RED + "{*gregtech.top.steam_heating_up*}"); | ||
} | ||
|
||
// No water | ||
if (!boiler.hasWater()) { | ||
probeInfo.text(TextStyleClass.WARNING + "{*gregtech.top.steam_no_water*}"); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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