Relocate Source to proper directory.
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
package appeng.tile.spatial;
|
||||
|
||||
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;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.events.MENetworkEvent;
|
||||
import appeng.api.networking.events.MENetworkSpatialEvent;
|
||||
import appeng.api.networking.spatial.ISpatialCache;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.hooks.TickHandler;
|
||||
import appeng.items.storage.ItemSpatialStorageCell;
|
||||
import appeng.me.cache.SpatialPylonCache;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkInvTile;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class TileSpatialIOPort extends AENetworkInvTile implements Callable
|
||||
{
|
||||
|
||||
final int sides[] = { 0, 1 };
|
||||
AppEngInternalInventory inv = new AppEngInternalInventory( this, 2 );
|
||||
YesNo lastRedstoneState = YesNo.UNDECIDED;
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TileSpatialIOPort(NBTTagCompound data)
|
||||
{
|
||||
data.setInteger( "lastRedstoneState", lastRedstoneState.ordinal() );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_TileSpatialIOPort(NBTTagCompound data)
|
||||
{
|
||||
if ( data.hasKey( "lastRedstoneState" ) )
|
||||
lastRedstoneState = YesNo.values()[data.getInteger( "lastRedstoneState" )];
|
||||
}
|
||||
|
||||
public TileSpatialIOPort() {
|
||||
gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL );
|
||||
}
|
||||
|
||||
public void updateRedstoneState()
|
||||
{
|
||||
YesNo currentState = worldObj.isBlockIndirectlyGettingPowered( xCoord, yCoord, zCoord ) ? YesNo.YES : YesNo.NO;
|
||||
if ( lastRedstoneState != currentState )
|
||||
{
|
||||
lastRedstoneState = currentState;
|
||||
if ( lastRedstoneState == YesNo.YES )
|
||||
triggerTransition();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getRedstoneState()
|
||||
{
|
||||
if ( lastRedstoneState == YesNo.UNDECIDED )
|
||||
updateRedstoneState();
|
||||
|
||||
return lastRedstoneState == YesNo.YES;
|
||||
}
|
||||
|
||||
private void triggerTransition()
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
{
|
||||
ItemStack cell = getStackInSlot( 0 );
|
||||
if ( isSpatialCell( cell ) )
|
||||
{
|
||||
TickHandler.instance.addCallable( null, this );// this needs to be cross world synced.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object call() throws Exception
|
||||
{
|
||||
|
||||
ItemStack cell = getStackInSlot( 0 );
|
||||
if ( isSpatialCell( cell ) && getStackInSlot( 1 ) == null )
|
||||
{
|
||||
IGrid gi = gridProxy.getGrid();
|
||||
IEnergyGrid energy = gridProxy.getEnergy();
|
||||
|
||||
ItemSpatialStorageCell sc = (ItemSpatialStorageCell) cell.getItem();
|
||||
|
||||
SpatialPylonCache spc = (SpatialPylonCache) gi.getCache( ISpatialCache.class );
|
||||
if ( spc.hasRegion() && spc.isValidRegion() )
|
||||
{
|
||||
double req = spc.requiredPower();
|
||||
double pr = energy.extractAEPower( req, Actionable.SIMULATE, PowerMultiplier.CONFIG );
|
||||
if ( Math.abs( pr - req ) < req * 0.001 )
|
||||
{
|
||||
MENetworkEvent res = gi.postEvent( new MENetworkSpatialEvent( this, req ) );
|
||||
if ( !res.isCanceled() )
|
||||
{
|
||||
TransitionResult tr = sc.doSpatialTransition( cell, worldObj, spc.getMin(), spc.getMax(), true );
|
||||
if ( tr.success )
|
||||
{
|
||||
energy.extractAEPower( req, Actionable.MODULATE, PowerMultiplier.CONFIG );
|
||||
setInventorySlotContents( 0, null );
|
||||
setInventorySlotContents( 1, cell );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType(ForgeDirection dir)
|
||||
{
|
||||
return AECableType.SMART;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionalCoord getLocation()
|
||||
{
|
||||
return new DimensionalCoord( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
{
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return (i == 0 ? isSpatialCell( itemstack ) : false);
|
||||
}
|
||||
|
||||
private boolean isSpatialCell(ItemStack cell)
|
||||
{
|
||||
if ( cell != null && cell.getItem() instanceof ISpatialStorageCell )
|
||||
{
|
||||
ISpatialStorageCell sc = (ISpatialStorageCell) cell.getItem();
|
||||
return sc != null && sc.isSpatialStorage( cell );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return isItemValidForSlot( i, itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return i == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide(ForgeDirection side)
|
||||
{
|
||||
return sides;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
package appeng.tile.spatial;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cluster.IAEMultiBlock;
|
||||
import appeng.me.cluster.implementations.SpatialPylonCalculator;
|
||||
import appeng.me.cluster.implementations.SpatialPylonCluster;
|
||||
import appeng.me.helpers.AENetworkProxy;
|
||||
import appeng.me.helpers.AENetworkProxyMultiblock;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkTile;
|
||||
|
||||
public class TileSpatialPylon extends AENetworkTile implements IAEMultiBlock
|
||||
{
|
||||
|
||||
public final int DISPLAY_ENDMIN = 0x01;
|
||||
public final int DISPLAY_ENDMAX = 0x02;
|
||||
public final int DISPLAY_MIDDLE = 0x01 + 0x02;
|
||||
public final int DISPLAY_X = 0x04;
|
||||
public final int DISPLAY_Y = 0x08;
|
||||
public final int DISPLAY_Z = 0x04 + 0x08;
|
||||
public final int MB_STATUS = 0x01 + 0x02 + 0x04 + 0x08;
|
||||
|
||||
public final int DISPLAY_ENABLED = 0x10;
|
||||
public final int DISPLAY_POWEREDENABLED = 0x20;
|
||||
public final int NET_STATUS = 0x10 + 0x20;
|
||||
|
||||
int displayBits = 0;
|
||||
SpatialPylonCluster clust;
|
||||
final SpatialPylonCalculator calc = new SpatialPylonCalculator( this );
|
||||
|
||||
boolean didHaveLight = false;
|
||||
|
||||
@Override
|
||||
protected AENetworkProxy createProxy()
|
||||
{
|
||||
return new AENetworkProxyMultiblock( this, "proxy", getItemFromTile( this ), true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeRotated()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
public boolean readFromStream_TileSpatialPylon(ByteBuf data) throws IOException
|
||||
{
|
||||
int old = displayBits;
|
||||
displayBits = data.readByte();
|
||||
return old != displayBits;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
public void writeToStream_TileSpatialPylon(ByteBuf data) throws IOException
|
||||
{
|
||||
data.writeByte( displayBits );
|
||||
}
|
||||
|
||||
public TileSpatialPylon() {
|
||||
gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL, GridFlags.MULTIBLOCK );
|
||||
gridProxy.setIdlePowerUsage( 0.5 );
|
||||
gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady()
|
||||
{
|
||||
super.onReady();
|
||||
onNeighborBlockChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markForUpdate()
|
||||
{
|
||||
super.markForUpdate();
|
||||
boolean hasLight = getLightValue() > 0;
|
||||
if ( hasLight != didHaveLight )
|
||||
{
|
||||
didHaveLight = hasLight;
|
||||
worldObj.func_147451_t( xCoord, yCoord, zCoord );
|
||||
// worldObj.updateAllLightTypes( xCoord, yCoord, zCoord );
|
||||
}
|
||||
}
|
||||
|
||||
public int getLightValue()
|
||||
{
|
||||
if ( (displayBits & DISPLAY_POWEREDENABLED) == DISPLAY_POWEREDENABLED )
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(MENetworkPowerStatusChange c)
|
||||
{
|
||||
recalculateDisplay();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void activeRender(MENetworkChannelsChanged c)
|
||||
{
|
||||
recalculateDisplay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
disconnect( false );
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload()
|
||||
{
|
||||
disconnect( false );
|
||||
super.onChunkUnload();
|
||||
}
|
||||
|
||||
public void onNeighborBlockChange()
|
||||
{
|
||||
calc.calculateMultiblock( worldObj, getLocation() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpatialPylonCluster getCluster()
|
||||
{
|
||||
return clust;
|
||||
}
|
||||
|
||||
public void recalculateDisplay()
|
||||
{
|
||||
int oldBits = displayBits;
|
||||
|
||||
displayBits = 0;
|
||||
|
||||
if ( clust != null )
|
||||
{
|
||||
if ( clust.min.equals( getLocation() ) )
|
||||
displayBits = DISPLAY_ENDMIN;
|
||||
else if ( clust.max.equals( getLocation() ) )
|
||||
displayBits = DISPLAY_ENDMAX;
|
||||
else
|
||||
displayBits = DISPLAY_MIDDLE;
|
||||
|
||||
switch (clust.currentAxis)
|
||||
{
|
||||
case X:
|
||||
displayBits |= DISPLAY_X;
|
||||
break;
|
||||
case Y:
|
||||
displayBits |= DISPLAY_Y;
|
||||
break;
|
||||
case Z:
|
||||
displayBits |= DISPLAY_Z;
|
||||
break;
|
||||
default:
|
||||
displayBits = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if ( gridProxy.getEnergy().isNetworkPowered() )
|
||||
displayBits |= DISPLAY_POWEREDENABLED;
|
||||
|
||||
if ( clust.isValid && gridProxy.isActive() )
|
||||
displayBits |= DISPLAY_ENABLED;
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// nothing?
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( oldBits != displayBits )
|
||||
markForUpdate();
|
||||
}
|
||||
|
||||
public void updateStatus(SpatialPylonCluster c)
|
||||
{
|
||||
clust = c;
|
||||
gridProxy.setValidSides( c == null ? EnumSet.noneOf( ForgeDirection.class ) : EnumSet.allOf( ForgeDirection.class ) );
|
||||
recalculateDisplay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(boolean b)
|
||||
{
|
||||
if ( clust != null )
|
||||
{
|
||||
clust.destroy();
|
||||
updateStatus( null );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getDisplayBits()
|
||||
{
|
||||
return displayBits;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user