Err too much.
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.core.Configuration;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cache.helpers.TunnelCollection;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.power.PowerHandler;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
import buildcraft.api.power.PowerHandler.Type;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartP2PBCPower extends PartP2PTunnel<PartP2PBCPower> implements IPowerReceptor, IGridTickable
|
||||
{
|
||||
|
||||
PowerHandler pp;
|
||||
|
||||
public PartP2PBCPower(ItemStack is) {
|
||||
super( is );
|
||||
pp = new PowerHandler( this, Type.MACHINE );
|
||||
pp.configure( 1f, 320f, 800f, 640f );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
return new TickingRequest( 1, 20, false, false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
{
|
||||
if ( !output && proxy.isActive() )
|
||||
{
|
||||
float totalRequiredPower = 0.0f;
|
||||
TunnelCollection<PartP2PBCPower> tunnelset;
|
||||
|
||||
try
|
||||
{
|
||||
tunnelset = getOutputs();
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
for (PartP2PBCPower o : tunnelset)
|
||||
{
|
||||
IPowerReceptor target = o.getPowerTarget();
|
||||
if ( target != null )
|
||||
{
|
||||
PowerReceiver tp = target.getPowerReceiver( side.getOpposite() );
|
||||
if ( tp != null )
|
||||
{
|
||||
float howmuch = tp.powerRequest();
|
||||
|
||||
if ( howmuch > tp.getMaxEnergyReceived() )
|
||||
howmuch = tp.getMaxEnergyReceived();
|
||||
|
||||
if ( howmuch > 0.01 && howmuch > tp.getMinEnergyReceived() )
|
||||
{
|
||||
totalRequiredPower += howmuch;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( totalRequiredPower < 0.1 )
|
||||
return TickRateModulation.SLOWER;
|
||||
|
||||
float currentTotal = pp.getEnergyStored();
|
||||
if ( currentTotal < 0.01 )
|
||||
return TickRateModulation.SLOWER;
|
||||
|
||||
for (PartP2PBCPower o : tunnelset)
|
||||
{
|
||||
IPowerReceptor target = o.getPowerTarget();
|
||||
if ( target != null )
|
||||
{
|
||||
PowerReceiver tp = target.getPowerReceiver( side.getOpposite() );
|
||||
if ( tp != null )
|
||||
{
|
||||
float howmuch = tp.powerRequest(); // orientation.getOpposite() );
|
||||
if ( howmuch > tp.getMaxEnergyReceived() )
|
||||
howmuch = tp.getMaxEnergyReceived();
|
||||
|
||||
if ( howmuch > 0.01 && howmuch > tp.getMinEnergyReceived() )
|
||||
{
|
||||
float toPull = currentTotal * (howmuch / totalRequiredPower);
|
||||
float pulled = pp.useEnergy( 0, toPull, true );
|
||||
QueueTunnelDrain( PowerUnits.MJ, pulled * Configuration.TunnelPowerLoss );
|
||||
|
||||
tp.receiveEnergy( Type.PIPE, pulled, o.side.getOpposite() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TickRateModulation.FASTER;
|
||||
}
|
||||
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
return 0.5f;
|
||||
};
|
||||
|
||||
private IPowerReceptor getPowerTarget()
|
||||
{
|
||||
TileEntity te = getWorld().getBlockTileEntity( tile.xCoord + side.offsetX, tile.yCoord + side.offsetY, tile.zCoord + side.offsetZ );
|
||||
if ( te != null )
|
||||
{
|
||||
if ( te instanceof IPowerReceptor )
|
||||
return (IPowerReceptor) te;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.writeToNBT( tag );
|
||||
pp.writeToNBT( tag );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.readFromNBT( tag );
|
||||
pp.readFromNBT( tag );
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Icon getTypeTexture()
|
||||
{
|
||||
return Block.blockEmerald.getBlockTextureFromSide( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public PowerReceiver getPowerReceiver(ForgeDirection side)
|
||||
{
|
||||
if ( side.equals( side ) )
|
||||
return pp.getPowerReceiver();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWork(PowerHandler workProvider)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
{
|
||||
return tile.worldObj;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cache.helpers.TunnelCollection;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements ic2.api.energy.tile.IEnergySink, ic2.api.energy.tile.IEnergySource
|
||||
{
|
||||
|
||||
public PartP2PIC2Power(ItemStack is) {
|
||||
super( is );
|
||||
}
|
||||
|
||||
double OutputPacket;
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.writeToNBT( tag );
|
||||
tag.setDouble( "OutputPacket", OutputPacket );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.readFromNBT( tag );
|
||||
OutputPacket = tag.getDouble( "OutputPacket" );
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Icon getTypeTexture()
|
||||
{
|
||||
return Block.blockDiamond.getBlockTextureFromSide( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
{
|
||||
if ( !output )
|
||||
return direction.equals( side );
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction)
|
||||
{
|
||||
if ( output )
|
||||
return direction.equals( side );
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double demandedEnergyUnits()
|
||||
{
|
||||
if ( output )
|
||||
return 0;
|
||||
|
||||
try
|
||||
{
|
||||
for (PartP2PIC2Power t : getOutputs())
|
||||
{
|
||||
if ( t.OutputPacket <= 0.0001 )
|
||||
{
|
||||
return 2048;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange()
|
||||
{
|
||||
getHost().PartChanged();
|
||||
}
|
||||
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
return 0.5f;
|
||||
};
|
||||
|
||||
@Override
|
||||
public double injectEnergyUnits(ForgeDirection directionFrom, double amount)
|
||||
{
|
||||
|
||||
TunnelCollection<PartP2PIC2Power> outs;
|
||||
try
|
||||
{
|
||||
outs = getOutputs();
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return amount;
|
||||
}
|
||||
|
||||
if ( outs.isEmpty() )
|
||||
return amount;
|
||||
|
||||
LinkedList<PartP2PIC2Power> Options = new LinkedList();
|
||||
for (PartP2PIC2Power o : outs)
|
||||
{
|
||||
if ( o.OutputPacket <= 0.01 )
|
||||
Options.add( o );
|
||||
}
|
||||
|
||||
PartP2PIC2Power x = (PartP2PIC2Power) Platform.pickRandom( Options );
|
||||
if ( x != null && x.OutputPacket <= 0.001 )
|
||||
{
|
||||
x.OutputPacket = amount;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxSafeInput()
|
||||
{
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getOfferedEnergy()
|
||||
{
|
||||
if ( output )
|
||||
return OutputPacket;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEnergy(double amount)
|
||||
{
|
||||
OutputPacket -= amount;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityChest;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.integration.abstraction.IBC;
|
||||
import appeng.integration.abstraction.ITE;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cache.helpers.TunnelCollection;
|
||||
import appeng.tile.inventory.AppEngNullInventory;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.WrapperBCPipe;
|
||||
import appeng.util.inv.WrapperChainedInventory;
|
||||
import appeng.util.inv.WrapperMCISidedInventory;
|
||||
import appeng.util.inv.WrapperTEPipe;
|
||||
import buildcraft.api.transport.IPipeConnection;
|
||||
import buildcraft.api.transport.IPipeTile.PipeType;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements IPipeConnection, IInventory, ISidedInventory
|
||||
{
|
||||
|
||||
public PartP2PItems(ItemStack is) {
|
||||
super( is );
|
||||
}
|
||||
|
||||
int oldSize = 0;
|
||||
IInventory cachedInv;
|
||||
|
||||
LinkedList<IInventory> which = new LinkedList<IInventory>();
|
||||
|
||||
IInventory getOutputInv()
|
||||
{
|
||||
IInventory output = null;
|
||||
|
||||
if ( proxy.isActive() )
|
||||
{
|
||||
TileEntity te = tile.worldObj.getBlockTileEntity( tile.xCoord + side.offsetX, tile.yCoord + side.offsetY, tile.zCoord + side.offsetZ );
|
||||
|
||||
if ( which.contains( this ) )
|
||||
return null;
|
||||
|
||||
which.add( this );
|
||||
|
||||
if ( AppEng.instance.isIntegrationEnabled( "BC" ) )
|
||||
{
|
||||
IBC buildcraft = (IBC) AppEng.instance.getIntegration( "BC" );
|
||||
if ( buildcraft != null )
|
||||
{
|
||||
if ( buildcraft.isPipe( te, side.getOpposite() ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
output = new WrapperBCPipe( te, side.getOpposite() );
|
||||
}
|
||||
catch (Throwable _)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( AppEng.instance.isIntegrationEnabled( "TE" ) )
|
||||
{
|
||||
ITE thermal = (ITE) AppEng.instance.getIntegration( "TE" );
|
||||
if ( thermal != null )
|
||||
{
|
||||
if ( thermal.isPipe( te, side.getOpposite() ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
output = new WrapperTEPipe( te, side.getOpposite() );
|
||||
}
|
||||
catch (Throwable _)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( output == null )
|
||||
{
|
||||
if ( te instanceof TileEntityChest )
|
||||
{
|
||||
output = Platform.GetChestInv( te );
|
||||
}
|
||||
else if ( te instanceof ISidedInventory )
|
||||
{
|
||||
output = new WrapperMCISidedInventory( (ISidedInventory) te, side.getOpposite() );
|
||||
}
|
||||
else if ( te instanceof IInventory )
|
||||
{
|
||||
output = (IInventory) te;
|
||||
}
|
||||
}
|
||||
|
||||
which.pop();
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
cachedInv = null;
|
||||
PartP2PItems input = getInput();
|
||||
if ( input != null )
|
||||
input.onChange();
|
||||
}
|
||||
|
||||
IInventory getDest()
|
||||
{
|
||||
if ( cachedInv != null )
|
||||
return cachedInv;
|
||||
|
||||
List<IInventory> outs = new LinkedList<IInventory>();
|
||||
TunnelCollection<PartP2PItems> itemTunnels;
|
||||
|
||||
try
|
||||
{
|
||||
itemTunnels = getOutputs();
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return new AppEngNullInventory();
|
||||
}
|
||||
|
||||
for (PartP2PItems t : itemTunnels)
|
||||
{
|
||||
IInventory inv = t.getOutputInv();
|
||||
if ( inv != null )
|
||||
{
|
||||
if ( Platform.getRandomInt() % 2 == 0 )
|
||||
outs.add( inv );
|
||||
else
|
||||
outs.add( 0, inv );
|
||||
}
|
||||
}
|
||||
|
||||
return cachedInv = new WrapperChainedInventory( outs );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange()
|
||||
{
|
||||
cachedInv = null;
|
||||
int olderSize = oldSize;
|
||||
oldSize = getDest().getSizeInventory();
|
||||
if ( olderSize != oldSize )
|
||||
{
|
||||
getHost().PartChanged();
|
||||
tile.worldObj.notifyBlocksOfNeighborChange( tile.xCoord, tile.yCoord, tile.zCoord, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Icon getTypeTexture()
|
||||
{
|
||||
return Block.hopperBlock.getBlockTextureFromSide( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return getDest().getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i)
|
||||
{
|
||||
return getDest().getStackInSlot( i );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j)
|
||||
{
|
||||
return getDest().decrStackSize( i, j );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack)
|
||||
{
|
||||
getDest().setInventorySlotContents( i, itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInvName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvNameLocalized()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return getDest().getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openChest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeChest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, net.minecraft.item.ItemStack itemstack)
|
||||
{
|
||||
return getDest().isItemValidForSlot( i, itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int var1)
|
||||
{
|
||||
int[] slots = new int[getSizeInventory()];
|
||||
for (int x = 0; x < getSizeInventory(); x++)
|
||||
slots[x] = x;
|
||||
return slots;
|
||||
}
|
||||
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
return 2.0f;
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return getDest().isItemValidForSlot( i, itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectOverride overridePipeConnection(PipeType type, ForgeDirection with)
|
||||
{
|
||||
return side.equals( with ) && type == PipeType.ITEM ? ConnectOverride.CONNECT : ConnectOverride.DEFAULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInventoryChanged()
|
||||
{
|
||||
// eh?
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import appeng.me.GridAccessException;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartP2PLiquids extends PartP2PTunnel<PartP2PLiquids> implements IFluidHandler
|
||||
{
|
||||
|
||||
public PartP2PLiquids(ItemStack is) {
|
||||
super( is );
|
||||
}
|
||||
|
||||
private FluidTankInfo[] getTank()
|
||||
{
|
||||
if ( output )
|
||||
{
|
||||
PartP2PLiquids tun = getInput();
|
||||
if ( tun != null )
|
||||
return new FluidTankInfo[] { new FluidTankInfo( null, 10000 ) };
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( !getOutputs().isEmpty() )
|
||||
return new FluidTankInfo[] { new FluidTankInfo( null, 10000 ) };
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :(
|
||||
}
|
||||
}
|
||||
return new FluidTankInfo[] { new FluidTankInfo( null, 0 ) };
|
||||
}
|
||||
|
||||
IFluidHandler cachedTank;
|
||||
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
return 2.0f;
|
||||
};
|
||||
|
||||
private int tmpUsed;
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.writeToNBT( tag );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.readFromNBT( tag );
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Icon getTypeTexture()
|
||||
{
|
||||
return Block.blockLapis.getBlockTextureFromSide( 0 );
|
||||
}
|
||||
|
||||
List<PartP2PLiquids> getOutputs(Fluid input)
|
||||
{
|
||||
List<PartP2PLiquids> outs = new LinkedList<PartP2PLiquids>();
|
||||
|
||||
try
|
||||
{
|
||||
for (PartP2PLiquids l : getOutputs())
|
||||
{
|
||||
IFluidHandler targ = getTarget();
|
||||
if ( targ != null )
|
||||
{
|
||||
if ( targ.canFill( side.getOpposite(), input ) )
|
||||
outs.add( l );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
return outs;
|
||||
}
|
||||
|
||||
public void onNeighborBlockChange()
|
||||
{
|
||||
cachedTank = null;
|
||||
};
|
||||
|
||||
IFluidHandler getTarget()
|
||||
{
|
||||
if ( cachedTank != null )
|
||||
return cachedTank;
|
||||
|
||||
TileEntity te = tile.worldObj.getBlockTileEntity( tile.xCoord + side.offsetX, tile.yCoord + side.offsetY, tile.zCoord + side.offsetZ );
|
||||
if ( te instanceof IFluidHandler )
|
||||
return cachedTank = (IFluidHandler) te;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
List<PartP2PLiquids> list = getOutputs( resource.getFluid() );
|
||||
int requestTotal = 0;
|
||||
|
||||
Iterator<PartP2PLiquids> i = list.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
PartP2PLiquids l = i.next();
|
||||
IFluidHandler tank = l.getTarget();
|
||||
if ( tank != null )
|
||||
l.tmpUsed = tank.fill( l.side.getOpposite(), resource.copy(), false );
|
||||
else
|
||||
l.tmpUsed = 0;
|
||||
|
||||
if ( l.tmpUsed <= 0 )
|
||||
i.remove();
|
||||
else
|
||||
requestTotal += l.tmpUsed;
|
||||
}
|
||||
|
||||
if ( requestTotal <= 0 )
|
||||
return 0;
|
||||
|
||||
if ( !doFill )
|
||||
return Math.min( resource.amount, requestTotal );
|
||||
|
||||
int avilable = resource.amount;
|
||||
int used = 0;
|
||||
|
||||
i = list.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
PartP2PLiquids l = i.next();
|
||||
|
||||
FluidStack insert = resource.copy();
|
||||
insert.amount = (int) Math.ceil( insert.amount * ((double) l.tmpUsed / (double) requestTotal) );
|
||||
if ( insert.amount > avilable )
|
||||
insert.amount = avilable;
|
||||
|
||||
IFluidHandler tank = l.getTarget();
|
||||
if ( tank != null )
|
||||
l.tmpUsed = tank.fill( l.side.getOpposite(), insert.copy(), true );
|
||||
else
|
||||
l.tmpUsed = 0;
|
||||
|
||||
avilable -= insert.amount;
|
||||
used += insert.amount;
|
||||
}
|
||||
|
||||
return used;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
return !output && from.equals( side ) && !getOutputs( fluid ).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from)
|
||||
{
|
||||
if ( from.equals( side ) )
|
||||
return getTank();
|
||||
return new FluidTankInfo[0];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRedstoneWire;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraft.world.World;
|
||||
import appeng.api.networking.events.MENetworkBootingStatusChange;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.me.GridAccessException;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartP2PRedstone extends PartP2PTunnel<PartP2PRedstone>
|
||||
{
|
||||
|
||||
public PartP2PRedstone(ItemStack is) {
|
||||
super( is );
|
||||
}
|
||||
|
||||
int power;
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower()
|
||||
{
|
||||
return output ? power : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower()
|
||||
{
|
||||
return output ? power : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange()
|
||||
{
|
||||
setNetworkReady();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void changeStateA(MENetworkBootingStatusChange bs)
|
||||
{
|
||||
setNetworkReady();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void changeStateB(MENetworkChannelsChanged bs)
|
||||
{
|
||||
setNetworkReady();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void changeStateC(MENetworkPowerStatusChange bs)
|
||||
{
|
||||
setNetworkReady();
|
||||
}
|
||||
|
||||
public void setNetworkReady()
|
||||
{
|
||||
if ( output )
|
||||
{
|
||||
PartP2PRedstone in = getInput();
|
||||
if ( in != null )
|
||||
putInput( ((PartP2PRedstone) in).power );
|
||||
}
|
||||
}
|
||||
|
||||
boolean recursive = false;
|
||||
|
||||
protected void putInput(Object o)
|
||||
{
|
||||
if ( recursive )
|
||||
return;
|
||||
|
||||
recursive = true;
|
||||
if ( output && proxy.isActive() )
|
||||
{
|
||||
int newPower = (Integer) o;
|
||||
if ( power != newPower )
|
||||
{
|
||||
power = newPower;
|
||||
notifyNeightbors();
|
||||
}
|
||||
}
|
||||
recursive = false;
|
||||
|
||||
}
|
||||
|
||||
public void notifyNeightbors()
|
||||
{
|
||||
World worldObj = tile.worldObj;
|
||||
|
||||
int xCoord = tile.xCoord;
|
||||
int yCoord = tile.yCoord;
|
||||
int zCoord = tile.zCoord;
|
||||
|
||||
worldObj.notifyBlocksOfNeighborChange( xCoord, yCoord, zCoord, worldObj.getBlockId( xCoord, yCoord, zCoord ) );
|
||||
|
||||
// and this cause somtimes it can go thought walls.
|
||||
worldObj.notifyBlocksOfNeighborChange( xCoord - 1, yCoord, zCoord, worldObj.getBlockId( xCoord, yCoord, zCoord ) );
|
||||
worldObj.notifyBlocksOfNeighborChange( xCoord, yCoord - 1, zCoord, worldObj.getBlockId( xCoord, yCoord, zCoord ) );
|
||||
worldObj.notifyBlocksOfNeighborChange( xCoord, yCoord, zCoord - 1, worldObj.getBlockId( xCoord, yCoord, zCoord ) );
|
||||
worldObj.notifyBlocksOfNeighborChange( xCoord, yCoord, zCoord + 1, worldObj.getBlockId( xCoord, yCoord, zCoord ) );
|
||||
worldObj.notifyBlocksOfNeighborChange( xCoord, yCoord + 1, zCoord, worldObj.getBlockId( xCoord, yCoord, zCoord ) );
|
||||
worldObj.notifyBlocksOfNeighborChange( xCoord + 1, yCoord, zCoord, worldObj.getBlockId( xCoord, yCoord, zCoord ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.writeToNBT( tag );
|
||||
tag.setInteger( "power", power );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.readFromNBT( tag );
|
||||
power = tag.getInteger( "power" );
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Icon getTypeTexture()
|
||||
{
|
||||
return Block.blockRedstone.getBlockTextureFromSide( 0 );
|
||||
}
|
||||
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
return 0.5f;
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
if ( !output )
|
||||
{
|
||||
int x = tile.xCoord + side.offsetX;
|
||||
int y = tile.yCoord + side.offsetY;
|
||||
int z = tile.zCoord + side.offsetZ;
|
||||
|
||||
Block b = Block.blocksList[tile.worldObj.getBlockId( x, y, z )];
|
||||
if ( b != null && !output )
|
||||
{
|
||||
int srcSide = side.ordinal();
|
||||
if ( b instanceof BlockRedstoneWire )
|
||||
srcSide = 1;
|
||||
power = b.isProvidingStrongPower( tile.worldObj, x, y, z, srcSide );
|
||||
power = Math.max( power, b.isProvidingWeakPower( tile.worldObj, x, y, z, srcSide ) );
|
||||
sendToOutput( power );
|
||||
}
|
||||
else
|
||||
sendToOutput( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
private void sendToOutput(int power)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (PartP2PRedstone rs : getOutputs())
|
||||
{
|
||||
rs.putInput( power );
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.implementations.IMemoryCard;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartCollsionHelper;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.parts.PartItemStack;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cache.P2PCache;
|
||||
import appeng.me.cache.helpers.TunnelCollection;
|
||||
import appeng.parts.PartBasicState;
|
||||
|
||||
public class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
|
||||
{
|
||||
|
||||
public boolean output;
|
||||
public long freq;
|
||||
TunnelCollection type = new TunnelCollection<T>( null, getClass() );
|
||||
|
||||
public PartP2PTunnel(ItemStack is) {
|
||||
super( PartP2PTunnel.class, is );
|
||||
if ( getClass() == PartP2PTunnel.class )
|
||||
throw new RuntimeException( "Don't construct the root tunnel!" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
data.setBoolean( "output", output );
|
||||
data.setLong( "freq", freq );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
output = data.getBoolean( "output" );
|
||||
freq = data.getLong( "freq" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
ItemStack is = player.inventory.getCurrentItem();
|
||||
|
||||
if ( is != null && is.getItem() instanceof IMemoryCard )
|
||||
{
|
||||
IMemoryCard mc = (IMemoryCard) is.getItem();
|
||||
NBTTagCompound data = mc.getData( is );
|
||||
|
||||
ItemStack newType = ItemStack.loadItemStackFromNBT( data );
|
||||
long freq = data.getLong( "freq" );
|
||||
|
||||
getHost().removePart( side );
|
||||
ForgeDirection dir = getHost().addPart( newType, side );
|
||||
IPart newBus = getHost().getPart( dir );
|
||||
|
||||
if ( newBus instanceof PartP2PTunnel )
|
||||
{
|
||||
PartP2PTunnel newTunnel = (PartP2PTunnel) newBus;
|
||||
newTunnel.output = true;
|
||||
newTunnel.onChange();
|
||||
|
||||
try
|
||||
{
|
||||
P2PCache p2p = newTunnel.proxy.getP2P();
|
||||
p2p.updateFreq( newTunnel, freq );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onShiftActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
ItemStack is = player.inventory.getCurrentItem();
|
||||
if ( is != null && is.getItem() instanceof IMemoryCard )
|
||||
{
|
||||
IMemoryCard mc = (IMemoryCard) is.getItem();
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
|
||||
long newFreq = freq;
|
||||
output = false;
|
||||
|
||||
if ( output || freq == 0 )
|
||||
{
|
||||
newFreq = System.currentTimeMillis();
|
||||
try
|
||||
{
|
||||
proxy.getP2P().updateFreq( this, newFreq );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
onChange();
|
||||
|
||||
ItemStack p2pItem = getItemStack( PartItemStack.Wrench );
|
||||
String type = p2pItem.getUnlocalizedName();
|
||||
|
||||
p2pItem.writeToNBT( data );
|
||||
data.setLong( "freq", freq );
|
||||
|
||||
mc.setMemoryCardContents( is, type + ".name", data );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(PartItemStack type)
|
||||
{
|
||||
if ( type == PartItemStack.World || type == PartItemStack.Network || type == PartItemStack.Wrench )
|
||||
return super.getItemStack( type );
|
||||
|
||||
return AEApi.instance().parts().partP2PTunnelME.stack( 1 );
|
||||
}
|
||||
|
||||
public TunnelCollection<T> getCollection(Collection<PartP2PTunnel> collection)
|
||||
{
|
||||
type.setSource( collection );
|
||||
return type;
|
||||
}
|
||||
|
||||
public T getInput()
|
||||
{
|
||||
PartP2PTunnel tunn;
|
||||
try
|
||||
{
|
||||
tunn = proxy.getP2P().getInput( freq );
|
||||
if ( getClass().isInstance( tunn ) )
|
||||
return (T) tunn;
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public TunnelCollection<T> getOutputs() throws GridAccessException
|
||||
{
|
||||
return (TunnelCollection<T>) proxy.getP2P().getOutputs( freq, getClass() );
|
||||
}
|
||||
|
||||
public void onChange()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
rh.setTexture( getTypeTexture() );
|
||||
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
rh.setTexture( CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.BlockP2PTunnel2.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon() );
|
||||
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
}
|
||||
|
||||
protected Icon getTypeTexture()
|
||||
{
|
||||
return AEApi.instance().blocks().blockQuartz.block().getIcon( 0, 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
rh.useSimpliedRendering( x, y, z, this );
|
||||
rh.setTexture( getTypeTexture() );
|
||||
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setTexture( CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.BlockP2PTunnel2.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon() );
|
||||
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setBounds( 3, 3, 13, 13, 13, 14 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setTexture( CableBusTextures.BlockP2PTunnel3.getIcon() );
|
||||
|
||||
rh.setBounds( 6, 5, 12, 10, 11, 13 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setBounds( 5, 6, 12, 11, 10, 13 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
renderLights( x, y, z, rh, renderer );
|
||||
}
|
||||
|
||||
protected void QueueTunnelDrain(PowerUnits mj, float f)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColors(boolean hasChan, boolean hasPower)
|
||||
{
|
||||
super.setColors( hasChan, hasPower );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(IPartCollsionHelper bch)
|
||||
{
|
||||
bch.addBox( 2, 2, 14, 14, 14, 16 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cableConnectionRenderTo()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.me.helpers.AENetworkProxy;
|
||||
|
||||
public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME>
|
||||
{
|
||||
|
||||
AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", true );
|
||||
|
||||
public PartP2PTunnelME(ItemStack is) {
|
||||
super( is );
|
||||
proxy.setFlags( GridFlags.TIER_2_CAPACITY, GridFlags.REQURE_CHANNEL, GridFlags.DENSE_CHANNEL, GridFlags.CANNOT_CARRY_DENSE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPartHostInfo(ForgeDirection side, IPartHost host, TileEntity tile)
|
||||
{
|
||||
super.setPartHostInfo( side, host, tile );
|
||||
outerProxy.setValidSides( EnumSet.of( side ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound extra)
|
||||
{
|
||||
super.readFromNBT( extra );
|
||||
outerProxy.readFromNBT( extra );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound extra)
|
||||
{
|
||||
super.writeToNBT( extra );
|
||||
outerProxy.writeToNBT( extra );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToWorld()
|
||||
{
|
||||
super.addToWorld();
|
||||
outerProxy.onReady();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFromWorld()
|
||||
{
|
||||
super.removeFromWorld();
|
||||
outerProxy.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode getExternalFacingNode()
|
||||
{
|
||||
return outerProxy.getNode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType(ForgeDirection dir)
|
||||
{
|
||||
return AECableType.DENSE;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user