Added IMC Support for P2P / Grinder / Spatial / MatterCannon
This commit is contained in:
+42
-2
@@ -1,8 +1,15 @@
|
|||||||
package appeng.core;
|
package appeng.core;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import appeng.api.config.TunnelType;
|
||||||
|
import appeng.core.api.IIMCHandler;
|
||||||
|
import appeng.core.api.imc.IMCGrinder;
|
||||||
|
import appeng.core.api.imc.IMCMatterCannon;
|
||||||
|
import appeng.core.api.imc.IMCP2PAttunement;
|
||||||
|
import appeng.core.api.imc.IMCSpatial;
|
||||||
import appeng.core.crash.CrashEnhancement;
|
import appeng.core.crash.CrashEnhancement;
|
||||||
import appeng.core.crash.CrashInfo;
|
import appeng.core.crash.CrashInfo;
|
||||||
import appeng.core.features.AEFeature;
|
import appeng.core.features.AEFeature;
|
||||||
@@ -21,6 +28,8 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
|||||||
import cpw.mods.fml.common.Mod;
|
import cpw.mods.fml.common.Mod;
|
||||||
import cpw.mods.fml.common.Mod.EventHandler;
|
import cpw.mods.fml.common.Mod.EventHandler;
|
||||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||||
|
import cpw.mods.fml.common.event.FMLInterModComms;
|
||||||
|
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;
|
||||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||||
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
|
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
|
||||||
@@ -42,6 +51,8 @@ public class AppEng
|
|||||||
public final static String modid = "appliedenergistics2";
|
public final static String modid = "appliedenergistics2";
|
||||||
public final static String name = "Applied Energistics 2";
|
public final static String name = "Applied Energistics 2";
|
||||||
|
|
||||||
|
HashMap<String, IIMCHandler> IMCHandlers = new HashMap();
|
||||||
|
|
||||||
public static AppEng instance;
|
public static AppEng instance;
|
||||||
|
|
||||||
public final static String dependencies =
|
public final static String dependencies =
|
||||||
@@ -51,8 +62,7 @@ public class AppEng
|
|||||||
"after:gregtech_addon;after:Mekanism;after:IC2;after:ThermalExpansion;after:BuildCraft|Core;" +
|
"after:gregtech_addon;after:Mekanism;after:IC2;after:ThermalExpansion;after:BuildCraft|Core;" +
|
||||||
|
|
||||||
// depend on version of forge used for build.
|
// depend on version of forge used for build.
|
||||||
"required-after:AppliedEnergistics2-Core;" +
|
"required-after:AppliedEnergistics2-Core;" + "required-after:Forge@[" // require forge.
|
||||||
"required-after:Forge@[" // require forge.
|
|
||||||
+ net.minecraftforge.common.ForgeVersion.majorVersion + "." // majorVersion
|
+ net.minecraftforge.common.ForgeVersion.majorVersion + "." // majorVersion
|
||||||
+ net.minecraftforge.common.ForgeVersion.minorVersion + "." // minorVersion
|
+ net.minecraftforge.common.ForgeVersion.minorVersion + "." // minorVersion
|
||||||
+ net.minecraftforge.common.ForgeVersion.revisionVersion + "." // revisionVersion
|
+ net.minecraftforge.common.ForgeVersion.revisionVersion + "." // revisionVersion
|
||||||
@@ -61,6 +71,15 @@ public class AppEng
|
|||||||
public AppEng() {
|
public AppEng() {
|
||||||
instance = this;
|
instance = this;
|
||||||
|
|
||||||
|
IMCHandlers.put( "whitelist-spatial", new IMCSpatial() );
|
||||||
|
IMCHandlers.put( "add-grindable", new IMCGrinder() );
|
||||||
|
IMCHandlers.put( "add-mattercannon-ammo", new IMCMatterCannon() );
|
||||||
|
|
||||||
|
for (TunnelType type : TunnelType.values())
|
||||||
|
{
|
||||||
|
IMCHandlers.put( "add-p2p-attunement-" + type.name().replace( '_', '-' ).toLowerCase(), new IMCP2PAttunement() );
|
||||||
|
}
|
||||||
|
|
||||||
for (CrashInfo ci : CrashInfo.values())
|
for (CrashInfo ci : CrashInfo.values())
|
||||||
FMLCommonHandler.instance().registerCrashCallable( new CrashEnhancement( ci ) );
|
FMLCommonHandler.instance().registerCrashCallable( new CrashEnhancement( ci ) );
|
||||||
}
|
}
|
||||||
@@ -147,6 +166,27 @@ public class AppEng
|
|||||||
AELog.info( "PostInit ( end " + star.elapsed( TimeUnit.MILLISECONDS ) + "ms )" );
|
AELog.info( "PostInit ( end " + star.elapsed( TimeUnit.MILLISECONDS ) + "ms )" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void processIMC(FMLInterModComms.IMCEvent event)
|
||||||
|
{
|
||||||
|
for (IMCMessage m : event.getMessages())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IIMCHandler handler = IMCHandlers.get( m.key );
|
||||||
|
if ( handler != null )
|
||||||
|
handler.post( m );
|
||||||
|
else
|
||||||
|
throw new RuntimeException( "Invalid IMC Called: " + m.key );
|
||||||
|
}
|
||||||
|
catch (Throwable t)
|
||||||
|
{
|
||||||
|
AELog.warning( "Problem detected when processing IMC " + m.key + " from " + m.getSender() );
|
||||||
|
AELog.error( t );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void serverStopping(FMLServerStoppingEvent event)
|
public void serverStopping(FMLServerStoppingEvent event)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package appeng.core.api;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;
|
||||||
|
|
||||||
|
public interface IIMCHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
void post(IMCMessage m);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/* Example:
|
||||||
|
|
||||||
|
NBTTagCompound msg = new NBTTagCompound();
|
||||||
|
NBTTagCompound in = new NBTTagCompound();
|
||||||
|
NBTTagCompound out = new NBTTagCompound();
|
||||||
|
|
||||||
|
new ItemStack( Blocks.iron_ore ).writeToNBT( in );
|
||||||
|
new ItemStack( Items.iron_ingot ).writeToNBT( out );
|
||||||
|
msg.setTag( "in", in );
|
||||||
|
msg.setTag( "out", out );
|
||||||
|
msg.setInteger( "turns", 8 );
|
||||||
|
|
||||||
|
FMLInterModComms.sendMessage( "appliedenergistics2", "add-grindable", msg );
|
||||||
|
|
||||||
|
-- or --
|
||||||
|
|
||||||
|
NBTTagCompound msg = new NBTTagCompound();
|
||||||
|
NBTTagCompound in = new NBTTagCompound();
|
||||||
|
NBTTagCompound out = new NBTTagCompound();
|
||||||
|
NBTTagCompound optional = new NBTTagCompound();
|
||||||
|
|
||||||
|
new ItemStack( Blocks.iron_ore ).writeToNBT( in );
|
||||||
|
new ItemStack( Items.iron_ingot ).writeToNBT( out );
|
||||||
|
new ItemStack( Blocks.gravel ).writeToNBT( optional );
|
||||||
|
msg.setTag( "in", in );
|
||||||
|
msg.setTag( "out", out );
|
||||||
|
msg.setTag( "optional", optional );
|
||||||
|
msg.setFloat( "chance", 0.5 );
|
||||||
|
msg.setInteger( "turns", 8 );
|
||||||
|
|
||||||
|
FMLInterModComms.sendMessage( "appliedenergistics2", "add-grindable", msg );
|
||||||
|
|
||||||
|
*/
|
||||||
|
package appeng.core.api.imc;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import appeng.api.AEApi;
|
||||||
|
import appeng.core.api.IIMCHandler;
|
||||||
|
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;
|
||||||
|
|
||||||
|
public class IMCGrinder implements IIMCHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void post(IMCMessage m)
|
||||||
|
{
|
||||||
|
NBTTagCompound msg = m.getNBTValue();
|
||||||
|
NBTTagCompound inTag = (NBTTagCompound) msg.getTag( "in" );
|
||||||
|
NBTTagCompound outTag = (NBTTagCompound) msg.getTag( "out" );
|
||||||
|
|
||||||
|
ItemStack in = ItemStack.loadItemStackFromNBT( inTag );
|
||||||
|
ItemStack out = ItemStack.loadItemStackFromNBT( outTag );
|
||||||
|
|
||||||
|
int turns = msg.getInteger( "turns" );
|
||||||
|
|
||||||
|
if ( in == null )
|
||||||
|
throw new RuntimeException( "invalid input" );
|
||||||
|
|
||||||
|
if ( out == null )
|
||||||
|
throw new RuntimeException( "invalid output" );
|
||||||
|
|
||||||
|
if ( msg.hasKey( "optional" ) )
|
||||||
|
{
|
||||||
|
NBTTagCompound optionalTag = (NBTTagCompound) msg.getTag( "optional" );
|
||||||
|
ItemStack optional = ItemStack.loadItemStackFromNBT( optionalTag );
|
||||||
|
|
||||||
|
if ( optional == null )
|
||||||
|
throw new RuntimeException( "invalid optional" );
|
||||||
|
|
||||||
|
float chance = msg.getFloat( "chance" );
|
||||||
|
|
||||||
|
AEApi.instance().registries().grinder().addRecipe( in, out, optional, chance, turns );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
AEApi.instance().registries().grinder().addRecipe( in, out, turns );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/* Example:
|
||||||
|
|
||||||
|
NBTTagCompound msg = new NBTTagCompound();
|
||||||
|
NBTTagCompound item = new NBTTagCompound();
|
||||||
|
|
||||||
|
new ItemStack( Blocks.anvil ).writeToNBT( item );
|
||||||
|
msg.setTag( "item", item );
|
||||||
|
msg.setDouble( "weight", 32.0 );
|
||||||
|
|
||||||
|
FMLInterModComms.sendMessage( "appliedenergistics2", "add-mattercannon-ammo", msg );
|
||||||
|
|
||||||
|
*/
|
||||||
|
package appeng.core.api.imc;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import appeng.api.AEApi;
|
||||||
|
import appeng.core.api.IIMCHandler;
|
||||||
|
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;
|
||||||
|
|
||||||
|
public class IMCMatterCannon implements IIMCHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void post(IMCMessage m)
|
||||||
|
{
|
||||||
|
NBTTagCompound msg = m.getNBTValue();
|
||||||
|
NBTTagCompound item = (NBTTagCompound) msg.getTag( "item" );
|
||||||
|
|
||||||
|
ItemStack ammo = ItemStack.loadItemStackFromNBT( item );
|
||||||
|
double weight = msg.getDouble( "weight" );
|
||||||
|
|
||||||
|
if ( ammo == null )
|
||||||
|
throw new RuntimeException( "invalid item" );
|
||||||
|
|
||||||
|
AEApi.instance().registries().matterCannon().registerAmmo( ammo, weight );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/* Example:
|
||||||
|
|
||||||
|
FMLInterModComms.sendMessage( "appliedenergistics2", "add-p2p-attunement-me", new ItemStack( myBlockOrItem ) );
|
||||||
|
FMLInterModComms.sendMessage( "appliedenergistics2", "add-p2p-attunement-bc-power", new ItemStack( myBlockOrItem ) );
|
||||||
|
FMLInterModComms.sendMessage( "appliedenergistics2", "add-p2p-attunement-ic2-power", new ItemStack( myBlockOrItem ) );
|
||||||
|
FMLInterModComms.sendMessage( "appliedenergistics2", "add-p2p-attunement-redstone", new ItemStack( myBlockOrItem ) );
|
||||||
|
FMLInterModComms.sendMessage( "appliedenergistics2", "add-p2p-attunement-fluid", new ItemStack( myBlockOrItem ) );
|
||||||
|
FMLInterModComms.sendMessage( "appliedenergistics2", "add-p2p-attunement-item", new ItemStack( myBlockOrItem ) );
|
||||||
|
|
||||||
|
*/
|
||||||
|
package appeng.core.api.imc;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import appeng.api.AEApi;
|
||||||
|
import appeng.api.config.TunnelType;
|
||||||
|
import appeng.core.api.IIMCHandler;
|
||||||
|
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;
|
||||||
|
|
||||||
|
public class IMCP2PAttunement implements IIMCHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void post(IMCMessage m)
|
||||||
|
{
|
||||||
|
String key = m.key.substring( "add-p2p-attunement-".length() ).replace( '-', '_' ).toUpperCase();
|
||||||
|
|
||||||
|
TunnelType type = TunnelType.valueOf( key );
|
||||||
|
|
||||||
|
if ( type != null )
|
||||||
|
{
|
||||||
|
ItemStack is = m.getItemStackValue();
|
||||||
|
if ( is != null )
|
||||||
|
AEApi.instance().registries().p2pTunnel().addNewAttunement( is, type );
|
||||||
|
else
|
||||||
|
throw new RuntimeException( "invalid item" );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new RuntimeException( "invalid type" );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/* Example:
|
||||||
|
|
||||||
|
FMLInterModComms.sendMessage( "appliedenergistics2", "whitelist-spatial", "mymod.tileentities.MyTileEntity" );
|
||||||
|
|
||||||
|
*/
|
||||||
|
package appeng.core.api.imc;
|
||||||
|
|
||||||
|
import appeng.api.AEApi;
|
||||||
|
import appeng.core.AELog;
|
||||||
|
import appeng.core.api.IIMCHandler;
|
||||||
|
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;
|
||||||
|
|
||||||
|
public class IMCSpatial implements IIMCHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void post(IMCMessage m)
|
||||||
|
{
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class classInstance = Class.forName( m.getStringValue() );
|
||||||
|
AEApi.instance().registries().moveable().whiteListTileEntity( classInstance );
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException e)
|
||||||
|
{
|
||||||
|
AELog.info( "Bad Class Registered: " + m.getStringValue() + " by " + m.getSender() );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user