From b68f9395e8794bf0b10d2140604349b1b88032ec Mon Sep 17 00:00:00 2001 From: Boblet Date: Tue, 18 Jan 2022 16:54:45 +0100 Subject: [PATCH] i rember --- .../java/com/hbm/items/tool/IItemAbility.java | 81 ++++- .../com/hbm/items/tool/ItemSwordAbility.java | 71 ---- .../com/hbm/items/tool/ItemToolAbility.java | 327 +++++++----------- 3 files changed, 203 insertions(+), 276 deletions(-) diff --git a/src/main/java/com/hbm/items/tool/IItemAbility.java b/src/main/java/com/hbm/items/tool/IItemAbility.java index 30600fae6..a03be2de0 100644 --- a/src/main/java/com/hbm/items/tool/IItemAbility.java +++ b/src/main/java/com/hbm/items/tool/IItemAbility.java @@ -1,9 +1,88 @@ package com.hbm.items.tool; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.network.play.client.C07PacketPlayerDigging; +import net.minecraft.network.play.server.S23PacketBlockChange; import net.minecraft.world.World; +import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.event.world.BlockEvent; public interface IItemAbility { - public void breakExtraBlock(World world, int x, int y, int z, EntityPlayer player, int refX, int refY, int refZ); + public boolean canHarvestBlock(Block par1Block, ItemStack itemStack); + + public default void breakExtraBlock(World world, int x, int y, int z, EntityPlayer playerEntity, int refX, int refY, int refZ) { + + if(world.isAirBlock(x, y, z)) + return; + + if(!(playerEntity instanceof EntityPlayerMP)) + return; + + EntityPlayerMP player = (EntityPlayerMP) playerEntity; + ItemStack stack = player.getHeldItem(); + + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + + if(!canHarvestBlock(block, stack)) + return; + + Block refBlock = world.getBlock(refX, refY, refZ); + float refStrength = ForgeHooks.blockStrength(refBlock, player, world, refX, refY, refZ); + float strength = ForgeHooks.blockStrength(block, player, world, x, y, z); + + if(!ForgeHooks.canHarvestBlock(block, player, meta) || refStrength / strength > 10f || block.getBlockHardness(world, x, y, z) < 0) + return; + + BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(world, player.theItemInWorldManager.getGameType(), player, x, y, z); + if(event.isCanceled()) + return; + + if(player.capabilities.isCreativeMode) { + block.onBlockHarvested(world, x, y, z, meta, player); + if(block.removedByPlayer(world, player, x, y, z, false)) + block.onBlockDestroyedByPlayer(world, x, y, z, meta); + + if(!world.isRemote) { + player.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world)); + } + return; + } + + player.getCurrentEquippedItem().func_150999_a(world, block, x, y, z, player); + + if(!world.isRemote) { + + block.onBlockHarvested(world, x, y, z, meta, player); + + if(block.removedByPlayer(world, player, x, y, z, true)) { + block.onBlockDestroyedByPlayer(world, x, y, z, meta); + block.harvestBlock(world, player, x, y, z, meta); + block.dropXpOnBlockBreak(world, x, y, z, event.getExpToDrop()); + } + + player.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world)); + + } else { + world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12)); + if(block.removedByPlayer(world, player, x, y, z, true)) { + block.onBlockDestroyedByPlayer(world, x, y, z, meta); + } + ItemStack itemstack = player.getCurrentEquippedItem(); + if(itemstack != null) { + itemstack.func_150999_a(world, block, x, y, z, player); + + if(itemstack.stackSize == 0) { + player.destroyCurrentEquippedItem(); + } + } + + Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C07PacketPlayerDigging(2, x, y, z, Minecraft.getMinecraft().objectMouseOver.sideHit)); + } + } } diff --git a/src/main/java/com/hbm/items/tool/ItemSwordAbility.java b/src/main/java/com/hbm/items/tool/ItemSwordAbility.java index ed8c6a07e..12843a724 100644 --- a/src/main/java/com/hbm/items/tool/ItemSwordAbility.java +++ b/src/main/java/com/hbm/items/tool/ItemSwordAbility.java @@ -83,77 +83,6 @@ public class ItemSwordAbility extends ItemSword implements IItemAbility { return multimap; } - public void breakExtraBlock(World world, int x, int y, int z, EntityPlayer playerEntity, int refX, int refY, int refZ) { - - if(world.isAirBlock(x, y, z)) - return; - - if(!(playerEntity instanceof EntityPlayerMP)) - return; - - EntityPlayerMP player = (EntityPlayerMP) playerEntity; - ItemStack stack = player.getHeldItem(); - - Block block = world.getBlock(x, y, z); - int meta = world.getBlockMetadata(x, y, z); - - if(!canHarvestBlock(block, stack)) - return; - - Block refBlock = world.getBlock(refX, refY, refZ); - float refStrength = ForgeHooks.blockStrength(refBlock, player, world, refX, refY, refZ); - float strength = ForgeHooks.blockStrength(block, player, world, x, y, z); - - if(!ForgeHooks.canHarvestBlock(block, player, meta) || refStrength / strength > 10f) - return; - - BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(world, player.theItemInWorldManager.getGameType(), player, x, y, z); - if(event.isCanceled()) - return; - - if(player.capabilities.isCreativeMode) { - block.onBlockHarvested(world, x, y, z, meta, player); - if(block.removedByPlayer(world, player, x, y, z, false)) - block.onBlockDestroyedByPlayer(world, x, y, z, meta); - - if(!world.isRemote) { - player.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world)); - } - return; - } - - player.getCurrentEquippedItem().func_150999_a(world, block, x, y, z, player); - - if(!world.isRemote) { - - block.onBlockHarvested(world, x, y, z, meta, player); - - if(block.removedByPlayer(world, player, x, y, z, true)) { - block.onBlockDestroyedByPlayer(world, x, y, z, meta); - block.harvestBlock(world, player, x, y, z, meta); - block.dropXpOnBlockBreak(world, x, y, z, event.getExpToDrop()); - } - - player.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world)); - - } else { - world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12)); - if(block.removedByPlayer(world, player, x, y, z, true)) { - block.onBlockDestroyedByPlayer(world, x, y, z, meta); - } - ItemStack itemstack = player.getCurrentEquippedItem(); - if(itemstack != null) { - itemstack.func_150999_a(world, block, x, y, z, player); - - if(itemstack.stackSize == 0) { - player.destroyCurrentEquippedItem(); - } - } - - Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C07PacketPlayerDigging(2, x, y, z, Minecraft.getMinecraft().objectMouseOver.sideHit)); - } - } - @SideOnly(Side.CLIENT) public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) { diff --git a/src/main/java/com/hbm/items/tool/ItemToolAbility.java b/src/main/java/com/hbm/items/tool/ItemToolAbility.java index 48b10527d..93db30e41 100644 --- a/src/main/java/com/hbm/items/tool/ItemToolAbility.java +++ b/src/main/java/com/hbm/items/tool/ItemToolAbility.java @@ -43,10 +43,10 @@ public class ItemToolAbility extends ItemTool implements IItemAbility, IDepthRoc private EnumToolType toolType; private EnumRarity rarity = EnumRarity.common; //was there a reason for this to be private? - protected float damage; - protected double movement; - private List breakAbility = new ArrayList() {{ add(null); }}; - private List hitAbility = new ArrayList(); + protected float damage; + protected double movement; + private List breakAbility = new ArrayList() {{ add(null); }}; + private List hitAbility = new ArrayList(); public static enum EnumToolType { @@ -65,11 +65,11 @@ public class ItemToolAbility extends ItemTool implements IItemAbility, IDepthRoc MINER( Sets.newHashSet(new Material[] { Material.grass, Material.iron, Material.anvil, Material.rock, Material.clay, Material.sand, Material.ground, Material.snow, Material.craftedSnow }) ); - + private EnumToolType(Set materials) { this.materials = materials; } - + private EnumToolType(Set materials, Set blocks) { this.materials = materials; this.blocks = blocks; @@ -86,168 +86,93 @@ public class ItemToolAbility extends ItemTool implements IItemAbility, IDepthRoc this.toolType = type; this.setHarvestLevel(type.toString().toLowerCase(), material.getHarvestLevel()); } - + public ItemToolAbility addBreakAbility(ToolAbility breakAbility) { this.breakAbility.add(breakAbility); return this; } - + public ItemToolAbility addHitAbility(WeaponAbility weaponAbility) { this.hitAbility.add(weaponAbility); return this; } - - // + + // public ItemToolAbility setRarity(EnumRarity rarity) { this.rarity = rarity; return this; } - - public EnumRarity getRarity(ItemStack stack) { - return this.rarity != EnumRarity.common ? this.rarity : super.getRarity(stack); - } - - public boolean hitEntity(ItemStack stack, EntityLivingBase victim, EntityLivingBase attacker) { - if(!attacker.worldObj.isRemote && !this.hitAbility.isEmpty() && attacker instanceof EntityPlayer && canOperate(stack)) { - - for(WeaponAbility ability : this.hitAbility) { + public EnumRarity getRarity(ItemStack stack) { + return this.rarity != EnumRarity.common ? this.rarity : super.getRarity(stack); + } + + public boolean hitEntity(ItemStack stack, EntityLivingBase victim, EntityLivingBase attacker) { + + if(!attacker.worldObj.isRemote && !this.hitAbility.isEmpty() && attacker instanceof EntityPlayer && canOperate(stack)) { + + for(WeaponAbility ability : this.hitAbility) { ability.onHit(attacker.worldObj, (EntityPlayer) attacker, victim, this); - } - } - - stack.damageItem(2, attacker); - - return true; - } + } + } - @Override - public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) { - - World world = player.worldObj; - Block block = world.getBlock(x, y, z); - int meta = world.getBlockMetadata(x, y, z); - - if(!world.isRemote && canHarvestBlock(block, stack) && this.getCurrentAbility(stack) != null && canOperate(stack)) - this.getCurrentAbility(stack).onDig(world, x, y, z, player, block, meta, this); - - return false; - } + stack.damageItem(2, attacker); - @Override - public float getDigSpeed(ItemStack stack, Block block, int meta) { - - if(!canOperate(stack)) - return 1; - - if(toolType == null) - return super.getDigSpeed(stack, block, meta); - - if(toolType.blocks.contains(block) || toolType.materials.contains(block.getMaterial())) - return this.efficiencyOnProperMaterial; - - return super.getDigSpeed(stack, block, meta); - } - - @Override - public boolean canHarvestBlock(Block block, ItemStack stack) { - - if(!canOperate(stack)) return false; - - if(this.getCurrentAbility(stack) instanceof SilkAbility) - return true; - - return getDigSpeed(stack, block, 0) > 1; - } - - @Override - public Multimap getItemAttributeModifiers() { - - Multimap multimap = HashMultimap.create(); - multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Tool modifier", (double)this.damage, 0)); + return true; + } + + @Override + public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) { + + World world = player.worldObj; + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); + + if(!world.isRemote && canHarvestBlock(block, stack) && this.getCurrentAbility(stack) != null && canOperate(stack)) + this.getCurrentAbility(stack).onDig(world, x, y, z, player, block, meta, this); + + return false; + } + + @Override + public float getDigSpeed(ItemStack stack, Block block, int meta) { + + if(!canOperate(stack)) + return 1; + + if(toolType == null) + return super.getDigSpeed(stack, block, meta); + + if(toolType.blocks.contains(block) || toolType.materials.contains(block.getMaterial())) + return this.efficiencyOnProperMaterial; + + return super.getDigSpeed(stack, block, meta); + } + + @Override + public boolean canHarvestBlock(Block block, ItemStack stack) { + + if(!canOperate(stack)) + return false; + + if(this.getCurrentAbility(stack) instanceof SilkAbility) + return true; + + return getDigSpeed(stack, block, 0) > 1; + } + + @Override + public Multimap getItemAttributeModifiers() { + + Multimap multimap = HashMultimap.create(); + multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Tool modifier", (double) this.damage, 0)); multimap.put(SharedMonsterAttributes.movementSpeed.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Tool modifier", movement, 1)); - return multimap; - } - - public void breakExtraBlock(World world, int x, int y, int z, EntityPlayer playerEntity, int refX, int refY, int refZ) { - - if (world.isAirBlock(x, y, z)) - return; - - if(!(playerEntity instanceof EntityPlayerMP)) - return; - - EntityPlayerMP player = (EntityPlayerMP) playerEntity; - ItemStack stack = player.getHeldItem(); - - Block block = world.getBlock(x, y, z); - int meta = world.getBlockMetadata(x, y, z); - - if(!canHarvestBlock(block, stack)) - return; - - Block refBlock = world.getBlock(refX, refY, refZ); - float refStrength = ForgeHooks.blockStrength(refBlock, player, world, refX, refY, refZ); - float strength = ForgeHooks.blockStrength(block, player, world, x,y,z); - - if (!ForgeHooks.canHarvestBlock(block, player, meta) || refStrength/strength > 10f) - return; - - BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(world, player.theItemInWorldManager.getGameType(), player, x,y,z); - if(event.isCanceled()) - return; - - if (player.capabilities.isCreativeMode) { - block.onBlockHarvested(world, x, y, z, meta, player); - if (block.removedByPlayer(world, player, x, y, z, false)) - block.onBlockDestroyedByPlayer(world, x, y, z, meta); - - if (!world.isRemote) { - player.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world)); - } - return; - } - - player.getCurrentEquippedItem().func_150999_a(world, block, x, y, z, player); - - if (!world.isRemote) { - - block.onBlockHarvested(world, x,y,z, meta, player); - - if(block.removedByPlayer(world, player, x,y,z, true)) - { - block.onBlockDestroyedByPlayer( world, x,y,z, meta); - block.harvestBlock(world, player, x,y,z, meta); - block.dropXpOnBlockBreak(world, x,y,z, event.getExpToDrop()); - } - - player.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world)); - - } else { - world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12)); - if(block.removedByPlayer(world, player, x,y,z, true)) - { - block.onBlockDestroyedByPlayer(world, x,y,z, meta); - } - ItemStack itemstack = player.getCurrentEquippedItem(); - if (itemstack != null) - { - itemstack.func_150999_a(world, block, x, y, z, player); - - if (itemstack.stackSize == 0) - { - player.destroyCurrentEquippedItem(); - } - } - - Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C07PacketPlayerDigging(2, x, y, z, Minecraft.getMinecraft().objectMouseOver.sideHit)); - } - } + return multimap; + } @SideOnly(Side.CLIENT) public boolean hasEffect(ItemStack stack) { - - return getCurrentAbility(stack) != null ? true : super.hasEffect(stack); + return getCurrentAbility(stack) != null || stack.isItemEnchanted(); } @SideOnly(Side.CLIENT) @@ -285,62 +210,56 @@ public class ItemToolAbility extends ItemTool implements IItemAbility, IDepthRoc list.add(EnumChatFormatting.RED + "Can break depth rock!"); } } - - public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { - - if(world.isRemote || this.breakAbility.size() < 2 || !canOperate(stack)) - return super.onItemRightClick(stack, world, player); - - int i = getAbility(stack); - i++; - - if(player.isSneaking()) - i = 0; - - setAbility(stack, i % this.breakAbility.size()); - - while(getCurrentAbility(stack) != null && !getCurrentAbility(stack).isAllowed()) { - - player.addChatComponentMessage( - new ChatComponentText("[Ability ") - .appendSibling(new ChatComponentTranslation(getCurrentAbility(stack).getName(), new Object[0])) - .appendSibling(new ChatComponentText(getCurrentAbility(stack).getExtension() + " is blacklisted!]")) - .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED))); - - i++; - setAbility(stack, i % this.breakAbility.size()); - } - - if(getCurrentAbility(stack) != null) { - player.addChatComponentMessage( - new ChatComponentText("[Enabled ") - .appendSibling(new ChatComponentTranslation(getCurrentAbility(stack).getName(), new Object[0])) - .appendSibling(new ChatComponentText(getCurrentAbility(stack).getExtension() + "]")) - .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.YELLOW))); - } else { - player.addChatComponentMessage(new ChatComponentText(EnumChatFormatting.GOLD + "[Tool ability deactivated]")); - } - world.playSoundAtEntity(player, "random.orb", 0.25F, getCurrentAbility(stack) == null ? 0.75F : 1.25F); - - return stack; - } - - private ToolAbility getCurrentAbility(ItemStack stack) { - - int ability = getAbility(stack) % this.breakAbility.size(); - - return this.breakAbility.get(ability); - } - - private int getAbility(ItemStack stack) { - - if(stack.hasTagCompound()) - return stack.stackTagCompound.getInteger("ability"); - - return 0; - } - + public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { + + if(world.isRemote || this.breakAbility.size() < 2 || !canOperate(stack)) + return super.onItemRightClick(stack, world, player); + + int i = getAbility(stack); + i++; + + if(player.isSneaking()) + i = 0; + + setAbility(stack, i % this.breakAbility.size()); + + while(getCurrentAbility(stack) != null && !getCurrentAbility(stack).isAllowed()) { + + player.addChatComponentMessage(new ChatComponentText("[Ability ").appendSibling(new ChatComponentTranslation(getCurrentAbility(stack).getName(), new Object[0])) + .appendSibling(new ChatComponentText(getCurrentAbility(stack).getExtension() + " is blacklisted!]")).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED))); + + i++; + setAbility(stack, i % this.breakAbility.size()); + } + + if(getCurrentAbility(stack) != null) { + player.addChatComponentMessage(new ChatComponentText("[Enabled ").appendSibling(new ChatComponentTranslation(getCurrentAbility(stack).getName(), new Object[0])) + .appendSibling(new ChatComponentText(getCurrentAbility(stack).getExtension() + "]")).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.YELLOW))); + } else { + player.addChatComponentMessage(new ChatComponentText(EnumChatFormatting.GOLD + "[Tool ability deactivated]")); + } + + world.playSoundAtEntity(player, "random.orb", 0.25F, getCurrentAbility(stack) == null ? 0.75F : 1.25F); + + return stack; + } + + private ToolAbility getCurrentAbility(ItemStack stack) { + + int ability = getAbility(stack) % this.breakAbility.size(); + + return this.breakAbility.get(ability); + } + + private int getAbility(ItemStack stack) { + + if(stack.hasTagCompound()) + return stack.stackTagCompound.getInteger("ability"); + + return 0; + } + private void setAbility(ItemStack stack, int ability) { if(!stack.hasTagCompound()) @@ -357,7 +276,7 @@ public class ItemToolAbility extends ItemTool implements IItemAbility, IDepthRoc this.rockBreaker = true; return this; } - + private boolean rockBreaker = false; @Override