Fix type in LootEntry json name. And rename LootTable.finalize to freeze to avoid overriding Object function. Closes #2846 and #2847

This commit is contained in:
LexManos 2016-05-10 23:35:02 -07:00
parent 92800f61d3
commit 34d4b0b93f
3 changed files with 24 additions and 21 deletions

View file

@ -39,23 +39,23 @@
} }
+ //======================== FORGE START ============================================= + //======================== FORGE START =============================================
+ private boolean isFinalized = false; + private boolean isFrozen = false;
+ public void finalize() + public void freeze()
+ { + {
+ this.isFinalized = true; + this.isFrozen = true;
+ } + }
+ public boolean isFinalized(){ return this.isFinalized; } + public boolean isFrozen(){ return this.isFrozen; }
+ private void checkFinalized() + private void checkFrozen()
+ { + {
+ if (this.isFinalized()) + if (this.isFrozen())
+ throw new RuntimeException("Attempted to modify LootPool after being finalized!"); + throw new RuntimeException("Attempted to modify LootPool after being frozen!");
+ } + }
+ +
+ public String getName(){ return this.name; } + public String getName(){ return this.name; }
+ public RandomValueRange getRolls() { return this.field_186455_c; } + public RandomValueRange getRolls() { return this.field_186455_c; }
+ public RandomValueRange getBonusRolls() { return this.field_186456_d; } + public RandomValueRange getBonusRolls() { return this.field_186456_d; }
+ public void setRolls (RandomValueRange v){ checkFinalized(); this.field_186455_c = v; } + public void setRolls (RandomValueRange v){ checkFrozen(); this.field_186455_c = v; }
+ public void setBonusRolls(RandomValueRange v){ checkFinalized(); this.field_186456_d = v; } + public void setBonusRolls(RandomValueRange v){ checkFrozen(); this.field_186456_d = v; }
+ +
+ public LootEntry getEntry(String name) + public LootEntry getEntry(String name)
+ { + {
@ -66,7 +66,7 @@
+ } + }
+ public LootEntry removeEntry(String name) + public LootEntry removeEntry(String name)
+ { + {
+ checkFinalized(); + checkFrozen();
+ for (LootEntry entry : this.field_186453_a) + for (LootEntry entry : this.field_186453_a)
+ { + {
+ if (name.equals(entry.getEntryName())) + if (name.equals(entry.getEntryName()))
@ -79,7 +79,7 @@
+ } + }
+ public void addEntry(LootEntry entry) + public void addEntry(LootEntry entry)
+ { + {
+ checkFinalized(); + checkFrozen();
+ for (LootEntry e : this.field_186453_a) + for (LootEntry e : this.field_186453_a)
+ if (e == entry || e.getEntryName().equals(entry.getEntryName())) + if (e == entry || e.getEntryName().equals(entry.getEntryName()))
+ throw new RuntimeException("Attempted to add a duplicate entry to pool: " + e.getEntryName()); + throw new RuntimeException("Attempted to add a duplicate entry to pool: " + e.getEntryName());

View file

@ -19,17 +19,17 @@
} }
+ //======================== FORGE START ============================================= + //======================== FORGE START =============================================
+ private boolean isFinalized = false; + private boolean isFrozen = false;
+ public void finalize() + public void freeze()
+ { + {
+ this.isFinalized = true; + this.isFrozen = true;
+ for (LootPool pool : this.field_186466_c) + for (LootPool pool : this.field_186466_c)
+ pool.finalize(); + pool.freeze();
+ } + }
+ public boolean isFinalized(){ return this.isFinalized; } + public boolean isFrozen(){ return this.isFrozen; }
+ private void checkFinalized() + private void checkFrozen()
+ { + {
+ if (this.isFinalized()) + if (this.isFrozen())
+ throw new RuntimeException("Attempted to modify LootTable after being finalized!"); + throw new RuntimeException("Attempted to modify LootTable after being finalized!");
+ } + }
+ +
@ -45,7 +45,7 @@
+ +
+ public LootPool removePool(String name) + public LootPool removePool(String name)
+ { + {
+ checkFinalized(); + checkFrozen();
+ for (LootPool pool : this.field_186466_c) + for (LootPool pool : this.field_186466_c)
+ { + {
+ if (name.equals(pool.getName())) + if (name.equals(pool.getName()))
@ -60,7 +60,7 @@
+ +
+ public void addPool(LootPool pool) + public void addPool(LootPool pool)
+ { + {
+ checkFinalized(); + checkFrozen();
+ for (LootPool p : this.field_186466_c) + for (LootPool p : this.field_186466_c)
+ { + {
+ if (p == pool || p.getName().equals(pool.getName())) + if (p == pool || p.getName().equals(pool.getName()))

View file

@ -1021,6 +1021,9 @@ public class ForgeHooks
if (!custom) if (!custom)
ret = ForgeEventFactory.loadLootTable(name, ret); ret = ForgeEventFactory.loadLootTable(name, ret);
if (ret != null)
ret.freeze();
return ret; return ret;
} }
@ -1093,7 +1096,7 @@ public class ForgeHooks
ctx.entryCount++; ctx.entryCount++;
if (json.has("entryName")) if (json.has("entryName"))
return ctx.validateEntryName(JsonUtils.getString(json, "EntryName")); return ctx.validateEntryName(JsonUtils.getString(json, "entryName"));
if (ctx.custom) if (ctx.custom)
return "custom#" + json.hashCode(); //We don't care about custom ones modders shouldn't be editing them! return "custom#" + json.hashCode(); //We don't care about custom ones modders shouldn't be editing them!