EntityDrop.java 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package me.km.effects.passive;
  2. import me.km.KajetansMod;
  3. import me.km.api.Module;
  4. import me.km.api.ModuleListener;
  5. import me.km.api.Utils;
  6. import me.km.effects.Effect;
  7. import me.km.effects.EffectUtils;
  8. import net.minecraft.entity.Entity;
  9. import net.minecraft.entity.item.EntityItem;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraftforge.event.entity.living.LivingDropsEvent;
  12. import net.minecraftforge.event.entity.living.LivingExperienceDropEvent;
  13. import net.minecraftforge.fml.common.eventhandler.EventPriority;
  14. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  15. public class EntityDrop extends ModuleListener
  16. {
  17. public EntityDrop(Module m)
  18. {
  19. super(m);
  20. }
  21. // low, due to changes with SnuviScript
  22. @SubscribeEvent(priority = EventPriority.LOW)
  23. public void onEntityDrop(LivingDropsEvent e)
  24. {
  25. if(!KajetansMod.worldManager.getWorldPreferences(e.getEntityLiving().world).skills)
  26. {
  27. return;
  28. }
  29. Entity killer = e.getSource().getImmediateSource();
  30. if(killer == null || !(killer instanceof EntityPlayer))
  31. {
  32. return;
  33. }
  34. EntityPlayer p = (EntityPlayer) killer;
  35. int drops = EffectUtils.getEffectLevel(p, Effect.MORE_DROPS);
  36. if(drops >= 1)
  37. {
  38. int random;
  39. for(EntityItem item : e.getDrops())
  40. {
  41. random = Utils.randomInt(-2, drops);
  42. if(random >= 1)
  43. {
  44. item.getItem().grow(random);
  45. }
  46. }
  47. }
  48. }
  49. // low, due to changes with SnuviScript
  50. @SubscribeEvent(priority = EventPriority.LOW)
  51. public void onEntityDropXp(LivingExperienceDropEvent e)
  52. {
  53. if(!KajetansMod.worldManager.getWorldPreferences(e.getEntityLiving().world).skills)
  54. {
  55. return;
  56. }
  57. EntityPlayer p = e.getAttackingPlayer();
  58. if(p == null)
  59. {
  60. return;
  61. }
  62. int xp = EffectUtils.getEffectLevel(p, Effect.XP_COLLECTOR);
  63. if(xp >= 1)
  64. {
  65. int i = e.getOriginalExperience();
  66. i *= 1 + xp / 5f;
  67. e.setDroppedExperience(i);
  68. }
  69. }
  70. }