Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BlockCampfire extends Block implements ITileEntityProvider {
- public static final PropertyDirection FACING = BlockHorizontal.FACING;
- private static final AxisAlignedBB COLLISION_BOX = new AxisAlignedBB(0.0625 * 1, 0, 0.0625 * 1, 0.0625 * 15,
- 0.0625 * 1, 0.0625 * 15);
- public BlockCampfire() {
- super(Material.ROCK);
- setUnlocalizedName(Reference.Blocks.CAMPFIRE.getUnlocalizedName());
- setRegistryName(Reference.Blocks.CAMPFIRE.getRegistryName());
- setHardness(1.0F);
- setCreativeTab(RoR.CREATIVE_TAB);
- }
- @Override
- public TileEntity createNewTileEntity(World worldIn, int meta) {
- return new TileEntityCampfire();
- }
- @Override
- public boolean isFullCube(IBlockState state) {
- return false;
- }
- @Override
- public boolean isOpaqueCube(IBlockState state) {
- return false;
- }
- @Override
- public BlockRenderLayer getBlockLayer() {
- return BlockRenderLayer.SOLID;
- }
- @Override
- public Item getItemDropped(IBlockState state, Random rand, int fortune) {
- return Item.getItemFromBlock(RoRBlocks.campfire);
- }
- public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
- {
- TileEntity tileEntity = worldIn.getTileEntity(pos);
- if (tileEntity instanceof TileEntityCampfire) {
- InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityCampfire) tileEntity);
- }
- }
- super.breakBlock(worldIn, pos, state);
- }
- @Override
- public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox,
- List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean p_185477_7_) {
- super.addCollisionBoxToList(pos, entityBox, collidingBoxes, COLLISION_BOX);
- }
- @Override
- public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer,
- ItemStack stack) {
- worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
- }
- @Override
- public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos) {
- if(world.getTileEntity(pos).getTileData().getBoolean("burning")) {
- return 13;
- }
- return 0;
- }
- @Override
- public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
- EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
- if (worldIn.isRemote) {
- return true;
- } else {
- TileEntity tileEntity = worldIn.getTileEntity(pos);
- if (tileEntity instanceof TileEntityCampfire) {
- if (playerIn.getHeldItemMainhand().getItem() == Items.FLINT_AND_STEEL) {
- if (!tileEntity.getTileData().getBoolean("burning")) {
- tileEntity.getTileData().setBoolean("burning", true);
- }
- } else if(playerIn.getHeldItemMainhand().getItem() == Items.WATER_BUCKET) {
- if (tileEntity.getTileData().getBoolean("burning")) {
- tileEntity.getTileData().setBoolean("burning", false);
- playerIn.setHeldItem(EnumHand.MAIN_HAND, new ItemStack(Items.BUCKET));
- }
- } else {
- playerIn.openGui(RoR.instance, RoRGuiHandler.TILE_ENTITY_CAMPFIRE_GUI, worldIn, pos.getX(), pos.getY(), pos.getZ());
- }
- }
- return true;
- }
- }
- @SideOnly(Side.CLIENT)
- public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
- if (worldIn.getTileEntity(pos).getTileData().getBoolean("burning")) {
- double d0 = (double) pos.getX() + 0.5D;
- double d1 = (double) pos.getY() + rand.nextDouble() * 6.0D / 16.0D;
- double d2 = (double) pos.getZ() + 0.5D;
- double d3 = 0.52D;
- double d4 = rand.nextDouble() * 0.6D - 0.3D;
- if (rand.nextDouble() < 0.1D) {
- worldIn.playSound((double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D,
- SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
- }
- worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 - 0.1D, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);
- worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 - 0.1D, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);
- worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + 0.1D, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);
- worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + 0.1D, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);
- worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 - 0.1D, 0.0D, 0.0D, 0.0D, new int[0]);
- worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + d4, d1, d2 - 0.1D, 0.0D, 0.0D, 0.0D, new int[0]);
- worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 + 0.1D, 0.0D, 0.0D, 0.0D, new int[0]);
- worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + d4, d1, d2 + 0.1D, 0.0D, 0.0D, 0.0D, new int[0]);
- }
- }
- public IBlockState getStateFromMeta(int meta) {
- EnumFacing enumfacing = EnumFacing.getFront(meta);
- if (enumfacing.getAxis() == EnumFacing.Axis.Y) {
- enumfacing = EnumFacing.NORTH;
- }
- return this.getDefaultState().withProperty(FACING, enumfacing);
- }
- public int getMetaFromState(IBlockState state) {
- return ((EnumFacing) state.getValue(FACING)).getIndex();
- }
- protected BlockStateContainer createBlockState() {
- return new BlockStateContainer(this, new IProperty[] { FACING });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment