From 34d4b0b93f90793dd06376f804ea2ff55579b61b Mon Sep 17 00:00:00 2001 From: LexManos Date: Tue, 10 May 2016 23:35:02 -0700 Subject: [PATCH] Fix type in LootEntry json name. And rename LootTable.finalize to freeze to avoid overriding Object function. Closes #2846 and #2847 --- .../world/storage/loot/LootPool.java.patch | 22 +++++++++---------- .../world/storage/loot/LootTable.java.patch | 18 +++++++-------- .../net/minecraftforge/common/ForgeHooks.java | 5 ++++- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/patches/minecraft/net/minecraft/world/storage/loot/LootPool.java.patch b/patches/minecraft/net/minecraft/world/storage/loot/LootPool.java.patch index e6fd85c7f..3ca7df40d 100644 --- a/patches/minecraft/net/minecraft/world/storage/loot/LootPool.java.patch +++ b/patches/minecraft/net/minecraft/world/storage/loot/LootPool.java.patch @@ -39,23 +39,23 @@ } + //======================== FORGE START ============================================= -+ private boolean isFinalized = false; -+ public void finalize() ++ private boolean isFrozen = false; ++ public void freeze() + { -+ this.isFinalized = true; ++ this.isFrozen = true; + } -+ public boolean isFinalized(){ return this.isFinalized; } -+ private void checkFinalized() ++ public boolean isFrozen(){ return this.isFrozen; } ++ private void checkFrozen() + { -+ if (this.isFinalized()) -+ throw new RuntimeException("Attempted to modify LootPool after being finalized!"); ++ if (this.isFrozen()) ++ throw new RuntimeException("Attempted to modify LootPool after being frozen!"); + } + + public String getName(){ return this.name; } + public RandomValueRange getRolls() { return this.field_186455_c; } + public RandomValueRange getBonusRolls() { return this.field_186456_d; } -+ public void setRolls (RandomValueRange v){ checkFinalized(); this.field_186455_c = v; } -+ public void setBonusRolls(RandomValueRange v){ checkFinalized(); this.field_186456_d = v; } ++ public void setRolls (RandomValueRange v){ checkFrozen(); this.field_186455_c = v; } ++ public void setBonusRolls(RandomValueRange v){ checkFrozen(); this.field_186456_d = v; } + + public LootEntry getEntry(String name) + { @@ -66,7 +66,7 @@ + } + public LootEntry removeEntry(String name) + { -+ checkFinalized(); ++ checkFrozen(); + for (LootEntry entry : this.field_186453_a) + { + if (name.equals(entry.getEntryName())) @@ -79,7 +79,7 @@ + } + public void addEntry(LootEntry entry) + { -+ checkFinalized(); ++ checkFrozen(); + for (LootEntry e : this.field_186453_a) + if (e == entry || e.getEntryName().equals(entry.getEntryName())) + throw new RuntimeException("Attempted to add a duplicate entry to pool: " + e.getEntryName()); diff --git a/patches/minecraft/net/minecraft/world/storage/loot/LootTable.java.patch b/patches/minecraft/net/minecraft/world/storage/loot/LootTable.java.patch index 915e80435..ec673e536 100644 --- a/patches/minecraft/net/minecraft/world/storage/loot/LootTable.java.patch +++ b/patches/minecraft/net/minecraft/world/storage/loot/LootTable.java.patch @@ -19,17 +19,17 @@ } + //======================== FORGE START ============================================= -+ private boolean isFinalized = false; -+ public void finalize() ++ private boolean isFrozen = false; ++ public void freeze() + { -+ this.isFinalized = true; ++ this.isFrozen = true; + for (LootPool pool : this.field_186466_c) -+ pool.finalize(); ++ pool.freeze(); + } -+ public boolean isFinalized(){ return this.isFinalized; } -+ private void checkFinalized() ++ public boolean isFrozen(){ return this.isFrozen; } ++ private void checkFrozen() + { -+ if (this.isFinalized()) ++ if (this.isFrozen()) + throw new RuntimeException("Attempted to modify LootTable after being finalized!"); + } + @@ -45,7 +45,7 @@ + + public LootPool removePool(String name) + { -+ checkFinalized(); ++ checkFrozen(); + for (LootPool pool : this.field_186466_c) + { + if (name.equals(pool.getName())) @@ -60,7 +60,7 @@ + + public void addPool(LootPool pool) + { -+ checkFinalized(); ++ checkFrozen(); + for (LootPool p : this.field_186466_c) + { + if (p == pool || p.getName().equals(pool.getName())) diff --git a/src/main/java/net/minecraftforge/common/ForgeHooks.java b/src/main/java/net/minecraftforge/common/ForgeHooks.java index adcdd6c00..4ef224e53 100644 --- a/src/main/java/net/minecraftforge/common/ForgeHooks.java +++ b/src/main/java/net/minecraftforge/common/ForgeHooks.java @@ -1021,6 +1021,9 @@ public class ForgeHooks if (!custom) ret = ForgeEventFactory.loadLootTable(name, ret); + if (ret != null) + ret.freeze(); + return ret; } @@ -1093,7 +1096,7 @@ public class ForgeHooks ctx.entryCount++; if (json.has("entryName")) - return ctx.validateEntryName(JsonUtils.getString(json, "EntryName")); + return ctx.validateEntryName(JsonUtils.getString(json, "entryName")); if (ctx.custom) return "custom#" + json.hashCode(); //We don't care about custom ones modders shouldn't be editing them!