Better immutability checks

This commit is contained in:
onebeastchris 2024-12-02 02:48:54 +08:00
parent a9577a946e
commit 77ffb6098e

View file

@ -63,7 +63,7 @@ public class Item {
protected final Key javaIdentifier; protected final Key javaIdentifier;
private int javaId = -1; private int javaId = -1;
private final int attackDamage; private final int attackDamage;
private final DataComponents baseComponents; private final DataComponents baseComponents; // unmodifiable
private final List<Item> enchantmentGlintPresent = List.of(Items.ENCHANTED_GOLDEN_APPLE, Items.EXPERIENCE_BOTTLE, Items.WRITTEN_BOOK, private final List<Item> enchantmentGlintPresent = List.of(Items.ENCHANTED_GOLDEN_APPLE, Items.EXPERIENCE_BOTTLE, Items.WRITTEN_BOOK,
Items.NETHER_STAR, Items.ENCHANTED_BOOK, Items.END_CRYSTAL); Items.NETHER_STAR, Items.ENCHANTED_BOOK, Items.END_CRYSTAL);
@ -104,10 +104,11 @@ public class Item {
*/ */
@NonNull @NonNull
public DataComponents gatherComponents(DataComponents others) { public DataComponents gatherComponents(DataComponents others) {
DataComponents components = baseComponents.clone();
if (others == null) { if (others == null) {
return new DataComponents(ImmutableMap.copyOf(components.getDataComponents())); return baseComponents;
} }
DataComponents components = baseComponents.clone();
components.getDataComponents().putAll(others.getDataComponents()); components.getDataComponents().putAll(others.getDataComponents());
return new DataComponents(ImmutableMap.copyOf(components.getDataComponents())); return new DataComponents(ImmutableMap.copyOf(components.getDataComponents()));
} }
@ -315,7 +316,7 @@ public class Item {
} }
public DataComponents components() { public DataComponents components() {
return this.components; return new DataComponents(ImmutableMap.copyOf(components.getDataComponents()));
} }
private Builder() { private Builder() {