Auto Reflection Based TileEvents.
This commit is contained in:
+80
-90
@@ -57,7 +57,7 @@ import appeng.api.util.IConfigManager;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.storage.MEInventoryHandler;
|
||||
import appeng.tile.events.AETileEventHandler;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkPowerTile;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
@@ -143,114 +143,105 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, IFluidHan
|
||||
recalculateDisplay();
|
||||
}
|
||||
|
||||
private class invManger extends AETileEventHandler
|
||||
@TileEvent(TileEventType.TICK)
|
||||
public void Tick_TileChest()
|
||||
{
|
||||
if ( worldObj.isRemote )
|
||||
return;
|
||||
|
||||
public invManger() {
|
||||
super( TileEventType.TICK, TileEventType.NETWORK, TileEventType.WORLD_NBT );
|
||||
}
|
||||
double idleUsage = gridProxy.getIdlePowerUsage();
|
||||
|
||||
@Override
|
||||
public void Tick()
|
||||
try
|
||||
{
|
||||
if ( worldObj.isRemote )
|
||||
return;
|
||||
|
||||
double idleUsage = gridProxy.getIdlePowerUsage();
|
||||
|
||||
try
|
||||
if ( !gridProxy.getEnergy().isNetworkPowered() )
|
||||
{
|
||||
if ( !gridProxy.getEnergy().isNetworkPowered() )
|
||||
{
|
||||
double powerUsed = extractAEPower( idleUsage, Actionable.MODULATE, PowerMultiplier.CONFIG ); // drain
|
||||
if ( powerUsed + 0.1 >= idleUsage != (state & 0x40) > 0 )
|
||||
recalculateDisplay();
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
double powerUsed = extractAEPower( gridProxy.getIdlePowerUsage(), Actionable.MODULATE, PowerMultiplier.CONFIG ); // drain
|
||||
double powerUsed = extractAEPower( idleUsage, Actionable.MODULATE, PowerMultiplier.CONFIG ); // drain
|
||||
if ( powerUsed + 0.1 >= idleUsage != (state & 0x40) > 0 )
|
||||
recalculateDisplay();
|
||||
}
|
||||
|
||||
if ( inv.getStackInSlot( 0 ) != null )
|
||||
{
|
||||
tryToStoreContents();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(ByteBuf data) throws IOException
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
if ( worldObj.getTotalWorldTime() - lastStateChange > 8 )
|
||||
state = 0;
|
||||
else
|
||||
state &= 0x24924924; // just keep the blinks...
|
||||
|
||||
for (int x = 0; x < getCellCount(); x++)
|
||||
state |= (getCellStatus( x ) << (3 * x));
|
||||
|
||||
if ( isPowered() )
|
||||
state |= 0x40;
|
||||
else
|
||||
state &= ~0x40;
|
||||
|
||||
data.writeByte( state );
|
||||
data.writeByte( paintedColor.ordinal() );
|
||||
|
||||
ItemStack is = inv.getStackInSlot( 1 );
|
||||
|
||||
if ( is == null )
|
||||
{
|
||||
data.writeInt( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
data.writeInt( (is.getItemDamage() << Platform.DEF_OFFSET) | Item.getIdFromItem( is.getItem() ) );
|
||||
}
|
||||
double powerUsed = extractAEPower( gridProxy.getIdlePowerUsage(), Actionable.MODULATE, PowerMultiplier.CONFIG ); // drain
|
||||
if ( powerUsed + 0.1 >= idleUsage != (state & 0x40) > 0 )
|
||||
recalculateDisplay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream(ByteBuf data) throws IOException
|
||||
if ( inv.getStackInSlot( 0 ) != null )
|
||||
{
|
||||
int oldState = state;
|
||||
ItemStack oldType = storageType;
|
||||
|
||||
state = data.readByte();
|
||||
AEColor oldPaintedColor = paintedColor;
|
||||
paintedColor = AEColor.values()[data.readByte()];
|
||||
|
||||
int item = data.readInt();
|
||||
|
||||
if ( item == 0 )
|
||||
storageType = null;
|
||||
else
|
||||
storageType = new ItemStack( Item.getItemById( item & 0xffff ), 1, item >> Platform.DEF_OFFSET );
|
||||
|
||||
lastStateChange = worldObj.getTotalWorldTime();
|
||||
|
||||
return oldPaintedColor != paintedColor || (state & 0xDB6DB6DB) != (oldState & 0xDB6DB6DB) || !Platform.isSameItemPrecise( oldType, storageType );
|
||||
tryToStoreContents();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
public void writeToStream_TileChest(ByteBuf data) throws IOException
|
||||
{
|
||||
if ( worldObj.getTotalWorldTime() - lastStateChange > 8 )
|
||||
state = 0;
|
||||
else
|
||||
state &= 0x24924924; // just keep the blinks...
|
||||
|
||||
for (int x = 0; x < getCellCount(); x++)
|
||||
state |= (getCellStatus( x ) << (3 * x));
|
||||
|
||||
if ( isPowered() )
|
||||
state |= 0x40;
|
||||
else
|
||||
state &= ~0x40;
|
||||
|
||||
data.writeByte( state );
|
||||
data.writeByte( paintedColor.ordinal() );
|
||||
|
||||
ItemStack is = inv.getStackInSlot( 1 );
|
||||
|
||||
if ( is == null )
|
||||
{
|
||||
config.readFromNBT( data );
|
||||
priority = data.getInteger( "priority" );
|
||||
if ( data.hasKey( "paintedColor" ) )
|
||||
paintedColor = AEColor.values()[data.getByte( "paintedColor" )];
|
||||
data.writeInt( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
else
|
||||
{
|
||||
config.writeToNBT( data );
|
||||
data.setInteger( "priority", priority );
|
||||
data.setByte( "paintedColor", (byte) paintedColor.ordinal() );
|
||||
data.writeInt( (is.getItemDamage() << Platform.DEF_OFFSET) | Item.getIdFromItem( is.getItem() ) );
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
public boolean readFromStream_TileChest(ByteBuf data) throws IOException
|
||||
{
|
||||
int oldState = state;
|
||||
ItemStack oldType = storageType;
|
||||
|
||||
state = data.readByte();
|
||||
AEColor oldPaintedColor = paintedColor;
|
||||
paintedColor = AEColor.values()[data.readByte()];
|
||||
|
||||
int item = data.readInt();
|
||||
|
||||
if ( item == 0 )
|
||||
storageType = null;
|
||||
else
|
||||
storageType = new ItemStack( Item.getItemById( item & 0xffff ), 1, item >> Platform.DEF_OFFSET );
|
||||
|
||||
lastStateChange = worldObj.getTotalWorldTime();
|
||||
|
||||
return oldPaintedColor != paintedColor || (state & 0xDB6DB6DB) != (oldState & 0xDB6DB6DB) || !Platform.isSameItemPrecise( oldType, storageType );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_TileChest(NBTTagCompound data)
|
||||
{
|
||||
config.readFromNBT( data );
|
||||
priority = data.getInteger( "priority" );
|
||||
if ( data.hasKey( "paintedColor" ) )
|
||||
paintedColor = AEColor.values()[data.getByte( "paintedColor" )];
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TileChest(NBTTagCompound data)
|
||||
{
|
||||
config.writeToNBT( data );
|
||||
data.setInteger( "priority", priority );
|
||||
data.setByte( "paintedColor", (byte) paintedColor.ordinal() );
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(MENetworkPowerStatusChange c)
|
||||
@@ -267,7 +258,6 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, IFluidHan
|
||||
public TileChest() {
|
||||
internalMaxPower = PowerMultiplier.CONFIG.multiply( 40 );
|
||||
gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL );
|
||||
addNewHandler( new invManger() );
|
||||
config.registerSetting( Settings.SORT_BY, SortOrder.NAME );
|
||||
config.registerSetting( Settings.VIEW_MODE, ViewItems.ALL );
|
||||
config.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING );
|
||||
|
||||
+34
-44
@@ -32,7 +32,7 @@ import appeng.helpers.IPriorityHost;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.storage.DriveWatcher;
|
||||
import appeng.me.storage.MEInventoryHandler;
|
||||
import appeng.tile.events.AETileEventHandler;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkInvTile;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
@@ -87,55 +87,46 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
|
||||
markForUpdate();
|
||||
}
|
||||
|
||||
private class invManger extends AETileEventHandler
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
public void writeToStream_TileDrive(ByteBuf data) throws IOException
|
||||
{
|
||||
if ( worldObj.getTotalWorldTime() - lastStateChange > 8 )
|
||||
state = 0;
|
||||
else
|
||||
state &= 0x24924924; // just keep the blinks...
|
||||
|
||||
public invManger() {
|
||||
super( TileEventType.WORLD_NBT, TileEventType.NETWORK );
|
||||
}
|
||||
if ( gridProxy.isActive() )
|
||||
state |= 0x80000000;
|
||||
else
|
||||
state &= ~0x80000000;
|
||||
|
||||
@Override
|
||||
public void writeToStream(ByteBuf data) throws IOException
|
||||
{
|
||||
if ( worldObj.getTotalWorldTime() - lastStateChange > 8 )
|
||||
state = 0;
|
||||
else
|
||||
state &= 0x24924924; // just keep the blinks...
|
||||
for (int x = 0; x < getCellCount(); x++)
|
||||
state |= (getCellStatus( x ) << (3 * x));
|
||||
|
||||
if ( gridProxy.isActive() )
|
||||
state |= 0x80000000;
|
||||
else
|
||||
state &= ~0x80000000;
|
||||
data.writeInt( state );
|
||||
}
|
||||
|
||||
for (int x = 0; x < getCellCount(); x++)
|
||||
state |= (getCellStatus( x ) << (3 * x));
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
public boolean readFromStream_TileDrive(ByteBuf data) throws IOException
|
||||
{
|
||||
int oldState = state;
|
||||
state = data.readInt();
|
||||
lastStateChange = worldObj.getTotalWorldTime();
|
||||
return (state & 0xDB6DB6DB) != (oldState & 0xDB6DB6DB);
|
||||
}
|
||||
|
||||
data.writeInt( state );
|
||||
}
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_TileDrive(NBTTagCompound data)
|
||||
{
|
||||
isCached = false;
|
||||
priority = data.getInteger( "priority" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream(ByteBuf data) throws IOException
|
||||
{
|
||||
int oldState = state;
|
||||
state = data.readInt();
|
||||
lastStateChange = worldObj.getTotalWorldTime();
|
||||
return (state & 0xDB6DB6DB) != (oldState & 0xDB6DB6DB);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
isCached = false;
|
||||
priority = data.getInteger( "priority" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
data.setInteger( "priority", priority );
|
||||
}
|
||||
|
||||
};
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TileDrive(NBTTagCompound data)
|
||||
{
|
||||
data.setInteger( "priority", priority );
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(MENetworkPowerStatusChange c)
|
||||
@@ -152,7 +143,6 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
|
||||
public TileDrive() {
|
||||
mySrc = new MachineSource( this );
|
||||
gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL );
|
||||
addNewHandler( new invManger() );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -34,7 +34,7 @@ import appeng.api.util.IConfigManager;
|
||||
import appeng.core.settings.TickRates;
|
||||
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;
|
||||
@@ -62,35 +62,26 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
|
||||
YesNo lastRedstoneState = YesNo.UNDECIDED;
|
||||
|
||||
class TileIOPortHandler extends AETileEventHandler
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TileIOPort(NBTTagCompound data)
|
||||
{
|
||||
cm.writeToNBT( data );
|
||||
cells.writeToNBT( data, "cells" );
|
||||
upgrades.writeToNBT( data, "upgrades" );
|
||||
data.setInteger( "lastRedstoneState", lastRedstoneState.ordinal() );
|
||||
}
|
||||
|
||||
public TileIOPortHandler() {
|
||||
super( TileEventType.WORLD_NBT );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
cm.writeToNBT( data );
|
||||
cells.writeToNBT( data, "cells" );
|
||||
upgrades.writeToNBT( data, "upgrades" );
|
||||
data.setInteger( "lastRedstoneState", lastRedstoneState.ordinal() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
cm.readFromNBT( data );
|
||||
cells.readFromNBT( data, "cells" );
|
||||
upgrades.readFromNBT( data, "upgrades" );
|
||||
if ( data.hasKey( "lastRedstoneState" ) )
|
||||
lastRedstoneState = YesNo.values()[data.getInteger( "lastRedstoneState" )];
|
||||
}
|
||||
};
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_TileIOPort(NBTTagCompound data)
|
||||
{
|
||||
cm.readFromNBT( data );
|
||||
cells.readFromNBT( data, "cells" );
|
||||
upgrades.readFromNBT( data, "upgrades" );
|
||||
if ( data.hasKey( "lastRedstoneState" ) )
|
||||
lastRedstoneState = YesNo.values()[data.getInteger( "lastRedstoneState" )];
|
||||
}
|
||||
|
||||
public TileIOPort() {
|
||||
addNewHandler( new TileIOPortHandler() );
|
||||
gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL );
|
||||
cm.registerSetting( Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
|
||||
cm.registerSetting( Settings.FULLNESS_MODE, FullnessMode.EMPTY );
|
||||
|
||||
@@ -8,7 +8,7 @@ import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.tile.AEBaseInvTile;
|
||||
import appeng.tile.events.AETileEventHandler;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
@@ -20,35 +20,22 @@ public class TileSkyChest extends AEBaseInvTile
|
||||
final int sides[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 };
|
||||
final AppEngInternalInventory inv = new AppEngInternalInventory( this, 9 * 4 );
|
||||
|
||||
class SkyChestHnadler extends AETileEventHandler
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
public void writeToStream_TileSkyChest(ByteBuf data) throws IOException
|
||||
{
|
||||
data.writeBoolean( playerOpen > 0 );
|
||||
}
|
||||
|
||||
public SkyChestHnadler() {
|
||||
super( TileEventType.NETWORK );
|
||||
}
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
public boolean readFromStream_TileSkyChest(ByteBuf data) throws IOException
|
||||
{
|
||||
int wasOpen = playerOpen;
|
||||
playerOpen = data.readBoolean() ? 1 : 0;
|
||||
|
||||
@Override
|
||||
public void writeToStream(ByteBuf data) throws IOException
|
||||
{
|
||||
data.writeBoolean( playerOpen > 0 );
|
||||
}
|
||||
if ( wasOpen != playerOpen )
|
||||
lastEvent = System.currentTimeMillis();
|
||||
|
||||
@Override
|
||||
public boolean readFromStream(ByteBuf data) throws IOException
|
||||
{
|
||||
int wasOpen = playerOpen;
|
||||
playerOpen = data.readBoolean() ? 1 : 0;
|
||||
|
||||
if ( wasOpen != playerOpen )
|
||||
lastEvent = System.currentTimeMillis();
|
||||
|
||||
return false; // TESR yo!
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public TileSkyChest() {
|
||||
addNewHandler( new SkyChestHnadler() );
|
||||
return false; // TESR yo!
|
||||
}
|
||||
|
||||
// server
|
||||
|
||||
Reference in New Issue
Block a user