Guest User

Untitled

a guest
May 29th, 2017
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.16 KB | None | 0 0
  1. public class BlockCampfire extends Block implements ITileEntityProvider {
  2.  
  3.     public static final PropertyDirection FACING = BlockHorizontal.FACING;
  4.     private static final AxisAlignedBB COLLISION_BOX = new AxisAlignedBB(0.0625 * 1, 0, 0.0625 * 1, 0.0625 * 15,
  5.             0.0625 * 1, 0.0625 * 15);
  6.    
  7.     public BlockCampfire() {
  8.         super(Material.ROCK);
  9.         setUnlocalizedName(Reference.Blocks.CAMPFIRE.getUnlocalizedName());
  10.         setRegistryName(Reference.Blocks.CAMPFIRE.getRegistryName());
  11.         setHardness(1.0F);
  12.         setCreativeTab(RoR.CREATIVE_TAB);
  13.     }
  14.  
  15.     @Override
  16.     public TileEntity createNewTileEntity(World worldIn, int meta) {
  17.         return new TileEntityCampfire();
  18.     }
  19.  
  20.     @Override
  21.     public boolean isFullCube(IBlockState state) {
  22.         return false;
  23.     }
  24.  
  25.     @Override
  26.     public boolean isOpaqueCube(IBlockState state) {
  27.         return false;
  28.     }
  29.  
  30.     @Override
  31.     public BlockRenderLayer getBlockLayer() {
  32.         return BlockRenderLayer.SOLID;
  33.     }
  34.  
  35.     @Override
  36.     public Item getItemDropped(IBlockState state, Random rand, int fortune) {
  37.         return Item.getItemFromBlock(RoRBlocks.campfire);
  38.     }
  39.  
  40.     public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
  41.         {
  42.             TileEntity tileEntity = worldIn.getTileEntity(pos);
  43.  
  44.             if (tileEntity instanceof TileEntityCampfire) {
  45.                 InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityCampfire) tileEntity);
  46.             }
  47.         }
  48.  
  49.         super.breakBlock(worldIn, pos, state);
  50.     }
  51.  
  52.     @Override
  53.     public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox,
  54.             List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean p_185477_7_) {
  55.         super.addCollisionBoxToList(pos, entityBox, collidingBoxes, COLLISION_BOX);
  56.     }
  57.  
  58.     @Override
  59.     public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer,
  60.             ItemStack stack) {
  61.         worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
  62.     }
  63.    
  64.     @Override
  65.     public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos) {
  66.         if(world.getTileEntity(pos).getTileData().getBoolean("burning")) {
  67.             return 13;
  68.         }
  69.        
  70.         return 0;
  71.     }
  72.  
  73.     @Override
  74.     public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
  75.             EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  76.         if (worldIn.isRemote) {
  77.             return true;
  78.         } else {
  79.             TileEntity tileEntity = worldIn.getTileEntity(pos);
  80.             if (tileEntity instanceof TileEntityCampfire) {
  81.                 if (playerIn.getHeldItemMainhand().getItem() == Items.FLINT_AND_STEEL) {
  82.                     if (!tileEntity.getTileData().getBoolean("burning")) {
  83.                         tileEntity.getTileData().setBoolean("burning", true);
  84.                        
  85.                     }
  86.                 } else if(playerIn.getHeldItemMainhand().getItem() == Items.WATER_BUCKET) {
  87.                     if (tileEntity.getTileData().getBoolean("burning")) {
  88.                         tileEntity.getTileData().setBoolean("burning", false);
  89.                         playerIn.setHeldItem(EnumHand.MAIN_HAND, new ItemStack(Items.BUCKET));
  90.                     }
  91.                 } else {
  92.                     playerIn.openGui(RoR.instance, RoRGuiHandler.TILE_ENTITY_CAMPFIRE_GUI, worldIn, pos.getX(), pos.getY(), pos.getZ());
  93.                 }
  94.             }
  95.            
  96.             return true;
  97.         }
  98.     }
  99.  
  100.     @SideOnly(Side.CLIENT)
  101.     public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
  102.         if (worldIn.getTileEntity(pos).getTileData().getBoolean("burning")) {
  103.             double d0 = (double) pos.getX() + 0.5D;
  104.             double d1 = (double) pos.getY() + rand.nextDouble() * 6.0D / 16.0D;
  105.             double d2 = (double) pos.getZ() + 0.5D;
  106.             double d3 = 0.52D;
  107.             double d4 = rand.nextDouble() * 0.6D - 0.3D;
  108.  
  109.             if (rand.nextDouble() < 0.1D) {
  110.                 worldIn.playSound((double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D,
  111.                         SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
  112.             }
  113.             worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 - 0.1D, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);
  114.             worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 - 0.1D, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);
  115.  
  116.             worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + 0.1D, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);
  117.             worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + 0.1D, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);
  118.  
  119.             worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 - 0.1D, 0.0D, 0.0D, 0.0D, new int[0]);
  120.             worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + d4, d1, d2 - 0.1D, 0.0D, 0.0D, 0.0D, new int[0]);
  121.  
  122.             worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 + 0.1D, 0.0D, 0.0D, 0.0D, new int[0]);
  123.             worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + d4, d1, d2 + 0.1D, 0.0D, 0.0D, 0.0D, new int[0]);
  124.         }
  125.     }
  126.  
  127.     public IBlockState getStateFromMeta(int meta) {
  128.         EnumFacing enumfacing = EnumFacing.getFront(meta);
  129.  
  130.         if (enumfacing.getAxis() == EnumFacing.Axis.Y) {
  131.             enumfacing = EnumFacing.NORTH;
  132.         }
  133.  
  134.         return this.getDefaultState().withProperty(FACING, enumfacing);
  135.     }
  136.  
  137.     public int getMetaFromState(IBlockState state) {
  138.         return ((EnumFacing) state.getValue(FACING)).getIndex();
  139.     }
  140.  
  141.     protected BlockStateContainer createBlockState() {
  142.         return new BlockStateContainer(this, new IProperty[] { FACING });
  143.     }
  144.  
  145. }
Advertisement
Add Comment
Please, Sign In to add comment