Relocate Source to proper directory.

This commit is contained in:
AlgorithmX2
2014-09-23 19:26:27 -05:00
parent fe927ce65d
commit 386d18a059
785 changed files with 35585 additions and 35580 deletions
@@ -0,0 +1,376 @@
package appeng.me.helpers;
import java.util.EnumSet;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.AEApi;
import appeng.api.networking.GridFlags;
import appeng.api.networking.GridNotification;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridBlock;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.events.MENetworkPowerIdleChange;
import appeng.api.networking.pathing.IPathingGrid;
import appeng.api.networking.security.ISecurityGrid;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.networking.ticking.ITickManager;
import appeng.api.util.AEColor;
import appeng.api.util.DimensionalCoord;
import appeng.api.util.IOrientable;
import appeng.core.WorldSettings;
import appeng.hooks.TickHandler;
import appeng.me.GridAccessException;
import appeng.me.cache.P2PCache;
import appeng.parts.networking.PartCable;
import appeng.tile.AEBaseTile;
import appeng.util.Platform;
public class AENetworkProxy implements IGridBlock
{
final private IGridProxyable gp;
final private boolean worldNode;
private ItemStack myRepInstance;
private boolean isReady = false;
private IGridNode node = null;
private EnumSet<ForgeDirection> validSides;
public AEColor myColor = AEColor.Transparent;
private EnumSet<GridFlags> flags = EnumSet.noneOf( GridFlags.class );
private double idleDraw = 1.0;
final private String nbtName; // name
NBTTagCompound data = null; // input
private EntityPlayer owner;
@Override
public ItemStack getMachineRepresentation()
{
return myRepInstance;
}
public void setVisualRepresentation(ItemStack is)
{
myRepInstance = is;
}
public AENetworkProxy(IGridProxyable te, String nbtName, ItemStack visual, boolean inWorld) {
this.gp = te;
this.nbtName = nbtName;
worldNode = inWorld;
myRepInstance = visual;
validSides = EnumSet.allOf( ForgeDirection.class );
}
public void writeToNBT(NBTTagCompound tag)
{
if ( node != null )
node.saveToNBT( nbtName, tag );
}
public void readFromNBT(NBTTagCompound tag)
{
data = tag;
if ( node != null && data != null )
{
node.loadFromNBT( nbtName, data );
data = null;
}
else if ( node != null && owner != null )
{
node.setPlayerID( WorldSettings.getInstance().getPlayerID( owner.getGameProfile() ) );
owner = null;
}
}
@Override
public DimensionalCoord getLocation()
{
return gp.getLocation();
}
@Override
public AEColor getGridColor()
{
return myColor;
}
@Override
public void onGridNotification(GridNotification notification)
{
if ( gp instanceof PartCable )
((PartCable) gp).markForUpdate();
}
@Override
public void setNetworkStatus(IGrid grid, int channelsInUse)
{
}
@Override
public EnumSet<ForgeDirection> getConnectableSides()
{
return validSides;
}
public void setValidSides(EnumSet<ForgeDirection> validSides)
{
this.validSides = validSides;
if ( node != null )
node.updateState();
}
public IGridNode getNode()
{
if ( node == null && Platform.isServer() && isReady )
{
node = AEApi.instance().createGridNode( this );
readFromNBT( data );
node.updateState();
}
return node;
}
public void validate()
{
if ( gp instanceof AEBaseTile )
TickHandler.instance.addInit( (AEBaseTile) gp );
}
public void onChunkUnload()
{
isReady = false;
invalidate();
}
public void invalidate()
{
isReady = false;
if ( node != null )
{
node.destroy();
node = null;
}
}
public void onReady()
{
isReady = true;
// send orientation based directionality to the node.
if ( gp instanceof IOrientable )
{
IOrientable ori = (IOrientable) gp;
if ( ori.canBeRotated() )
ori.setOrientation( ori.getForward(), ori.getUp() );
}
getNode();
}
@Override
public IGridHost getMachine()
{
return gp;
}
/**
* short cut!
*
* @return
* @throws GridAccessException
*/
public IGrid getGrid() throws GridAccessException
{
if ( node == null )
throw new GridAccessException();
IGrid grid = node.getGrid();
if ( grid == null )
throw new GridAccessException();
return grid;
}
public IEnergyGrid getEnergy() throws GridAccessException
{
IGrid grid = getGrid();
if ( grid == null )
throw new GridAccessException();
IEnergyGrid eg = grid.getCache( IEnergyGrid.class );
if ( eg == null )
throw new GridAccessException();
return eg;
}
public IPathingGrid getPath() throws GridAccessException
{
IGrid grid = getGrid();
if ( grid == null )
throw new GridAccessException();
IPathingGrid pg = grid.getCache( IPathingGrid.class );
if ( pg == null )
throw new GridAccessException();
return pg;
}
public ITickManager getTick() throws GridAccessException
{
IGrid grid = getGrid();
if ( grid == null )
throw new GridAccessException();
ITickManager pg = grid.getCache( ITickManager.class );
if ( pg == null )
throw new GridAccessException();
return pg;
}
public IStorageGrid getStorage() throws GridAccessException
{
IGrid grid = getGrid();
if ( grid == null )
throw new GridAccessException();
IStorageGrid pg = grid.getCache( IStorageGrid.class );
if ( pg == null )
throw new GridAccessException();
return pg;
}
public P2PCache getP2P() throws GridAccessException
{
IGrid grid = getGrid();
if ( grid == null )
throw new GridAccessException();
P2PCache pg = grid.getCache( P2PCache.class );
if ( pg == null )
throw new GridAccessException();
return pg;
}
public ISecurityGrid getSecurity() throws GridAccessException
{
IGrid grid = getGrid();
if ( grid == null )
throw new GridAccessException();
ISecurityGrid sg = grid.getCache( ISecurityGrid.class );
if ( sg == null )
throw new GridAccessException();
return sg;
}
public ICraftingGrid getCrafting() throws GridAccessException
{
IGrid grid = getGrid();
if ( grid == null )
throw new GridAccessException();
ICraftingGrid sg = grid.getCache( ICraftingGrid.class );
if ( sg == null )
throw new GridAccessException();
return sg;
}
@Override
public boolean isWorldAccessible()
{
return worldNode;
}
@Override
public EnumSet<GridFlags> getFlags()
{
return flags;
}
public void setFlags(GridFlags... requireChannel)
{
EnumSet<GridFlags> flags = EnumSet.noneOf( GridFlags.class );
for (GridFlags gf : requireChannel)
flags.add( gf );
this.flags = flags;
}
@Override
public double getIdlePowerUsage()
{
return idleDraw;
}
public void setIdlePowerUsage(double idle)
{
idleDraw = idle;
if ( node != null )
{
try
{
IGrid g = getGrid();
g.postEvent( new MENetworkPowerIdleChange( node ) );
}
catch (GridAccessException e)
{
// not ready for this yet..
}
}
}
public boolean isReady()
{
return isReady;
}
public boolean isActive()
{
if ( node == null )
return false;
return node.isActive();
}
public boolean isPowered()
{
try
{
return getEnergy().isNetworkPowered();
}
catch (GridAccessException e)
{
return false;
}
}
@Override
public void gridChanged()
{
gp.gridChanged();
}
public void setOwner(EntityPlayer player)
{
owner = player;
}
}
@@ -0,0 +1,33 @@
package appeng.me.helpers;
import java.util.Iterator;
import net.minecraft.item.ItemStack;
import appeng.api.networking.IGridMultiblock;
import appeng.api.networking.IGridNode;
import appeng.me.cluster.IAECluster;
import appeng.me.cluster.IAEMultiBlock;
import appeng.util.iterators.ChainedIterator;
import appeng.util.iterators.ProxyNodeIterator;
public class AENetworkProxyMultiblock extends AENetworkProxy implements IGridMultiblock
{
IAECluster getCluster()
{
return ((IAEMultiBlock) getMachine()).getCluster();
}
public AENetworkProxyMultiblock(IGridProxyable te, String nbtName, ItemStack itemStack, boolean inWorld) {
super( te, nbtName, itemStack, inWorld );
}
@Override
public Iterator<IGridNode> getMultiblockNodes()
{
if ( getCluster() == null )
return new ChainedIterator<IGridNode>();
return new ProxyNodeIterator( getCluster().getTiles() );
}
}
@@ -0,0 +1,27 @@
package appeng.me.helpers;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergySource;
public class ChannelPowerSrc implements IEnergySource
{
IGridNode node;
IEnergySource realSrc;
public ChannelPowerSrc(IGridNode networkNode, IEnergySource src) {
node = networkNode;
realSrc = src;
}
@Override
public double extractAEPower(double amt, Actionable mode, PowerMultiplier usePowerMultiplier)
{
if ( node.isActive() )
return realSrc.extractAEPower( amt, mode, usePowerMultiplier );
return 0.0;
}
}
@@ -0,0 +1,94 @@
package appeng.me.helpers;
import java.util.LinkedList;
import java.util.Set;
import appeng.api.storage.data.IAEStack;
import com.google.common.collect.SetMultimap;
public class GenericInterestManager<T>
{
class SavedTransactions
{
public final boolean put;
public final IAEStack stack;
public final T iw;
public SavedTransactions(boolean putOperation, IAEStack myStack, T watcher) {
put = putOperation;
stack = myStack;
iw = watcher;
}
};
private final SetMultimap<IAEStack, T> container;
private LinkedList<SavedTransactions> transactions = null;
private int transDepth = 0;
public GenericInterestManager(SetMultimap<IAEStack, T> interests) {
container = interests;
}
public void enableTransactions()
{
if ( transDepth == 0 )
transactions = new LinkedList();
transDepth++;
}
public void disableTransactions()
{
transDepth--;
if ( transDepth == 0 )
{
LinkedList<SavedTransactions> myActions = transactions;
transactions = null;
for (SavedTransactions t : myActions)
{
if ( t.put )
put( t.stack, t.iw );
else
remove( t.stack, t.iw );
}
}
}
public boolean containsKey(IAEStack stack)
{
return container.containsKey( stack );
}
public Set<T> get(IAEStack stack)
{
return container.get( stack );
}
public boolean put(IAEStack stack, T iw)
{
if ( transactions != null )
{
transactions.add( new SavedTransactions( true, stack, iw ) );
return true;
}
else
return container.put( stack, iw );
}
public boolean remove(IAEStack stack, T iw)
{
if ( transactions != null )
{
transactions.add( new SavedTransactions( true, stack, iw ) );
return true;
}
else
return container.remove( stack, iw );
}
}
@@ -0,0 +1,14 @@
package appeng.me.helpers;
import appeng.api.networking.IGridHost;
import appeng.api.util.DimensionalCoord;
public interface IGridProxyable extends IGridHost
{
AENetworkProxy getProxy();
DimensionalCoord getLocation();
void gridChanged();
}