Search in sources :

Example 1 with MergeFunction

use of org.spongepowered.api.data.merge.MergeFunction in project SpongeCommon by SpongePowered.

the class MixinWorld_Data method offer.

@Override
public DataTransactionResult offer(int x, int y, int z, DataManipulator<?, ?> manipulator, MergeFunction function) {
    final BlockState blockState = getBlock(x, y, z).withExtendedProperties(new Location<>(this, x, y, z));
    final ImmutableDataManipulator<?, ?> immutableDataManipulator = manipulator.asImmutable();
    if (blockState.supports((Class) immutableDataManipulator.getClass())) {
        final List<ImmutableValue<?>> old = new ArrayList<>(blockState.getValues());
        final BlockState newState = blockState.with(immutableDataManipulator).get();
        old.removeAll(newState.getValues());
        setBlock(x, y, z, newState);
        return DataTransactionResult.successReplaceResult(old, manipulator.getValues());
    }
    return getTileEntity(x, y, z).map(tileEntity -> tileEntity.offer(manipulator, function)).orElseGet(() -> DataTransactionResult.failResult(manipulator.getValues()));
}
Also used : SpongeImpl(org.spongepowered.common.SpongeImpl) Value(org.spongepowered.api.data.value.mutable.Value) ImmutableDataManipulator(org.spongepowered.api.data.manipulator.ImmutableDataManipulator) ImmutableValue(org.spongepowered.api.data.value.immutable.ImmutableValue) DataTransactionResult(org.spongepowered.api.data.DataTransactionResult) PropertyStore(org.spongepowered.api.data.property.PropertyStore) Key(org.spongepowered.api.data.key.Key) ArrayList(java.util.ArrayList) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) ImmutableList(com.google.common.collect.ImmutableList) Mixin(org.spongepowered.asm.mixin.Mixin) MergeFunction(org.spongepowered.api.data.merge.MergeFunction) Location(org.spongepowered.api.world.Location) ImmutableSet(com.google.common.collect.ImmutableSet) DirectionFacingProvider(org.spongepowered.common.registry.provider.DirectionFacingProvider) Collection(java.util.Collection) BaseValue(org.spongepowered.api.data.value.BaseValue) EnumFacing(net.minecraft.util.EnumFacing) Sponge(org.spongepowered.api.Sponge) Set(java.util.Set) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException) DataHolder(org.spongepowered.api.data.DataHolder) BlockState(org.spongepowered.api.block.BlockState) Direction(org.spongepowered.api.util.Direction) List(java.util.List) DataView(org.spongepowered.api.data.DataView) World(org.spongepowered.api.world.World) Property(org.spongepowered.api.data.Property) DataManipulator(org.spongepowered.api.data.manipulator.DataManipulator) Optional(java.util.Optional) Collections(java.util.Collections) ImmutableValue(org.spongepowered.api.data.value.immutable.ImmutableValue) BlockState(org.spongepowered.api.block.BlockState) ArrayList(java.util.ArrayList)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 EnumFacing (net.minecraft.util.EnumFacing)1 Sponge (org.spongepowered.api.Sponge)1 BlockState (org.spongepowered.api.block.BlockState)1 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)1 DataHolder (org.spongepowered.api.data.DataHolder)1 DataTransactionResult (org.spongepowered.api.data.DataTransactionResult)1 DataView (org.spongepowered.api.data.DataView)1 Property (org.spongepowered.api.data.Property)1 Key (org.spongepowered.api.data.key.Key)1 DataManipulator (org.spongepowered.api.data.manipulator.DataManipulator)1 ImmutableDataManipulator (org.spongepowered.api.data.manipulator.ImmutableDataManipulator)1 MergeFunction (org.spongepowered.api.data.merge.MergeFunction)1