From 3e175aa8e6ebb10f213581ca6a80b741b00082a2 Mon Sep 17 00:00:00 2001 From: mezz Date: Fri, 7 Apr 2017 22:09:28 -0700 Subject: [PATCH] Use improved Forge LootTableLoadEvent, remove hacky LootTableLoader --- gradle.properties | 2 +- src/main/java/forestry/Forestry.java | 2 +- .../java/forestry/core/EventHandlerCore.java | 17 +++--- .../forestry/core/loot/LootTableLoader.java | 57 ------------------- 4 files changed, 12 insertions(+), 66 deletions(-) delete mode 100644 src/main/java/forestry/core/loot/LootTableLoader.java diff --git a/gradle.properties b/gradle.properties index 098f061db..d207eec9d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ mcversion=1.11.2 -forgeversion=13.20.0.2262 +forgeversion=13.20.0.2279 mcp_mappings=snapshot_20161220 tesla_version=1.11-1.3.0.51 diff --git a/src/main/java/forestry/Forestry.java b/src/main/java/forestry/Forestry.java index 9797895ea..e5e250a55 100644 --- a/src/main/java/forestry/Forestry.java +++ b/src/main/java/forestry/Forestry.java @@ -54,7 +54,7 @@ import net.minecraftforge.fml.common.registry.GameRegistry; version = Constants.VERSION, guiFactory = "forestry.core.config.ForestryGuiConfigFactory", acceptedMinecraftVersions = "[1.11]", - dependencies = "required-after:forge@[13.20.0.2230,);" + dependencies = "required-after:forge@[13.20.0.2270,);" + "after:JEI@[4.3.0,);") // + "after:" + PluginIC2.modId + ";") public class Forestry { diff --git a/src/main/java/forestry/core/EventHandlerCore.java b/src/main/java/forestry/core/EventHandlerCore.java index 8e64ca731..96994dc6d 100755 --- a/src/main/java/forestry/core/EventHandlerCore.java +++ b/src/main/java/forestry/core/EventHandlerCore.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.core; +import java.net.URL; import java.util.Collection; import forestry.api.genetics.AlleleManager; @@ -18,7 +19,6 @@ import forestry.api.genetics.IBreedingTracker; import forestry.api.genetics.ISpeciesRoot; import forestry.core.config.Constants; import forestry.core.errors.ErrorStateRegistry; -import forestry.core.loot.LootTableLoader; import forestry.core.models.ModelBlockCached; import forestry.core.render.TextureManagerForestry; import forestry.plugins.PluginManager; @@ -107,12 +107,15 @@ public class EventHandlerCore { } ResourceLocation resourceLocation = new ResourceLocation(Constants.MOD_ID, event.getName().getResourcePath()); - LootTable forestryChestAdditions = LootTableLoader.loadBuiltinLootTable(resourceLocation); - if (forestryChestAdditions != null) { - for (String poolName : PluginManager.getLootPoolNames()) { - LootPool pool = forestryChestAdditions.getPool(poolName); - if (pool != null) { - event.getTable().addPool(pool); + URL url = EventHandlerCore.class.getResource("/assets/" + resourceLocation.getResourceDomain() + "/loot_tables/" + resourceLocation.getResourcePath() + ".json"); + if (url != null) { + LootTable forestryChestAdditions = event.getLootTableManager().getLootTableFromLocation(resourceLocation); + if (forestryChestAdditions != LootTable.EMPTY_LOOT_TABLE) { + for (String poolName : PluginManager.getLootPoolNames()) { + LootPool pool = forestryChestAdditions.getPool(poolName); + if (pool != null) { + event.getTable().addPool(pool); + } } } } diff --git a/src/main/java/forestry/core/loot/LootTableLoader.java b/src/main/java/forestry/core/loot/LootTableLoader.java deleted file mode 100644 index 2175d6aea..000000000 --- a/src/main/java/forestry/core/loot/LootTableLoader.java +++ /dev/null @@ -1,57 +0,0 @@ -package forestry.core.loot; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.net.URL; - -import com.google.common.base.Charsets; -import com.google.common.io.Resources; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonParseException; -import forestry.core.utils.Log; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.storage.loot.LootContext; -import net.minecraft.world.storage.loot.LootEntry; -import net.minecraft.world.storage.loot.LootPool; -import net.minecraft.world.storage.loot.LootTable; -import net.minecraft.world.storage.loot.LootTableManager; -import net.minecraft.world.storage.loot.RandomValueRange; -import net.minecraft.world.storage.loot.conditions.LootCondition; -import net.minecraft.world.storage.loot.conditions.LootConditionManager; -import net.minecraft.world.storage.loot.functions.LootFunction; -import net.minecraft.world.storage.loot.functions.LootFunctionManager; - -/** - * Copy of {@link LootTableManager} that can load Forestry's loot table additions. - * This is a workaround so I can load loot table jsons that have pools to be added to vanilla's chests. - * During {@link net.minecraftforge.event.LootTableLoadEvent} the world's lootTable is not set yet. - */ -public class LootTableLoader { - private static final Gson GSON_INSTANCE = (new GsonBuilder()).registerTypeAdapter(RandomValueRange.class, new RandomValueRange.Serializer()).registerTypeAdapter(LootPool.class, new LootPool.Serializer()).registerTypeAdapter(LootTable.class, new LootTable.Serializer()).registerTypeHierarchyAdapter(LootEntry.class, new LootEntry.Serializer()).registerTypeHierarchyAdapter(LootFunction.class, new LootFunctionManager.Serializer()).registerTypeHierarchyAdapter(LootCondition.class, new LootConditionManager.Serializer()).registerTypeHierarchyAdapter(LootContext.EntityTarget.class, new LootContext.EntityTarget.Serializer()).create(); - - @Nullable - public static LootTable loadBuiltinLootTable(ResourceLocation resource) { - URL url = LootTableLoader.class.getResource("/assets/" + resource.getResourceDomain() + "/loot_tables/" + resource.getResourcePath() + ".json"); - - if (url != null) { - String s; - - try { - s = Resources.toString(url, Charsets.UTF_8); - } catch (IOException ioexception) { - Log.warning("Couldn\'t load loot table " + resource + " from " + url, ioexception); - return LootTable.EMPTY_LOOT_TABLE; - } - - try { - return net.minecraftforge.common.ForgeHooks.loadLootTable(GSON_INSTANCE, resource, s, false); - } catch (JsonParseException jsonparseexception) { - Log.error("Couldn\'t load loot table " + resource + " from " + url, jsonparseexception); - return LootTable.EMPTY_LOOT_TABLE; - } - } else { - return null; - } - } -}