Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.Cmonster.OreMod.blocks;
- import com.Cmonster.OreMod.Reference;
- import com.Cmonster.OreMod.creativetabs.TabElements;
- import com.Cmonster.OreMod.entities.EntityJohn_tnt;
- 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.creativetab.CreativeTabs;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.item.EntityTNTPrimed;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.projectile.EntityArrow;
- import net.minecraft.init.Blocks;
- import net.minecraft.init.Items;
- import net.minecraft.init.SoundEvents;
- import net.minecraft.item.ItemStack;
- import net.minecraft.util.EnumFacing;
- import net.minecraft.util.EnumHand;
- import net.minecraft.util.SoundCategory;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.Explosion;
- import net.minecraft.world.World;
- public class BlockJohnny_tnt extends Block
- {
- public static final PropertyBool EXPLODE = PropertyBool.create("explode");
- public BlockJohnny_tnt()
- {
- super(Material.TNT);
- this.setUnlocalizedName(Reference.OreModBlocks.JOHNNY_TNT.getUnlocalizedName());
- this.setRegistryName(Reference.OreModBlocks.JOHNNY_TNT.getRegistryName());
- this.setDefaultState(this.blockState.getBaseState().withProperty(EXPLODE, Boolean.valueOf(false)));
- this.setSoundType(SoundType.PLANT);
- this.setCreativeTab(TabElements.tab_elements);
- }
- /**
- * Called after the block is set in the Chunk data, but before the Tile Entity is set
- */
- public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
- {
- super.onBlockAdded(worldIn, pos, state);
- if (worldIn.isBlockPowered(pos))
- {
- this.onBlockDestroyedByPlayer(worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)));
- worldIn.setBlockToAir(pos);
- }
- }
- /**
- * Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
- * change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
- * block, etc.
- */
- public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
- {
- if (worldIn.isBlockPowered(pos))
- {
- this.onBlockDestroyedByPlayer(worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)));
- worldIn.setBlockToAir(pos);
- }
- }
- /**
- * Called when this Block is destroyed by an Explosion
- */
- public void onBlockDestroyedByExplosion(World worldIn, BlockPos pos, Explosion explosionIn)
- {
- if (!worldIn.isRemote)
- {
- EntityJohn_tnt entitytntprimed = new EntityJohn_tnt(worldIn, (double)((float)pos.getX() + 0.5F), (double)pos.getY(), (double)((float)pos.getZ() + 0.5F), explosionIn.getExplosivePlacedBy());
- entitytntprimed.setFuse((short)(worldIn.rand.nextInt(entitytntprimed.getFuse() / 4) + entitytntprimed.getFuse() / 8));
- worldIn.spawnEntity(entitytntprimed);
- }
- }
- /**
- * Called when a player destroys this Block
- */
- public void onBlockDestroyedByPlayer(World worldIn, BlockPos pos, IBlockState state)
- {
- this.explode(worldIn, pos, state, (EntityLivingBase)null);
- }
- public void explode(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase igniter)
- {
- if (!worldIn.isRemote)
- {
- if (((Boolean)state.getValue(EXPLODE)).booleanValue())
- {
- EntityJohn_tnt entityjohn_tnt = new EntityJohn_tnt(worldIn, (double)((float)pos.getX() + 0.5F), (double)pos.getY(), (double)((float)pos.getZ() + 0.5F), igniter);
- worldIn.spawnEntity(entityjohn_tnt);
- worldIn.playSound((EntityPlayer)null, entityjohn_tnt.posX, entityjohn_tnt.posY, entityjohn_tnt.posZ, SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F);
- }
- }
- }
- /**
- * Called when the block is right clicked by a player.
- */
- public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
- {
- ItemStack itemstack = playerIn.getHeldItem(hand);
- if (!itemstack.isEmpty() && (itemstack.getItem() == Items.FLINT_AND_STEEL || itemstack.getItem() == Items.FIRE_CHARGE))
- {
- this.explode(worldIn, pos, state.withProperty(EXPLODE, Boolean.valueOf(true)), playerIn);
- worldIn.setBlockState(pos, Blocks.AIR.getDefaultState(), 11);
- if (itemstack.getItem() == Items.FLINT_AND_STEEL)
- {
- itemstack.damageItem(1, playerIn);
- }
- else if (!playerIn.capabilities.isCreativeMode)
- {
- itemstack.shrink(1);
- }
- return true;
- }
- else
- {
- return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
- }
- }
- /**
- * Called When an Entity Collided with the Block
- */
- public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
- {
- if (!worldIn.isRemote && entityIn instanceof EntityArrow)
- {
- EntityArrow entityarrow = (EntityArrow)entityIn;
- if (entityarrow.isBurning())
- {
- this.explode(worldIn, pos, worldIn.getBlockState(pos).withProperty(EXPLODE, Boolean.valueOf(true)), entityarrow.shootingEntity instanceof EntityLivingBase ? (EntityLivingBase)entityarrow.shootingEntity : null);
- worldIn.setBlockToAir(pos);
- }
- }
- }
- /**
- * Return whether this block can drop from an explosion.
- */
- public boolean canDropFromExplosion(Explosion explosionIn)
- {
- return false;
- }
- /**
- * Convert the BlockState into the correct metadata value
- */
- public int getMetaFromState(IBlockState state)
- {
- return ((Boolean)state.getValue(EXPLODE)).booleanValue() ? 1 : 0;
- }
- protected BlockStateContainer createBlockState()
- {
- return new BlockStateContainer(this, new IProperty[] {EXPLODE});
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement