show converter HE/RF buffer levels

This commit is contained in:
George Paton 2026-05-08 12:12:43 +10:00
parent ea957c95aa
commit b25a30a273
4 changed files with 98 additions and 12 deletions

View File

@ -1,20 +1,44 @@
package com.hbm.blocks.machine;
import java.util.ArrayList;
import java.util.List;
import com.hbm.blocks.ILookOverlay;
import com.hbm.tileentity.network.TileEntityConverterHeRf;
import com.hbm.util.BobMathUtil;
import com.hbm.util.i18n.I18nUtil;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderGameOverlayEvent.Pre;
import net.minecraftforge.common.util.ForgeDirection;
public class BlockConverterHeRf extends BlockContainer {
public class BlockConverterHeRf extends BlockContainer implements ILookOverlay {
public BlockConverterHeRf(Material p_i45386_1_) {
super(p_i45386_1_);
public BlockConverterHeRf(Material mat) {
super(mat);
}
@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
public TileEntity createNewTileEntity(World world, int meta) {
return new TileEntityConverterHeRf();
}
@Override
public void printHook(Pre event, World world, int x, int y, int z) {
TileEntity tile = world.getTileEntity(x, y, z);
if(!(tile instanceof TileEntityConverterHeRf)) return;
TileEntityConverterHeRf converter = (TileEntityConverterHeRf) tile;
List<String> text = new ArrayList<>();
text.add(EnumChatFormatting.GREEN + "-> " + EnumChatFormatting.RESET + BobMathUtil.getShortNumber(converter.getPower()) + "HE");
text.add(EnumChatFormatting.RED + "<- " + EnumChatFormatting.RESET + BobMathUtil.getShortNumber(converter.getEnergyStored(ForgeDirection.UNKNOWN)) + "RF");
ILookOverlay.printGeneric(event, I18nUtil.resolveKey(getUnlocalizedName() + ".name"), 0xffff00, 0x404000, text);
}
}

View File

@ -1,20 +1,44 @@
package com.hbm.blocks.machine;
import java.util.ArrayList;
import java.util.List;
import com.hbm.blocks.ILookOverlay;
import com.hbm.tileentity.network.TileEntityConverterRfHe;
import com.hbm.util.BobMathUtil;
import com.hbm.util.i18n.I18nUtil;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderGameOverlayEvent.Pre;
import net.minecraftforge.common.util.ForgeDirection;
public class BlockConverterRfHe extends BlockContainer {
public class BlockConverterRfHe extends BlockContainer implements ILookOverlay {
public BlockConverterRfHe(Material p_i45386_1_) {
super(p_i45386_1_);
public BlockConverterRfHe(Material mat) {
super(mat);
}
@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
public TileEntity createNewTileEntity(World world, int meta) {
return new TileEntityConverterRfHe();
}
@Override
public void printHook(Pre event, World world, int x, int y, int z) {
TileEntity tile = world.getTileEntity(x, y, z);
if(!(tile instanceof TileEntityConverterRfHe)) return;
TileEntityConverterRfHe converter = (TileEntityConverterRfHe) tile;
List<String> text = new ArrayList<>();
text.add(EnumChatFormatting.GREEN + "-> " + EnumChatFormatting.RESET + BobMathUtil.getShortNumber(converter.getEnergyStored(ForgeDirection.UNKNOWN)) + "RF");
text.add(EnumChatFormatting.RED + "<- " + EnumChatFormatting.RESET + BobMathUtil.getShortNumber(converter.getPower()) + "HE");
ILookOverlay.printGeneric(event, I18nUtil.resolveKey(getUnlocalizedName() + ".name"), 0xffff00, 0x404000, text);
}
}

View File

@ -11,6 +11,7 @@ import api.hbm.energymk2.IEnergyReceiverMK2;
import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyHandler;
import cofh.api.energy.IEnergyReceiver;
import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
@ -31,7 +32,7 @@ public class TileEntityConverterHeRf extends TileEntityLoadedBase implements IEn
@Override
public void updateEntity() {
if (!worldObj.isRemote) {
if(!worldObj.isRemote) {
long rfCreated = Math.min(storage.getMaxEnergyStored() - storage.getEnergyStored(), power / heInput * rfOutput);
this.power -= rfCreated * heInput / rfOutput;
@ -39,13 +40,13 @@ public class TileEntityConverterHeRf extends TileEntityLoadedBase implements IEn
if(power > 0) this.power *= (1D - inputDecay);
if(rfCreated > 0) this.worldObj.markTileEntityChunkModified(this.xCoord, this.yCoord, this.zCoord, this);
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
this.trySubscribe(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir);
BlockPos loc = new BlockPos(xCoord, yCoord, zCoord).offset(dir);
TileEntity entity = Compat.getTileStandard(worldObj, loc.getX(), loc.getY(), loc.getZ());
if (entity != null && entity instanceof IEnergyReceiver) {
if(entity != null && entity instanceof IEnergyReceiver) {
IEnergyReceiver receiver = (IEnergyReceiver) entity;
int maxExtract = storage.getMaxExtract();
@ -55,6 +56,8 @@ public class TileEntityConverterHeRf extends TileEntityLoadedBase implements IEn
storage.extractEnergy(energyTransferred, false);
}
}
networkPackNT(15);
}
}
@ -85,6 +88,22 @@ public class TileEntityConverterHeRf extends TileEntityLoadedBase implements IEn
storage.writeToNBT(nbt);
}
@Override
public void serialize(ByteBuf buf) {
super.serialize(buf);
buf.writeLong(power);
buf.writeInt(storage.getEnergyStored());
}
@Override
public void deserialize(ByteBuf buf) {
super.deserialize(buf);
power = buf.readLong();
storage.setEnergyStored(buf.readInt());
}
@Override
public String getConfigName() {
return "HEToRFConverter";

View File

@ -8,6 +8,7 @@ import com.hbm.tileentity.TileEntityLoadedBase;
import api.hbm.energymk2.IEnergyProviderMK2;
import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyHandler;
import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
@ -26,7 +27,7 @@ public class TileEntityConverterRfHe extends TileEntityLoadedBase implements IEn
@Override
public void updateEntity() {
if (!worldObj.isRemote) {
if(!worldObj.isRemote) {
long rfCreated = Math.min(storage.getEnergyStored(), (maxPower - power) * rfInput / heOutput);
storage.setEnergyStored((int) (storage.getEnergyStored() - rfCreated));
@ -37,6 +38,8 @@ public class TileEntityConverterRfHe extends TileEntityLoadedBase implements IEn
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
this.tryProvide(worldObj, xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir);
}
networkPackNT(15);
}
}
@ -66,6 +69,22 @@ public class TileEntityConverterRfHe extends TileEntityLoadedBase implements IEn
storage.writeToNBT(nbt);
}
@Override
public void serialize(ByteBuf buf) {
super.serialize(buf);
buf.writeLong(power);
buf.writeInt(storage.getEnergyStored());
}
@Override
public void deserialize(ByteBuf buf) {
super.deserialize(buf);
power = buf.readLong();
storage.setEnergyStored(buf.readInt());
}
@Override
public String getConfigName() {
return "RFToHEConverter";