Search in sources :

Example 1 with ImmutableAxisData

use of org.spongepowered.api.data.manipulator.immutable.block.ImmutableAxisData in project SpongeCommon by SpongePowered.

the class MixinBlockLever method getStateWithData.

@Override
public Optional<BlockState> getStateWithData(IBlockState blockState, ImmutableDataManipulator<?, ?> manipulator) {
    if (manipulator instanceof ImmutablePoweredData) {
        return Optional.of((BlockState) blockState.withProperty(BlockLever.POWERED, ((ImmutablePoweredData) manipulator).powered().get()));
    }
    if (manipulator instanceof ImmutableDirectionalData) {
        final Direction dir = ((ImmutableDirectionalData) manipulator).direction().get();
        final Axis axis = this.getAxisFromOrientation(blockState.getValue(BlockLever.FACING));
        return Optional.of((BlockState) blockState.withProperty(BlockLever.FACING, DirectionResolver.getAsOrientation(dir, axis)));
    }
    if (manipulator instanceof ImmutableAxisData) {
        final Axis axis = ((ImmutableAxisData) manipulator).axis().get();
        final Direction dir = DirectionResolver.getFor(blockState.getValue(BlockLever.FACING));
        return Optional.of((BlockState) blockState.withProperty(BlockLever.FACING, DirectionResolver.getAsOrientation(dir, axis)));
    }
    return super.getStateWithData(blockState, manipulator);
}
Also used : ImmutablePoweredData(org.spongepowered.api.data.manipulator.immutable.block.ImmutablePoweredData) ImmutableAxisData(org.spongepowered.api.data.manipulator.immutable.block.ImmutableAxisData) Direction(org.spongepowered.api.util.Direction) ImmutableDirectionalData(org.spongepowered.api.data.manipulator.immutable.block.ImmutableDirectionalData) Axis(org.spongepowered.api.util.Axis)

Aggregations

ImmutableAxisData (org.spongepowered.api.data.manipulator.immutable.block.ImmutableAxisData)1 ImmutableDirectionalData (org.spongepowered.api.data.manipulator.immutable.block.ImmutableDirectionalData)1 ImmutablePoweredData (org.spongepowered.api.data.manipulator.immutable.block.ImmutablePoweredData)1 Axis (org.spongepowered.api.util.Axis)1 Direction (org.spongepowered.api.util.Direction)1