Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
Added a try catch for the main loot pool in chests
Browse files Browse the repository at this point in the history
  • Loading branch information
Wehavecookies56 committed Jul 28, 2016
1 parent 80db7e2 commit 2ee571d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
21 changes: 11 additions & 10 deletions src/main/java/uk/co/wehavecookies56/kk/api/munny/MunnyRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
*/
public class MunnyRegistry {

public static Map<ItemStack, Integer> munnyValues = new HashMap<ItemStack, Integer>();
public static Map<Item, Integer> munnyValues = new HashMap<Item, Integer>();
public static Map<String, Integer> materialValues = new HashMap<String, Integer>();

public static Logger apiLogger = LogManager.getFormatterLogger("kkMunnyAPI");

Expand All @@ -34,13 +35,13 @@ public class MunnyRegistry {
//addMunnyValue(orichalcum, 10000);
}

public static boolean addMunnyValue(ItemStack item, int value) {
public static boolean addMunnyValue(Item item, int value) {
if (!munnyValues.containsKey(item)) {
munnyValues.put(item, value);
apiLogger.log(Level.INFO, "Registered %s munny value.", item.getDisplayName());
apiLogger.log(Level.INFO, "Registered %s munny value.", new ItemStack(item).getDisplayName());
return true;
} else {
apiLogger.log(Level.WARN, "Item %s has already had a munny value registered.", item.getDisplayName());
apiLogger.log(Level.WARN, "Item %s has already had a munny value registered.", new ItemStack(item).getDisplayName());
return false;
}
}
Expand All @@ -50,16 +51,16 @@ public static boolean addMunnyValueFromOreDict(String name, int value) {
if (oreStacks.isEmpty()) {
return false;
} else {
/*List<Item> items = new ArrayList<Item>();
List<Item> items = new ArrayList<Item>();
for (int i = 0; i < oreStacks.size(); i++) {
items.add(oreStacks.get(i).getItem());
}*/
}
for (int i = 0; i < oreStacks.size(); i++) {
if (!munnyValues.containsKey(oreStacks.get(i))) {
munnyValues.put(oreStacks.get(i), value);
apiLogger.log(Level.INFO, "Registered %s munny value.", oreStacks.get(i).getDisplayName());
if (!munnyValues.containsKey(items.get(i))) {
munnyValues.put(items.get(i), value);
apiLogger.log(Level.INFO, "Registered %s munny value.", new ItemStack(items.get(i)).getDisplayName());
} else {
apiLogger.log(Level.WARN, "Item %s has already had a munny value registered.", oreStacks.get(i).getDisplayName());
apiLogger.log(Level.WARN, "Item %s has already had a munny value registered.", new ItemStack(items.get(i)).getDisplayName());
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ public void onEntityItemPickUp (EntityItemPickupEvent event) {

@SubscribeEvent
public void addTooltip (ItemTooltipEvent event) {
if (MunnyRegistry.munnyValues.containsKey(new ItemStack(event.getItemStack().getItem()))) {
event.getToolTip().add(TextFormatting.YELLOW + "Munny: " + MunnyRegistry.munnyValues.get(new ItemStack(event.getItemStack().getItem())));
if (MunnyRegistry.munnyValues.containsKey(event.getItemStack().getItem())) {
event.getToolTip().add(TextFormatting.YELLOW + "Munny: " + MunnyRegistry.munnyValues.get(event.getItemStack().getItem()));
}
//TODO Localize all this
if (event.getItemStack().getItem() instanceof ItemKeyblade) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ public void loadLoot(LootTableLoadEvent event) {
event.getTable().addPool(musicDiscPool);
break;
}
LootPool main = event.getTable().getPool("main");
main.addEntry(new LootEntryItem(ModItems.Recipe, 5, 10, new LootFunction[0], new LootCondition[0], Reference.MODID + ":" + ModItems.Recipe.getUnlocalizedName().substring(5)));
try {
LootPool main = event.getTable().getPool("main");
main.addEntry(new LootEntryItem(ModItems.Recipe, 5, 10, new LootFunction[0], new LootCondition[0], Reference.MODID + ":" + ModItems.Recipe.getUnlocalizedName().substring(5)));
} catch (NullPointerException e) {
LootEntry[] recipeEntry = {new LootEntryItem(ModItems.Recipe, 5, 10, new LootFunction[0], new LootCondition[0], Reference.MODID + ":" + ModItems.Recipe.getUnlocalizedName().substring(5))};
LootPool main = new LootPool(recipeEntry, new LootCondition[0], new RandomValueRange(1, 2), new RandomValueRange(0, 0), "kk_recipes");
}
LootPool materialPool = new LootPool(materialEntries, new LootCondition[0], new RandomValueRange(1), new RandomValueRange(0), "kk_loot_rare_materials");
event.getTable().addPool(materialPool);
}
Expand Down

0 comments on commit 2ee571d

Please sign in to comment.