Jump to content

[SOLVED] [1.12.2] Syncing player capabilities in LivingDeathEvent


FlashHUN

Recommended Posts

I need to give the player Exp from my mod when they kill specific entities, however when the event fires, they don't get any exp. What am I doing wrong? The event is fired, everything works, but the EXP still doesn't get set to what it should be set to.

@SubscribeEvent
    public void onDeath(LivingDeathEvent event) {
    	Entity entity = event.getEntityLiving();
    	if (event.getSource().getTrueSource() instanceof EntityPlayer) {
    		Random rand = new Random();
    		EntityPlayer player = (EntityPlayer)event.getSource().getTrueSource();
    		if (entity instanceof EntityShinobi) {
    			EntityShinobi shinobi = (EntityShinobi)entity;
    			int i = rand.nextInt(17);
    			int r = rand.nextInt(1);
    			if (r == 0) {
    				player.getCapability(CapabilityMana.MANA_CAPABILITY, null).setExp(player.getCapability(CapabilityMana.MANA_CAPABILITY, null).getExp() + 150+i);
    				PacketHandler.INSTANCE.sendTo(new PacketExp(player), (EntityPlayerMP)player);
    				
    			}
    			else {
    				player.getCapability(CapabilityMana.MANA_CAPABILITY, null).setExp(player.getCapability(CapabilityMana.MANA_CAPABILITY, null).getExp() + 150-i);
    				PacketHandler.INSTANCE.sendTo(new PacketExp(player), (EntityPlayerMP)player);
    			}
    		}
    	}
    }

 

Edited by FlashHUN
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.



×
×
  • Create New...

Important Information

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