修修修
This commit is contained in:
parent
120264726e
commit
7138077cd1
|
|
@ -34,6 +34,10 @@ public final class InputEvents {
|
|||
hovered = JeiRuntimeProxy.getIngredientUnderMouse();
|
||||
}
|
||||
if (hovered.isPresent()) {
|
||||
// 若 JEI 作弊模式开启,则放行给 JEI 处理(Shift+左键=一组)
|
||||
if (JeiRuntimeProxy.isJeiCheatModeEnabled()) {
|
||||
return;
|
||||
}
|
||||
ITypedIngredient<?> typed = hovered.get();
|
||||
GenericStack stack = GenericEntryStackHelper.ingredientToStack(typed);
|
||||
if (stack != null) {
|
||||
|
|
@ -58,6 +62,10 @@ public final class InputEvents {
|
|||
if (hovered.isEmpty()) return;
|
||||
|
||||
ITypedIngredient<?> typed = hovered.get();
|
||||
// 若 JEI 作弊模式开启,则放行给 JEI 处理(中键=一组)
|
||||
if (JeiRuntimeProxy.isJeiCheatModeEnabled()) {
|
||||
return;
|
||||
}
|
||||
GenericStack stack = GenericEntryStackHelper.ingredientToStack(typed);
|
||||
if (stack == null) return;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
package com.extendedae_plus.content.wireless;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
|
|
@ -35,6 +34,11 @@ public class WirelessTransceiverBlock extends Block implements EntityBlock {
|
|||
if (!level.isClientSide && player.isShiftKeyDown()) {
|
||||
BlockEntity be = level.getBlockEntity(pos);
|
||||
if (be instanceof WirelessTransceiverBlockEntity te) {
|
||||
if (te.isLocked()) {
|
||||
player.displayClientMessage(Component.literal("收发器已锁定,无法修改频道"), true);
|
||||
super.attack(state, level, pos, player);
|
||||
return;
|
||||
}
|
||||
int step = 1;
|
||||
if (player.getMainHandItem().is(Items.REDSTONE_TORCH)) step = 10;
|
||||
if (player.getMainHandItem().is(Items.STICK)) step = 10;
|
||||
|
|
@ -57,6 +61,10 @@ public class WirelessTransceiverBlock extends Block implements EntityBlock {
|
|||
if (be instanceof WirelessTransceiverBlockEntity te) {
|
||||
boolean sneaking = player.isShiftKeyDown();
|
||||
if (sneaking) {
|
||||
if (te.isLocked()) {
|
||||
player.displayClientMessage(Component.literal("收发器已锁定,无法修改频道"), true);
|
||||
return InteractionResult.CONSUME;
|
||||
}
|
||||
// 频率调节:主手 +1(或 +10),副手 -1(或 -10)
|
||||
int step = 1;
|
||||
// 手持红石火把:加10;手持木棍:减10(仅改变步长,不改变加/减方向)
|
||||
|
|
@ -73,6 +81,10 @@ public class WirelessTransceiverBlock extends Block implements EntityBlock {
|
|||
te.setFrequency(f);
|
||||
player.displayClientMessage(Component.literal("频道:" + te.getFrequency()), true);
|
||||
} else {
|
||||
if (te.isLocked()) {
|
||||
player.displayClientMessage(Component.literal("收发器已锁定,无法切换模式"), true);
|
||||
return InteractionResult.CONSUME;
|
||||
}
|
||||
te.setMasterMode(!te.isMasterMode());
|
||||
player.displayClientMessage(Component.literal(te.isMasterMode() ? "模式:主端" : "模式:从端"), true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,9 @@ public class WirelessTransceiverBlockEntity extends BlockEntity implements IWire
|
|||
|
||||
private IManagedGridNode managedNode;
|
||||
|
||||
private long frequency = 0L;
|
||||
private boolean masterMode = true;
|
||||
private long frequency = 1L;
|
||||
private boolean masterMode = false;
|
||||
private boolean locked = false;
|
||||
|
||||
private WirelessMasterLink masterLink;
|
||||
private WirelessSlaveLink slaveLink;
|
||||
|
|
@ -86,6 +87,7 @@ public class WirelessTransceiverBlockEntity extends BlockEntity implements IWire
|
|||
}
|
||||
|
||||
public void setFrequency(long frequency) {
|
||||
if (this.locked) return;
|
||||
if (this.frequency == frequency) return;
|
||||
this.frequency = frequency;
|
||||
if (isMasterMode()) {
|
||||
|
|
@ -101,6 +103,7 @@ public class WirelessTransceiverBlockEntity extends BlockEntity implements IWire
|
|||
}
|
||||
|
||||
public void setMasterMode(boolean masterMode) {
|
||||
if (this.locked) return;
|
||||
if (this.masterMode == masterMode) return;
|
||||
// 切换前清理原模式状态
|
||||
if (this.masterMode) {
|
||||
|
|
@ -118,6 +121,16 @@ public class WirelessTransceiverBlockEntity extends BlockEntity implements IWire
|
|||
setChanged();
|
||||
}
|
||||
|
||||
public boolean isLocked() {
|
||||
return locked;
|
||||
}
|
||||
|
||||
public void setLocked(boolean locked) {
|
||||
if (this.locked == locked) return;
|
||||
this.locked = locked;
|
||||
setChanged();
|
||||
}
|
||||
|
||||
public void onRemoved() {
|
||||
if (this.masterMode) {
|
||||
masterLink.onUnloadOrRemove();
|
||||
|
|
@ -164,6 +177,7 @@ public class WirelessTransceiverBlockEntity extends BlockEntity implements IWire
|
|||
super.saveAdditional(tag);
|
||||
tag.putLong("frequency", frequency);
|
||||
tag.putBoolean("master", masterMode);
|
||||
tag.putBoolean("locked", locked);
|
||||
if (managedNode != null) {
|
||||
managedNode.saveToNBT(tag);
|
||||
}
|
||||
|
|
@ -174,6 +188,7 @@ public class WirelessTransceiverBlockEntity extends BlockEntity implements IWire
|
|||
super.load(tag);
|
||||
this.frequency = tag.getLong("frequency");
|
||||
this.masterMode = tag.getBoolean("master");
|
||||
this.locked = tag.getBoolean("locked");
|
||||
if (managedNode != null) {
|
||||
managedNode.loadFromNBT(tag);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,11 @@ public final class ModBlocks {
|
|||
|
||||
public static final RegistryObject<Block> WIRELESS_TRANSCEIVER = BLOCKS.register(
|
||||
"wireless_transceiver",
|
||||
() -> new WirelessTransceiverBlock(BlockBehaviour.Properties.of().mapColor(MapColor.METAL).strength(2.0F, 6.0F))
|
||||
() -> new WirelessTransceiverBlock(
|
||||
BlockBehaviour.Properties.of()
|
||||
.mapColor(MapColor.METAL)
|
||||
.strength(1.5F, 6.0F)
|
||||
.requiresCorrectToolForDrops()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,4 +61,17 @@ public final class JeiRuntimeProxy {
|
|||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测 JEI 是否开启了作弊模式(给物品)。
|
||||
* 使用 JEI 内部开关,若 JEI 未初始化或异常则返回 false。
|
||||
*/
|
||||
public static boolean isJeiCheatModeEnabled() {
|
||||
try {
|
||||
// 使用完全限定名以避免在源码缺失时的编译依赖问题
|
||||
return mezz.jei.common.Internal.getClientToggleState().isCheatItemsEnabled();
|
||||
} catch (Throwable t) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user