材质&调整标签大小写敏感

This commit is contained in:
GaLicn 2025-12-12 09:57:31 +08:00
parent 84cfc1ccb2
commit 56b82e0e8e
10 changed files with 42 additions and 25 deletions

View File

@ -55,11 +55,11 @@ public class LabelNetworkRegistry extends SavedData {
} }
/** /**
* 规范化标签trim + toLowerCase * 规范化标签trim保持大小写敏感
*/ */
public static String normalizeLabel(String raw) { public static String normalizeLabel(String raw) {
if (raw == null) return null; if (raw == null) return null;
String t = raw.trim().toLowerCase(Locale.ROOT); String t = raw.trim();
if (t.isEmpty()) return null; if (t.isEmpty()) return null;
if (t.length() > 64) { if (t.length() > 64) {
t = t.substring(0, 64); t = t.substring(0, 64);

View File

@ -266,13 +266,13 @@ public class LabeledWirelessTransceiverScreen extends AbstractContainerScreen<La
private void applyFilter() { private void applyFilter() {
String prevSelected = lastSelectedLabel; String prevSelected = lastSelectedLabel;
String q = searchBox.getValue() == null ? "" : searchBox.getValue().trim().toLowerCase(); String q = searchBox.getValue() == null ? "" : searchBox.getValue().trim();
filtered.clear(); filtered.clear();
if (q.isEmpty()) { if (q.isEmpty()) {
filtered.addAll(entries); filtered.addAll(entries);
} else { } else {
for (LabelEntry e : entries) { for (LabelEntry e : entries) {
if (e.label().toLowerCase().contains(q)) { if (e.label().contains(q)) {
filtered.add(e); filtered.add(e);
} }
} }

View File

@ -16,7 +16,7 @@ import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.NetworkHooks;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -26,11 +26,11 @@ import org.jetbrains.annotations.Nullable;
* 取消所有徒手/道具调节只允许右键打开后续 UI当前仅占位返回 SUCCESS * 取消所有徒手/道具调节只允许右键打开后续 UI当前仅占位返回 SUCCESS
*/ */
public class LabeledWirelessTransceiverBlock extends Block implements EntityBlock { public class LabeledWirelessTransceiverBlock extends Block implements EntityBlock {
public static final IntegerProperty STATE = IntegerProperty.create("state", 0, 5); public static final BooleanProperty STATE = BooleanProperty.create("state");
public LabeledWirelessTransceiverBlock(Properties props) { public LabeledWirelessTransceiverBlock(Properties props) {
super(props); super(props);
this.registerDefaultState(this.stateDefinition.any().setValue(STATE, 5)); this.registerDefaultState(this.stateDefinition.any().setValue(STATE, false));
} }
@Override @Override

View File

@ -223,28 +223,18 @@ public class LabeledWirelessTransceiverBlockEntity extends AEBaseBlockEntity imp
} }
IGridNode node = this.getGridNode(); IGridNode node = this.getGridNode();
int newState = 5; // 默认无连接 boolean online = false;
if (node != null && node.isActive()) { if (node != null && node.isActive()) {
int usedChannels = 0; try {
for (var connection : node.getConnections()) { var grid = node.getGrid();
usedChannels = Math.max(connection.getUsedChannels(), usedChannels); online = grid != null && grid.getEnergyService().isNetworkPowered();
} } catch (Throwable ignored) {
if (usedChannels >= 32) { online = false;
newState = 4;
} else if (usedChannels >= 24) {
newState = 3;
} else if (usedChannels >= 16) {
newState = 2;
} else if (usedChannels >= 8) {
newState = 1;
} else if (usedChannels >= 0) {
newState = 0;
} }
} }
if (currentState.getValue(LabeledWirelessTransceiverBlock.STATE) != newState) { if (currentState.getValue(LabeledWirelessTransceiverBlock.STATE) != online) {
this.level.setBlock(this.worldPosition, currentState.setValue(LabeledWirelessTransceiverBlock.STATE, newState), 3); this.level.setBlock(this.worldPosition, currentState.setValue(LabeledWirelessTransceiverBlock.STATE, online), 3);
} }
} }

View File

@ -0,0 +1,10 @@
{
"variants": {
"state=false": {
"model": "extendedae_plus:block/wirelesstransceiver/lable_wireless_transceiver_off"
},
"state=true": {
"model": "extendedae_plus:block/wirelesstransceiver/lable_wireless_transceiver_on"
}
}
}

View File

@ -0,0 +1,7 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "extendedae_plus:block/wireless_transceiver/lable_wireless_transceiver_off"
}
}

View File

@ -0,0 +1,7 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "extendedae_plus:block/wireless_transceiver/lable_wireless_transceiver_on"
}
}

View File

@ -0,0 +1,3 @@
{
"parent": "extendedae_plus:block/wirelesstransceiver/lable_wireless_transceiver_off"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 499 B