Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package NewDivide.NDMiscMod.blocks;
- import net.minecraft.block.Block;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.properties.IProperty;
- import net.minecraft.block.properties.PropertyBool;
- import net.minecraft.block.state.BlockState;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.util.BlockPos;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.EnumWorldBlockLayer;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- public class ItemBlockXray extends Block {
- public static final PropertyBool NORTH = PropertyBool.create("north");
- public static final PropertyBool EAST = PropertyBool.create("east");
- public static final PropertyBool SOUTH = PropertyBool.create("south");
- public static final PropertyBool WEST = PropertyBool.create("west");
- public static final PropertyBool UP = PropertyBool.create("up");
- public static final PropertyBool DOWN = PropertyBool.create("down");
- public ItemBlockXray(Material materialIn) {
- super(materialIn);
- this.setState(false, false, false, false, false, false);
- }
- @Override
- public boolean isOpaqueCube() {
- return true;
- }
- @SideOnly(Side.CLIENT)
- public EnumWorldBlockLayer getBlockLayer() {
- return EnumWorldBlockLayer.CUTOUT;
- }
- @Override
- public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) {
- state = getActualState(state, worldIn, pos);
- }
- @Override
- public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
- state = getActualState(state, worldIn, pos);
- }
- @Override
- public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
- IBlockState nextState = state;
- nextState.withProperty(NORTH, canConnectTo(worldIn, pos, EnumFacing.NORTH));
- nextState.withProperty(EAST, canConnectTo(worldIn, pos, EnumFacing.EAST));
- nextState.withProperty(SOUTH, canConnectTo(worldIn, pos, EnumFacing.SOUTH));
- nextState.withProperty(WEST, canConnectTo(worldIn, pos, EnumFacing.WEST));
- nextState.withProperty(UP, canConnectTo(worldIn, pos, EnumFacing.UP));
- nextState.withProperty(DOWN, canConnectTo(worldIn, pos, EnumFacing.DOWN));
- return nextState;
- }
- @Override
- public int getMetaFromState(IBlockState state) {
- int meta = 0;
- if ((Boolean) state.getProperties().get(NORTH))
- meta += 32;
- if ((Boolean) state.getProperties().get(EAST))
- meta += 16;
- if ((Boolean) state.getProperties().get(SOUTH))
- meta += 8;
- if ((Boolean) state.getProperties().get(WEST))
- meta += 4;
- if ((Boolean) state.getProperties().get(UP))
- meta += 2;
- if ((Boolean) state.getProperties().get(DOWN))
- meta += 1;
- return meta;
- }
- @Override
- public IBlockState getStateFromMeta(int meta) {
- return this.getDefaultState()
- .withProperty(NORTH, ((meta - 0) / 32 == 1))
- .withProperty(EAST, ((meta - 32) / 16 == 1))
- .withProperty(SOUTH, ((meta - 48) / 8 == 1))
- .withProperty(WEST, ((meta - 56) / 4 == 1))
- .withProperty(UP, ((meta - 60) / 2 == 1))
- .withProperty(DOWN, ((meta - 62) / 1 == 1));
- }
- public void setState(boolean n, boolean e, boolean s, boolean w, boolean u, boolean d) {
- this.blockState.getBaseState().withProperty(NORTH, n);
- this.blockState.getBaseState().withProperty(EAST, e);
- this.blockState.getBaseState().withProperty(SOUTH, s);
- this.blockState.getBaseState().withProperty(WEST, w);
- this.blockState.getBaseState().withProperty(UP, u);
- this.blockState.getBaseState().withProperty(DOWN, d);
- }
- public boolean canConnectTo(IBlockAccess world, BlockPos pos, EnumFacing dir) {
- return this == world.getBlockState(pos.offset(dir)).getBlock();
- }
- protected BlockState createBlockState() {
- return new BlockState(this, new IProperty[] { NORTH, EAST, SOUTH, WEST, UP, DOWN });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment