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 damage = 3.0F;
- public Hammer(ToolMaterial toolMaterial, int durabillity) {
- super(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()) {
- World world = player.getEntityWorld();
- RayTraceResult sideHit = this.rayTrace(world, player, false);
- EnumFacing facing = sideHit.sideHit;
- EnumFacing facing1 = null, facing2 = null;
- for (EnumFacing.Axis axis : EnumFacing.Axis.values()) {
- if (axis == facing.getAxis()) {
- continue;
- }
- EnumFacing f = EnumFacing.getFacingFromAxis(EnumFacing.AxisDirection.POSITIVE, axis);
- if (facing1 == null) {
- facing1 = f;
- } else {
- facing2 = f;
- }
- }
- for (int i = -1; i <= 1; i++) {
- BlockPos offset1 = pos.offset(facing1, i);
- for (int j = -1; j <= 1; j++) {
- if (i == 0 && j == 0)
- continue;
- BlockPos offset2 = offset1.offset(facing2, j);
- world.destroyBlock(offset2, false);
- }
- }
- }
- return false;
- }
- @Override
- // Break blocks on survival
- public boolean onBlockDestroyed(ItemStack itemStack, World worldIn, IBlockState state, BlockPos pos,
- EntityLivingBase entityLiving) {
- EntityPlayer player = (EntityPlayer) entityLiving;
- RayTraceResult sideHit = this.rayTrace(worldIn, player, false);
- EnumFacing facing = sideHit.sideHit;
- EnumFacing facing1 = null, facing2 = null;
- for (EnumFacing.Axis axis : EnumFacing.Axis.values()) {
- if (axis == facing.getAxis()) {
- continue;
- }
- EnumFacing f = EnumFacing.getFacingFromAxis(EnumFacing.AxisDirection.POSITIVE, axis);
- if (facing1 == null) {
- facing1 = f;
- } else {
- facing2 = f;
- }
- }
- for (int i = -1; i <= 1; i++) {
- BlockPos offset1 = pos.offset(facing1, i);
- for (int j = -1; j <= 1; j++) {
- if (i == 0 && j == 0)
- continue;
- BlockPos offset2 = offset1.offset(facing2, j);
- if (worldIn.getBlockState(offset2).getBlock().canHarvestBlock(worldIn, offset2, player)) {
- worldIn.destroyBlock(offset2, true);
- } else {
- worldIn.destroyBlock(offset2, false);
- }
- if (state.getBlock().isToolEffective("pickaxe", state)) {
- if ((double) state.getBlockHardness(worldIn, pos) != 0.0D && state.getBlock() != Blocks.AIR) {
- itemStack.damageItem(1, player);
- }
- } else {
- if ((double) state.getBlockHardness(worldIn, pos) != 0.0D && state.getBlock() != Blocks.AIR) {
- itemStack.damageItem(3, player);
- }
- }
- }
- }
- if ((double) state.getBlockHardness(worldIn, pos) != 0.0D) {
- itemStack.damageItem(1, entityLiving);
- }
- 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