Use standard inheritance to propagage NBT events (#3058)

* Remove the old annotation system
* Use TileEntity#onLoad instead of onChunkLoad event
* Do not call invalidate in onChunkUnload and validate in onLoad
This commit is contained in:
fscan
2017-08-28 09:34:09 +02:00
committed by yueh
parent 98b9380494
commit 548af3c6cc
34 changed files with 337 additions and 685 deletions
@@ -32,8 +32,6 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.implementations.tiles.IColorableTile;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.util.AEColor;
import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
import appeng.util.item.AEItemStack;
@@ -49,9 +47,10 @@ public class TileCraftingMonitorTile extends TileCraftingTile implements IColora
private IAEItemStack dspPlay;
private AEColor paintedColor = AEColor.TRANSPARENT;
@TileEvent( TileEventType.NETWORK_READ )
public boolean readFromStream_TileCraftingMonitorTile( final ByteBuf data ) throws IOException
@Override
protected boolean readFromStream( final ByteBuf data ) throws IOException
{
final boolean c = super.readFromStream( data );
final AEColor oldPaintedColor = this.paintedColor;
this.paintedColor = AEColor.values()[data.readByte()];
@@ -67,12 +66,13 @@ public class TileCraftingMonitorTile extends TileCraftingTile implements IColora
}
this.setUpdateList( true );
return oldPaintedColor != this.paintedColor; // tesr!
return oldPaintedColor != this.paintedColor || c; // tesr!
}
@TileEvent( TileEventType.NETWORK_WRITE )
public void writeToStream_TileCraftingMonitorTile( final ByteBuf data ) throws IOException
@Override
protected void writeToStream( final ByteBuf data ) throws IOException
{
super.writeToStream( data );
data.writeByte( this.paintedColor.ordinal() );
if( this.dspPlay == null )
@@ -86,19 +86,22 @@ public class TileCraftingMonitorTile extends TileCraftingTile implements IColora
}
}
@TileEvent( TileEventType.WORLD_NBT_READ )
public void readFromNBT_TileCraftingMonitorTile( final NBTTagCompound data )
@Override
public void readFromNBT( final NBTTagCompound data )
{
super.readFromNBT( data );
if( data.hasKey( "paintedColor" ) )
{
this.paintedColor = AEColor.values()[data.getByte( "paintedColor" )];
}
}
@TileEvent( TileEventType.WORLD_NBT_WRITE )
public void writeToNBT_TileCraftingMonitorTile( final NBTTagCompound data )
@Override
public NBTTagCompound writeToNBT( final NBTTagCompound data )
{
super.writeToNBT( data );
data.setByte( "paintedColor", (byte) this.paintedColor.ordinal() );
return data;
}
@Override
@@ -51,8 +51,6 @@ 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.TileEvent;
import appeng.tile.events.TileEventType;
import appeng.tile.grid.AENetworkTile;
import appeng.util.Platform;
@@ -194,19 +192,22 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IP
return this.cluster != null;
}
@TileEvent( TileEventType.WORLD_NBT_WRITE )
public void writeToNBT_TileCraftingTile( final NBTTagCompound data )
@Override
public NBTTagCompound writeToNBT( final NBTTagCompound data )
{
super.writeToNBT( data );
data.setBoolean( "core", this.isCoreBlock() );
if( this.isCoreBlock() && this.cluster != null )
{
this.cluster.writeToNBT( data );
}
return data;
}
@TileEvent( TileEventType.WORLD_NBT_READ )
public void readFromNBT_TileCraftingTile( final NBTTagCompound data )
@Override
public void readFromNBT( final NBTTagCompound data )
{
super.readFromNBT( data );
this.setCoreBlock( data.getBoolean( "core" ) );
if( this.isCoreBlock() )
{
@@ -65,8 +65,6 @@ import appeng.items.misc.ItemEncodedPattern;
import appeng.me.GridAccessException;
import appeng.parts.automation.DefinitionUpgradeInventory;
import appeng.parts.automation.UpgradeInventory;
import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
import appeng.tile.grid.AENetworkInvTile;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.ConfigManager;
@@ -198,23 +196,26 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
return this.upgrades.getInstalledUpgrades( u );
}
@TileEvent( TileEventType.NETWORK_READ )
public boolean readFromStream_TileMolecularAssembler( final ByteBuf data )
@Override
protected boolean readFromStream( final ByteBuf data ) throws IOException
{
final boolean c = super.readFromStream( data );
final boolean oldPower = this.isPowered;
this.isPowered = data.readBoolean();
return this.isPowered != oldPower;
return this.isPowered != oldPower || c;
}
@TileEvent( TileEventType.NETWORK_WRITE )
public void writeToStream_TileMolecularAssembler( final ByteBuf data )
@Override
protected void writeToStream( final ByteBuf data ) throws IOException
{
super.writeToStream( data );
data.writeBoolean( this.isPowered );
}
@TileEvent( TileEventType.WORLD_NBT_WRITE )
public void writeToNBT_TileMolecularAssembler( final NBTTagCompound data )
@Override
public NBTTagCompound writeToNBT( final NBTTagCompound data )
{
super.writeToNBT( data );
if( this.forcePlan && this.myPlan != null )
{
final ItemStack pattern = this.myPlan.getPattern();
@@ -228,14 +229,14 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
}
this.upgrades.writeToNBT( data, "upgrades" );
this.gridInv.writeToNBT( data, "inv" );
this.patternInv.writeToNBT( data, "pattern" );
this.settings.writeToNBT( data );
return data;
}
@TileEvent( TileEventType.WORLD_NBT_READ )
public void readFromNBT_TileMolecularAssembler( final NBTTagCompound data )
@Override
public void readFromNBT( final NBTTagCompound data )
{
super.readFromNBT( data );
if( data.hasKey( "myPlan" ) )
{
final ItemStack myPat = new ItemStack( data.getCompoundTag( "myPlan" ) );
@@ -255,8 +256,6 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
}
this.upgrades.readFromNBT( data, "upgrades" );
this.gridInv.readFromNBT( data, "inv" );
this.patternInv.readFromNBT( data, "pattern" );
this.settings.readFromNBT( data );
this.recalculatePlan();
}