Auto Reflection Based TileEvents.
This commit is contained in:
@@ -10,7 +10,7 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.implementations.tiles.IColorableTile;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.tile.events.AETileEventHandler;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@@ -28,61 +28,48 @@ public class TileCraftingMonitorTile extends TileCraftingTile implements IColora
|
||||
IAEItemStack dspPlay;
|
||||
AEColor paintedColor = AEColor.Transparent;
|
||||
|
||||
class CraftingMonitorHandler extends AETileEventHandler
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
public boolean readFromStream_TileCraftingMonitorTile(ByteBuf data) throws IOException
|
||||
{
|
||||
AEColor oldPaintedColor = paintedColor;
|
||||
paintedColor = AEColor.values()[data.readByte()];
|
||||
|
||||
public CraftingMonitorHandler() {
|
||||
super( TileEventType.NETWORK, TileEventType.WORLD_NBT );
|
||||
}
|
||||
boolean hasItem = data.readBoolean();
|
||||
|
||||
@Override
|
||||
public boolean readFromStream(ByteBuf data) throws IOException
|
||||
if ( hasItem )
|
||||
dspPlay = AEItemStack.loadItemStackFromPacket( data );
|
||||
else
|
||||
dspPlay = null;
|
||||
|
||||
updateList = true;
|
||||
return oldPaintedColor != paintedColor; // tesr!
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
public void writeToStream_TileCraftingMonitorTile(ByteBuf data) throws IOException
|
||||
{
|
||||
data.writeByte( paintedColor.ordinal() );
|
||||
|
||||
if ( dspPlay == null )
|
||||
data.writeBoolean( false );
|
||||
else
|
||||
{
|
||||
AEColor oldPaintedColor = paintedColor;
|
||||
paintedColor = AEColor.values()[data.readByte()];
|
||||
|
||||
boolean hasItem = data.readBoolean();
|
||||
|
||||
if ( hasItem )
|
||||
dspPlay = AEItemStack.loadItemStackFromPacket( data );
|
||||
else
|
||||
dspPlay = null;
|
||||
|
||||
updateList = true;
|
||||
return oldPaintedColor != paintedColor; // tesr!
|
||||
data.writeBoolean( true );
|
||||
dspPlay.writeToPacket( data );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(ByteBuf data) throws IOException
|
||||
{
|
||||
data.writeByte( paintedColor.ordinal() );
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_TileCraftingMonitorTile(NBTTagCompound data)
|
||||
{
|
||||
if ( data.hasKey( "paintedColor" ) )
|
||||
paintedColor = AEColor.values()[data.getByte( "paintedColor" )];
|
||||
}
|
||||
|
||||
if ( dspPlay == null )
|
||||
data.writeBoolean( false );
|
||||
else
|
||||
{
|
||||
data.writeBoolean( true );
|
||||
dspPlay.writeToPacket( data );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
if ( data.hasKey( "paintedColor" ) )
|
||||
paintedColor = AEColor.values()[data.getByte( "paintedColor" )];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
data.setByte( "paintedColor", (byte) paintedColor.ordinal() );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public TileCraftingMonitorTile() {
|
||||
addNewHandler( new CraftingMonitorHandler() );
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TileCraftingMonitorTile(NBTTagCompound data)
|
||||
{
|
||||
data.setByte( "paintedColor", (byte) paintedColor.ordinal() );
|
||||
}
|
||||
|
||||
public boolean isAccelerator()
|
||||
|
||||
@@ -28,7 +28,7 @@ import appeng.me.cluster.implementations.CraftingCPUCalculator;
|
||||
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
||||
import appeng.me.helpers.AENetworkProxy;
|
||||
import appeng.me.helpers.AENetworkProxyMultiblock;
|
||||
import appeng.tile.events.AETileEventHandler;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkTile;
|
||||
import appeng.util.Platform;
|
||||
@@ -78,38 +78,28 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IP
|
||||
clust.updateName();
|
||||
}
|
||||
|
||||
private class CraftingHandler extends AETileEventHandler
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TileCraftingTile(NBTTagCompound data)
|
||||
{
|
||||
data.setBoolean( "core", isCoreBlock );
|
||||
if ( isCoreBlock && clust != null )
|
||||
clust.writeToNBT( data );
|
||||
}
|
||||
|
||||
public CraftingHandler() {
|
||||
super( TileEventType.WORLD_NBT );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_TileCraftingTile(NBTTagCompound data)
|
||||
{
|
||||
isCoreBlock = data.getBoolean( "core" );
|
||||
if ( isCoreBlock )
|
||||
{
|
||||
data.setBoolean( "core", isCoreBlock );
|
||||
if ( isCoreBlock && clust != null )
|
||||
clust.writeToNBT( data );
|
||||
if ( clust != null )
|
||||
clust.readFromNBT( data );
|
||||
else
|
||||
previousState = (NBTTagCompound) data.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
isCoreBlock = data.getBoolean( "core" );
|
||||
if ( isCoreBlock )
|
||||
{
|
||||
if ( clust != null )
|
||||
clust.readFromNBT( data );
|
||||
else
|
||||
previousState = (NBTTagCompound) data.copy();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
public TileCraftingTile() {
|
||||
addNewHandler( new CraftingHandler() );
|
||||
gridProxy.setFlags( GridFlags.MULTIBLOCK, GridFlags.REQUIRE_CHANNEL );
|
||||
gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ import appeng.core.sync.packets.PacketAssemblerAnimation;
|
||||
import appeng.items.misc.ItemEncodedPattern;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.automation.UpgradeInventory;
|
||||
import appeng.tile.events.AETileEventHandler;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkInvTile;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
@@ -175,81 +175,71 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IAEAppEn
|
||||
return 5;
|
||||
}
|
||||
|
||||
private class TileMolecularAssemblerHandler extends AETileEventHandler
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
public boolean readFromStream_TileMolecularAssembler(ByteBuf data) throws IOException
|
||||
{
|
||||
boolean oldPower = isPowered;
|
||||
isPowered = data.readBoolean();
|
||||
return isPowered != oldPower;
|
||||
}
|
||||
|
||||
public TileMolecularAssemblerHandler() {
|
||||
super( TileEventType.WORLD_NBT, TileEventType.NETWORK );
|
||||
}
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
public void writeToStream_TileMolecularAssembler(ByteBuf data) throws IOException
|
||||
{
|
||||
data.writeBoolean( isPowered );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream(ByteBuf data) throws IOException
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TileMolecularAssembler(NBTTagCompound data)
|
||||
{
|
||||
if ( forcePlan && myPlan != null )
|
||||
{
|
||||
boolean oldPower = isPowered;
|
||||
isPowered = data.readBoolean();
|
||||
return isPowered != oldPower;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(ByteBuf data) throws IOException
|
||||
{
|
||||
data.writeBoolean( isPowered );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
if ( forcePlan && myPlan != null )
|
||||
ItemStack pattern = myPlan.getPattern();
|
||||
if ( pattern != null )
|
||||
{
|
||||
ItemStack pattern = myPlan.getPattern();
|
||||
if ( pattern != null )
|
||||
NBTTagCompound pdata = new NBTTagCompound();
|
||||
pattern.writeToNBT( pdata );
|
||||
data.setTag( "myPlan", pdata );
|
||||
data.setInteger( "pushDirection", pushDirection.ordinal() );
|
||||
}
|
||||
}
|
||||
|
||||
upgrades.writeToNBT( data, "upgrades" );
|
||||
inv.writeToNBT( data, "inv" );
|
||||
settings.writeToNBT( data );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_TileMolecularAssembler(NBTTagCompound data)
|
||||
{
|
||||
if ( data.hasKey( "myPlan" ) )
|
||||
{
|
||||
ItemStack myPat = ItemStack.loadItemStackFromNBT( data.getCompoundTag( "myPlan" ) );
|
||||
|
||||
if ( myPat != null && myPat.getItem() instanceof ItemEncodedPattern )
|
||||
{
|
||||
World w = getWorldObj();
|
||||
ItemEncodedPattern iep = (ItemEncodedPattern) myPat.getItem();
|
||||
ICraftingPatternDetails ph = iep.getPatternForItem( myPat, w );
|
||||
if ( ph != null && ph.isCraftable() )
|
||||
{
|
||||
NBTTagCompound pdata = new NBTTagCompound();
|
||||
pattern.writeToNBT( pdata );
|
||||
data.setTag( "myPlan", pdata );
|
||||
data.setInteger( "pushDirection", pushDirection.ordinal() );
|
||||
forcePlan = true;
|
||||
myPlan = ph;
|
||||
pushDirection = ForgeDirection.getOrientation( data.getInteger( "pushDirection" ) );
|
||||
}
|
||||
}
|
||||
|
||||
upgrades.writeToNBT( data, "upgrades" );
|
||||
inv.writeToNBT( data, "inv" );
|
||||
settings.writeToNBT( data );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
if ( data.hasKey( "myPlan" ) )
|
||||
{
|
||||
ItemStack myPat = ItemStack.loadItemStackFromNBT( data.getCompoundTag( "myPlan" ) );
|
||||
|
||||
if ( myPat != null && myPat.getItem() instanceof ItemEncodedPattern )
|
||||
{
|
||||
World w = getWorldObj();
|
||||
ItemEncodedPattern iep = (ItemEncodedPattern) myPat.getItem();
|
||||
ICraftingPatternDetails ph = iep.getPatternForItem( myPat, w );
|
||||
if ( ph != null && ph.isCraftable() )
|
||||
{
|
||||
forcePlan = true;
|
||||
myPlan = ph;
|
||||
pushDirection = ForgeDirection.getOrientation( data.getInteger( "pushDirection" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
upgrades.readFromNBT( data, "upgrades" );
|
||||
inv.readFromNBT( data, "inv" );
|
||||
settings.readFromNBT( data );
|
||||
recalculatePlan();
|
||||
}
|
||||
|
||||
};
|
||||
upgrades.readFromNBT( data, "upgrades" );
|
||||
inv.readFromNBT( data, "inv" );
|
||||
settings.readFromNBT( data );
|
||||
recalculatePlan();
|
||||
}
|
||||
|
||||
public TileMolecularAssembler() {
|
||||
settings.registerSetting( Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
|
||||
inv.setMaxStackSize( 1 );
|
||||
gridProxy.setIdlePowerUsage( 0.0 );
|
||||
addNewHandler( new TileMolecularAssemblerHandler() );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user