Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Hammer extends ItemTool {
- public static float attack_speed = -2.8F;
- public static float base_damage = 3.0F;
- public Hammer(ToolMaterial toolMaterial, int durabillity) {
- super(base_damage, attack_speed, toolMaterial, Collections.emptySet());
- this.setHarvestLevel("pickaxe", toolMaterial.getHarvestLevel());
- this.setMaxDamage(durabillity);
- }
- @Override
- // Break blocks on creative
- public boolean onBlockStartBreak(ItemStack itemStack, BlockPos pos, EntityPlayer player) {
- if (player.isCreative()) {
- EnumFacing facing = player.getHorizontalFacing();
- World worldIn = player.getEntityWorld();
- IBlockState state = worldIn.getBlockState(pos);
- Block block = state.getBlock();
- float headYaw = player.getRotationYawHead();
- for (int x = (pos.getX() - 1); x < (pos.getX() + 2); x++) {
- for (int y = (pos.getY() - 1); y < (pos.getY() + 2); y++) {
- if (!worldIn.isAirBlock(new BlockPos(x, y, pos.getZ())) && ((double) state.getBlockHardness(worldIn,
- new BlockPos(x, y, pos.getZ()).offset(facing)) != 0.0D)) {
- state = worldIn.getBlockState(new BlockPos(x, y, pos.getZ()).offset(facing));
- if (state.getBlock().isToolEffective("pickaxe", state)) {
- itemStack.damageItem(1, player);
- } else {
- itemStack.damageItem(3, player);
- }
- }
- worldIn.setBlockToAir(new BlockPos(x, y, pos.getZ()).offset(facing));
- }
- }
- }
- return false;
- }
- @Override
- // Break blocks on survival
- public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos,
- EntityLivingBase entityLiving) {
- EnumFacing facing = entityLiving.getHorizontalFacing();
- Block block = state.getBlock();
- float headYaw = entityLiving.getRotationYawHead();
- EntityPlayer player = (EntityPlayer) entityLiving;
- for (int x = (pos.getX() - 1); x < (pos.getX() + 2); x++) {
- for (int y = (pos.getY() - 1); y < (pos.getY() + 2); y++) {
- if (!worldIn.isAirBlock(new BlockPos(x, y, pos.getZ())) && ((double) state.getBlockHardness(worldIn,
- new BlockPos(x, y, pos.getZ()).offset(facing)) != 0.0D)) {
- state = worldIn.getBlockState(new BlockPos(x, y, pos.getZ()).offset(facing));
- if (state.getBlock().isToolEffective("pickaxe", state)) {
- stack.damageItem(1, entityLiving);
- } else {
- stack.damageItem(3, entityLiving);
- }
- }
- if (block.canHarvestBlock(worldIn, new BlockPos(x, y, pos.getZ()).offset(facing), player)) {
- worldIn.destroyBlock(new BlockPos(x, y, pos.getZ()).offset(facing), true);
- } else {
- worldIn.setBlockToAir(new BlockPos(x, y, pos.getZ()).offset(facing));
- }
- }
- }
- return true;
- }
- @Override
- public boolean hitEntity(ItemStack itemStack, EntityLivingBase target, EntityLivingBase attacker) {
- itemStack.damageItem(1, attacker);
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement