Store Light and Redstone Env data so to prevent cross chunk lookups.
This commit is contained in:
@@ -21,6 +21,7 @@ import net.minecraft.util.Vec3;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
import appeng.api.AEApi;
|
import appeng.api.AEApi;
|
||||||
|
import appeng.api.config.YesNo;
|
||||||
import appeng.api.exceptions.FailedConnection;
|
import appeng.api.exceptions.FailedConnection;
|
||||||
import appeng.api.implementations.parts.IPartCable;
|
import appeng.api.implementations.parts.IPartCable;
|
||||||
import appeng.api.networking.IGridHost;
|
import appeng.api.networking.IGridHost;
|
||||||
@@ -57,7 +58,7 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
|
|||||||
private FacadeContainer fc = new FacadeContainer();
|
private FacadeContainer fc = new FacadeContainer();
|
||||||
private EnumSet<LayerFlags> myLayerFlags = EnumSet.noneOf( LayerFlags.class );
|
private EnumSet<LayerFlags> myLayerFlags = EnumSet.noneOf( LayerFlags.class );
|
||||||
|
|
||||||
public boolean hasRedstone = false;
|
public YesNo hasRedstone = YesNo.UNDECIDED;
|
||||||
public IPartHost tcb;
|
public IPartHost tcb;
|
||||||
|
|
||||||
boolean inWorld = false;
|
boolean inWorld = false;
|
||||||
@@ -336,7 +337,6 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
|
|||||||
isLoading.set( true );
|
isLoading.set( true );
|
||||||
|
|
||||||
TileEntity te = getTile();
|
TileEntity te = getTile();
|
||||||
hasRedstone = te.getWorldObj().isBlockIndirectlyGettingPowered( te.xCoord, te.yCoord, te.zCoord );
|
|
||||||
|
|
||||||
// start with the center, then install the side parts into the grid.
|
// start with the center, then install the side parts into the grid.
|
||||||
for (int x = 6; x >= 0; x--)
|
for (int x = 6; x >= 0; x--)
|
||||||
@@ -492,7 +492,7 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
|
|||||||
public void onNeighborChanged()
|
public void onNeighborChanged()
|
||||||
{
|
{
|
||||||
TileEntity te = getTile();
|
TileEntity te = getTile();
|
||||||
hasRedstone = te.getWorldObj().isBlockIndirectlyGettingPowered( te.xCoord, te.yCoord, te.zCoord );
|
hasRedstone = YesNo.UNDECIDED;
|
||||||
|
|
||||||
for (ForgeDirection s : ForgeDirection.values())
|
for (ForgeDirection s : ForgeDirection.values())
|
||||||
{
|
{
|
||||||
@@ -502,6 +502,12 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateRedstone()
|
||||||
|
{
|
||||||
|
TileEntity te = getTile();
|
||||||
|
hasRedstone = te.getWorldObj().isBlockIndirectlyGettingPowered( te.xCoord, te.yCoord, te.zCoord ) ? YesNo.YES : YesNo.NO;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isSolidOnSide(ForgeDirection side)
|
public boolean isSolidOnSide(ForgeDirection side)
|
||||||
{
|
{
|
||||||
if ( side == null || side == ForgeDirection.UNKNOWN )
|
if ( side == null || side == ForgeDirection.UNKNOWN )
|
||||||
@@ -637,6 +643,8 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
|
|||||||
|
|
||||||
public void writeToNBT(NBTTagCompound data)
|
public void writeToNBT(NBTTagCompound data)
|
||||||
{
|
{
|
||||||
|
data.setInteger( "hasRedstone", hasRedstone.ordinal() );
|
||||||
|
|
||||||
for (ForgeDirection s : ForgeDirection.values())
|
for (ForgeDirection s : ForgeDirection.values())
|
||||||
{
|
{
|
||||||
fc.writeToNBT( data );
|
fc.writeToNBT( data );
|
||||||
@@ -658,6 +666,9 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
|
|||||||
|
|
||||||
public void readFromNBT(NBTTagCompound data)
|
public void readFromNBT(NBTTagCompound data)
|
||||||
{
|
{
|
||||||
|
if ( data.hasKey( "hasRedstone" ) )
|
||||||
|
hasRedstone = YesNo.values()[data.getInteger( "hasRedstone" )];
|
||||||
|
|
||||||
for (int x = 0; x < 7; x++)
|
for (int x = 0; x < 7; x++)
|
||||||
{
|
{
|
||||||
ForgeDirection side = ForgeDirection.getOrientation( x );
|
ForgeDirection side = ForgeDirection.getOrientation( x );
|
||||||
@@ -921,7 +932,10 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
|
|||||||
@Override
|
@Override
|
||||||
public boolean hasRedstone(ForgeDirection side)
|
public boolean hasRedstone(ForgeDirection side)
|
||||||
{
|
{
|
||||||
return hasRedstone;
|
if ( hasRedstone == YesNo.UNDECIDED )
|
||||||
|
updateRedstone();
|
||||||
|
|
||||||
|
return hasRedstone == YesNo.YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLadder(EntityLivingBase entity)
|
public boolean isLadder(EntityLivingBase entity)
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ public class PartToggleBus extends PartBasicState
|
|||||||
{
|
{
|
||||||
super.addToWorld();
|
super.addToWorld();
|
||||||
outerProxy.onReady();
|
outerProxy.onReady();
|
||||||
|
hasRedstone = getHost().hasRedstone( side );
|
||||||
updateInternalState();
|
updateInternalState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTi
|
|||||||
}
|
}
|
||||||
|
|
||||||
int lastValue = 0;
|
int lastValue = 0;
|
||||||
|
float opacity = -1;
|
||||||
|
|
||||||
public void setLightLevel(int out)
|
public void setLightLevel(int out)
|
||||||
{
|
{
|
||||||
@@ -53,8 +54,12 @@ public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTi
|
|||||||
|
|
||||||
private int blockLight(int emit)
|
private int blockLight(int emit)
|
||||||
{
|
{
|
||||||
TileEntity te = this.getTile();
|
if ( opacity < 0 )
|
||||||
float opacity = 255 - te.getWorldObj().getBlockLightOpacity( te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ );
|
{
|
||||||
|
TileEntity te = this.getTile();
|
||||||
|
opacity = 255 - te.getWorldObj().getBlockLightOpacity( te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ );
|
||||||
|
}
|
||||||
|
|
||||||
return (int) (emit * (opacity / 255.0f));
|
return (int) (emit * (opacity / 255.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +101,10 @@ public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTi
|
|||||||
@Override
|
@Override
|
||||||
public void onNeighborChanged()
|
public void onNeighborChanged()
|
||||||
{
|
{
|
||||||
|
opacity = -1;
|
||||||
|
|
||||||
doWork();
|
doWork();
|
||||||
|
|
||||||
if ( output )
|
if ( output )
|
||||||
getHost().markForUpdate();
|
getHost().markForUpdate();
|
||||||
}
|
}
|
||||||
@@ -105,6 +113,7 @@ public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTi
|
|||||||
public void writeToNBT(NBTTagCompound tag)
|
public void writeToNBT(NBTTagCompound tag)
|
||||||
{
|
{
|
||||||
super.writeToNBT( tag );
|
super.writeToNBT( tag );
|
||||||
|
tag.setFloat( "opacity", opacity );
|
||||||
tag.setInteger( "lastValue", lastValue );
|
tag.setInteger( "lastValue", lastValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,6 +121,8 @@ public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTi
|
|||||||
public void readFromNBT(NBTTagCompound tag)
|
public void readFromNBT(NBTTagCompound tag)
|
||||||
{
|
{
|
||||||
super.readFromNBT( tag );
|
super.readFromNBT( tag );
|
||||||
|
if ( tag.hasKey( "opacity" ) )
|
||||||
|
opacity = tag.getFloat( "opacity" );
|
||||||
lastValue = tag.getInteger( "lastValue" );
|
lastValue = tag.getInteger( "lastValue" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ public class PartMonitor extends AEBasePart implements IPartMonitor, IPowerChann
|
|||||||
|
|
||||||
byte spin = 0; // 0-3
|
byte spin = 0; // 0-3
|
||||||
int clientFlags = 0; // sent as byte.
|
int clientFlags = 0; // sent as byte.
|
||||||
|
float opacity = -1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side)
|
public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side)
|
||||||
@@ -61,6 +62,7 @@ public class PartMonitor extends AEBasePart implements IPartMonitor, IPowerChann
|
|||||||
public void writeToNBT(NBTTagCompound data)
|
public void writeToNBT(NBTTagCompound data)
|
||||||
{
|
{
|
||||||
super.writeToNBT( data );
|
super.writeToNBT( data );
|
||||||
|
data.setFloat( "opacity", opacity );
|
||||||
data.setByte( "spin", (byte) spin );
|
data.setByte( "spin", (byte) spin );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,6 +70,8 @@ public class PartMonitor extends AEBasePart implements IPartMonitor, IPowerChann
|
|||||||
public void readFromNBT(NBTTagCompound data)
|
public void readFromNBT(NBTTagCompound data)
|
||||||
{
|
{
|
||||||
super.readFromNBT( data );
|
super.readFromNBT( data );
|
||||||
|
if ( data.hasKey( "opacity" ) )
|
||||||
|
opacity = data.getFloat( "opacity" );
|
||||||
spin = data.getByte( "spin" );
|
spin = data.getByte( "spin" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,6 +122,7 @@ public class PartMonitor extends AEBasePart implements IPartMonitor, IPowerChann
|
|||||||
@Override
|
@Override
|
||||||
public void onNeighborChanged()
|
public void onNeighborChanged()
|
||||||
{
|
{
|
||||||
|
opacity = -1;
|
||||||
getHost().markForUpdate();
|
getHost().markForUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,8 +178,12 @@ public class PartMonitor extends AEBasePart implements IPartMonitor, IPowerChann
|
|||||||
|
|
||||||
private int blockLight(int emit)
|
private int blockLight(int emit)
|
||||||
{
|
{
|
||||||
TileEntity te = this.getTile();
|
if ( opacity < 0 )
|
||||||
float opacity = 255 - te.getWorldObj().getBlockLightOpacity( te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ );
|
{
|
||||||
|
TileEntity te = this.getTile();
|
||||||
|
opacity = 255 - te.getWorldObj().getBlockLightOpacity( te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ );
|
||||||
|
}
|
||||||
|
|
||||||
return (int) (emit * (opacity / 255.0f));
|
return (int) (emit * (opacity / 255.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ import java.util.concurrent.Callable;
|
|||||||
|
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
import appeng.api.config.Actionable;
|
import appeng.api.config.Actionable;
|
||||||
import appeng.api.config.PowerMultiplier;
|
import appeng.api.config.PowerMultiplier;
|
||||||
|
import appeng.api.config.YesNo;
|
||||||
import appeng.api.implementations.TransitionResult;
|
import appeng.api.implementations.TransitionResult;
|
||||||
import appeng.api.implementations.items.ISpatialStorageCell;
|
import appeng.api.implementations.items.ISpatialStorageCell;
|
||||||
import appeng.api.networking.GridFlags;
|
import appeng.api.networking.GridFlags;
|
||||||
@@ -20,6 +22,8 @@ import appeng.api.util.DimensionalCoord;
|
|||||||
import appeng.hooks.TickHandler;
|
import appeng.hooks.TickHandler;
|
||||||
import appeng.items.storage.ItemSpatialStorageCell;
|
import appeng.items.storage.ItemSpatialStorageCell;
|
||||||
import appeng.me.cache.SpatialPylonCache;
|
import appeng.me.cache.SpatialPylonCache;
|
||||||
|
import appeng.tile.events.AETileEventHandler;
|
||||||
|
import appeng.tile.events.TileEventType;
|
||||||
import appeng.tile.grid.AENetworkInvTile;
|
import appeng.tile.grid.AENetworkInvTile;
|
||||||
import appeng.tile.inventory.AppEngInternalInventory;
|
import appeng.tile.inventory.AppEngInternalInventory;
|
||||||
import appeng.tile.inventory.InvOperation;
|
import appeng.tile.inventory.InvOperation;
|
||||||
@@ -30,25 +34,53 @@ public class TileSpatialIOPort extends AENetworkInvTile implements Callable
|
|||||||
|
|
||||||
final int sides[] = { 0, 1 };
|
final int sides[] = { 0, 1 };
|
||||||
AppEngInternalInventory inv = new AppEngInternalInventory( this, 2 );
|
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() {
|
public TileSpatialIOPort() {
|
||||||
|
addNewHandler( new SpatialTileIOPortHandler() );
|
||||||
gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL );
|
gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateRedstoneState()
|
public void updateRedstoneState()
|
||||||
{
|
{
|
||||||
boolean currentState = worldObj.isBlockIndirectlyGettingPowered( xCoord, yCoord, zCoord );
|
YesNo currentState = worldObj.isBlockIndirectlyGettingPowered( xCoord, yCoord, zCoord ) ? YesNo.YES : YesNo.NO;
|
||||||
if ( lastRedstoneState != currentState )
|
if ( lastRedstoneState != currentState )
|
||||||
{
|
{
|
||||||
lastRedstoneState = currentState;
|
lastRedstoneState = currentState;
|
||||||
if ( currentState )
|
if ( lastRedstoneState == YesNo.YES )
|
||||||
{
|
|
||||||
triggerTransition();
|
triggerTransition();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getRedstoneState()
|
||||||
|
{
|
||||||
|
if ( lastRedstoneState == YesNo.UNDECIDED )
|
||||||
|
updateRedstoneState();
|
||||||
|
|
||||||
|
return lastRedstoneState == YesNo.YES;
|
||||||
|
}
|
||||||
|
|
||||||
private void triggerTransition()
|
private void triggerTransition()
|
||||||
{
|
{
|
||||||
if ( Platform.isServer() )
|
if ( Platform.isServer() )
|
||||||
@@ -81,7 +113,7 @@ public class TileSpatialIOPort extends AENetworkInvTile implements Callable
|
|||||||
if ( Math.abs( pr - req ) < req * 0.001 )
|
if ( Math.abs( pr - req ) < req * 0.001 )
|
||||||
{
|
{
|
||||||
MENetworkEvent res = gi.postEvent( new MENetworkSpatialEvent( this, req ) );
|
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 );
|
TransitionResult tr = sc.doSpatialTransition( cell, worldObj, spc.getMin(), spc.getMax(), true );
|
||||||
if ( tr.success )
|
if ( tr.success )
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import appeng.api.config.OperationMode;
|
|||||||
import appeng.api.config.RedstoneMode;
|
import appeng.api.config.RedstoneMode;
|
||||||
import appeng.api.config.Settings;
|
import appeng.api.config.Settings;
|
||||||
import appeng.api.config.Upgrades;
|
import appeng.api.config.Upgrades;
|
||||||
|
import appeng.api.config.YesNo;
|
||||||
import appeng.api.implementations.IUpgradeableHost;
|
import appeng.api.implementations.IUpgradeableHost;
|
||||||
import appeng.api.networking.GridFlags;
|
import appeng.api.networking.GridFlags;
|
||||||
import appeng.api.networking.IGridNode;
|
import appeng.api.networking.IGridNode;
|
||||||
@@ -59,7 +60,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
|||||||
|
|
||||||
BaseActionSource mySrc = new MachineSource( this );
|
BaseActionSource mySrc = new MachineSource( this );
|
||||||
|
|
||||||
boolean lastRedstoneState = false;
|
YesNo lastRedstoneState = YesNo.UNDECIDED;
|
||||||
|
|
||||||
class TileIOPortHandler extends AETileEventHandler
|
class TileIOPortHandler extends AETileEventHandler
|
||||||
{
|
{
|
||||||
@@ -74,6 +75,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
|||||||
cm.writeToNBT( data );
|
cm.writeToNBT( data );
|
||||||
cells.writeToNBT( data, "cells" );
|
cells.writeToNBT( data, "cells" );
|
||||||
upgrades.writeToNBT( data, "upgrades" );
|
upgrades.writeToNBT( data, "upgrades" );
|
||||||
|
data.setInteger( "lastRedstoneState", lastRedstoneState.ordinal() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -82,6 +84,8 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
|||||||
cm.readFromNBT( data );
|
cm.readFromNBT( data );
|
||||||
cells.readFromNBT( data, "cells" );
|
cells.readFromNBT( data, "cells" );
|
||||||
upgrades.readFromNBT( data, "upgrades" );
|
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()
|
public void updateRedstoneState()
|
||||||
{
|
{
|
||||||
boolean currentState = worldObj.isBlockIndirectlyGettingPowered( xCoord, yCoord, zCoord );
|
YesNo currentState = worldObj.isBlockIndirectlyGettingPowered( xCoord, yCoord, zCoord ) ? YesNo.YES : YesNo.NO;
|
||||||
if ( lastRedstoneState != currentState )
|
if ( lastRedstoneState != currentState )
|
||||||
{
|
{
|
||||||
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()
|
private boolean isEnabled()
|
||||||
{
|
{
|
||||||
if ( getInstalledUpgrades( Upgrades.REDSTONE ) == 0 )
|
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 );
|
RedstoneMode rs = (RedstoneMode) cm.getSetting( Settings.REDSTONE_CONTROLLED );
|
||||||
if ( rs == RedstoneMode.HIGH_SIGNAL )
|
if ( rs == RedstoneMode.HIGH_SIGNAL )
|
||||||
return lastRedstoneState;
|
return getRedstoneState();
|
||||||
return !lastRedstoneState;
|
return !getRedstoneState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user