Search in sources :

Example 6 with LootFunction

use of net.minecraft.world.storage.loot.functions.LootFunction in project Random-Things by lumien231.

the class RTEventHandler method loadLootTable.

@SubscribeEvent
public void loadLootTable(LootTableLoadEvent event) {
    LootTable table = event.getTable();
    if (event.getName().equals(LootTableList.CHESTS_SIMPLE_DUNGEON)) {
        if (Worldgen.LAVA_CHARM)
            addSingleItemWithChance("lavaCharm", table, ModItems.lavaCharm, 0.1f);
        if (Worldgen.SUMMONING_PENDULUM)
            addSingleItemWithChance("summoningPendulum", table, ModItems.summoningPendulum, 0.1f);
        if (Worldgen.MAGIC_HOOD)
            addSingleItemWithChance("magicHood", table, ModItems.magicHood, 0.15f);
        if (Worldgen.SLIME_CUBE)
            addSingleItemWithChance("slimeCube", table, Item.getItemFromBlock(ModBlocks.slimeCube), 0.3f);
    } else if (Worldgen.LAVA_CHARM && event.getName().equals(LootTableList.CHESTS_NETHER_BRIDGE)) {
        addSingleItemWithChance("lavaCharm", table, ModItems.lavaCharm, 0.3f);
    } else if (Worldgen.MAGIC_HOOD && event.getName().equals(LootTableList.CHESTS_VILLAGE_BLACKSMITH)) {
        addSingleItemWithChance("magicHood", table, ModItems.magicHood, 0.02f);
    } else if (Worldgen.SUMMONING_PENDULUM && event.getName().equals(LootTableList.CHESTS_STRONGHOLD_CORRIDOR)) {
        addSingleItemWithChance("summoningPendulum", table, ModItems.summoningPendulum, 0.5f);
    } else if (Worldgen.SLIME_CUBE && event.getName().equals(LootTableList.CHESTS_JUNGLE_TEMPLE)) {
        addSingleItemWithChance("slimeCube", table, Item.getItemFromBlock(ModBlocks.slimeCube), 0.8f);
    }
    if (Worldgen.BIOME_CRYSTAL && event.getName().toString().startsWith("minecraft:chests/")) {
        LootEntry crystalEntry = new LootEntryItem(ModItems.biomeCrystal, 1, 0, new LootFunction[] { new LootFunction(new LootCondition[] {}) {

            @Override
            public ItemStack apply(ItemStack stack, Random rand, LootContext context) {
                Object[] locationArray = Biome.REGISTRY.getKeys().toArray();
                ResourceLocation randomLocation = (ResourceLocation) locationArray[rand.nextInt(locationArray.length)];
                stack.setTagCompound(new NBTTagCompound());
                stack.getTagCompound().setString("biomeName", randomLocation.toString());
                return stack;
            }
        } }, new LootCondition[] {}, "randomthings:biomeCrystal");
        LootPool crystalPool = new LootPool(new LootEntry[] { crystalEntry }, new LootCondition[] { new RandomChance(0.2f) }, new RandomValueRange(1, 1), new RandomValueRange(0, 0), "randomthings:biomeCrystal");
        table.addPool(crystalPool);
    }
}
Also used : LootTable(net.minecraft.world.storage.loot.LootTable) LootContext(net.minecraft.world.storage.loot.LootContext) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) RandomChance(net.minecraft.world.storage.loot.conditions.RandomChance) LootEntryItem(net.minecraft.world.storage.loot.LootEntryItem) LootFunction(net.minecraft.world.storage.loot.functions.LootFunction) LootCondition(net.minecraft.world.storage.loot.conditions.LootCondition) LootEntry(net.minecraft.world.storage.loot.LootEntry) Random(java.util.Random) RandomValueRange(net.minecraft.world.storage.loot.RandomValueRange) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) LootPool(net.minecraft.world.storage.loot.LootPool) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 7 with LootFunction

use of net.minecraft.world.storage.loot.functions.LootFunction in project BiomesOPlenty by Glitchfiend.

the class LootTableEventHandler method onLootTableLoad.

@SubscribeEvent
public void onLootTableLoad(LootTableLoadEvent event) {
    if (event.getName().equals(LootTableList.CHESTS_NETHER_BRIDGE)) {
        LootPool main = event.getTable().getPool("main");
        if (main != null) {
            main.addEntry(new LootEntryItem(BOPItems.ash, 3, 6, new LootFunction[0], new LootCondition[0], "biomesoplenty:ash"));
            main.addEntry(new LootEntryItem(BOPItems.fleshchunk, 5, 5, new LootFunction[0], new LootCondition[0], "biomesoplenty:fleshchunk"));
        }
    }
    if (event.getName().equals(LootTableList.CHESTS_SPAWN_BONUS_CHEST)) {
        LootPool main = event.getTable().getPool("main");
        if (main != null) {
            main.addEntry(new LootEntryItem(BOPItems.pear, 4, 2, new LootFunction[0], new LootCondition[0], "biomesoplenty:pear"));
            main.addEntry(new LootEntryItem(BOPItems.peach, 4, 2, new LootFunction[0], new LootCondition[0], "biomesoplenty:peach"));
            main.addEntry(new LootEntryItem(BOPItems.persimmon, 4, 2, new LootFunction[0], new LootCondition[0], "biomesoplenty:persimmon"));
        }
    }
    if (event.getName().equals(LootTableList.GAMEPLAY_FISHING_JUNK)) {
        LootPool main = event.getTable().getPool("main");
        if (main != null) {
            main.addEntry(new LootEntryItem(new ItemStack(BOPBlocks.seaweed).getItem(), 7, 1, new LootFunction[0], new LootCondition[0], "biomesoplenty:seaweed"));
        }
    }
}
Also used : LootEntryItem(net.minecraft.world.storage.loot.LootEntryItem) LootFunction(net.minecraft.world.storage.loot.functions.LootFunction) LootPool(net.minecraft.world.storage.loot.LootPool) LootCondition(net.minecraft.world.storage.loot.conditions.LootCondition) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

LootCondition (net.minecraft.world.storage.loot.conditions.LootCondition)7 LootFunction (net.minecraft.world.storage.loot.functions.LootFunction)7 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)7 LootEntryItem (net.minecraft.world.storage.loot.LootEntryItem)6 LootPool (net.minecraft.world.storage.loot.LootPool)5 ItemStack (net.minecraft.item.ItemStack)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 RandomValueRange (net.minecraft.world.storage.loot.RandomValueRange)3 SetNBT (net.minecraft.world.storage.loot.functions.SetNBT)3 LootEntry (net.minecraft.world.storage.loot.LootEntry)2 LootTable (net.minecraft.world.storage.loot.LootTable)2 RandomChance (net.minecraft.world.storage.loot.conditions.RandomChance)2 CapturedMob (crazypants.enderio.util.CapturedMob)1 Random (java.util.Random)1 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)1 LootContext (net.minecraft.world.storage.loot.LootContext)1 SetCount (net.minecraft.world.storage.loot.functions.SetCount)1