Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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?

Guest
This topic is now closed to further replies.

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.