Skip to content

Commit d167e5e

Browse files
authored
Fixes for DataHolder & ItemStackSnapshot (#4182)
* fix DataHolder#getKeys * fix ItemStackSnapshot getKeys & getValues
1 parent 50b1c89 commit d167e5e

2 files changed

Lines changed: 6 additions & 9 deletions

File tree

src/main/java/org/spongepowered/common/data/holder/SpongeDataHolder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ default <E, V extends Value<E>> Optional<V> getValue(final Key<V> key) {
113113
default Set<Key<?>> getKeys() {
114114
return this.impl$delegateDataHolder().stream()
115115
.flatMap(dh -> this.impl$getAllProviders(dh).stream()
116-
.filter(provider -> provider.get(dh).isPresent()).map(DataProvider::key))
116+
.map(DataProvider::key))
117+
.filter(this::supports)
117118
.collect(ImmutableSet.toImmutableSet());
118119
}
119120

src/main/java/org/spongepowered/common/item/SpongeItemStackSnapshot.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public class SpongeItemStackSnapshot implements ItemStackSnapshot {
7373
private final int damageValue;
7474
private final ImmutableList<DataManipulator.Immutable> manipulators;
7575
private final transient ItemStack privateStack; // only for internal use since the processors have a huge say
76-
private final ImmutableSet<Key<?>> keys;
77-
private final ImmutableSet<org.spongepowered.api.data.value.Value.Immutable<?>> values;
76+
private final Set<Key<?>> keys;
77+
private final Set<org.spongepowered.api.data.value.Value.Immutable<?>> values;
7878
private final DataComponentPatch components;
7979
private @Nullable UUID creatorUniqueId;
8080

@@ -95,17 +95,13 @@ public SpongeItemStackSnapshot(final ItemStack itemStack) {
9595
this.itemType = itemStack.type();
9696
this.quantity = itemStack.quantity();
9797
final ImmutableList.Builder<DataManipulator.Immutable> builder = ImmutableList.builder();
98-
final ImmutableSet.Builder<Key<?>> keyBuilder = ImmutableSet.builder();
99-
final ImmutableSet.Builder<org.spongepowered.api.data.value.Value.Immutable<?>> valueBuilder = ImmutableSet.builder();
10098
final DataManipulator.Mutable customData = ((SpongeDataHolderBridge) itemStack).bridge$getManipulator();
10199
builder.add(customData.asImmutable());
102-
keyBuilder.addAll(customData.getKeys());
103-
valueBuilder.addAll(customData.getValues());
104100
this.damageValue = ItemStackUtil.toNative(itemStack).getDamageValue();
105101
this.manipulators = builder.build();
106102
this.privateStack = itemStack.copy();
107-
this.keys = keyBuilder.build();
108-
this.values = valueBuilder.build();
103+
this.keys = itemStack.getKeys();
104+
this.values = itemStack.getValues();
109105
this.components = ItemStackUtil.toNative(this.privateStack).getComponentsPatch();
110106
}
111107

0 commit comments

Comments
 (0)