fix: 实体加速器能量不足的显示界面显示问题
This commit is contained in:
parent
28dfdaac78
commit
848cf86624
|
|
@ -30,8 +30,8 @@ public class EntitySpeedTickerMenu extends UpgradeableMenu<EntitySpeedTickerPart
|
|||
@GuiSync(719) public int effectiveSpeed = 1;
|
||||
@GuiSync(720) public double multiplier = 1.0;
|
||||
@GuiSync(721) public boolean targetBlacklisted = false;
|
||||
// 来自部件的网络能量不足提示(服务端设置,客户端用于显示警告)
|
||||
@GuiSync(722) public boolean networkEnergyInsufficient = false;
|
||||
// 来自部件的网络能量充足提示(服务端设置,客户端用于显示警告)
|
||||
@GuiSync(722) public boolean networkEnergySufficient = true;
|
||||
|
||||
public boolean getAccelerateEnabled() {
|
||||
return this.accelerateEnabled;
|
||||
|
|
@ -41,6 +41,16 @@ public class EntitySpeedTickerMenu extends UpgradeableMenu<EntitySpeedTickerPart
|
|||
this.accelerateEnabled = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 Part 更新 networkEnergySufficient 的封装方法(由服务器调用)
|
||||
* 该方法会更新 @GuiSync 字段并广播变化到客户端
|
||||
*/
|
||||
public void setNetworkEnergySufficient(boolean sufficient) {
|
||||
this.networkEnergySufficient = sufficient;
|
||||
// 触发一次数据广播,使客户端立即接收到最新状态
|
||||
this.broadcastChanges();
|
||||
}
|
||||
|
||||
|
||||
// 构造方法,初始化菜单并与部件绑定
|
||||
public EntitySpeedTickerMenu(int id, Inventory ip, EntitySpeedTickerPart host) {
|
||||
|
|
@ -99,11 +109,11 @@ public class EntitySpeedTickerMenu extends UpgradeableMenu<EntitySpeedTickerPart
|
|||
this.effectiveSpeed = (int) PowerUtils.computeProductWithCapFromMenu(this, 8);
|
||||
}
|
||||
|
||||
// 从部件同步网络能量不足状态(防御性编程,避免 NPE)
|
||||
// 从部件同步网络能量充足状态:仅在服务器端从部件读取,客户端应使用由 @GuiSync 同步过来的值
|
||||
try {
|
||||
EntitySpeedTickerPart host = getHost();
|
||||
if (host != null) {
|
||||
this.networkEnergyInsufficient = host.isNetworkEnergyInsufficient();
|
||||
if (host != null && !isClientSide()) {
|
||||
this.networkEnergySufficient = host.isNetworkEnergySufficient();
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,13 +62,13 @@ public class EntitySpeedTickerPart extends UpgradeablePart implements IGridTicka
|
|||
public static final PartModel MODELS_ON;
|
||||
@PartModels
|
||||
public static final PartModel MODELS_HAS_CHANNEL;
|
||||
|
||||
|
||||
static {
|
||||
MODELS_OFF = new PartModel(MODEL_BASE, new ResourceLocation(ExtendedAEPlus.MODID, "part/entity_speed_ticker_off"));
|
||||
MODELS_ON = new PartModel(MODEL_BASE, new ResourceLocation(ExtendedAEPlus.MODID, "part/entity_speed_ticker_on"));
|
||||
MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, new ResourceLocation(ExtendedAEPlus.MODID, "part/entity_speed_ticker_has_channel"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构造函数,初始化部件并设置网络节点属性
|
||||
* @param partItem 部件物品
|
||||
|
|
@ -84,16 +84,15 @@ public class EntitySpeedTickerPart extends UpgradeablePart implements IGridTicka
|
|||
|
||||
// 控制是否启用加速(默认启用)
|
||||
private boolean accelerateEnabled = true;
|
||||
// 标记网络中是否能量不足(用于 GUI 提示)
|
||||
private boolean networkEnergyInsufficient = true;
|
||||
|
||||
// 标记网络中能量是否充足(用于 GUI 提示,默认充足)
|
||||
private boolean networkEnergySufficient = true;
|
||||
|
||||
public boolean getAccelerateEnabled() {
|
||||
return this.accelerateEnabled;
|
||||
}
|
||||
|
||||
public boolean isNetworkEnergyInsufficient() {
|
||||
return this.networkEnergyInsufficient;
|
||||
public boolean isNetworkEnergySufficient() {
|
||||
return this.networkEnergySufficient;
|
||||
}
|
||||
|
||||
public void setAccelerateEnabled(boolean accelerateEnabled) {
|
||||
|
|
@ -101,15 +100,16 @@ public class EntitySpeedTickerPart extends UpgradeablePart implements IGridTicka
|
|||
}
|
||||
|
||||
/**
|
||||
* 更新网络能量不足标记并在菜单存在且状态变化时触发同步
|
||||
* @param insufficient 是否能量不足
|
||||
* 更新网络能量充足标记并在菜单存在且状态变化时触发同步
|
||||
* @param sufficient 是否能量充足
|
||||
*/
|
||||
private void updateNetworkEnergyInsufficient(boolean insufficient) {
|
||||
if (this.networkEnergyInsufficient == insufficient) return;
|
||||
this.networkEnergyInsufficient = insufficient;
|
||||
private void updateNetworkEnergySufficient(boolean sufficient) {
|
||||
// 保持部件内部状态一致(部件为权威来源)
|
||||
this.networkEnergySufficient = sufficient;
|
||||
if (this.menu != null) {
|
||||
try {
|
||||
this.menu.broadcastChanges();
|
||||
// 使用菜单的封装方法更新并广播,以保持封装性
|
||||
this.menu.setNetworkEnergySufficient(sufficient);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
}
|
||||
|
|
@ -260,16 +260,17 @@ public class EntitySpeedTickerPart extends UpgradeablePart implements IGridTicka
|
|||
double simulated = getMainNode().getGrid().getEnergyService()
|
||||
.extractAEPower(requiredPower, Actionable.SIMULATE, PowerMultiplier.CONFIG);
|
||||
if (simulated < requiredPower) {
|
||||
updateNetworkEnergyInsufficient(false);
|
||||
updateNetworkEnergySufficient(false); // 能量不足
|
||||
return;
|
||||
}
|
||||
|
||||
double extractedPower = getMainNode().getGrid().getEnergyService()
|
||||
.extractAEPower(requiredPower, Actionable.MODULATE, PowerMultiplier.CONFIG);
|
||||
if (extractedPower < requiredPower) {
|
||||
updateNetworkEnergyInsufficient(false);
|
||||
updateNetworkEnergySufficient(false); // 能量不足
|
||||
return;
|
||||
}
|
||||
updateNetworkEnergySufficient(true); // 能量充足
|
||||
|
||||
// 计算加速倍数:基于 2 的次方,并把 8 张映射到最大 1024x(2^10)
|
||||
// 已由 product 计算得到 speed;上面已在没有卡时提前返回
|
||||
|
|
|
|||
|
|
@ -126,9 +126,10 @@ public class EntitySpeedTickerScreen<C extends EntitySpeedTickerMenu> extends Up
|
|||
double finalPower = PowerUtils.computeFinalPowerForProduct(effectiveSpeed, energyCardCount);
|
||||
double remainingRatio = PowerUtils.getRemainingRatio(energyCardCount);
|
||||
|
||||
// 如果网络能量不足,优先显示警告信息并在能量值处显示 0
|
||||
if (getMenu().networkEnergyInsufficient) {
|
||||
if (!getMenu().networkEnergySufficient) {
|
||||
setTextContent("enable", Component.translatable("screen.extendedae_plus.entity_speed_ticker.warning_network_energy_insufficient"));
|
||||
}else {
|
||||
setTextContent("enable", null);
|
||||
}
|
||||
setTextContent("speed", Component.translatable("screen.extendedae_plus.entity_speed_ticker.speed", effectiveSpeed));
|
||||
setTextContent("energy", Component.translatable("screen.extendedae_plus.entity_speed_ticker.energy", Platform.formatPower(finalPower, false)));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user