Skip to content

Commit

Permalink
Add missing data conversion for BlockStateKeys (#3864)
Browse files Browse the repository at this point in the history
* Add missing data conversion for BlockStateKeys

* Update src/main/java/org/spongepowered/common/data/provider/block/state/BlockStateDataProvider.java

Co-authored-by: Joni Aromaa <me@joniaromaa.fi>

---------

Co-authored-by: Joni Aromaa <me@joniaromaa.fi>
  • Loading branch information
Lignium and aromaa committed Jun 12, 2023
1 parent c2e5344 commit 995deec
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.spongepowered.api.data.BlockStateKeys;
import org.spongepowered.api.data.Key;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.state.StateProperty;
import org.spongepowered.common.data.provider.DataProviderRegistrator;

public final class BlockStateDataProvider {
Expand Down Expand Up @@ -134,13 +135,13 @@ public static void register(final DataProviderRegistrator registrator) {
}

// @formatter:off
private static <T, V extends Comparable<V>> void registerProperty(final DataProviderRegistrator registrator, final Key<Value<T>> key, final Property<V> property) {
private static <T extends Comparable<T>, V extends Comparable<V>> void registerProperty(final DataProviderRegistrator registrator, final Key<Value<T>> key, final Property<V> property) {

registrator.asImmutable(BlockState.class)
.create(key)
.supports(bs -> bs.getOptionalValue(property).isPresent())
.get(bs -> (T) bs.getOptionalValue(property).orElse(null))
.set((bs, v) -> bs.setValue(property, (V) v));
.get(bs -> ((org.spongepowered.api.block.BlockState) bs).stateProperty((StateProperty<T>) property).orElse(null))
.set((bs, v) -> (BlockState) ((org.spongepowered.api.block.BlockState) bs).withStateProperty((StateProperty<T>) property, v).orElse((org.spongepowered.api.block.BlockState) bs));
}
// @formatter:on

Expand Down

0 comments on commit 995deec

Please sign in to comment.