Search in sources :

Example 1 with BlockOldLeaf

use of net.minecraft.block.BlockOldLeaf 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 BlockOldLeaf

use of net.minecraft.block.BlockOldLeaf in project SpongeCommon by SpongePowered.

the class MixinBlockLeaves method getTreeData.

protected ImmutableTreeData getTreeData(IBlockState blockState) {
    BlockPlanks.EnumType type;
    if (blockState.getBlock() instanceof BlockOldLeaf) {
        type = blockState.getValue(BlockOldLeaf.VARIANT);
    } else if (blockState.getBlock() instanceof BlockNewLeaf) {
        type = blockState.getValue(BlockNewLeaf.VARIANT);
    } else {
        type = BlockPlanks.EnumType.OAK;
    }
    final TreeType treeType = TreeTypeResolver.getFor(type);
    return ImmutableDataCachingUtil.getManipulator(ImmutableSpongeTreeData.class, treeType);
}
Also used : TreeType(org.spongepowered.api.data.type.TreeType) BlockNewLeaf(net.minecraft.block.BlockNewLeaf) BlockOldLeaf(net.minecraft.block.BlockOldLeaf) BlockPlanks(net.minecraft.block.BlockPlanks)

Example 3 with BlockOldLeaf

use of net.minecraft.block.BlockOldLeaf in project SpongeCommon by SpongePowered.

the class MixinBlockLeaves method getStateWithValue.

@Override
public <E> Optional<BlockState> getStateWithValue(IBlockState blockState, Key<? extends BaseValue<E>> key, E value) {
    if (key.equals(Keys.TREE_TYPE)) {
        final TreeType treeType = (TreeType) value;
        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 (key.equals(Keys.DECAYABLE)) {
        final boolean decayable = (Boolean) value;
        return Optional.of((BlockState) blockState.withProperty(BlockLeaves.DECAYABLE, decayable));
    }
    return super.getStateWithValue(blockState, key, value);
}
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) BlockOldLeaf(net.minecraft.block.BlockOldLeaf) BlockPlanks(net.minecraft.block.BlockPlanks)

Aggregations

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