Store Light and Redstone Env data so to prevent cross chunk lookups.
This commit is contained in:
@@ -4,9 +4,11 @@ import java.util.concurrent.Callable;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.config.YesNo;
|
||||
import appeng.api.implementations.TransitionResult;
|
||||
import appeng.api.implementations.items.ISpatialStorageCell;
|
||||
import appeng.api.networking.GridFlags;
|
||||
@@ -20,6 +22,8 @@ import appeng.api.util.DimensionalCoord;
|
||||
import appeng.hooks.TickHandler;
|
||||
import appeng.items.storage.ItemSpatialStorageCell;
|
||||
import appeng.me.cache.SpatialPylonCache;
|
||||
import appeng.tile.events.AETileEventHandler;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkInvTile;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
@@ -30,25 +34,53 @@ public class TileSpatialIOPort extends AENetworkInvTile implements Callable
|
||||
|
||||
final int sides[] = { 0, 1 };
|
||||
AppEngInternalInventory inv = new AppEngInternalInventory( this, 2 );
|
||||
boolean lastRedstoneState = false;
|
||||
YesNo lastRedstoneState = YesNo.UNDECIDED;
|
||||
|
||||
class SpatialTileIOPortHandler extends AETileEventHandler
|
||||
{
|
||||
|
||||
public SpatialTileIOPortHandler() {
|
||||
super( TileEventType.WORLD_NBT );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
data.setInteger( "lastRedstoneState", lastRedstoneState.ordinal() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
if ( data.hasKey( "lastRedstoneState" ) )
|
||||
lastRedstoneState = YesNo.values()[data.getInteger( "lastRedstoneState" )];
|
||||
}
|
||||
};
|
||||
|
||||
public TileSpatialIOPort() {
|
||||
addNewHandler( new SpatialTileIOPortHandler() );
|
||||
gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL );
|
||||
}
|
||||
|
||||
public void updateRedstoneState()
|
||||
{
|
||||
boolean currentState = worldObj.isBlockIndirectlyGettingPowered( xCoord, yCoord, zCoord );
|
||||
YesNo currentState = worldObj.isBlockIndirectlyGettingPowered( xCoord, yCoord, zCoord ) ? YesNo.YES : YesNo.NO;
|
||||
if ( lastRedstoneState != currentState )
|
||||
{
|
||||
lastRedstoneState = currentState;
|
||||
if ( currentState )
|
||||
{
|
||||
if ( lastRedstoneState == YesNo.YES )
|
||||
triggerTransition();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getRedstoneState()
|
||||
{
|
||||
if ( lastRedstoneState == YesNo.UNDECIDED )
|
||||
updateRedstoneState();
|
||||
|
||||
return lastRedstoneState == YesNo.YES;
|
||||
}
|
||||
|
||||
private void triggerTransition()
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
@@ -81,7 +113,7 @@ public class TileSpatialIOPort extends AENetworkInvTile implements Callable
|
||||
if ( Math.abs( pr - req ) < req * 0.001 )
|
||||
{
|
||||
MENetworkEvent res = gi.postEvent( new MENetworkSpatialEvent( this, req ) );
|
||||
if ( ! res.isCanceled() )
|
||||
if ( !res.isCanceled() )
|
||||
{
|
||||
TransitionResult tr = sc.doSpatialTransition( cell, worldObj, spc.getMin(), spc.getMax(), true );
|
||||
if ( tr.success )
|
||||
|
||||
@@ -11,6 +11,7 @@ import appeng.api.config.OperationMode;
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.config.YesNo;
|
||||
import appeng.api.implementations.IUpgradeableHost;
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.IGridNode;
|
||||
@@ -59,7 +60,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
|
||||
BaseActionSource mySrc = new MachineSource( this );
|
||||
|
||||
boolean lastRedstoneState = false;
|
||||
YesNo lastRedstoneState = YesNo.UNDECIDED;
|
||||
|
||||
class TileIOPortHandler extends AETileEventHandler
|
||||
{
|
||||
@@ -74,6 +75,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
cm.writeToNBT( data );
|
||||
cells.writeToNBT( data, "cells" );
|
||||
upgrades.writeToNBT( data, "upgrades" );
|
||||
data.setInteger( "lastRedstoneState", lastRedstoneState.ordinal() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,6 +84,8 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
cm.readFromNBT( data );
|
||||
cells.readFromNBT( data, "cells" );
|
||||
upgrades.readFromNBT( data, "upgrades" );
|
||||
if ( data.hasKey( "lastRedstoneState" ) )
|
||||
lastRedstoneState = YesNo.values()[data.getInteger( "lastRedstoneState" )];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -137,7 +141,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
|
||||
public void updateRedstoneState()
|
||||
{
|
||||
boolean currentState = worldObj.isBlockIndirectlyGettingPowered( xCoord, yCoord, zCoord );
|
||||
YesNo currentState = worldObj.isBlockIndirectlyGettingPowered( xCoord, yCoord, zCoord ) ? YesNo.YES : YesNo.NO;
|
||||
if ( lastRedstoneState != currentState )
|
||||
{
|
||||
lastRedstoneState = currentState;
|
||||
@@ -145,6 +149,14 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getRedstoneState()
|
||||
{
|
||||
if ( lastRedstoneState == YesNo.UNDECIDED )
|
||||
updateRedstoneState();
|
||||
|
||||
return lastRedstoneState == YesNo.YES;
|
||||
}
|
||||
|
||||
private boolean isEnabled()
|
||||
{
|
||||
if ( getInstalledUpgrades( Upgrades.REDSTONE ) == 0 )
|
||||
@@ -152,8 +164,8 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
|
||||
RedstoneMode rs = (RedstoneMode) cm.getSetting( Settings.REDSTONE_CONTROLLED );
|
||||
if ( rs == RedstoneMode.HIGH_SIGNAL )
|
||||
return lastRedstoneState;
|
||||
return !lastRedstoneState;
|
||||
return getRedstoneState();
|
||||
return !getRedstoneState();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user