Added LivingExperienceDropsEvent to change the amount of experience an entity drops

This commit is contained in:
Lumien 2015-04-14 00:09:42 +02:00
parent 5ac654dc1c
commit 81ab4cbc5f
3 changed files with 67 additions and 0 deletions

View file

@ -9,6 +9,15 @@
{
this.func_70078_a((Entity)null);
}
@@ -316,7 +316,7 @@
if (!this.field_70170_p.field_72995_K && (this.field_70718_bc > 0 || this.func_70684_aJ()) && this.func_146066_aG() && this.field_70170_p.func_82736_K().func_82766_b("doMobLoot"))
{
i = this.func_70693_a(this.field_70717_bb);
-
+ i = net.minecraftforge.event.ForgeEventFactory.getExperienceDrop(this, this.field_70717_bb, i);
while (i > 0)
{
int j = EntityXPOrb.func_70527_a(i);
@@ -377,6 +377,7 @@
{
this.field_70755_b = p_70604_1_;

View file

@ -43,6 +43,7 @@ import net.minecraftforge.event.entity.EntityMountEvent;
import net.minecraftforge.event.entity.EntityStruckByLightningEvent;
import net.minecraftforge.event.entity.PlaySoundAtEntityEvent;
import net.minecraftforge.event.entity.item.ItemExpireEvent;
import net.minecraftforge.event.entity.living.LivingExperienceDropEvent;
import net.minecraftforge.event.entity.living.LivingHealEvent;
import net.minecraftforge.event.entity.living.LivingPackSizeEvent;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
@ -143,6 +144,16 @@ public class ForgeEventFactory
MinecraftForge.EVENT_BUS.post(event);
return event.getResult();
}
public static int getExperienceDrop(EntityLivingBase entity, EntityPlayer attackingPlayer, int originalExperience)
{
LivingExperienceDropEvent event = new LivingExperienceDropEvent(entity, attackingPlayer, originalExperience);
if (MinecraftForge.EVENT_BUS.post(event))
{
return 0;
}
return event.getDroppedExperience();
}
public static List<BiomeGenBase.SpawnListEntry> getPotentialSpawns(WorldServer world, EnumCreatureType type, BlockPos pos, List<BiomeGenBase.SpawnListEntry> oldList)
{

View file

@ -0,0 +1,47 @@
package net.minecraftforge.event.entity.living;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
/**
* Event for when an entity drops experience on its death, can be used to change
* the amount of experience points dropped or completely prevent dropping of experience
* by canceling the event.
*/
@Cancelable
public class LivingExperienceDropEvent extends LivingEvent
{
final EntityPlayer attackingPlayer;
final int originalExperiencePoints;
int droppedExperiencePoints;
public LivingExperienceDropEvent(EntityLivingBase entity, EntityPlayer attackingPlayer, int originalExperience)
{
super(entity);
this.attackingPlayer = attackingPlayer;
this.originalExperiencePoints = this.droppedExperiencePoints = originalExperience;
}
public int getDroppedExperience()
{
return droppedExperiencePoints;
}
public void setDroppedExperience(int droppedExperience)
{
this.droppedExperiencePoints = droppedExperience;
}
public EntityPlayer getAttackingPlayer()
{
return attackingPlayer;
}
public int getOriginalExperience()
{
return originalExperiencePoints;
}
}