Guest User

Untitled

a guest
Apr 28th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1. package com.theishiopian.foragecraft.handler;
  2. import java.util.List;
  3.  
  4. import com.theishiopian.foragecraft.ForageCraftMod;
  5.  
  6. import net.minecraft.entity.player.EntityPlayer;
  7. import net.minecraft.item.ItemStack;
  8. import net.minecraft.util.ResourceLocation;
  9. import net.minecraft.world.World;
  10. import net.minecraft.world.WorldServer;
  11. import net.minecraft.world.storage.loot.LootContext;
  12. import net.minecraft.world.storage.loot.LootTable;
  13. import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent;
  14. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  15.  
  16. public class BlockForageHandler
  17. {
  18.     static List<ItemStack> list;
  19.  
  20.     @SubscribeEvent
  21.     public void blockBreak(HarvestDropsEvent event)
  22.     {
  23.         World world = event.getWorld();
  24.        
  25.         EntityPlayer player = event.getHarvester();
  26.        
  27.         //LootTable loottable = world.getLootTableManager().getLootTableFromLocation(ForageCraftMod.ForageTable.get(event.getState().getBlock()));
  28.        
  29.         LootTable loottable = world.getLootTableManager().getLootTableFromLocation(new ResourceLocation("foragecraft:loot_tables/dirt.json"));
  30.        
  31.         System.out.println(loottable.toString());
  32.        
  33.         LootContext.Builder context = new LootContext.Builder((WorldServer) world);
  34.  
  35.         event.getDrops().clear();
  36.        
  37.         if (player != null) {
  38.             context.withLuck(player.getLuck());
  39.             context.withPlayer(player);
  40.         }
  41.        
  42.         list = loottable.generateLootForPools(world.rand, context.build());
  43.        
  44.         System.out.println(list.toString());
  45.        
  46.         for (ItemStack itemstack : list)
  47.         {
  48.             event.getDrops().add(itemstack);
  49.            
  50.             System.out.println("adding item "+itemstack.getItem().toString());
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment