Jump to content

[SOLVED][1.7.10]Manipulating damage when a certain item is in players inventory.


OwnAgePau

Recommended Posts

So I have made a few items that will manipulate the damage done to or by the player and I have succesfully made a check that checks whether this is the case.

I want to check how much damage is done (in both cases) and decrease or increase the total damage by half the amount.

 

Item A is there to increase the damage done by the player to other entities by 50%. - The Black Diamond Ring in this case.

Item B is there to decrease the damage done to the player by other entities by 50%.

 

To do this I thought it would be best to do this in a forge event and the entityAttacked(LivingAttackEvent event) seemed perfect for that.

 

So far I have not found a way to alter the amount of damage done by that specific attack so I made it so the entity is attacked another time but now its damageSource is "bonus magic" so that the event wont trigger my check.

 

My code to do this so far:

@SubscribeEvent
    public void entityAttacked(LivingAttackEvent event){
if(event.entityLiving.worldObj.isRemote){
       if(!(event.entityLiving instanceof EntityPlayer)){
              EntityLiving attackedEnt = (EntityLiving) event.entityLiving;
      DamageSource attackSource = event.source;
      Entity player = event.source.getEntity();
              if(player instanceof EntityPlayer){
                     EntityPlayer thePlayer = (EntityPlayer)player;
                     if("generic".equals(attackSource.damageType) || "magic".equals(attackSource.damageType) || 
		    "player".equals(attackSource.damageType)){
	            if(this.checkPlayerHasAmulet(thePlayer)){
		           System.out.println("Normal Damage : " + event.ammount);
		           System.out.println("Bonus Damage from Ring : " + event.ammount / 2);
		           attackedEnt.attackEntityFrom(new DamageSource("bonus magic"), event.ammount / 2);
		    }
	     }
              }
       }
}
}

private boolean checkPlayerHasAmulet(EntityPlayer player){
ItemStack[] inventoryPlayer = player.inventory.mainInventory;
for(int i = 0; i < inventoryPlayer.length;i++){
    ItemStack stack = inventoryPlayer[i];
    if(stack != null){
	if(stack.stackSize > 0){
	    Item item = stack.getItem();
	    // Check if Black Diamond Ring is in your hotbar
	    if(item.equals(SoulItems.BlackdiamondAmuletRing.get()) && i < 9){
		item.setDamage(stack, item.getDamage(stack) + 1);
		return true;
	    }
	}
    }
}
return true;
    }

 

As you can probably see I now attack the entity with half the event.ammount (which is always 0.5, or in cases of a critical attack 0.75) as somehow the event.ammount is always 1, it seems it uses the base player damage or something.

 

Is there any way to check how much damage is actually done? And is there perhaps an easier way to go about doing this?

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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