Skip to content

Commit

Permalink
Better immutability checks
Browse files Browse the repository at this point in the history
  • Loading branch information
onebeastchris committed Dec 1, 2024
1 parent a9577a9 commit 77ffb60
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions core/src/main/java/org/geysermc/geyser/item/type/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class Item {
protected final Key javaIdentifier;
private int javaId = -1;
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,
Items.NETHER_STAR, Items.ENCHANTED_BOOK, Items.END_CRYSTAL);
Expand Down Expand Up @@ -104,10 +104,11 @@ public Rarity defaultRarity() {
*/
@NonNull
public DataComponents gatherComponents(DataComponents others) {
DataComponents components = baseComponents.clone();
if (others == null) {
return new DataComponents(ImmutableMap.copyOf(components.getDataComponents()));
return baseComponents;
}

DataComponents components = baseComponents.clone();
components.getDataComponents().putAll(others.getDataComponents());
return new DataComponents(ImmutableMap.copyOf(components.getDataComponents()));
}
Expand Down Expand Up @@ -315,7 +316,7 @@ public Builder components(DataComponents components) {
}

public DataComponents components() {
return this.components;
return new DataComponents(ImmutableMap.copyOf(components.getDataComponents()));
}

private Builder() {
Expand Down

0 comments on commit 77ffb60

Please # to comment.