Add an event that allows to modify the looting level based on damage source

This commit is contained in:
Bernhard Bonigl committed 2016-07-03 15:19:31 +02:00
1 parent f58d1cae1a
commit 432e3ab08a
4 files changed
+52 -1

No files matched your search

@@ -1,6 +1,9 @@
package net.minecraftforge.debug;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.util.DamageSource;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.storage.loot.LootEntryItem;
import net.minecraft.world.storage.loot.LootPool;
@@ -9,6 +12,7 @@ import net.minecraft.world.storage.loot.conditions.LootCondition;
import net.minecraft.world.storage.loot.functions.LootFunction;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.LootTableLoadEvent;
import net.minecraftforge.event.entity.living.LootingLevelEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@@ -39,4 +43,13 @@ public class LootTablesDebug {
// Get rid of all building mats. Which is pool #3, index starts at 0, but 0 is named "main"
event.getTable().removePool("pool3");
}
@SubscribeEvent
public void lootingEvent(LootingLevelEvent event) {
// if the player shoots something with a projectile, use looting 3
DamageSource damageSource = event.getDamageSource();
if(damageSource.isProjectile() && damageSource.getEntity() instanceof EntityPlayer && damageSource.getSourceOfDamage() instanceof EntityArrow) {
event.setLootingLevel(3);
}
}
}