From 2afc7ba1244493a08531bf1b829345c637ef1a33 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 30 Oct 2016 20:28:02 +0100 Subject: [PATCH] Added back loot from 1.7.10 --- .../mod/ActuallyAdditions.java | 1 - .../mod/event/CommonEvents.java | 2 + .../mod/misc/DungeonLoot.java | 103 ++++++++++++++---- 3 files changed, 82 insertions(+), 24 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java index cce318417..8bf0b15e3 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java @@ -115,7 +115,6 @@ public class ActuallyAdditions{ TileEntityBase.init(); new CommonEvents(); InitCrafting.init(); - DungeonLoot.init(); InitEntities.init(); proxy.init(event); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java b/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java index cc74eeda5..59ade40a8 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java @@ -19,6 +19,7 @@ import de.ellpeck.actuallyadditions.mod.data.PlayerData; import de.ellpeck.actuallyadditions.mod.data.WorldData; import de.ellpeck.actuallyadditions.mod.items.InitItems; import de.ellpeck.actuallyadditions.mod.misc.ConnectionPair; +import de.ellpeck.actuallyadditions.mod.misc.DungeonLoot; import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay; import de.ellpeck.actuallyadditions.mod.util.ItemUtil; @@ -46,6 +47,7 @@ public class CommonEvents{ public CommonEvents(){ MinecraftForge.EVENT_BUS.register(this); + MinecraftForge.EVENT_BUS.register(new DungeonLoot()); } public static void checkAchievements(ItemStack gotten, EntityPlayer player, InitAchievements.Type type){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/DungeonLoot.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/DungeonLoot.java index 2c238b662..9129e0f5e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/DungeonLoot.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/DungeonLoot.java @@ -10,36 +10,93 @@ package de.ellpeck.actuallyadditions.mod.misc; +import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; +import de.ellpeck.actuallyadditions.mod.items.InitItems; +import de.ellpeck.actuallyadditions.mod.items.metalists.TheCrystals; +import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems; import de.ellpeck.actuallyadditions.mod.util.ModUtil; +import net.minecraft.item.Item; +import net.minecraft.world.storage.loot.LootEntryItem; +import net.minecraft.world.storage.loot.LootPool; +import net.minecraft.world.storage.loot.LootTableList; +import net.minecraft.world.storage.loot.RandomValueRange; +import net.minecraft.world.storage.loot.conditions.LootCondition; +import net.minecraft.world.storage.loot.functions.LootFunction; +import net.minecraft.world.storage.loot.functions.SetCount; +import net.minecraft.world.storage.loot.functions.SetMetadata; +import net.minecraftforge.event.LootTableLoadEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -//TODO Fix dungeon loot (oh god) -public final class DungeonLoot{ +public class DungeonLoot{ - public static void init(){ - if(ConfigBoolValues.DUNGEON_LOOT.isEnabled()){ - ModUtil.LOGGER.info("Initializing Dungeon Loot..."); + @SubscribeEvent + public void onLootTableLoad(LootTableLoadEvent event){ + if(ConfigBoolValues.DUNGEON_LOOT.isEnabled() && event.getName() != null && event.getTable() != null){ + boolean addCrystals = false; + boolean addDrillCore = false; + boolean addQuartz = false; + boolean addBatWings = false; + boolean addBook = false; - /*ChestGenHooks dungeon = ChestGenHooks.getInfo(ChestGenHooks.DUNGEON_CHEST); - ChestGenHooks mineshaft = ChestGenHooks.getInfo(ChestGenHooks.MINESHAFT_CORRIDOR); - ChestGenHooks blacksmith = ChestGenHooks.getInfo(ChestGenHooks.VILLAGE_BLACKSMITH); - - for(int i = 0; i < TheCrystals.values().length; i++){ - WeightedRandomChestContent item = new WeightedRandomChestContent(InitItems.itemCrystal, i, 2, 4, 5); - WeightedRandomChestContent block = new WeightedRandomChestContent(Item.getItemFromBlock(InitBlocks.blockCrystal), i, 1, 3, 1); - dungeon.addItem(item); - dungeon.addItem(block); - mineshaft.addItem(item); - mineshaft.addItem(block); + if(LootTableList.CHESTS_SIMPLE_DUNGEON.equals(event.getName())){ + addCrystals = true; + addDrillCore = true; + addQuartz = true; + } + else if(LootTableList.CHESTS_ABANDONED_MINESHAFT.equals(event.getName())){ + addCrystals = true; + addDrillCore = true; + } + else if(LootTableList.CHESTS_VILLAGE_BLACKSMITH.equals(event.getName())){ + addDrillCore = true; + addQuartz = true; + addBatWings = true; + addBook = true; + } + else if(LootTableList.CHESTS_STRONGHOLD_LIBRARY.equals(event.getName())){ + addBatWings = true; + addBook = true; + } + else if(LootTableList.CHESTS_IGLOO_CHEST.equals(event.getName())){ + addBatWings = true; } - WeightedRandomChestContent drillCore = new WeightedRandomChestContent(InitItems.itemMisc, TheMiscItems.DRILL_CORE.ordinal(), 1, 1, 3); - dungeon.addItem(drillCore); - mineshaft.addItem(drillCore); - blacksmith.addItem(drillCore); - WeightedRandomChestContent quartz = new WeightedRandomChestContent(InitItems.itemMisc, TheMiscItems.QUARTZ.ordinal(), 3, 4, 30); - dungeon.addItem(quartz); - blacksmith.addItem(quartz);*/ + LootPool pool = event.getTable().getPool("main"); + if(pool != null){ + LootCondition[] noCondition = new LootCondition[0]; + + if(addCrystals){ + LootFunction damage = new SetMetadata(noCondition, new RandomValueRange(0, TheCrystals.values().length-1)); + LootFunction amount = new SetCount(noCondition, new RandomValueRange(1, 3)); + LootFunction[] functions = new LootFunction[]{damage, amount}; + + pool.addEntry(new LootEntryItem(InitItems.itemCrystal, 50, 0, functions, noCondition, ModUtil.MOD_ID+":crystalItems")); + pool.addEntry(new LootEntryItem(Item.getItemFromBlock(InitBlocks.blockCrystal), 5, 0, functions, noCondition, ModUtil.MOD_ID+":crystalBlocks")); + } + + if(addDrillCore){ + LootFunction damage = new SetMetadata(noCondition, new RandomValueRange(TheMiscItems.DRILL_CORE.ordinal())); + pool.addEntry(new LootEntryItem(InitItems.itemMisc, 10, 0, new LootFunction[]{damage}, noCondition, ModUtil.MOD_ID+":drillCore")); + } + + if(addQuartz){ + LootFunction damage = new SetMetadata(noCondition, new RandomValueRange(TheMiscItems.QUARTZ.ordinal())); + LootFunction amount = new SetCount(noCondition, new RandomValueRange(1, 10)); + pool.addEntry(new LootEntryItem(InitItems.itemMisc, 80, 0, new LootFunction[]{damage, amount}, noCondition, ModUtil.MOD_ID+":quartz")); + } + + if(addBatWings){ + LootFunction damage = new SetMetadata(noCondition, new RandomValueRange(TheMiscItems.BAT_WING.ordinal())); + LootFunction amount = new SetCount(noCondition, new RandomValueRange(1, 2)); + pool.addEntry(new LootEntryItem(InitItems.itemMisc, 5, 0, new LootFunction[]{damage, amount}, noCondition, ModUtil.MOD_ID+":batWings")); + } + + if(addBook){ + LootFunction amount = new SetCount(noCondition, new RandomValueRange(1)); + pool.addEntry(new LootEntryItem(InitItems.itemBooklet, 100, 0, new LootFunction[]{amount}, noCondition, ModUtil.MOD_ID+":booklet")); + } + } } } }