Jump to content

[1.6.2] [Solved] Bow Damages?


xwerswoodx

Recommended Posts

Hello everyone,

 

Firstly, if same topic was opened, I'm very sorry about this. I searched but can't find it.

 

I did some bows for minecraft.

 

package acidmod.functions;

import acidmod.ref;

import com.google.common.collect.Multimap;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;

public class addbow extends ItemBow {

@SideOnly(Side.CLIENT)
private Icon[] iconArray;

    private float bowDamage;
    private final EnumToolMaterial toolMaterial;
    public static final String[] bowPullIconNameArray = new String[] {"pulling_0", "pulling_1", "pulling_2"};

public addbow(int uid, String str, EnumToolMaterial material) {
	super(uid);

	this.toolMaterial = material;
	this.setCreativeTab(CreativeTabs.tabCombat);
	this.setUnlocalizedName(str);
	this.setMaxDamage(material.getMaxUses());
	this.setMaxStackSize(1);
	this.bowDamage = 4.0F + material.getDamageVsEntity();
}

    public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block)
    {
        if (par2Block.blockID == Block.web.blockID)
        {
            return 15.0F;
        }
        else
        {
            Material material = par2Block.blockMaterial;
            return material != Material.plants && material != Material.vine && material != Material.coral && material != Material.leaves && material != Material.pumpkin ? 1.0F : 1.5F;
        }
    }

@SideOnly(Side.CLIENT)
@Override
    public void registerIcons(IconRegister reg)
    {
	this.itemIcon = reg.registerIcon(ref.uid + ":" + (this.getUnlocalizedName().substring(5)) + "_standby");
        this.iconArray = new Icon[bowPullIconNameArray.length];

        for (int i = 0; i < this.iconArray.length; ++i) {
        	this.iconArray[i] = reg.registerIcon(ref.uid + ":" + (this.getUnlocalizedName().substring(5)) + "_" + bowPullIconNameArray[i]);
        }
    }

    public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack)
    {
        return this.toolMaterial.getToolCraftingMaterial() == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack);
    }

public Multimap getItemAttributeModifiers()
    {
        Multimap multimap = super.getItemAttributeModifiers();
        multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Bow modifier", (double)this.bowDamage, 0));
        return multimap;
    }
    
}

 

	this.stoneBow = new addbow(stoneBowID, "stonebow", EnumToolMaterial.STONE);
	this.ironBow = new addbow(ironBowID, "ironbow", EnumToolMaterial.IRON);
	this.goldBow = new addbow(goldBowID, "goldbow", EnumToolMaterial.GOLD);
	this.diamondBow = new addbow(diamondBowID, "diamondbow", EnumToolMaterial.EMERALD);

 

Every think works correctly, but when I attack some mobs with bow, it kill 3 times, and with diamond 3 times, too. So I think damage doesn't works correctly, and how can I see, how many damages do mobs take? or how can I fix?

Link to comment
Share on other sites

Arrows have fixed damage.  You have to find the part where the arrow is created and modify its damage there.

For a block I made that acted like a dispenser, I wanted to increase the damage from arrows, ended up with this:

[cope]        EntityArrow entityarrow = new EntityArrow(par1World, par2IPosition.getX(), par2IPosition.getY(), par2IPosition.getZ());
        entityarrow.canBePickedUp = 1;
        entityarrow.setDamage(6);

 

ItemBow should have a function that handles the creation of the arrow and adding it to the world, just override that function and apply the damage you want.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Thanks for answer, I try to fix now :)

 

Thanks for your help, I fixed it. Maybe someone wants to know how can I fix;

 

package acidmod.functions;

import acidmod.ref;

import com.google.common.collect.Multimap;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.EnumAction;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.ArrowLooseEvent;
import net.minecraftforge.event.entity.player.ArrowNockEvent;

public class addbow extends ItemBow {

@SideOnly(Side.CLIENT)
private Icon[] iconArray;

    private float bowDamage;
    private final EnumToolMaterial toolMaterial;
    public static final String[] bowPullIconNameArray = new String[] {"pulling_0", "pulling_1", "pulling_2"};

public addbow(int uid, String str, EnumToolMaterial material) {
	super(uid);

	this.toolMaterial = material;
	this.setCreativeTab(CreativeTabs.tabCombat);
	this.setUnlocalizedName(str);
	this.setMaxDamage(material.getMaxUses());
	this.setMaxStackSize(1);
	this.bowDamage = (4.0F + material.getDamageVsEntity()) / 2;
}

    public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block)
    {
        if (par2Block.blockID == Block.web.blockID)
        {
            return 15.0F;
        }
        else
        {
            Material material = par2Block.blockMaterial;
            return material != Material.plants && material != Material.vine && material != Material.coral && material != Material.leaves && material != Material.pumpkin ? 1.0F : 1.5F;
        }
    }

