Applied-Energistics-2-tiler.../tile/events/AETileEventHandler.java

139 lines
2.6 KiB
Java
Raw Normal View History

package appeng.tile.events;
2014-02-09 02:34:52 +01:00
import io.netty.buffer.ByteBuf;
import java.io.IOException;
2014-08-28 09:39:52 +02:00
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import net.minecraft.nbt.NBTTagCompound;
2014-08-28 09:39:52 +02:00
import appeng.tile.AEBaseTile;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
2014-08-28 09:39:52 +02:00
public class AETileEventHandler
{
2014-08-28 09:39:52 +02:00
private final Method method;
private final TileEventType type;
2014-08-28 09:39:52 +02:00
public AETileEventHandler(Method m, TileEventType which) {
method = m;
type = which;
}
// TICK
2014-08-28 09:39:52 +02:00
public void Tick(AEBaseTile tile)
{
2014-08-28 09:39:52 +02:00
try
{
method.invoke( tile );
}
catch (IllegalAccessException e)
{
throw new RuntimeException( e );
}
catch (IllegalArgumentException e)
{
throw new RuntimeException( e );
}
catch (InvocationTargetException e)
{
throw new RuntimeException( e );
}
}
// WORLD_NBT
2014-08-28 09:39:52 +02:00
public void writeToNBT(AEBaseTile tile, NBTTagCompound data)
{
2014-08-28 09:39:52 +02:00
try
{
method.invoke( tile, data );
}
catch (IllegalAccessException e)
{
throw new RuntimeException( e );
}
catch (IllegalArgumentException e)
{
throw new RuntimeException( e );
}
catch (InvocationTargetException e)
{
throw new RuntimeException( e );
}
}
// WORLD NBT
2014-08-28 09:39:52 +02:00
public void readFromNBT(AEBaseTile tile, NBTTagCompound data)
{
2014-08-28 09:39:52 +02:00
try
{
method.invoke( tile, data );
}
catch (IllegalAccessException e)
{
throw new RuntimeException( e );
}
catch (IllegalArgumentException e)
{
throw new RuntimeException( e );
}
catch (InvocationTargetException e)
{
throw new RuntimeException( e );
}
}
// NETWORK
2014-08-28 09:39:52 +02:00
public void writeToStream(AEBaseTile tile, ByteBuf data) throws IOException
{
2014-08-28 09:39:52 +02:00
try
{
method.invoke( tile, data );
}
catch (IllegalAccessException e)
{
throw new RuntimeException( e );
}
catch (IllegalArgumentException e)
{
throw new RuntimeException( e );
}
catch (InvocationTargetException e)
{
throw new RuntimeException( e );
}
}
// NETWORK
/**
* returning true from this method, will update the block's render
*
* @param data
* @return
* @throws IOException
*/
@SideOnly(Side.CLIENT)
2014-08-28 09:39:52 +02:00
public boolean readFromStream(AEBaseTile tile, ByteBuf data) throws IOException
{
2014-08-28 09:39:52 +02:00
try
{
return (Boolean) method.invoke( tile, data );
}
catch (IllegalAccessException e)
{
throw new RuntimeException( e );
}
catch (IllegalArgumentException e)
{
throw new RuntimeException( e );
}
catch (InvocationTargetException e)
{
throw new RuntimeException( e );
}
}
}