@SubscribeEvent public void handleBounty(LootingLevelEvent event) { EntityLivingBase target = event.getEntityLiving(); EntityLivingBase attacker = target.getAttackingEntity(); if (attacker instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) attacker; Collection<PotionEffect> potions = player.getActivePotionEffects(); for (PotionEffect potion : potions) { if (potion.getPotion() instanceof PotionHunt) { PotionHunt huntPotion = (PotionHunt) potion.getPotion(); if (huntPotion.appliesTo(target)) { event.setLootingLevel(event.getLootingLevel() + 2); return; } } } } }
@SubscribeEvent public void addLooting(LootingLevelEvent event){ DamageSource source = event.getDamageSource(); Entity attacker = source.getSourceOfDamage(); final int prevLooting = event.getLootingLevel(); int looting = 0; if(attacker !=null){ if(attacker instanceof EntityPlayer){ EntityPlayer player = (EntityPlayer)attacker; ItemStack hand = player.getHeldItemMainhand(); if(ItemStackTools.isValid(hand)){ UpgradeData lapis = BatHelper.getBatUpgradeData(hand, ModBats.LAPIS); if(lapis !=null){ looting+=(int) ModBats.LAPIS.getValue(lapis); } } } } event.setLootingLevel(prevLooting+looting); }
@SubscribeEvent public void onEntityLooted(LootingLevelEvent event) { EntityLivingBase target = event.getEntityLiving(); BlockPos pos = target.getPosition(); int lootingBonus = 0; for (int x = -16; x <= 16; x++) for (int z = -16; z <= 16; z++) for (int y = -8; y <= 8; y++) if (target.world.getBlockState(pos.add(x, y, z)).getBlock() == Blocks.BEACON) { Block block = target.world.getBlockState(pos.add(x, y, z).down()).getBlock(); if (block == Blocks.IRON_BLOCK) lootingBonus = Math.max(lootingBonus, 1); else if (block == Blocks.GOLD_BLOCK) lootingBonus = Math.max(lootingBonus, 2); else if (block == Blocks.DIAMOND_BLOCK) lootingBonus = Math.max(lootingBonus, 3); else if (block == Blocks.EMERALD_BLOCK) lootingBonus = Math.max(lootingBonus, 4); } event.setLootingLevel(event.getLootingLevel() + lootingBonus); }
@SubscribeEvent public void looting(LootingLevelEvent event) { if(event.getDamageSource() instanceof TF2DamageSource) { event.setLootingLevel(event.getLootingLevel() + (int) TF2Attribute.getModifier("Looting",((TF2DamageSource) event.getDamageSource()).getWeapon(),0,(EntityLivingBase) event.getDamageSource().getTrueSource())); } }
@SubscribeEvent public void onLootingLevel(LootingLevelEvent event) { if (!event.getEntity().worldObj.isRemote) { if (event.getDamageSource() instanceof EntityDamageSource) { EntityDamageSource source = (EntityDamageSource) event.getDamageSource(); if (source.getEntity() instanceof EntitySourceBomb) { event.setLootingLevel(1); } } } }
public static int getLootingLevel(EntityLivingBase target, DamageSource cause, int level) { LootingLevelEvent event = new LootingLevelEvent(target, cause, level); MinecraftForge.EVENT_BUS.post(event); return event.getLootingLevel(); }