Allow registration of materials via IMC

This commit is contained in:
Bernhard Bonigl committed 2014-09-22 16:02:16 +02:00
1 parent 8e0bfdd0ed
commit 2610428782
2 files changed
+104 -3

No files matched your search

+15 -3
View File
@@ -3,6 +3,7 @@ package tconstruct;
import java.util.Map;
import java.util.Random;
import cpw.mods.fml.common.event.*;
import mantle.pulsar.config.ForgeCFG;
import mantle.pulsar.control.PulseManager;
import net.minecraft.world.gen.structure.MapGenStructureIO;
@@ -36,6 +37,7 @@ import tconstruct.plugins.waila.TinkerWaila;
import tconstruct.smeltery.TinkerSmeltery;
import tconstruct.tools.TinkerTools;
import tconstruct.util.EnvironmentChecks;
import tconstruct.util.IMCHandler;
import tconstruct.util.config.DimensionBlacklist;
import tconstruct.util.config.PHConstruct;
import tconstruct.util.network.PacketPipeline;
@@ -52,9 +54,6 @@ 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.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkCheckHandler;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
@@ -211,6 +210,19 @@ public class TConstruct
}
}
/* IMC Mod Support */
@EventHandler
public void handleIMC(FMLInterModComms.IMCEvent e)
{
IMCHandler.processIMC(e.getMessages());
}
@EventHandler
public void loadComplete(FMLLoadCompleteEvent evt)
{
IMCHandler.processIMC(FMLInterModComms.fetchRuntimeMessages(this));
}
public static LiquidCasting getTableCasting ()
{
return tableCasting;
@@ -0,0 +1,89 @@
package tconstruct.util;
import cpw.mods.fml.common.event.FMLInterModComms;
import net.minecraft.nbt.NBTTagCompound;
import tconstruct.TConstruct;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.tools.ToolMaterial;
import java.util.List;
public final class IMCHandler {
private IMCHandler() {}
public static void processIMC(List<FMLInterModComms.IMCMessage> messages)
{
for(FMLInterModComms.IMCMessage message : messages)
{
String type = message.key;
if(type == null || type.isEmpty())
continue;
// process materials added from mods
if(type.equals("addMaterial"))
{
if(!message.isNBTMessage())
{
logInvalidMessage(message);
continue;
}
NBTTagCompound tag = message.getNBTValue();
ToolMaterial mat = scanMaterial(tag);
if(mat != null) {
TConstructRegistry.addtoolMaterial(tag.getInteger("Id"), mat);
TConstruct.logger.info("IMC: Added material " + mat.materialName);
}
}
}
}
private static void logInvalidMessage(FMLInterModComms.IMCMessage message)
{
TConstruct.logger.error(String.format("Received invalid IMC '%s' from %s. Not a NBT Message.", message.key, message.getSender()));
}
private static ToolMaterial scanMaterial(NBTTagCompound tag)
{
if(!tag.hasKey("Name")) {
TConstruct.logger.error("Material IMC: Material has no name");
return null;
}
String name = tag.getString("Name");
if(!tag.hasKey("Id")) {
TConstruct.logger.error("Material IMC: Materials need a unique id. " + name);
return null;
}
else if(!tag.hasKey("Durability")) {
TConstruct.logger.error("Material IMC: Materials need a durability. " + name);
return null;
}
else if(!tag.hasKey("MiningSpeed")) {
TConstruct.logger.error("Material IMC: Materials need a mining speed. " + name);
return null;
}
else if(tag.hasKey("Stonebound") && tag.hasKey("Jagged")) {
TConstruct.logger.error("Material IMC: Materials can only be Stonebound or Jagged. " + name);
return null;
}
int hlvl = tag.getInteger("HarvestLevel");
int durability = tag.getInteger("Durability");
int speed = tag.getInteger("MiningSpeed");
int attack = tag.getInteger("Attack");
float handle = tag.getFloat("HandleModifier");
int reinforced = tag.getInteger("Reinforced");
float shoddy = tag.getFloat("Stonebound");
String style = tag.getString("Style");
int color = tag.getInteger("Color");
if(tag.hasKey("Jagged"))
shoddy = tag.getFloat("Jagged");
if(tag.hasKey("localizationString"))
return new ToolMaterial(name, tag.getString("localizationString"), hlvl, durability, speed, attack, handle, reinforced, shoddy, style, color);
else
return new ToolMaterial(name, hlvl, durability, speed, attack, handle, reinforced, shoddy, style, color);
}
}