From 5e786d8902066f2d208673106f9ba9261c62e2cd Mon Sep 17 00:00:00 2001 From: ddoggy99 Date: Thu, 12 Sep 2013 23:27:11 +1000 Subject: [PATCH] Cleaned up IMC code --- common/buildcraft/BuildCraftBuilders.java | 7 ++ common/buildcraft/BuildCraftCore.java | 7 ++ common/buildcraft/BuildCraftEnergy.java | 39 +--------- common/buildcraft/BuildCraftFactory.java | 7 ++ common/buildcraft/BuildCraftSilicon.java | 7 ++ common/buildcraft/BuildCraftTransport.java | 25 +------ common/buildcraft/core/InterModComms.java | 87 ++++++++++++++++++++++ 7 files changed, 123 insertions(+), 56 deletions(-) create mode 100644 common/buildcraft/core/InterModComms.java diff --git a/common/buildcraft/BuildCraftBuilders.java b/common/buildcraft/BuildCraftBuilders.java index b18cb4a6..0c685382 100644 --- a/common/buildcraft/BuildCraftBuilders.java +++ b/common/buildcraft/BuildCraftBuilders.java @@ -56,6 +56,7 @@ import buildcraft.builders.TileMarker; import buildcraft.builders.TilePathMarker; import buildcraft.builders.network.PacketHandlerBuilders; import buildcraft.core.DefaultProps; +import buildcraft.core.InterModComms; import buildcraft.core.Version; import buildcraft.core.blueprints.BptPlayerIndex; import buildcraft.core.blueprints.BptRootIndex; @@ -64,6 +65,7 @@ import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLInterModComms; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStoppingEvent; import cpw.mods.fml.common.network.NetworkMod; @@ -331,6 +333,11 @@ public class BuildCraftBuilders { FillerManager.registry.addRecipe(new FillerFillPyramid(), new Object[]{" ", " b ", "bbb", 'g', Block.glass, 'b', Block.brick}); FillerManager.registry.addRecipe(new FillerFillStairs(), new Object[]{" b", " bb", "bbb", 'g', Block.glass, 'b', Block.brick}); } + + @EventHandler + public void processIMCRequests(FMLInterModComms.IMCEvent event) { + InterModComms.processIMC(event); + } public static BptPlayerIndex getPlayerIndex(String name) { BptRootIndex rootIndex = getBptRootIndex(); diff --git a/common/buildcraft/BuildCraftCore.java b/common/buildcraft/BuildCraftCore.java index 4fa93c6b..5d8e1da4 100644 --- a/common/buildcraft/BuildCraftCore.java +++ b/common/buildcraft/BuildCraftCore.java @@ -38,6 +38,7 @@ import buildcraft.core.DefaultProps; import buildcraft.core.EntityEnergyLaser; import buildcraft.core.EntityPowerLaser; import buildcraft.core.EntityRobot; +import buildcraft.core.InterModComms; import buildcraft.core.ItemBuildCraft; import buildcraft.core.ItemSpring; import buildcraft.core.ItemWrench; @@ -67,6 +68,7 @@ import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLInterModComms; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; @@ -341,4 +343,9 @@ public class BuildCraftCore { GameRegistry.addRecipe(new ItemStack(goldGearItem), " I ", "IGI", " I ", Character.valueOf('I'), Item.ingotGold, Character.valueOf('G'), ironGearItem); GameRegistry.addRecipe(new ItemStack(diamondGearItem), " I ", "IGI", " I ", Character.valueOf('I'), Item.diamond, Character.valueOf('G'), goldGearItem); } + + @EventHandler + public void processIMCRequests(FMLInterModComms.IMCEvent event) { + InterModComms.processIMC(event); + } } diff --git a/common/buildcraft/BuildCraftEnergy.java b/common/buildcraft/BuildCraftEnergy.java index cb7b3ca2..872b88d8 100644 --- a/common/buildcraft/BuildCraftEnergy.java +++ b/common/buildcraft/BuildCraftEnergy.java @@ -13,6 +13,7 @@ import buildcraft.api.recipes.RefineryRecipes; import buildcraft.core.BlockIndex; import buildcraft.core.BlockSpring; import buildcraft.core.DefaultProps; +import buildcraft.core.InterModComms; import buildcraft.core.Version; import buildcraft.core.network.PacketHandler; import buildcraft.core.proxy.CoreProxy; @@ -44,8 +45,6 @@ import cpw.mods.fml.common.registry.LanguageRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import java.util.TreeMap; -import java.util.logging.Level; -import java.util.logging.Logger; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.item.Item; @@ -253,40 +252,10 @@ public class BuildCraftEnergy { Character.valueOf('g'), Block.glass, Character.valueOf('G'), BuildCraftCore.ironGearItem, Character.valueOf('p'), Block.pistonBase}); } - @Mod.IMCCallback + @EventHandler public void processIMCRequests(FMLInterModComms.IMCEvent event) { - for (FMLInterModComms.IMCMessage m : event.getMessages()) { - if (m.key.equals("oil-lake-biome")) { - try { - String biomeID = m.getStringValue().trim(); - int id = Integer.valueOf(biomeID); - if (id >= BiomeGenBase.biomeList.length) { - throw new IllegalArgumentException("Biome ID must be less than " + BiomeGenBase.biomeList.length); - } - OilPopulate.INSTANCE.surfaceDepositBiomes.add(id); - } catch (Exception ex) { - Logger.getLogger("Buildcraft").log(Level.WARNING, - String.format("Received an invalid oil-lake-biome request %s from mod %s", m.getStringValue(), m.getSender())); - } - Logger.getLogger("Buildcraft").log(Level.INFO, - String.format("Received an successfull oil-lake-biome request %s from mod %s", m.getStringValue(), m.getSender())); - } else if (m.key.equals("oil-gen-exclude")) { - try { - String biomeID = m.getStringValue().trim(); - int id = Integer.valueOf(biomeID); - if (id >= BiomeGenBase.biomeList.length) { - throw new IllegalArgumentException("Biome ID must be less than " + BiomeGenBase.biomeList.length); - } - OilPopulate.INSTANCE.excludedBiomes.add(id); - } catch (Exception ex) { - Logger.getLogger("Buildcraft").log(Level.WARNING, - String.format("Received an invalid oil-gen-exclude request %s from mod %s", m.getStringValue(), m.getSender())); - } - Logger.getLogger("Buildcraft").log(Level.INFO, - String.format("Received an successfull oil-gen-exclude request %s from mod %s", m.getStringValue(), m.getSender())); - } - } - } + InterModComms.processIMC(event); + } // public static int createPollution (World world, int i, int j, int k, int // saturation) { // int remainingSaturation = saturation; diff --git a/common/buildcraft/BuildCraftFactory.java b/common/buildcraft/BuildCraftFactory.java index b5370298..3d75bc94 100644 --- a/common/buildcraft/BuildCraftFactory.java +++ b/common/buildcraft/BuildCraftFactory.java @@ -8,6 +8,7 @@ package buildcraft; import buildcraft.core.DefaultProps; +import buildcraft.core.InterModComms; import buildcraft.core.Version; import buildcraft.core.proxy.CoreProxy; import buildcraft.factory.BlockAutoWorkbench; @@ -42,6 +43,7 @@ import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLInterModComms; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkMod; @@ -317,6 +319,11 @@ public class BuildCraftFactory { 'G', BuildCraftCore.ironGearItem, 'F', new ItemStack(Block.fenceIron)); } + + @EventHandler + public void processIMCRequests(FMLInterModComms.IMCEvent event) { + InterModComms.processIMC(event); + } @ForgeSubscribe @SideOnly(Side.CLIENT) diff --git a/common/buildcraft/BuildCraftSilicon.java b/common/buildcraft/BuildCraftSilicon.java index 39e0d326..735d164e 100644 --- a/common/buildcraft/BuildCraftSilicon.java +++ b/common/buildcraft/BuildCraftSilicon.java @@ -11,6 +11,7 @@ import buildcraft.api.bptblocks.BptBlockInventory; import buildcraft.api.bptblocks.BptBlockRotateMeta; import buildcraft.api.recipes.AssemblyRecipe; import buildcraft.core.DefaultProps; +import buildcraft.core.InterModComms; import buildcraft.core.ItemRedstoneChipset; import buildcraft.core.Version; import buildcraft.core.proxy.CoreProxy; @@ -27,6 +28,7 @@ import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLInterModComms; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.NetworkRegistry; @@ -224,4 +226,9 @@ public class BuildCraftSilicon { CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 6), "Autarchic Diamond OR Gate"); } + + @EventHandler + public void processIMCRequests(FMLInterModComms.IMCEvent event) { + InterModComms.processIMC(event); + } } diff --git a/common/buildcraft/BuildCraftTransport.java b/common/buildcraft/BuildCraftTransport.java index e5345e60..9787d97e 100644 --- a/common/buildcraft/BuildCraftTransport.java +++ b/common/buildcraft/BuildCraftTransport.java @@ -15,6 +15,7 @@ import buildcraft.api.transport.IPipe; import buildcraft.api.transport.PipeManager; import buildcraft.core.CreativeTabBuildCraft; import buildcraft.core.DefaultProps; +import buildcraft.core.InterModComms; import buildcraft.core.ItemBuildCraft; import buildcraft.core.Version; import buildcraft.core.proxy.CoreProxy; @@ -84,7 +85,7 @@ import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.event.FMLInitializationEvent; -import cpw.mods.fml.common.event.FMLInterModComms; +import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent; import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; @@ -443,26 +444,8 @@ public class BuildCraftTransport { } @EventHandler - public void processIMCRequests(FMLInterModComms.IMCEvent event) { - Splitter splitter = Splitter.on("@").trimResults(); - for (IMCMessage m : event.getMessages()) { - if ("add-facade".equals(m.key)) { - String[] array = Iterables.toArray(splitter.split(m.getStringValue()), String.class); - if (array.length != 2) { - Logger.getLogger("Buildcraft").log(Level.INFO, - String.format("Received an invalid add-facade request %s from mod %s", m.getStringValue(), m.getSender())); - continue; - } - Integer blId = Ints.tryParse(array[0]); - Integer metaId = Ints.tryParse(array[1]); - if (blId == null || metaId == null) { - Logger.getLogger("Buildcraft").log(Level.INFO, - String.format("Received an invalid add-facade request %s from mod %s", m.getStringValue(), m.getSender())); - continue; - } - ItemFacade.addFacade(new ItemStack(blId, 1, metaId)); - } - } + public void processIMCRequests(IMCEvent event) { + InterModComms.processIMC(event); } public static Item buildPipe(int defaultID, Class clas, String descr, Object... ingredients) { diff --git a/common/buildcraft/core/InterModComms.java b/common/buildcraft/core/InterModComms.java new file mode 100644 index 00000000..e4a56ece --- /dev/null +++ b/common/buildcraft/core/InterModComms.java @@ -0,0 +1,87 @@ +/** + * BuildCraft is open-source. It is distributed under the terms of the + * BuildCraft Open Source License. It grants rights to read, modify, compile or + * run the code. It does *NOT* grant the right to redistribute this software or + * its modifications in any form, binary or source, except if expressively + * granted by the copyright holder. + */ +package buildcraft.core; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import net.minecraft.item.ItemStack; +import net.minecraft.world.biome.BiomeGenBase; +import buildcraft.energy.worldgen.OilPopulate; +import buildcraft.transport.ItemFacade; + +import com.google.common.base.Splitter; +import com.google.common.collect.Iterables; +import com.google.common.primitives.Ints; + +import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent; +import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage; + +public class InterModComms { + + public static void processIMC(IMCEvent event) { + for (IMCMessage m : event.getMessages()) { + if ("add-facade".equals(m.key)) { + processFacadeIMC(event, m); + } else if (m.key.equals("oil-lake-biome")) { + processOilLakeBiomeIMC(event, m); + } else if (m.key.equals("oil-gen-exclude")) { + processOilGenExcludeIMC(event, m); + } + } + } + + public static void processFacadeIMC(IMCEvent event, IMCMessage m) { + try { + Splitter splitter = Splitter.on("@").trimResults(); + + String[] array = Iterables.toArray(splitter.split(m.getStringValue()), String.class); + if (array.length != 2) { + Logger.getLogger("Buildcraft").log(Level.INFO, String.format("Received an invalid add-facade request %s from mod %s", m.getStringValue(), m.getSender())); + } else { + Integer blId = Ints.tryParse(array[0]); + Integer metaId = Ints.tryParse(array[1]); + if (blId == null || metaId == null) { + Logger.getLogger("Buildcraft").log(Level.INFO, String.format("Received an invalid add-facade request %s from mod %s", m.getStringValue(), m.getSender())); + } else { + ItemFacade.addFacade(new ItemStack(blId, 1, metaId)); + } + } + } catch (Exception ex) { + + } + } + + public static void processOilLakeBiomeIMC(IMCEvent event, IMCMessage m) { + try { + String biomeID = m.getStringValue().trim(); + int id = Integer.valueOf(biomeID); + if (id >= BiomeGenBase.biomeList.length) { + throw new IllegalArgumentException("Biome ID must be less than " + BiomeGenBase.biomeList.length); + } + OilPopulate.INSTANCE.surfaceDepositBiomes.add(id); + } catch (Exception ex) { + Logger.getLogger("Buildcraft").log(Level.WARNING, String.format("Received an invalid oil-lake-biome request %s from mod %s", m.getStringValue(), m.getSender())); + } + Logger.getLogger("Buildcraft").log(Level.INFO, String.format("Received an successfull oil-lake-biome request %s from mod %s", m.getStringValue(), m.getSender())); + } + + public static void processOilGenExcludeIMC(IMCEvent event, IMCMessage m) { + try { + String biomeID = m.getStringValue().trim(); + int id = Integer.valueOf(biomeID); + if (id >= BiomeGenBase.biomeList.length) { + throw new IllegalArgumentException("Biome ID must be less than " + BiomeGenBase.biomeList.length); + } + OilPopulate.INSTANCE.excludedBiomes.add(id); + } catch (Exception ex) { + Logger.getLogger("Buildcraft").log(Level.WARNING, String.format("Received an invalid oil-gen-exclude request %s from mod %s", m.getStringValue(), m.getSender())); + } + Logger.getLogger("Buildcraft").log(Level.INFO, String.format("Received an successfull oil-gen-exclude request %s from mod %s", m.getStringValue(), m.getSender())); + } +}