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()));
}
Aggregations