Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.toxic.blocks;
- import net.minecraft.block.Block;
- import net.minecraft.block.SoundType;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.properties.IProperty;
- import net.minecraft.block.properties.PropertyBool;
- import net.minecraft.block.state.BlockStateContainer;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.init.Blocks;
- import net.minecraft.util.EnumBlockRenderType;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.Mirror;
- import net.minecraft.util.math.AxisAlignedBB;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- public class BlockCable 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");
- protected static final AxisAlignedBB[] BOUNDING_BOXES = new AxisAlignedBB[] { /* PUT BOUNDING BOXES HERE */ };
- public BlockCable() {
- super(Material.IRON);
- this.setDefaultState(this.blockState.getBaseState().withProperty(NORTH, Boolean.valueOf(false)).withProperty(EAST, Boolean.valueOf(false)).withProperty(SOUTH, Boolean.valueOf(false)).withProperty(WEST, Boolean.valueOf(false)).withProperty(UP, Boolean.valueOf(false)).withProperty(DOWN, Boolean.valueOf(false)));
- }
- // public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
- // state = this.getActualState(state, source, pos);
- // return BOUNDING_BOXES[0];
- // }
- /**
- * Returns the correct index into boundingBoxes, based on what the fence is connected to.
- */
- private static int getBoundingBoxIdx(IBlockState state) {
- int i = 0;
- if (((Boolean) state.getValue(DOWN)).booleanValue()) {
- i |= 1 << EnumFacing.DOWN.getIndex();
- }
- if (((Boolean) state.getValue(UP)).booleanValue()) {
- i |= 1 << EnumFacing.UP.getIndex();
- }
- if (((Boolean) state.getValue(NORTH)).booleanValue()) {
- i |= 1 << EnumFacing.NORTH.getIndex();
- }
- if (((Boolean) state.getValue(EAST)).booleanValue()) {
- i |= 1 << EnumFacing.EAST.getIndex();
- }
- if (((Boolean) state.getValue(SOUTH)).booleanValue()) {
- i |= 1 << EnumFacing.SOUTH.getIndex();
- }
- if (((Boolean) state.getValue(WEST)).booleanValue()) {
- i |= 1 << EnumFacing.WEST.getIndex();
- }
- return i;
- }
- public boolean isOpaqueCube(IBlockState state) {
- return false;
- }
- public boolean isFullCube(IBlockState state) {
- return false;
- }
- public boolean isPassable(IBlockAccess worldIn, BlockPos pos) {
- return false;
- }
- public boolean canConnectTo(IBlockAccess worldIn, BlockPos pos, EnumFacing p_176524_3_) {
- IBlockState iblockstate = worldIn.getBlockState(pos);
- Block block = iblockstate.getBlock();
- boolean flag = false;
- return block == BlockRegistry.cable || flag;
- }
- @SideOnly(Side.CLIENT)
- public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
- return true;
- }
- public int getMetaFromState(IBlockState state) {
- return 0;
- }
- public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
- return state.withProperty(NORTH, canFenceConnectTo(worldIn, pos, EnumFacing.NORTH)).withProperty(EAST, canFenceConnectTo(worldIn, pos, EnumFacing.EAST)).withProperty(SOUTH, canFenceConnectTo(worldIn, pos, EnumFacing.SOUTH)).withProperty(WEST, canFenceConnectTo(worldIn, pos, EnumFacing.WEST)).withProperty(UP, canFenceConnectTo(worldIn, pos, EnumFacing.UP)).withProperty(DOWN, canFenceConnectTo(worldIn, pos, EnumFacing.DOWN));
- }
- /**
- * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed blockstate.
- */
- public IBlockState withRotation(IBlockState state, Rotation rot) {
- switch (rot) {
- case CLOCKWISE_180:
- return state.withProperty(NORTH, state.getValue(SOUTH)).withProperty(EAST, state.getValue(WEST)).withProperty(SOUTH, state.getValue(NORTH)).withProperty(WEST, state.getValue(EAST));
- case COUNTERCLOCKWISE_90:
- return state.withProperty(NORTH, state.getValue(EAST)).withProperty(EAST, state.getValue(SOUTH)).withProperty(SOUTH, state.getValue(WEST)).withProperty(WEST, state.getValue(NORTH));
- case CLOCKWISE_90:
- return state.withProperty(NORTH, state.getValue(WEST)).withProperty(EAST, state.getValue(NORTH)).withProperty(SOUTH, state.getValue(EAST)).withProperty(WEST, state.getValue(SOUTH));
- default:
- return state;
- }
- }
- /**
- * Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed blockstate.
- */
- public IBlockState withMirror(IBlockState state, Mirror mirrorIn) {
- switch (mirrorIn) {
- case LEFT_RIGHT:
- return state.withProperty(NORTH, state.getValue(SOUTH)).withProperty(SOUTH, state.getValue(NORTH));
- case FRONT_BACK:
- return state.withProperty(EAST, state.getValue(WEST)).withProperty(WEST, state.getValue(EAST));
- default:
- return super.withMirror(state, mirrorIn);
- }
- }
- protected BlockStateContainer createBlockState() {
- return new BlockStateContainer(this, new IProperty[] { NORTH, EAST, WEST, SOUTH, UP, DOWN });
- }
- /* ======================================== FORGE START ======================================== */
- @Override
- public boolean canBeConnectedTo(IBlockAccess world, BlockPos pos, EnumFacing facing) {
- Block connector = world.getBlockState(pos.offset(facing)).getBlock();
- if (connector instanceof BlockCable) {
- if (this != Blocks.NETHER_BRICK_FENCE && connector == Blocks.NETHER_BRICK_FENCE) {
- return false;
- } else if (this == Blocks.NETHER_BRICK_FENCE && connector != Blocks.NETHER_BRICK_FENCE) {
- return false;
- }
- return true;
- }
- return false;
- }
- private boolean canFenceConnectTo(IBlockAccess world, BlockPos pos, EnumFacing facing) {
- BlockPos other = pos.offset(facing);
- Block block = world.getBlockState(other).getBlock();
- return ((BlockCable) block).canBeConnectedTo(world, other, facing.getOpposite()) || canConnectTo(world, other, facing.getOpposite());
- }
- /* ======================================== FORGE END ======================================== */
- public BlockFaceShape getBlockFaceShape(IBlockAccess p_193383_1_, IBlockState p_193383_2_, BlockPos p_193383_3_, EnumFacing p_193383_4_) {
- return p_193383_4_ != EnumFacing.UP && p_193383_4_ != EnumFacing.DOWN ? BlockFaceShape.MIDDLE_POLE : BlockFaceShape.CENTER;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement