Relocate Source to proper directory.
This commit is contained in:
@@ -0,0 +1,516 @@
|
||||
package appeng.parts;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.crash.CrashReportCategory;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.implementations.IUpgradeableHost;
|
||||
import appeng.api.implementations.items.IMemoryCard;
|
||||
import appeng.api.implementations.items.MemoryCardMessages;
|
||||
import appeng.api.implementations.tiles.ISegmentedInventory;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.security.IActionHost;
|
||||
import appeng.api.parts.BusSupport;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.parts.ISimplifiedBundle;
|
||||
import appeng.api.parts.PartItemStack;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.api.util.IConfigurableObject;
|
||||
import appeng.helpers.ICustomNameObject;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
import appeng.me.helpers.AENetworkProxy;
|
||||
import appeng.me.helpers.IGridProxyable;
|
||||
import appeng.parts.networking.PartCable;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.SettingsFrom;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class AEBasePart implements IPart, IGridProxyable, IActionHost, IUpgradeableHost, ICustomNameObject
|
||||
{
|
||||
|
||||
protected ISimplifiedBundle renderCache = null;
|
||||
|
||||
protected AENetworkProxy proxy;
|
||||
protected TileEntity tile = null;
|
||||
protected IPartHost host = null;
|
||||
protected ForgeDirection side = null;
|
||||
|
||||
protected final ItemStack is;
|
||||
|
||||
public AEBasePart(Class c, ItemStack is) {
|
||||
this.is = is;
|
||||
proxy = new AENetworkProxy( this, "part", is, this instanceof PartCable );
|
||||
proxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
rh.setBounds( 1, 1, 1, 15, 15, 15 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
rh.setBounds( 1, 1, 1, 15, 15, 15 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
rh.setBounds( 1, 1, 1, 15, 15, 15 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderDynamic(double x, double y, double z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack(PartItemStack type)
|
||||
{
|
||||
if ( type == PartItemStack.Network )
|
||||
{
|
||||
ItemStack copy = is.copy();
|
||||
copy.setTagCompound( null );
|
||||
return copy;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
proxy.readFromNBT( data );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
proxy.writeToNBT( data );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(ByteBuf data) throws IOException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream(ByteBuf data) throws IOException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode getGridNode()
|
||||
{
|
||||
return proxy.getNode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityCollision(Entity entity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFromWorld()
|
||||
{
|
||||
proxy.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToWorld()
|
||||
{
|
||||
proxy.onReady();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPartHostInfo(ForgeDirection side, IPartHost host, TileEntity tile)
|
||||
{
|
||||
this.side = side;
|
||||
this.tile = tile;
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public IPartHost getHost()
|
||||
{
|
||||
return host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode getExternalFacingNode()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode getGridNode(ForgeDirection dir)
|
||||
{
|
||||
return proxy.getNode();
|
||||
}
|
||||
|
||||
protected AEColor getColor()
|
||||
{
|
||||
if ( getHost() == null )
|
||||
return AEColor.Transparent;
|
||||
return getHost().getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionalCoord getLocation()
|
||||
{
|
||||
return new DimensionalCoord( tile );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(IPartCollisionHelper bch)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void randomDisplayTick(World world, int x, int y, int z, Random r)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightLevel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType(ForgeDirection dir)
|
||||
{
|
||||
return AECableType.GLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(List<ItemStack> drops, boolean wrenched)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cableConnectionRenderTo()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gridChanged()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLadder(EntityLivingBase entity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(String name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInstalledUpgrades(Upgrades u)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* depending on the from, different settings will be accepted, don't call this with null
|
||||
*
|
||||
* @param from
|
||||
* @param compound
|
||||
*/
|
||||
public void uploadSettings(SettingsFrom from, NBTTagCompound compound)
|
||||
{
|
||||
if ( compound != null && this instanceof IConfigurableObject )
|
||||
{
|
||||
IConfigManager cm = ((IConfigurableObject) this).getConfigManager();
|
||||
if ( cm != null )
|
||||
cm.readFromNBT( compound );
|
||||
}
|
||||
|
||||
if ( this instanceof IPriorityHost )
|
||||
{
|
||||
IPriorityHost pHost = (IPriorityHost) this;
|
||||
pHost.setPriority( compound.getInteger( "priority" ) );
|
||||
}
|
||||
|
||||
if ( this instanceof ISegmentedInventory )
|
||||
{
|
||||
IInventory inv = ((ISegmentedInventory) this).getInventoryByName( "config" );
|
||||
if ( inv != null && inv instanceof AppEngInternalAEInventory )
|
||||
{
|
||||
AppEngInternalAEInventory target = (AppEngInternalAEInventory) inv;
|
||||
AppEngInternalAEInventory tmp = new AppEngInternalAEInventory( null, target.getSizeInventory() );
|
||||
tmp.readFromNBT( compound, "config" );
|
||||
for (int x = 0; x < tmp.getSizeInventory(); x++)
|
||||
target.setInventorySlotContents( x, tmp.getStackInSlot( x ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* null means nothing to store...
|
||||
*
|
||||
* @param from
|
||||
* @return
|
||||
*/
|
||||
public NBTTagCompound downloadSettings(SettingsFrom from)
|
||||
{
|
||||
NBTTagCompound output = new NBTTagCompound();
|
||||
|
||||
if ( this instanceof IConfigurableObject )
|
||||
{
|
||||
IConfigManager cm = this.getConfigManager();
|
||||
if ( cm != null )
|
||||
cm.writeToNBT( output );
|
||||
}
|
||||
|
||||
if ( this instanceof IPriorityHost )
|
||||
{
|
||||
IPriorityHost pHost = (IPriorityHost) this;
|
||||
output.setInteger( "priority", pHost.getPriority() );
|
||||
}
|
||||
|
||||
if ( this instanceof ISegmentedInventory )
|
||||
{
|
||||
IInventory inv = ((ISegmentedInventory) this).getInventoryByName( "config" );
|
||||
if ( inv != null && inv instanceof AppEngInternalAEInventory )
|
||||
{
|
||||
((AppEngInternalAEInventory) inv).writeToNBT( output, "config" );
|
||||
}
|
||||
}
|
||||
|
||||
return output.hasNoTags() ? null : output;
|
||||
}
|
||||
|
||||
public boolean useStandardMemoryCard()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean useMemoryCard(EntityPlayer player)
|
||||
{
|
||||
ItemStack memCardIS = player.inventory.getCurrentItem();
|
||||
|
||||
if ( memCardIS != null && useStandardMemoryCard() && memCardIS.getItem() instanceof IMemoryCard )
|
||||
{
|
||||
IMemoryCard memc = (IMemoryCard) memCardIS.getItem();
|
||||
|
||||
ItemStack is = getItemStack( PartItemStack.Network );
|
||||
|
||||
// Blocks and parts share the same soul!
|
||||
if ( AEApi.instance().parts().partInterface.sameAsStack( is ) )
|
||||
is = AEApi.instance().blocks().blockInterface.stack( 1 );
|
||||
|
||||
String name = is.getUnlocalizedName();
|
||||
|
||||
if ( player.isSneaking() )
|
||||
{
|
||||
NBTTagCompound data = downloadSettings( SettingsFrom.MEMORY_CARD );
|
||||
if ( data != null )
|
||||
{
|
||||
memc.setMemoryCardContents( memCardIS, name, data );
|
||||
memc.notifyUser( player, MemoryCardMessages.SETTINGS_SAVED );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String storedName = memc.getSettingsName( memCardIS );
|
||||
NBTTagCompound data = memc.getData( memCardIS );
|
||||
if ( name.equals( storedName ) )
|
||||
{
|
||||
uploadSettings( SettingsFrom.MEMORY_CARD, data );
|
||||
memc.notifyUser( player, MemoryCardMessages.SETTINGS_LOADED );
|
||||
}
|
||||
else
|
||||
memc.notifyUser( player, MemoryCardMessages.INVALID_MACHINE );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
final public boolean onActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
if ( useMemoryCard( player ) )
|
||||
return true;
|
||||
|
||||
return onPartActivate( player, pos );
|
||||
}
|
||||
|
||||
@Override
|
||||
final public boolean onShiftActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
if ( useMemoryCard( player ) )
|
||||
return true;
|
||||
|
||||
return onPartShiftActivate( player, pos );
|
||||
}
|
||||
|
||||
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean onPartShiftActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side)
|
||||
{
|
||||
proxy.setOwner( player );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getTile()
|
||||
{
|
||||
return tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void securityBreak()
|
||||
{
|
||||
if ( is.stackSize > 0 )
|
||||
{
|
||||
List<ItemStack> items = new ArrayList();
|
||||
items.add( is.copy() );
|
||||
host.removePart( side, false );
|
||||
Platform.spawnDrops( tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord, items );
|
||||
is.stackSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AENetworkProxy getProxy()
|
||||
{
|
||||
return proxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode getActionableNode()
|
||||
{
|
||||
return proxy.getNode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBePlacedOn(BusSupport what)
|
||||
{
|
||||
return what == BusSupport.CABLE;
|
||||
}
|
||||
|
||||
public void saveChanges()
|
||||
{
|
||||
host.markForSave();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requireDynamicRender()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCustomName()
|
||||
{
|
||||
return is.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
{
|
||||
return is.hasDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getBreakingTexture()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addEntityCrashInfo(CrashReportCategory crashreportcategory)
|
||||
{
|
||||
crashreportcategory.addCrashSection( "Part Side", side );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package appeng.parts;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
|
||||
public class BusCollisionHelper implements IPartCollisionHelper
|
||||
{
|
||||
|
||||
final List<AxisAlignedBB> boxes;
|
||||
|
||||
final private ForgeDirection x;
|
||||
final private ForgeDirection y;
|
||||
final private ForgeDirection z;
|
||||
|
||||
final private Entity entity;
|
||||
final private boolean isVisual;
|
||||
|
||||
public BusCollisionHelper(List<AxisAlignedBB> boxes, ForgeDirection x, ForgeDirection y, ForgeDirection z, Entity e, boolean visual) {
|
||||
this.boxes = boxes;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
entity = e;
|
||||
isVisual = visual;
|
||||
}
|
||||
|
||||
public BusCollisionHelper(List<AxisAlignedBB> boxes, ForgeDirection s, Entity e, boolean visual) {
|
||||
this.boxes = boxes;
|
||||
entity = e;
|
||||
isVisual = visual;
|
||||
|
||||
switch (s)
|
||||
{
|
||||
case DOWN:
|
||||
x = ForgeDirection.EAST;
|
||||
y = ForgeDirection.NORTH;
|
||||
z = ForgeDirection.DOWN;
|
||||
break;
|
||||
case UP:
|
||||
x = ForgeDirection.EAST;
|
||||
y = ForgeDirection.SOUTH;
|
||||
z = ForgeDirection.UP;
|
||||
break;
|
||||
case EAST:
|
||||
x = ForgeDirection.SOUTH;
|
||||
y = ForgeDirection.UP;
|
||||
z = ForgeDirection.EAST;
|
||||
break;
|
||||
case WEST:
|
||||
x = ForgeDirection.NORTH;
|
||||
y = ForgeDirection.UP;
|
||||
z = ForgeDirection.WEST;
|
||||
break;
|
||||
case NORTH:
|
||||
x = ForgeDirection.WEST;
|
||||
y = ForgeDirection.UP;
|
||||
z = ForgeDirection.NORTH;
|
||||
break;
|
||||
case SOUTH:
|
||||
x = ForgeDirection.EAST;
|
||||
y = ForgeDirection.UP;
|
||||
z = ForgeDirection.SOUTH;
|
||||
break;
|
||||
case UNKNOWN:
|
||||
default:
|
||||
x = ForgeDirection.EAST;
|
||||
y = ForgeDirection.UP;
|
||||
z = ForgeDirection.SOUTH;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBBCollision()
|
||||
{
|
||||
return !isVisual;
|
||||
}
|
||||
|
||||
/**
|
||||
* pretty much useless...
|
||||
*/
|
||||
public Entity getEntity()
|
||||
{
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBox(double minX, double minY, double minZ, double maxX, double maxY, double maxZ)
|
||||
{
|
||||
minX /= 16.0;
|
||||
minY /= 16.0;
|
||||
minZ /= 16.0;
|
||||
maxX /= 16.0;
|
||||
maxY /= 16.0;
|
||||
maxZ /= 16.0;
|
||||
|
||||
double aX = minX * x.offsetX + minY * y.offsetX + minZ * z.offsetX;
|
||||
double aY = minX * x.offsetY + minY * y.offsetY + minZ * z.offsetY;
|
||||
double aZ = minX * x.offsetZ + minY * y.offsetZ + minZ * z.offsetZ;
|
||||
|
||||
double bX = maxX * x.offsetX + maxY * y.offsetX + maxZ * z.offsetX;
|
||||
double bY = maxX * x.offsetY + maxY * y.offsetY + maxZ * z.offsetY;
|
||||
double bZ = maxX * x.offsetZ + maxY * y.offsetZ + maxZ * z.offsetZ;
|
||||
|
||||
if ( x.offsetX + y.offsetX + z.offsetX < 0 )
|
||||
{
|
||||
aX += 1;
|
||||
bX += 1;
|
||||
}
|
||||
|
||||
if ( x.offsetY + y.offsetY + z.offsetY < 0 )
|
||||
{
|
||||
aY += 1;
|
||||
bY += 1;
|
||||
}
|
||||
|
||||
if ( x.offsetZ + y.offsetZ + z.offsetZ < 0 )
|
||||
{
|
||||
aZ += 1;
|
||||
bZ += 1;
|
||||
}
|
||||
|
||||
minX = Math.min( aX, bX );
|
||||
minY = Math.min( aY, bY );
|
||||
minZ = Math.min( aZ, bZ );
|
||||
maxX = Math.max( aX, bX );
|
||||
maxY = Math.max( aY, bY );
|
||||
maxZ = Math.max( aZ, bZ );
|
||||
|
||||
boxes.add( AxisAlignedBB.getBoundingBox( minX, minY, minZ, maxX, maxY, maxZ ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeDirection getWorldX()
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeDirection getWorldY()
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForgeDirection getWorldZ()
|
||||
{
|
||||
return z;
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,108 @@
|
||||
package appeng.parts;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.implementations.parts.IPartCable;
|
||||
import appeng.api.parts.IFacadePart;
|
||||
import appeng.api.parts.IPart;
|
||||
|
||||
/**
|
||||
* Thin data storage to optimize memory usage for cables.
|
||||
*/
|
||||
public class CableBusStorage
|
||||
{
|
||||
|
||||
private IPartCable center;
|
||||
private IPart sides[];
|
||||
private IFacadePart facades[];
|
||||
|
||||
protected IPartCable getCenter()
|
||||
{
|
||||
return center;
|
||||
}
|
||||
|
||||
protected void setCenter(IPartCable center)
|
||||
{
|
||||
this.center = center;
|
||||
}
|
||||
|
||||
protected IPart getSide(ForgeDirection side)
|
||||
{
|
||||
int x = side.ordinal();
|
||||
if ( sides != null && sides.length > x )
|
||||
return sides[x];
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void setSide(ForgeDirection side, IPart part)
|
||||
{
|
||||
int x = side.ordinal();
|
||||
|
||||
if ( sides != null && sides.length > x && part == null )
|
||||
{
|
||||
sides[x] = null;
|
||||
sides = shrink( sides, true );
|
||||
}
|
||||
else if ( part != null )
|
||||
{
|
||||
sides = grow( sides, x, true );
|
||||
sides[x] = part;
|
||||
}
|
||||
}
|
||||
|
||||
public IFacadePart getFacade(int x)
|
||||
{
|
||||
if ( facades != null && facades.length > x )
|
||||
return facades[x];
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setFacade(int x, IFacadePart facade)
|
||||
{
|
||||
if ( facades != null && facades.length > x && facade == null )
|
||||
{
|
||||
facades[x] = null;
|
||||
facades = shrink( facades, false );
|
||||
}
|
||||
else
|
||||
{
|
||||
facades = grow( facades, x, false );
|
||||
facades[x] = facade;
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T[] grow(T[] in, int new_value, boolean parts)
|
||||
{
|
||||
if ( in != null && in.length > new_value )
|
||||
return in;
|
||||
|
||||
int newSize = new_value + 1;
|
||||
|
||||
T[] newArray = (T[]) (parts ? new IPart[newSize] : new IFacadePart[newSize]);
|
||||
if ( in != null )
|
||||
System.arraycopy( in, 0, newArray, 0, in.length );
|
||||
|
||||
return newArray;
|
||||
}
|
||||
|
||||
private <T> T[] shrink(T[] in, boolean parts)
|
||||
{
|
||||
int newSize = 0;
|
||||
for (int x = 0; x < in.length; x++)
|
||||
if ( in[x] != null )
|
||||
newSize = x;
|
||||
|
||||
if ( newSize == 0 )
|
||||
return null;
|
||||
|
||||
newSize++;
|
||||
if ( newSize == in.length )
|
||||
return in;
|
||||
|
||||
T[] newArray = (T[]) (parts ? new IPart[newSize] : new IFacadePart[newSize]);
|
||||
System.arraycopy( in, 0, newArray, 0, newSize );
|
||||
|
||||
return newArray;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package appeng.parts;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.parts.SelectedPart;
|
||||
import appeng.api.util.AEColor;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public interface ICableBusContainer
|
||||
{
|
||||
|
||||
int isProvidingStrongPower(ForgeDirection opposite);
|
||||
|
||||
int isProvidingWeakPower(ForgeDirection opposite);
|
||||
|
||||
boolean canConnectRedstone(EnumSet<ForgeDirection> of);
|
||||
|
||||
void onEntityCollision(Entity e);
|
||||
|
||||
boolean activate(EntityPlayer player, Vec3 vecFromPool);
|
||||
|
||||
void onNeighborChanged();
|
||||
|
||||
boolean isSolidOnSide(ForgeDirection side);
|
||||
|
||||
boolean isEmpty();
|
||||
|
||||
SelectedPart selectPart(Vec3 v3);
|
||||
|
||||
boolean recolourBlock(ForgeDirection side, AEColor colour, EntityPlayer who);
|
||||
|
||||
boolean isLadder(EntityLivingBase entity);
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
void randomDisplayTick(World world, int x, int y, int z, Random r);
|
||||
|
||||
int getLightValue();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package appeng.parts;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.parts.SelectedPart;
|
||||
import appeng.api.util.AEColor;
|
||||
|
||||
public class NullCableBusContainer implements ICableBusContainer
|
||||
{
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower(ForgeDirection opposite)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower(ForgeDirection opposite)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone(EnumSet<ForgeDirection> of)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityCollision(Entity e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activate(EntityPlayer player, Vec3 vecFromPool)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolidOnSide(ForgeDirection side)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SelectedPart selectPart(Vec3 v3)
|
||||
{
|
||||
return new SelectedPart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean recolourBlock(ForgeDirection side, AEColor colour, EntityPlayer who)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLadder(EntityLivingBase entity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomDisplayTick(World world, int x, int y, int z, Random r)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightValue()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package appeng.parts;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.implementations.IPowerChannelState;
|
||||
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.api.parts.IPartRenderHelper;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.me.GridAccessException;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartBasicState extends AEBasePart implements IPowerChannelState
|
||||
{
|
||||
|
||||
protected final int POWERED_FLAG = 1;
|
||||
protected final int CHANNEL_FLAG = 2;
|
||||
|
||||
protected int clientFlags = 0; // sent as byte.
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void chanRender(MENetworkChannelsChanged c)
|
||||
{
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(MENetworkPowerStatusChange c)
|
||||
{
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
|
||||
public void setColors(boolean hasChan, boolean hasPower)
|
||||
{
|
||||
if ( hasChan )
|
||||
{
|
||||
int l = 14;
|
||||
Tessellator.instance.setBrightness( l << 20 | l << 4 );
|
||||
Tessellator.instance.setColorOpaque_I( getColor().blackVariant );
|
||||
}
|
||||
else if ( hasPower )
|
||||
{
|
||||
int l = 9;
|
||||
Tessellator.instance.setBrightness( l << 20 | l << 4 );
|
||||
Tessellator.instance.setColorOpaque_I( getColor().whiteVariant );
|
||||
}
|
||||
else
|
||||
{
|
||||
Tessellator.instance.setBrightness( 0 );
|
||||
Tessellator.instance.setColorOpaque_I( 0x000000 );
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderLights(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
rh.normalRendering();
|
||||
setColors( (clientFlags & (POWERED_FLAG | CHANNEL_FLAG)) == (POWERED_FLAG | CHANNEL_FLAG), (clientFlags & POWERED_FLAG) == POWERED_FLAG );
|
||||
rh.renderFace( x, y, z, CableBusTextures.PartMonitorSidesStatusLights.getIcon(), ForgeDirection.EAST, renderer );
|
||||
rh.renderFace( x, y, z, CableBusTextures.PartMonitorSidesStatusLights.getIcon(), ForgeDirection.WEST, renderer );
|
||||
rh.renderFace( x, y, z, CableBusTextures.PartMonitorSidesStatusLights.getIcon(), ForgeDirection.UP, renderer );
|
||||
rh.renderFace( x, y, z, CableBusTextures.PartMonitorSidesStatusLights.getIcon(), ForgeDirection.DOWN, renderer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(ByteBuf data) throws IOException
|
||||
{
|
||||
super.writeToStream( data );
|
||||
|
||||
clientFlags = 0;
|
||||
|
||||
try
|
||||
{
|
||||
if ( proxy.getEnergy().isNetworkPowered() )
|
||||
clientFlags |= POWERED_FLAG;
|
||||
|
||||
if ( proxy.getNode().meetsChannelRequirements() )
|
||||
clientFlags |= CHANNEL_FLAG;
|
||||
|
||||
clientFlags = populateFlags( clientFlags );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// meh
|
||||
}
|
||||
|
||||
data.writeByte( (byte) clientFlags );
|
||||
}
|
||||
|
||||
protected int populateFlags(int cf)
|
||||
{
|
||||
return cf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream(ByteBuf data) throws IOException
|
||||
{
|
||||
boolean eh = super.readFromStream( data );
|
||||
|
||||
int old = clientFlags;
|
||||
clientFlags = data.readByte();
|
||||
|
||||
return eh || old != clientFlags;
|
||||
}
|
||||
|
||||
public PartBasicState(Class c, ItemStack is) {
|
||||
super( c, is );
|
||||
proxy.setFlags( GridFlags.REQUIRE_CHANNEL );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPowered()
|
||||
{
|
||||
return (clientFlags & POWERED_FLAG) == POWERED_FLAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive()
|
||||
{
|
||||
return (clientFlags & CHANNEL_FLAG) == CHANNEL_FLAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getBreakingTexture()
|
||||
{
|
||||
return CableBusTextures.PartTransitionPlaneBack.getIcon();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,460 @@
|
||||
package appeng.parts;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Block.SoundType;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.parts.IFacadePart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartItem;
|
||||
import appeng.api.parts.PartItemStack;
|
||||
import appeng.api.parts.SelectedPart;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.CommonHelper;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketClick;
|
||||
import appeng.core.sync.packets.PacketPartPlacement;
|
||||
import appeng.facade.IFacadeItem;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.integration.abstraction.IBC;
|
||||
import appeng.integration.abstraction.IFMP;
|
||||
import appeng.integration.abstraction.IImmibisMicroblocks;
|
||||
import appeng.util.LookDirection;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
|
||||
public class PartPlacement
|
||||
{
|
||||
|
||||
private ThreadLocal<Object> placing = new ThreadLocal<Object>();
|
||||
private boolean wasCanceled = false;
|
||||
|
||||
@SubscribeEvent
|
||||
public void playerInteract(TickEvent.ClientTickEvent event)
|
||||
{
|
||||
wasCanceled = false;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void playerInteract(PlayerInteractEvent event)
|
||||
{
|
||||
if ( event.action == Action.RIGHT_CLICK_AIR && event.entityPlayer.worldObj.isRemote )
|
||||
{
|
||||
// re-check to see if this event was already channeled, cause these two events are really stupid...
|
||||
MovingObjectPosition mop = Platform.rayTrace( event.entityPlayer, true, false );
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
float f = 1.0F;
|
||||
double d0 = (double) mc.playerController.getBlockReachDistance();
|
||||
Vec3 vec3 = mc.renderViewEntity.getPosition( f );
|
||||
|
||||
if ( mop != null && mop.hitVec.distanceTo( vec3 ) < d0 )
|
||||
{
|
||||
World w = event.entity.worldObj;
|
||||
TileEntity te = w.getTileEntity( mop.blockX, mop.blockY, mop.blockZ );
|
||||
if ( te instanceof IPartHost && wasCanceled )
|
||||
event.setCanceled( true );
|
||||
}
|
||||
else if ( event.entityPlayer != null )
|
||||
{
|
||||
ItemStack held = event.entityPlayer.getHeldItem();
|
||||
boolean supportedItem = AEApi.instance().items().itemMemoryCard.sameAsStack( held )
|
||||
|| AEApi.instance().items().itemColorApplicator.sameAsStack( held );
|
||||
if ( event.entityPlayer.isSneaking() && held != null && supportedItem )
|
||||
{
|
||||
try
|
||||
{
|
||||
NetworkHandler.instance.sendToServer( new PacketClick( event.x, event.y, event.z, event.face, 0, 0, 0 ) );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj.isRemote )
|
||||
{
|
||||
if ( placing.get() != null )
|
||||
return;
|
||||
|
||||
placing.set( event );
|
||||
|
||||
ItemStack held = event.entityPlayer.getHeldItem();
|
||||
if ( place( held, event.x, event.y, event.z, event.face, event.entityPlayer, event.entityPlayer.worldObj, PlaceType.INTERACT_FIRST_PASS, 0 ) )
|
||||
{
|
||||
event.setCanceled( true );
|
||||
wasCanceled = true;
|
||||
}
|
||||
|
||||
placing.set( null );
|
||||
}
|
||||
}
|
||||
|
||||
public enum PlaceType
|
||||
{
|
||||
PLACE_ITEM, INTERACT_FIRST_PASS, INTERACT_SECOND_PASS
|
||||
};
|
||||
|
||||
public static boolean place(ItemStack held, int x, int y, int z, int face, EntityPlayer player, World world, PlaceType pass, int depth)
|
||||
{
|
||||
if ( depth > 3 )
|
||||
return false;
|
||||
|
||||
ForgeDirection side = ForgeDirection.getOrientation( face );
|
||||
|
||||
if ( held != null && Platform.isWrench( player, held, x, y, z ) && player.isSneaking() )
|
||||
{
|
||||
if ( !Platform.hasPermissions( new DimensionalCoord( world, x, y, z ), player ) )
|
||||
return false;
|
||||
|
||||
Block block = world.getBlock( x, y, z );
|
||||
TileEntity tile = world.getTileEntity( x, y, z );
|
||||
IPartHost host = null;
|
||||
|
||||
if ( tile instanceof IPartHost )
|
||||
host = (IPartHost) tile;
|
||||
|
||||
if ( host != null )
|
||||
{
|
||||
if ( !world.isRemote )
|
||||
{
|
||||
LookDirection dir = Platform.getPlayerRay( player, getEyeOffset( player ) );
|
||||
MovingObjectPosition mop = block.collisionRayTrace( world, x, y, z, dir.a, dir.b );
|
||||
if ( mop != null )
|
||||
{
|
||||
List<ItemStack> is = new LinkedList();
|
||||
SelectedPart sp = selectPart( player, host, mop.hitVec.addVector( -mop.blockX, -mop.blockY, -mop.blockZ ) );
|
||||
|
||||
if ( sp.part != null )
|
||||
{
|
||||
is.add( sp.part.getItemStack( PartItemStack.Wrench ) );
|
||||
sp.part.getDrops( is, true );
|
||||
host.removePart( sp.side, false );
|
||||
}
|
||||
|
||||
if ( sp.facade != null )
|
||||
{
|
||||
is.add( sp.facade.getItemStack() );
|
||||
host.getFacadeContainer().removeFacade( host, sp.side );
|
||||
Platform.notifyBlocksOfNeighbors( world, x, y, z );
|
||||
}
|
||||
|
||||
if ( host.isEmpty() )
|
||||
host.cleanup();
|
||||
|
||||
if ( is != null && !is.isEmpty() )
|
||||
{
|
||||
Platform.spawnDrops( world, x, y, z, is );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.swingItem();
|
||||
try
|
||||
{
|
||||
NetworkHandler.instance.sendToServer( new PacketPartPlacement( x, y, z, face, getEyeOffset( player ) ) );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
TileEntity tile = world.getTileEntity( x, y, z );
|
||||
IPartHost host = null;
|
||||
|
||||
if ( tile instanceof IPartHost )
|
||||
host = (IPartHost) tile;
|
||||
|
||||
if ( held != null )
|
||||
{
|
||||
IFacadePart fp = isFacade( held, side );
|
||||
if ( fp != null )
|
||||
{
|
||||
if ( host != null )
|
||||
{
|
||||
if ( !world.isRemote )
|
||||
{
|
||||
if ( host.getPart( ForgeDirection.UNKNOWN ) == null )
|
||||
return false;
|
||||
|
||||
if ( host.canAddPart( held, side ) )
|
||||
{
|
||||
if ( host.getFacadeContainer().addFacade( fp ) )
|
||||
{
|
||||
host.markForUpdate();
|
||||
if ( !player.capabilities.isCreativeMode )
|
||||
{
|
||||
held.stackSize--;
|
||||
if ( held.stackSize == 0 )
|
||||
{
|
||||
player.inventory.mainInventory[player.inventory.currentItem] = null;
|
||||
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( player, held ) );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.swingItem();
|
||||
try
|
||||
{
|
||||
NetworkHandler.instance.sendToServer( new PacketPartPlacement( x, y, z, face, getEyeOffset( player ) ) );
|
||||
return true;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( host == null && tile != null && AppEng.instance.isIntegrationEnabled( IntegrationType.FMP ) )
|
||||
host = ((IFMP) AppEng.instance.getIntegration( IntegrationType.FMP )).getOrCreateHost( tile );
|
||||
|
||||
if ( host == null && tile != null && AppEng.instance.isIntegrationEnabled( IntegrationType.ImmibisMicroblocks ) )
|
||||
host = ((IImmibisMicroblocks) AppEng.instance.getIntegration( IntegrationType.ImmibisMicroblocks )).getOrCreateHost( player, face, tile );
|
||||
|
||||
// if ( held == null )
|
||||
{
|
||||
Block block = world.getBlock( x, y, z );
|
||||
if ( host != null && player.isSneaking() && block != null )
|
||||
{
|
||||
LookDirection dir = Platform.getPlayerRay( player, getEyeOffset( player ) );
|
||||
MovingObjectPosition mop = block.collisionRayTrace( world, x, y, z, dir.a, dir.b );
|
||||
if ( mop != null )
|
||||
{
|
||||
mop.hitVec = mop.hitVec.addVector( -mop.blockX, -mop.blockY, -mop.blockZ );
|
||||
SelectedPart sPart = selectPart( player, host, mop.hitVec );
|
||||
if ( sPart != null && sPart.part != null )
|
||||
if ( sPart.part.onShiftActivate( player, mop.hitVec ) )
|
||||
{
|
||||
if ( world.isRemote )
|
||||
{
|
||||
try
|
||||
{
|
||||
NetworkHandler.instance.sendToServer( new PacketPartPlacement( x, y, z, face, getEyeOffset( player ) ) );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( held == null || !(held.getItem() instanceof IPartItem) )
|
||||
return false;
|
||||
|
||||
int te_x = x;
|
||||
int te_y = y;
|
||||
int te_z = z;
|
||||
|
||||
if ( host == null && pass == PlaceType.PLACE_ITEM )
|
||||
{
|
||||
ItemStack is = AEApi.instance().blocks().blockMultiPart.stack( 1 );
|
||||
ItemBlock ib = (ItemBlock) is.getItem();
|
||||
ForgeDirection offset = ForgeDirection.UNKNOWN;
|
||||
|
||||
Block blkID = world.getBlock( x, y, z );
|
||||
if ( blkID != null && !blkID.isReplaceable( world, x, y, z ) )
|
||||
{
|
||||
offset = side;
|
||||
if ( Platform.isServer() )
|
||||
side = side.getOpposite();
|
||||
}
|
||||
|
||||
te_x = x + offset.offsetX;
|
||||
te_y = y + offset.offsetY;
|
||||
te_z = z + offset.offsetZ;
|
||||
|
||||
tile = world.getTileEntity( te_x, te_y, te_z );
|
||||
if ( tile instanceof IPartHost )
|
||||
host = (IPartHost) tile;
|
||||
|
||||
if ( host == null && tile != null && AppEng.instance.isIntegrationEnabled( IntegrationType.FMP ) )
|
||||
host = ((IFMP) AppEng.instance.getIntegration( IntegrationType.FMP )).getOrCreateHost( tile );
|
||||
|
||||
if ( host == null && tile != null && AppEng.instance.isIntegrationEnabled( IntegrationType.ImmibisMicroblocks ) )
|
||||
host = ((IImmibisMicroblocks) AppEng.instance.getIntegration( IntegrationType.ImmibisMicroblocks )).getOrCreateHost( player, face, tile );
|
||||
|
||||
if ( host == null && AEApi.instance().blocks().blockMultiPart.block().canPlaceBlockAt( world, te_x, te_y, te_z )
|
||||
&& ib.placeBlockAt( is, player, world, te_x, te_y, te_z, side.ordinal(), 0.5f, 0.5f, 0.5f, 0 ) )
|
||||
{
|
||||
if ( !world.isRemote )
|
||||
{
|
||||
tile = world.getTileEntity( te_x, te_y, te_z );
|
||||
|
||||
if ( tile instanceof IPartHost )
|
||||
host = (IPartHost) tile;
|
||||
|
||||
pass = PlaceType.INTERACT_SECOND_PASS;
|
||||
}
|
||||
else
|
||||
{
|
||||
player.swingItem();
|
||||
try
|
||||
{
|
||||
NetworkHandler.instance.sendToServer( new PacketPartPlacement( x, y, z, face, getEyeOffset( player ) ) );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if ( host != null && !host.canAddPart( held, side ) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( host == null )
|
||||
return false;
|
||||
|
||||
if ( !host.canAddPart( held, side ) )
|
||||
{
|
||||
if ( pass == PlaceType.INTERACT_FIRST_PASS || pass == PlaceType.PLACE_ITEM )
|
||||
{
|
||||
ForgeDirection offset = side;
|
||||
|
||||
te_x = x + offset.offsetX;
|
||||
te_y = y + offset.offsetY;
|
||||
te_z = z + offset.offsetZ;
|
||||
|
||||
Block blkID = world.getBlock( te_x, te_y, te_z );
|
||||
tile = world.getTileEntity( te_x, te_y, te_z );
|
||||
|
||||
if ( tile != null && AppEng.instance.isIntegrationEnabled( IntegrationType.FMP ) )
|
||||
host = ((IFMP) AppEng.instance.getIntegration( IntegrationType.FMP )).getOrCreateHost( tile );
|
||||
|
||||
if ( (blkID == null || blkID.isReplaceable( world, te_x, te_y, te_z ) || host != null) && offset != ForgeDirection.UNKNOWN )
|
||||
return place( held, te_x, te_y, te_z, side.getOpposite().ordinal(), player, world,
|
||||
pass == PlaceType.INTERACT_FIRST_PASS ? PlaceType.INTERACT_SECOND_PASS : PlaceType.PLACE_ITEM, depth + 1 );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !world.isRemote )
|
||||
{
|
||||
Block block = world.getBlock( x, y, z );
|
||||
LookDirection dir = Platform.getPlayerRay( player, getEyeOffset( player ) );
|
||||
MovingObjectPosition mop = block.collisionRayTrace( world, x, y, z, dir.a, dir.b );
|
||||
if ( mop != null )
|
||||
{
|
||||
SelectedPart sp = selectPart( player, host, mop.hitVec.addVector( -mop.blockX, -mop.blockY, -mop.blockZ ) );
|
||||
|
||||
if ( sp.part != null )
|
||||
{
|
||||
if ( !player.isSneaking() && sp.part.onActivate( player, mop.hitVec ) )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
DimensionalCoord dc = host.getLocation();
|
||||
if ( !Platform.hasPermissions( dc, player ) )
|
||||
return false;
|
||||
|
||||
ForgeDirection mySide = host.addPart( held, side, player );
|
||||
if ( mySide != null )
|
||||
{
|
||||
SoundType ss = AEApi.instance().blocks().blockMultiPart.block().stepSound;
|
||||
|
||||
// ss.getPlaceSound()
|
||||
world.playSoundEffect( 0.5 + x, 0.5 + y, 0.5 + z, ss.func_150496_b(), (ss.getVolume() + 1.0F) / 2.0F, ss.getPitch() * 0.8F );
|
||||
|
||||
if ( !player.capabilities.isCreativeMode )
|
||||
{
|
||||
held.stackSize--;
|
||||
if ( held.stackSize == 0 )
|
||||
{
|
||||
player.inventory.mainInventory[player.inventory.currentItem] = null;
|
||||
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( player, held ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.swingItem();
|
||||
try
|
||||
{
|
||||
NetworkHandler.instance.sendToServer( new PacketPartPlacement( x, y, z, face, getEyeOffset( player ) ) );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static float eyeHeight = 0.0f;
|
||||
|
||||
private static float getEyeOffset(EntityPlayer p)
|
||||
{
|
||||
if ( p.worldObj.isRemote )
|
||||
return Platform.getEyeOffset( p );
|
||||
|
||||
return eyeHeight;
|
||||
}
|
||||
|
||||
private static SelectedPart selectPart(EntityPlayer player, IPartHost host, Vec3 pos)
|
||||
{
|
||||
CommonHelper.proxy.updateRenderMode( player );
|
||||
SelectedPart sp = host.selectPart( pos );
|
||||
CommonHelper.proxy.updateRenderMode( null );
|
||||
|
||||
return sp;
|
||||
}
|
||||
|
||||
public static IFacadePart isFacade(ItemStack held, ForgeDirection side)
|
||||
{
|
||||
if ( held.getItem() instanceof IFacadeItem )
|
||||
return ((IFacadeItem) held.getItem()).createPartFromItemStack( held, side );
|
||||
|
||||
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.BC ) )
|
||||
{
|
||||
IBC bc = (IBC) AppEng.instance.getIntegration( IntegrationType.BC );
|
||||
if ( bc.isFacade( held ) )
|
||||
return bc.createFacadePart( held, side );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import scala.NotImplementedError;
|
||||
|
||||
public class NonNullArrayIterator<E> implements Iterator<E>
|
||||
{
|
||||
|
||||
int offset = 0;
|
||||
final E[] g;
|
||||
|
||||
public NonNullArrayIterator(E[] o) {
|
||||
g = o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
while (offset < g.length && g[offset] == null)
|
||||
offset++;
|
||||
|
||||
return offset != g.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E next()
|
||||
{
|
||||
return g[offset++];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
throw new NotImplementedError();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,458 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.MachineSource;
|
||||
import appeng.api.networking.storage.IStorageGrid;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.core.sync.packets.PacketTransitionEffect;
|
||||
import appeng.hooks.TickHandler;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.PartBasicState;
|
||||
import appeng.server.ServerHelper;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartAnnihilationPlane extends PartBasicState implements IGridTickable, Callable
|
||||
{
|
||||
|
||||
public PartAnnihilationPlane(ItemStack is) {
|
||||
super( PartAnnihilationPlane.class, is );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
rh.setTexture( CableBusTextures.PartPlaneSides.getIcon(), CableBusTextures.PartPlaneSides.getIcon(),
|
||||
CableBusTextures.PartTransitionPlaneBack.getIcon(), is.getIconIndex(), CableBusTextures.PartPlaneSides.getIcon(),
|
||||
CableBusTextures.PartPlaneSides.getIcon() );
|
||||
|
||||
rh.setBounds( 1, 1, 15, 15, 15, 16 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
rh.setBounds( 5, 5, 14, 11, 11, 15 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
int minX = 1;
|
||||
int minY = 1;
|
||||
int maxX = 15;
|
||||
int maxY = 15;
|
||||
|
||||
ForgeDirection e = rh.getWorldX();
|
||||
ForgeDirection u = rh.getWorldY();
|
||||
|
||||
TileEntity te = getHost().getTile();
|
||||
|
||||
if ( isTransitionPlane( te.getWorldObj().getTileEntity( x - e.offsetX, y - e.offsetY, z - e.offsetZ ), side ) )
|
||||
minX = 0;
|
||||
|
||||
if ( isTransitionPlane( te.getWorldObj().getTileEntity( x + e.offsetX, y + e.offsetY, z + e.offsetZ ), side ) )
|
||||
maxX = 16;
|
||||
|
||||
if ( isTransitionPlane( te.getWorldObj().getTileEntity( x - u.offsetX, y - u.offsetY, z - u.offsetZ ), side ) )
|
||||
minY = 0;
|
||||
|
||||
if ( isTransitionPlane( te.getWorldObj().getTileEntity( x + u.offsetX, y + u.offsetY, z + u.offsetZ ), side ) )
|
||||
maxY = 16;
|
||||
|
||||
boolean isActive = (clientFlags & (POWERED_FLAG | CHANNEL_FLAG)) == (POWERED_FLAG | CHANNEL_FLAG);
|
||||
|
||||
renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache );
|
||||
rh.setTexture( CableBusTextures.PartPlaneSides.getIcon(), CableBusTextures.PartPlaneSides.getIcon(),
|
||||
CableBusTextures.PartTransitionPlaneBack.getIcon(), isActive ? CableBusTextures.BlockAnnihilationPlaneOn.getIcon() : is.getIconIndex(),
|
||||
CableBusTextures.PartPlaneSides.getIcon(), CableBusTextures.PartPlaneSides.getIcon() );
|
||||
|
||||
rh.setBounds( minX, minY, 15, maxX, maxY, 16 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setTexture( CableBusTextures.PartMonitorSidesStatus.getIcon(), CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartTransitionPlaneBack.getIcon(), isActive ? CableBusTextures.BlockAnnihilationPlaneOn.getIcon() : is.getIconIndex(),
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon(), CableBusTextures.PartMonitorSidesStatus.getIcon() );
|
||||
|
||||
rh.setBounds( 5, 5, 14, 11, 11, 15 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
renderLights( x, y, z, rh, renderer );
|
||||
}
|
||||
|
||||
private boolean isTransitionPlane(TileEntity blockTileEntity, ForgeDirection side)
|
||||
{
|
||||
if ( blockTileEntity instanceof IPartHost )
|
||||
{
|
||||
IPart p = ((IPartHost) blockTileEntity).getPart( side );
|
||||
return p instanceof PartAnnihilationPlane;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(IPartCollisionHelper bch)
|
||||
{
|
||||
int minX = 1;
|
||||
int minY = 1;
|
||||
int maxX = 15;
|
||||
int maxY = 15;
|
||||
|
||||
IPartHost host = getHost();
|
||||
if ( host != null )
|
||||
{
|
||||
TileEntity te = host.getTile();
|
||||
|
||||
int x = te.xCoord;
|
||||
int y = te.yCoord;
|
||||
int z = te.zCoord;
|
||||
|
||||
ForgeDirection e = bch.getWorldX();
|
||||
ForgeDirection u = bch.getWorldY();
|
||||
|
||||
if ( isTransitionPlane( te.getWorldObj().getTileEntity( x - e.offsetX, y - e.offsetY, z - e.offsetZ ), side ) )
|
||||
minX = 0;
|
||||
|
||||
if ( isTransitionPlane( te.getWorldObj().getTileEntity( x + e.offsetX, y + e.offsetY, z + e.offsetZ ), side ) )
|
||||
maxX = 16;
|
||||
|
||||
if ( isTransitionPlane( te.getWorldObj().getTileEntity( x - u.offsetX, y - u.offsetY, z - u.offsetZ ), side ) )
|
||||
minY = 0;
|
||||
|
||||
if ( isTransitionPlane( te.getWorldObj().getTileEntity( x + u.offsetX, y + u.offsetY, z + u.offsetZ ), side ) )
|
||||
maxY = 16;
|
||||
}
|
||||
|
||||
bch.addBox( 5, 5, 14, 11, 11, 15 );
|
||||
bch.addBox( minX, minY, 15, maxX, maxY, bch.isBBCollision() ? 15 : 16 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cableConnectionRenderTo()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
boolean breaking = false;
|
||||
LinkedList<IAEItemStack> Buffer = new LinkedList();
|
||||
BaseActionSource mySrc = new MachineSource( this );
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
|
||||
data.setInteger( "bufferSize", Buffer.size() );
|
||||
for (int x = 0; x < Buffer.size(); x++)
|
||||
{
|
||||
NBTTagCompound pack = new NBTTagCompound();
|
||||
Buffer.get( x ).writeToNBT( pack );
|
||||
data.setTag( "buffer" + x, pack );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
|
||||
int size = data.getInteger( "bufferSize" );
|
||||
Buffer.clear();
|
||||
for (int x = 0; x < size; x++)
|
||||
{
|
||||
NBTTagCompound pack = (NBTTagCompound) data.getTag( "buffer" + x );
|
||||
IAEItemStack ais = AEItemStack.loadItemStackFromNBT( pack );
|
||||
if ( ais != null )
|
||||
Buffer.add( ais );
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAccepting()
|
||||
{
|
||||
return Buffer.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(List<ItemStack> drops, boolean wrenched)
|
||||
{
|
||||
for (IAEItemStack is : Buffer)
|
||||
if ( is != null )
|
||||
drops.add( is.getItemStack() );
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void chanRender(MENetworkChannelsChanged c)
|
||||
{
|
||||
onNeighborChanged();
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(MENetworkPowerStatusChange c)
|
||||
{
|
||||
onNeighborChanged();
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
|
||||
public TickRateModulation EatBlock(boolean eatForReal)
|
||||
{
|
||||
if ( isAccepting() && proxy.isActive() )
|
||||
{
|
||||
try
|
||||
{
|
||||
TileEntity te = getTile();
|
||||
WorldServer w = (WorldServer) te.getWorldObj();
|
||||
|
||||
int x = te.xCoord + side.offsetX;
|
||||
int y = te.yCoord + side.offsetY;
|
||||
int z = te.zCoord + side.offsetZ;
|
||||
|
||||
Block blk = w.getBlock( x, y, z );
|
||||
|
||||
IStorageGrid storage = (IStorageGrid) proxy.getStorage();
|
||||
IEnergyGrid energy = (IEnergyGrid) proxy.getEnergy();
|
||||
|
||||
Material mat = blk.getMaterial();
|
||||
boolean ignore = mat == Material.air || mat == Material.lava || mat == Material.water || mat.isLiquid() || blk == Blocks.bedrock
|
||||
|| blk == Blocks.end_portal || blk == Blocks.end_portal_frame || blk == Blocks.command_block;
|
||||
|
||||
if ( !ignore )
|
||||
{
|
||||
if ( !w.isAirBlock( x, y, z ) && w.blockExists( x, y, z ) && blk != null && w.canMineBlock( Platform.getPlayer( w ), x, y, z ) )
|
||||
{
|
||||
float hardness = blk.getBlockHardness( w, x, y, z );
|
||||
if ( hardness >= 0.0 )
|
||||
{
|
||||
ItemStack[] out = Platform.getBlockDrops( w, x, y, z );
|
||||
float total = 1 + hardness;
|
||||
for (ItemStack is : out)
|
||||
total += is.stackSize;
|
||||
|
||||
boolean hasPower = energy.extractAEPower( total, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > total - 0.1;
|
||||
if ( hasPower )
|
||||
{
|
||||
if ( eatForReal )
|
||||
{
|
||||
energy.extractAEPower( total, Actionable.MODULATE, PowerMultiplier.CONFIG );
|
||||
w.setBlock( x, y, z, Platform.air, 0, 3 );
|
||||
|
||||
AxisAlignedBB box = AxisAlignedBB.getBoundingBox( x - 0.2, y - 0.2, z - 0.2, x + 1.2, y + 1.2, z + 1.2 );
|
||||
for (Object ei : w.getEntitiesWithinAABB( EntityItem.class, box ))
|
||||
{
|
||||
if ( ei instanceof EntityItem )
|
||||
{
|
||||
EntityItem item = (EntityItem) ei;
|
||||
if ( !item.isDead )
|
||||
{
|
||||
IAEItemStack storedItem = AEItemStack.create( item.getEntityItem() );
|
||||
storedItem = Platform.poweredInsert( energy, storage.getItemInventory(), storedItem, mySrc );
|
||||
if ( storedItem != null )
|
||||
Buffer.add( storedItem );
|
||||
|
||||
item.setDead();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ServerHelper.proxy.sendToAllNearExcept( null, x, y, z, 64, w, new PacketTransitionEffect( x, y, z, side, true ) );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
|
||||
for (ItemStack snaggedItem : out)
|
||||
{
|
||||
IAEItemStack storedItem = AEItemStack.create( snaggedItem );
|
||||
storedItem = Platform.poweredInsert( energy, storage.getItemInventory(), storedItem, mySrc );
|
||||
if ( storedItem != null )
|
||||
Buffer.add( storedItem );
|
||||
}
|
||||
|
||||
return TickRateModulation.URGENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
breaking = true;
|
||||
TickHandler.instance.addCallable( this.tile.getWorldObj(), this );
|
||||
return TickRateModulation.URGENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e1)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
// nothing to do here :)
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
return new TickingRequest( TickRates.AnnihilationPlane.min, TickRates.AnnihilationPlane.max, false, true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
try
|
||||
{
|
||||
proxy.getTick().alertDevice( proxy.getNode() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityCollision(Entity entity)
|
||||
{
|
||||
if ( entity instanceof EntityItem && !entity.isDead && isAccepting() )
|
||||
{
|
||||
boolean capture = false;
|
||||
|
||||
switch (side)
|
||||
{
|
||||
case DOWN:
|
||||
case UP:
|
||||
if ( entity.posX > tile.xCoord && entity.posX < tile.xCoord + 1 )
|
||||
if ( entity.posZ > tile.zCoord && entity.posZ < tile.zCoord + 1 )
|
||||
if ( (entity.posY > tile.yCoord + 0.9 && side == ForgeDirection.UP) || (entity.posY < tile.yCoord + 0.1 && side == ForgeDirection.DOWN) )
|
||||
capture = true;
|
||||
break;
|
||||
case SOUTH:
|
||||
case NORTH:
|
||||
if ( entity.posX > tile.xCoord && entity.posX < tile.xCoord + 1 )
|
||||
if ( entity.posY > tile.yCoord && entity.posY < tile.yCoord + 1 )
|
||||
if ( (entity.posZ > tile.zCoord + 0.9 && side == ForgeDirection.SOUTH)
|
||||
|| (entity.posZ < tile.zCoord + 0.1 && side == ForgeDirection.NORTH) )
|
||||
capture = true;
|
||||
break;
|
||||
case EAST:
|
||||
case WEST:
|
||||
if ( entity.posZ > tile.zCoord && entity.posZ < tile.zCoord + 1 )
|
||||
if ( entity.posY > tile.yCoord && entity.posY < tile.yCoord + 1 )
|
||||
if ( (entity.posX > tile.xCoord + 0.9 && side == ForgeDirection.EAST)
|
||||
|| (entity.posX < tile.xCoord + 0.1 && side == ForgeDirection.WEST) )
|
||||
capture = true;
|
||||
break;
|
||||
default:
|
||||
// umm?
|
||||
break;
|
||||
}
|
||||
|
||||
if ( capture && Platform.isServer() && proxy.isActive() )
|
||||
{
|
||||
IAEItemStack stack = AEItemStack.create( ((EntityItem) entity).getEntityItem() );
|
||||
if ( stack != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
ServerHelper.proxy.sendToAllNearExcept( null, tile.xCoord, tile.yCoord, tile.zCoord, 64, tile.getWorldObj(),
|
||||
new PacketTransitionEffect( entity.posX, entity.posY, entity.posZ, side, false ) );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
|
||||
Buffer.add( stack );
|
||||
storeBuffer();
|
||||
entity.setDead();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
{
|
||||
if ( breaking )
|
||||
return TickRateModulation.URGENT;
|
||||
|
||||
if ( isAccepting() )
|
||||
return EatBlock( false );
|
||||
else
|
||||
{
|
||||
storeBuffer();
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
}
|
||||
|
||||
private void storeBuffer()
|
||||
{
|
||||
try
|
||||
{
|
||||
IStorageGrid storage = (IStorageGrid) proxy.getStorage();
|
||||
IEnergyGrid energy = (IEnergyGrid) proxy.getEnergy();
|
||||
|
||||
while (!Buffer.isEmpty())
|
||||
{
|
||||
IAEItemStack storedItem = Buffer.pop();
|
||||
storedItem = Platform.poweredInsert( energy, storage.getItemInventory(), storedItem, mySrc );
|
||||
if ( storedItem != null )
|
||||
{
|
||||
Buffer.add( storedItem );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e1)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object call() throws Exception
|
||||
{
|
||||
breaking = false;
|
||||
return EatBlock( true );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,335 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
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.Vec3;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.config.YesNo;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.crafting.ICraftingGrid;
|
||||
import appeng.api.networking.crafting.ICraftingLink;
|
||||
import appeng.api.networking.crafting.ICraftingRequester;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.MachineSource;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.helpers.MultiCraftingTracker;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartExportBus extends PartSharedItemBus implements IGridTickable, ICraftingRequester
|
||||
{
|
||||
|
||||
final MultiCraftingTracker cratingTracker = new MultiCraftingTracker( this, 9 );
|
||||
final BaseActionSource mySrc;
|
||||
|
||||
public PartExportBus(ItemStack is) {
|
||||
super( PartExportBus.class, is );
|
||||
settings.registerSetting( Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
|
||||
settings.registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
|
||||
settings.registerSetting( Settings.CRAFT_ONLY, YesNo.NO );
|
||||
mySrc = new MachineSource( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound extra)
|
||||
{
|
||||
super.readFromNBT( extra );
|
||||
cratingTracker.readFromNBT( extra );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound extra)
|
||||
{
|
||||
super.writeToNBT( extra );
|
||||
cratingTracker.writeToNBT( extra );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
if ( !player.isSneaking() )
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return true;
|
||||
|
||||
Platform.openGUI( player, getHost().getTile(), side, GuiBridge.GUI_BUS );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
|
||||
rh.setTexture( CableBusTextures.PartExportSides.getIcon(), CableBusTextures.PartExportSides.getIcon(), CableBusTextures.PartMonitorBack.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartExportSides.getIcon(), CableBusTextures.PartExportSides.getIcon() );
|
||||
|
||||
rh.setBounds( 4, 4, 12, 12, 12, 14 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
rh.setBounds( 5, 5, 14, 11, 11, 15 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
rh.setBounds( 6, 6, 15, 10, 10, 16 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache );
|
||||
rh.setTexture( CableBusTextures.PartExportSides.getIcon(), CableBusTextures.PartExportSides.getIcon(), CableBusTextures.PartMonitorBack.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartExportSides.getIcon(), CableBusTextures.PartExportSides.getIcon() );
|
||||
|
||||
rh.setBounds( 4, 4, 12, 12, 12, 14 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setBounds( 5, 5, 14, 11, 11, 15 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setBounds( 6, 6, 15, 10, 10, 16 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setTexture( CableBusTextures.PartMonitorSidesStatus.getIcon(), CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorBack.getIcon(), is.getIconIndex(), CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon() );
|
||||
|
||||
rh.setBounds( 6, 6, 11, 10, 10, 12 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
renderLights( x, y, z, rh, renderer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cableConnectionRenderTo()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(IPartCollisionHelper bch)
|
||||
{
|
||||
bch.addBox( 4, 4, 12, 12, 12, 14 );
|
||||
bch.addBox( 5, 5, 14, 11, 11, 15 );
|
||||
bch.addBox( 6, 6, 15, 10, 10, 16 );
|
||||
bch.addBox( 6, 6, 11, 10, 10, 12 );
|
||||
}
|
||||
|
||||
long itemToSend = 1;
|
||||
boolean didSomething = false;
|
||||
|
||||
@Override
|
||||
TickRateModulation doBusWork()
|
||||
{
|
||||
if ( !proxy.isActive() )
|
||||
return TickRateModulation.IDLE;
|
||||
|
||||
itemToSend = 1;
|
||||
didSomething = false;
|
||||
|
||||
switch (getInstalledUpgrades( Upgrades.SPEED ))
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
itemToSend = 1;
|
||||
break;
|
||||
case 1:
|
||||
itemToSend = 8;
|
||||
break;
|
||||
case 2:
|
||||
itemToSend = 32;
|
||||
break;
|
||||
case 3:
|
||||
itemToSend = 64;
|
||||
break;
|
||||
case 4:
|
||||
itemToSend = 96;
|
||||
break;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
InventoryAdaptor d = getHandler();
|
||||
IMEMonitor<IAEItemStack> inv = proxy.getStorage().getItemInventory();
|
||||
IEnergyGrid energy = proxy.getEnergy();
|
||||
ICraftingGrid cg = proxy.getCrafting();
|
||||
FuzzyMode fzMode = (FuzzyMode) getConfigManager().getSetting( Settings.FUZZY_MODE );
|
||||
|
||||
if ( d != null )
|
||||
{
|
||||
for (int x = 0; x < availableSlots() && itemToSend > 0; x++)
|
||||
{
|
||||
IAEItemStack ais = config.getAEStackInSlot( x );
|
||||
if ( ais == null || itemToSend <= 0 || craftOnly() )
|
||||
{
|
||||
if ( isCraftingEnabled() )
|
||||
didSomething = cratingTracker.handleCrafting( x, itemToSend, ais, d, getTile().getWorldObj(), proxy.getGrid(), cg, mySrc )
|
||||
|| didSomething;
|
||||
continue;
|
||||
}
|
||||
|
||||
long before = itemToSend;
|
||||
|
||||
if ( getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
{
|
||||
for (IAEItemStack o : ImmutableList.copyOf( inv.getStorageList().findFuzzy( ais, fzMode ) ))
|
||||
{
|
||||
pushItemIntoTarget( d, energy, inv, o );
|
||||
if ( itemToSend <= 0 )
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
pushItemIntoTarget( d, energy, inv, ais );
|
||||
|
||||
if ( itemToSend == before && isCraftingEnabled() )
|
||||
didSomething = cratingTracker.handleCrafting( x, itemToSend, ais, d, getTile().getWorldObj(), proxy.getGrid(), cg, mySrc )
|
||||
|| didSomething;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
return didSomething ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
}
|
||||
|
||||
private boolean craftOnly()
|
||||
{
|
||||
return getConfigManager().getSetting( Settings.CRAFT_ONLY ) == YesNo.YES;
|
||||
}
|
||||
|
||||
private boolean isCraftingEnabled()
|
||||
{
|
||||
return getInstalledUpgrades( Upgrades.CRAFTING ) > 0;
|
||||
}
|
||||
|
||||
private void pushItemIntoTarget(InventoryAdaptor d, IEnergyGrid energy, IMEInventory<IAEItemStack> inv, IAEItemStack ais)
|
||||
{
|
||||
ItemStack is = ais.getItemStack();
|
||||
is.stackSize = (int) itemToSend;
|
||||
|
||||
ItemStack o = d.simulateAdd( is );
|
||||
long canFit = o == null ? itemToSend : itemToSend - o.stackSize;
|
||||
|
||||
if ( canFit > 0 )
|
||||
{
|
||||
ais = ais.copy();
|
||||
ais.setStackSize( canFit );
|
||||
IAEItemStack itemsToAdd = Platform.poweredExtraction( energy, inv, ais, mySrc );
|
||||
|
||||
if ( itemsToAdd != null )
|
||||
{
|
||||
itemToSend -= itemsToAdd.getStackSize();
|
||||
|
||||
ItemStack failed = d.addItems( itemsToAdd.getItemStack() );
|
||||
if ( failed != null )
|
||||
{
|
||||
ais.setStackSize( failed.stackSize );
|
||||
inv.injectItems( ais, Actionable.MODULATE, mySrc );
|
||||
}
|
||||
else
|
||||
didSomething = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack items, Actionable mode)
|
||||
{
|
||||
InventoryAdaptor d = getHandler();
|
||||
|
||||
try
|
||||
{
|
||||
if ( d != null && proxy.isActive() )
|
||||
{
|
||||
IEnergyGrid energy = proxy.getEnergy();
|
||||
|
||||
double power = items.getStackSize();
|
||||
if ( energy.extractAEPower( power, mode, PowerMultiplier.CONFIG ) > power - 0.01 )
|
||||
{
|
||||
if ( mode == Actionable.MODULATE )
|
||||
return AEItemStack.create( d.addItems( items.getItemStack() ) );
|
||||
return AEItemStack.create( d.simulateAdd( items.getItemStack() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
{
|
||||
return doBusWork();
|
||||
}
|
||||
|
||||
public RedstoneMode getRSMode()
|
||||
{
|
||||
return (RedstoneMode) settings.getSetting( Settings.REDSTONE_CONTROLLED );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSleeping()
|
||||
{
|
||||
return getHandler() == null || super.isSleeping();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
return new TickingRequest( TickRates.ExportBus.min, TickRates.ExportBus.max, isSleeping(), false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableSet<ICraftingLink> getRequestedJobs()
|
||||
{
|
||||
return cratingTracker.getRequestedJobs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jobStateChange(ICraftingLink link)
|
||||
{
|
||||
cratingTracker.jobStateChange( link );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,514 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemFirework;
|
||||
import net.minecraft.item.ItemReed;
|
||||
import net.minecraft.item.ItemSkull;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraftforge.common.IPlantable;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.config.IncludeExclude;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.networking.events.MENetworkCellArrayUpdate;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartItem;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.storage.ICellContainer;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.storage.MEInventoryHandler;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.prioitylist.FuzzyPriorityList;
|
||||
import appeng.util.prioitylist.PrecisePriorityList;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartFormationPlane extends PartUpgradeable implements ICellContainer, IPriorityHost, IMEInventory<IAEItemStack>
|
||||
{
|
||||
|
||||
int priority = 0;
|
||||
boolean wasActive = false;
|
||||
boolean blocked = false;
|
||||
MEInventoryHandler myHandler = new MEInventoryHandler( this, StorageChannel.ITEMS );
|
||||
AppEngInternalAEInventory Config = new AppEngInternalAEInventory( this, 63 );
|
||||
|
||||
public PartFormationPlane(ItemStack is) {
|
||||
super( PartFormationPlane.class, is );
|
||||
settings.registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
|
||||
updateHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
if ( !player.isSneaking() )
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return true;
|
||||
|
||||
Platform.openGUI( player, getHost().getTile(), side, GuiBridge.GUI_FPLANE );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected int getUpgradeSlots()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(String name)
|
||||
{
|
||||
if ( name.equals( "config" ) )
|
||||
return Config;
|
||||
|
||||
return super.getInventoryByName( name );
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(MENetworkPowerStatusChange c)
|
||||
{
|
||||
boolean currentActive = proxy.isActive();
|
||||
if ( wasActive != currentActive )
|
||||
{
|
||||
wasActive = currentActive;
|
||||
updateHandler();// proxy.getGrid().postEvent( new MENetworkCellArrayUpdate() );
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void updateChannels(MENetworkChannelsChanged chann)
|
||||
{
|
||||
boolean currentActive = proxy.isActive();
|
||||
if ( wasActive != currentActive )
|
||||
{
|
||||
wasActive = currentActive;
|
||||
updateHandler();// proxy.getGrid().postEvent( new MENetworkCellArrayUpdate() );
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
rh.setTexture( CableBusTextures.PartPlaneSides.getIcon(), CableBusTextures.PartPlaneSides.getIcon(),
|
||||
CableBusTextures.PartTransitionPlaneBack.getIcon(), is.getIconIndex(), CableBusTextures.PartPlaneSides.getIcon(),
|
||||
CableBusTextures.PartPlaneSides.getIcon() );
|
||||
|
||||
rh.setBounds( 1, 1, 15, 15, 15, 16 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
rh.setBounds( 5, 5, 14, 11, 11, 15 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
int minX = 1;
|
||||
int minY = 1;
|
||||
int maxX = 15;
|
||||
int maxY = 15;
|
||||
|
||||
ForgeDirection e = rh.getWorldX();
|
||||
ForgeDirection u = rh.getWorldY();
|
||||
|
||||
TileEntity te = getHost().getTile();
|
||||
|
||||
if ( isTransitionPlane( te.getWorldObj().getTileEntity( x - e.offsetX, y - e.offsetY, z - e.offsetZ ), side ) )
|
||||
minX = 0;
|
||||
|
||||
if ( isTransitionPlane( te.getWorldObj().getTileEntity( x + e.offsetX, y + e.offsetY, z + e.offsetZ ), side ) )
|
||||
maxX = 16;
|
||||
|
||||
if ( isTransitionPlane( te.getWorldObj().getTileEntity( x - u.offsetX, y - u.offsetY, z - u.offsetZ ), side ) )
|
||||
minY = 0;
|
||||
|
||||
if ( isTransitionPlane( te.getWorldObj().getTileEntity( x + u.offsetX, y + u.offsetY, z + u.offsetZ ), side ) )
|
||||
maxY = 16;
|
||||
|
||||
boolean isActive = (clientFlags & (POWERED_FLAG | CHANNEL_FLAG)) == (POWERED_FLAG | CHANNEL_FLAG);
|
||||
|
||||
renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache );
|
||||
rh.setTexture( CableBusTextures.PartPlaneSides.getIcon(), CableBusTextures.PartPlaneSides.getIcon(),
|
||||
CableBusTextures.PartTransitionPlaneBack.getIcon(), isActive ? CableBusTextures.BlockFormPlaneOn.getIcon() : is.getIconIndex(),
|
||||
CableBusTextures.PartPlaneSides.getIcon(), CableBusTextures.PartPlaneSides.getIcon() );
|
||||
|
||||
rh.setBounds( minX, minY, 15, maxX, maxY, 16 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setTexture( CableBusTextures.PartMonitorSidesStatus.getIcon(), CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartTransitionPlaneBack.getIcon(), isActive ? CableBusTextures.BlockFormPlaneOn.getIcon() : is.getIconIndex(),
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon(), CableBusTextures.PartMonitorSidesStatus.getIcon() );
|
||||
|
||||
rh.setBounds( 5, 5, 14, 11, 11, 15 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
renderLights( x, y, z, rh, renderer );
|
||||
}
|
||||
|
||||
private boolean isTransitionPlane(TileEntity blockTileEntity, ForgeDirection side)
|
||||
{
|
||||
if ( blockTileEntity instanceof IPartHost )
|
||||
{
|
||||
IPart p = ((IPartHost) blockTileEntity).getPart( side );
|
||||
return p instanceof PartFormationPlane;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(IPartCollisionHelper bch)
|
||||
{
|
||||
int minX = 1;
|
||||
int minY = 1;
|
||||
int maxX = 15;
|
||||
int maxY = 15;
|
||||
|
||||
IPartHost host = getHost();
|
||||
if ( host != null )
|
||||
{
|
||||
TileEntity te = host.getTile();
|
||||
|
||||
int x = te.xCoord;
|
||||
int y = te.yCoord;
|
||||
int z = te.zCoord;
|
||||
|
||||
ForgeDirection e = bch.getWorldX();
|
||||
ForgeDirection u = bch.getWorldY();
|
||||
|
||||
if ( isTransitionPlane( te.getWorldObj().getTileEntity( x - e.offsetX, y - e.offsetY, z - e.offsetZ ), side ) )
|
||||
minX = 0;
|
||||
|
||||
if ( isTransitionPlane( te.getWorldObj().getTileEntity( x + e.offsetX, y + e.offsetY, z + e.offsetZ ), side ) )
|
||||
maxX = 16;
|
||||
|
||||
if ( isTransitionPlane( te.getWorldObj().getTileEntity( x - u.offsetX, y - u.offsetY, z - u.offsetZ ), side ) )
|
||||
minY = 0;
|
||||
|
||||
if ( isTransitionPlane( te.getWorldObj().getTileEntity( x + u.offsetX, y + u.offsetY, z + u.offsetZ ), side ) )
|
||||
maxY = 16;
|
||||
}
|
||||
|
||||
bch.addBox( 5, 5, 14, 11, 11, 15 );
|
||||
bch.addBox( minX, minY, 15, maxX, maxY, 16 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cableConnectionRenderTo()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IMEInventoryHandler> getCellArray(StorageChannel channel)
|
||||
{
|
||||
if ( proxy.isActive() && channel == StorageChannel.ITEMS )
|
||||
{
|
||||
List<IMEInventoryHandler> Handler = new ArrayList( 1 );
|
||||
Handler.add( myHandler );
|
||||
return Handler;
|
||||
}
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue)
|
||||
{
|
||||
updateHandler();
|
||||
host.markForSave();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPriority(int newValue)
|
||||
{
|
||||
priority = newValue;
|
||||
host.markForSave();
|
||||
updateHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
|
||||
{
|
||||
super.onChangeInventory( inv, slot, mc, removedStack, newStack );
|
||||
|
||||
if ( inv == Config )
|
||||
updateHandler();
|
||||
}
|
||||
|
||||
public void upgradesChanged()
|
||||
{
|
||||
updateHandler();
|
||||
}
|
||||
|
||||
private void updateHandler()
|
||||
{
|
||||
myHandler.myAccess = AccessRestriction.WRITE;
|
||||
myHandler.myWhitelist = getInstalledUpgrades( Upgrades.INVERTER ) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST;
|
||||
myHandler.myPriority = priority;
|
||||
|
||||
IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
|
||||
|
||||
int slotsToUse = 18 + getInstalledUpgrades( Upgrades.CAPACITY ) * 9;
|
||||
for (int x = 0; x < Config.getSizeInventory() && x < slotsToUse; x++)
|
||||
{
|
||||
IAEItemStack is = Config.getAEStackInSlot( x );
|
||||
if ( is != null )
|
||||
priorityList.add( is );
|
||||
}
|
||||
|
||||
if ( getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
myHandler.myPartitionList = new FuzzyPriorityList( priorityList, (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE ) );
|
||||
else
|
||||
myHandler.myPartitionList = new PrecisePriorityList( priorityList );
|
||||
|
||||
try
|
||||
{
|
||||
proxy.getGrid().postEvent( new MENetworkCellArrayUpdate() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
Config.writeToNBT( data, "config" );
|
||||
data.setInteger( "priority", priority );
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
Config.readFromNBT( data, "config" );
|
||||
priority = data.getInteger( "priority" );
|
||||
updateHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems(IAEItemStack request, Actionable mode, BaseActionSource src)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getAvailableItems(IItemList<IAEItemStack> out)
|
||||
{
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageChannel getChannel()
|
||||
{
|
||||
return StorageChannel.ITEMS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
{
|
||||
return priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blinkCell(int slot)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
TileEntity te = host.getTile();
|
||||
World w = te.getWorldObj();
|
||||
ForgeDirection side = this.side;
|
||||
|
||||
int x = te.xCoord + side.offsetX;
|
||||
int y = te.yCoord + side.offsetY;
|
||||
int z = te.zCoord + side.offsetZ;
|
||||
|
||||
blocked = !w.getBlock( x, y, z ).isReplaceable( w, x, y, z );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems(IAEItemStack input, Actionable type, BaseActionSource src)
|
||||
{
|
||||
if ( blocked || input == null || input.getStackSize() <= 0 )
|
||||
return input;
|
||||
|
||||
ItemStack is = input.getItemStack();
|
||||
Item i = is.getItem();
|
||||
|
||||
long maxStorage = Math.min( input.getStackSize(), is.getMaxStackSize() );
|
||||
boolean worked = false;
|
||||
|
||||
TileEntity te = host.getTile();
|
||||
World w = te.getWorldObj();
|
||||
ForgeDirection side = this.side;
|
||||
|
||||
int x = te.xCoord + side.offsetX;
|
||||
int y = te.yCoord + side.offsetY;
|
||||
int z = te.zCoord + side.offsetZ;
|
||||
|
||||
if ( w.getBlock( x, y, z ).isReplaceable( w, x, y, z ) )
|
||||
{
|
||||
if ( i instanceof ItemBlock || i instanceof IPlantable || i instanceof ItemSkull || i instanceof ItemFirework || i instanceof IPartItem
|
||||
|| i instanceof ItemReed )
|
||||
{
|
||||
EntityPlayer player = Platform.getPlayer( (WorldServer) w );
|
||||
Platform.configurePlayer( player, side, tile );
|
||||
|
||||
if ( i instanceof ItemFirework )
|
||||
{
|
||||
Chunk c = w.getChunkFromBlockCoords( x, z );
|
||||
int sum = 0;
|
||||
for (List Z : c.entityLists)
|
||||
sum += Z.size();
|
||||
if ( sum > 32 )
|
||||
return input;
|
||||
}
|
||||
maxStorage = is.stackSize;
|
||||
worked = true;
|
||||
if ( type == Actionable.MODULATE )
|
||||
{
|
||||
if ( i instanceof IPlantable || i instanceof ItemSkull || i instanceof ItemReed )
|
||||
{
|
||||
boolean Worked = false;
|
||||
|
||||
if ( Worked == false && side.offsetX == 0 && side.offsetZ == 0 )
|
||||
Worked = i.onItemUse( is, player, w, x + side.offsetX, y + side.offsetY, z + side.offsetZ, side.getOpposite().ordinal(),
|
||||
side.offsetX, side.offsetY, side.offsetZ );
|
||||
|
||||
if ( Worked == false && side.offsetX == 0 && side.offsetZ == 0 )
|
||||
Worked = i.onItemUse( is, player, w, x - side.offsetX, y - side.offsetY, z - side.offsetZ, side.ordinal(), side.offsetX,
|
||||
side.offsetY, side.offsetZ );
|
||||
|
||||
if ( Worked == false && side.offsetY == 0 )
|
||||
Worked = i.onItemUse( is, player, w, x, y - 1, z, ForgeDirection.UP.ordinal(), side.offsetX, side.offsetY, side.offsetZ );
|
||||
|
||||
if ( Worked == false )
|
||||
Worked = i.onItemUse( is, player, w, x, y, z, side.getOpposite().ordinal(), side.offsetX, side.offsetY, side.offsetZ );
|
||||
|
||||
maxStorage = maxStorage - is.stackSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
i.onItemUse( is, player, w, x, y, z, side.getOpposite().ordinal(), side.offsetX, side.offsetY, side.offsetZ );
|
||||
maxStorage = maxStorage - is.stackSize;
|
||||
}
|
||||
}
|
||||
else
|
||||
maxStorage = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
worked = true;
|
||||
Chunk c = w.getChunkFromBlockCoords( x, z );
|
||||
int sum = 0;
|
||||
for (List Z : c.entityLists)
|
||||
sum += Z.size();
|
||||
|
||||
if ( sum < AEConfig.instance.formationPlaneEntityLimit )
|
||||
{
|
||||
if ( type == Actionable.MODULATE )
|
||||
{
|
||||
|
||||
is.stackSize = (int) maxStorage;
|
||||
EntityItem ei = new EntityItem( w, // w
|
||||
((side.offsetX != 0 ? 0.0 : 0.7) * (Platform.getRandomFloat() - 0.5f)) + 0.5 + side.offsetX * -0.3 + (double) x, // spawn
|
||||
((side.offsetY != 0 ? 0.0 : 0.7) * (Platform.getRandomFloat() - 0.5f)) + 0.5 + side.offsetY * -0.3 + (double) y, // spawn
|
||||
((side.offsetZ != 0 ? 0.0 : 0.7) * (Platform.getRandomFloat() - 0.5f)) + 0.5 + side.offsetZ * -0.3 + (double) z, // spawn
|
||||
is.copy() );
|
||||
|
||||
Entity result = ei;
|
||||
|
||||
ei.motionX = side.offsetX * 0.2;
|
||||
ei.motionY = side.offsetY * 0.2;
|
||||
ei.motionZ = side.offsetZ * 0.2;
|
||||
|
||||
if ( is.getItem().hasCustomEntity( is ) )
|
||||
{
|
||||
result = is.getItem().createEntity( w, ei, is );
|
||||
if ( result != null )
|
||||
ei.setDead();
|
||||
else
|
||||
result = ei;
|
||||
}
|
||||
|
||||
if ( !w.spawnEntityInWorld( result ) )
|
||||
{
|
||||
result.setDead();
|
||||
worked = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
worked = false;
|
||||
}
|
||||
}
|
||||
|
||||
blocked = !w.getBlock( x, y, z ).isReplaceable( w, x, y, z );
|
||||
|
||||
if ( worked )
|
||||
{
|
||||
IAEItemStack out = input.copy();
|
||||
out.decStackSize( maxStorage );
|
||||
if ( out.getStackSize() == 0 )
|
||||
return null;
|
||||
return out;
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveChanges(IMEInventory cellInventory)
|
||||
{
|
||||
// nope!
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Vec3;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.energy.IEnergySource;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.MachineSource;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.IInventoryDestination;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartImportBus extends PartSharedItemBus implements IGridTickable, IInventoryDestination
|
||||
{
|
||||
|
||||
BaseActionSource mySrc;
|
||||
IMEInventory<IAEItemStack> destination = null;
|
||||
IAEItemStack lastItemChecked = null;
|
||||
|
||||
public PartImportBus(ItemStack is) {
|
||||
super( PartImportBus.class, is );
|
||||
settings.registerSetting( Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
|
||||
settings.registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
|
||||
mySrc = new MachineSource( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
if ( !player.isSneaking() )
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return true;
|
||||
|
||||
Platform.openGUI( player, getHost().getTile(), side, GuiBridge.GUI_BUS );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert(ItemStack stack)
|
||||
{
|
||||
if ( stack == null || stack.getItem() == null )
|
||||
return false;
|
||||
|
||||
IAEItemStack out = destination.injectItems( lastItemChecked = AEApi.instance().storage().createItemStack( stack ), Actionable.SIMULATE, mySrc );
|
||||
if ( out == null )
|
||||
return true;
|
||||
return out.getStackSize() != stack.stackSize;
|
||||
}
|
||||
|
||||
private IInventoryDestination configDest(IMEMonitor<IAEItemStack> itemInventory)
|
||||
{
|
||||
destination = itemInventory;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
rh.setTexture( CableBusTextures.PartImportSides.getIcon(), CableBusTextures.PartImportSides.getIcon(), CableBusTextures.PartMonitorBack.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartImportSides.getIcon(), CableBusTextures.PartImportSides.getIcon() );
|
||||
|
||||
rh.setBounds( 3, 3, 15, 13, 13, 16 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
rh.setBounds( 4, 4, 14, 12, 12, 15 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
rh.setBounds( 5, 5, 13, 11, 11, 14 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache );
|
||||
rh.setTexture( CableBusTextures.PartImportSides.getIcon(), CableBusTextures.PartImportSides.getIcon(), CableBusTextures.PartMonitorBack.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartImportSides.getIcon(), CableBusTextures.PartImportSides.getIcon() );
|
||||
|
||||
rh.setBounds( 4, 4, 14, 12, 12, 16 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setBounds( 5, 5, 13, 11, 11, 14 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setBounds( 6, 6, 12, 10, 10, 13 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
rh.setTexture( CableBusTextures.PartMonitorSidesStatus.getIcon(), CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorBack.getIcon(), is.getIconIndex(), CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon() );
|
||||
|
||||
rh.setBounds( 6, 6, 11, 10, 10, 12 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
renderLights( x, y, z, rh, renderer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(IPartCollisionHelper bch)
|
||||
{
|
||||
bch.addBox( 6, 6, 11, 10, 10, 13 );
|
||||
bch.addBox( 5, 5, 13, 11, 11, 14 );
|
||||
bch.addBox( 4, 4, 14, 12, 12, 16 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cableConnectionRenderTo()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
return new TickingRequest( TickRates.ImportBus.min, TickRates.ImportBus.max, getHandler() == null, false );
|
||||
}
|
||||
|
||||
private int itemToSend; // used in tickingRequest
|
||||
private boolean worked; // used in tickingRequest
|
||||
|
||||
TickRateModulation doBusWork()
|
||||
{
|
||||
if ( !proxy.isActive() )
|
||||
return TickRateModulation.IDLE;
|
||||
|
||||
worked = false;
|
||||
|
||||
InventoryAdaptor myAdaptor = getHandler();
|
||||
FuzzyMode fzMode = (FuzzyMode) getConfigManager().getSetting( Settings.FUZZY_MODE );
|
||||
|
||||
if ( myAdaptor != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (getInstalledUpgrades( Upgrades.SPEED ))
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
itemToSend = 1;
|
||||
break;
|
||||
case 1:
|
||||
itemToSend = 8;
|
||||
break;
|
||||
case 2:
|
||||
itemToSend = 32;
|
||||
break;
|
||||
case 3:
|
||||
itemToSend = 64;
|
||||
break;
|
||||
case 4:
|
||||
itemToSend = 96;
|
||||
break;
|
||||
}
|
||||
|
||||
itemToSend = Math.min( itemToSend, (int) (0.01 + proxy.getEnergy().extractAEPower( itemToSend, Actionable.SIMULATE, PowerMultiplier.CONFIG )) );
|
||||
IMEMonitor<IAEItemStack> inv = proxy.getStorage().getItemInventory();
|
||||
IEnergyGrid energy = proxy.getEnergy();
|
||||
|
||||
boolean Configured = false;
|
||||
for (int x = 0; x < availableSlots(); x++)
|
||||
{
|
||||
IAEItemStack ais = config.getAEStackInSlot( x );
|
||||
if ( ais != null && itemToSend > 0 )
|
||||
{
|
||||
Configured = true;
|
||||
while (itemToSend > 0)
|
||||
{
|
||||
if ( importStuff( myAdaptor, ais, inv, energy, fzMode ) )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !Configured )
|
||||
{
|
||||
while (itemToSend > 0)
|
||||
{
|
||||
if ( importStuff( myAdaptor, null, inv, energy, fzMode ) )
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :3
|
||||
}
|
||||
}
|
||||
else
|
||||
return TickRateModulation.SLEEP;
|
||||
|
||||
return worked ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
{
|
||||
return doBusWork();
|
||||
}
|
||||
|
||||
private boolean importStuff(InventoryAdaptor myAdaptor, IAEItemStack whatToImport, IMEMonitor<IAEItemStack> inv, IEnergySource energy, FuzzyMode fzMode)
|
||||
{
|
||||
int toSend = this.itemToSend;
|
||||
|
||||
if ( toSend > 64 )
|
||||
toSend = 64;
|
||||
|
||||
ItemStack newItems;
|
||||
if ( getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
newItems = myAdaptor.removeSimilarItems( toSend, whatToImport == null ? null : whatToImport.getItemStack(), fzMode, configDest( inv ) );
|
||||
else
|
||||
newItems = myAdaptor.removeItems( toSend, whatToImport == null ? null : whatToImport.getItemStack(), configDest( inv ) );
|
||||
|
||||
if ( newItems != null )
|
||||
{
|
||||
newItems.stackSize = (int) (Math.min( newItems.stackSize, energy.extractAEPower( newItems.stackSize, Actionable.SIMULATE, PowerMultiplier.CONFIG ) ) + 0.01);
|
||||
itemToSend -= newItems.stackSize;
|
||||
|
||||
if ( lastItemChecked == null || !lastItemChecked.isSameType( newItems ) )
|
||||
lastItemChecked = AEApi.instance().storage().createItemStack( newItems );
|
||||
else
|
||||
lastItemChecked.setStackSize( newItems.stackSize );
|
||||
|
||||
IAEItemStack failed = Platform.poweredInsert( energy, destination, lastItemChecked, mySrc );
|
||||
// destination.injectItems( lastItemChecked, Actionable.MODULATE );
|
||||
if ( failed != null )
|
||||
{
|
||||
myAdaptor.addItems( failed.getItemStack() );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
worked = true;
|
||||
}
|
||||
else
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public RedstoneMode getRSMode()
|
||||
{
|
||||
return (RedstoneMode) settings.getSetting( Settings.REDSTONE_CONTROLLED );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSleeping()
|
||||
{
|
||||
return getHandler() == null || super.isSleeping();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,687 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.config.LevelType;
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.config.YesNo;
|
||||
import appeng.api.networking.crafting.ICraftingGrid;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.networking.crafting.ICraftingProvider;
|
||||
import appeng.api.networking.crafting.ICraftingProviderHelper;
|
||||
import appeng.api.networking.crafting.ICraftingWatcher;
|
||||
import appeng.api.networking.crafting.ICraftingWatcherHost;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.energy.IEnergyWatcher;
|
||||
import appeng.api.networking.energy.IEnergyWatcherHost;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkCraftingPatternChange;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.storage.IBaseMonitor;
|
||||
import appeng.api.networking.storage.IStackWatcher;
|
||||
import appeng.api.networking.storage.IStackWatcherHost;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IMEMonitorHandlerReceiver;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherHost, IStackWatcherHost, ICraftingWatcherHost,
|
||||
IMEMonitorHandlerReceiver<IAEItemStack>, ICraftingProvider
|
||||
{
|
||||
|
||||
final int FLAG_ON = 4;
|
||||
|
||||
AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 1 );
|
||||
|
||||
boolean prevState = false;
|
||||
|
||||
long lastReportedValue = 0;
|
||||
long reportingValue = 0;
|
||||
|
||||
IStackWatcher myWatcher;
|
||||
IEnergyWatcher myEnergyWatcher;
|
||||
ICraftingWatcher myCraftingWatcher;
|
||||
|
||||
public long getReportingValue()
|
||||
{
|
||||
return reportingValue;
|
||||
}
|
||||
|
||||
public void setReportingValue(long v)
|
||||
{
|
||||
reportingValue = v;
|
||||
if ( getConfigManager().getSetting( Settings.LEVEL_TYPE ) == LevelType.ENERGY_LEVEL )
|
||||
configureWatchers();
|
||||
else
|
||||
updateState();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerChanged(MENetworkPowerStatusChange c)
|
||||
{
|
||||
updateState();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void channelChanged(MENetworkChannelsChanged c)
|
||||
{
|
||||
updateState();
|
||||
}
|
||||
|
||||
public void upgradesChanged()
|
||||
{
|
||||
configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue)
|
||||
{
|
||||
configureWatchers();
|
||||
}
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
if ( proxy.isActive() )
|
||||
{
|
||||
boolean isOn = isLevelEmitterOn();
|
||||
if ( prevState != isOn )
|
||||
{
|
||||
host.markForUpdate();
|
||||
TileEntity te = host.getTile();
|
||||
prevState = isOn;
|
||||
Platform.notifyBlocksOfNeighbors( te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord );
|
||||
Platform.notifyBlocksOfNeighbors( te.getWorldObj(), te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
data.setLong( "lastReportedValue", lastReportedValue );
|
||||
data.setLong( "reportingValue", reportingValue );
|
||||
data.setBoolean( "prevState", prevState );
|
||||
config.writeToNBT( data, "config" );
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
lastReportedValue = data.getLong( "lastReportedValue" );
|
||||
reportingValue = data.getLong( "reportingValue" );
|
||||
prevState = data.getBoolean( "prevState" );
|
||||
config.readFromNBT( data, "config" );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int populateFlags(int cf)
|
||||
{
|
||||
return cf | (prevState ? FLAG_ON : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatcher(ICraftingWatcher newWatcher)
|
||||
{
|
||||
myCraftingWatcher = newWatcher;
|
||||
configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatcher(IStackWatcher newWatcher)
|
||||
{
|
||||
myWatcher = newWatcher;
|
||||
configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatcher(IEnergyWatcher newWatcher)
|
||||
{
|
||||
myEnergyWatcher = newWatcher;
|
||||
configureWatchers();
|
||||
}
|
||||
|
||||
// update the system...
|
||||
public void configureWatchers()
|
||||
{
|
||||
IAEItemStack myStack = config.getAEStackInSlot( 0 );
|
||||
|
||||
if ( myWatcher != null )
|
||||
myWatcher.clear();
|
||||
|
||||
if ( myEnergyWatcher != null )
|
||||
myEnergyWatcher.clear();
|
||||
|
||||
if ( myCraftingWatcher != null )
|
||||
myCraftingWatcher.clear();
|
||||
|
||||
try
|
||||
{
|
||||
proxy.getGrid().postEvent( new MENetworkCraftingPatternChange( this, proxy.getNode() ) );
|
||||
}
|
||||
catch (GridAccessException e1)
|
||||
{
|
||||
// :/
|
||||
}
|
||||
|
||||
if ( getInstalledUpgrades( Upgrades.CRAFTING ) > 0 )
|
||||
{
|
||||
if ( myCraftingWatcher != null && myStack != null )
|
||||
myCraftingWatcher.add( myStack );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( getConfigManager().getSetting( Settings.LEVEL_TYPE ) == LevelType.ENERGY_LEVEL )
|
||||
{
|
||||
if ( myEnergyWatcher != null )
|
||||
myEnergyWatcher.add( (double) reportingValue );
|
||||
|
||||
try
|
||||
{
|
||||
// update to power...
|
||||
lastReportedValue = (long) proxy.getEnergy().getStoredPower();
|
||||
updateState();
|
||||
|
||||
// no more item stuff..
|
||||
proxy.getStorage().getItemInventory().removeListener( this );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if ( getInstalledUpgrades( Upgrades.FUZZY ) > 0 || myStack == null )
|
||||
{
|
||||
proxy.getStorage().getItemInventory().addListener( this, proxy.getGrid() );
|
||||
}
|
||||
else
|
||||
{
|
||||
proxy.getStorage().getItemInventory().removeListener( this );
|
||||
|
||||
if ( myWatcher != null )
|
||||
myWatcher.add( myStack );
|
||||
}
|
||||
|
||||
updateReportingValue( proxy.getStorage().getItemInventory() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// >.>
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
|
||||
{
|
||||
if ( inv == config )
|
||||
configureWatchers();
|
||||
|
||||
super.onChangeInventory( inv, slot, mc, removedStack, newStack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postChange(IBaseMonitor<IAEItemStack> monitor, Iterable<IAEItemStack> change, BaseActionSource actionSource)
|
||||
{
|
||||
updateReportingValue( (IMEMonitor<IAEItemStack>) monitor );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
if ( !player.isSneaking() )
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return true;
|
||||
|
||||
Platform.openGUI( player, getHost().getTile(), side, GuiBridge.GUI_LEVELEMITTER );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void updateReportingValue(IMEMonitor<IAEItemStack> monitor)
|
||||
{
|
||||
IAEItemStack myStack = config.getAEStackInSlot( 0 );
|
||||
|
||||
if ( myStack == null )
|
||||
{
|
||||
lastReportedValue = 0;
|
||||
for (IAEItemStack st : monitor.getStorageList())
|
||||
lastReportedValue += st.getStackSize();
|
||||
}
|
||||
else if ( getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
{
|
||||
lastReportedValue = 0;
|
||||
FuzzyMode fzMode = (FuzzyMode) getConfigManager().getSetting( Settings.FUZZY_MODE );
|
||||
Collection<IAEItemStack> fuzzyList = monitor.getStorageList().findFuzzy( myStack, fzMode );
|
||||
for (IAEItemStack st : fuzzyList)
|
||||
lastReportedValue += st.getStackSize();
|
||||
}
|
||||
else
|
||||
{
|
||||
IAEItemStack r = monitor.getStorageList().findPrecise( myStack );
|
||||
if ( r == null )
|
||||
lastReportedValue = 0;
|
||||
else
|
||||
lastReportedValue = r.getStackSize();
|
||||
}
|
||||
|
||||
updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(Object effectiveGrid)
|
||||
{
|
||||
try
|
||||
{
|
||||
return proxy.getGrid() == effectiveGrid;
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestChange(ICraftingGrid craftingGrid, IAEItemStack what)
|
||||
{
|
||||
updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onThresholdPass(IEnergyGrid energyGrid)
|
||||
{
|
||||
lastReportedValue = (long) energyGrid.getStoredPower();
|
||||
updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStackChange(IItemList o, IAEStack fullStack, IAEStack diffStack, BaseActionSource src, StorageChannel chan)
|
||||
{
|
||||
if ( chan == StorageChannel.ITEMS && fullStack.equals( config.getAEStackInSlot( 0 ) ) && getInstalledUpgrades( Upgrades.FUZZY ) == 0 )
|
||||
{
|
||||
lastReportedValue = fullStack.getStackSize();
|
||||
updateState();
|
||||
}
|
||||
}
|
||||
|
||||
public PartLevelEmitter(ItemStack is) {
|
||||
super( PartLevelEmitter.class, is );
|
||||
getConfigManager().registerSetting( Settings.REDSTONE_EMITTER, RedstoneMode.HIGH_SIGNAL );
|
||||
getConfigManager().registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
|
||||
getConfigManager().registerSetting( Settings.LEVEL_TYPE, LevelType.ITEM_LEVEL );
|
||||
getConfigManager().registerSetting( Settings.CRAFT_VIA_REDSTONE, YesNo.NO );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
rh.setTexture( is.getIconIndex() );
|
||||
Tessellator.instance.startDrawingQuads();
|
||||
renderTorchAtAngle( 0, -0.5, 0 );
|
||||
Tessellator.instance.draw();
|
||||
// rh.setBounds( 7, 7, 10, 9, 9, 15 );
|
||||
// rh.renderInventoryBox( renderer );
|
||||
}
|
||||
|
||||
double cenx;
|
||||
double ceny;
|
||||
double cenz;
|
||||
|
||||
public void addVertexWithUV(double x, double y, double z, double u, double v)
|
||||
{
|
||||
Tessellator var12 = Tessellator.instance;
|
||||
|
||||
x -= cenx;
|
||||
y -= ceny;
|
||||
z -= cenz;
|
||||
|
||||
if ( side == ForgeDirection.DOWN )
|
||||
{
|
||||
y = -y;
|
||||
z = -z;
|
||||
}
|
||||
|
||||
if ( side == ForgeDirection.EAST )
|
||||
{
|
||||
double m = x;
|
||||
x = y;
|
||||
y = m;
|
||||
y = -y;
|
||||
}
|
||||
|
||||
if ( side == ForgeDirection.WEST )
|
||||
{
|
||||
double m = x;
|
||||
x = -y;
|
||||
y = m;
|
||||
}
|
||||
|
||||
if ( side == ForgeDirection.SOUTH )
|
||||
{
|
||||
double m = z;
|
||||
z = y;
|
||||
y = m;
|
||||
y = -y;
|
||||
}
|
||||
|
||||
if ( side == ForgeDirection.NORTH )
|
||||
{
|
||||
double m = z;
|
||||
z = -y;
|
||||
y = m;
|
||||
}
|
||||
|
||||
x += cenx;// + orientation.offsetX * 0.4;
|
||||
y += ceny;// + orientation.offsetY * 0.4;
|
||||
z += cenz;// + orientation.offsetZ * 0.4;
|
||||
|
||||
var12.addVertexWithUV( x, y, z, u, v );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomDisplayTick(World world, int x, int y, int z, Random r)
|
||||
{
|
||||
if ( isLevelEmitterOn() )
|
||||
{
|
||||
ForgeDirection d = side;
|
||||
|
||||
double d0 = (double) ((float) d.offsetX * 0.45F) + (double) (r.nextFloat() - 0.5F) * 0.2D;
|
||||
double d1 = (double) ((float) d.offsetY * 0.45F) + (double) (r.nextFloat() - 0.5F) * 0.2D;
|
||||
double d2 = (double) ((float) d.offsetZ * 0.45F) + (double) (r.nextFloat() - 0.5F) * 0.2D;
|
||||
|
||||
world.spawnParticle( "reddust", 0.5 + x + d0, 0.5 + y + d1, 0.5 + z + d2, 0.0D, 0.0D, 0.0D );
|
||||
}
|
||||
}
|
||||
|
||||
public void renderTorchAtAngle(double baseX, double baseY, double baseZ)
|
||||
{
|
||||
boolean isOn = isLevelEmitterOn();
|
||||
IIcon offTexture = is.getIconIndex();
|
||||
IIcon IIcon = (isOn ? CableBusTextures.LevelEmitterTorchOn.getIcon() : offTexture);
|
||||
//
|
||||
cenx = baseX + 0.5;
|
||||
ceny = baseY + 0.5;
|
||||
cenz = baseZ + 0.5;
|
||||
|
||||
baseY += 7.0 / 16.0;
|
||||
;
|
||||
double par10 = 0;
|
||||
// double par11 = 0;
|
||||
double Zero = 0;
|
||||
|
||||
/*
|
||||
* double d5 = (double)IIcon.func_94209_e(); double d6 = (double)IIcon.func_94206_g(); double d7 =
|
||||
* (double)IIcon.func_94212_f(); double d8 = (double)IIcon.func_94210_h(); double d9 =
|
||||
* (double)IIcon.func_94214_a(7.0D); double d10 = (double)IIcon.func_94207_b(6.0D); double d11 =
|
||||
* (double)IIcon.func_94214_a(9.0D); double d12 = (double)IIcon.func_94207_b(8.0D); double d13 =
|
||||
* (double)IIcon.func_94214_a(7.0D); double d14 = (double)IIcon.func_94207_b(13.0D); double d15 =
|
||||
* (double)IIcon.func_94214_a(9.0D); double d16 = (double)IIcon.func_94207_b(15.0D);
|
||||
*/
|
||||
|
||||
float var16 = IIcon.getMinU();
|
||||
float var17 = IIcon.getMaxU();
|
||||
float var18 = IIcon.getMinV();
|
||||
float var19 = IIcon.getMaxV();
|
||||
/*
|
||||
* float var16 = (float)var14 / 256.0F; float var17 = ((float)var14 + 15.99F) / 256.0F; float var18 =
|
||||
* (float)var15 / 256.0F; float var19 = ((float)var15 + 15.99F) / 256.0F;
|
||||
*/
|
||||
double var20b = (double) offTexture.getInterpolatedU( 7.0D );
|
||||
double var24b = (double) offTexture.getInterpolatedU( 9.0D );
|
||||
|
||||
double var20 = (double) IIcon.getInterpolatedU( 7.0D );
|
||||
double var24 = (double) IIcon.getInterpolatedU( 9.0D );
|
||||
double var22 = (double) IIcon.getInterpolatedV( 6.0D + (isOn ? 0 : 1.0D) );
|
||||
double var26 = (double) IIcon.getInterpolatedV( 8.0D + (isOn ? 0 : 1.0D) );
|
||||
double var28 = (double) IIcon.getInterpolatedU( 7.0D );
|
||||
double var30 = (double) IIcon.getInterpolatedV( 13.0D );
|
||||
double var32 = (double) IIcon.getInterpolatedU( 9.0D );
|
||||
double var34 = (double) IIcon.getInterpolatedV( 15.0D );
|
||||
|
||||
double var22b = (double) IIcon.getInterpolatedV( 9.0D );
|
||||
double var26b = (double) IIcon.getInterpolatedV( 11.0D );
|
||||
|
||||
baseX += 0.5D;
|
||||
baseZ += 0.5D;
|
||||
double var36 = baseX - 0.5D;
|
||||
double var38 = baseX + 0.5D;
|
||||
double var40 = baseZ - 0.5D;
|
||||
double var42 = baseZ + 0.5D;
|
||||
double var44 = 0.0625D;
|
||||
double var422 = 0.1915D + 1.0 / 16.0;
|
||||
double TorchLen = 0.625D;
|
||||
|
||||
double toff = 0.0d;
|
||||
|
||||
if ( !isOn )
|
||||
{
|
||||
toff = 1.0d / 16.0d;
|
||||
}
|
||||
|
||||
Tessellator var12 = Tessellator.instance;
|
||||
if ( isOn )
|
||||
{
|
||||
var12.setColorOpaque_F( 1.0F, 1.0F, 1.0F );
|
||||
var12.setBrightness( 11 << 20 | 11 << 4 );
|
||||
}
|
||||
|
||||
this.addVertexWithUV( baseX + Zero * (1.0D - TorchLen) - var44, baseY + TorchLen - toff, baseZ + par10 * (1.0D - TorchLen) - var44, var20, var22 );
|
||||
this.addVertexWithUV( baseX + Zero * (1.0D - TorchLen) - var44, baseY + TorchLen - toff, baseZ + par10 * (1.0D - TorchLen) + var44, var20, var26 );
|
||||
this.addVertexWithUV( baseX + Zero * (1.0D - TorchLen) + var44, baseY + TorchLen - toff, baseZ + par10 * (1.0D - TorchLen) + var44, var24, var26 );
|
||||
this.addVertexWithUV( baseX + Zero * (1.0D - TorchLen) + var44, baseY + TorchLen - toff, baseZ + par10 * (1.0D - TorchLen) - var44, var24, var22 );
|
||||
|
||||
this.addVertexWithUV( baseX + Zero * (1.0D - TorchLen) + var44, baseY + var422, baseZ + par10 * (1.0D - TorchLen) - var44, var24b, var22b );
|
||||
this.addVertexWithUV( baseX + Zero * (1.0D - TorchLen) + var44, baseY + var422, baseZ + par10 * (1.0D - TorchLen) + var44, var24b, var26b );
|
||||
this.addVertexWithUV( baseX + Zero * (1.0D - TorchLen) - var44, baseY + var422, baseZ + par10 * (1.0D - TorchLen) + var44, var20b, var26b );
|
||||
this.addVertexWithUV( baseX + Zero * (1.0D - TorchLen) - var44, baseY + var422, baseZ + par10 * (1.0D - TorchLen) - var44, var20b, var22b );
|
||||
|
||||
this.addVertexWithUV( baseX + var44 + Zero, baseY, baseZ - var44 + par10, var32, var30 );
|
||||
this.addVertexWithUV( baseX + var44 + Zero, baseY, baseZ + var44 + par10, var32, var34 );
|
||||
this.addVertexWithUV( baseX - var44 + Zero, baseY, baseZ + var44 + par10, var28, var34 );
|
||||
this.addVertexWithUV( baseX - var44 + Zero, baseY, baseZ - var44 + par10, var28, var30 );
|
||||
|
||||
this.addVertexWithUV( baseX - var44, baseY + 1.0D, var40, (double) var16, (double) var18 );
|
||||
this.addVertexWithUV( baseX - var44 + Zero, baseY + 0.0D, var40 + par10, (double) var16, (double) var19 );
|
||||
this.addVertexWithUV( baseX - var44 + Zero, baseY + 0.0D, var42 + par10, (double) var17, (double) var19 );
|
||||
this.addVertexWithUV( baseX - var44, baseY + 1.0D, var42, (double) var17, (double) var18 );
|
||||
|
||||
this.addVertexWithUV( baseX + var44, baseY + 1.0D, var42, (double) var16, (double) var18 );
|
||||
this.addVertexWithUV( baseX + Zero + var44, baseY + 0.0D, var42 + par10, (double) var16, (double) var19 );
|
||||
this.addVertexWithUV( baseX + Zero + var44, baseY + 0.0D, var40 + par10, (double) var17, (double) var19 );
|
||||
this.addVertexWithUV( baseX + var44, baseY + 1.0D, var40, (double) var17, (double) var18 );
|
||||
|
||||
this.addVertexWithUV( var36, baseY + 1.0D, baseZ + var44, (double) var16, (double) var18 );
|
||||
this.addVertexWithUV( var36 + Zero, baseY + 0.0D, baseZ + var44 + par10, (double) var16, (double) var19 );
|
||||
this.addVertexWithUV( var38 + Zero, baseY + 0.0D, baseZ + var44 + par10, (double) var17, (double) var19 );
|
||||
this.addVertexWithUV( var38, baseY + 1.0D, baseZ + var44, (double) var17, (double) var18 );
|
||||
|
||||
this.addVertexWithUV( var38, baseY + 1.0D, baseZ - var44, (double) var16, (double) var18 );
|
||||
this.addVertexWithUV( var38 + Zero, baseY + 0.0D, baseZ - var44 + par10, (double) var16, (double) var19 );
|
||||
this.addVertexWithUV( var36 + Zero, baseY + 0.0D, baseZ - var44 + par10, (double) var17, (double) var19 );
|
||||
this.addVertexWithUV( var36, baseY + 1.0D, baseZ - var44, (double) var17, (double) var18 );
|
||||
}
|
||||
|
||||
boolean status = false;;
|
||||
|
||||
private boolean isLevelEmitterOn()
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return (clientFlags & FLAG_ON) == FLAG_ON;
|
||||
|
||||
if ( getInstalledUpgrades( Upgrades.CRAFTING ) > 0 )
|
||||
{
|
||||
try
|
||||
{
|
||||
return proxy.getCrafting().isRequesting( config.getAEStackInSlot( 0 ) );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
return prevState;
|
||||
}
|
||||
|
||||
boolean flipState = getConfigManager().getSetting( Settings.REDSTONE_EMITTER ) == RedstoneMode.LOW_SIGNAL;
|
||||
return flipState ? reportingValue >= lastReportedValue + 1 : reportingValue < lastReportedValue + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
rh.setTexture( is.getIconIndex() );
|
||||
// rh.setTexture( CableBusTextures.ItemPartLevelEmitterOn.getIcon() );
|
||||
|
||||
// rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
// rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
// rh.setBounds( 7, 7, 10, 9, 9, 15 );
|
||||
// rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
renderer.renderAllFaces = true;
|
||||
|
||||
Tessellator tess = Tessellator.instance;
|
||||
tess.setBrightness( rh.getBlock().getMixedBrightnessForBlock( this.getHost().getTile().getWorldObj(), x, y, z ) );
|
||||
tess.setColorOpaque_F( 1.0F, 1.0F, 1.0F );
|
||||
|
||||
renderTorchAtAngle( x, y, z );
|
||||
|
||||
renderer.renderAllFaces = false;
|
||||
|
||||
rh.setBounds( 7, 7, 11, 9, 9, 12 );
|
||||
renderLights( x, y, z, rh, renderer );
|
||||
|
||||
// super.renderWorldBlock( world, x, y, z, block, modelId, renderer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getBreakingTexture()
|
||||
{
|
||||
return is.getIconIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(IPartCollisionHelper bch)
|
||||
{
|
||||
bch.addBox( 7, 7, 11, 9, 9, 16 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType(ForgeDirection dir)
|
||||
{
|
||||
return AECableType.SMART;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cableConnectionRenderTo()
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower()
|
||||
{
|
||||
return prevState ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower()
|
||||
{
|
||||
return prevState ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(String name)
|
||||
{
|
||||
if ( name.equals( "config" ) )
|
||||
return config;
|
||||
|
||||
return super.getInventoryByName( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListUpdate()
|
||||
{
|
||||
try
|
||||
{
|
||||
updateReportingValue( proxy.getStorage().getItemInventory() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// ;P
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBusy()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provideCrafting(ICraftingProviderHelper craftingTracker)
|
||||
{
|
||||
if ( getInstalledUpgrades( Upgrades.CRAFTING ) > 0 )
|
||||
{
|
||||
if ( settings.getSetting( Settings.CRAFT_VIA_REDSTONE ) == YesNo.YES )
|
||||
{
|
||||
IAEItemStack what = config.getAEStackInSlot( 0 );
|
||||
if ( what != null )
|
||||
craftingTracker.setEmitable( what );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public abstract class PartSharedItemBus extends PartUpgradeable implements IGridTickable
|
||||
{
|
||||
|
||||
private TileEntity getTileEntity(TileEntity self, int x, int y, int z)
|
||||
{
|
||||
World w = self.getWorldObj();
|
||||
|
||||
if ( w.getChunkProvider().chunkExists( x >> 4, z >> 4 ) )
|
||||
{
|
||||
TileEntity te = w.getTileEntity( x, y, z );
|
||||
return te;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public PartSharedItemBus(Class c, ItemStack is) {
|
||||
super( c, is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upgradesChanged()
|
||||
{
|
||||
updateState();
|
||||
}
|
||||
|
||||
protected int availableSlots()
|
||||
{
|
||||
return Math.min( 1 + getInstalledUpgrades( Upgrades.CAPACITY ) * 4, config.getSizeInventory() );
|
||||
}
|
||||
|
||||
public void writeToNBT(net.minecraft.nbt.NBTTagCompound extra)
|
||||
{
|
||||
super.writeToNBT( extra );
|
||||
config.writeToNBT( extra, "config" );
|
||||
}
|
||||
|
||||
public void readFromNBT(net.minecraft.nbt.NBTTagCompound extra)
|
||||
{
|
||||
super.readFromNBT( extra );
|
||||
config.readFromNBT( extra, "config" );
|
||||
}
|
||||
|
||||
AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 9 );
|
||||
|
||||
int adaptorHash = 0;
|
||||
InventoryAdaptor adaptor;
|
||||
|
||||
InventoryAdaptor getHandler()
|
||||
{
|
||||
TileEntity self = getHost().getTile();
|
||||
TileEntity target = getTileEntity( self, self.xCoord + side.offsetX, self.yCoord + side.offsetY, self.zCoord + side.offsetZ );
|
||||
|
||||
int newAdaptorHash = Platform.generateTileHash( target );
|
||||
|
||||
if ( adaptorHash == newAdaptorHash && newAdaptorHash != 0 )
|
||||
return adaptor;
|
||||
|
||||
adaptorHash = newAdaptorHash;
|
||||
adaptor = InventoryAdaptor.getAdaptor( target, side.getOpposite() );
|
||||
|
||||
return adaptor;
|
||||
}
|
||||
|
||||
boolean lastRedstone = false;
|
||||
|
||||
abstract TickRateModulation doBusWork();
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
updateState();
|
||||
if ( lastRedstone != host.hasRedstone( side ) )
|
||||
{
|
||||
lastRedstone = !lastRedstone;
|
||||
if ( lastRedstone && getRSMode() == RedstoneMode.SIGNAL_PULSE )
|
||||
doBusWork();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( !isSleeping() )
|
||||
proxy.getTick().wakeDevice( proxy.getNode() );
|
||||
else
|
||||
proxy.getTick().sleepDevice( proxy.getNode() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(String name)
|
||||
{
|
||||
if ( name.equals( "config" ) )
|
||||
return config;
|
||||
|
||||
return super.getInventoryByName( name );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.implementations.tiles.ISegmentedInventory;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.parts.PartBasicState;
|
||||
import appeng.tile.inventory.IAEAppEngInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.ConfigManager;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
|
||||
public class PartUpgradeable extends PartBasicState implements ISegmentedInventory, IAEAppEngInventory, IConfigManagerHost
|
||||
{
|
||||
|
||||
IConfigManager settings = new ConfigManager( this );
|
||||
private UpgradeInventory upgrades = new UpgradeInventory( is, this, getUpgradeSlots() );
|
||||
|
||||
@Override
|
||||
public int getInstalledUpgrades(Upgrades u)
|
||||
{
|
||||
return upgrades.getInstalledUpgrades( u );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone()
|
||||
{
|
||||
return upgrades.getMaxInstalled( Upgrades.REDSTONE ) > 0;
|
||||
}
|
||||
|
||||
protected int getUpgradeSlots()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(List<ItemStack> drops, boolean wrenched)
|
||||
{
|
||||
for (ItemStack is : upgrades)
|
||||
if ( is != null )
|
||||
drops.add( is );
|
||||
}
|
||||
|
||||
public void writeToNBT(net.minecraft.nbt.NBTTagCompound extra)
|
||||
{
|
||||
super.writeToNBT( extra );
|
||||
settings.writeToNBT( extra );
|
||||
upgrades.writeToNBT( extra, "upgrades" );
|
||||
}
|
||||
|
||||
public void readFromNBT(net.minecraft.nbt.NBTTagCompound extra)
|
||||
{
|
||||
super.readFromNBT( extra );
|
||||
settings.readFromNBT( extra );
|
||||
upgrades.readFromNBT( extra, "upgrades" );
|
||||
}
|
||||
|
||||
public PartUpgradeable(Class c, ItemStack is) {
|
||||
super( c, is );
|
||||
upgrades.setMaxStackSize( 1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(String name)
|
||||
{
|
||||
if ( name.equals( "upgrades" ) )
|
||||
return upgrades;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void upgradesChanged()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
|
||||
{
|
||||
if ( inv == upgrades )
|
||||
{
|
||||
upgradesChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public RedstoneMode getRSMode()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
protected boolean isSleeping()
|
||||
{
|
||||
if ( getInstalledUpgrades( Upgrades.REDSTONE ) > 0 )
|
||||
{
|
||||
switch (getRSMode())
|
||||
{
|
||||
case IGNORE:
|
||||
return false;
|
||||
|
||||
case HIGH_SIGNAL:
|
||||
if ( host.hasRedstone( side ) )
|
||||
return false;
|
||||
|
||||
break;
|
||||
|
||||
case LOW_SIGNAL:
|
||||
if ( !host.hasRedstone( side ) )
|
||||
return false;
|
||||
|
||||
break;
|
||||
|
||||
case SIGNAL_PULSE:
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.implementations.items.IUpgradeModule;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.IAEAppEngInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class UpgradeInventory extends AppEngInternalInventory implements IAEAppEngInventory
|
||||
{
|
||||
|
||||
private final Object itemorblock;
|
||||
private final IAEAppEngInventory parent;
|
||||
|
||||
private boolean cached = false;
|
||||
private int FuzzyUpgrades = 0;
|
||||
private int SpeedUpgrades = 0;
|
||||
private int RedstoneUpgrades = 0;
|
||||
private int CapacityUpgrades = 0;
|
||||
private int InverterUpgrades = 0;
|
||||
private int CraftingUpgrades = 0;
|
||||
|
||||
public UpgradeInventory(Object itemOrBlock, IAEAppEngInventory _te, int s) {
|
||||
super( null, s );
|
||||
te = this;
|
||||
parent = _te;
|
||||
itemorblock = itemOrBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean eventsEnabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack newItemStack)
|
||||
{
|
||||
super.setInventorySlotContents( slot, newItemStack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
if ( itemstack == null )
|
||||
return false;
|
||||
Item it = itemstack.getItem();
|
||||
if ( it instanceof IUpgradeModule )
|
||||
{
|
||||
Upgrades u = ((IUpgradeModule) it).getType( itemstack );
|
||||
if ( u != null )
|
||||
{
|
||||
return getInstalledUpgrades( u ) < getMaxInstalled( u );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getMaxInstalled(Upgrades u)
|
||||
{
|
||||
Integer max = null;
|
||||
for (ItemStack is : u.getSupported().keySet())
|
||||
{
|
||||
if ( is.getItem() == itemorblock )
|
||||
{
|
||||
max = u.getSupported().get( is );
|
||||
break;
|
||||
}
|
||||
else if ( is.getItem() instanceof ItemBlock && Block.getBlockFromItem( is.getItem() ) == itemorblock )
|
||||
{
|
||||
max = u.getSupported().get( is );
|
||||
break;
|
||||
}
|
||||
else if ( itemorblock instanceof ItemStack && Platform.isSameItem( (ItemStack) itemorblock, is ) )
|
||||
{
|
||||
max = u.getSupported().get( is );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( max == null )
|
||||
return 0;
|
||||
return max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
private void updateUpgradeInfo()
|
||||
{
|
||||
cached = true;
|
||||
InverterUpgrades = CapacityUpgrades = RedstoneUpgrades = SpeedUpgrades = FuzzyUpgrades = CraftingUpgrades = 0;
|
||||
|
||||
for (ItemStack is : this)
|
||||
{
|
||||
if ( is == null || is.getItem() == null || !(is.getItem() instanceof IUpgradeModule) )
|
||||
continue;
|
||||
|
||||
Upgrades myUpgrade = ((IUpgradeModule) is.getItem()).getType( is );
|
||||
switch (myUpgrade)
|
||||
{
|
||||
case CAPACITY:
|
||||
CapacityUpgrades++;
|
||||
break;
|
||||
case FUZZY:
|
||||
FuzzyUpgrades++;
|
||||
break;
|
||||
case REDSTONE:
|
||||
RedstoneUpgrades++;
|
||||
break;
|
||||
case SPEED:
|
||||
SpeedUpgrades++;
|
||||
break;
|
||||
case INVERTER:
|
||||
InverterUpgrades++;
|
||||
break;
|
||||
case CRAFTING:
|
||||
CraftingUpgrades++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CapacityUpgrades = Math.min( CapacityUpgrades, getMaxInstalled( Upgrades.CAPACITY ) );
|
||||
FuzzyUpgrades = Math.min( FuzzyUpgrades, getMaxInstalled( Upgrades.FUZZY ) );
|
||||
RedstoneUpgrades = Math.min( RedstoneUpgrades, getMaxInstalled( Upgrades.REDSTONE ) );
|
||||
SpeedUpgrades = Math.min( SpeedUpgrades, getMaxInstalled( Upgrades.SPEED ) );
|
||||
InverterUpgrades = Math.min( InverterUpgrades, getMaxInstalled( Upgrades.INVERTER ) );
|
||||
CraftingUpgrades = Math.min( CraftingUpgrades, getMaxInstalled( Upgrades.CRAFTING ) );
|
||||
}
|
||||
|
||||
public int getInstalledUpgrades(Upgrades u)
|
||||
{
|
||||
if ( !cached )
|
||||
updateUpgradeInfo();
|
||||
|
||||
switch (u)
|
||||
{
|
||||
case CAPACITY:
|
||||
return CapacityUpgrades;
|
||||
case FUZZY:
|
||||
return FuzzyUpgrades;
|
||||
case REDSTONE:
|
||||
return RedstoneUpgrades;
|
||||
case SPEED:
|
||||
return SpeedUpgrades;
|
||||
case INVERTER:
|
||||
return InverterUpgrades;
|
||||
case CRAFTING:
|
||||
return CraftingUpgrades;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound target)
|
||||
{
|
||||
super.readFromNBT( target );
|
||||
updateUpgradeInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
|
||||
{
|
||||
cached = false;
|
||||
if ( parent != null && Platform.isServer() )
|
||||
parent.onChangeInventory( inv, slot, mc, removedStack, newStack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveChanges()
|
||||
{
|
||||
parent.saveChanges();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package appeng.parts.layers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class InvLayerData
|
||||
{
|
||||
|
||||
// a simple empty array for empty stuff..
|
||||
private final static int[] nullSides = new int[] {};
|
||||
|
||||
// cache of inventory state.
|
||||
final private int sides[][];
|
||||
final private List<ISidedInventory> invs;
|
||||
final private List<InvSot> slots;
|
||||
|
||||
public InvLayerData(int a[][], List<ISidedInventory> b, List<InvSot> c) {
|
||||
sides = a;
|
||||
invs = b;
|
||||
slots = c;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if a slot index is valid, prevent crashes from bad code :)
|
||||
*
|
||||
* @param slot
|
||||
* @return true, if the slot exists.
|
||||
*/
|
||||
boolean isSlotValid(int slot)
|
||||
{
|
||||
return slots != null && slot >= 0 && slot < slots.size();
|
||||
}
|
||||
|
||||
public ItemStack decrStackSize(int slot, int amount)
|
||||
{
|
||||
if ( isSlotValid( slot ) )
|
||||
return slots.get( slot ).decrStackSize( amount );
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getSizeInventory()
|
||||
{
|
||||
if ( slots == null )
|
||||
return 0;
|
||||
|
||||
return slots.size();
|
||||
}
|
||||
|
||||
public ItemStack getStackInSlot(int slot)
|
||||
{
|
||||
if ( isSlotValid( slot ) )
|
||||
return slots.get( slot ).getStackInSlot();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isItemValidForSlot(int slot, ItemStack itemstack)
|
||||
{
|
||||
if ( isSlotValid( slot ) )
|
||||
return slots.get( slot ).isItemValidForSlot( itemstack );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setInventorySlotContents(int slot, ItemStack itemstack)
|
||||
{
|
||||
if ( isSlotValid( slot ) )
|
||||
slots.get( slot ).setInventorySlotContents( itemstack );
|
||||
}
|
||||
|
||||
public boolean canExtractItem(int slot, ItemStack itemstack, int side)
|
||||
{
|
||||
if ( isSlotValid( slot ) )
|
||||
return slots.get( slot ).canExtractItem( itemstack, side );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canInsertItem(int slot, ItemStack itemstack, int side)
|
||||
{
|
||||
if ( isSlotValid( slot ) )
|
||||
return slots.get( slot ).canInsertItem( itemstack, side );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void markDirty()
|
||||
{
|
||||
if ( invs != null )
|
||||
{
|
||||
for (IInventory inv : invs)
|
||||
inv.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
public int[] getAccessibleSlotsFromSide(int side)
|
||||
{
|
||||
if ( sides == null || side < 0 || side > 5 )
|
||||
return nullSides;
|
||||
return sides[side];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package appeng.parts.layers;
|
||||
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class InvSot
|
||||
{
|
||||
|
||||
final public ISidedInventory partInv;
|
||||
final public int index;
|
||||
|
||||
public InvSot(ISidedInventory part, int slot) {
|
||||
partInv = part;
|
||||
index = slot;
|
||||
}
|
||||
|
||||
public ItemStack decrStackSize(int j)
|
||||
{
|
||||
return partInv.decrStackSize( index, j );
|
||||
}
|
||||
|
||||
public ItemStack getStackInSlot()
|
||||
{
|
||||
return partInv.getStackInSlot( index );
|
||||
}
|
||||
|
||||
public boolean isItemValidForSlot(ItemStack itemstack)
|
||||
{
|
||||
return partInv.isItemValidForSlot( index, itemstack );
|
||||
}
|
||||
|
||||
public void setInventorySlotContents(ItemStack itemstack)
|
||||
{
|
||||
partInv.setInventorySlotContents( index, itemstack );
|
||||
}
|
||||
|
||||
public boolean canExtractItem(ItemStack itemstack, int side)
|
||||
{
|
||||
return partInv.canExtractItem( index, itemstack, side );
|
||||
}
|
||||
|
||||
public boolean canInsertItem(ItemStack itemstack, int side)
|
||||
{
|
||||
return partInv.canInsertItem( index, itemstack, side );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package appeng.parts.layers;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.LayerBase;
|
||||
import buildcraft.api.mj.IBatteryObject;
|
||||
import buildcraft.api.mj.ISidedBatteryProvider;
|
||||
|
||||
public class LayerIBatteryProvider extends LayerBase implements ISidedBatteryProvider
|
||||
{
|
||||
|
||||
@Override
|
||||
public IBatteryObject getMjBattery(String kind, ForgeDirection direction)
|
||||
{
|
||||
IPart p = getPart( direction );
|
||||
|
||||
if ( p instanceof ISidedBatteryProvider )
|
||||
return ((ISidedBatteryProvider) p).getMjBattery( kind, direction );
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package appeng.parts.layers;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.LayerBase;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
|
||||
public class LayerIEnergyHandler extends LayerBase implements IEnergyHandler
|
||||
{
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
|
||||
{
|
||||
IPart part = getPart( from );
|
||||
if ( part instanceof IEnergyHandler )
|
||||
return ((IEnergyHandler) part).receiveEnergy( from, maxReceive, simulate );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate)
|
||||
{
|
||||
IPart part = getPart( from );
|
||||
if ( part instanceof IEnergyHandler )
|
||||
return ((IEnergyHandler) part).extractEnergy( from, maxExtract, simulate );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ForgeDirection from)
|
||||
{
|
||||
IPart part = getPart( from );
|
||||
if ( part instanceof IEnergyHandler )
|
||||
return ((IEnergyHandler) part).getEnergyStored( from );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from)
|
||||
{
|
||||
IPart part = getPart( from );
|
||||
if ( part instanceof IEnergyHandler )
|
||||
return ((IEnergyHandler) part).getMaxEnergyStored( from );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectEnergy(ForgeDirection from)
|
||||
{
|
||||
IPart part = getPart( from );
|
||||
if ( part instanceof IEnergyHandler )
|
||||
return ((IEnergyHandler) part).canConnectEnergy( from );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
package appeng.parts.layers;
|
||||
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
import ic2.api.energy.tile.IEnergyTile;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.LayerBase;
|
||||
import appeng.api.parts.LayerFlags;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class LayerIEnergySink extends LayerBase implements IEnergySink
|
||||
{
|
||||
|
||||
private boolean isInIC2()
|
||||
{
|
||||
return getLayerFlags().contains( LayerFlags.IC2_ENET );
|
||||
}
|
||||
|
||||
private TileEntity getEnergySinkTile()
|
||||
{
|
||||
IPartHost host = (IPartHost) this;
|
||||
return host.getTile();
|
||||
}
|
||||
|
||||
private World getEnergySinkWorld()
|
||||
{
|
||||
if ( getEnergySinkTile() == null )
|
||||
return null;
|
||||
|
||||
return getEnergySinkTile().getWorldObj();
|
||||
}
|
||||
|
||||
private boolean isTileValid()
|
||||
{
|
||||
TileEntity te = getEnergySinkTile();
|
||||
|
||||
if ( te == null )
|
||||
return false;
|
||||
|
||||
return !te.isInvalid() && te.getWorldObj().blockExists( te.xCoord, te.yCoord, te.zCoord );
|
||||
}
|
||||
|
||||
final private void addToENet()
|
||||
{
|
||||
if ( getEnergySinkWorld() == null )
|
||||
return;
|
||||
|
||||
// re-add
|
||||
removeFromENet();
|
||||
|
||||
if ( !isInIC2() && Platform.isServer() && isTileValid() )
|
||||
{
|
||||
getLayerFlags().add( LayerFlags.IC2_ENET );
|
||||
MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileLoadEvent( (IEnergySink) getEnergySinkTile() ) );
|
||||
}
|
||||
}
|
||||
|
||||
final private void removeFromENet()
|
||||
{
|
||||
if ( getEnergySinkWorld() == null )
|
||||
return;
|
||||
|
||||
if ( isInIC2() && Platform.isServer() )
|
||||
{
|
||||
getLayerFlags().remove( LayerFlags.IC2_ENET );
|
||||
MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileUnloadEvent( (IEnergySink) getEnergySinkTile() ) );
|
||||
}
|
||||
}
|
||||
|
||||
final private boolean interestedInIC2()
|
||||
{
|
||||
if ( !((IPartHost) this).isInWorld() )
|
||||
return false;
|
||||
|
||||
int interested = 0;
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
IPart part = getPart( dir );
|
||||
if ( part instanceof IEnergyTile )
|
||||
{
|
||||
interested++;
|
||||
}
|
||||
}
|
||||
return interested == 1;// if more then one tile is interested we need to abandonship...
|
||||
}
|
||||
|
||||
@Override
|
||||
public void partChanged()
|
||||
{
|
||||
super.partChanged();
|
||||
|
||||
if ( interestedInIC2() )
|
||||
addToENet();
|
||||
else
|
||||
removeFromENet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
{
|
||||
if ( !isInIC2() )
|
||||
return false;
|
||||
|
||||
IPart part = getPart( direction );
|
||||
if ( part instanceof IEnergySink )
|
||||
return ((IEnergySink) part).acceptsEnergyFrom( emitter, direction );
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDemandedEnergy()
|
||||
{
|
||||
if ( !isInIC2() )
|
||||
return 0;
|
||||
|
||||
// this is a flawed implementation, that requires a change to the IC2 API.
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
IPart part = getPart( dir );
|
||||
if ( part instanceof IEnergySink )
|
||||
{
|
||||
// use lower number cause ic2 deletes power it sends that isn't received.
|
||||
return ((IEnergySink) part).getDemandedEnergy();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage)
|
||||
{
|
||||
if ( !isInIC2() )
|
||||
return amount;
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
IPart part = getPart( dir );
|
||||
if ( part instanceof IEnergySink )
|
||||
{
|
||||
return ((IEnergySink) part).injectEnergy( directionFrom, amount, voltage );
|
||||
}
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSinkTier()
|
||||
{
|
||||
return Integer.MAX_VALUE; // no real options here...
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
package appeng.parts.layers;
|
||||
|
||||
import ic2.api.energy.tile.IEnergyEmitter;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
import ic2.api.energy.tile.IEnergySource;
|
||||
import ic2.api.energy.tile.IEnergyTile;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.LayerBase;
|
||||
import appeng.api.parts.LayerFlags;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class LayerIEnergySource extends LayerBase implements IEnergySource
|
||||
{
|
||||
|
||||
private boolean isInIC2()
|
||||
{
|
||||
return getLayerFlags().contains( LayerFlags.IC2_ENET );
|
||||
}
|
||||
|
||||
private TileEntity getEnergySourceTile()
|
||||
{
|
||||
IPartHost host = (IPartHost) this;
|
||||
return host.getTile();
|
||||
}
|
||||
|
||||
private World getEnergySourceWorld()
|
||||
{
|
||||
if ( getEnergySourceTile() == null )
|
||||
return null;
|
||||
return getEnergySourceTile().getWorldObj();
|
||||
}
|
||||
|
||||
private boolean isTileValid()
|
||||
{
|
||||
TileEntity te = getEnergySourceTile();
|
||||
if ( te == null )
|
||||
return false;
|
||||
return !te.isInvalid();
|
||||
}
|
||||
|
||||
final private void addToENet()
|
||||
{
|
||||
if ( getEnergySourceWorld() == null )
|
||||
return;
|
||||
|
||||
// re-add
|
||||
removeFromENet();
|
||||
|
||||
if ( !isInIC2() && Platform.isServer() && isTileValid() )
|
||||
{
|
||||
getLayerFlags().add( LayerFlags.IC2_ENET );
|
||||
MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileLoadEvent( (IEnergySink) getEnergySourceTile() ) );
|
||||
}
|
||||
}
|
||||
|
||||
final private void removeFromENet()
|
||||
{
|
||||
if ( getEnergySourceWorld() == null )
|
||||
return;
|
||||
|
||||
if ( isInIC2() && Platform.isServer() )
|
||||
{
|
||||
getLayerFlags().remove( LayerFlags.IC2_ENET );
|
||||
MinecraftForge.EVENT_BUS.post( new ic2.api.energy.event.EnergyTileUnloadEvent( (IEnergySink) getEnergySourceTile() ) );
|
||||
}
|
||||
}
|
||||
|
||||
final private boolean interestedInIC2()
|
||||
{
|
||||
if ( !((IPartHost) this).isInWorld() )
|
||||
return false;
|
||||
|
||||
int interested = 0;
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
IPart part = getPart( dir );
|
||||
if ( part instanceof IEnergyTile )
|
||||
{
|
||||
interested++;
|
||||
}
|
||||
}
|
||||
return interested == 1;// if more then one tile is interested we need to abandonship...
|
||||
}
|
||||
|
||||
@Override
|
||||
public void partChanged()
|
||||
{
|
||||
super.partChanged();
|
||||
|
||||
if ( interestedInIC2() )
|
||||
addToENet();
|
||||
else
|
||||
removeFromENet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction)
|
||||
{
|
||||
if ( !isInIC2() )
|
||||
return false;
|
||||
|
||||
IPart part = getPart( direction );
|
||||
if ( part instanceof IEnergySink )
|
||||
return ((IEnergyEmitter) part).emitsEnergyTo( receiver, direction );
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getOfferedEnergy()
|
||||
{
|
||||
if ( !isInIC2() )
|
||||
return 0;
|
||||
|
||||
// this is a flawed implementation, that requires a change to the IC2 API.
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
IPart part = getPart( dir );
|
||||
if ( part instanceof IEnergySource )
|
||||
{
|
||||
// use lower number cause ic2 deletes power it sends that isn't received.
|
||||
return ((IEnergySource) part).getOfferedEnergy();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEnergy(double amount)
|
||||
{
|
||||
// this is a flawed implementation, that requires a change to the IC2 API.
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
IPart part = getPart( dir );
|
||||
if ( part instanceof IEnergySource )
|
||||
{
|
||||
((IEnergySource) part).drawEnergy( amount );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSourceTier()
|
||||
{
|
||||
// this is a flawed implementation, that requires a change to the IC2 API.
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
IPart part = getPart( dir );
|
||||
if ( part instanceof IEnergySource )
|
||||
{
|
||||
return ((IEnergySource) part).getSourceTier();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package appeng.parts.layers;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.LayerBase;
|
||||
|
||||
public class LayerIFluidHandler extends LayerBase implements IFluidHandler
|
||||
{
|
||||
|
||||
static final FluidTankInfo[] emptyList = new FluidTankInfo[0];
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
IPart part = getPart( from );
|
||||
if ( part instanceof IFluidHandler )
|
||||
return ((IFluidHandler) part).fill( from, resource, doFill );
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
IPart part = getPart( from );
|
||||
if ( part instanceof IFluidHandler )
|
||||
return ((IFluidHandler) part).drain( from, resource, doDrain );
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
|
||||
{
|
||||
IPart part = getPart( from );
|
||||
if ( part instanceof IFluidHandler )
|
||||
return ((IFluidHandler) part).drain( from, maxDrain, doDrain );
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, net.minecraftforge.fluids.Fluid fluid)
|
||||
{
|
||||
IPart part = getPart( from );
|
||||
if ( part instanceof IFluidHandler )
|
||||
return ((IFluidHandler) part).canFill( from, fluid );
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, net.minecraftforge.fluids.Fluid fluid)
|
||||
{
|
||||
IPart part = getPart( from );
|
||||
if ( part instanceof IFluidHandler )
|
||||
return ((IFluidHandler) part).canDrain( from, fluid );
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from)
|
||||
{
|
||||
IPart part = getPart( from );
|
||||
if ( part instanceof IFluidHandler )
|
||||
return ((IFluidHandler) part).getTankInfo( from );
|
||||
return emptyList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package appeng.parts.layers;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.LayerBase;
|
||||
import buildcraft.api.transport.IPipeConnection;
|
||||
import buildcraft.api.transport.IPipeTile.PipeType;
|
||||
|
||||
public class LayerIPipeConnection extends LayerBase implements IPipeConnection
|
||||
{
|
||||
|
||||
@Override
|
||||
public ConnectOverride overridePipeConnection(PipeType type, ForgeDirection with)
|
||||
{
|
||||
IPart part = getPart( with );
|
||||
if ( part instanceof IPipeConnection )
|
||||
return ((IPipeConnection) part).overridePipeConnection( type, with );
|
||||
return ConnectOverride.DEFAULT;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package appeng.parts.layers;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.LayerBase;
|
||||
import buildcraft.api.power.IPowerEmitter;
|
||||
|
||||
public class LayerIPowerEmitter extends LayerBase implements IPowerEmitter
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean canEmitPowerFrom(ForgeDirection side)
|
||||
{
|
||||
IPart part = getPart( side );
|
||||
if ( part instanceof IPowerEmitter )
|
||||
return ((IPowerEmitter) part).canEmitPowerFrom( side );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package appeng.parts.layers;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.LayerBase;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.power.PowerHandler;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
|
||||
public class LayerIPowerReceptor extends LayerBase implements IPowerReceptor
|
||||
{
|
||||
|
||||
@Override
|
||||
public PowerReceiver getPowerReceiver(ForgeDirection side)
|
||||
{
|
||||
IPart part = getPart( side );
|
||||
if ( part instanceof IPowerReceptor )
|
||||
return ((IPowerReceptor) part).getPowerReceiver( side );
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWork(PowerHandler workProvider)
|
||||
{
|
||||
// do nothing, this seems pointless.
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
{
|
||||
return ((IPartHost) this).getTile().getWorldObj();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
package appeng.parts.layers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.LayerBase;
|
||||
|
||||
/**
|
||||
* Inventory wrapper for parts,
|
||||
*
|
||||
* this is considerably more complicated then the other wrappers as it requires creating a "unified inventory".
|
||||
*
|
||||
* You must use {@link ISidedInventory} instead of {@link IInventory}.
|
||||
*
|
||||
* If your inventory changes in between placement and removal, you must trigger a PartChange on the {@link IPartHost} so
|
||||
* it can recalculate the inventory wrapper.
|
||||
*/
|
||||
public class LayerISidedInventory extends LayerBase implements ISidedInventory
|
||||
{
|
||||
|
||||
// a simple empty array for empty stuff..
|
||||
private final static int[] nullSides = new int[] {};
|
||||
|
||||
InvLayerData invLayer = null;
|
||||
|
||||
/**
|
||||
* Recalculate inventory wrapper cache.
|
||||
*/
|
||||
@Override
|
||||
public void notifyNeighbors()
|
||||
{
|
||||
// cache of inventory state.
|
||||
int sideData[][] = null;
|
||||
List<ISidedInventory> invs = null;
|
||||
List<InvSot> slots = null;
|
||||
|
||||
invs = new ArrayList();
|
||||
int slotCount = 0;
|
||||
|
||||
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
IPart bp = getPart( side );
|
||||
if ( bp instanceof ISidedInventory )
|
||||
{
|
||||
ISidedInventory part = (ISidedInventory) bp;
|
||||
slotCount += part.getSizeInventory();
|
||||
invs.add( part );
|
||||
}
|
||||
}
|
||||
|
||||
if ( invs.isEmpty() || slotCount == 0 )
|
||||
{
|
||||
invs = null;
|
||||
sideData = null;
|
||||
slots = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
sideData = new int[][] { nullSides, nullSides, nullSides, nullSides, nullSides, nullSides };
|
||||
slots = new ArrayList<InvSot>( Collections.nCopies( slotCount, (InvSot) null ) );
|
||||
|
||||
int offsetForLayer = 0;
|
||||
int offsetForPart = 0;
|
||||
for (ISidedInventory sides : invs)
|
||||
{
|
||||
offsetForPart = 0;
|
||||
slotCount = sides.getSizeInventory();
|
||||
|
||||
ForgeDirection currentSide = ForgeDirection.UNKNOWN;
|
||||
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
||||
if ( getPart( side ) == sides )
|
||||
{
|
||||
currentSide = side;
|
||||
break;
|
||||
}
|
||||
|
||||
int cSidesList[] = sideData[currentSide.ordinal()] = new int[slotCount];
|
||||
for (int cSlot = 0; cSlot < slotCount; cSlot++)
|
||||
{
|
||||
cSidesList[cSlot] = offsetForLayer;
|
||||
slots.set( offsetForLayer++, new InvSot( sides, offsetForPart++ ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( sideData == null || slots == null )
|
||||
invLayer = null;
|
||||
else
|
||||
invLayer = new InvLayerData( sideData, invs, slots );
|
||||
|
||||
// make sure inventory is updated before we call FMP.
|
||||
super.notifyNeighbors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount)
|
||||
{
|
||||
if ( invLayer == null )
|
||||
return null;
|
||||
|
||||
return invLayer.decrStackSize( slot, amount );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
if ( invLayer == null )
|
||||
return 0;
|
||||
|
||||
return invLayer.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot)
|
||||
{
|
||||
if ( invLayer == null )
|
||||
return null;
|
||||
|
||||
return invLayer.getStackInSlot( slot );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack itemstack)
|
||||
{
|
||||
if ( invLayer == null )
|
||||
return false;
|
||||
|
||||
return invLayer.isItemValidForSlot( slot, itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack itemstack)
|
||||
{
|
||||
if ( invLayer == null )
|
||||
return;
|
||||
|
||||
invLayer.setInventorySlotContents( slot, itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int slot, ItemStack itemstack, int side)
|
||||
{
|
||||
if ( invLayer == null )
|
||||
return false;
|
||||
|
||||
return invLayer.canExtractItem( slot, itemstack, side );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int slot, ItemStack itemstack, int side)
|
||||
{
|
||||
if ( invLayer == null )
|
||||
return false;
|
||||
|
||||
return invLayer.canInsertItem( slot, itemstack, side );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
if ( invLayer != null )
|
||||
invLayer.markDirty();
|
||||
|
||||
super.markForSave();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side)
|
||||
{
|
||||
if ( invLayer != null )
|
||||
return invLayer.getAccessibleSlotsFromSide( side );
|
||||
|
||||
return nullSides;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 64; // no options here.
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
return "AEMultiPart";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package appeng.parts.layers;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.implementations.tiles.ITileStorageMonitorable;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.LayerBase;
|
||||
import appeng.api.storage.IStorageMonitorable;
|
||||
|
||||
public class LayerITileStorageMonitorable extends LayerBase implements ITileStorageMonitorable
|
||||
{
|
||||
|
||||
@Override
|
||||
public IStorageMonitorable getMonitorable(ForgeDirection side, BaseActionSource src)
|
||||
{
|
||||
IPart part = getPart( side );
|
||||
if ( part instanceof ITileStorageMonitorable )
|
||||
return ((ITileStorageMonitorable) part).getMonitorable( side, src );
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
package appeng.parts.misc;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.parts.BusSupport;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.parts.ISimplifiedBundle;
|
||||
import appeng.api.parts.PartItemStack;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartCableAnchor implements IPart
|
||||
{
|
||||
|
||||
protected ISimplifiedBundle renderCache = null;
|
||||
ItemStack is = null;
|
||||
IPartHost host = null;
|
||||
ForgeDirection mySide = ForgeDirection.UP;
|
||||
|
||||
public PartCableAnchor(ItemStack is) {
|
||||
this.is = is;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache );
|
||||
IIcon myIcon = is.getIconIndex();
|
||||
rh.setTexture( myIcon );
|
||||
if ( host != null && host.getFacadeContainer().getFacade( mySide ) != null )
|
||||
rh.setBounds( 7, 7, 10, 9, 9, 14 );
|
||||
else
|
||||
rh.setBounds( 7, 7, 10, 9, 9, 16 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
rh.setTexture( null );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void randomDisplayTick(World world, int x, int y, int z, Random r)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(IPartRenderHelper instance, RenderBlocks renderer)
|
||||
{
|
||||
instance.setTexture( is.getIconIndex() );
|
||||
instance.setBounds( 7, 7, 4, 9, 9, 14 );
|
||||
instance.renderInventoryBox( renderer );
|
||||
instance.setTexture( null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(IPartCollisionHelper bch)
|
||||
{
|
||||
if ( host != null && host.getFacadeContainer().getFacade( mySide ) != null )
|
||||
bch.addBox( 7, 7, 10, 9, 9, 14 );
|
||||
else
|
||||
bch.addBox( 7, 7, 10, 9, 9, 16 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack(PartItemStack wrenched)
|
||||
{
|
||||
return is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requireDynamicRender()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderDynamic(double x, double y, double z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightLevel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(ByteBuf data) throws IOException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream(ByteBuf data) throws IOException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode getGridNode()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityCollision(Entity entity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFromWorld()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToWorld()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode getExternalFacingNode()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPartHostInfo(ForgeDirection side, IPartHost host, TileEntity tile)
|
||||
{
|
||||
this.host = host;
|
||||
mySide = side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(List<ItemStack> drops, boolean wrenched)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cableConnectionRenderTo()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLadder(EntityLivingBase entity)
|
||||
{
|
||||
return mySide.offsetY == 0 && ( entity.isCollidedHorizontally || ! entity.onGround );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onShiftActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBePlacedOn(BusSupport what)
|
||||
{
|
||||
return what == BusSupport.CABLE || what == BusSupport.DENSE_CABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getBreakingTexture()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,407 @@
|
||||
package appeng.parts.misc;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.implementations.tiles.ISegmentedInventory;
|
||||
import appeng.api.implementations.tiles.ITileStorageMonitorable;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.crafting.ICraftingLink;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.networking.crafting.ICraftingProviderHelper;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IStorageMonitorable;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.helpers.DualityInterface;
|
||||
import appeng.helpers.IInterfaceHost;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
import appeng.parts.PartBasicState;
|
||||
import appeng.tile.inventory.IAEAppEngInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.IInventoryDestination;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartInterface extends PartBasicState implements IGridTickable, ISegmentedInventory, IStorageMonitorable, IInventoryDestination, IInterfaceHost,
|
||||
ISidedInventory, IAEAppEngInventory, ITileStorageMonitorable, IPriorityHost
|
||||
{
|
||||
|
||||
DualityInterface duality = new DualityInterface( proxy, this );
|
||||
|
||||
public PartInterface(ItemStack is) {
|
||||
super( PartInterface.class, is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToWorld()
|
||||
{
|
||||
super.addToWorld();
|
||||
duality.initialize();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange(MENetworkChannelsChanged c)
|
||||
{
|
||||
duality.notifyNeightbors();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange(MENetworkPowerStatusChange c)
|
||||
{
|
||||
duality.notifyNeightbors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gridChanged()
|
||||
{
|
||||
duality.gridChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
duality.writeToNBT( data );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
duality.readFromNBT( data );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(List<ItemStack> drops, boolean wrenched)
|
||||
{
|
||||
duality.addDrops( drops );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
rh.setTexture( CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorBack.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon() );
|
||||
|
||||
rh.setBounds( 3, 3, 15, 13, 13, 16 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 15 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
rh.setBounds( 5, 5, 12, 11, 11, 14 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache );
|
||||
rh.setTexture( CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorBack.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon() );
|
||||
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setTexture( CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorBack.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon() );
|
||||
|
||||
rh.setBounds( 5, 5, 12, 11, 11, 13 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setTexture( CableBusTextures.PartMonitorSidesStatus.getIcon(), CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorBack.getIcon(), is.getIconIndex(), CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon() );
|
||||
|
||||
rh.setBounds( 5, 5, 13, 11, 11, 14 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
renderLights( x, y, z, rh, renderer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getBreakingTexture()
|
||||
{
|
||||
return is.getIconIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(IPartCollisionHelper bch)
|
||||
{
|
||||
bch.addBox( 2, 2, 14, 14, 14, 16 );
|
||||
bch.addBox( 5, 5, 12, 11, 11, 14 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cableConnectionRenderTo()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getTileEntity()
|
||||
{
|
||||
return (TileEntity) super.getHost().getTile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert(ItemStack stack)
|
||||
{
|
||||
return duality.canInsert( stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEItemStack> getItemInventory()
|
||||
{
|
||||
return duality.getItemInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEFluidStack> getFluidInventory()
|
||||
{
|
||||
return duality.getFluidInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
return duality.getTickingRequest( node );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
{
|
||||
return duality.tickingRequest( node, TicksSinceLastCall );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return duality.getStorage().getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i)
|
||||
{
|
||||
return duality.getStorage().getStackInSlot( i );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j)
|
||||
{
|
||||
return duality.getStorage().decrStackSize( i, j );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i)
|
||||
{
|
||||
return duality.getStorage().getStackInSlotOnClosing( i );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack)
|
||||
{
|
||||
duality.getStorage().setInventorySlotContents( i, itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
return duality.getStorage().getInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return duality.getStorage().hasCustomInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return duality.getStorage().getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
return duality.getConfigManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(String name)
|
||||
{
|
||||
return duality.getInventoryByName( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
duality.getStorage().markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
||||
{
|
||||
return duality.getStorage().isUseableByPlayer( entityplayer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
duality.getStorage().openInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
duality.getStorage().closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return duality.getStorage().isItemValidForSlot( i, itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int s)
|
||||
{
|
||||
return duality.getAccessibleSlotsFromSide( s );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
|
||||
{
|
||||
duality.onChangeInventory( inv, slot, mc, removedStack, newStack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public DualityInterface getInterfaceDuality()
|
||||
{
|
||||
return duality;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate(EntityPlayer p, Vec3 pos)
|
||||
{
|
||||
if ( p.isSneaking() )
|
||||
return false;
|
||||
|
||||
if ( Platform.isServer() )
|
||||
Platform.openGUI( p, getTileEntity(), side, GuiBridge.GUI_INTERFACE );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageMonitorable getMonitorable(ForgeDirection side, BaseActionSource src)
|
||||
{
|
||||
return duality.getMonitorable( side, src, this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table)
|
||||
{
|
||||
return duality.pushPattern( patternDetails, table );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provideCrafting(ICraftingProviderHelper craftingTracker)
|
||||
{
|
||||
duality.provideCrafting( craftingTracker );
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<ForgeDirection> getTargets()
|
||||
{
|
||||
return EnumSet.of( side );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBusy()
|
||||
{
|
||||
return duality.isBusy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInstalledUpgrades(Upgrades u)
|
||||
{
|
||||
return duality.getInstalledUpgrades( u );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableSet<ICraftingLink> getRequestedJobs()
|
||||
{
|
||||
return duality.getRequestedJobs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack items, Actionable mode)
|
||||
{
|
||||
return duality.injectCraftedItems( link, items, mode );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jobStateChange(ICraftingLink link)
|
||||
{
|
||||
duality.jobStateChange( link );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
{
|
||||
return duality.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPriority(int newValue)
|
||||
{
|
||||
duality.setPriority( newValue );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package appeng.parts.misc;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class PartInvertedToggleBus extends PartToggleBus
|
||||
{
|
||||
|
||||
public PartInvertedToggleBus(ItemStack is) {
|
||||
super( PartInvertedToggleBus.class, is );
|
||||
proxy.setIdlePowerUsage( 0.0 );
|
||||
outerProxy.setIdlePowerUsage( 0.0 );
|
||||
proxy.setFlags();
|
||||
outerProxy.setFlags();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean getIntention()
|
||||
{
|
||||
return !super.getIntention();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,512 @@
|
||||
package appeng.parts.misc;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.config.IncludeExclude;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.StorageFilter;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.events.MENetworkCellArrayUpdate;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.MachineSource;
|
||||
import appeng.api.networking.storage.IBaseMonitor;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.ITickManager;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.storage.ICellContainer;
|
||||
import appeng.api.storage.IExternalStorageHandler;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IMEMonitorHandlerReceiver;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.core.stats.Achievements;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.helpers.IInterfaceHost;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.storage.MEInventoryHandler;
|
||||
import appeng.me.storage.MEMonitorIInventory;
|
||||
import appeng.parts.automation.PartUpgradeable;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.transformer.annotations.integration.Interface;
|
||||
import appeng.transformer.annotations.integration.Method;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.prioitylist.FuzzyPriorityList;
|
||||
import appeng.util.prioitylist.PrecisePriorityList;
|
||||
import buildcraft.api.transport.IPipeConnection;
|
||||
import buildcraft.api.transport.IPipeTile.PipeType;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@Interface(iname = "BC", iface = "buildcraft.api.transport.IPipeConnection")
|
||||
public class PartStorageBus extends PartUpgradeable implements IGridTickable, ICellContainer, IMEMonitorHandlerReceiver<IAEItemStack>, IPipeConnection,
|
||||
IPriorityHost
|
||||
{
|
||||
|
||||
int priority = 0;
|
||||
BaseActionSource mySrc;
|
||||
|
||||
AppEngInternalAEInventory Config = new AppEngInternalAEInventory( this, 63 );
|
||||
|
||||
public PartStorageBus(ItemStack is)
|
||||
{
|
||||
super( PartStorageBus.class, is );
|
||||
getConfigManager().registerSetting( Settings.ACCESS, AccessRestriction.READ_WRITE );
|
||||
getConfigManager().registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
|
||||
getConfigManager().registerSetting( Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY );
|
||||
mySrc = new MachineSource( this );
|
||||
}
|
||||
|
||||
boolean cached = false;
|
||||
MEMonitorIInventory monitor = null;
|
||||
MEInventoryHandler handler = null;
|
||||
|
||||
int handlerHash = 0;
|
||||
boolean wasActive = false;
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(MENetworkPowerStatusChange c)
|
||||
{
|
||||
updateStatus();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void updateChannels(MENetworkChannelsChanged chann)
|
||||
{
|
||||
updateStatus();
|
||||
}
|
||||
|
||||
private void updateStatus()
|
||||
{
|
||||
boolean currentActive = proxy.isActive();
|
||||
if ( wasActive != currentActive )
|
||||
{
|
||||
wasActive = currentActive;
|
||||
try
|
||||
{
|
||||
proxy.getGrid().postEvent( new MENetworkCellArrayUpdate() );
|
||||
host.markForUpdate();
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
if ( !player.isSneaking() )
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return true;
|
||||
|
||||
Platform.openGUI( player, getHost().getTile(), side, GuiBridge.GUI_STORAGEBUS );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected int getUpgradeSlots()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(Object verificationToken)
|
||||
{
|
||||
return handler == verificationToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(String name)
|
||||
{
|
||||
if ( name.equals( "config" ) )
|
||||
return Config;
|
||||
|
||||
return super.getInventoryByName( name );
|
||||
}
|
||||
|
||||
private byte resetCacheLogic = 0;
|
||||
|
||||
private void resetCache(boolean fullReset)
|
||||
{
|
||||
if ( host == null || host.getTile() == null || host.getTile().getWorldObj() == null || host.getTile().getWorldObj().isRemote )
|
||||
return;
|
||||
|
||||
if ( fullReset )
|
||||
resetCacheLogic = 2;
|
||||
else
|
||||
resetCacheLogic = 1;
|
||||
|
||||
try
|
||||
{
|
||||
proxy.getTick().alertDevice( proxy.getNode() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
private void resetCache()
|
||||
{
|
||||
boolean fullReset = resetCacheLogic == 2;
|
||||
resetCacheLogic = 0;
|
||||
|
||||
IMEInventory<IAEItemStack> in = getInternalHandler();
|
||||
IItemList<IAEItemStack> before = AEApi.instance().storage().createItemList();
|
||||
if ( in != null )
|
||||
before = in.getAvailableItems( before );
|
||||
|
||||
cached = false;
|
||||
if ( fullReset )
|
||||
handlerHash = 0;
|
||||
|
||||
IMEInventory<IAEItemStack> out = getInternalHandler();
|
||||
|
||||
if ( monitor != null )
|
||||
monitor.onTick();
|
||||
|
||||
IItemList<IAEItemStack> after = AEApi.instance().storage().createItemList();
|
||||
if ( out != null )
|
||||
after = out.getAvailableItems( after );
|
||||
|
||||
Platform.postListChanges( before, after, this, mySrc );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
resetCache( false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
|
||||
{
|
||||
super.onChangeInventory( inv, slot, mc, removedStack, newStack );
|
||||
|
||||
if ( inv == Config )
|
||||
resetCache( true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upgradesChanged()
|
||||
{
|
||||
super.upgradesChanged();
|
||||
resetCache( true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue)
|
||||
{
|
||||
resetCache( true );
|
||||
host.markForSave();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPriority(int newValue)
|
||||
{
|
||||
priority = newValue;
|
||||
host.markForSave();
|
||||
resetCache( true );
|
||||
}
|
||||
|
||||
public MEInventoryHandler getInternalHandler()
|
||||
{
|
||||
if ( cached )
|
||||
return handler;
|
||||
|
||||
boolean wasSleeping = monitor == null;
|
||||
|
||||
cached = true;
|
||||
TileEntity self = getHost().getTile();
|
||||
TileEntity target = self.getWorldObj().getTileEntity( self.xCoord + side.offsetX, self.yCoord + side.offsetY, self.zCoord + side.offsetZ );
|
||||
|
||||
int newHandlerHash = Platform.generateTileHash( target );
|
||||
|
||||
if ( handlerHash == newHandlerHash && handlerHash != 0 )
|
||||
return handler;
|
||||
|
||||
try
|
||||
{
|
||||
// force grid to update handlers...
|
||||
proxy.getGrid().postEvent( new MENetworkCellArrayUpdate() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :3
|
||||
}
|
||||
|
||||
handlerHash = newHandlerHash;
|
||||
handler = null;
|
||||
monitor = null;
|
||||
if ( target != null )
|
||||
{
|
||||
IExternalStorageHandler esh = AEApi.instance().registries().externalStorage().getHandler( target, side.getOpposite(), StorageChannel.ITEMS, mySrc );
|
||||
if ( esh != null )
|
||||
{
|
||||
IMEInventory inv = esh.getInventory( target, side.getOpposite(), StorageChannel.ITEMS, mySrc );
|
||||
|
||||
if ( inv instanceof MEMonitorIInventory )
|
||||
{
|
||||
MEMonitorIInventory h = (MEMonitorIInventory) inv;
|
||||
h.mode = (StorageFilter) getConfigManager().getSetting( Settings.STORAGE_FILTER );
|
||||
h.mySource = new MachineSource( this );
|
||||
}
|
||||
|
||||
if ( inv instanceof MEMonitorIInventory )
|
||||
monitor = (MEMonitorIInventory) inv;
|
||||
|
||||
if ( inv != null )
|
||||
{
|
||||
checkInterfaceVsStorageBus( target, side.getOpposite() );
|
||||
|
||||
handler = new MEInventoryHandler( inv, StorageChannel.ITEMS );
|
||||
|
||||
handler.myAccess = (AccessRestriction) this.getConfigManager().getSetting( Settings.ACCESS );
|
||||
handler.myWhitelist = getInstalledUpgrades( Upgrades.INVERTER ) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST;
|
||||
handler.myPriority = priority;
|
||||
|
||||
IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
|
||||
|
||||
int slotsToUse = 18 + getInstalledUpgrades( Upgrades.CAPACITY ) * 9;
|
||||
for (int x = 0; x < Config.getSizeInventory() && x < slotsToUse; x++)
|
||||
{
|
||||
IAEItemStack is = Config.getAEStackInSlot( x );
|
||||
if ( is != null )
|
||||
priorityList.add( is );
|
||||
}
|
||||
|
||||
if ( getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
handler.myPartitionList = new FuzzyPriorityList( priorityList, (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE ) );
|
||||
else
|
||||
handler.myPartitionList = new PrecisePriorityList( priorityList );
|
||||
|
||||
if ( inv instanceof IMEMonitor )
|
||||
((IMEMonitor) inv).addListener( this, handler );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update sleep state...
|
||||
if ( wasSleeping != (monitor == null) )
|
||||
{
|
||||
try
|
||||
{
|
||||
ITickManager tm = proxy.getTick();
|
||||
if ( monitor == null )
|
||||
tm.sleepDevice( proxy.getNode() );
|
||||
else
|
||||
tm.wakeDevice( proxy.getNode() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :(
|
||||
}
|
||||
}
|
||||
|
||||
return handler;
|
||||
}
|
||||
|
||||
private void checkInterfaceVsStorageBus(TileEntity target, ForgeDirection side)
|
||||
{
|
||||
IInterfaceHost achiv = null;
|
||||
|
||||
if ( target instanceof IInterfaceHost )
|
||||
achiv = (IInterfaceHost) target;
|
||||
|
||||
if ( target instanceof IPartHost )
|
||||
{
|
||||
Object part = ((IPartHost) target).getPart( side );
|
||||
if ( part instanceof IInterfaceHost )
|
||||
achiv = (IInterfaceHost) part;
|
||||
}
|
||||
|
||||
if ( achiv != null )
|
||||
{
|
||||
Platform.addStat( achiv.getActionableNode().getPlayerID(), Achievements.Recursive.getAchievement() );
|
||||
Platform.addStat( getActionableNode().getPlayerID(), Achievements.Recursive.getAchievement() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
rh.setTexture( CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageBack.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageSides.getIcon() );
|
||||
|
||||
rh.setBounds( 3, 3, 15, 13, 13, 16 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 15 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
rh.setBounds( 5, 5, 12, 11, 11, 14 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache );
|
||||
rh.setTexture( CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageBack.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageSides.getIcon() );
|
||||
|
||||
rh.setBounds( 3, 3, 15, 13, 13, 16 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 15 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setTexture( CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageBack.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartStorageSides.getIcon(), CableBusTextures.PartStorageSides.getIcon() );
|
||||
|
||||
rh.setBounds( 5, 5, 12, 11, 11, 13 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setTexture( CableBusTextures.PartMonitorSidesStatus.getIcon(), CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorBack.getIcon(), is.getIconIndex(), CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon() );
|
||||
|
||||
rh.setBounds( 5, 5, 13, 11, 11, 14 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
renderLights( x, y, z, rh, renderer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(IPartCollisionHelper bch)
|
||||
{
|
||||
bch.addBox( 3, 3, 15, 13, 13, 16 );
|
||||
bch.addBox( 2, 2, 14, 14, 14, 15 );
|
||||
bch.addBox( 5, 5, 12, 11, 11, 14 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cableConnectionRenderTo()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
return new TickingRequest( TickRates.StorageBus.min, TickRates.StorageBus.max, monitor == null, true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
{
|
||||
if ( resetCacheLogic != 0 )
|
||||
resetCache();
|
||||
|
||||
if ( monitor != null )
|
||||
return monitor.onTick();
|
||||
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
Config.writeToNBT( data, "config" );
|
||||
data.setInteger( "priority", priority );
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
Config.readFromNBT( data, "config" );
|
||||
priority = data.getInteger( "priority" );
|
||||
};
|
||||
|
||||
@Override
|
||||
public List<IMEInventoryHandler> getCellArray(StorageChannel channel)
|
||||
{
|
||||
if ( channel == StorageChannel.ITEMS )
|
||||
{
|
||||
IMEInventoryHandler out = proxy.isActive() ? getInternalHandler() : null;
|
||||
if ( out != null )
|
||||
return Arrays.asList( new IMEInventoryHandler[] { out } );
|
||||
}
|
||||
return Arrays.asList( new IMEInventoryHandler[] {} );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
{
|
||||
return priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blinkCell(int slot)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postChange(IBaseMonitor<IAEItemStack> monitor, Iterable<IAEItemStack> change, BaseActionSource source)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( proxy.isActive() )
|
||||
proxy.getStorage().postAlterationOfStoredItems( StorageChannel.ITEMS, change, mySrc );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :(
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(iname = "BC")
|
||||
public ConnectOverride overridePipeConnection(PipeType type, ForgeDirection with)
|
||||
{
|
||||
return type == PipeType.ITEM && with == side ? ConnectOverride.CONNECT : ConnectOverride.DISCONNECT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListUpdate()
|
||||
{
|
||||
// not used here.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveChanges(IMEInventory cellInventory)
|
||||
{
|
||||
// nope!
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
package appeng.parts.misc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
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.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.exceptions.FailedConnection;
|
||||
import appeng.api.networking.IGridConnection;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.me.helpers.AENetworkProxy;
|
||||
import appeng.parts.PartBasicState;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartToggleBus extends PartBasicState
|
||||
{
|
||||
|
||||
AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", null, true );
|
||||
IGridConnection connection;
|
||||
|
||||
protected final int REDSTONE_FLAG = 4;
|
||||
|
||||
boolean hasRedstone = false;
|
||||
|
||||
@Override
|
||||
public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side)
|
||||
{
|
||||
super.onPlacement( player, held, side );
|
||||
outerProxy.setOwner( player );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int populateFlags(int cf)
|
||||
{
|
||||
return cf | (getIntention() ? REDSTONE_FLAG : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
boolean oldHasRedstone = hasRedstone;
|
||||
hasRedstone = getHost().hasRedstone( side );
|
||||
|
||||
if ( hasRedstone != oldHasRedstone )
|
||||
{
|
||||
updateInternalState();
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public PartToggleBus(ItemStack is) {
|
||||
this( PartToggleBus.class, is );
|
||||
proxy.setIdlePowerUsage( 0.0 );
|
||||
outerProxy.setIdlePowerUsage( 0.0 );
|
||||
proxy.setFlags();
|
||||
outerProxy.setFlags();
|
||||
}
|
||||
|
||||
public PartToggleBus(Class cls, ItemStack is) {
|
||||
super( cls, is );
|
||||
}
|
||||
|
||||
@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();
|
||||
hasRedstone = getHost().hasRedstone( side );
|
||||
updateInternalState();
|
||||
}
|
||||
|
||||
private void updateInternalState()
|
||||
{
|
||||
boolean intention = getIntention();
|
||||
if ( intention != (connection != null) )
|
||||
{
|
||||
if ( proxy.getNode() != null && outerProxy.getNode() != null )
|
||||
{
|
||||
if ( intention )
|
||||
{
|
||||
try
|
||||
{
|
||||
connection = AEApi.instance().createGridConnection( proxy.getNode(), outerProxy.getNode() );
|
||||
}
|
||||
catch (FailedConnection e)
|
||||
{
|
||||
// :(
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
connection.destroy();
|
||||
connection = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean getIntention()
|
||||
{
|
||||
return getHost().hasRedstone( side );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFromWorld()
|
||||
{
|
||||
super.removeFromWorld();
|
||||
outerProxy.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode getExternalFacingNode()
|
||||
{
|
||||
return outerProxy.getNode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType(ForgeDirection dir)
|
||||
{
|
||||
return AECableType.GLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColors(boolean hasChan, boolean hasPower)
|
||||
{
|
||||
hasRedstone = (clientFlags & REDSTONE_FLAG) == REDSTONE_FLAG;
|
||||
super.setColors( hasChan && hasRedstone, hasPower && hasRedstone );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache );
|
||||
rh.setTexture( is.getIconIndex() );
|
||||
|
||||
rh.setBounds( 6, 6, 14, 10, 10, 16 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setBounds( 6, 6, 11, 10, 10, 13 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setTexture( CableBusTextures.PartMonitorSidesStatus.getIcon(), CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorBack.getIcon(), is.getIconIndex(), CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon() );
|
||||
|
||||
rh.setBounds( 6, 6, 13, 10, 10, 14 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
renderLights( x, y, z, rh, renderer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getBreakingTexture()
|
||||
{
|
||||
return is.getIconIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(IPartCollisionHelper bch)
|
||||
{
|
||||
bch.addBox( 6, 6, 11, 10, 10, 16 );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
GL11.glTranslated( -0.2, -0.3, 0.0 );
|
||||
|
||||
rh.setTexture( is.getIconIndex() );
|
||||
rh.setBounds( 6, 6, 14 - 4, 10, 10, 16 - 4 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
rh.setBounds( 6, 6, 11 - 4, 10, 10, 13 - 4 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
rh.setBounds( 6, 6, 13 - 4, 10, 10, 14 - 4 );
|
||||
rh.setTexture( CableBusTextures.PartMonitorSidesStatus.getIcon() );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
rh.setTexture( CableBusTextures.PartMonitorSidesStatusLights.getIcon() );
|
||||
rh.setInvColor( 0x000000 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
rh.setInvColor( 0xffffff );
|
||||
|
||||
rh.setTexture( null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cableConnectionRenderTo()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void securityBreak()
|
||||
{
|
||||
if ( is.stackSize > 0 )
|
||||
{
|
||||
List<ItemStack> items = new ArrayList();
|
||||
items.add( is.copy() );
|
||||
host.removePart( side, false );
|
||||
Platform.spawnDrops( tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord, items );
|
||||
is.stackSize = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,243 @@
|
||||
package appeng.parts.networking;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.client.texture.OffsetIcon;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartCableCovered extends PartCable
|
||||
{
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void channelUpdated(MENetworkChannelsChanged c)
|
||||
{
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(MENetworkPowerStatusChange c)
|
||||
{
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
|
||||
public PartCableCovered(Class c, ItemStack is) {
|
||||
super( c, is );
|
||||
}
|
||||
|
||||
public PartCableCovered(ItemStack is) {
|
||||
this( PartCableCovered.class, is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getTexture(AEColor c)
|
||||
{
|
||||
return getCoveredTexture( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType()
|
||||
{
|
||||
return AECableType.COVERED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(IPartCollisionHelper bch)
|
||||
{
|
||||
bch.addBox( 5.0, 5.0, 5.0, 11.0, 11.0, 11.0 );
|
||||
|
||||
if ( Platform.isServer() )
|
||||
{
|
||||
IGridNode n = getGridNode();
|
||||
if ( n != null )
|
||||
connections = n.getConnectedSides();
|
||||
else
|
||||
connections.clear();
|
||||
}
|
||||
|
||||
for (ForgeDirection of : connections)
|
||||
{
|
||||
switch (of)
|
||||
{
|
||||
case DOWN:
|
||||
bch.addBox( 5.0, 0.0, 5.0, 11.0, 5.0, 11.0 );
|
||||
break;
|
||||
case EAST:
|
||||
bch.addBox( 11.0, 5.0, 5.0, 16.0, 11.0, 11.0 );
|
||||
break;
|
||||
case NORTH:
|
||||
bch.addBox( 5.0, 5.0, 0.0, 11.0, 11.0, 5.0 );
|
||||
break;
|
||||
case SOUTH:
|
||||
bch.addBox( 5.0, 5.0, 11.0, 11.0, 11.0, 16.0 );
|
||||
break;
|
||||
case UP:
|
||||
bch.addBox( 5.0, 11.0, 5.0, 11.0, 16.0, 11.0 );
|
||||
break;
|
||||
case WEST:
|
||||
bch.addBox( 0.0, 5.0, 5.0, 5.0, 11.0, 11.0 );
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
GL11.glTranslated( -0.0, -0.0, 0.3 );
|
||||
|
||||
rh.setBounds( 5.0f, 5.0f, 2.0f, 11.0f, 11.0f, 14.0f );
|
||||
float offu = 0;
|
||||
float offv = 9;
|
||||
|
||||
OffsetIcon main = new OffsetIcon( getTexture( getCableColor() ), offu, offv );
|
||||
|
||||
for (ForgeDirection side : EnumSet.of( ForgeDirection.UP, ForgeDirection.DOWN ))
|
||||
{
|
||||
rh.renderInventoryFace( main, side, renderer );
|
||||
}
|
||||
|
||||
offu = 9;
|
||||
offv = 0;
|
||||
main = new OffsetIcon( getTexture( getCableColor() ), offu, offv );
|
||||
|
||||
for (ForgeDirection side : EnumSet.of( ForgeDirection.EAST, ForgeDirection.WEST ))
|
||||
{
|
||||
rh.renderInventoryFace( main, side, renderer );
|
||||
}
|
||||
|
||||
main = new OffsetIcon( getTexture( getCableColor() ), 0, 0 );
|
||||
|
||||
for (ForgeDirection side : EnumSet.of( ForgeDirection.SOUTH, ForgeDirection.NORTH ))
|
||||
{
|
||||
rh.renderInventoryFace( main, side, renderer );
|
||||
}
|
||||
|
||||
rh.setTexture( null );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache );
|
||||
rh.setTexture( getTexture( getCableColor() ) );
|
||||
|
||||
EnumSet<ForgeDirection> sides = connections.clone();
|
||||
|
||||
boolean hasBuses = false;
|
||||
IPartHost ph = getHost();
|
||||
for (ForgeDirection of : EnumSet.complementOf( connections ))
|
||||
{
|
||||
IPart bp = ph.getPart( of );
|
||||
if ( bp instanceof IGridHost )
|
||||
{
|
||||
if ( of != ForgeDirection.UNKNOWN )
|
||||
{
|
||||
sides.add( of );
|
||||
hasBuses = true;
|
||||
}
|
||||
|
||||
int len = bp.cableConnectionRenderTo();
|
||||
if ( len < 8 )
|
||||
{
|
||||
switch (of)
|
||||
{
|
||||
case DOWN:
|
||||
rh.setBounds( 6, len, 6, 10, 5, 10 );
|
||||
break;
|
||||
case EAST:
|
||||
rh.setBounds( 11, 6, 6, 16 - len, 10, 10 );
|
||||
break;
|
||||
case NORTH:
|
||||
rh.setBounds( 6, 6, len, 10, 10, 5 );
|
||||
break;
|
||||
case SOUTH:
|
||||
rh.setBounds( 6, 6, 11, 10, 10, 16 - len );
|
||||
break;
|
||||
case UP:
|
||||
rh.setBounds( 6, 11, 6, 10, 16 - len, 10 );
|
||||
break;
|
||||
case WEST:
|
||||
rh.setBounds( len, 6, 6, 5, 10, 10 );
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( sides.size() != 2 || !nonLinear( sides ) || hasBuses )
|
||||
{
|
||||
for (ForgeDirection of : connections)
|
||||
{
|
||||
renderCoveredConnection( x, y, z, rh, renderer, channelsOnSide[of.ordinal()], of );
|
||||
}
|
||||
|
||||
rh.setTexture( getTexture( getCableColor() ) );
|
||||
rh.setBounds( 5, 5, 5, 11, 11, 11 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
}
|
||||
else
|
||||
{
|
||||
IIcon def = getTexture( getCableColor() );
|
||||
IIcon off = new OffsetIcon( def, 0, -12 );
|
||||
for (ForgeDirection of : connections)
|
||||
{
|
||||
switch (of)
|
||||
{
|
||||
case DOWN:
|
||||
case UP:
|
||||
rh.setTexture( def, def, off, off, off, off );
|
||||
renderer.setRenderBounds( 5 / 16.0, 0, 5 / 16.0, 11 / 16.0, 16 / 16.0, 11 / 16.0 );
|
||||
break;
|
||||
case EAST:
|
||||
case WEST:
|
||||
rh.setTexture( off, off, off, off, def, def );
|
||||
renderer.uvRotateEast = renderer.uvRotateWest = 1;
|
||||
renderer.uvRotateBottom = renderer.uvRotateTop = 1;
|
||||
renderer.setRenderBounds( 0, 5 / 16.0, 5 / 16.0, 16 / 16.0, 11 / 16.0, 11 / 16.0 );
|
||||
break;
|
||||
case NORTH:
|
||||
case SOUTH:
|
||||
rh.setTexture( off, off, def, def, off, off );
|
||||
renderer.uvRotateNorth = renderer.uvRotateSouth = 1;
|
||||
renderer.setRenderBounds( 5 / 16.0, 5 / 16.0, 0, 11 / 16.0, 11 / 16.0, 16 / 16.0 );
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
rh.renderBlockCurrentBounds( x, y, z, renderer );
|
||||
}
|
||||
|
||||
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0;
|
||||
rh.setTexture( null );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package appeng.parts.networking;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class PartCableGlass extends PartCable
|
||||
{
|
||||
|
||||
public PartCableGlass(Class c, ItemStack is) {
|
||||
super( c, is );
|
||||
}
|
||||
|
||||
public PartCableGlass(ItemStack is) {
|
||||
this( PartCableGlass.class, is );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,355 @@
|
||||
package appeng.parts.networking;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import appeng.client.texture.FlippableIcon;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.block.AEBaseBlock;
|
||||
import appeng.client.texture.OffsetIcon;
|
||||
import appeng.client.texture.TaughtIcon;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartCableSmart extends PartCable
|
||||
{
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void channelUpdated(MENetworkChannelsChanged c)
|
||||
{
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(MENetworkPowerStatusChange c)
|
||||
{
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
|
||||
public PartCableSmart(Class c, ItemStack is) {
|
||||
super( c, is );
|
||||
}
|
||||
|
||||
public PartCableSmart(ItemStack is) {
|
||||
this( PartCableSmart.class, is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType()
|
||||
{
|
||||
return AECableType.SMART;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getTexture(AEColor c)
|
||||
{
|
||||
return getSmartTexture( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
GL11.glTranslated( -0.0, -0.0, 0.3 );
|
||||
|
||||
float offu = 0;
|
||||
float offv = 9;
|
||||
|
||||
OffsetIcon main = new OffsetIcon( getTexture( getCableColor() ), offu, offv );
|
||||
OffsetIcon ch1 = new OffsetIcon( getChannelTex( 4, false ).getIcon(), offu, offv );
|
||||
OffsetIcon ch2 = new OffsetIcon( getChannelTex( 4, true ).getIcon(), offu, offv );
|
||||
|
||||
for (ForgeDirection side : EnumSet.of( ForgeDirection.UP, ForgeDirection.DOWN ))
|
||||
{
|
||||
rh.setBounds( 5.0f, 5.0f, 2.0f, 11.0f, 11.0f, 14.0f );
|
||||
rh.renderInventoryFace( main, side, renderer );
|
||||
rh.renderInventoryFace( ch1, side, renderer );
|
||||
rh.renderInventoryFace( ch2, side, renderer );
|
||||
}
|
||||
|
||||
offu = 9;
|
||||
offv = 0;
|
||||
main = new OffsetIcon( getTexture( getCableColor() ), offu, offv );
|
||||
ch1 = new OffsetIcon( getChannelTex( 4, false ).getIcon(), offu, offv );
|
||||
ch2 = new OffsetIcon( getChannelTex( 4, true ).getIcon(), offu, offv );
|
||||
|
||||
for (ForgeDirection side : EnumSet.of( ForgeDirection.EAST, ForgeDirection.WEST ))
|
||||
{
|
||||
rh.setBounds( 5.0f, 5.0f, 2.0f, 11.0f, 11.0f, 14.0f );
|
||||
rh.renderInventoryFace( main, side, renderer );
|
||||
rh.renderInventoryFace( ch1, side, renderer );
|
||||
rh.renderInventoryFace( ch2, side, renderer );
|
||||
}
|
||||
|
||||
main = new OffsetIcon( getTexture( getCableColor() ), 0, 0 );
|
||||
ch1 = new OffsetIcon( getChannelTex( 4, false ).getIcon(), 0, 0 );
|
||||
ch2 = new OffsetIcon( getChannelTex( 4, true ).getIcon(), 0, 0 );
|
||||
|
||||
for (ForgeDirection side : EnumSet.of( ForgeDirection.SOUTH, ForgeDirection.NORTH ))
|
||||
{
|
||||
rh.setBounds( 5.0f, 5.0f, 2.0f, 11.0f, 11.0f, 14.0f );
|
||||
rh.renderInventoryFace( main, side, renderer );
|
||||
rh.renderInventoryFace( ch1, side, renderer );
|
||||
rh.renderInventoryFace( ch2, side, renderer );
|
||||
}
|
||||
|
||||
rh.setTexture( null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(IPartCollisionHelper bch)
|
||||
{
|
||||
bch.addBox( 5.0, 5.0, 5.0, 11.0, 11.0, 11.0 );
|
||||
|
||||
if ( Platform.isServer() )
|
||||
{
|
||||
IGridNode n = getGridNode();
|
||||
if ( n != null )
|
||||
connections = n.getConnectedSides();
|
||||
else
|
||||
connections.clear();
|
||||
}
|
||||
|
||||
for (ForgeDirection of : connections)
|
||||
{
|
||||
switch (of)
|
||||
{
|
||||
case DOWN:
|
||||
bch.addBox( 5.0, 0.0, 5.0, 11.0, 5.0, 11.0 );
|
||||
break;
|
||||
case EAST:
|
||||
bch.addBox( 11.0, 5.0, 5.0, 16.0, 11.0, 11.0 );
|
||||
break;
|
||||
case NORTH:
|
||||
bch.addBox( 5.0, 5.0, 0.0, 11.0, 11.0, 5.0 );
|
||||
break;
|
||||
case SOUTH:
|
||||
bch.addBox( 5.0, 5.0, 11.0, 11.0, 11.0, 16.0 );
|
||||
break;
|
||||
case UP:
|
||||
bch.addBox( 5.0, 11.0, 5.0, 11.0, 16.0, 11.0 );
|
||||
break;
|
||||
case WEST:
|
||||
bch.addBox( 0.0, 5.0, 5.0, 5.0, 11.0, 11.0 );
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache );
|
||||
rh.setTexture( getTexture( getCableColor() ) );
|
||||
|
||||
EnumSet<ForgeDirection> sides = connections.clone();
|
||||
|
||||
boolean hasBuses = false;
|
||||
IPartHost ph = getHost();
|
||||
for (ForgeDirection of : EnumSet.complementOf( connections ))
|
||||
{
|
||||
IPart bp = ph.getPart( of );
|
||||
if ( bp instanceof IGridHost )
|
||||
{
|
||||
if ( of != ForgeDirection.UNKNOWN )
|
||||
{
|
||||
sides.add( of );
|
||||
hasBuses = true;
|
||||
}
|
||||
|
||||
int len = bp.cableConnectionRenderTo();
|
||||
if ( len < 8 )
|
||||
{
|
||||
switch (of)
|
||||
{
|
||||
case DOWN:
|
||||
rh.setBounds( 6, len, 6, 10, 5, 10 );
|
||||
break;
|
||||
case EAST:
|
||||
rh.setBounds( 11, 6, 6, 16 - len, 10, 10 );
|
||||
break;
|
||||
case NORTH:
|
||||
rh.setBounds( 6, 6, len, 10, 10, 5 );
|
||||
break;
|
||||
case SOUTH:
|
||||
rh.setBounds( 6, 6, 11, 10, 10, 16 - len );
|
||||
break;
|
||||
case UP:
|
||||
rh.setBounds( 6, 11, 6, 10, 16 - len, 10 );
|
||||
break;
|
||||
case WEST:
|
||||
rh.setBounds( len, 6, 6, 5, 10, 10 );
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
setSmartConnectionRotations( of, renderer );
|
||||
IIcon defa = new TaughtIcon( getChannelTex( channelsOnSide[of.ordinal()], false ).getIcon(), -0.2f );
|
||||
IIcon defb = new TaughtIcon( getChannelTex( channelsOnSide[of.ordinal()], true ).getIcon(), -0.2f );
|
||||
|
||||
if ( of == ForgeDirection.EAST || of == ForgeDirection.WEST )
|
||||
{
|
||||
AEBaseBlock blk = (AEBaseBlock) rh.getBlock();
|
||||
FlippableIcon ico = blk.getRendererInstance().getTexture( ForgeDirection.EAST );
|
||||
ico.setFlip( false, true );
|
||||
}
|
||||
|
||||
Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 );
|
||||
Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant );
|
||||
rh.setTexture( defa, defa, defa, defa, defa, defa );
|
||||
renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer );
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant );
|
||||
rh.setTexture( defb, defb, defb, defb, defb, defb );
|
||||
renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer );
|
||||
|
||||
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0;
|
||||
|
||||
rh.setTexture( getTexture( getCableColor() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( sides.size() != 2 || !nonLinear( sides ) || hasBuses )
|
||||
{
|
||||
for (ForgeDirection of : connections)
|
||||
{
|
||||
renderSmartConection( x, y, z, rh, renderer, channelsOnSide[of.ordinal()], of );
|
||||
}
|
||||
|
||||
rh.setTexture( getCoveredTexture( getCableColor() ) );
|
||||
rh.setBounds( 5, 5, 5, 11, 11, 11 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
}
|
||||
else
|
||||
{
|
||||
ForgeDirection selectedSide = ForgeDirection.UNKNOWN;
|
||||
|
||||
for (ForgeDirection of : connections)
|
||||
{
|
||||
selectedSide = of;
|
||||
break;
|
||||
}
|
||||
|
||||
int channels = channelsOnSide[selectedSide.ordinal()];
|
||||
IIcon def = getTexture( getCableColor() );
|
||||
IIcon off = new OffsetIcon( def, 0, -12 );
|
||||
|
||||
IIcon defa = new TaughtIcon( getChannelTex( channels, false ).getIcon(), -0.2f );
|
||||
IIcon offa = new OffsetIcon( defa, 0, -12 );
|
||||
|
||||
IIcon defb = new TaughtIcon( getChannelTex( channels, true ).getIcon(), -0.2f );
|
||||
IIcon offb = new OffsetIcon( defb, 0, -12 );
|
||||
|
||||
switch (selectedSide)
|
||||
{
|
||||
case DOWN:
|
||||
case UP:
|
||||
renderer.setRenderBounds( 5 / 16.0, 0, 5 / 16.0, 11 / 16.0, 16 / 16.0, 11 / 16.0 );
|
||||
rh.setTexture( def, def, off, off, off, off );
|
||||
rh.renderBlockCurrentBounds( x, y, z, renderer );
|
||||
|
||||
renderer.uvRotateTop = 0;
|
||||
renderer.uvRotateBottom = 0;
|
||||
renderer.uvRotateSouth = 3;
|
||||
renderer.uvRotateEast = 3;
|
||||
|
||||
Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 );
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant );
|
||||
rh.setTexture( defa, defa, offa, offa, offa, offa );
|
||||
renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer );
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant );
|
||||
rh.setTexture( defb, defb, offb, offb, offb, offb );
|
||||
renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer );
|
||||
break;
|
||||
case EAST:
|
||||
case WEST:
|
||||
rh.setTexture( off, off, off, off, def, def );
|
||||
renderer.uvRotateEast = 2;
|
||||
renderer.uvRotateWest = 1;
|
||||
renderer.uvRotateBottom = 2;
|
||||
renderer.uvRotateTop = 1;
|
||||
renderer.uvRotateSouth = 0;
|
||||
renderer.uvRotateNorth = 0;
|
||||
|
||||
AEBaseBlock blk = (AEBaseBlock) rh.getBlock();
|
||||
FlippableIcon ico = blk.getRendererInstance().getTexture( ForgeDirection.EAST );
|
||||
ico.setFlip( false, true );
|
||||
|
||||
renderer.setRenderBounds( 0, 5 / 16.0, 5 / 16.0, 16 / 16.0, 11 / 16.0, 11 / 16.0 );
|
||||
rh.renderBlockCurrentBounds( x, y, z, renderer );
|
||||
|
||||
Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 );
|
||||
|
||||
FlippableIcon fpA = new FlippableIcon( defa );
|
||||
FlippableIcon fpB = new FlippableIcon( defb );
|
||||
|
||||
fpA = new FlippableIcon( defa );
|
||||
fpB = new FlippableIcon( defb );
|
||||
|
||||
fpA.setFlip( true, false );
|
||||
fpB.setFlip( true, false );
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant );
|
||||
rh.setTexture( offa, offa, offa, offa, defa, fpA );
|
||||
renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer );
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant );
|
||||
rh.setTexture( offb, offb, offb, offb, defb, fpB );
|
||||
renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer );
|
||||
break;
|
||||
case NORTH:
|
||||
case SOUTH:
|
||||
rh.setTexture( off, off, def, def, off, off );
|
||||
renderer.uvRotateTop = 3;
|
||||
renderer.uvRotateBottom = 3;
|
||||
renderer.uvRotateNorth = 1;
|
||||
renderer.uvRotateSouth = 2;
|
||||
renderer.uvRotateWest = 1;
|
||||
renderer.setRenderBounds( 5 / 16.0, 5 / 16.0, 0, 11 / 16.0, 11 / 16.0, 16 / 16.0 );
|
||||
rh.renderBlockCurrentBounds( x, y, z, renderer );
|
||||
|
||||
Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 );
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant );
|
||||
rh.setTexture( offa, offa, defa, defa, offa, offa );
|
||||
renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer );
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant );
|
||||
rh.setTexture( offb, offb, defb, defb, offb, offb );
|
||||
renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0;
|
||||
rh.setTexture( null );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,501 @@
|
||||
package appeng.parts.networking;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import appeng.client.texture.FlippableIcon;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.parts.BusSupport;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.block.AEBaseBlock;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.client.texture.OffsetIcon;
|
||||
import appeng.client.texture.TaughtIcon;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartDenseCable extends PartCable
|
||||
{
|
||||
|
||||
@Override
|
||||
public BusSupport supportsBuses()
|
||||
{
|
||||
return BusSupport.DENSE_CABLE;
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void channelUpdated(MENetworkChannelsChanged c)
|
||||
{
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(MENetworkPowerStatusChange c)
|
||||
{
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
|
||||
public PartDenseCable(Class c, ItemStack is) {
|
||||
super( c, is );
|
||||
proxy.setFlags( GridFlags.DENSE_CAPACITY, GridFlags.PREFERRED );
|
||||
}
|
||||
|
||||
public PartDenseCable(ItemStack is) {
|
||||
this( PartDenseCable.class, is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType()
|
||||
{
|
||||
return AECableType.DENSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getTexture(AEColor c)
|
||||
{
|
||||
if ( c == AEColor.Transparent )
|
||||
return AEApi.instance().parts().partCableSmart.stack( AEColor.Transparent, 1 ).getIconIndex();
|
||||
|
||||
return getSmartTexture( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
GL11.glTranslated( -0.0, -0.0, 0.3 );
|
||||
rh.setBounds( 4.0f, 4.0f, 2.0f, 12.0f, 12.0f, 14.0f );
|
||||
|
||||
float offu = 0;
|
||||
float offv = 9;
|
||||
|
||||
OffsetIcon main = new OffsetIcon( getTexture( getCableColor() ), offu, offv );
|
||||
OffsetIcon ch1 = new OffsetIcon( getChannelTex( 4, false ).getIcon(), offu, offv );
|
||||
OffsetIcon ch2 = new OffsetIcon( getChannelTex( 4, true ).getIcon(), offu, offv );
|
||||
|
||||
for (ForgeDirection side : EnumSet.of( ForgeDirection.UP, ForgeDirection.DOWN ))
|
||||
{
|
||||
rh.renderInventoryFace( main, side, renderer );
|
||||
rh.renderInventoryFace( ch1, side, renderer );
|
||||
rh.renderInventoryFace( ch2, side, renderer );
|
||||
}
|
||||
|
||||
offu = 9;
|
||||
offv = 0;
|
||||
main = new OffsetIcon( getTexture( getCableColor() ), offu, offv );
|
||||
ch1 = new OffsetIcon( getChannelTex( 4, false ).getIcon(), offu, offv );
|
||||
ch2 = new OffsetIcon( getChannelTex( 4, true ).getIcon(), offu, offv );
|
||||
|
||||
for (ForgeDirection side : EnumSet.of( ForgeDirection.EAST, ForgeDirection.WEST ))
|
||||
{
|
||||
rh.renderInventoryFace( main, side, renderer );
|
||||
rh.renderInventoryFace( ch1, side, renderer );
|
||||
rh.renderInventoryFace( ch2, side, renderer );
|
||||
}
|
||||
|
||||
main = new OffsetIcon( getTexture( getCableColor() ), 0, 0 );
|
||||
ch1 = new OffsetIcon( getChannelTex( 4, false ).getIcon(), 0, 0 );
|
||||
ch2 = new OffsetIcon( getChannelTex( 4, true ).getIcon(), 0, 0 );
|
||||
|
||||
for (ForgeDirection side : EnumSet.of( ForgeDirection.SOUTH, ForgeDirection.NORTH ))
|
||||
{
|
||||
rh.renderInventoryFace( main, side, renderer );
|
||||
rh.renderInventoryFace( ch1, side, renderer );
|
||||
rh.renderInventoryFace( ch2, side, renderer );
|
||||
}
|
||||
|
||||
rh.setTexture( null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(IPartCollisionHelper bch)
|
||||
{
|
||||
boolean noLadder = !bch.isBBCollision();
|
||||
double min = noLadder ? 3.0 : 4.9;
|
||||
double max = noLadder ? 13.0 : 11.1;
|
||||
|
||||
bch.addBox( min, min, min, max, max, max );
|
||||
|
||||
if ( Platform.isServer() )
|
||||
{
|
||||
IGridNode n = getGridNode();
|
||||
if ( n != null )
|
||||
connections = n.getConnectedSides();
|
||||
else
|
||||
connections.clear();
|
||||
}
|
||||
|
||||
for (ForgeDirection of : connections)
|
||||
{
|
||||
if ( isDense( of ) )
|
||||
{
|
||||
switch (of)
|
||||
{
|
||||
case DOWN:
|
||||
bch.addBox( min, 0.0, min, max, min, max );
|
||||
break;
|
||||
case EAST:
|
||||
bch.addBox( max, min, min, 16.0, max, max );
|
||||
break;
|
||||
case NORTH:
|
||||
bch.addBox( min, min, 0.0, max, max, min );
|
||||
break;
|
||||
case SOUTH:
|
||||
bch.addBox( min, min, max, max, max, 16.0 );
|
||||
break;
|
||||
case UP:
|
||||
bch.addBox( min, max, min, max, 16.0, max );
|
||||
break;
|
||||
case WEST:
|
||||
bch.addBox( 0.0, min, min, min, max, max );
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (of)
|
||||
{
|
||||
case DOWN:
|
||||
bch.addBox( 5.0, 0.0, 5.0, 11.0, 5.0, 11.0 );
|
||||
break;
|
||||
case EAST:
|
||||
bch.addBox( 11.0, 5.0, 5.0, 16.0, 11.0, 11.0 );
|
||||
break;
|
||||
case NORTH:
|
||||
bch.addBox( 5.0, 5.0, 0.0, 11.0, 11.0, 5.0 );
|
||||
break;
|
||||
case SOUTH:
|
||||
bch.addBox( 5.0, 5.0, 11.0, 11.0, 11.0, 16.0 );
|
||||
break;
|
||||
case UP:
|
||||
bch.addBox( 5.0, 11.0, 5.0, 11.0, 16.0, 11.0 );
|
||||
break;
|
||||
case WEST:
|
||||
bch.addBox( 0.0, 5.0, 5.0, 5.0, 11.0, 11.0 );
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDense(ForgeDirection of)
|
||||
{
|
||||
TileEntity te = tile.getWorldObj().getTileEntity( tile.xCoord + of.offsetX, tile.yCoord + of.offsetY, tile.zCoord + of.offsetZ );
|
||||
if ( te instanceof IGridHost )
|
||||
{
|
||||
AECableType t = ((IGridHost) te).getCableConnectionType( of.getOpposite() );
|
||||
return t == AECableType.DENSE;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isSmart(ForgeDirection of)
|
||||
{
|
||||
TileEntity te = tile.getWorldObj().getTileEntity( tile.xCoord + of.offsetX, tile.yCoord + of.offsetY, tile.zCoord + of.offsetZ );
|
||||
if ( te instanceof IGridHost )
|
||||
{
|
||||
AECableType t = ((IGridHost) te).getCableConnectionType( of.getOpposite() );
|
||||
return t == AECableType.SMART;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderDenseConnection(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer, int channels, ForgeDirection of)
|
||||
{
|
||||
TileEntity te = this.tile.getWorldObj().getTileEntity( x + of.offsetX, y + of.offsetY, z + of.offsetZ );
|
||||
IPartHost ccph = te instanceof IPartHost ? (IPartHost) te : null;
|
||||
IGridHost ghh = te instanceof IGridHost ? (IGridHost) te : null;
|
||||
boolean isGlass = false;
|
||||
AEColor myColor = getCableColor();
|
||||
/*
|
||||
* ( ghh != null && ccph != null && ghh.getCableConnectionType( of ) == AECableType.GLASS && ccph.getPart(
|
||||
* of.getOpposite() ) == null ) { isGlass = true; rh.setTexture( getGlassTexture( myColor = ccph.getColor() ) );
|
||||
* } else if ( ccph == null && ghh != null && ghh.getCableConnectionType( of ) != AECableType.GLASS ) {
|
||||
* rh.setTexture( getSmartTexture( myColor ) ); switch (of) { case DOWN: rh.setBounds( 3, 0, 3, 13, 4, 13 );
|
||||
* break; case EAST: rh.setBounds( 12, 3, 3, 16, 13, 13 ); break; case NORTH: rh.setBounds( 3, 3, 0, 13, 13, 4
|
||||
* ); break; case SOUTH: rh.setBounds( 3, 3, 12, 13, 13, 16 ); break; case UP: rh.setBounds( 3, 12, 3, 13, 16,
|
||||
* 13 ); break; case WEST: rh.setBounds( 0, 3, 3, 4, 13, 13 ); break; default: return; } rh.renderBlock( x, y,
|
||||
* z, renderer );
|
||||
*
|
||||
* if ( true ) { setSmartConnectionRotations( of, renderer ); IIcon defa = new TaughtIcon( getChannelTex(
|
||||
* channels, false ).getIcon(), -0.2f ); IIcon defb = new TaughtIcon( getChannelTex( channels, true ).getIcon(),
|
||||
* -0.2f );
|
||||
*
|
||||
* if ( of == ForgeDirection.EAST || of == ForgeDirection.WEST ) { AEBaseBlock blk = (AEBaseBlock)
|
||||
* rh.getBlock(); FlippableIcon ico = blk.getRendererInstance().getTexture( ForgeDirection.EAST ); ico.setFlip(
|
||||
* false, true ); }
|
||||
*
|
||||
* Tessellator.instance.setBrightness( 15 << 20 | 15 << 5 ); Tessellator.instance.setColorOpaque_I(
|
||||
* myColor.mediumVariant ); rh.setTexture( defa, defa, defa, defa, defa, defa ); renderAllFaces( (AEBaseBlock)
|
||||
* rh.getBlock(), x, y, z, renderer );
|
||||
*
|
||||
* Tessellator.instance.setColorOpaque_I( myColor.whiteVariant ); rh.setTexture( defb, defb, defb, defb, defb,
|
||||
* defb ); renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, renderer );
|
||||
*
|
||||
* renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth =
|
||||
* renderer.uvRotateTop = renderer.uvRotateWest = 0; }
|
||||
*
|
||||
* rh.setTexture( getTexture( getCableColor() ) ); }
|
||||
*/
|
||||
|
||||
rh.setFacesToRender( EnumSet.complementOf( EnumSet.of( of, of.getOpposite() ) ) );
|
||||
if ( ghh != null && ccph != null && ghh.getCableConnectionType( of ) != AECableType.GLASS && ccph.getColor() != AEColor.Transparent
|
||||
&& ccph.getPart( of.getOpposite() ) == null )
|
||||
rh.setTexture( getTexture( myColor = ccph.getColor() ) );
|
||||
else
|
||||
rh.setTexture( getTexture( getCableColor() ) );
|
||||
|
||||
switch (of)
|
||||
{
|
||||
case DOWN:
|
||||
rh.setBounds( 4, 0, 4, 12, 5, 12 );
|
||||
break;
|
||||
case EAST:
|
||||
rh.setBounds( 11, 4, 4, 16, 12, 12 );
|
||||
break;
|
||||
case NORTH:
|
||||
rh.setBounds( 4, 4, 0, 12, 12, 5 );
|
||||
break;
|
||||
case SOUTH:
|
||||
rh.setBounds( 4, 4, 11, 12, 12, 16 );
|
||||
break;
|
||||
case UP:
|
||||
rh.setBounds( 4, 11, 4, 12, 16, 12 );
|
||||
break;
|
||||
case WEST:
|
||||
rh.setBounds( 0, 4, 4, 5, 12, 12 );
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) );
|
||||
if ( !isGlass )
|
||||
{
|
||||
setSmartConnectionRotations( of, renderer );
|
||||
|
||||
IIcon defa = new TaughtIcon( getChannelTex( channels, false ).getIcon(), -0.2f );
|
||||
IIcon defb = new TaughtIcon( getChannelTex( channels, true ).getIcon(), -0.2f );
|
||||
|
||||
Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 );
|
||||
Tessellator.instance.setColorOpaque_I( myColor.blackVariant );
|
||||
rh.setTexture( defa, defa, defa, defa, defa, defa );
|
||||
renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer );
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( myColor.whiteVariant );
|
||||
rh.setTexture( defb, defb, defb, defb, defb, defb );
|
||||
renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer );
|
||||
|
||||
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache );
|
||||
rh.setTexture( getTexture( getCableColor() ) );
|
||||
|
||||
EnumSet<ForgeDirection> sides = connections.clone();
|
||||
|
||||
boolean hasBuses = false;
|
||||
for (ForgeDirection of : connections)
|
||||
{
|
||||
if ( !isDense( of ) )
|
||||
hasBuses = true;
|
||||
}
|
||||
|
||||
if ( sides.size() != 2 || !nonLinear( sides ) || hasBuses )
|
||||
{
|
||||
for (ForgeDirection of : connections)
|
||||
{
|
||||
if ( isDense( of ) )
|
||||
renderDenseConnection( x, y, z, rh, renderer, channelsOnSide[of.ordinal()], of );
|
||||
else if ( isSmart( of ) )
|
||||
renderSmartConection( x, y, z, rh, renderer, channelsOnSide[of.ordinal()], of );
|
||||
else
|
||||
renderCoveredConnection( x, y, z, rh, renderer, channelsOnSide[of.ordinal()], of );
|
||||
}
|
||||
|
||||
rh.setTexture( getDenseTexture( getCableColor() ) );
|
||||
rh.setBounds( 3, 3, 3, 13, 13, 13 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
}
|
||||
else
|
||||
{
|
||||
ForgeDirection selectedSide = ForgeDirection.UNKNOWN;
|
||||
|
||||
for (ForgeDirection of : connections)
|
||||
{
|
||||
selectedSide = of;
|
||||
break;
|
||||
}
|
||||
|
||||
int channels = channelsOnSide[selectedSide.ordinal()];
|
||||
IIcon def = getTexture( getCableColor() );
|
||||
IIcon off = new OffsetIcon( def, 0, -12 );
|
||||
|
||||
IIcon defa = new TaughtIcon( getChannelTex( channels, false ).getIcon(), -0.2f );
|
||||
IIcon offa = new OffsetIcon( defa, 0, -12 );
|
||||
|
||||
IIcon defb = new TaughtIcon( getChannelTex( channels, true ).getIcon(), -0.2f );
|
||||
IIcon offb = new OffsetIcon( defb, 0, -12 );
|
||||
|
||||
switch (selectedSide)
|
||||
{
|
||||
case DOWN:
|
||||
case UP:
|
||||
renderer.setRenderBounds( 3 / 16.0, 0, 3 / 16.0, 13 / 16.0, 16 / 16.0, 13 / 16.0 );
|
||||
rh.setTexture( def, def, off, off, off, off );
|
||||
rh.renderBlockCurrentBounds( x, y, z, renderer );
|
||||
|
||||
renderer.uvRotateTop = 0;
|
||||
renderer.uvRotateBottom = 0;
|
||||
renderer.uvRotateSouth = 3;
|
||||
renderer.uvRotateEast = 3;
|
||||
|
||||
Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 );
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant );
|
||||
rh.setTexture( defa, defa, offa, offa, offa, offa );
|
||||
renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer );
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant );
|
||||
rh.setTexture( defb, defb, offb, offb, offb, offb );
|
||||
renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer );
|
||||
break;
|
||||
case EAST:
|
||||
case WEST:
|
||||
rh.setTexture( off, off, off, off, def, def );
|
||||
renderer.uvRotateEast = 2;
|
||||
renderer.uvRotateWest = 1;
|
||||
renderer.uvRotateBottom = 2;
|
||||
renderer.uvRotateTop = 1;
|
||||
renderer.uvRotateSouth = 0;
|
||||
renderer.uvRotateNorth = 0;
|
||||
|
||||
AEBaseBlock blk = (AEBaseBlock) rh.getBlock();
|
||||
FlippableIcon ico = blk.getRendererInstance().getTexture( ForgeDirection.EAST );
|
||||
ico.setFlip( false, true );
|
||||
|
||||
renderer.setRenderBounds( 0, 3 / 16.0, 3 / 16.0, 16 / 16.0, 13 / 16.0, 13 / 16.0 );
|
||||
rh.renderBlockCurrentBounds( x, y, z, renderer );
|
||||
|
||||
Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 );
|
||||
|
||||
FlippableIcon fpA = new FlippableIcon( defa );
|
||||
FlippableIcon fpB = new FlippableIcon( defb );
|
||||
|
||||
fpA = new FlippableIcon( defa );
|
||||
fpB = new FlippableIcon( defb );
|
||||
|
||||
fpA.setFlip( true, false );
|
||||
fpB.setFlip( true, false );
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant );
|
||||
rh.setTexture( offa, offa, offa, offa, defa, fpA );
|
||||
renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer );
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant );
|
||||
rh.setTexture( offb, offb, offb, offb, defb, fpB );
|
||||
renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer );
|
||||
break;
|
||||
case NORTH:
|
||||
case SOUTH:
|
||||
rh.setTexture( off, off, def, def, off, off );
|
||||
renderer.uvRotateTop = 3;
|
||||
renderer.uvRotateBottom = 3;
|
||||
renderer.uvRotateNorth = 1;
|
||||
renderer.uvRotateSouth = 2;
|
||||
renderer.uvRotateWest = 1;
|
||||
renderer.setRenderBounds( 3 / 16.0, 3 / 16.0, 0, 13 / 16.0, 13 / 16.0, 16 / 16.0 );
|
||||
rh.renderBlockCurrentBounds( x, y, z, renderer );
|
||||
|
||||
Tessellator.instance.setBrightness( 15 << 20 | 15 << 4 );
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( getCableColor().blackVariant );
|
||||
rh.setTexture( offa, offa, defa, defa, offa, offa );
|
||||
renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer );
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( getCableColor().whiteVariant );
|
||||
rh.setTexture( offb, offb, defb, defb, offb, offb );
|
||||
renderAllFaces( (AEBaseBlock) rh.getBlock(), x, y, z, rh, renderer );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0;
|
||||
rh.setTexture( null );
|
||||
}
|
||||
|
||||
private IIcon getDenseTexture(AEColor c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case Black:
|
||||
return CableBusTextures.MEDense_Black.getIcon();
|
||||
case Blue:
|
||||
return CableBusTextures.MEDense_Blue.getIcon();
|
||||
case Brown:
|
||||
return CableBusTextures.MEDense_Brown.getIcon();
|
||||
case Cyan:
|
||||
return CableBusTextures.MEDense_Cyan.getIcon();
|
||||
case Gray:
|
||||
return CableBusTextures.MEDense_Gray.getIcon();
|
||||
case Green:
|
||||
return CableBusTextures.MEDense_Green.getIcon();
|
||||
case LightBlue:
|
||||
return CableBusTextures.MEDense_LightBlue.getIcon();
|
||||
case LightGray:
|
||||
return CableBusTextures.MEDense_LightGrey.getIcon();
|
||||
case Lime:
|
||||
return CableBusTextures.MEDense_Lime.getIcon();
|
||||
case Magenta:
|
||||
return CableBusTextures.MEDense_Magenta.getIcon();
|
||||
case Orange:
|
||||
return CableBusTextures.MEDense_Orange.getIcon();
|
||||
case Pink:
|
||||
return CableBusTextures.MEDense_Pink.getIcon();
|
||||
case Purple:
|
||||
return CableBusTextures.MEDense_Purple.getIcon();
|
||||
case Red:
|
||||
return CableBusTextures.MEDense_Red.getIcon();
|
||||
case White:
|
||||
return CableBusTextures.MEDense_White.getIcon();
|
||||
case Yellow:
|
||||
return CableBusTextures.MEDense_Yellow.getIcon();
|
||||
default:
|
||||
}
|
||||
|
||||
return is.getIconIndex();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
package appeng.parts.networking;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
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.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.energy.IEnergyGridProvider;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.helpers.AENetworkProxy;
|
||||
import appeng.parts.AEBasePart;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartQuartzFiber extends AEBasePart implements IEnergyGridProvider
|
||||
{
|
||||
|
||||
AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", proxy.getMachineRepresentation(), true );
|
||||
|
||||
public PartQuartzFiber(ItemStack is) {
|
||||
super( PartQuartzFiber.class, is );
|
||||
proxy.setIdlePowerUsage( 0 );
|
||||
proxy.setFlags( GridFlags.CANNOT_CARRY );
|
||||
outerProxy.setIdlePowerUsage( 0 );
|
||||
outerProxy.setFlags( GridFlags.CANNOT_CARRY );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side)
|
||||
{
|
||||
super.onPlacement( player, held, side );
|
||||
outerProxy.setOwner( player );
|
||||
}
|
||||
|
||||
@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.GLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
IIcon myIcon = is.getIconIndex();
|
||||
rh.setTexture( myIcon );
|
||||
rh.setBounds( 6, 6, 10, 10, 10, 16 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
rh.setTexture( null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(IPartCollisionHelper bch)
|
||||
{
|
||||
bch.addBox( 6, 6, 10, 10, 10, 16 );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
GL11.glTranslated( -0.2, -0.3, 0.0 );
|
||||
|
||||
rh.setTexture( is.getIconIndex() );
|
||||
rh.setBounds( 6.0f, 6.0f, 5.0f, 10.0f, 10.0f, 11.0f );
|
||||
rh.renderInventoryBox( renderer );
|
||||
rh.setTexture( null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public double extractAEPower(double amt, Actionable mode, Set<IEnergyGrid> seen)
|
||||
{
|
||||
double acquiredPower = 0;
|
||||
|
||||
try
|
||||
{
|
||||
IEnergyGrid eg = proxy.getEnergy();
|
||||
acquiredPower += eg.extractAEPower( amt - acquiredPower, mode, seen );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
IEnergyGrid eg = outerProxy.getEnergy();
|
||||
acquiredPower += eg.extractAEPower( amt - acquiredPower, mode, seen );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
return acquiredPower;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double injectAEPower(double amt, Actionable mode, Set<IEnergyGrid> seen)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
IEnergyGrid eg = proxy.getEnergy();
|
||||
if ( !seen.contains( eg ) )
|
||||
return eg.injectAEPower( amt, mode, seen );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
IEnergyGrid eg = outerProxy.getEnergy();
|
||||
if ( !seen.contains( eg ) )
|
||||
return eg.injectAEPower( amt, mode, seen );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
return amt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cableConnectionRenderTo()
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getEnergyDemand(double amt, Set<IEnergyGrid> seen)
|
||||
{
|
||||
double demand = 0;
|
||||
|
||||
try
|
||||
{
|
||||
IEnergyGrid eg = proxy.getEnergy();
|
||||
demand += eg.getEnergyDemand( amt - demand, seen );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
IEnergyGrid eg = outerProxy.getEnergy();
|
||||
demand += eg.getEnergyDemand( amt - demand, seen );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
return demand;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,442 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.config.TunnelType;
|
||||
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.AppEng;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.integration.abstraction.IMJ5;
|
||||
import appeng.integration.abstraction.IMJ6;
|
||||
import appeng.integration.abstraction.helpers.BaseMJperdition;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cache.helpers.TunnelCollection;
|
||||
import appeng.transformer.annotations.integration.Interface;
|
||||
import appeng.transformer.annotations.integration.InterfaceList;
|
||||
import appeng.transformer.annotations.integration.Method;
|
||||
import buildcraft.api.mj.IBatteryObject;
|
||||
import buildcraft.api.mj.ISidedBatteryProvider;
|
||||
import buildcraft.api.mj.MjAPI;
|
||||
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;
|
||||
|
||||
@InterfaceList(value = { @Interface(iface = "buildcraft.api.mj.ISidedBatteryProvider", iname = "MJ6"),
|
||||
@Interface(iface = "buildcraft.api.mj.IBatteryObject", iname = "MJ6"), @Interface(iface = "buildcraft.api.power.IPowerReceptor", iname = "MJ5"),
|
||||
@Interface(iface = "appeng.api.networking.ticking.IGridTickable", iname = "MJ5") })
|
||||
public class PartP2PBCPower extends PartP2PTunnel<PartP2PBCPower> implements IPowerReceptor, ISidedBatteryProvider, IBatteryObject, IGridTickable
|
||||
{
|
||||
|
||||
BaseMJperdition pp;
|
||||
|
||||
public TunnelType getTunnelType()
|
||||
{
|
||||
return TunnelType.BC_POWER;
|
||||
}
|
||||
|
||||
public PartP2PBCPower(ItemStack is) {
|
||||
super( is );
|
||||
|
||||
if ( !AppEng.instance.isIntegrationEnabled( IntegrationType.MJ5 ) && !AppEng.instance.isIntegrationEnabled( IntegrationType.MJ6 ) )
|
||||
throw new RuntimeException( "MJ Not installed!" );
|
||||
|
||||
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.MJ5 ) )
|
||||
{
|
||||
pp = (BaseMJperdition) ((IMJ5) AppEng.instance.getIntegration( IntegrationType.MJ5 )).createPerdition( this );
|
||||
if ( pp != null )
|
||||
pp.configure( 1, 380, 1.0f / 5.0f, 1000 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(iname = "MJ5")
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
return new TickingRequest( TickRates.MJTunnel.min, TickRates.MJTunnel.max, false, false );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(iname = "MJ5")
|
||||
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 )
|
||||
{
|
||||
double 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;
|
||||
|
||||
double currentTotal = pp.getPowerReceiver().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 )
|
||||
{
|
||||
double howmuch = tp.powerRequest();
|
||||
|
||||
if ( howmuch > tp.getMaxEnergyReceived() )
|
||||
howmuch = tp.getMaxEnergyReceived();
|
||||
|
||||
if ( howmuch > 0.01 && howmuch > tp.getMinEnergyReceived() )
|
||||
{
|
||||
double toPull = currentTotal * (howmuch / totalRequiredPower);
|
||||
double pulled = pp.useEnergy( 0, toPull, true );
|
||||
QueueTunnelDrain( PowerUnits.MJ, pulled );
|
||||
|
||||
tp.receiveEnergy( Type.PIPE, pulled, o.side.getOpposite() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TickRateModulation.FASTER;
|
||||
}
|
||||
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
return 0.5f;
|
||||
};
|
||||
|
||||
@Method(iname = "MJ6")
|
||||
private IBatteryObject getTargetBattery()
|
||||
{
|
||||
TileEntity te = getWorld().getTileEntity( tile.xCoord + side.offsetX, tile.yCoord + side.offsetY, tile.zCoord + side.offsetZ );
|
||||
if ( te != null )
|
||||
{
|
||||
IBatteryObject bo = MjAPI.getMjBattery( te, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite() );
|
||||
if ( bo != null )
|
||||
return bo;
|
||||
|
||||
return ((IMJ6) AppEng.instance.getIntegration( IntegrationType.MJ6 )).provider( te, side.getOpposite() );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Method(iname = "MJ5")
|
||||
private IPowerReceptor getPowerTarget()
|
||||
{
|
||||
TileEntity te = getWorld().getTileEntity( 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 );
|
||||
if ( pp != null )
|
||||
pp.writeToNBT( tag );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.readFromNBT( tag );
|
||||
if ( pp != null )
|
||||
pp.readFromNBT( tag );
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getTypeTexture()
|
||||
{
|
||||
return Blocks.emerald_block.getBlockTextureFromSide( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(iname = "MJ5")
|
||||
public PowerReceiver getPowerReceiver(ForgeDirection side)
|
||||
{
|
||||
if ( side.equals( side ) )
|
||||
return ((BaseMJperdition) pp).getPowerReceiver();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(iname = "MJ5")
|
||||
public void doWork(PowerHandler workProvider)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
{
|
||||
return tile.getWorldObj();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(iname = "MJ6")
|
||||
public IBatteryObject getMjBattery(String kind, ForgeDirection direction)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(iname = "MJ6")
|
||||
public double getEnergyRequested()
|
||||
{
|
||||
try
|
||||
{
|
||||
double totalRequiredPower = 0.0f;
|
||||
|
||||
for (PartP2PBCPower g : getOutputs())
|
||||
{
|
||||
IBatteryObject o = g.getTargetBattery();
|
||||
if ( o != null )
|
||||
totalRequiredPower += o.getEnergyRequested();
|
||||
}
|
||||
|
||||
return totalRequiredPower;
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(iname = "MJ6")
|
||||
public double addEnergy(double mj)
|
||||
{
|
||||
return addEnergyInternal( mj, false, false );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(iname = "MJ6")
|
||||
public double addEnergy(double mj, boolean ignoreCycleLimit)
|
||||
{
|
||||
return addEnergyInternal( mj, true, ignoreCycleLimit );
|
||||
}
|
||||
|
||||
@Method(iname = "MJ6")
|
||||
private double addEnergyInternal(double mj, boolean cycleLimitMode, boolean ignoreCycleLimit)
|
||||
{
|
||||
if ( output || !proxy.isActive() )
|
||||
return 0;
|
||||
|
||||
double originalInput = mj;
|
||||
|
||||
try
|
||||
{
|
||||
TunnelCollection<PartP2PBCPower> outs = getOutputs();
|
||||
|
||||
double outputs = 0;
|
||||
for (PartP2PBCPower g : outs)
|
||||
{
|
||||
IBatteryObject o = g.getTargetBattery();
|
||||
if ( o != null )
|
||||
{
|
||||
outputs = outputs + 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
if ( outputs < 0.0000001 )
|
||||
return 0;
|
||||
|
||||
for (PartP2PBCPower g : outs)
|
||||
{
|
||||
IBatteryObject o = g.getTargetBattery();
|
||||
if ( o != null )
|
||||
{
|
||||
double fraction = originalInput / outputs;
|
||||
if ( cycleLimitMode )
|
||||
fraction = o.addEnergy( fraction );
|
||||
else
|
||||
fraction = o.addEnergy( fraction, ignoreCycleLimit );
|
||||
mj -= fraction;
|
||||
}
|
||||
}
|
||||
|
||||
if ( mj > 0 )
|
||||
{
|
||||
for (PartP2PBCPower g : outs)
|
||||
{
|
||||
IBatteryObject o = g.getTargetBattery();
|
||||
if ( o != null )
|
||||
{
|
||||
if ( cycleLimitMode )
|
||||
mj = mj - o.addEnergy( mj );
|
||||
else
|
||||
mj = mj - o.addEnergy( mj, ignoreCycleLimit );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return originalInput - mj;
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(iname = "MJ6")
|
||||
public double getEnergyStored()
|
||||
{
|
||||
try
|
||||
{
|
||||
double totalRequiredPower = 0.0f;
|
||||
|
||||
for (PartP2PBCPower g : getOutputs())
|
||||
{
|
||||
IBatteryObject o = g.getTargetBattery();
|
||||
if ( o != null )
|
||||
totalRequiredPower += o.getEnergyStored();
|
||||
}
|
||||
|
||||
return totalRequiredPower;
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(iname = "MJ6")
|
||||
public void setEnergyStored(double mj)
|
||||
{
|
||||
// EHh?!
|
||||
}
|
||||
|
||||
@Override
|
||||
public double maxCapacity()
|
||||
{
|
||||
try
|
||||
{
|
||||
double totalRequiredPower = 0.0f;
|
||||
|
||||
for (PartP2PBCPower g : getOutputs())
|
||||
{
|
||||
IBatteryObject o = g.getTargetBattery();
|
||||
if ( o != null )
|
||||
totalRequiredPower += o.maxCapacity();
|
||||
}
|
||||
|
||||
return totalRequiredPower;
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(iname = "MJ6")
|
||||
public double minimumConsumption()
|
||||
{
|
||||
try
|
||||
{
|
||||
double totalRequiredPower = 1000000000000.0;
|
||||
|
||||
for (PartP2PBCPower g : getOutputs())
|
||||
{
|
||||
IBatteryObject o = g.getTargetBattery();
|
||||
if ( o != null )
|
||||
totalRequiredPower = Math.min( totalRequiredPower, o.minimumConsumption() );
|
||||
}
|
||||
|
||||
return totalRequiredPower;
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(iname = "MJ6")
|
||||
public double maxReceivedPerCycle()
|
||||
{
|
||||
try
|
||||
{
|
||||
double totalRequiredPower = 1000000.0;
|
||||
|
||||
for (PartP2PBCPower g : getOutputs())
|
||||
{
|
||||
IBatteryObject o = g.getTargetBattery();
|
||||
if ( o != null )
|
||||
totalRequiredPower = Math.min( totalRequiredPower, o.maxReceivedPerCycle() );
|
||||
}
|
||||
|
||||
return totalRequiredPower;
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(iname = "MJ6")
|
||||
public IBatteryObject reconfigure(double maxCapacity, double maxReceivedPerCycle, double minimumConsumption)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(iname = "MJ6")
|
||||
public String kind()
|
||||
{
|
||||
return "tunnel";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.config.TunnelType;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cache.helpers.TunnelCollection;
|
||||
import appeng.transformer.annotations.integration.Interface;
|
||||
import appeng.transformer.annotations.integration.InterfaceList;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@InterfaceList(value = { @Interface(iface = "ic2.api.energy.tile.IEnergySink", iname = "IC2"),
|
||||
@Interface(iface = "ic2.api.energy.tile.IEnergySource", iname = "IC2") })
|
||||
public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements ic2.api.energy.tile.IEnergySink, ic2.api.energy.tile.IEnergySource
|
||||
{
|
||||
|
||||
public TunnelType getTunnelType()
|
||||
{
|
||||
return TunnelType.IC2_POWER;
|
||||
}
|
||||
|
||||
public PartP2PIC2Power(ItemStack is) {
|
||||
super( is );
|
||||
|
||||
if ( !AppEng.instance.isIntegrationEnabled( IntegrationType.IC2 ) )
|
||||
throw new RuntimeException( "IC2 Not installed!" );
|
||||
}
|
||||
|
||||
// two packet buffering...
|
||||
double OutputEnergyA;
|
||||
double OutputEnergyB;
|
||||
|
||||
// two packet buffering...
|
||||
double OutputVoltageA;
|
||||
double OutputVoltageB;
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.writeToNBT( tag );
|
||||
tag.setDouble( "OutputPacket", OutputEnergyA );
|
||||
tag.setDouble( "OutputPacket2", OutputEnergyB );
|
||||
tag.setDouble( "OutputVoltageA", OutputVoltageA );
|
||||
tag.setDouble( "OutputVoltageB", OutputVoltageB );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.readFromNBT( tag );
|
||||
OutputEnergyA = tag.getDouble( "OutputPacket" );
|
||||
OutputEnergyB = tag.getDouble( "OutputPacket2" );
|
||||
OutputVoltageA = tag.getDouble( "OutputVoltageA" );
|
||||
OutputVoltageB = tag.getDouble( "OutputVoltageB" );
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getTypeTexture()
|
||||
{
|
||||
return Blocks.diamond_block.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 getDemandedEnergy()
|
||||
{
|
||||
if ( output )
|
||||
return 0;
|
||||
|
||||
try
|
||||
{
|
||||
for (PartP2PIC2Power t : getOutputs())
|
||||
{
|
||||
if ( t.OutputEnergyA <= 0.0001 || t.OutputEnergyB <= 0.0001 )
|
||||
{
|
||||
return 2048;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
getHost().notifyNeighbors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelConfigChange()
|
||||
{
|
||||
getHost().partChanged();
|
||||
}
|
||||
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
return 0.5f;
|
||||
};
|
||||
|
||||
@Override
|
||||
public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage)
|
||||
{
|
||||
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.OutputEnergyA <= 0.01 )
|
||||
Options.add( o );
|
||||
}
|
||||
|
||||
if ( Options.isEmpty() )
|
||||
{
|
||||
for (PartP2PIC2Power o : outs)
|
||||
if ( o.OutputEnergyB <= 0.01 )
|
||||
Options.add( o );
|
||||
}
|
||||
|
||||
if ( Options.isEmpty() )
|
||||
{
|
||||
for (PartP2PIC2Power o : outs)
|
||||
Options.add( o );
|
||||
}
|
||||
|
||||
if ( Options.isEmpty() )
|
||||
return amount;
|
||||
|
||||
PartP2PIC2Power x = (PartP2PIC2Power) Platform.pickRandom( Options );
|
||||
|
||||
if ( x != null && x.OutputEnergyA <= 0.001 )
|
||||
{
|
||||
QueueTunnelDrain( PowerUnits.EU, amount );
|
||||
x.OutputEnergyA = amount;
|
||||
x.OutputVoltageA = voltage;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( x != null && x.OutputEnergyB <= 0.001 )
|
||||
{
|
||||
QueueTunnelDrain( PowerUnits.EU, amount );
|
||||
x.OutputEnergyB = amount;
|
||||
x.OutputVoltageB = voltage;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSinkTier()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getOfferedEnergy()
|
||||
{
|
||||
if ( output )
|
||||
return OutputEnergyA;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEnergy(double amount)
|
||||
{
|
||||
OutputEnergyA -= amount;
|
||||
if ( OutputEnergyA < 0.001 )
|
||||
{
|
||||
OutputEnergyA = OutputEnergyB;
|
||||
OutputEnergyB = 0;
|
||||
|
||||
OutputVoltageA = OutputVoltageB;
|
||||
OutputVoltageB = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSourceTier()
|
||||
{
|
||||
if ( output )
|
||||
return calculateTierFromVoltage( OutputVoltageA );
|
||||
return 4;
|
||||
}
|
||||
|
||||
private int calculateTierFromVoltage(double voltage)
|
||||
{
|
||||
return ic2.api.energy.EnergyNet.instance.getTierFromPower( voltage );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,362 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
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.IIcon;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.TunnelType;
|
||||
import appeng.api.networking.IGridNode;
|
||||
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.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.integration.abstraction.IBC;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cache.helpers.TunnelCollection;
|
||||
import appeng.tile.inventory.AppEngNullInventory;
|
||||
import appeng.transformer.annotations.integration.Interface;
|
||||
import appeng.transformer.annotations.integration.Method;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.WrapperBCPipe;
|
||||
import appeng.util.inv.WrapperChainedInventory;
|
||||
import appeng.util.inv.WrapperMCISidedInventory;
|
||||
import buildcraft.api.transport.IPipeConnection;
|
||||
import buildcraft.api.transport.IPipeTile.PipeType;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@Interface(iface = "buildcraft.api.transport.IPipeConnection", iname = "BC")
|
||||
public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements IPipeConnection, IInventory, ISidedInventory, IGridTickable
|
||||
{
|
||||
|
||||
public TunnelType getTunnelType()
|
||||
{
|
||||
return TunnelType.ITEM;
|
||||
}
|
||||
|
||||
public PartP2PItems(ItemStack is) {
|
||||
super( is );
|
||||
}
|
||||
|
||||
int oldSize = 0;
|
||||
boolean requested;
|
||||
IInventory cachedInv;
|
||||
|
||||
LinkedList<IInventory> which = new LinkedList<IInventory>();
|
||||
|
||||
IInventory getOutputInv()
|
||||
{
|
||||
IInventory output = null;
|
||||
|
||||
if ( proxy.isActive() )
|
||||
{
|
||||
TileEntity te = tile.getWorldObj().getTileEntity( 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( IntegrationType.BC ) )
|
||||
{
|
||||
IBC buildcraft = (IBC) AppEng.instance.getIntegration( IntegrationType.BC );
|
||||
if ( buildcraft != null )
|
||||
{
|
||||
if ( buildcraft.isPipe( te, side.getOpposite() ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
output = new WrapperBCPipe( te, side.getOpposite() );
|
||||
}
|
||||
catch (Throwable ignore)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 ignore) { } } } }
|
||||
*/
|
||||
|
||||
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 && output )
|
||||
input.onTunnelNetworkChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
return new TickingRequest( TickRates.ItemTunnel.min, TickRates.ItemTunnel.max, false, false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
{
|
||||
boolean wasReq = requested;
|
||||
|
||||
if ( requested && cachedInv != null )
|
||||
((WrapperChainedInventory) cachedInv).cycleOrder();
|
||||
|
||||
requested = false;
|
||||
return wasReq ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
}
|
||||
|
||||
IInventory getDest()
|
||||
{
|
||||
requested = true;
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void changeStateA(MENetworkBootingStatusChange bs)
|
||||
{
|
||||
if ( !output )
|
||||
{
|
||||
cachedInv = null;
|
||||
int olderSize = oldSize;
|
||||
oldSize = getDest().getSizeInventory();
|
||||
if ( olderSize != oldSize )
|
||||
{
|
||||
getHost().notifyNeighbors();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void changeStateB(MENetworkChannelsChanged bs)
|
||||
{
|
||||
if ( !output )
|
||||
{
|
||||
cachedInv = null;
|
||||
int olderSize = oldSize;
|
||||
oldSize = getDest().getSizeInventory();
|
||||
if ( olderSize != oldSize )
|
||||
{
|
||||
getHost().notifyNeighbors();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void changeStateC(MENetworkPowerStatusChange bs)
|
||||
{
|
||||
if ( !output )
|
||||
{
|
||||
cachedInv = null;
|
||||
int olderSize = oldSize;
|
||||
oldSize = getDest().getSizeInventory();
|
||||
if ( olderSize != oldSize )
|
||||
{
|
||||
getHost().notifyNeighbors();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
if ( !output )
|
||||
{
|
||||
cachedInv = null;
|
||||
int olderSize = oldSize;
|
||||
oldSize = getDest().getSizeInventory();
|
||||
if ( olderSize != oldSize )
|
||||
{
|
||||
getHost().notifyNeighbors();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PartP2PItems input = getInput();
|
||||
if ( input != null )
|
||||
input.getHost().notifyNeighbors();
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getTypeTexture()
|
||||
{
|
||||
return Blocks.hopper.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 getInventoryName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return getDest().getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
}
|
||||
|
||||
@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
|
||||
@Method(iname = "BC")
|
||||
public ConnectOverride overridePipeConnection(PipeType type, ForgeDirection with)
|
||||
{
|
||||
return side.equals( with ) && type == PipeType.ITEM ? ConnectOverride.CONNECT : ConnectOverride.DEFAULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
// eh?
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import appeng.api.config.TunnelType;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.me.GridAccessException;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTickable
|
||||
{
|
||||
|
||||
public PartP2PLight(ItemStack is) {
|
||||
super( is );
|
||||
}
|
||||
|
||||
public TunnelType getTunnelType()
|
||||
{
|
||||
return TunnelType.LIGHT;
|
||||
}
|
||||
|
||||
int lastValue = 0;
|
||||
float opacity = -1;
|
||||
|
||||
public void setLightLevel(int out)
|
||||
{
|
||||
lastValue = out;
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightLevel()
|
||||
{
|
||||
if ( output && isPowered() )
|
||||
return blockLight( lastValue );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int blockLight(int emit)
|
||||
{
|
||||
if ( opacity < 0 )
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chanRender(MENetworkChannelsChanged c)
|
||||
{
|
||||
onTunnelNetworkChange();
|
||||
super.chanRender( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void powerRender(MENetworkPowerStatusChange c)
|
||||
{
|
||||
onTunnelNetworkChange();
|
||||
super.powerRender( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
if ( output )
|
||||
{
|
||||
PartP2PLight src = getInput();
|
||||
if ( src != null && src.proxy.isActive() )
|
||||
setLightLevel( src.lastValue );
|
||||
else
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
else
|
||||
doWork();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelConfigChange()
|
||||
{
|
||||
onTunnelNetworkChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
opacity = -1;
|
||||
|
||||
doWork();
|
||||
|
||||
if ( output )
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.writeToNBT( tag );
|
||||
tag.setFloat( "opacity", opacity );
|
||||
tag.setInteger( "lastValue", lastValue );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.readFromNBT( tag );
|
||||
if ( tag.hasKey( "opacity" ) )
|
||||
opacity = tag.getFloat( "opacity" );
|
||||
lastValue = tag.getInteger( "lastValue" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream(ByteBuf data) throws IOException
|
||||
{
|
||||
super.readFromStream( data );
|
||||
lastValue = data.readInt();
|
||||
output = lastValue > 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(ByteBuf data) throws IOException
|
||||
{
|
||||
super.writeToStream( data );
|
||||
data.writeInt( output ? lastValue : 0 );
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getTypeTexture()
|
||||
{
|
||||
return Blocks.quartz_block.getBlockTextureFromSide( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
return new TickingRequest( TickRates.LightTunnel.min, TickRates.LightTunnel.max, false, false );
|
||||
}
|
||||
|
||||
private boolean doWork()
|
||||
{
|
||||
if ( output )
|
||||
return false;
|
||||
|
||||
TileEntity te = getTile();
|
||||
World w = te.getWorldObj();
|
||||
|
||||
int newLevel = w.getBlockLightValue( te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ );
|
||||
|
||||
if ( lastValue != newLevel && proxy.isActive() )
|
||||
{
|
||||
lastValue = newLevel;
|
||||
try
|
||||
{
|
||||
for (PartP2PLight out : getOutputs())
|
||||
out.setLightLevel( lastValue );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
{
|
||||
return doWork() ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import appeng.api.config.TunnelType;
|
||||
import appeng.me.GridAccessException;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartP2PLiquids extends PartP2PTunnel<PartP2PLiquids> implements IFluidHandler
|
||||
{
|
||||
|
||||
private final static FluidTankInfo[] activeTank = new FluidTankInfo[] { new FluidTankInfo( null, 10000 ) };
|
||||
private final static FluidTankInfo[] inactiveTank = new FluidTankInfo[] { new FluidTankInfo( null, 0 ) };
|
||||
|
||||
public TunnelType getTunnelType()
|
||||
{
|
||||
return TunnelType.FLUID;
|
||||
}
|
||||
|
||||
public PartP2PLiquids(ItemStack is) {
|
||||
super( is );
|
||||
}
|
||||
|
||||
private FluidTankInfo[] getTank()
|
||||
{
|
||||
if ( output )
|
||||
{
|
||||
PartP2PLiquids tun = getInput();
|
||||
if ( tun != null )
|
||||
return activeTank;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( !getOutputs().isEmpty() )
|
||||
return activeTank;
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :(
|
||||
}
|
||||
}
|
||||
return inactiveTank;
|
||||
}
|
||||
|
||||
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 IIcon getTypeTexture()
|
||||
{
|
||||
return Blocks.lapis_block.getBlockTextureFromSide( 0 );
|
||||
}
|
||||
|
||||
List<PartP2PLiquids> getOutputs(Fluid input)
|
||||
{
|
||||
List<PartP2PLiquids> outs = new LinkedList<PartP2PLiquids>();
|
||||
|
||||
try
|
||||
{
|
||||
for (PartP2PLiquids l : getOutputs())
|
||||
{
|
||||
IFluidHandler targ = l.getTarget();
|
||||
if ( targ != null )
|
||||
{
|
||||
if ( targ.canFill( l.side.getOpposite(), input ) )
|
||||
outs.add( l );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
return outs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
cachedTank = null;
|
||||
if ( output )
|
||||
{
|
||||
PartP2PLiquids in = getInput();
|
||||
if ( in != null )
|
||||
in.onTunnelNetworkChange();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
cachedTank = null;
|
||||
}
|
||||
|
||||
IFluidHandler getTarget()
|
||||
{
|
||||
if ( !proxy.isActive() )
|
||||
return null;
|
||||
|
||||
if ( cachedTank != null )
|
||||
return cachedTank;
|
||||
|
||||
TileEntity te = tile.getWorldObj().getTileEntity( tile.xCoord + side.offsetX, tile.yCoord + side.offsetY, tile.zCoord + side.offsetZ );
|
||||
if ( te instanceof IFluidHandler )
|
||||
return cachedTank = (IFluidHandler) te;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static final ThreadLocal<Stack<PartP2PLiquids>> depth = new ThreadLocal<Stack<PartP2PLiquids>>();
|
||||
|
||||
private Stack<PartP2PLiquids> getDepth()
|
||||
{
|
||||
Stack<PartP2PLiquids> s = depth.get();
|
||||
|
||||
if ( s == null )
|
||||
depth.set( s = new Stack<PartP2PLiquids>() );
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
Stack<PartP2PLiquids> stack = getDepth();
|
||||
|
||||
for (PartP2PLiquids t : stack)
|
||||
if ( t == this )
|
||||
return 0;
|
||||
|
||||
stack.push( this );
|
||||
|
||||
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 )
|
||||
{
|
||||
if ( stack.pop() != this )
|
||||
throw new RuntimeException( "Invalid Recursion detected." );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( !doFill )
|
||||
{
|
||||
if ( stack.pop() != this )
|
||||
throw new RuntimeException( "Invalid Recursion detected." );
|
||||
|
||||
return Math.min( resource.amount, requestTotal );
|
||||
}
|
||||
|
||||
int available = 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 > available )
|
||||
insert.amount = available;
|
||||
|
||||
IFluidHandler tank = l.getTarget();
|
||||
if ( tank != null )
|
||||
l.tmpUsed = tank.fill( l.side.getOpposite(), insert.copy(), true );
|
||||
else
|
||||
l.tmpUsed = 0;
|
||||
|
||||
available -= insert.amount;
|
||||
used += insert.amount;
|
||||
}
|
||||
|
||||
if ( stack.pop() != this )
|
||||
throw new RuntimeException( "Invalid Recursion detected." );
|
||||
|
||||
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,253 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.config.TunnelType;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.integration.modules.helpers.NullRFHandler;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.transformer.annotations.integration.Interface;
|
||||
import appeng.transformer.annotations.integration.InterfaceList;
|
||||
import appeng.util.Platform;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@InterfaceList(value = { @Interface(iface = "cofh.api.energy.IEnergyHandler", iname = "RF") })
|
||||
public class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements cofh.api.energy.IEnergyHandler
|
||||
{
|
||||
|
||||
private static final IEnergyHandler myNullHandler = new NullRFHandler();
|
||||
|
||||
boolean cachedTarget = false;
|
||||
IEnergyHandler outputTarget;
|
||||
|
||||
public TunnelType getTunnelType()
|
||||
{
|
||||
return TunnelType.RF_POWER;
|
||||
}
|
||||
|
||||
public PartP2PRFPower(ItemStack is) {
|
||||
super( is );
|
||||
|
||||
if ( !AppEng.instance.isIntegrationEnabled( IntegrationType.RF ) )
|
||||
throw new RuntimeException( "RF Not installed!" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.writeToNBT( tag );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.readFromNBT( tag );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
super.onNeighborChanged();
|
||||
cachedTarget = false;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getTypeTexture()
|
||||
{
|
||||
return Blocks.iron_block.getBlockTextureFromSide( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
getHost().notifyNeighbors();
|
||||
}
|
||||
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
static final ThreadLocal<Stack<PartP2PRFPower>> depth = new ThreadLocal<Stack<PartP2PRFPower>>();
|
||||
|
||||
private Stack<PartP2PRFPower> getDepth()
|
||||
{
|
||||
Stack<PartP2PRFPower> s = depth.get();
|
||||
|
||||
if ( s == null )
|
||||
depth.set( s = new Stack<PartP2PRFPower>() );
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
|
||||
{
|
||||
if ( output )
|
||||
return 0;
|
||||
|
||||
if ( isActive() )
|
||||
{
|
||||
Stack<PartP2PRFPower> stack = getDepth();
|
||||
|
||||
for (PartP2PRFPower t : stack)
|
||||
if ( t == this )
|
||||
return 0;
|
||||
|
||||
stack.push( this );
|
||||
|
||||
int total = 0;
|
||||
|
||||
try
|
||||
{
|
||||
for (PartP2PRFPower t : getOutputs())
|
||||
{
|
||||
if ( Platform.getRandomInt() % 2 > 0 )
|
||||
{
|
||||
int recv = t.getOutput().receiveEnergy( t.side.getOpposite(), maxReceive, simulate );
|
||||
maxReceive -= recv;
|
||||
total += recv;
|
||||
|
||||
if ( maxReceive <= 0 )
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( maxReceive > 0 )
|
||||
{
|
||||
for (PartP2PRFPower t : getOutputs())
|
||||
{
|
||||
int recv = t.getOutput().receiveEnergy( t.side.getOpposite(), maxReceive, simulate );
|
||||
maxReceive -= recv;
|
||||
total += recv;
|
||||
|
||||
if ( maxReceive <= 0 )
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QueueTunnelDrain( PowerUnits.RF, total );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
}
|
||||
|
||||
if ( stack.pop() != this )
|
||||
throw new RuntimeException( "Invalid Recursion detected." );
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ForgeDirection from)
|
||||
{
|
||||
if ( output || !isActive() )
|
||||
return 0;
|
||||
|
||||
int total = 0;
|
||||
|
||||
Stack<PartP2PRFPower> stack = getDepth();
|
||||
|
||||
for (PartP2PRFPower t : stack)
|
||||
if ( t == this )
|
||||
return 0;
|
||||
|
||||
stack.push( this );
|
||||
|
||||
try
|
||||
{
|
||||
for (PartP2PRFPower t : getOutputs())
|
||||
{
|
||||
total += t.getOutput().getEnergyStored( t.side.getOpposite() );
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( stack.pop() != this )
|
||||
throw new RuntimeException( "Invalid Recursion detected." );
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from)
|
||||
{
|
||||
if ( output || !isActive() )
|
||||
return 0;
|
||||
|
||||
int total = 0;
|
||||
|
||||
Stack<PartP2PRFPower> stack = getDepth();
|
||||
|
||||
for (PartP2PRFPower t : stack)
|
||||
if ( t == this )
|
||||
return 0;
|
||||
|
||||
stack.push( this );
|
||||
|
||||
try
|
||||
{
|
||||
for (PartP2PRFPower t : getOutputs())
|
||||
{
|
||||
total += t.getOutput().getMaxEnergyStored( t.side.getOpposite() );
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( stack.pop() != this )
|
||||
throw new RuntimeException( "Invalid Recursion detected." );
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
private IEnergyHandler getOutput()
|
||||
{
|
||||
if ( output )
|
||||
{
|
||||
if ( !cachedTarget )
|
||||
{
|
||||
TileEntity self = getTile();
|
||||
TileEntity te = self.getWorldObj().getTileEntity( self.xCoord + side.offsetX, self.yCoord + side.offsetY, self.zCoord + side.offsetZ );
|
||||
outputTarget = te instanceof IEnergyHandler ? (IEnergyHandler) te : null;
|
||||
cachedTarget = true;
|
||||
}
|
||||
|
||||
if ( outputTarget == null || !outputTarget.canConnectEnergy( side.getOpposite() ) )
|
||||
return myNullHandler;
|
||||
|
||||
return outputTarget;
|
||||
}
|
||||
return myNullHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectEnergy(ForgeDirection from)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRedstoneWire;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import appeng.api.config.TunnelType;
|
||||
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 appeng.util.Platform;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartP2PRedstone extends PartP2PTunnel<PartP2PRedstone>
|
||||
{
|
||||
|
||||
public TunnelType getTunnelType()
|
||||
{
|
||||
return TunnelType.REDSTONE;
|
||||
}
|
||||
|
||||
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 onTunnelNetworkChange()
|
||||
{
|
||||
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;
|
||||
notifyNeighbors();
|
||||
}
|
||||
}
|
||||
recursive = false;
|
||||
|
||||
}
|
||||
|
||||
public void notifyNeighbors()
|
||||
{
|
||||
World worldObj = tile.getWorldObj();
|
||||
|
||||
int xCoord = tile.xCoord;
|
||||
int yCoord = tile.yCoord;
|
||||
int zCoord = tile.zCoord;
|
||||
|
||||
Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord, zCoord );
|
||||
|
||||
// and this cause sometimes it can go thought walls.
|
||||
Platform.notifyBlocksOfNeighbors( worldObj, xCoord - 1, yCoord, zCoord );
|
||||
Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord - 1, zCoord );
|
||||
Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord, zCoord - 1 );
|
||||
Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord, zCoord + 1 );
|
||||
Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord + 1, zCoord );
|
||||
Platform.notifyBlocksOfNeighbors( worldObj, xCoord + 1, 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 IIcon getTypeTexture()
|
||||
{
|
||||
return Blocks.redstone_block.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 = tile.getWorldObj().getBlock( x, y, z );
|
||||
if ( b != null && !output )
|
||||
{
|
||||
int srcSide = side.ordinal();
|
||||
if ( b instanceof BlockRedstoneWire )
|
||||
srcSide = 1;
|
||||
power = b.isProvidingStrongPower( tile.getWorldObj(), x, y, z, srcSide );
|
||||
power = Math.max( power, b.isProvidingWeakPower( tile.getWorldObj(), 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,389 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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.IIcon;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.config.TunnelType;
|
||||
import appeng.api.implementations.items.IMemoryCard;
|
||||
import appeng.api.implementations.items.MemoryCardMessages;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartItem;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.parts.PartItemStack;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cache.P2PCache;
|
||||
import appeng.me.cache.helpers.TunnelCollection;
|
||||
import appeng.parts.PartBasicState;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
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 boolean useStandardMemoryCard()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@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 onPartActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
ItemStack is = player.inventory.getCurrentItem();
|
||||
|
||||
// UniqueIdentifier id = GameRegistry.findUniqueIdentifierFor( is.getItem() );
|
||||
// AELog.info( "ID:" + id.toString() + " : " + is.getItemDamage() );
|
||||
|
||||
TunnelType tt = AEApi.instance().registries().p2pTunnel().getTunnelTypeByItem( is );
|
||||
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" );
|
||||
|
||||
if ( newType != null )
|
||||
{
|
||||
if ( newType.getItem() instanceof IPartItem )
|
||||
{
|
||||
IPart testPart = ((IPartItem) newType.getItem()).createPartFromItemStack( newType );
|
||||
if ( testPart instanceof PartP2PTunnel )
|
||||
{
|
||||
getHost().removePart( side, true );
|
||||
ForgeDirection dir = getHost().addPart( newType, side, player );
|
||||
IPart newBus = getHost().getPart( dir );
|
||||
|
||||
if ( newBus instanceof PartP2PTunnel )
|
||||
{
|
||||
PartP2PTunnel newTunnel = (PartP2PTunnel) newBus;
|
||||
newTunnel.output = true;
|
||||
|
||||
try
|
||||
{
|
||||
P2PCache p2p = newTunnel.proxy.getP2P();
|
||||
p2p.updateFreq( newTunnel, freq );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
newTunnel.onTunnelNetworkChange();
|
||||
}
|
||||
|
||||
mc.notifyUser( player, MemoryCardMessages.SETTINGS_LOADED );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
mc.notifyUser( player, MemoryCardMessages.INVALID_MACHINE );
|
||||
}
|
||||
else if ( tt != null ) // attune-ment
|
||||
{
|
||||
ItemStack newType = null;
|
||||
|
||||
switch (tt)
|
||||
{
|
||||
case LIGHT:
|
||||
newType = AEApi.instance().parts().partP2PTunnelLight.stack( 1 );
|
||||
break;
|
||||
|
||||
case RF_POWER:
|
||||
newType = AEApi.instance().parts().partP2PTunnelRF.stack( 1 );
|
||||
break;
|
||||
|
||||
case BC_POWER:
|
||||
newType = AEApi.instance().parts().partP2PTunnelMJ.stack( 1 );
|
||||
break;
|
||||
|
||||
case FLUID:
|
||||
newType = AEApi.instance().parts().partP2PTunnelLiquids.stack( 1 );
|
||||
break;
|
||||
|
||||
case IC2_POWER:
|
||||
newType = AEApi.instance().parts().partP2PTunnelEU.stack( 1 );
|
||||
break;
|
||||
|
||||
case ITEM:
|
||||
newType = AEApi.instance().parts().partP2PTunnelItems.stack( 1 );
|
||||
break;
|
||||
|
||||
case ME:
|
||||
newType = AEApi.instance().parts().partP2PTunnelME.stack( 1 );
|
||||
break;
|
||||
|
||||
case REDSTONE:
|
||||
newType = AEApi.instance().parts().partP2PTunnelRedstone.stack( 1 );
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if ( newType != null && !Platform.isSameItem( newType, this.is ) )
|
||||
{
|
||||
boolean oldOutput = output;
|
||||
long myFreq = freq;
|
||||
|
||||
getHost().removePart( side, false );
|
||||
ForgeDirection dir = getHost().addPart( newType, side, player );
|
||||
IPart newBus = getHost().getPart( dir );
|
||||
|
||||
if ( newBus instanceof PartP2PTunnel )
|
||||
{
|
||||
PartP2PTunnel newTunnel = (PartP2PTunnel) newBus;
|
||||
newTunnel.output = oldOutput;
|
||||
newTunnel.onTunnelNetworkChange();
|
||||
|
||||
try
|
||||
{
|
||||
P2PCache p2p = newTunnel.proxy.getP2P();
|
||||
p2p.updateFreq( newTunnel, myFreq );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
Platform.notifyBlocksOfNeighbors( tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public TunnelType getTunnelType()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartShiftActivate(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;
|
||||
boolean wasOutput = output;
|
||||
output = false;
|
||||
|
||||
if ( wasOutput || freq == 0 )
|
||||
newFreq = System.currentTimeMillis();
|
||||
|
||||
try
|
||||
{
|
||||
proxy.getP2P().updateFreq( this, newFreq );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
onTunnelConfigChange();
|
||||
|
||||
ItemStack p2pItem = getItemStack( PartItemStack.Wrench );
|
||||
String type = p2pItem.getUnlocalizedName();
|
||||
|
||||
p2pItem.writeToNBT( data );
|
||||
data.setLong( "freq", freq );
|
||||
|
||||
mc.setMemoryCardContents( is, type + ".name", data );
|
||||
mc.notifyUser( player, MemoryCardMessages.SETTINGS_SAVED );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onTunnelConfigChange()
|
||||
{
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(PartItemStack type)
|
||||
{
|
||||
if ( type == PartItemStack.World || type == PartItemStack.Network || type == PartItemStack.Wrench || type == PartItemStack.Pick )
|
||||
return super.getItemStack( type );
|
||||
|
||||
return AEApi.instance().parts().partP2PTunnelME.stack( 1 );
|
||||
}
|
||||
|
||||
public TunnelCollection<T> getCollection(Collection<PartP2PTunnel> collection, Class<? extends PartP2PTunnel> c)
|
||||
{
|
||||
if ( type.matches( c ) )
|
||||
{
|
||||
type.setSource( collection );
|
||||
return type;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public T getInput()
|
||||
{
|
||||
if ( freq == 0 )
|
||||
return null;
|
||||
|
||||
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
|
||||
{
|
||||
if ( proxy.isActive() )
|
||||
return (TunnelCollection<T>) proxy.getP2P().getOutputs( freq, getClass() );
|
||||
return new TunnelCollection( new ArrayList(), getClass() );
|
||||
}
|
||||
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
rh.setTexture( getTypeTexture() );
|
||||
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
rh.setTexture( CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.BlockP2PTunnel2.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.PartTunnelSides.getIcon() );
|
||||
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
}
|
||||
|
||||
protected IIcon getTypeTexture()
|
||||
{
|
||||
return AEApi.instance().blocks().blockQuartz.block().getIcon( 0, 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache );
|
||||
rh.setTexture( getTypeTexture() );
|
||||
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setTexture( CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.BlockP2PTunnel2.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.PartTunnelSides.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 );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getBreakingTexture()
|
||||
{
|
||||
return CableBusTextures.BlockP2PTunnel2.getIcon();
|
||||
}
|
||||
|
||||
protected void QueueTunnelDrain(PowerUnits unit, double f)
|
||||
{
|
||||
double ae_to_tax = unit.convertTo( PowerUnits.AE, f * AEConfig.TunnelPowerLoss );
|
||||
|
||||
try
|
||||
{
|
||||
proxy.getEnergy().extractAEPower( ae_to_tax, Actionable.MODULATE, PowerMultiplier.ONE );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColors(boolean hasChan, boolean hasPower)
|
||||
{
|
||||
super.setColors( hasChan, hasPower );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(IPartCollisionHelper bch)
|
||||
{
|
||||
bch.addBox( 5, 5, 12, 11, 11, 13 );
|
||||
bch.addBox( 3, 3, 13, 13, 13, 14 );
|
||||
bch.addBox( 2, 2, 14, 14, 14, 16 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cableConnectionRenderTo()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.TunnelType;
|
||||
import appeng.api.exceptions.FailedConnection;
|
||||
import appeng.api.networking.GridFlags;
|
||||
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.api.parts.IPartHost;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.hooks.TickHandler;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cache.helpers.Connections;
|
||||
import appeng.me.cache.helpers.TunnelConnection;
|
||||
import appeng.me.helpers.AENetworkProxy;
|
||||
|
||||
public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements IGridTickable
|
||||
{
|
||||
|
||||
public TunnelType getTunnelType()
|
||||
{
|
||||
return TunnelType.ME;
|
||||
}
|
||||
|
||||
AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", null, true );
|
||||
public Connections connection = new Connections( this );
|
||||
|
||||
public PartP2PTunnelME(ItemStack is) {
|
||||
super( is );
|
||||
proxy.setFlags( GridFlags.REQUIRE_CHANNEL, GridFlags.COMPRESSED_CHANNEL );
|
||||
outerProxy.setFlags( GridFlags.DENSE_CAPACITY, GridFlags.CANNOT_CARRY_COMPRESSED );
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
super.onTunnelNetworkChange();
|
||||
if ( !output )
|
||||
{
|
||||
try
|
||||
{
|
||||
proxy.getTick().wakeDevice( proxy.getNode() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
return new TickingRequest( TickRates.METunnel.min, TickRates.METunnel.max, true, false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
{
|
||||
// just move on...
|
||||
try
|
||||
{
|
||||
if ( !proxy.getPath().isNetworkBooting() )
|
||||
{
|
||||
if ( !proxy.getEnergy().isNetworkPowered() )
|
||||
{
|
||||
connection.markDestroy();
|
||||
TickHandler.instance.addCallable( tile.getWorldObj(), connection );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( proxy.isActive() )
|
||||
{
|
||||
connection.markCreate();
|
||||
TickHandler.instance.addCallable( tile.getWorldObj(), connection );
|
||||
}
|
||||
else
|
||||
{
|
||||
connection.markDestroy();
|
||||
TickHandler.instance.addCallable( tile.getWorldObj(), connection );
|
||||
}
|
||||
}
|
||||
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// meh?
|
||||
}
|
||||
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side)
|
||||
{
|
||||
super.onPlacement( player, held, side );
|
||||
outerProxy.setOwner( player );
|
||||
}
|
||||
|
||||
public void updateConnections(Connections connections)
|
||||
{
|
||||
if ( connections.destroy )
|
||||
{
|
||||
for (TunnelConnection cw : connection.connections.values())
|
||||
cw.c.destroy();
|
||||
|
||||
connection.connections.clear();
|
||||
}
|
||||
else if ( connections.create )
|
||||
{
|
||||
|
||||
Iterator<TunnelConnection> i = connection.connections.values().iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
TunnelConnection cw = i.next();
|
||||
try
|
||||
{
|
||||
if ( cw.tunnel.proxy.getGrid() != proxy.getGrid() )
|
||||
{
|
||||
cw.c.destroy();
|
||||
i.remove();
|
||||
}
|
||||
else if ( !cw.tunnel.proxy.isActive() )
|
||||
{
|
||||
cw.c.destroy();
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
LinkedList<PartP2PTunnelME> newSides = new LinkedList<PartP2PTunnelME>();
|
||||
try
|
||||
{
|
||||
for (PartP2PTunnelME me : getOutputs())
|
||||
{
|
||||
if ( me.proxy.isActive() && connections.connections.get( me.getGridNode() ) == null )
|
||||
{
|
||||
newSides.add( me );
|
||||
}
|
||||
}
|
||||
|
||||
for (PartP2PTunnelME me : newSides)
|
||||
{
|
||||
try
|
||||
{
|
||||
connections.connections.put( me.getGridNode(),
|
||||
new TunnelConnection( me, AEApi.instance().createGridConnection( outerProxy.getNode(), me.outerProxy.getNode() ) ) );
|
||||
}
|
||||
catch (FailedConnection e)
|
||||
{
|
||||
AELog.error( e );
|
||||
// :(
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.networking.energy.IEnergySource;
|
||||
import appeng.api.networking.security.PlayerSource;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class PartConversionMonitor extends PartStorageMonitor
|
||||
{
|
||||
|
||||
public PartConversionMonitor(ItemStack is) {
|
||||
super( PartConversionMonitor.class, is );
|
||||
frontBright = CableBusTextures.PartConvMonitor_Bright;
|
||||
frontColored = CableBusTextures.PartConvMonitor_Colored;
|
||||
frontDark = CableBusTextures.PartConvMonitor_Dark;
|
||||
// frontSolid = CableBusTextures.PartConvMonitor_Solid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartShiftActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return true;
|
||||
|
||||
if ( !proxy.isActive() )
|
||||
return false;
|
||||
|
||||
if ( !Platform.hasPermissions( getLocation(), player ) )
|
||||
return false;
|
||||
|
||||
boolean ModeB = false;
|
||||
|
||||
ItemStack item = player.getCurrentEquippedItem();
|
||||
if ( item == null && getDisplayed() != null )
|
||||
{
|
||||
ModeB = true;
|
||||
item = ((IAEItemStack) getDisplayed()).getItemStack();
|
||||
}
|
||||
|
||||
if ( item != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( !proxy.isActive() )
|
||||
return false;
|
||||
|
||||
IEnergySource energy = proxy.getEnergy();
|
||||
IMEMonitor<IAEItemStack> cell = proxy.getStorage().getItemInventory();
|
||||
IAEItemStack input = AEItemStack.create( item );
|
||||
|
||||
if ( ModeB )
|
||||
{
|
||||
for (int x = 0; x < player.inventory.getSizeInventory(); x++)
|
||||
{
|
||||
ItemStack targetStack = player.inventory.getStackInSlot( x );
|
||||
if ( input.equals( targetStack ) )
|
||||
{
|
||||
IAEItemStack insertItem = input.copy();
|
||||
insertItem.setStackSize( targetStack.stackSize );
|
||||
IAEItemStack failedToInsert = Platform.poweredInsert( energy, cell, insertItem, new PlayerSource( player, this ) );
|
||||
player.inventory.setInventorySlotContents( x, failedToInsert == null ? null : failedToInsert.getItemStack() );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IAEItemStack failedToInsert = Platform.poweredInsert( energy, cell, input, new PlayerSource( player, this ) );
|
||||
player.inventory.setInventorySlotContents( player.inventory.currentItem, failedToInsert == null ? null : failedToInsert.getItemStack() );
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void extractItem(EntityPlayer player)
|
||||
{
|
||||
IAEItemStack input = (IAEItemStack) getDisplayed();
|
||||
if ( input != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( !proxy.isActive() )
|
||||
return;
|
||||
|
||||
IEnergySource energy = proxy.getEnergy();
|
||||
IMEMonitor<IAEItemStack> cell = proxy.getStorage().getItemInventory();
|
||||
|
||||
ItemStack is = input.getItemStack();
|
||||
input.setStackSize( is.getMaxStackSize() );
|
||||
|
||||
IAEItemStack retrieved = Platform.poweredExtraction( energy, cell, input, new PlayerSource( player, this ) );
|
||||
if ( retrieved != null )
|
||||
{
|
||||
ItemStack newItems = retrieved.getItemStack();
|
||||
InventoryAdaptor adaptor = InventoryAdaptor.getAdaptor( player, ForgeDirection.UNKNOWN );
|
||||
newItems = adaptor.addItems( newItems );
|
||||
if ( newItems != null )
|
||||
{
|
||||
TileEntity te = tile;
|
||||
List<ItemStack> list = Arrays.asList( new ItemStack[] { newItems } );
|
||||
Platform.spawnDrops( player.worldObj, te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ, list );
|
||||
}
|
||||
|
||||
if ( player.openContainer != null )
|
||||
player.openContainer.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.IAEAppEngInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
|
||||
public class PartCraftingTerminal extends PartTerminal implements IAEAppEngInventory
|
||||
{
|
||||
|
||||
AppEngInternalInventory craftingGrid = new AppEngInternalInventory( this, 9 );
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
craftingGrid.writeToNBT( data, "craftingGrid" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
craftingGrid.readFromNBT( data, "craftingGrid" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(List<ItemStack> drops, boolean wrenched)
|
||||
{
|
||||
super.getDrops(drops, wrenched);
|
||||
|
||||
for (ItemStack is : craftingGrid)
|
||||
if ( is != null )
|
||||
drops.add( is );
|
||||
}
|
||||
|
||||
public PartCraftingTerminal(ItemStack is) {
|
||||
super( PartCraftingTerminal.class, is );
|
||||
frontBright = CableBusTextures.PartCraftingTerm_Bright;
|
||||
frontColored = CableBusTextures.PartCraftingTerm_Colored;
|
||||
frontDark = CableBusTextures.PartCraftingTerm_Dark;
|
||||
// frontSolid = CableBusTextures.PartCraftingTerm_Solid;
|
||||
}
|
||||
|
||||
public GuiBridge getGui()
|
||||
{
|
||||
return GuiBridge.GUI_CRAFTING_TERMINAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
|
||||
{
|
||||
host.markForSave();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(String name)
|
||||
{
|
||||
if ( name.equals( "crafting" ) )
|
||||
return craftingGrid;
|
||||
return super.getInventoryByName( name );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartDarkMonitor extends PartMonitor
|
||||
{
|
||||
|
||||
public PartDarkMonitor(ItemStack is) {
|
||||
super( PartDarkMonitor.class, is, false );
|
||||
notLightSource = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
|
||||
rh.setTexture( CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorBack.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon() );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
rh.setInvColor( getColor().mediumVariant );
|
||||
rh.renderInventoryFace( frontBright.getIcon(), ForgeDirection.SOUTH, renderer );
|
||||
|
||||
rh.setBounds( 4, 4, 13, 12, 12, 14 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
rh.setTexture( CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorBack.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon() );
|
||||
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
if ( getLightLevel() > 0 )
|
||||
{
|
||||
int l = 13;
|
||||
Tessellator.instance.setBrightness( l << 20 | l << 4 );
|
||||
}
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( getColor().mediumVariant );
|
||||
rh.renderFace( x, y, z, frontBright.getIcon(), ForgeDirection.SOUTH, renderer );
|
||||
|
||||
rh.setBounds( 4, 4, 13, 12, 12, 14 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Vec3;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class PartInterfaceTerminal extends PartMonitor
|
||||
{
|
||||
|
||||
public PartInterfaceTerminal(ItemStack is) {
|
||||
super( PartInterfaceTerminal.class, is, true );
|
||||
frontBright = CableBusTextures.PartInterfaceTerm_Bright;
|
||||
frontColored = CableBusTextures.PartInterfaceTerm_Colored;
|
||||
frontDark = CableBusTextures.PartInterfaceTerm_Dark;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
if ( !super.onPartActivate( player, pos ) )
|
||||
{
|
||||
if ( !player.isSneaking() )
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return true;
|
||||
|
||||
Platform.openGUI( player, getHost().getTile(), side, GuiBridge.GUI_INTERFACE_TERMINAL );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,334 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.implementations.IPowerChannelState;
|
||||
import appeng.api.implementations.parts.IPartMonitor;
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.events.MENetworkBootingStatusChange;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.AEBasePart;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartMonitor extends AEBasePart implements IPartMonitor, IPowerChannelState
|
||||
{
|
||||
|
||||
// CableBusTextures frontSolid = CableBusTextures.PartMonitor_Solid;
|
||||
CableBusTextures frontDark = CableBusTextures.PartMonitor_Colored;
|
||||
CableBusTextures frontBright = CableBusTextures.PartMonitor_Bright;
|
||||
CableBusTextures frontColored = CableBusTextures.PartMonitor_Colored;
|
||||
|
||||
boolean notLightSource = !this.getClass().equals( PartMonitor.class );
|
||||
|
||||
final int POWERED_FLAG = 4;
|
||||
final int BOOTING_FLAG = 8;
|
||||
final int CHANNEL_FLAG = 16;
|
||||
|
||||
byte spin = 0; // 0-3
|
||||
int clientFlags = 0; // sent as byte.
|
||||
float opacity = -1;
|
||||
|
||||
@Override
|
||||
public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side)
|
||||
{
|
||||
super.onPlacement( player, held, side );
|
||||
|
||||
byte rotation = (byte) (MathHelper.floor_double( (double) ((player.rotationYaw * 4F) / 360F) + 2.5D ) & 3);
|
||||
if ( side == ForgeDirection.UP )
|
||||
spin = rotation;
|
||||
else if ( side == ForgeDirection.DOWN )
|
||||
spin = rotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
data.setFloat( "opacity", opacity );
|
||||
data.setByte( "spin", (byte) spin );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
if ( data.hasKey( "opacity" ) )
|
||||
opacity = data.getFloat( "opacity" );
|
||||
spin = data.getByte( "spin" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
TileEntity te = getTile();
|
||||
|
||||
if ( !player.isSneaking() && Platform.isWrench( player, player.inventory.getCurrentItem(), te.xCoord, te.yCoord, te.zCoord ) )
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
{
|
||||
if ( spin > 3 )
|
||||
spin = 0;
|
||||
|
||||
switch (spin)
|
||||
{
|
||||
case 0:
|
||||
spin = 1;
|
||||
break;
|
||||
case 1:
|
||||
spin = 3;
|
||||
break;
|
||||
case 2:
|
||||
spin = 0;
|
||||
break;
|
||||
case 3:
|
||||
spin = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
this.host.markForUpdate();
|
||||
this.saveChanges();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return super.onPartActivate( player, pos );
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void bootingRender(MENetworkBootingStatusChange c)
|
||||
{
|
||||
if ( notLightSource )
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
opacity = -1;
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(MENetworkPowerStatusChange c)
|
||||
{
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(ByteBuf data) throws IOException
|
||||
{
|
||||
super.writeToStream( data );
|
||||
clientFlags = spin & 3;
|
||||
;
|
||||
|
||||
try
|
||||
{
|
||||
if ( proxy.getEnergy().isNetworkPowered() )
|
||||
clientFlags = clientFlags | POWERED_FLAG;
|
||||
|
||||
if ( proxy.getPath().isNetworkBooting() )
|
||||
clientFlags = clientFlags | BOOTING_FLAG;
|
||||
|
||||
if ( proxy.getNode().meetsChannelRequirements() )
|
||||
clientFlags = clientFlags | CHANNEL_FLAG;
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// um.. nothing.
|
||||
}
|
||||
|
||||
data.writeByte( (byte) clientFlags );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream(ByteBuf data) throws IOException
|
||||
{
|
||||
super.readFromStream( data );
|
||||
int oldFlags = clientFlags;
|
||||
clientFlags = data.readByte();
|
||||
spin = (byte) (clientFlags & 3);
|
||||
if ( clientFlags == oldFlags )
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightLevel()
|
||||
{
|
||||
return blockLight( isPowered() ? (notLightSource ? 9 : 15) : 0 );
|
||||
}
|
||||
|
||||
private int blockLight(int emit)
|
||||
{
|
||||
if ( opacity < 0 )
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPowered()
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
return proxy.getEnergy().isNetworkPowered();
|
||||
else
|
||||
return ((clientFlags & POWERED_FLAG) == POWERED_FLAG);
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public PartMonitor(ItemStack is) {
|
||||
this( PartMonitor.class, is, false );
|
||||
}
|
||||
|
||||
protected PartMonitor(Class c, ItemStack is, boolean requireChannel) {
|
||||
super( c, is );
|
||||
|
||||
if ( requireChannel )
|
||||
{
|
||||
proxy.setFlags( GridFlags.REQUIRE_CHANNEL );
|
||||
proxy.setIdlePowerUsage( 1.0 / 2.0 );
|
||||
}
|
||||
else
|
||||
proxy.setIdlePowerUsage( 1.0 / 16.0 ); // lights drain a little bit.
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
|
||||
rh.setTexture( CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorBack.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon() );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
rh.setInvColor( getColor().whiteVariant );
|
||||
rh.renderInventoryFace( frontBright.getIcon(), ForgeDirection.SOUTH, renderer );
|
||||
|
||||
rh.setInvColor( getColor().mediumVariant );
|
||||
rh.renderInventoryFace( frontDark.getIcon(), ForgeDirection.SOUTH, renderer );
|
||||
|
||||
rh.setInvColor( getColor().blackVariant );
|
||||
rh.renderInventoryFace( frontColored.getIcon(), ForgeDirection.SOUTH, renderer );
|
||||
|
||||
rh.setBounds( 4, 4, 13, 12, 12, 14 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache );
|
||||
|
||||
rh.setTexture( CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorBack.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon() );
|
||||
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
if ( getLightLevel() > 0 )
|
||||
{
|
||||
int l = 13;
|
||||
Tessellator.instance.setBrightness( l << 20 | l << 4 );
|
||||
}
|
||||
|
||||
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = this.spin;
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( getColor().whiteVariant );
|
||||
rh.renderFace( x, y, z, frontBright.getIcon(), ForgeDirection.SOUTH, renderer );
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( getColor().mediumVariant );
|
||||
rh.renderFace( x, y, z, frontDark.getIcon(), ForgeDirection.SOUTH, renderer );
|
||||
|
||||
Tessellator.instance.setColorOpaque_I( getColor().blackVariant );
|
||||
rh.renderFace( x, y, z, frontColored.getIcon(), ForgeDirection.SOUTH, renderer );
|
||||
|
||||
renderer.uvRotateBottom = renderer.uvRotateEast = renderer.uvRotateNorth = renderer.uvRotateSouth = renderer.uvRotateTop = renderer.uvRotateWest = 0;
|
||||
|
||||
if ( notLightSource )
|
||||
{
|
||||
rh.setTexture( CableBusTextures.PartMonitorSidesStatus.getIcon(), CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorBack.getIcon(), is.getIconIndex(), CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
||||
CableBusTextures.PartMonitorSidesStatus.getIcon() );
|
||||
}
|
||||
|
||||
rh.setBounds( 4, 4, 13, 12, 12, 14 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
if ( notLightSource )
|
||||
{
|
||||
boolean hasChan = (clientFlags & (POWERED_FLAG | CHANNEL_FLAG)) == (POWERED_FLAG | CHANNEL_FLAG);
|
||||
boolean hasPower = (clientFlags & POWERED_FLAG) == POWERED_FLAG;
|
||||
|
||||
if ( hasChan )
|
||||
{
|
||||
int l = 14;
|
||||
Tessellator.instance.setBrightness( l << 20 | l << 4 );
|
||||
Tessellator.instance.setColorOpaque_I( getColor().blackVariant );
|
||||
}
|
||||
else if ( hasPower )
|
||||
{
|
||||
int l = 9;
|
||||
Tessellator.instance.setBrightness( l << 20 | l << 4 );
|
||||
Tessellator.instance.setColorOpaque_I( getColor().whiteVariant );
|
||||
}
|
||||
else
|
||||
{
|
||||
Tessellator.instance.setBrightness( 0 );
|
||||
Tessellator.instance.setColorOpaque_I( 0x000000 );
|
||||
}
|
||||
|
||||
rh.renderFace( x, y, z, CableBusTextures.PartMonitorSidesStatusLights.getIcon(), ForgeDirection.EAST, renderer );
|
||||
rh.renderFace( x, y, z, CableBusTextures.PartMonitorSidesStatusLights.getIcon(), ForgeDirection.WEST, renderer );
|
||||
rh.renderFace( x, y, z, CableBusTextures.PartMonitorSidesStatusLights.getIcon(), ForgeDirection.UP, renderer );
|
||||
rh.renderFace( x, y, z, CableBusTextures.PartMonitorSidesStatusLights.getIcon(), ForgeDirection.DOWN, renderer );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(IPartCollisionHelper bch)
|
||||
{
|
||||
bch.addBox( 2, 2, 14, 14, 14, 16 );
|
||||
bch.addBox( 4, 4, 13, 12, 12, 14 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive()
|
||||
{
|
||||
if ( notLightSource )
|
||||
return ((clientFlags & (CHANNEL_FLAG | POWERED_FLAG)) == (CHANNEL_FLAG | POWERED_FLAG));
|
||||
else
|
||||
return isPowered();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import appeng.api.implementations.ICraftingPatternItem;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.IAEAppEngInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
|
||||
public class PartPatternTerminal extends PartTerminal implements IAEAppEngInventory
|
||||
{
|
||||
|
||||
AppEngInternalInventory crafting = new AppEngInternalInventory( this, 9 );
|
||||
AppEngInternalInventory output = new AppEngInternalInventory( this, 3 );
|
||||
AppEngInternalInventory pattern = new AppEngInternalInventory( this, 2 );
|
||||
|
||||
private boolean craftingMode = true;
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
data.setBoolean( "craftingMode", isCraftingRecipe() );
|
||||
pattern.writeToNBT( data, "pattern" );
|
||||
output.writeToNBT( data, "outputList" );
|
||||
crafting.writeToNBT( data, "craftingGrid" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
setCraftingRecipe( data.getBoolean( "craftingMode" ) );
|
||||
pattern.readFromNBT( data, "pattern" );
|
||||
output.readFromNBT( data, "outputList" );
|
||||
crafting.readFromNBT( data, "craftingGrid" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(List<ItemStack> drops, boolean wrenched)
|
||||
{
|
||||
for (ItemStack is : pattern)
|
||||
if ( is != null )
|
||||
drops.add( is );
|
||||
}
|
||||
|
||||
public PartPatternTerminal(ItemStack is) {
|
||||
super( PartPatternTerminal.class, is );
|
||||
frontBright = CableBusTextures.PartPatternTerm_Bright;
|
||||
frontColored = CableBusTextures.PartPatternTerm_Colored;
|
||||
frontDark = CableBusTextures.PartPatternTerm_Dark;
|
||||
}
|
||||
|
||||
public GuiBridge getGui()
|
||||
{
|
||||
return GuiBridge.GUI_PATTERN_TERMINAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(String name)
|
||||
{
|
||||
if ( name.equals( "crafting" ) )
|
||||
return crafting;
|
||||
|
||||
if ( name.equals( "output" ) )
|
||||
return output;
|
||||
|
||||
if ( name.equals( "pattern" ) )
|
||||
return pattern;
|
||||
|
||||
return super.getInventoryByName( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
|
||||
{
|
||||
if ( inv == pattern && slot == 1 )
|
||||
{
|
||||
ItemStack is = pattern.getStackInSlot( 1 );
|
||||
if ( is != null && is.getItem() instanceof ICraftingPatternItem )
|
||||
{
|
||||
ICraftingPatternItem pattern = (ICraftingPatternItem) is.getItem();
|
||||
ICraftingPatternDetails details = pattern.getPatternForItem( is, this.getHost().getTile().getWorldObj() );
|
||||
if ( details != null )
|
||||
{
|
||||
setCraftingRecipe( details.isCraftable() );
|
||||
|
||||
for (int x = 0; x < crafting.getSizeInventory() && x < details.getInputs().length; x++)
|
||||
{
|
||||
IAEItemStack aeis = details.getInputs()[x];
|
||||
crafting.setInventorySlotContents( x, aeis == null ? null : aeis.getItemStack() );
|
||||
}
|
||||
|
||||
for (int x = 0; x < output.getSizeInventory() && x < details.getOutputs().length; x++)
|
||||
{
|
||||
IAEItemStack aeis = details.getOutputs()[x];
|
||||
output.setInventorySlotContents( x, aeis == null ? null : aeis.getItemStack() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( inv == crafting )
|
||||
{
|
||||
fixCraftingRecipes();
|
||||
}
|
||||
|
||||
host.markForSave();
|
||||
}
|
||||
|
||||
public boolean isCraftingRecipe()
|
||||
{
|
||||
return craftingMode;
|
||||
}
|
||||
|
||||
public void setCraftingRecipe(boolean craftingMode)
|
||||
{
|
||||
this.craftingMode = craftingMode;
|
||||
fixCraftingRecipes();
|
||||
}
|
||||
|
||||
private void fixCraftingRecipes()
|
||||
{
|
||||
if ( isCraftingRecipe() )
|
||||
{
|
||||
for (int x = 0; x < crafting.getSizeInventory(); x++)
|
||||
{
|
||||
ItemStack is = crafting.getStackInSlot( x );
|
||||
if ( is != null )
|
||||
is.stackSize = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartSemiDarkMonitor extends PartMonitor
|
||||
{
|
||||
|
||||
public PartSemiDarkMonitor(ItemStack is) {
|
||||
super( PartSemiDarkMonitor.class, is,false );
|
||||
notLightSource = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
|
||||
rh.setTexture( CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorBack.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon() );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
int light = getColor().whiteVariant;
|
||||
int dark = getColor().mediumVariant;
|
||||
rh.setInvColor( (((((light >> 16) & 0xff) + ((dark >> 16) & 0xff)) / 2) << 16) | (((((light >> 8) & 0xff) + ((dark >> 8) & 0xff)) / 2) << 8)
|
||||
| ((((light) & 0xff) + ((dark) & 0xff)) / 2) );
|
||||
rh.renderInventoryFace( frontBright.getIcon(), ForgeDirection.SOUTH, renderer );
|
||||
|
||||
rh.setBounds( 4, 4, 13, 12, 12, 14 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
rh.setTexture( CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorBack.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartMonitorSides.getIcon(), CableBusTextures.PartMonitorSides.getIcon() );
|
||||
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
if ( getLightLevel() > 0 )
|
||||
{
|
||||
int l = 13;
|
||||
Tessellator.instance.setBrightness( l << 20 | l << 4 );
|
||||
}
|
||||
|
||||
int light = getColor().whiteVariant;
|
||||
int dark = getColor().mediumVariant;
|
||||
Tessellator.instance.setColorOpaque( (((light >> 16) & 0xff) + ((dark >> 16) & 0xff)) / 2, (((light >> 8) & 0xff) + ((dark >> 8) & 0xff)) / 2,
|
||||
(((light) & 0xff) + ((dark) & 0xff)) / 2 );
|
||||
rh.renderFace( x, y, z, frontBright.getIcon(), ForgeDirection.SOUTH, renderer );
|
||||
|
||||
rh.setBounds( 4, 4, 13, 12, 12, 14 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,378 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.GLAllocation;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import appeng.api.implementations.parts.IPartStorageMonitor;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.storage.IStackWatcher;
|
||||
import appeng.api.networking.storage.IStackWatcherHost;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.client.ClientHelper;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.localization.PlayerMessages;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartStorageMonitor extends PartMonitor implements IPartStorageMonitor, IStackWatcherHost
|
||||
{
|
||||
|
||||
IAEItemStack configuredItem;
|
||||
boolean isLocked;
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
|
||||
data.setBoolean( "isLocked", isLocked );
|
||||
|
||||
NBTTagCompound myItem = new NBTTagCompound();
|
||||
if ( configuredItem != null )
|
||||
configuredItem.writeToNBT( myItem );
|
||||
|
||||
data.setTag( "configuredItem", myItem );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
|
||||
isLocked = data.getBoolean( "isLocked" );
|
||||
|
||||
NBTTagCompound myItem = data.getCompoundTag( "configuredItem" );
|
||||
configuredItem = AEItemStack.loadItemStackFromNBT( myItem );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(ByteBuf data) throws IOException
|
||||
{
|
||||
super.writeToStream( data );
|
||||
|
||||
data.writeByte( spin );
|
||||
data.writeBoolean( isLocked );
|
||||
data.writeBoolean( configuredItem != null ? true : false );
|
||||
if ( configuredItem != null )
|
||||
configuredItem.writeToPacket( data );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream(ByteBuf data) throws IOException
|
||||
{
|
||||
boolean stuff = super.readFromStream( data );
|
||||
|
||||
spin = data.readByte();
|
||||
isLocked = data.readBoolean();
|
||||
boolean val = data.readBoolean();
|
||||
if ( val )
|
||||
configuredItem = AEItemStack.loadItemStackFromPacket( data );
|
||||
else
|
||||
configuredItem = null;
|
||||
|
||||
updateList = true;
|
||||
|
||||
return stuff;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return true;
|
||||
|
||||
if ( !proxy.isActive() )
|
||||
return false;
|
||||
|
||||
if ( !Platform.hasPermissions( getLocation(), player ) )
|
||||
return false;
|
||||
|
||||
TileEntity te = this.tile;
|
||||
ItemStack eq = player.getCurrentEquippedItem();
|
||||
if ( Platform.isWrench( player, eq, te.xCoord, te.yCoord, te.zCoord ) )
|
||||
{
|
||||
isLocked = !isLocked;
|
||||
player.addChatMessage( (isLocked ? PlayerMessages.isNowLocked : PlayerMessages.isNowUnlocked).get() );
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
else if ( !isLocked )
|
||||
{
|
||||
configuredItem = AEItemStack.create( eq );
|
||||
configureWatchers();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
else
|
||||
extractItem( player );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void extractItem(EntityPlayer player)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected PartStorageMonitor(Class myClass, ItemStack is) {
|
||||
super( myClass, is, true );
|
||||
}
|
||||
|
||||
public PartStorageMonitor(ItemStack is) {
|
||||
super( PartStorageMonitor.class, is, true );
|
||||
frontBright = CableBusTextures.PartStorageMonitor_Bright;
|
||||
frontColored = CableBusTextures.PartStorageMonitor_Colored;
|
||||
frontDark = CableBusTextures.PartStorageMonitor_Dark;
|
||||
// frontSolid = CableBusTextures.PartStorageMonitor_Solid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requireDynamicRender()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private boolean updateList;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private Integer dspList;
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
protected void finalize() throws Throwable
|
||||
{
|
||||
super.finalize();
|
||||
if ( dspList != null )
|
||||
GLAllocation.deleteDisplayLists( dspList );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderDynamic(double x, double y, double z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
if ( dspList == null )
|
||||
dspList = GLAllocation.generateDisplayLists( 1 );
|
||||
|
||||
Tessellator tess = Tessellator.instance;
|
||||
if ( Platform.isDrawing( tess ) )
|
||||
return;
|
||||
|
||||
if ( (clientFlags & (POWERED_FLAG | CHANNEL_FLAG)) != (POWERED_FLAG | CHANNEL_FLAG) )
|
||||
return;
|
||||
|
||||
IAEItemStack ais = (IAEItemStack) getDisplayed();
|
||||
if ( ais != null )
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated( x + 0.5, y + 0.5, z + 0.5 );
|
||||
|
||||
if ( updateList )
|
||||
{
|
||||
updateList = false;
|
||||
GL11.glNewList( dspList, GL11.GL_COMPILE_AND_EXECUTE );
|
||||
tesrRenderScreen( tess, ais );
|
||||
GL11.glEndList();
|
||||
}
|
||||
else
|
||||
GL11.glCallList( dspList );
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
private void tesrRenderScreen(Tessellator tess, IAEItemStack ais)
|
||||
{
|
||||
GL11.glPushAttrib( GL11.GL_ALL_ATTRIB_BITS );
|
||||
ForgeDirection d = side;
|
||||
GL11.glTranslated( d.offsetX * 0.77, d.offsetY * 0.77, d.offsetZ * 0.77 );
|
||||
|
||||
if ( d == ForgeDirection.UP )
|
||||
{
|
||||
GL11.glScalef( 1.0f, -1.0f, 1.0f );
|
||||
GL11.glRotatef( 90.0f, 1.0f, 0.0f, 0.0f );
|
||||
GL11.glRotatef( (float) spin * 90.0F, 0, 0, 1 );
|
||||
}
|
||||
|
||||
if ( d == ForgeDirection.DOWN )
|
||||
{
|
||||
GL11.glScalef( 1.0f, -1.0f, 1.0f );
|
||||
GL11.glRotatef( -90.0f, 1.0f, 0.0f, 0.0f );
|
||||
GL11.glRotatef( (float) spin * -90.0F, 0, 0, 1 );
|
||||
}
|
||||
|
||||
if ( d == ForgeDirection.EAST )
|
||||
{
|
||||
GL11.glScalef( -1.0f, -1.0f, -1.0f );
|
||||
GL11.glRotatef( -90.0f, 0.0f, 1.0f, 0.0f );
|
||||
}
|
||||
|
||||
if ( d == ForgeDirection.WEST )
|
||||
{
|
||||
GL11.glScalef( -1.0f, -1.0f, -1.0f );
|
||||
GL11.glRotatef( 90.0f, 0.0f, 1.0f, 0.0f );
|
||||
}
|
||||
|
||||
if ( d == ForgeDirection.NORTH )
|
||||
{
|
||||
GL11.glScalef( -1.0f, -1.0f, -1.0f );
|
||||
}
|
||||
|
||||
if ( d == ForgeDirection.SOUTH )
|
||||
{
|
||||
GL11.glScalef( -1.0f, -1.0f, -1.0f );
|
||||
GL11.glRotatef( 180.0f, 0.0f, 1.0f, 0.0f );
|
||||
}
|
||||
|
||||
GL11.glPushMatrix();
|
||||
try
|
||||
{
|
||||
ItemStack sis = ais.getItemStack();
|
||||
sis.stackSize = 1;
|
||||
|
||||
int br = 16 << 20 | 16 << 4;
|
||||
int var11 = br % 65536;
|
||||
int var12 = br / 65536;
|
||||
OpenGlHelper.setLightmapTextureCoords( OpenGlHelper.lightmapTexUnit, var11 * 0.8F, var12 * 0.8F );
|
||||
|
||||
GL11.glColor4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||
|
||||
GL11.glDisable( GL11.GL_LIGHTING );
|
||||
GL11.glDisable( GL12.GL_RESCALE_NORMAL );
|
||||
// RenderHelper.enableGUIStandardItemLighting();
|
||||
tess.setColorOpaque_F( 1.0f, 1.0f, 1.0f );
|
||||
|
||||
ClientHelper.proxy.doRenderItem( sis, this.tile.getWorldObj() );
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
|
||||
GL11.glTranslatef( 0.0f, 0.14f, -0.24f );
|
||||
GL11.glScalef( 1.0f / 62.0f, 1.0f / 62.0f, 1.0f / 62.0f );
|
||||
|
||||
long qty = ais.getStackSize();
|
||||
if ( qty > 999999999999L )
|
||||
qty = 999999999999L;
|
||||
|
||||
String msg = Long.toString( qty );
|
||||
if ( qty > 1000000000 )
|
||||
msg = Long.toString( qty / 1000000000 ) + "B";
|
||||
else if ( qty > 1000000 )
|
||||
msg = Long.toString( qty / 1000000 ) + "M";
|
||||
else if ( qty > 9999 )
|
||||
msg = Long.toString( qty / 1000 ) + "K";
|
||||
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
int width = fr.getStringWidth( msg );
|
||||
GL11.glTranslatef( -0.5f * width, 0.0f, -1.0f );
|
||||
fr.drawString( msg, 0, 0, 0 );
|
||||
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEStack getDisplayed()
|
||||
{
|
||||
return configuredItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLocked()
|
||||
{
|
||||
return isLocked;
|
||||
}
|
||||
|
||||
IStackWatcher myWatcher;
|
||||
|
||||
@Override
|
||||
public void updateWatcher(IStackWatcher newWatcher)
|
||||
{
|
||||
myWatcher = newWatcher;
|
||||
configureWatchers();
|
||||
}
|
||||
|
||||
// update the system...
|
||||
public void configureWatchers()
|
||||
{
|
||||
if ( myWatcher != null )
|
||||
myWatcher.clear();
|
||||
|
||||
try
|
||||
{
|
||||
if ( configuredItem != null )
|
||||
{
|
||||
if ( myWatcher != null )
|
||||
myWatcher.add( configuredItem );
|
||||
|
||||
updateReportingValue( proxy.getStorage().getItemInventory() );
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// >.>
|
||||
}
|
||||
}
|
||||
|
||||
private void updateReportingValue(IMEMonitor<IAEItemStack> itemInventory)
|
||||
{
|
||||
if ( configuredItem != null )
|
||||
{
|
||||
IAEItemStack result = itemInventory.getStorageList().findPrecise( configuredItem );
|
||||
if ( result == null )
|
||||
configuredItem.setStackSize( 0 );
|
||||
else
|
||||
configuredItem.setStackSize( result.getStackSize() );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStackChange(IItemList o, IAEStack fullStack, IAEStack diffStack, BaseActionSource src, StorageChannel chan)
|
||||
{
|
||||
if ( configuredItem != null )
|
||||
{
|
||||
if ( fullStack == null )
|
||||
configuredItem.setStackSize( 0 );
|
||||
else
|
||||
configuredItem.setStackSize( fullStack.getStackSize() );
|
||||
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showNetworkInfo(MovingObjectPosition where)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.Vec3;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.SortDir;
|
||||
import appeng.api.config.SortOrder;
|
||||
import appeng.api.config.ViewItems;
|
||||
import appeng.api.implementations.tiles.IViewCellStorage;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.IAEAppEngInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.ConfigManager;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class PartTerminal extends PartMonitor implements ITerminalHost, IConfigManagerHost, IViewCellStorage, IAEAppEngInventory
|
||||
{
|
||||
|
||||
IConfigManager cm = new ConfigManager( this );
|
||||
AppEngInternalInventory viewCell = new AppEngInternalInventory( this, 5 );
|
||||
|
||||
public PartTerminal(Class clz, ItemStack is) {
|
||||
super( clz, is, true );
|
||||
|
||||
cm.registerSetting( Settings.SORT_BY, SortOrder.NAME );
|
||||
cm.registerSetting( Settings.VIEW_MODE, ViewItems.ALL );
|
||||
cm.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(List<ItemStack> drops, boolean wrenched)
|
||||
{
|
||||
super.getDrops( drops, wrenched );
|
||||
|
||||
for (ItemStack is : viewCell)
|
||||
if ( is != null )
|
||||
drops.add( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
cm.readFromNBT( data );
|
||||
viewCell.readFromNBT( data, "viewCell" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
cm.writeToNBT( data );
|
||||
viewCell.writeToNBT( data, "viewCell" );
|
||||
}
|
||||
|
||||
public PartTerminal(ItemStack is) {
|
||||
super( PartTerminal.class, is, true );
|
||||
frontBright = CableBusTextures.PartTerminal_Bright;
|
||||
frontColored = CableBusTextures.PartTerminal_Colored;
|
||||
frontDark = CableBusTextures.PartTerminal_Dark;
|
||||
// frontSolid = CableBusTextures.PartTerminal_Solid;
|
||||
|
||||
cm.registerSetting( Settings.SORT_BY, SortOrder.NAME );
|
||||
cm.registerSetting( Settings.VIEW_MODE, ViewItems.ALL );
|
||||
cm.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING );
|
||||
}
|
||||
|
||||
public GuiBridge getGui()
|
||||
{
|
||||
return GuiBridge.GUI_ME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
if ( !super.onPartActivate( player, pos ) )
|
||||
{
|
||||
if ( !player.isSneaking() )
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return true;
|
||||
|
||||
Platform.openGUI( player, getHost().getTile(), side, getGui() );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor getFluidInventory()
|
||||
{
|
||||
try
|
||||
{
|
||||
return proxy.getStorage().getFluidInventory();
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// err nope?
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor getItemInventory()
|
||||
{
|
||||
try
|
||||
{
|
||||
return proxy.getStorage().getItemInventory();
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// err nope?
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
return cm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getViewCellStorage()
|
||||
{
|
||||
return viewCell;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
|
||||
{
|
||||
host.markForSave();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user