3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 08:30:12 +01:00

Better immutability checks

Dieser Commit ist enthalten in:
onebeastchris 2024-12-02 02:48:54 +08:00
Ursprung a9577a946e
Commit 77ffb6098e

Datei anzeigen

@ -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() {