Search in sources :

Example 1 with ImmutableTreeData

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

the class MixinBlockLeaves method getStateWithData.

@Override
public Optional<BlockState> getStateWithData(IBlockState blockState, ImmutableDataManipulator<?, ?> manipulator) {
    if (manipulator instanceof ImmutableTreeData) {
        final TreeType treeType = ((ImmutableTreeData) manipulator).type().get();
        final BlockPlanks.EnumType type = TreeTypeResolver.getFor(treeType);
        if (blockState.getBlock() instanceof BlockOldLeaf) {
            if (treeType.equals(TreeTypes.OAK) || treeType.equals(TreeTypes.BIRCH) || treeType.equals(TreeTypes.SPRUCE) || treeType.equals(TreeTypes.JUNGLE)) {
                return Optional.of((BlockState) blockState.withProperty(BlockOldLeaf.VARIANT, type));
            }
        } else if (blockState.getBlock() instanceof BlockNewLeaf) {
            if (treeType.equals(TreeTypes.ACACIA) || treeType.equals(TreeTypes.DARK_OAK)) {
                return Optional.of((BlockState) blockState.withProperty(BlockNewLeaf.VARIANT, type));
            }
        }
        return Optional.empty();
    }
    if (manipulator instanceof ImmutableDecayableData) {
        final boolean decayable = ((ImmutableDecayableData) manipulator).decayable().get();
        return Optional.of((BlockState) blockState.withProperty(BlockLeaves.DECAYABLE, decayable));
    }
    return super.getStateWithData(blockState, manipulator);
}
Also used : TreeType(org.spongepowered.api.data.type.TreeType) BlockState(org.spongepowered.api.block.BlockState) IBlockState(net.minecraft.block.state.IBlockState) BlockNewLeaf(net.minecraft.block.BlockNewLeaf) ImmutableDecayableData(org.spongepowered.api.data.manipulator.immutable.block.ImmutableDecayableData) ImmutableTreeData(org.spongepowered.api.data.manipulator.immutable.block.ImmutableTreeData) BlockOldLeaf(net.minecraft.block.BlockOldLeaf) BlockPlanks(net.minecraft.block.BlockPlanks)

Example 2 with ImmutableTreeData

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

the class MixinBlockLog method getStateWithData.

@Override
public Optional<BlockState> getStateWithData(IBlockState blockState, ImmutableDataManipulator<?, ?> manipulator) {
    if (manipulator instanceof ImmutableTreeData) {
        final TreeType treeType = ((ImmutableTreeData) manipulator).type().get();
        final BlockPlanks.EnumType type = TreeTypeResolver.getFor(treeType);
        return processLogType(blockState, type, treeType);
    } else if (manipulator instanceof ImmutableLogAxisData) {
        final LogAxis logAxis = ((ImmutableLogAxisData) manipulator).type().get();
        return Optional.of((BlockState) blockState.withProperty(BlockLog.LOG_AXIS, (BlockLog.EnumAxis) (Object) logAxis));
    }
    return super.getStateWithData(blockState, manipulator);
}
Also used : TreeType(org.spongepowered.api.data.type.TreeType) BlockState(org.spongepowered.api.block.BlockState) IBlockState(net.minecraft.block.state.IBlockState) ImmutableTreeData(org.spongepowered.api.data.manipulator.immutable.block.ImmutableTreeData) LogAxis(org.spongepowered.api.data.type.LogAxis) ImmutableLogAxisData(org.spongepowered.api.data.manipulator.immutable.block.ImmutableLogAxisData) BlockPlanks(net.minecraft.block.BlockPlanks)

Aggregations

BlockPlanks (net.minecraft.block.BlockPlanks)2 IBlockState (net.minecraft.block.state.IBlockState)2 BlockState (org.spongepowered.api.block.BlockState)2 ImmutableTreeData (org.spongepowered.api.data.manipulator.immutable.block.ImmutableTreeData)2 TreeType (org.spongepowered.api.data.type.TreeType)2 BlockNewLeaf (net.minecraft.block.BlockNewLeaf)1 BlockOldLeaf (net.minecraft.block.BlockOldLeaf)1 ImmutableDecayableData (org.spongepowered.api.data.manipulator.immutable.block.ImmutableDecayableData)1 ImmutableLogAxisData (org.spongepowered.api.data.manipulator.immutable.block.ImmutableLogAxisData)1 LogAxis (org.spongepowered.api.data.type.LogAxis)1