2013-12-27 23:59:59 +01:00
|
|
|
package appeng.tile.events;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.io.IOException;
|
2014-08-28 09:39:52 +02:00
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.lang.reflect.Method;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-08-28 09:39:52 +02:00
|
|
|
import appeng.tile.AEBaseTile;
|
2013-12-27 23:59:59 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
2014-08-28 09:39:52 +02:00
|
|
|
public class AETileEventHandler
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
2014-08-28 09:39:52 +02:00
|
|
|
private final Method method;
|
|
|
|
private final TileEventType type;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-08-28 09:39:52 +02:00
|
|
|
public AETileEventHandler(Method m, TileEventType which) {
|
|
|
|
method = m;
|
|
|
|
type = which;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// TICK
|
2014-08-28 09:39:52 +02:00
|
|
|
public void Tick(AEBaseTile tile)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
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 );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// WORLD_NBT
|
2014-08-28 09:39:52 +02:00
|
|
|
public void writeToNBT(AEBaseTile tile, NBTTagCompound data)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
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 );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// WORLD NBT
|
2014-08-28 09:39:52 +02:00
|
|
|
public void readFromNBT(AEBaseTile tile, NBTTagCompound data)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
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 );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NETWORK
|
2014-08-28 09:39:52 +02:00
|
|
|
public void writeToStream(AEBaseTile tile, ByteBuf data) throws IOException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
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 );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
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 );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|