Merge pull request #1199 from ddoggy99/master

Cleaned up IMC code
This commit is contained in:
CovertJaguar 2013-09-12 09:42:52 -07:00
commit 47d504d781
7 changed files with 123 additions and 56 deletions

View file

@ -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;
@ -332,6 +334,11 @@ public class BuildCraftBuilders {
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();

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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;
@ -318,6 +320,11 @@ public class BuildCraftFactory {
'F', new ItemStack(Block.fenceIron));
}
@EventHandler
public void processIMCRequests(FMLInterModComms.IMCEvent event) {
InterModComms.processIMC(event);
}
@ForgeSubscribe
@SideOnly(Side.CLIENT)
public void loadTextures(TextureStitchEvent.Pre evt) {

View file

@ -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);
}
}

View file

@ -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<? extends Pipe> clas, String descr, Object... ingredients) {

View file

@ -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()));
}
}