public void fillWithLoot(@Nullable EntityPlayer player) { if (this.lootTable != null && this.world != null && this.world.getLootTableManager() != null) { LootTable loottable = this.world.getLootTableManager().getLootTableFromLocation(this.lootTable); this.lootTable = null; Random random; if (this.lootTableSeed == 0L) { random = new Random(); } else { random = new Random(this.lootTableSeed); } LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer) this.world); if (player != null) { lootcontext$builder.withLuck(player.getLuck()).withPlayer(player); // Forge: add player to LootContext } loottable.fillInventory(this, random, lootcontext$builder.build()); } }
@Override public @Nonnull EnumActionResult onItemUseFirst(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side, float hitX, float hitY, float hitZ, @Nonnull EnumHand hand) { if (world.isRemote || System.getProperty("INDEV") == null || !player.isCreative()) { return EnumActionResult.PASS; } TileEntity te = world.getTileEntity(pos); if (te instanceof TileEntityChest) { TileEntityChest chest = (TileEntityChest) te; chest.clear(); LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer) world); lootcontext$builder.withLuck(player.getLuck()); LootTable loottable = world.getLootTableManager().getLootTableFromLocation(LootTableList.CHESTS_SIMPLE_DUNGEON); // LootTable loottable = world.getLootTableManager().getLootTableFromLocation(LootTableList.CHESTS_IGLOO_CHEST); loottable.fillInventory(chest, world.rand, lootcontext$builder.build()); return EnumActionResult.PASS; } else { IBlockState blockState = world.getBlockState(pos); int meta = blockState.getBlock().getMetaFromState(blockState); player.sendMessage(new TextComponentString(blockState + " (" + meta + ")")); } return EnumActionResult.PASS; }
public static ItemStack getStack(World world, EntityPlayer player, ResourceLocation lootTable) { long lootTableSeed = world.rand.nextLong(); LootTable loottable = world.getLootTableManager().getLootTableFromLocation(lootTable); Random random; if (lootTableSeed == 0L) { random = new Random(); } else { random = new Random(lootTableSeed); } LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer)world); if (player != null) { lootcontext$builder.withLuck(player.getLuck()); } loottable.fillInventory(INVENTORY, random, lootcontext$builder.build()); ItemStack result = INVENTORY.getStackInSlot(0); if (result != null) result = result.copy(); INVENTORY.setInventorySlotContents(0, null); return result; } }