9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-25 01:49:30 +00:00

Merge pull request #303 from jhqwqmc/dev

refactor(core): 优化物品隐藏属性功能
This commit is contained in:
XiaoMoMi
2025-07-21 22:16:40 +08:00
committed by GitHub

View File

@@ -20,6 +20,17 @@ import java.util.stream.Stream;
public class HideTooltipModifier<I> implements ItemDataModifier<I> {
public static final Map<Key, Integer> TO_LEGACY;
public static final List<Key> COMPONENTS = List.of(
ComponentKeys.UNBREAKABLE,
ComponentKeys.ENCHANTMENTS,
ComponentKeys.STORED_ENCHANTMENTS,
ComponentKeys.CAN_PLACE_ON,
ComponentKeys.CAN_BREAK,
ComponentKeys.ATTRIBUTE_MODIFIERS,
ComponentKeys.DYED_COLOR,
ComponentKeys.TRIM,
ComponentKeys.JUKEBOX_PLAYABLE
);
static {
ImmutableMap.Builder<Key, Integer> builder = ImmutableMap.builder();
builder.put(ComponentKeys.ENCHANTMENTS, 1);
@@ -52,13 +63,24 @@ public class HideTooltipModifier<I> implements ItemDataModifier<I> {
if (components.isEmpty()) {
this.applier = new DummyApplier<>();
} else if (components.size() == 1) {
this.applier = new SemiModernApplier<>(components.getFirst());
if (COMPONENTS.contains(components.getFirst())) {
this.applier = new SemiModernApplier<>(components.getFirst());
} else {
this.applier = new DummyApplier<>();
}
} else {
List<Applier<I>> appliers = new ArrayList<>();
for (Key key : components) {
if (!COMPONENTS.contains(key)) continue;
appliers.add(new SemiModernApplier<>(key));
}
this.applier = new CompoundApplier<>(appliers);
if (appliers.isEmpty()) {
this.applier = new DummyApplier<>();
} else if (appliers.size() == 1) {
this.applier = appliers.getFirst();
} else {
this.applier = new CompoundApplier<>(appliers);
}
}
} else {
this.applier = new LegacyApplier<>(components);
@@ -134,10 +156,6 @@ public class HideTooltipModifier<I> implements ItemDataModifier<I> {
if (previous instanceof CompoundTag compoundTag) {
compoundTag.putBoolean("show_in_tooltip", false);
item.setNBTComponent(this.component, compoundTag);
} else {
CompoundTag compoundTag = new CompoundTag();
compoundTag.putBoolean("show_in_tooltip", false);
item.setNBTComponent(this.component, compoundTag);
}
}
}