Search in sources :

Example 1 with LootContext

use of net.minecraft.world.storage.loot.LootContext in project MorePlanets by SteveKunG.

the class TileEntityTreasureChestMP method fillWithLoot.

protected void fillWithLoot(@Nullable EntityPlayer player) {
    if (this.lootTable != 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());
        }
        loottable.fillInventory(this, random, lootcontext$builder.build());
    }
}
Also used : LootTable(net.minecraft.world.storage.loot.LootTable) Random(java.util.Random) LootContext(net.minecraft.world.storage.loot.LootContext)

Example 2 with LootContext

use of net.minecraft.world.storage.loot.LootContext in project MorePlanets by SteveKunG.

the class TileEntityCrashedAlienProbe method fillWithLoot.

protected void fillWithLoot(@Nullable EntityPlayer player) {
    if (this.lootTable != 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());
        }
        loottable.fillInventory(this, random, lootcontext$builder.build());
    }
}
Also used : LootTable(net.minecraft.world.storage.loot.LootTable) Random(java.util.Random) LootContext(net.minecraft.world.storage.loot.LootContext)

Example 3 with LootContext

use of net.minecraft.world.storage.loot.LootContext in project MorePlanets by SteveKunG.

the class EntitySpaceFishHook method handleHookRetraction.

@Override
public int handleHookRetraction() {
    if (!this.world.isRemote && this.angler != null) {
        int i = 0;
        if (this.caughtEntity != null) {
            this.bringInHookedEntity();
            this.world.setEntityState(this, (byte) 31);
            i = this.caughtEntity instanceof EntityItem ? 3 : 5;
        } else if (this.ticksCatchable > 0) {
            LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer) this.world);
            lootcontext$builder.withLuck(this.luck + this.angler.getLuck());
            double x = MathHelper.floor(this.posX);
            double y = MathHelper.floor(this.getEntityBoundingBox().minY) + 1.0F;
            double z = MathHelper.floor(this.posZ);
            Block block = this.world.getBlockState(new BlockPos(x, y - 1, z)).getBlock();
            ResourceLocation resource = block instanceof IFishableLiquidBlock ? ((IFishableLiquidBlock) block).getLootTable() : this.world.provider instanceof IGalacticraftWorldProvider ? MPLootTables.SPACE_FISHING : LootTableList.GAMEPLAY_FISHING;
            List<ItemStack> result = this.world.getLootTableManager().getLootTableFromLocation(resource).generateLootForPools(this.rand, lootcontext$builder.build());
            for (ItemStack itemstack : result) {
                EntityItem entityitem = new EntityItem(this.world, this.posX, this.posY, this.posZ, itemstack);
                double d0 = this.angler.posX - this.posX;
                double d1 = this.angler.posY - this.posY;
                double d2 = this.angler.posZ - this.posZ;
                double d3 = MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
                entityitem.motionX = d0 * 0.1D;
                entityitem.motionY = d1 * 0.1D + MathHelper.sqrt(d3) * 0.08D;
                entityitem.motionZ = d2 * 0.1D;
                this.world.spawnEntity(entityitem);
                this.angler.world.spawnEntity(new EntityXPOrb(this.angler.world, this.angler.posX, this.angler.posY + 0.5D, this.angler.posZ + 0.5D, this.rand.nextInt(6) + 1));
                Item item = itemstack.getItem();
                if (item == Items.FISH || item == Items.COOKED_FISH) {
                    this.angler.addStat(StatList.FISH_CAUGHT, 1);
                }
            }
            i = 1;
        }
        if (this.inGround) {
            i = 2;
        }
        this.setDead();
        return i;
    } else {
        return 0;
    }
}
Also used : IFishableLiquidBlock(stevekung.mods.moreplanets.util.blocks.IFishableLiquidBlock) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) LootContext(net.minecraft.world.storage.loot.LootContext) WorldServer(net.minecraft.world.WorldServer) Item(net.minecraft.item.Item) EntityItem(net.minecraft.entity.item.EntityItem) ResourceLocation(net.minecraft.util.ResourceLocation) Block(net.minecraft.block.Block) IFishableLiquidBlock(stevekung.mods.moreplanets.util.blocks.IFishableLiquidBlock) StatList(net.minecraft.stats.StatList) LootTableList(net.minecraft.world.storage.loot.LootTableList) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) EntityXPOrb(net.minecraft.entity.item.EntityXPOrb)

Example 4 with LootContext

use of net.minecraft.world.storage.loot.LootContext in project ImmersiveEngineering by BluSunrize.

the class TileEntityWoodenCrate method onGuiOpened.

@Override
public void onGuiOpened(EntityPlayer player, boolean clientside) {
    if (this.lootTable != null && !clientside) {
        LootTable loottable = this.worldObj.getLootTableManager().getLootTableFromLocation(this.lootTable);
        this.lootTable = null;
        Random random;
        LootContext.Builder contextBuilder = new LootContext.Builder((WorldServer) this.worldObj);
        if (player != null)
            contextBuilder.withLuck(player.getLuck());
        LootContext context = contextBuilder.build();
        Random rand = new Random();
        List<ItemStack> list = loottable.generateLootForPools(rand, context);
        List<Integer> listSlots = Lists.newArrayList();
        for (int i = 0; i < inventory.length; i++) if (inventory[i] == null)
            listSlots.add(Integer.valueOf(i));
        Collections.shuffle(listSlots, rand);
        if (listSlots.isEmpty())
            return;
        Utils.shuffleLootItems(list, listSlots.size(), rand);
        for (ItemStack itemstack : list) {
            int slot = listSlots.remove(listSlots.size() - 1).intValue();
            inventory[slot] = itemstack;
        }
    }
}
Also used : LootTable(net.minecraft.world.storage.loot.LootTable) Random(java.util.Random) LootContext(net.minecraft.world.storage.loot.LootContext) ItemStack(net.minecraft.item.ItemStack) IComparatorOverride(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IComparatorOverride)

Aggregations

LootContext (net.minecraft.world.storage.loot.LootContext)4 Random (java.util.Random)3 LootTable (net.minecraft.world.storage.loot.LootTable)3 ItemStack (net.minecraft.item.ItemStack)2 IComparatorOverride (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IComparatorOverride)1 List (java.util.List)1 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)1 Block (net.minecraft.block.Block)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityXPOrb (net.minecraft.entity.item.EntityXPOrb)1 Item (net.minecraft.item.Item)1 StatList (net.minecraft.stats.StatList)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 WorldServer (net.minecraft.world.WorldServer)1 LootTableList (net.minecraft.world.storage.loot.LootTableList)1 IFishableLiquidBlock (stevekung.mods.moreplanets.util.blocks.IFishableLiquidBlock)1