Fix goggle tooltip

This commit is contained in:
2025-09-27 16:16:37 +02:00
parent 22ee3c9dcf
commit cf9ca661bb

View File

@@ -33,6 +33,7 @@ import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import com.imbgt.kineticbridge.KineticBridge;
import com.imbgt.kineticbridge.machine.KineticOutputHatchPartMachine;
import com.simibubi.create.content.kinetics.KineticNetwork;
import com.simibubi.create.content.kinetics.base.GeneratingKineticBlockEntity;
@@ -47,7 +48,7 @@ import java.util.Set;
* Block entity that bridges a GTCEu meta machine with Create's kinetic network.
*/
public class KineticOutputHatchBlockEntity extends GeneratingKineticBlockEntity
implements IMachineBlockEntity, IManaged {
implements IMachineBlockEntity, IManaged {
private static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(
KineticOutputHatchBlockEntity.class);
@@ -65,6 +66,7 @@ public class KineticOutputHatchBlockEntity extends GeneratingKineticBlockEntity
private float generatedSpeed = 0.0f;
private float lastGeneratedSpeed = 0.0f;
private boolean metaUnloaded = false;
private float turbineOcV = 0.0f;
public KineticOutputHatchBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState blockState) {
super(type, pos, blockState);
@@ -80,30 +82,18 @@ public class KineticOutputHatchBlockEntity extends GeneratingKineticBlockEntity
if (level == null || level.isClientSide())
return;
MetaMachine mm = getMetaMachine();
if (!(mm instanceof KineticOutputHatchPartMachine hatch)) {
this.generatedSpeed = 0;
finalizeKinetics();
return;
}
var ec = getEc();
if (ec != null) {
ec.setEnergyStored(0);
}
ITurbineMachine turbine = null;
for (var controller : hatch.getControllers()) {
if (controller instanceof ITurbineMachine tm) {
turbine = tm;
break;
}
}
ITurbineMachine turbine = getTurbine();
if (turbine == null) {
this.generatedSpeed = 0;
finalizeKinetics();
return;
}
int rotorSpeed = turbine.getRotorSpeed();
int maxRotorSpeed = turbine.getMaxRotorHolderSpeed();
@@ -121,6 +111,20 @@ public class KineticOutputHatchBlockEntity extends GeneratingKineticBlockEntity
return hatch.getEnergyContainer();
}
private ITurbineMachine getTurbine() {
ITurbineMachine turbine = null;
MetaMachine mm = getMetaMachine();
if ((mm instanceof KineticOutputHatchPartMachine hatch)) {
for (var controller : hatch.getControllers()) {
if (controller instanceof ITurbineMachine tm) {
turbine = tm;
break;
}
}
}
return turbine;
}
private void finalizeKinetics() {
if (Math.abs(this.lastGeneratedSpeed - this.generatedSpeed) >= 1) {
updateGeneratedRotation();
@@ -178,11 +182,22 @@ public class KineticOutputHatchBlockEntity extends GeneratingKineticBlockEntity
if (ec == null) {
return 0;
}
long euMax = Math.max(0L, ec.getOutputVoltage() * ec.getOutputAmperage());
double suMAx = euMax * FeCompat.ratio(false) * SU_TO_FE;
return (float) suMAx;
if (turbineOcV == 0.0f) {
var turbine = getTurbine();
if (turbine == null) {
return 0;
}
this.turbineOcV = turbine.getOverclockVoltage();
setChanged();
sendData();
}
double suTurbine = this.turbineOcV * FeCompat.ratio(false) * SU_TO_FE;
return (float) Math.min(suTurbine, suMAx);
}
@Override
@@ -197,12 +212,14 @@ public class KineticOutputHatchBlockEntity extends GeneratingKineticBlockEntity
}
super.read(tag, clientPacket);
this.generatedSpeed = tag.getFloat("GeneratedSpeed");
this.turbineOcV = tag.getFloat("TurbineOcV");
}
@Override
protected void write(CompoundTag tag, boolean clientPacket) {
super.write(tag, clientPacket);
tag.putFloat("GeneratedSpeed", generatedSpeed);
tag.putFloat("GeneratedSpeed", this.generatedSpeed);
tag.putFloat("TurbineOcV", this.turbineOcV);
}
@Override
@@ -210,16 +227,16 @@ public class KineticOutputHatchBlockEntity extends GeneratingKineticBlockEntity
boolean added = super.addToGoggleTooltip(tooltip, isPlayerSneaking);
MetaMachine machine = getMetaMachine();
if (machine instanceof KineticOutputHatchPartMachine hatch) {
tooltip.add(Component.translatable("tooltip.kineticbridge.max_stress",
Component.literal(FormattingUtil.formatNumbers(calculateAddedStressCapacity()))
.withStyle(ChatFormatting.AQUA),
Component.literal(String.format("%.0f", (double) speed))
.withStyle(ChatFormatting.AQUA)));
NotifiableEnergyContainer container = hatch.getEnergyContainer();
long maxPower = container.getOutputVoltage() * container.getOutputAmperage();
tooltip.add(Component.translatable("tooltip.kineticbridge.max_power",
Component.literal(FormattingUtil.formatNumbers(maxPower))
.withStyle(ChatFormatting.AQUA)));
tooltip.add(Component.translatable("tooltip.kineticbridge.max_stress",
Component.literal(FormattingUtil.formatNumbers(Math.max(0.0f, calculateAddedStressCapacity())))
.withStyle(ChatFormatting.AQUA),
Component.literal(String.format("%.0f", (double) speed))
.withStyle(ChatFormatting.AQUA)));
return true;
}
return added;
@@ -263,9 +280,9 @@ public class KineticOutputHatchBlockEntity extends GeneratingKineticBlockEntity
@Override
public void onLoad() {
super.onLoad();
metaMachine.onLoad();
if (!level.isClientSide)
updateGeneratedRotation();
metaMachine.onLoad();
}
private void unloadMetaMachine() {
@@ -289,15 +306,15 @@ public class KineticOutputHatchBlockEntity extends GeneratingKineticBlockEntity
@Override
public boolean shouldRenderGrid(Player player, BlockPos pos, BlockState state, ItemStack held,
Set<GTToolType> toolTypes) {
Set<GTToolType> toolTypes) {
return metaMachine.shouldRenderGrid(player, pos, state, held, toolTypes);
}
@Override
public @Nullable com.lowdragmc.lowdraglib.gui.texture.ResourceTexture sideTips(Player player, BlockPos pos,
BlockState state,
Set<GTToolType> toolTypes,
Direction side) {
BlockState state,
Set<GTToolType> toolTypes,
Direction side) {
return metaMachine.sideTips(player, pos, state, toolTypes, side);
}