Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Machine extends Block {
- public static final PropertyDirection FACING = BlockHorizontal.FACING;
- public static final PropertyBool ACTIVE = PropertyBool.create("burning");
- public Machine(String resource) {
- super(Material.IRON);
- setSoundType(SoundType.METAL);
- setUnlocalizedName(Exkva.MODID + "." + resource);
- setRegistryName(new ResourceLocation(Exkva.MODID, resource));
- this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(ACTIVE, false));
- }
- public void initModel() {
- ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
- }
- @Override
- public boolean hasTileEntity(IBlockState state) {
- return true;
- }
- @Override
- protected BlockStateContainer createBlockState() {
- return new BlockStateContainer(this, new IProperty[] {ACTIVE, FACING});
- }
- @Override
- public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
- worldIn.setBlockState(pos, this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
- }
- @Override
- public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
- if(!worldIn.isRemote) {
- IBlockState north, south, east, west;
- north = worldIn.getBlockState(pos.north());
- south = worldIn.getBlockState(pos.south());
- east = worldIn.getBlockState(pos.east());
- west = worldIn.getBlockState(pos.west());
- EnumFacing face = (EnumFacing) state.getValue(FACING);
- if (face == EnumFacing.NORTH && north.isFullBlock() && south.isFullBlock()) {
- face = EnumFacing.SOUTH;
- } else if (face == EnumFacing.SOUTH && south.isFullBlock() && north.isFullBlock()) {
- face = EnumFacing.NORTH;
- } else if (face == EnumFacing.WEST && west.isFullBlock() && east.isFullBlock()) {
- face = EnumFacing.EAST;
- } else if (face == EnumFacing.EAST && east.isFullBlock() && west.isFullBlock()) {
- face = EnumFacing.WEST;
- }
- worldIn.setBlockState(pos, state.withProperty(FACING, face), 2);
- }
- }
- @Override
- public int getMetaFromState(IBlockState state) {
- return ((EnumFacing) state.getValue(FACING)).getIndex();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement