Skip to content
Permalink
Browse files

Rework to use RandomChance LootConditions instead of weights.

Should more closely match the behaviour of the previous loot system.
Thanks to MysteryM for the idea.
  • Loading branch information...
Leviathan143 Leviathan143
Leviathan143 authored and Leviathan143 committed Dec 21, 2016
1 parent 0e3d7a9 commit ded35ec6dd16a0f2ccf5a2ba0846bc764587bac7
Showing with 85 additions and 62 deletions.
  1. +85 −62 src/main/java/crazypants/enderio/LootManager.java
@@ -65,82 +65,105 @@ public void onLootTableLoad(LootTableLoadEvent evt) {

if (evt.getName().equals(LootTableList.CHESTS_SIMPLE_DUNGEON)) {

lp.addEntry(createLootEntry(itemAlloy.getItem(), Alloy.DARK_STEEL.ordinal(), 1, 3, 25, Config.lootDarkSteel));
lp.addEntry(createLootEntry(itemConduitProbe.getItem(), 10, Config.lootItemConduitProbe));
lp.addEntry(createLootEntry(Items.QUARTZ, 3, 16, 25, Config.lootQuartz));
lp.addEntry(createLootEntry(Items.NETHER_WART, 1, 4, 20, Config.lootNetherWart));
lp.addEntry(createLootEntry(Items.ENDER_PEARL, 1, 2, 30, Config.lootEnderPearl));
lp.addEntry(createLootEntry(DarkSteelItems.itemDarkSteelSword, 10, Config.lootTheEnder));
lp.addEntry(createLootEntry(DarkSteelItems.itemDarkSteelBoots, 10, Config.lootDarkSteelBoots));
lp.addEntry(createLootCapacitor(15, true));
lp.addEntry(createLootCapacitor(15, true));
lp.addEntry(createLootCapacitor(15, true));
//175
} else if (evt.getName().equals(LootTableList.CHESTS_VILLAGE_BLACKSMITH)) {

lp.addEntry(createLootEntry(itemAlloy.getItem(), Alloy.ELECTRICAL_STEEL.ordinal(), 2, 6, 20, Config.lootElectricSteel));
lp.addEntry(createLootEntry(itemAlloy.getItem(), Alloy.REDSTONE_ALLOY.ordinal(), 3, 6, 35, Config.lootRedstoneAlloy));
lp.addEntry(createLootEntry(itemAlloy.getItem(), Alloy.DARK_STEEL.ordinal(), 3, 6, 35, Config.lootDarkSteel));
lp.addEntry(createLootEntry(itemAlloy.getItem(), Alloy.PULSATING_IRON.ordinal(), 1, 2, 30, Config.lootPhasedIron));
lp.addEntry(createLootEntry(itemAlloy.getItem(), Alloy.VIBRANT_ALLOY.ordinal(), 1, 2, 20, Config.lootPhasedGold));
lp.addEntry(createLootEntry(DarkSteelItems.itemDarkSteelSword, 1, 1, 25, Config.lootTheEnder));
lp.addEntry(createLootEntry(DarkSteelItems.itemDarkSteelBoots, 1, 1, 25, Config.lootDarkSteelBoots));
lp.addEntry(createLootCapacitor(10, true));
//200
} else if (evt.getName().equals(LootTableList.CHESTS_DESERT_PYRAMID)) {

lp.addEntry(createLootEntry(DarkSteelItems.itemDarkSteelSword, 20, Config.lootTheEnder));
lp.addEntry(createLootEntry(itemTravelStaff.getItem(), 10, Config.lootTravelStaff));
lp.addEntry(createLootCapacitor(25, true));
} else if (evt.getName().equals(LootTableList.CHESTS_JUNGLE_TEMPLE)) {

lp.addEntry(createLootEntry(DarkSteelItems.itemDarkSteelSword, 1, 1, 25, Config.lootTheEnder));
lp.addEntry(createLootEntry(itemTravelStaff.getItem(), 1, 1, 10, Config.lootTravelStaff));
lp.addEntry(createLootCapacitor(25, true));
lp.addEntry(createLootCapacitor(25, true));
}
if (Config.lootDarkSteel) {
lp.addEntry(createLootEntry(itemAlloy.getItem(), Alloy.DARK_STEEL.ordinal(), 1, 3, 0.25F));
}
if (Config.lootItemConduitProbe) {
lp.addEntry(createLootEntry(itemConduitProbe.getItem(), 0.10F));
}
if (Config.lootQuartz) {
lp.addEntry(createLootEntry(Items.QUARTZ, 3, 16, 0.25F));
}
if (Config.lootNetherWart) {
lp.addEntry(createLootEntry(Items.NETHER_WART, 1, 4, 0.20F));
}
if (Config.lootEnderPearl) {
lp.addEntry(createLootEntry(Items.ENDER_PEARL, 1, 2, 0.30F));
}
if (Config.lootTheEnder) {
lp.addEntry(createLootEntry(DarkSteelItems.itemDarkSteelSword, 0.1F));
}
if (Config.lootDarkSteelBoots) {
lp.addEntry(createLootEntry(DarkSteelItems.itemDarkSteelBoots, 0.1F));
}
lp.addEntry(createLootCapacitor(0.15F));
lp.addEntry(createLootCapacitor(0.15F));
lp.addEntry(createLootCapacitor(0.15F));

} else if (evt.getName().equals(LootTableList.CHESTS_VILLAGE_BLACKSMITH)) {

if (Config.lootElectricSteel) {
lp.addEntry(createLootEntry(itemAlloy.getItem(), Alloy.ELECTRICAL_STEEL.ordinal(), 2, 6, 0.20F));
}
if (Config.lootRedstoneAlloy) {
lp.addEntry(createLootEntry(itemAlloy.getItem(), Alloy.REDSTONE_ALLOY.ordinal(), 3, 6, 0.35F));
}
if (Config.lootDarkSteel) {
lp.addEntry(createLootEntry(itemAlloy.getItem(), Alloy.DARK_STEEL.ordinal(), 3, 6, 0.35F));
}
if (Config.lootPhasedIron) {
lp.addEntry(createLootEntry(itemAlloy.getItem(), Alloy.PULSATING_IRON.ordinal(), 1, 2, 0.3F));
}
if (Config.lootPhasedGold) {
lp.addEntry(createLootEntry(itemAlloy.getItem(), Alloy.VIBRANT_ALLOY.ordinal(), 1, 2, 0.2F));
}
if (Config.lootTheEnder) {
lp.addEntry(createLootEntry(DarkSteelItems.itemDarkSteelSword, 1, 1, 0.25F));
}
if (Config.lootDarkSteelBoots) {
lp.addEntry(createLootEntry(DarkSteelItems.itemDarkSteelBoots, 1, 1, 0.25F));
}
lp.addEntry(createLootCapacitor(0.1F));

} else if (evt.getName().equals(LootTableList.CHESTS_DESERT_PYRAMID)) {

if (Config.lootTheEnder) {
lp.addEntry(createLootEntry(DarkSteelItems.itemDarkSteelSword, 0.2F));
}
if (Config.lootTravelStaff) {
lp.addEntry(createLootEntry(itemTravelStaff.getItem(), 0.1F));
}
lp.addEntry(createLootCapacitor(25));

} else if (evt.getName().equals(LootTableList.CHESTS_JUNGLE_TEMPLE)) {

if (Config.lootTheEnder) {
lp.addEntry(createLootEntry(DarkSteelItems.itemDarkSteelSword, 1, 1, 0.25F));
}
if (Config.lootTravelStaff) {
lp.addEntry(createLootEntry(itemTravelStaff.getItem(), 1, 1, 0.1F));
}
lp.addEntry(createLootCapacitor(0.25F));
lp.addEntry(createLootCapacitor(0.25F));
}
table.addPool(lp);
}

//Each loot entry in a pool must have a unique name
private int emptyCount = 0;
private LootEntry createLootEntry(Item item, int chance, boolean enabled) {
return createLootEntry(item, 1, 1, chance, enabled);
private LootEntry createLootEntry(Item item, float chance) {
return createLootEntry(item, 1, 1, chance);
}

private LootEntry createLootEntry(Item item, int minSize, int maxSize, int chance, boolean enabled) {
return createLootEntry(item, 0, minSize, maxSize, chance, enabled);
private LootEntry createLootEntry(Item item, int minSize, int maxSize, float chance) {
return createLootEntry(item, 0, minSize, maxSize, chance);
}

/**If enabled is true, an empty loot entry of the same weight is added.
*This maintains the generation probabilities of other EIO loot.
* Without this, disabling loot in the config would change the generation probabilities of other loot.
**/
private LootEntry createLootEntry(Item item, int ordinal, int minStackSize, int maxStackSize, int chance, boolean enabled) {
if(!enabled) {
emptyCount++;
return new LootEntryEmpty(chance, 1, NO_CONDITIONS, "empty" + emptyCount);
}

/*
* All loot entries are given the same weight, the generation probabilities depend on the RandomChance condition.
*/
private LootEntry createLootEntry(Item item, int ordinal, int minStackSize, int maxStackSize, float chance) {
LootCondition[] chanceCond = new LootCondition[]{new RandomChance(chance)};
if(item.isDamageable()) {
return new LootEntryItem(item, 1, 1, new LootFunction[]{setCount(minStackSize, maxStackSize), setDamage(ordinal)}, NO_CONDITIONS, item.getRegistryName().toString() + ":" + ordinal);
return new LootEntryItem(item, 1, 1, new LootFunction[]{setCount(minStackSize, maxStackSize), setDamage(ordinal)}, chanceCond, item.getRegistryName().toString() + ":" + ordinal);
}
else {
return new LootEntryItem(item, 1, 1, new LootFunction[]{setCount(minStackSize, maxStackSize), setMetadata(ordinal)}, NO_CONDITIONS, item.getRegistryName().toString() + "|empty:" + ordinal);
return new LootEntryItem(item, 1, 1, new LootFunction[]{setCount(minStackSize, maxStackSize), setMetadata(ordinal)}, chanceCond, item.getRegistryName().toString() + ":" + ordinal);
}
}

int capCount = 0; //Each loot entry in a pool must have a unique name
/**If enabled is true an empty loot entry of the same weight is added.
*This maintains the generation probabilities of other EIO loot.
* Without this, disabling loot in the config would change the generation probabilities of other loot.
**/
private LootEntry createLootCapacitor(int weight, boolean enabled) {
if(!enabled) {
return new LootEntryEmpty(weight, 1, NO_CONDITIONS, "empty" + emptyCount);

}
private LootEntry createLootCapacitor(float chance) {
capCount++;
return new LootEntryItem(itemBasicCapacitor.getItem(), weight, 1, new LootFunction[]{ls, setMetadata(3)}, NO_CONDITIONS, itemBasicCapacitor.getItem().getRegistryName().toString() + capCount);
return new LootEntryItem(itemBasicCapacitor.getItem(), 1, 1, new LootFunction[]{ls, setMetadata(3)}, new LootCondition[]{new RandomChance(chance)}, itemBasicCapacitor.getItem().getRegistryName().toString() + capCount);
}

private SetCount setCount(int min, int max) {

0 comments on commit ded35ec

Please sign in to comment.
You can’t perform that action at this time.