@SideOnly(Side.CLIENT)
@Override
    public void registerIcons(IconRegister reg)
    {
	this.itemIcon = reg.registerIcon(ref.uid + ":" + (this.getUnlocalizedName().substring(5)) + "_standby");
        this.iconArray = new Icon[bowPullIconNameArray.length];

        for (int i = 0; i < this.iconArray.length; ++i) {
        	this.iconArray[i] = reg.registerIcon(ref.uid + ":" + (this.getUnlocalizedName().substring(5)) + "_" + bowPullIconNameArray[i]);
        }
    }

    public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4) {
    	int j = this.getMaxItemUseDuration(par1ItemStack) - par4;

        ArrowLooseEvent event = new ArrowLooseEvent(par3EntityPlayer, par1ItemStack, j);
        MinecraftForge.EVENT_BUS.post(event);
        if (event.isCanceled()) {
            return;
        }
        j = event.charge;
        
        boolean flag = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0;

        if (flag || par3EntityPlayer.inventory.hasItem(Item.arrow.itemID)) {
            float f = (float)j / 20.0F;
            f = (f * f + f * 2.0F) / 3.0F;

            if ((double)f < 0.1D) {
                return;
            }

            if (f > 1.0F) {
                f = 1.0F;
            }

            EntityArrow entityarrow = new EntityArrow(par2World, par3EntityPlayer, f * 2.0F);

            if (f == 1.0F) {
                entityarrow.setIsCritical(true);
            }

            int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack);
            float h = this.bowDamage;

            if (h + k > 0)
            {
            	if (k > 0) {
    				entityarrow.setDamage(entityarrow.getDamage() + (double)k * 0.5D + 0.5D + (double)h);
            	} else {
    				entityarrow.setDamage(entityarrow.getDamage() + (double)h);
            	}
            }

            int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack);

            if (l > 0)
            {
                entityarrow.setKnockbackStrength(l);
            }

            if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0)
            {
                entityarrow.setFire(100);
            }

            par1ItemStack.damageItem(1, par3EntityPlayer);
            par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);

            if (flag)
            {
                entityarrow.canBePickedUp = 2;
            }
            else
            {
                par3EntityPlayer.inventory.consumeInventoryItem(Item.arrow.itemID);
            }

            if (!par2World.isRemote)
            {
                par2World.spawnEntityInWorld(entityarrow);
            }
        }
    }

    public ItemStack onEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
        return par1ItemStack;
    }
    
    public int getMaxItemUseDuration(ItemStack par1ItemStack)
    {
        return 72000;
    }

    public EnumAction getItemUseAction(ItemStack par1ItemStack)
    {
        return EnumAction.bow;
    }

    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
        ArrowNockEvent event = new ArrowNockEvent(par3EntityPlayer, par1ItemStack);
        MinecraftForge.EVENT_BUS.post(event);
        if (event.isCanceled())
        {
            return event.result;
        }

        if (par3EntityPlayer.capabilities.isCreativeMode || par3EntityPlayer.inventory.hasItem(Item.arrow.itemID))
        {
            par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
        }

        return par1ItemStack;
    }

    public int getItemEnchantability()
    {
        return 1;
    }

    public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack)
    {
        return this.toolMaterial.getToolCraftingMaterial() == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack);
    }

public Multimap getItemAttributeModifiers()
    {
        Multimap multimap = super.getItemAttributeModifiers();
        multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Bow modifier", (double)this.bowDamage, 0));
        return multimap;
    }
    
}

 

I change power ench. code with;

 

            float h = this.bowDamage;

            if (h + k > 0)
            {
            	if (k > 0) {
    				entityarrow.setDamage(entityarrow.getDamage() + (double)k * 0.5D + 0.5D + (double)h);
            	} else {
    				entityarrow.setDamage(entityarrow.getDamage() + (double)h);
            	}
            }

 

But this was too much because all bows started to hit 1 times and I divide 2, bow damage;

 

	this.bowDamage = (4.0F + material.getDamageVsEntity()) / 2;

 

I know my eng. is not very well but I tried to explain how can you do.

 

Thanks for your help again. :)

Link to comment
Share on other sites

I don't know why you're averaging the bow damage with the enchantment damage, those should just add together.

 

entityarrow.setDamage(entityarrow.getDamage() + (double)(k+h));

 

Also, 4.0F + material.getDamageVsEntity() is waaay too high for a bow.  That's sword damage.  Dividing by 2 or even 4 would be prudent.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Yes you true, it can be together but when its together if you don't have ench. on weapon 0.5 added everytime, I can fix but I didn't want to change original settings :P

 

The problem with enchants being averaged with the regular damage is this:

 

If the regular damage is 5 and the enchantment of +1 damage is added to it, now your bow does 3 damage.

 

That's less than if it was unenchanted!

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.