mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-12-22 22:45:04 +01:00
Better immutability checks
This commit is contained in:
parent
a9577a946e
commit
77ffb6098e
1 changed files with 5 additions and 4 deletions
|
@ -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() {
|
||||||
|
|
Loading…
Reference in a new issue