Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
ae2f2f3b99
|
|
@ -21,12 +21,13 @@ import net.minecraftforge.registries.ForgeRegistries;
|
|||
*/
|
||||
public class EntitySpeedTickerMenu extends UpgradeableMenu<EntitySpeedTickerPart> {
|
||||
@GuiSync(716) public boolean accelerateEnabled = true; // 是否启用加速
|
||||
@GuiSync(717) public int entitySpeedCardCount; // 已安装的实体加速卡数量
|
||||
@GuiSync(718) public int energyCardCount; // 已安装的能量卡数量
|
||||
@GuiSync(719) public int effectiveSpeed = 1; // 当前生效的加速倍率
|
||||
@GuiSync(720) public double multiplier = 1.0; // 目标方块的配置倍率
|
||||
@GuiSync(721) public boolean targetBlacklisted = false; // 目标方块是否在黑名单中
|
||||
@GuiSync(722) public boolean networkEnergySufficient = true; // 网络能量是否充足
|
||||
@GuiSync(717) public boolean redstoneControlEnabled = false; // 是否启用红石控制
|
||||
@GuiSync(718) public int entitySpeedCardCount; // 已安装的实体加速卡数量
|
||||
@GuiSync(719) public int energyCardCount; // 已安装的能量卡数量
|
||||
@GuiSync(720) public int effectiveSpeed = 1; // 当前生效的加速倍率
|
||||
@GuiSync(721) public double multiplier = 1.0; // 目标方块的配置倍率
|
||||
@GuiSync(722) public boolean targetBlacklisted = false; // 目标方块是否在黑名单中
|
||||
@GuiSync(723) public boolean networkEnergySufficient = true; // 网络能量是否充足
|
||||
|
||||
/**
|
||||
* 构造函数,初始化菜单并绑定部件。
|
||||
|
|
@ -39,6 +40,7 @@ public class EntitySpeedTickerMenu extends UpgradeableMenu<EntitySpeedTickerPart
|
|||
if (host != null) {
|
||||
host.menu = this; // 绑定菜单到部件
|
||||
this.accelerateEnabled = host.getAccelerateEnabled(); // 同步初始开关状态
|
||||
this.redstoneControlEnabled = host.getRedstoneControlEnabled(); // 同步红石控制状态
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -49,6 +51,10 @@ public class EntitySpeedTickerMenu extends UpgradeableMenu<EntitySpeedTickerPart
|
|||
public boolean getAccelerateEnabled() {
|
||||
return this.accelerateEnabled;
|
||||
}
|
||||
|
||||
public boolean getRedstoneControlEnabled() {
|
||||
return this.redstoneControlEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置加速开关状态,并同步到部件。
|
||||
|
|
@ -61,6 +67,14 @@ public class EntitySpeedTickerMenu extends UpgradeableMenu<EntitySpeedTickerPart
|
|||
}
|
||||
broadcastChanges(); // 广播状态变化
|
||||
}
|
||||
|
||||
public void setRedstoneControlEnabled(boolean enabled) {
|
||||
this.redstoneControlEnabled = enabled;
|
||||
if (getHost() != null) {
|
||||
getHost().setRedstoneControlEnabled(enabled); // 同步到部件
|
||||
}
|
||||
broadcastChanges(); // 广播状态变化
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新网络能量充足状态并广播到客户端。
|
||||
|
|
@ -81,6 +95,9 @@ public class EntitySpeedTickerMenu extends UpgradeableMenu<EntitySpeedTickerPart
|
|||
updateTargetStatus(); // 更新目标方块的黑名单和倍率
|
||||
updateEffectiveSpeed(); // 计算生效速度
|
||||
updateNetworkEnergyStatus(); // 同步能量状态
|
||||
if (!isClientSide() && getHost() != null) {
|
||||
this.redstoneControlEnabled = getHost().getRedstoneControlEnabled(); // 同步红石控制状态
|
||||
}
|
||||
if (isClientSide()) {
|
||||
refreshClientGui(); // 客户端刷新界面
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import appeng.parts.PartModel;
|
|||
import appeng.parts.automation.UpgradeablePart;
|
||||
import com.extendedae_plus.ExtendedAEPlus;
|
||||
import com.extendedae_plus.ae.menu.EntitySpeedTickerMenu;
|
||||
import com.extendedae_plus.api.config.Settings;
|
||||
import com.extendedae_plus.config.ModConfig;
|
||||
import com.extendedae_plus.init.ModItems;
|
||||
import com.extendedae_plus.init.ModMenuTypes;
|
||||
|
|
@ -38,6 +39,7 @@ import net.minecraft.world.MenuProvider;
|
|||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
|
|
@ -66,6 +68,8 @@ public class EntitySpeedTickerPart extends UpgradeablePart implements IGridTicka
|
|||
|
||||
private static volatile MethodHandle cachedFEExtractHandle;
|
||||
private static volatile boolean FE_UNAVAILABLE;
|
||||
// 红石信号状态
|
||||
private YesNo redstoneState = YesNo.UNDECIDED;
|
||||
|
||||
// 静态块:初始化缓存
|
||||
static {
|
||||
|
|
@ -103,13 +107,22 @@ public class EntitySpeedTickerPart extends UpgradeablePart implements IGridTicka
|
|||
|
||||
// 注册可记忆的配置(YES/NO)
|
||||
this.getConfigManager().registerSetting(
|
||||
com.extendedae_plus.api.config.Settings.ACCELERATE,
|
||||
Settings.ACCELERATE,
|
||||
YesNo.YES
|
||||
);
|
||||
// 注册红石控制配置
|
||||
this.getConfigManager().registerSetting(
|
||||
Settings.REDSTONE_CONTROL,
|
||||
YesNo.NO
|
||||
);
|
||||
}
|
||||
|
||||
public boolean getAccelerateEnabled() {
|
||||
return this.getConfigManager().getSetting(com.extendedae_plus.api.config.Settings.ACCELERATE) == YesNo.YES;
|
||||
return this.getConfigManager().getSetting(Settings.ACCELERATE) == YesNo.YES;
|
||||
}
|
||||
|
||||
public boolean getRedstoneControlEnabled() {
|
||||
return this.getConfigManager().getSetting(Settings.REDSTONE_CONTROL) == YesNo.YES;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -118,11 +131,19 @@ public class EntitySpeedTickerPart extends UpgradeablePart implements IGridTicka
|
|||
* @param enabled 是否启用加速
|
||||
*/
|
||||
public void setAccelerateEnabled(boolean enabled) {
|
||||
this.getConfigManager().putSetting(com.extendedae_plus.api.config.Settings.ACCELERATE, enabled ? YesNo.YES : YesNo.NO);
|
||||
this.getConfigManager().putSetting(Settings.ACCELERATE, enabled ? YesNo.YES : YesNo.NO);
|
||||
if (menu != null) {
|
||||
menu.setAccelerateEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRedstoneControlEnabled(boolean enabled) {
|
||||
this.getConfigManager().putSetting(Settings.REDSTONE_CONTROL, enabled ? YesNo.YES : YesNo.NO);
|
||||
if (menu != null) {
|
||||
// 需要在EntitySpeedTickerMenu中添加对应的更新方法
|
||||
menu.broadcastChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getNetworkEnergySufficient() {
|
||||
return this.networkEnergySufficient;
|
||||
|
|
@ -208,6 +229,13 @@ public class EntitySpeedTickerPart extends UpgradeablePart implements IGridTicka
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged(BlockGetter level, BlockPos pos, BlockPos neighbor) {
|
||||
super.onNeighborChanged(level, pos, neighbor);
|
||||
// 当邻居方块变化时,更新红石状态
|
||||
updateRedstoneState();
|
||||
}
|
||||
|
||||
/**
|
||||
* 网络定时回调,处理目标方块实体的加速。
|
||||
*
|
||||
|
|
@ -220,6 +248,13 @@ public class EntitySpeedTickerPart extends UpgradeablePart implements IGridTicka
|
|||
if (!getAccelerateEnabled()) {
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
// 检查红石控制
|
||||
if (getRedstoneControlEnabled() && !getRedstoneState()) {
|
||||
// 如果启用了红石控制且没有红石信号,则不执行加速
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
updateCachedTarget();
|
||||
if (cachedTarget != null && isActive()) {
|
||||
ticker(cachedTarget);
|
||||
|
|
@ -455,4 +490,21 @@ public class EntitySpeedTickerPart extends UpgradeablePart implements IGridTicka
|
|||
cachedTarget = null;
|
||||
cachedTargetPos = null;
|
||||
}
|
||||
|
||||
// 获取红石信号状态
|
||||
private boolean getRedstoneState() {
|
||||
// 每次调用都更新红石状态,确保及时性
|
||||
updateRedstoneState();
|
||||
return redstoneState == YesNo.YES;
|
||||
}
|
||||
|
||||
// 更新红石信号状态
|
||||
private void updateRedstoneState() {
|
||||
var be = this.getHost().getBlockEntity();
|
||||
if (be != null && be.getLevel() != null) {
|
||||
redstoneState = be.getLevel().hasNeighborSignal(be.getBlockPos())
|
||||
? YesNo.YES
|
||||
: YesNo.NO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -24,7 +24,9 @@ import java.util.Map;
|
|||
*/
|
||||
public class EntitySpeedTickerScreen<C extends EntitySpeedTickerMenu> extends UpgradeableScreen<C> {
|
||||
private boolean eap$entitySpeedTickerEnabled = false; // 本地缓存的加速开关状态
|
||||
private boolean eap$redstoneControlEnabled = false; // 本地缓存的红石控制状态
|
||||
private final SettingToggleButton<YesNo> eap$entitySpeedTickerToggle; // 加速开关按钮
|
||||
private final SettingToggleButton<YesNo> eap$redstoneControlToggle; // 红石控制开关按钮
|
||||
|
||||
/**
|
||||
* 构造函数,初始化界面和控件。
|
||||
|
|
@ -37,13 +39,14 @@ public class EntitySpeedTickerScreen<C extends EntitySpeedTickerMenu> extends Up
|
|||
super((C) menu, playerInventory, title, style);
|
||||
this.addToLeftToolbar(CommonButtons.togglePowerUnit()); // 添加功率单位切换按钮
|
||||
this.eap$entitySpeedTickerEnabled = menu.getAccelerateEnabled();
|
||||
this.eap$redstoneControlEnabled = menu.getRedstoneControlEnabled();
|
||||
|
||||
// 初始化加速开关按钮
|
||||
eap$entitySpeedTickerToggle = new SettingToggleButton<>(
|
||||
Settings.BLOCKING_MODE,
|
||||
this.eap$entitySpeedTickerEnabled ? YesNo.YES : YesNo.NO,
|
||||
(btn, backwards) ->
|
||||
ModNetwork.CHANNEL.sendToServer(new ToggleEntityTickerC2SPacket())
|
||||
ModNetwork.CHANNEL.sendToServer(new ToggleEntityTickerC2SPacket(ToggleEntityTickerC2SPacket.Setting.accelerateEnabled))
|
||||
) {
|
||||
@Override
|
||||
public List<Component> getTooltipMessage() {
|
||||
|
|
@ -69,6 +72,30 @@ public class EntitySpeedTickerScreen<C extends EntitySpeedTickerMenu> extends Up
|
|||
};
|
||||
eap$entitySpeedTickerToggle.set(this.eap$entitySpeedTickerEnabled ? YesNo.YES : YesNo.NO);
|
||||
this.addToLeftToolbar(eap$entitySpeedTickerToggle);
|
||||
|
||||
// 初始化加速开关按钮
|
||||
eap$redstoneControlToggle = new SettingToggleButton<>(
|
||||
Settings.BLOCKING_MODE,
|
||||
this.eap$redstoneControlEnabled ? YesNo.YES : YesNo.NO,
|
||||
(btn, backwards) ->
|
||||
ModNetwork.CHANNEL.sendToServer(new ToggleEntityTickerC2SPacket(ToggleEntityTickerC2SPacket.Setting.redstoneControlEnabled))
|
||||
) {
|
||||
@Override
|
||||
public List<Component> getTooltipMessage() {
|
||||
boolean enabled = eap$redstoneControlEnabled;
|
||||
return List.of(
|
||||
Component.translatable("extendedae_plus.gui.redstone_control.title"),
|
||||
enabled ? Component.translatable("extendedae_plus.gui.redstone_control.enabled") :
|
||||
Component.translatable("extendedae_plus.gui.redstone_control.disabled") );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Icon getIcon() {
|
||||
return this.getCurrentValue() == YesNo.YES ? Icon.REDSTONE_LOW : Icon.REDSTONE_IGNORE;
|
||||
}
|
||||
};
|
||||
eap$redstoneControlToggle.set(this.eap$redstoneControlEnabled ? YesNo.YES : YesNo.NO);
|
||||
this.addToLeftToolbar(eap$redstoneControlToggle);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -83,6 +110,12 @@ public class EntitySpeedTickerScreen<C extends EntitySpeedTickerMenu> extends Up
|
|||
eap$entitySpeedTickerToggle.set(menu.targetBlacklisted ? YesNo.NO : (eap$entitySpeedTickerEnabled ? YesNo.YES : YesNo.NO));
|
||||
eap$entitySpeedTickerToggle.active = !menu.targetBlacklisted;
|
||||
}
|
||||
|
||||
if (eap$redstoneControlToggle != null && menu != null) {
|
||||
eap$redstoneControlEnabled = menu.getRedstoneControlEnabled();
|
||||
eap$redstoneControlToggle.set(eap$redstoneControlEnabled ? YesNo.YES : YesNo.NO);
|
||||
}
|
||||
|
||||
textData();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import java.util.Map;
|
|||
public final class Settings {
|
||||
private static final Map<String, Setting<?>> SETTINGS = new HashMap<>();
|
||||
public static final Setting<YesNo> ACCELERATE = register("accelerate", YesNo.NO, YesNo.YES);
|
||||
public static final Setting<YesNo> REDSTONE_CONTROL = register("redstoneControl", YesNo.NO, YesNo.YES);
|
||||
|
||||
|
||||
private Settings() {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ import appeng.api.storage.StorageHelper;
|
|||
import appeng.items.tools.powered.WirelessCraftingTerminalItem;
|
||||
import appeng.items.tools.powered.WirelessTerminalItem;
|
||||
import appeng.me.helpers.PlayerSource;
|
||||
import appeng.menu.locator.MenuLocators;
|
||||
import appeng.menu.me.crafting.CraftAmountMenu;
|
||||
import com.extendedae_plus.menu.locator.CuriosItemLocator;
|
||||
import com.extendedae_plus.util.wireless.WirelessTerminalLocator;
|
||||
import com.extendedae_plus.util.wireless.WirelessTerminalLocator.LocatedTerminal;
|
||||
import de.mari_023.ae2wtlib.terminal.WTMenuHost;
|
||||
|
|
@ -165,8 +168,32 @@ public class PickFromWirelessC2SPacket {
|
|||
}
|
||||
|
||||
long extracted = StorageHelper.poweredExtraction(energy, storage, targetKey, space, new PlayerSource(player));
|
||||
if (extracted <= 0) {
|
||||
return;
|
||||
// 1. 网络里为 0
|
||||
// 2. 主手当前是空的 OR 主手拿的不是这个物品
|
||||
// 3. 这个物品可以被 AE2 合成
|
||||
if (extracted == 0) {
|
||||
ItemStack mainHandItem = player.getMainHandItem();
|
||||
boolean handIsEmpty = mainHandItem.isEmpty();
|
||||
boolean handIsDifferentItem = !handIsEmpty && !AEItemKey.of(mainHandItem).equals(targetKey);
|
||||
|
||||
if (handIsEmpty || handIsDifferentItem) {
|
||||
var craftingService = grid.getCraftingService();
|
||||
if (craftingService.isCraftable(targetKey)) {
|
||||
// 主手为空一组
|
||||
if (curiosSlotId != null && curiosIndex >= 0) {
|
||||
CraftAmountMenu.open(player, new CuriosItemLocator(curiosSlotId, curiosIndex), targetKey, 64);
|
||||
} else {
|
||||
var hand = located.getHand();
|
||||
int slot = located.getSlotIndex();
|
||||
if (hand != null) {
|
||||
CraftAmountMenu.open(player, MenuLocators.forHand(player, hand), targetKey, 64);
|
||||
} else if (slot >= 0) {
|
||||
CraftAmountMenu.open(player, MenuLocators.forInventorySlot(slot), targetKey, 64);
|
||||
}
|
||||
}
|
||||
return; // 打开界面后直接结束,不执行后面的放物品逻辑
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (placeToMainHand) {
|
||||
|
|
|
|||
|
|
@ -9,37 +9,56 @@ import net.minecraftforge.network.NetworkEvent;
|
|||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* C2S: Toggle the accelerateEnabled flag on the EntitySpeedTickerPart bound to the open menu.
|
||||
* C2S: 切换 EntitySpeedTickerPart 的某个布尔配置项
|
||||
*/
|
||||
public class ToggleEntityTickerC2SPacket {
|
||||
public ToggleEntityTickerC2SPacket() {
|
||||
|
||||
private final Setting setting;
|
||||
|
||||
public ToggleEntityTickerC2SPacket(Setting setting) {
|
||||
this.setting = setting;
|
||||
}
|
||||
|
||||
public static void encode(ToggleEntityTickerC2SPacket msg, FriendlyByteBuf buf) {
|
||||
buf.writeEnum(msg.setting);
|
||||
}
|
||||
|
||||
public static ToggleEntityTickerC2SPacket decode(FriendlyByteBuf buf) {
|
||||
return new ToggleEntityTickerC2SPacket();
|
||||
return new ToggleEntityTickerC2SPacket(buf.readEnum(Setting.class));
|
||||
}
|
||||
|
||||
public static void handle(ToggleEntityTickerC2SPacket msg, Supplier<NetworkEvent.Context> ctxSupplier) {
|
||||
var ctx = ctxSupplier.get();
|
||||
NetworkEvent.Context ctx = ctxSupplier.get();
|
||||
ctx.enqueueWork(() -> {
|
||||
ServerPlayer player = ctx.getSender();
|
||||
if (player == null) return;
|
||||
|
||||
if (!(player.containerMenu instanceof EntitySpeedTickerMenu menu)) return;
|
||||
|
||||
EntitySpeedTickerPart part = menu.getHost();
|
||||
if (part == null) return;
|
||||
|
||||
// 切换部件上的状态,并把新状态同步到菜单字段,随后广播以通知客户端
|
||||
boolean current = part.getAccelerateEnabled();
|
||||
boolean next = !current;
|
||||
part.setAccelerateEnabled(next);
|
||||
// 确保菜单上的字段也被更新,这样 @GuiSync 会把状态发回客户端
|
||||
menu.setAccelerateEnabled(next);
|
||||
switch (msg.setting) {
|
||||
case accelerateEnabled -> {
|
||||
boolean newValue = !part.getAccelerateEnabled();
|
||||
part.setAccelerateEnabled(newValue);
|
||||
menu.setAccelerateEnabled(newValue);
|
||||
}
|
||||
case redstoneControlEnabled -> {
|
||||
boolean newValue = !part.getRedstoneControlEnabled();
|
||||
part.setRedstoneControlEnabled(newValue);
|
||||
menu.setRedstoneControlEnabled(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
// 统一广播,让所有打开界面的客户端同步最新状态
|
||||
menu.broadcastChanges();
|
||||
});
|
||||
ctx.setPacketHandled(true);
|
||||
}
|
||||
|
||||
public enum Setting {
|
||||
accelerateEnabled,
|
||||
redstoneControlEnabled
|
||||
}
|
||||
}
|
||||
|
|
@ -89,6 +89,9 @@
|
|||
"extendedae_plus.gui.entity_acceleration.blacklisted": "Target is blacklisted",
|
||||
"extendedae_plus.gui.entity_acceleration.enabled": "Accelerate target block entity ticks",
|
||||
"extendedae_plus.gui.entity_acceleration.disabled": "Do not accelerate target block entities",
|
||||
"extendedae_plus.gui.redstone_control.title": "Redstone Control",
|
||||
"extendedae_plus.gui.redstone_control.enabled": "Control acceleration with redstone signal",
|
||||
"extendedae_plus.gui.redstone_control.disabled": "Ignore redstone signals",
|
||||
|
||||
"extendedae_plus.screen.reload_mapping": "Reload Mapping",
|
||||
"extendedae_plus.screen.reload_mapping_success": "Overloading mapping successful",
|
||||
|
|
|
|||
|
|
@ -89,6 +89,9 @@
|
|||
"extendedae_plus.gui.entity_acceleration.blacklisted": "目标在黑名单中",
|
||||
"extendedae_plus.gui.entity_acceleration.enabled": "加速目标方块实体的tick",
|
||||
"extendedae_plus.gui.entity_acceleration.disabled": "不加速目标方块实体",
|
||||
"extendedae_plus.gui.redstone_control.title": "红石控制",
|
||||
"extendedae_plus.gui.redstone_control.enabled": "使用红石信号控制加速",
|
||||
"extendedae_plus.gui.redstone_control.disabled": "忽略红石信号",
|
||||
|
||||
"extendedae_plus.screen.reload_mapping": "重载映射",
|
||||
"extendedae_plus.screen.reload_mapping_success": "重载映射成功",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user