From 594ca864ed22b0de4e4df6fd69efd902be956a5d Mon Sep 17 00:00:00 2001 From: Aleksey-Terzi Date: Fri, 31 Jul 2015 09:50:06 +0300 Subject: [PATCH] Fix: possible crash when registering anvil recipes and OptiFine is not installed. --- build.gradle | 4 +-- build.prop | 2 +- src/com/aleksey/decorations/Core/Recipes.java | 31 ++++++++++--------- .../Handlers/ChunkEventHandler.java | 2 +- .../Network/InitClientWorldPacket.java | 2 +- .../Handlers/ServerTickHandler.java | 2 +- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/build.gradle b/build.gradle index ad60092..8f71591 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ buildscript { } configurations { - runtime.exclude group: "[1.7.10]TerraFirmaCraft-0.79.18.673" + runtime.exclude group: "[1.7.10]TerraFirmaCraft-0.79.21.741" } // define the properties file @@ -64,7 +64,7 @@ task copyJar(type: Copy) { tasks.build.dependsOn('copyJar') dependencies { - // Copy "[1.7.10]TerraFirmaCraft-0.79.18.673.jar" file + // Copy "[1.7.10]TerraFirmaCraft-0.79.21.741.jar" file // into the ./libs directory } diff --git a/build.prop b/build.prop index a0e45c1..6af1b69 100644 --- a/build.prop +++ b/build.prop @@ -1,5 +1,5 @@ minecraft_version=1.7.10 -forge_version=10.13.2.1291 +forge_version=10.13.4.1448-1.7.10 mod_version=1.0.19 group_name=com.aleksey.decorations archive_name=[1.7.10]Decorations \ No newline at end of file diff --git a/src/com/aleksey/decorations/Core/Recipes.java b/src/com/aleksey/decorations/Core/Recipes.java index 56d029c..82d47fe 100644 --- a/src/com/aleksey/decorations/Core/Recipes.java +++ b/src/com/aleksey/decorations/Core/Recipes.java @@ -6,6 +6,7 @@ import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.world.World; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.oredict.ShapelessOreRecipe; @@ -134,22 +135,24 @@ public static boolean areAnvilRecipesRegistered() return map.containsKey(_lanternCorePlan); } - public static void registerAnvilRecipes() + public static void registerAnvilRecipes(World world) { - if(DecorationsMod.isLanternsEnabled) + if(!DecorationsMod.isLanternsEnabled) + return; + + AnvilManager manager = AnvilManager.getInstance(); + //We need to set the world ref so that all anvil recipes can generate correctly + AnvilManager.world = world; + + manager.addPlan(_lanternCorePlan, new PlanRecipe(new RuleEnum[] { RuleEnum.HITLAST, RuleEnum.PUNCHNOTLAST, RuleEnum.HITNOTLAST })); + + for(int i = 0; i < Constants.Lanterns.length; i++) { - AnvilManager manager = AnvilManager.getInstance(); - - manager.addPlan(_lanternCorePlan, new PlanRecipe(new RuleEnum[] { RuleEnum.HITLAST, RuleEnum.PUNCHNOTLAST, RuleEnum.HITNOTLAST })); - - for(int i = 0; i < Constants.Lanterns.length; i++) - { - LanternInfo info = Constants.Lanterns[i]; - Item sheetItem = GameRegistry.findItem("terrafirmacraft", info.SheetName); - ItemStack lanternCore = new ItemStack(ItemList.LanternCores[i], 1, 0); - - manager.addRecipe(new AnvilRecipe(new ItemStack(sheetItem), null, _lanternCorePlan, false, info.Anvil, lanternCore).addRecipeSkill(Global.SKILL_GENERAL_SMITHING)); - } + LanternInfo info = Constants.Lanterns[i]; + Item sheetItem = GameRegistry.findItem("terrafirmacraft", info.SheetName); + ItemStack lanternCore = new ItemStack(ItemList.LanternCores[i], 1, 0); + + manager.addRecipe(new AnvilRecipe(new ItemStack(sheetItem), null, _lanternCorePlan, false, info.Anvil, lanternCore).addRecipeSkill(Global.SKILL_GENERAL_SMITHING)); } } } diff --git a/src/com/aleksey/decorations/Handlers/ChunkEventHandler.java b/src/com/aleksey/decorations/Handlers/ChunkEventHandler.java index 0c0ce8d..ceeb148 100644 --- a/src/com/aleksey/decorations/Handlers/ChunkEventHandler.java +++ b/src/com/aleksey/decorations/Handlers/ChunkEventHandler.java @@ -13,7 +13,7 @@ public void onLoadWorld(WorldEvent.Load event) { if(!event.world.isRemote && event.world.provider.dimensionId == 0 && !Recipes.areAnvilRecipesRegistered()) { - Recipes.registerAnvilRecipes(); + Recipes.registerAnvilRecipes(event.world); } } } \ No newline at end of file diff --git a/src/com/aleksey/decorations/Handlers/Network/InitClientWorldPacket.java b/src/com/aleksey/decorations/Handlers/Network/InitClientWorldPacket.java index df34fdc..adce9ca 100644 --- a/src/com/aleksey/decorations/Handlers/Network/InitClientWorldPacket.java +++ b/src/com/aleksey/decorations/Handlers/Network/InitClientWorldPacket.java @@ -28,7 +28,7 @@ public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) public void handleClientSide(EntityPlayer player) { if(!Recipes.areAnvilRecipesRegistered()) - Recipes.registerAnvilRecipes(); + Recipes.registerAnvilRecipes(player.worldObj); } @Override diff --git a/src/com/aleksey/decorations/Handlers/ServerTickHandler.java b/src/com/aleksey/decorations/Handlers/ServerTickHandler.java index d48a36e..dbe2c1d 100644 --- a/src/com/aleksey/decorations/Handlers/ServerTickHandler.java +++ b/src/com/aleksey/decorations/Handlers/ServerTickHandler.java @@ -19,7 +19,7 @@ public void onServerWorldTick(WorldTickEvent event) { if(world.provider.dimensionId == 0 && !Recipes.areAnvilRecipesRegistered()) { - Recipes.registerAnvilRecipes(); + Recipes.registerAnvilRecipes(world); } } }