Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.titanjc.titancraft.blocks;
- import com.titanjc.titancraft.Constants;
- import com.titanjc.titancraft.TitCMain;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockHorizontal;
- import net.minecraft.block.ITileEntityProvider;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.properties.IProperty;
- import net.minecraft.block.properties.PropertyBool;
- import net.minecraft.block.properties.PropertyEnum;
- import net.minecraft.block.properties.PropertyInteger;
- import net.minecraft.block.state.BlockStateContainer;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- /**
- * Created by Student on 1/26/2017.
- */
- public class BlockShelf extends BlockHorizontal implements ITileEntityProvider {
- private Boolean left;
- private Boolean center;
- private Boolean right;
- private Boolean lonely;
- private static final PropertyInteger CONNECTION = PropertyInteger.create("connections", 1, 4);
- private enum Connections{
- LEFT(1),
- RIGHT(2),
- CENTER(3),
- LONELY(4);
- private final int setting;
- Connections(int setting) {
- this.setting = setting;
- }
- public int getSetting() {
- return setting;
- }
- }
- public BlockShelf() {
- super(Material.WOOD);
- setUnlocalizedName(Constants.TitanCraftBlocks.SHELF.getUnlocalizedName());
- setRegistryName(Constants.TitanCraftBlocks.SHELF.getRegistryName());
- setCreativeTab(TitCMain.CREATIVE_TAB);
- setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.WEST).withProperty(CONNECTION, Connections.LONELY.getSetting()));
- left = right = center = lonely = false;
- }
- @Override
- public TileEntity createNewTileEntity(World worldIn, int meta) {
- return null;
- }
- @Override
- public boolean isFullCube(IBlockState state) {
- return false;
- }
- @Override
- public boolean isOpaqueCube(IBlockState state) {
- return false;
- }
- private boolean canConnectTo(IBlockAccess worldIn, BlockPos pos) {
- IBlockState iblockstate = worldIn.getBlockState(pos);
- Block block = iblockstate.getBlock();
- return (block instanceof BlockShelf);
- }
- @Override
- public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
- IBlockState state = super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer);
- return state.withProperty(FACING, placer.getHorizontalFacing());
- }
- @Override
- public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
- switch(state.getValue(FACING)) {
- case NORTH:
- left = canConnectTo(worldIn, pos.west());
- right = canConnectTo(worldIn, pos.east());
- break;
- case EAST:
- left = canConnectTo(worldIn, pos.north());
- right = canConnectTo(worldIn, pos.south());
- break;
- case WEST:
- left = canConnectTo(worldIn, pos.south());
- right = canConnectTo(worldIn, pos.north());
- break;
- case SOUTH:
- left = canConnectTo(worldIn, pos.east());
- right = canConnectTo(worldIn, pos.west());
- break;
- }
- center = (left && right);
- if(!center && !left && !right)
- return state.withProperty(CONNECTION, Connections.LONELY.getSetting()).withProperty(FACING, EnumFacing.getHorizontal(getMetaFromState(state)));
- if(center)
- return state.withProperty(CONNECTION, Connections.CENTER.getSetting()).withProperty(FACING, EnumFacing.getHorizontal(getMetaFromState(state)));
- if(left)
- return state.withProperty(CONNECTION, Connections.LEFT.getSetting()).withProperty(FACING, EnumFacing.getHorizontal(getMetaFromState(state)));
- else
- return state.withProperty(CONNECTION, Connections.RIGHT.getSetting()).withProperty(FACING, EnumFacing.getHorizontal(getMetaFromState(state)));
- }
- @Override
- public int getMetaFromState(IBlockState state) {
- return state.getValue(FACING).getHorizontalIndex();
- }
- @Override
- public IBlockState getStateFromMeta(int meta) {
- return getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
- }
- @Override
- protected BlockStateContainer createBlockState() {
- return new BlockStateContainer(this, FACING, CONNECTION);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment