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
- 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();
- if (facing == facing.NORTH) {
- 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())) != 0.0D)) {
- if (state.getBlock().isToolEffective("pickaxe", state)) {
- itemStack.damageItem(1, player);
- } else {
- itemStack.damageItem(3, player);
- }
- }
- worldIn.setBlockToAir(new BlockPos(x, y, pos.getZ()));
- }
- }
- }
- if (facing == facing.SOUTH) {
- 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())) != 0.0D)) {
- if (state.getBlock().isToolEffective("pickaxe", state)) {
- itemStack.damageItem(1, player);
- } else {
- itemStack.damageItem(3, player);
- }
- }
- worldIn.setBlockToAir(new BlockPos(x, y, pos.getZ()));
- }
- }
- }
- if (facing == facing.EAST) {
- for (int z = (pos.getZ() - 1); z < (pos.getZ() + 2); z++) {
- for (int y = (pos.getY() - 1); y < (pos.getY() + 2); y++) {
- if (!worldIn.isAirBlock(new BlockPos(pos.getX(), y, z))
- && ((double) state.getBlockHardness(worldIn, new BlockPos(pos.getX(), y, z)) != 0.0D)) {
- if (state.getBlock().isToolEffective("pickaxe", state)) {
- itemStack.damageItem(1, player);
- } else {
- itemStack.damageItem(3, player);
- }
- }
- worldIn.setBlockToAir(new BlockPos(pos.getX(), y, z));
- }
- }
- }
- if (facing == facing.WEST) {
- for (int z = (pos.getZ() - 1); z < (pos.getZ() + 2); z++) {
- for (int y = (pos.getY() - 1); y < (pos.getY() + 2); y++) {
- if (!worldIn.isAirBlock(new BlockPos(pos.getX(), y, z))
- && ((double) state.getBlockHardness(worldIn, new BlockPos(pos.getX(), y, z)) != 0.0D)) {
- if (state.getBlock().isToolEffective("pickaxe", state)) {
- itemStack.damageItem(1, player);
- } else {
- itemStack.damageItem(3, player);
- }
- }
- worldIn.setBlockToAir(new BlockPos(pos.getX(), y, z));
- }
- }
- }
- }
- return false;
- }
- @Override
- 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;
- if (facing == facing.NORTH) {
- 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())) != 0.0D)) {
- 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()), player)) {
- worldIn.destroyBlock(new BlockPos(x, y, pos.getZ()), true);
- } else {
- worldIn.setBlockToAir(new BlockPos(x, y, pos.getZ()));
- }
- }
- }
- }
- if (facing == facing.SOUTH) {
- 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())) != 0.0D)) {
- 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()), player)) {
- worldIn.destroyBlock(new BlockPos(x, y, pos.getZ()), true);
- } else {
- worldIn.setBlockToAir(new BlockPos(x, y, pos.getZ()));
- }
- }
- }
- }
- if (facing == facing.EAST) {
- for (int z = (pos.getZ() - 1); z < (pos.getZ() + 2); z++) {
- for (int y = (pos.getY() - 1); y < (pos.getY() + 2); y++) {
- if (!worldIn.isAirBlock(new BlockPos(pos.getX(), y, z))
- && ((double) state.getBlockHardness(worldIn, new BlockPos(pos.getX(), y, z)) != 0.0D)) {
- if (state.getBlock().isToolEffective("pickaxe", state)) {
- stack.damageItem(1, entityLiving);
- } else {
- stack.damageItem(3, entityLiving);
- }
- }
- if (block.canHarvestBlock(worldIn, new BlockPos(pos.getX(), y, z), player)) {
- worldIn.destroyBlock(new BlockPos(pos.getX(), y, z), true);
- } else {
- worldIn.setBlockToAir(new BlockPos(pos.getX(), y, z));
- }
- }
- }
- }
- if (facing == facing.WEST) {
- for (int z = (pos.getZ() - 1); z < (pos.getZ() + 2); z++) {
- for (int y = (pos.getY() - 1); y < (pos.getY() + 2); y++) {
- if (!worldIn.isAirBlock(new BlockPos(pos.getX(), y, z))
- && ((double) state.getBlockHardness(worldIn, new BlockPos(pos.getX(), y, z)) != 0.0D)) {
- if (state.getBlock().isToolEffective("pickaxe", state)) {
- stack.damageItem(1, entityLiving);
- } else {
- stack.damageItem(3, entityLiving);
- }
- }
- if (block.canHarvestBlock(worldIn, new BlockPos(pos.getX(), y, z), player)) {
- worldIn.destroyBlock(new BlockPos(pos.getX(), y, z), true);
- } else {
- worldIn.setBlockToAir(new BlockPos(pos.getX(), y, z));
- }
- }
- }
- }
- return true;
- }
- @Override
- public boolean hitEntity(ItemStack itemStack, EntityLivingBase target, EntityLivingBase attacker) {
- itemStack.damageItem(1, attacker);
- return true;
- }
- }
Add Comment
Please, Sign In to add comment