reformatted all src files (#141)
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -19,160 +19,146 @@
|
||||
package appeng.parts;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class BusCollisionHelper implements IPartCollisionHelper
|
||||
{
|
||||
public class BusCollisionHelper implements IPartCollisionHelper {
|
||||
|
||||
private final List<AxisAlignedBB> boxes;
|
||||
private final List<AxisAlignedBB> boxes;
|
||||
|
||||
private final EnumFacing x;
|
||||
private final EnumFacing y;
|
||||
private final EnumFacing z;
|
||||
private final EnumFacing x;
|
||||
private final EnumFacing y;
|
||||
private final EnumFacing z;
|
||||
|
||||
private final Entity entity;
|
||||
private final boolean isVisual;
|
||||
private final Entity entity;
|
||||
private final boolean isVisual;
|
||||
|
||||
public BusCollisionHelper( final List<AxisAlignedBB> boxes, final EnumFacing x, final EnumFacing y, final EnumFacing z, final Entity e, final boolean visual )
|
||||
{
|
||||
this.boxes = boxes;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.entity = e;
|
||||
this.isVisual = visual;
|
||||
}
|
||||
public BusCollisionHelper(final List<AxisAlignedBB> boxes, final EnumFacing x, final EnumFacing y, final EnumFacing z, final Entity e, final boolean visual) {
|
||||
this.boxes = boxes;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.entity = e;
|
||||
this.isVisual = visual;
|
||||
}
|
||||
|
||||
public BusCollisionHelper( final List<AxisAlignedBB> boxes, final AEPartLocation s, final Entity e, final boolean visual )
|
||||
{
|
||||
this.boxes = boxes;
|
||||
this.entity = e;
|
||||
this.isVisual = visual;
|
||||
public BusCollisionHelper(final List<AxisAlignedBB> boxes, final AEPartLocation s, final Entity e, final boolean visual) {
|
||||
this.boxes = boxes;
|
||||
this.entity = e;
|
||||
this.isVisual = visual;
|
||||
|
||||
switch( s )
|
||||
{
|
||||
case DOWN:
|
||||
this.x = EnumFacing.EAST;
|
||||
this.y = EnumFacing.NORTH;
|
||||
this.z = EnumFacing.DOWN;
|
||||
break;
|
||||
case UP:
|
||||
this.x = EnumFacing.EAST;
|
||||
this.y = EnumFacing.SOUTH;
|
||||
this.z = EnumFacing.UP;
|
||||
break;
|
||||
case EAST:
|
||||
this.x = EnumFacing.SOUTH;
|
||||
this.y = EnumFacing.UP;
|
||||
this.z = EnumFacing.EAST;
|
||||
break;
|
||||
case WEST:
|
||||
this.x = EnumFacing.NORTH;
|
||||
this.y = EnumFacing.UP;
|
||||
this.z = EnumFacing.WEST;
|
||||
break;
|
||||
case NORTH:
|
||||
this.x = EnumFacing.WEST;
|
||||
this.y = EnumFacing.UP;
|
||||
this.z = EnumFacing.NORTH;
|
||||
break;
|
||||
case SOUTH:
|
||||
this.x = EnumFacing.EAST;
|
||||
this.y = EnumFacing.UP;
|
||||
this.z = EnumFacing.SOUTH;
|
||||
break;
|
||||
case INTERNAL:
|
||||
default:
|
||||
this.x = EnumFacing.EAST;
|
||||
this.y = EnumFacing.UP;
|
||||
this.z = EnumFacing.SOUTH;
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch (s) {
|
||||
case DOWN:
|
||||
this.x = EnumFacing.EAST;
|
||||
this.y = EnumFacing.NORTH;
|
||||
this.z = EnumFacing.DOWN;
|
||||
break;
|
||||
case UP:
|
||||
this.x = EnumFacing.EAST;
|
||||
this.y = EnumFacing.SOUTH;
|
||||
this.z = EnumFacing.UP;
|
||||
break;
|
||||
case EAST:
|
||||
this.x = EnumFacing.SOUTH;
|
||||
this.y = EnumFacing.UP;
|
||||
this.z = EnumFacing.EAST;
|
||||
break;
|
||||
case WEST:
|
||||
this.x = EnumFacing.NORTH;
|
||||
this.y = EnumFacing.UP;
|
||||
this.z = EnumFacing.WEST;
|
||||
break;
|
||||
case NORTH:
|
||||
this.x = EnumFacing.WEST;
|
||||
this.y = EnumFacing.UP;
|
||||
this.z = EnumFacing.NORTH;
|
||||
break;
|
||||
case SOUTH:
|
||||
this.x = EnumFacing.EAST;
|
||||
this.y = EnumFacing.UP;
|
||||
this.z = EnumFacing.SOUTH;
|
||||
break;
|
||||
case INTERNAL:
|
||||
default:
|
||||
this.x = EnumFacing.EAST;
|
||||
this.y = EnumFacing.UP;
|
||||
this.z = EnumFacing.SOUTH;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* pretty much useless...
|
||||
*/
|
||||
public Entity getEntity()
|
||||
{
|
||||
return this.entity;
|
||||
}
|
||||
/**
|
||||
* pretty much useless...
|
||||
*/
|
||||
public Entity getEntity() {
|
||||
return this.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;
|
||||
@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 * this.x.getFrontOffsetX() + minY * this.y.getFrontOffsetX() + minZ * this.z.getFrontOffsetX();
|
||||
double aY = minX * this.x.getFrontOffsetY() + minY * this.y.getFrontOffsetY() + minZ * this.z.getFrontOffsetY();
|
||||
double aZ = minX * this.x.getFrontOffsetZ() + minY * this.y.getFrontOffsetZ() + minZ * this.z.getFrontOffsetZ();
|
||||
double aX = minX * this.x.getFrontOffsetX() + minY * this.y.getFrontOffsetX() + minZ * this.z.getFrontOffsetX();
|
||||
double aY = minX * this.x.getFrontOffsetY() + minY * this.y.getFrontOffsetY() + minZ * this.z.getFrontOffsetY();
|
||||
double aZ = minX * this.x.getFrontOffsetZ() + minY * this.y.getFrontOffsetZ() + minZ * this.z.getFrontOffsetZ();
|
||||
|
||||
double bX = maxX * this.x.getFrontOffsetX() + maxY * this.y.getFrontOffsetX() + maxZ * this.z.getFrontOffsetX();
|
||||
double bY = maxX * this.x.getFrontOffsetY() + maxY * this.y.getFrontOffsetY() + maxZ * this.z.getFrontOffsetY();
|
||||
double bZ = maxX * this.x.getFrontOffsetZ() + maxY * this.y.getFrontOffsetZ() + maxZ * this.z.getFrontOffsetZ();
|
||||
double bX = maxX * this.x.getFrontOffsetX() + maxY * this.y.getFrontOffsetX() + maxZ * this.z.getFrontOffsetX();
|
||||
double bY = maxX * this.x.getFrontOffsetY() + maxY * this.y.getFrontOffsetY() + maxZ * this.z.getFrontOffsetY();
|
||||
double bZ = maxX * this.x.getFrontOffsetZ() + maxY * this.y.getFrontOffsetZ() + maxZ * this.z.getFrontOffsetZ();
|
||||
|
||||
if( this.x.getFrontOffsetX() + this.y.getFrontOffsetX() + this.z.getFrontOffsetX() < 0 )
|
||||
{
|
||||
aX += 1;
|
||||
bX += 1;
|
||||
}
|
||||
if (this.x.getFrontOffsetX() + this.y.getFrontOffsetX() + this.z.getFrontOffsetX() < 0) {
|
||||
aX += 1;
|
||||
bX += 1;
|
||||
}
|
||||
|
||||
if( this.x.getFrontOffsetY() + this.y.getFrontOffsetY() + this.z.getFrontOffsetY() < 0 )
|
||||
{
|
||||
aY += 1;
|
||||
bY += 1;
|
||||
}
|
||||
if (this.x.getFrontOffsetY() + this.y.getFrontOffsetY() + this.z.getFrontOffsetY() < 0) {
|
||||
aY += 1;
|
||||
bY += 1;
|
||||
}
|
||||
|
||||
if( this.x.getFrontOffsetZ() + this.y.getFrontOffsetZ() + this.z.getFrontOffsetZ() < 0 )
|
||||
{
|
||||
aZ += 1;
|
||||
bZ += 1;
|
||||
}
|
||||
if (this.x.getFrontOffsetZ() + this.y.getFrontOffsetZ() + this.z.getFrontOffsetZ() < 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 );
|
||||
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);
|
||||
|
||||
this.boxes.add( new AxisAlignedBB( minX, minY, minZ, maxX, maxY, maxZ ) );
|
||||
}
|
||||
this.boxes.add(new AxisAlignedBB(minX, minY, minZ, maxX, maxY, maxZ));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumFacing getWorldX()
|
||||
{
|
||||
return this.x;
|
||||
}
|
||||
@Override
|
||||
public EnumFacing getWorldX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumFacing getWorldY()
|
||||
{
|
||||
return this.y;
|
||||
}
|
||||
@Override
|
||||
public EnumFacing getWorldY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumFacing getWorldZ()
|
||||
{
|
||||
return this.z;
|
||||
}
|
||||
@Override
|
||||
public EnumFacing getWorldZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBBCollision()
|
||||
{
|
||||
return !this.isVisual;
|
||||
}
|
||||
@Override
|
||||
public boolean isBBCollision() {
|
||||
return !this.isVisual;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,128 +19,105 @@
|
||||
package appeng.parts;
|
||||
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.api.implementations.parts.IPartCable;
|
||||
import appeng.api.parts.IFacadePart;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
/**
|
||||
* Thin data storage to optimize memory usage for cables.
|
||||
*/
|
||||
public class CableBusStorage
|
||||
{
|
||||
public class CableBusStorage {
|
||||
|
||||
private IPartCable center;
|
||||
private IPart[] sides;
|
||||
private IFacadePart[] facades;
|
||||
private IPartCable center;
|
||||
private IPart[] sides;
|
||||
private IFacadePart[] facades;
|
||||
|
||||
protected IPartCable getCenter()
|
||||
{
|
||||
return this.center;
|
||||
}
|
||||
protected IPartCable getCenter() {
|
||||
return this.center;
|
||||
}
|
||||
|
||||
protected void setCenter( final IPartCable center )
|
||||
{
|
||||
this.center = center;
|
||||
}
|
||||
protected void setCenter(final IPartCable center) {
|
||||
this.center = center;
|
||||
}
|
||||
|
||||
protected IPart getSide( final AEPartLocation side )
|
||||
{
|
||||
final int x = side.ordinal();
|
||||
if( this.sides != null && this.sides.length > x )
|
||||
{
|
||||
return this.sides[x];
|
||||
}
|
||||
protected IPart getSide(final AEPartLocation side) {
|
||||
final int x = side.ordinal();
|
||||
if (this.sides != null && this.sides.length > x) {
|
||||
return this.sides[x];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void setSide( final AEPartLocation side, final IPart part )
|
||||
{
|
||||
final int x = side.ordinal();
|
||||
protected void setSide(final AEPartLocation side, final IPart part) {
|
||||
final int x = side.ordinal();
|
||||
|
||||
if( this.sides != null && this.sides.length > x && part == null )
|
||||
{
|
||||
this.sides[x] = null;
|
||||
this.sides = this.shrink( this.sides, true );
|
||||
}
|
||||
else if( part != null )
|
||||
{
|
||||
this.sides = this.grow( this.sides, x, true );
|
||||
this.sides[x] = part;
|
||||
}
|
||||
}
|
||||
if (this.sides != null && this.sides.length > x && part == null) {
|
||||
this.sides[x] = null;
|
||||
this.sides = this.shrink(this.sides, true);
|
||||
} else if (part != null) {
|
||||
this.sides = this.grow(this.sides, x, true);
|
||||
this.sides[x] = part;
|
||||
}
|
||||
}
|
||||
|
||||
private <T> T[] shrink( final T[] in, final boolean parts )
|
||||
{
|
||||
int newSize = -1;
|
||||
for( int x = 0; x < in.length; x++ )
|
||||
{
|
||||
if( in[x] != null )
|
||||
{
|
||||
newSize = x;
|
||||
}
|
||||
}
|
||||
private <T> T[] shrink(final T[] in, final boolean parts) {
|
||||
int newSize = -1;
|
||||
for (int x = 0; x < in.length; x++) {
|
||||
if (in[x] != null) {
|
||||
newSize = x;
|
||||
}
|
||||
}
|
||||
|
||||
if( newSize == -1 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (newSize == -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
newSize++;
|
||||
if( newSize == in.length )
|
||||
{
|
||||
return in;
|
||||
}
|
||||
newSize++;
|
||||
if (newSize == in.length) {
|
||||
return in;
|
||||
}
|
||||
|
||||
final T[] newArray = (T[]) ( parts ? new IPart[newSize] : new IFacadePart[newSize] );
|
||||
System.arraycopy( in, 0, newArray, 0, newSize );
|
||||
final T[] newArray = (T[]) (parts ? new IPart[newSize] : new IFacadePart[newSize]);
|
||||
System.arraycopy(in, 0, newArray, 0, newSize);
|
||||
|
||||
return newArray;
|
||||
}
|
||||
return newArray;
|
||||
}
|
||||
|
||||
private <T> T[] grow( final T[] in, final int newValue, final boolean parts )
|
||||
{
|
||||
if( in != null && in.length > newValue )
|
||||
{
|
||||
return in;
|
||||
}
|
||||
private <T> T[] grow(final T[] in, final int newValue, final boolean parts) {
|
||||
if (in != null && in.length > newValue) {
|
||||
return in;
|
||||
}
|
||||
|
||||
final int newSize = newValue + 1;
|
||||
final int newSize = newValue + 1;
|
||||
|
||||
final T[] newArray = (T[]) ( parts ? new IPart[newSize] : new IFacadePart[newSize] );
|
||||
if( in != null )
|
||||
{
|
||||
System.arraycopy( in, 0, newArray, 0, in.length );
|
||||
}
|
||||
final T[] newArray = (T[]) (parts ? new IPart[newSize] : new IFacadePart[newSize]);
|
||||
if (in != null) {
|
||||
System.arraycopy(in, 0, newArray, 0, in.length);
|
||||
}
|
||||
|
||||
return newArray;
|
||||
}
|
||||
return newArray;
|
||||
}
|
||||
|
||||
public IFacadePart getFacade( final int x )
|
||||
{
|
||||
if( this.facades != null && this.facades.length > x )
|
||||
{
|
||||
return this.facades[x];
|
||||
}
|
||||
public IFacadePart getFacade(final int x) {
|
||||
if (this.facades != null && this.facades.length > x) {
|
||||
return this.facades[x];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setFacade( final int x, @Nullable final IFacadePart facade )
|
||||
{
|
||||
if( this.facades != null && this.facades.length > x && facade == null )
|
||||
{
|
||||
this.facades[x] = null;
|
||||
this.facades = this.shrink( this.facades, false );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.facades = this.grow( this.facades, x, false );
|
||||
this.facades[x] = facade;
|
||||
}
|
||||
}
|
||||
public void setFacade(final int x, @Nullable final IFacadePart facade) {
|
||||
if (this.facades != null && this.facades.length > x && facade == null) {
|
||||
this.facades[x] = null;
|
||||
this.facades = this.shrink(this.facades, false);
|
||||
} else {
|
||||
this.facades = this.grow(this.facades, x, false);
|
||||
this.facades[x] = facade;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
package appeng.parts;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Random;
|
||||
|
||||
import appeng.api.parts.SelectedPart;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.client.render.cablebus.CableBusRenderState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -34,43 +34,41 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.api.parts.SelectedPart;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.client.render.cablebus.CableBusRenderState;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public interface ICableBusContainer
|
||||
{
|
||||
public interface ICableBusContainer {
|
||||
|
||||
int isProvidingStrongPower( EnumFacing opposite );
|
||||
int isProvidingStrongPower(EnumFacing opposite);
|
||||
|
||||
int isProvidingWeakPower( EnumFacing opposite );
|
||||
int isProvidingWeakPower(EnumFacing opposite);
|
||||
|
||||
boolean canConnectRedstone( EnumSet<EnumFacing> of );
|
||||
boolean canConnectRedstone(EnumSet<EnumFacing> of);
|
||||
|
||||
void onEntityCollision( Entity e );
|
||||
void onEntityCollision(Entity e);
|
||||
|
||||
boolean activate( EntityPlayer player, EnumHand hand, Vec3d vecFromPool );
|
||||
boolean activate(EntityPlayer player, EnumHand hand, Vec3d vecFromPool);
|
||||
|
||||
boolean clicked( EntityPlayer player, EnumHand hand, Vec3d hitVec );
|
||||
boolean clicked(EntityPlayer player, EnumHand hand, Vec3d hitVec);
|
||||
|
||||
void onNeighborChanged( IBlockAccess w, BlockPos pos, BlockPos neighbor );
|
||||
void onNeighborChanged(IBlockAccess w, BlockPos pos, BlockPos neighbor);
|
||||
|
||||
boolean isSolidOnSide( EnumFacing side );
|
||||
boolean isSolidOnSide(EnumFacing side);
|
||||
|
||||
boolean isEmpty();
|
||||
boolean isEmpty();
|
||||
|
||||
SelectedPart selectPart( Vec3d v3 );
|
||||
SelectedPart selectPart(Vec3d v3);
|
||||
|
||||
boolean recolourBlock( EnumFacing side, AEColor colour, EntityPlayer who );
|
||||
boolean recolourBlock(EnumFacing side, AEColor colour, EntityPlayer who);
|
||||
|
||||
boolean isLadder( EntityLivingBase entity );
|
||||
boolean isLadder(EntityLivingBase entity);
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
void randomDisplayTick( World world, BlockPos pos, Random r );
|
||||
@SideOnly(Side.CLIENT)
|
||||
void randomDisplayTick(World world, BlockPos pos, Random r);
|
||||
|
||||
int getLightValue();
|
||||
int getLightValue();
|
||||
|
||||
CableBusRenderState getRenderState();
|
||||
CableBusRenderState getRenderState();
|
||||
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
package appeng.parts;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Random;
|
||||
|
||||
import appeng.api.parts.SelectedPart;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.client.render.cablebus.CableBusRenderState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -32,102 +32,85 @@ import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.parts.SelectedPart;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.client.render.cablebus.CableBusRenderState;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class NullCableBusContainer implements ICableBusContainer
|
||||
{
|
||||
public class NullCableBusContainer implements ICableBusContainer {
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower( final EnumFacing opposite )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int isProvidingStrongPower(final EnumFacing opposite) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower( final EnumFacing opposite )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int isProvidingWeakPower(final EnumFacing opposite) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone( final EnumSet<EnumFacing> of )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean canConnectRedstone(final EnumSet<EnumFacing> of) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityCollision( final Entity e )
|
||||
{
|
||||
@Override
|
||||
public void onEntityCollision(final Entity e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activate( final EntityPlayer player, final EnumHand hand, final Vec3d vecFromPool )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean activate(final EntityPlayer player, final EnumHand hand, final Vec3d vecFromPool) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged( IBlockAccess w, BlockPos pos, BlockPos neighbor )
|
||||
{
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockAccess w, BlockPos pos, BlockPos neighbor) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolidOnSide( final EnumFacing side )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isSolidOnSide(final EnumFacing side) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SelectedPart selectPart( final Vec3d v3 )
|
||||
{
|
||||
return new SelectedPart();
|
||||
}
|
||||
@Override
|
||||
public SelectedPart selectPart(final Vec3d v3) {
|
||||
return new SelectedPart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean recolourBlock( final EnumFacing side, final AEColor colour, final EntityPlayer who )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean recolourBlock(final EnumFacing side, final AEColor colour, final EntityPlayer who) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLadder( final EntityLivingBase entity )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isLadder(final EntityLivingBase entity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomDisplayTick( final World world, final BlockPos pos, final Random r )
|
||||
{
|
||||
@Override
|
||||
public void randomDisplayTick(final World world, final BlockPos pos, final Random r) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightValue()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int getLightValue() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CableBusRenderState getRenderState()
|
||||
{
|
||||
return new CableBusRenderState();
|
||||
}
|
||||
@Override
|
||||
public CableBusRenderState getRenderState() {
|
||||
return new CableBusRenderState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean clicked( EntityPlayer player, EnumHand hand, Vec3d hitVec )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean clicked(EntityPlayer player, EnumHand hand, Vec3d hitVec) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,12 +19,6 @@
|
||||
package appeng.parts;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.implementations.IPowerChannelState;
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.events.MENetworkBootingStatusChange;
|
||||
@@ -32,104 +26,91 @@ import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.me.GridAccessException;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public abstract class PartBasicState extends AEBasePart implements IPowerChannelState
|
||||
{
|
||||
public abstract class PartBasicState extends AEBasePart implements IPowerChannelState {
|
||||
|
||||
protected static final int POWERED_FLAG = 1;
|
||||
protected static final int CHANNEL_FLAG = 2;
|
||||
protected static final int POWERED_FLAG = 1;
|
||||
protected static final int CHANNEL_FLAG = 2;
|
||||
|
||||
private int clientFlags = 0; // sent as byte.
|
||||
private int clientFlags = 0; // sent as byte.
|
||||
|
||||
public PartBasicState( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
this.getProxy().setFlags( GridFlags.REQUIRE_CHANNEL );
|
||||
}
|
||||
public PartBasicState(final ItemStack is) {
|
||||
super(is);
|
||||
this.getProxy().setFlags(GridFlags.REQUIRE_CHANNEL);
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void chanRender( final MENetworkChannelsChanged c )
|
||||
{
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void chanRender(final MENetworkChannelsChanged c) {
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(final MENetworkPowerStatusChange c) {
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void bootingRender( final MENetworkBootingStatusChange bs )
|
||||
{
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void bootingRender(final MENetworkBootingStatusChange bs) {
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream( final ByteBuf data ) throws IOException
|
||||
{
|
||||
super.writeToStream( data );
|
||||
@Override
|
||||
public void writeToStream(final ByteBuf data) throws IOException {
|
||||
super.writeToStream(data);
|
||||
|
||||
this.setClientFlags( 0 );
|
||||
this.setClientFlags(0);
|
||||
|
||||
try
|
||||
{
|
||||
if( this.getProxy().getEnergy().isNetworkPowered() )
|
||||
{
|
||||
this.setClientFlags( this.getClientFlags() | POWERED_FLAG );
|
||||
}
|
||||
try {
|
||||
if (this.getProxy().getEnergy().isNetworkPowered()) {
|
||||
this.setClientFlags(this.getClientFlags() | POWERED_FLAG);
|
||||
}
|
||||
|
||||
if( this.getProxy().getNode().meetsChannelRequirements() )
|
||||
{
|
||||
this.setClientFlags( this.getClientFlags() | CHANNEL_FLAG );
|
||||
}
|
||||
if (this.getProxy().getNode().meetsChannelRequirements()) {
|
||||
this.setClientFlags(this.getClientFlags() | CHANNEL_FLAG);
|
||||
}
|
||||
|
||||
this.setClientFlags( this.populateFlags( this.getClientFlags() ) );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// meh
|
||||
}
|
||||
this.setClientFlags(this.populateFlags(this.getClientFlags()));
|
||||
} catch (final GridAccessException e) {
|
||||
// meh
|
||||
}
|
||||
|
||||
data.writeByte( (byte) this.getClientFlags() );
|
||||
}
|
||||
data.writeByte((byte) this.getClientFlags());
|
||||
}
|
||||
|
||||
protected int populateFlags( final int cf )
|
||||
{
|
||||
return cf;
|
||||
}
|
||||
protected int populateFlags(final int cf) {
|
||||
return cf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream( final ByteBuf data ) throws IOException
|
||||
{
|
||||
final boolean eh = super.readFromStream( data );
|
||||
@Override
|
||||
public boolean readFromStream(final ByteBuf data) throws IOException {
|
||||
final boolean eh = super.readFromStream(data);
|
||||
|
||||
final int old = this.getClientFlags();
|
||||
this.setClientFlags( data.readByte() );
|
||||
final int old = this.getClientFlags();
|
||||
this.setClientFlags(data.readByte());
|
||||
|
||||
return eh || old != this.getClientFlags();
|
||||
}
|
||||
return eh || old != this.getClientFlags();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPowered()
|
||||
{
|
||||
return ( this.getClientFlags() & POWERED_FLAG ) == POWERED_FLAG;
|
||||
}
|
||||
@Override
|
||||
public boolean isPowered() {
|
||||
return (this.getClientFlags() & POWERED_FLAG) == POWERED_FLAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive()
|
||||
{
|
||||
return ( this.getClientFlags() & CHANNEL_FLAG ) == CHANNEL_FLAG;
|
||||
}
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return (this.getClientFlags() & CHANNEL_FLAG) == CHANNEL_FLAG;
|
||||
}
|
||||
|
||||
public int getClientFlags()
|
||||
{
|
||||
return this.clientFlags;
|
||||
}
|
||||
public int getClientFlags() {
|
||||
return this.clientFlags;
|
||||
}
|
||||
|
||||
private void setClientFlags( final int clientFlags )
|
||||
{
|
||||
this.clientFlags = clientFlags;
|
||||
}
|
||||
private void setClientFlags(final int clientFlags) {
|
||||
this.clientFlags = clientFlags;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,62 +19,51 @@
|
||||
package appeng.parts;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class PartModel implements IPartModel
|
||||
{
|
||||
private final boolean isSolid;
|
||||
public class PartModel implements IPartModel {
|
||||
private final boolean isSolid;
|
||||
|
||||
private final List<ResourceLocation> resources;
|
||||
private final List<ResourceLocation> resources;
|
||||
|
||||
public PartModel( ResourceLocation resource )
|
||||
{
|
||||
this( true, resource );
|
||||
}
|
||||
public PartModel(ResourceLocation resource) {
|
||||
this(true, resource);
|
||||
}
|
||||
|
||||
public PartModel( ResourceLocation... resources )
|
||||
{
|
||||
this( true, resources );
|
||||
}
|
||||
public PartModel(ResourceLocation... resources) {
|
||||
this(true, resources);
|
||||
}
|
||||
|
||||
public PartModel( boolean isSolid, ResourceLocation resource )
|
||||
{
|
||||
this( isSolid, ImmutableList.of( resource ) );
|
||||
}
|
||||
public PartModel(boolean isSolid, ResourceLocation resource) {
|
||||
this(isSolid, ImmutableList.of(resource));
|
||||
}
|
||||
|
||||
public PartModel( boolean isSolid, ResourceLocation... resources )
|
||||
{
|
||||
this( isSolid, ImmutableList.copyOf( resources ) );
|
||||
}
|
||||
public PartModel(boolean isSolid, ResourceLocation... resources) {
|
||||
this(isSolid, ImmutableList.copyOf(resources));
|
||||
}
|
||||
|
||||
public PartModel( List<ResourceLocation> resources )
|
||||
{
|
||||
this( true, resources );
|
||||
}
|
||||
public PartModel(List<ResourceLocation> resources) {
|
||||
this(true, resources);
|
||||
}
|
||||
|
||||
public PartModel( boolean isSolid, List<ResourceLocation> resources )
|
||||
{
|
||||
this.isSolid = isSolid;
|
||||
this.resources = resources;
|
||||
}
|
||||
public PartModel(boolean isSolid, List<ResourceLocation> resources) {
|
||||
this.isSolid = isSolid;
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requireCableConnection()
|
||||
{
|
||||
return this.isSolid;
|
||||
}
|
||||
@Override
|
||||
public boolean requireCableConnection() {
|
||||
return this.isSolid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceLocation> getModels()
|
||||
{
|
||||
return this.resources;
|
||||
}
|
||||
@Override
|
||||
public List<ResourceLocation> getModels() {
|
||||
return this.resources;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,10 +19,19 @@
|
||||
package appeng.parts;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import appeng.api.definitions.IItems;
|
||||
import appeng.api.parts.*;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketClick;
|
||||
import appeng.core.sync.packets.PacketPartPlacement;
|
||||
import appeng.facade.IFacadeItem;
|
||||
import appeng.util.LookDirection;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -45,436 +54,341 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import appeng.api.definitions.IItems;
|
||||
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.AEPartLocation;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketClick;
|
||||
import appeng.core.sync.packets.PacketPartPlacement;
|
||||
import appeng.facade.IFacadeItem;
|
||||
import appeng.util.LookDirection;
|
||||
import appeng.util.Platform;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class PartPlacement
|
||||
{
|
||||
public class PartPlacement {
|
||||
|
||||
private static float eyeHeight = 0.0f;
|
||||
private final ThreadLocal<Object> placing = new ThreadLocal<>();
|
||||
private boolean wasCanceled = false;
|
||||
private static float eyeHeight = 0.0f;
|
||||
private final ThreadLocal<Object> placing = new ThreadLocal<>();
|
||||
private boolean wasCanceled = false;
|
||||
|
||||
public static EnumActionResult place( final ItemStack held, final BlockPos pos, EnumFacing side, final EntityPlayer player, final EnumHand hand, final World world, PlaceType pass, final int depth )
|
||||
{
|
||||
if( depth > 3 )
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
public static EnumActionResult place(final ItemStack held, final BlockPos pos, EnumFacing side, final EntityPlayer player, final EnumHand hand, final World world, PlaceType pass, final int depth) {
|
||||
if (depth > 3) {
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
|
||||
if( !held.isEmpty() && Platform.isWrench( player, held, pos ) && player.isSneaking() )
|
||||
{
|
||||
if( !Platform.hasPermissions( new DimensionalCoord( world, pos ), player ) )
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
if (!held.isEmpty() && Platform.isWrench(player, held, pos) && player.isSneaking()) {
|
||||
if (!Platform.hasPermissions(new DimensionalCoord(world, pos), player)) {
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
|
||||
final Block block = world.getBlockState( pos ).getBlock();
|
||||
final TileEntity tile = world.getTileEntity( pos );
|
||||
IPartHost host = null;
|
||||
final Block block = world.getBlockState(pos).getBlock();
|
||||
final TileEntity tile = world.getTileEntity(pos);
|
||||
IPartHost host = null;
|
||||
|
||||
if( tile instanceof IPartHost )
|
||||
{
|
||||
host = (IPartHost) tile;
|
||||
}
|
||||
if (tile instanceof IPartHost) {
|
||||
host = (IPartHost) tile;
|
||||
}
|
||||
|
||||
if( host != null )
|
||||
{
|
||||
if( !world.isRemote )
|
||||
{
|
||||
final LookDirection dir = Platform.getPlayerRay( player, getEyeOffset( player ) );
|
||||
final RayTraceResult mop = block.collisionRayTrace( world.getBlockState( pos ), world, pos, dir.getA(), dir.getB() );
|
||||
if (host != null) {
|
||||
if (!world.isRemote) {
|
||||
final LookDirection dir = Platform.getPlayerRay(player, getEyeOffset(player));
|
||||
final RayTraceResult mop = block.collisionRayTrace(world.getBlockState(pos), world, pos, dir.getA(), dir.getB());
|
||||
|
||||
if( mop != null )
|
||||
{
|
||||
final List<ItemStack> is = new ArrayList<>();
|
||||
final SelectedPart sp = selectPart( player, host,
|
||||
mop.hitVec.addVector( -mop.getBlockPos().getX(), -mop.getBlockPos().getY(), -mop.getBlockPos().getZ() ) );
|
||||
if (mop != null) {
|
||||
final List<ItemStack> is = new ArrayList<>();
|
||||
final SelectedPart sp = selectPart(player, host,
|
||||
mop.hitVec.addVector(-mop.getBlockPos().getX(), -mop.getBlockPos().getY(), -mop.getBlockPos().getZ()));
|
||||
|
||||
if( sp.part != null )
|
||||
{
|
||||
is.add( sp.part.getItemStack( PartItemStack.WRENCH ) );
|
||||
sp.part.getDrops( is, true );
|
||||
host.removePart( sp.side, false );
|
||||
}
|
||||
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, pos );
|
||||
}
|
||||
if (sp.facade != null) {
|
||||
is.add(sp.facade.getItemStack());
|
||||
host.getFacadeContainer().removeFacade(host, sp.side);
|
||||
Platform.notifyBlocksOfNeighbors(world, pos);
|
||||
}
|
||||
|
||||
if( host.isEmpty() )
|
||||
{
|
||||
host.cleanup();
|
||||
}
|
||||
if (host.isEmpty()) {
|
||||
host.cleanup();
|
||||
}
|
||||
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
Platform.spawnDrops( world, pos, is );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.swingArm( hand );
|
||||
NetworkHandler.instance().sendToServer( new PacketPartPlacement( pos, side, getEyeOffset( player ), hand ) );
|
||||
}
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
if (!is.isEmpty()) {
|
||||
Platform.spawnDrops(world, pos, is);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
player.swingArm(hand);
|
||||
NetworkHandler.instance().sendToServer(new PacketPartPlacement(pos, side, getEyeOffset(player), hand));
|
||||
}
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
IPartHost host = null;
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
IPartHost host = null;
|
||||
|
||||
if( tile instanceof IPartHost )
|
||||
{
|
||||
host = (IPartHost) tile;
|
||||
}
|
||||
if (tile instanceof IPartHost) {
|
||||
host = (IPartHost) tile;
|
||||
}
|
||||
|
||||
if( !held.isEmpty() )
|
||||
{
|
||||
final IFacadePart fp = isFacade( held, AEPartLocation.fromFacing( side ) );
|
||||
if( fp != null )
|
||||
{
|
||||
if( host != null )
|
||||
{
|
||||
if( !world.isRemote )
|
||||
{
|
||||
if( host.getPart( AEPartLocation.INTERNAL ) == null )
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
if (!held.isEmpty()) {
|
||||
final IFacadePart fp = isFacade(held, AEPartLocation.fromFacing(side));
|
||||
if (fp != null) {
|
||||
if (host != null) {
|
||||
if (!world.isRemote) {
|
||||
if (host.getPart(AEPartLocation.INTERNAL) == null) {
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
|
||||
if( host.canAddPart( held, AEPartLocation.fromFacing( side ) ) )
|
||||
{
|
||||
if( host.getFacadeContainer().addFacade( fp ) )
|
||||
{
|
||||
host.markForSave();
|
||||
host.markForUpdate();
|
||||
if( !player.capabilities.isCreativeMode )
|
||||
{
|
||||
held.grow( -1 );
|
||||
;
|
||||
if( held.getCount() == 0 )
|
||||
{
|
||||
player.setHeldItem( hand, ItemStack.EMPTY );
|
||||
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( player, held, hand ) );
|
||||
}
|
||||
}
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.swingArm( hand );
|
||||
NetworkHandler.instance().sendToServer( new PacketPartPlacement( pos, side, getEyeOffset( player ), hand ) );
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
if (host.canAddPart(held, AEPartLocation.fromFacing(side))) {
|
||||
if (host.getFacadeContainer().addFacade(fp)) {
|
||||
host.markForSave();
|
||||
host.markForUpdate();
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
held.grow(-1);
|
||||
if (held.getCount() == 0) {
|
||||
player.setHeldItem(hand, ItemStack.EMPTY);
|
||||
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held, hand));
|
||||
}
|
||||
}
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
player.swingArm(hand);
|
||||
NetworkHandler.instance().sendToServer(new PacketPartPlacement(pos, side, getEyeOffset(player), hand));
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
if( held.isEmpty() )
|
||||
{
|
||||
final Block block = world.getBlockState( pos ).getBlock();
|
||||
if( host != null && player.isSneaking() && block != null )
|
||||
{
|
||||
final LookDirection dir = Platform.getPlayerRay( player, getEyeOffset( player ) );
|
||||
final RayTraceResult mop = block.collisionRayTrace( world.getBlockState( pos ), world, pos, dir.getA(), dir.getB() );
|
||||
if (held.isEmpty()) {
|
||||
final Block block = world.getBlockState(pos).getBlock();
|
||||
if (host != null && player.isSneaking() && block != null) {
|
||||
final LookDirection dir = Platform.getPlayerRay(player, getEyeOffset(player));
|
||||
final RayTraceResult mop = block.collisionRayTrace(world.getBlockState(pos), world, pos, dir.getA(), dir.getB());
|
||||
|
||||
if( mop != null )
|
||||
{
|
||||
mop.hitVec = mop.hitVec.addVector( -mop.getBlockPos().getX(), -mop.getBlockPos().getY(), -mop.getBlockPos().getZ() );
|
||||
final SelectedPart sPart = selectPart( player, host, mop.hitVec );
|
||||
if( sPart != null && sPart.part != null )
|
||||
{
|
||||
if( sPart.part.onShiftActivate( player, hand, mop.hitVec ) )
|
||||
{
|
||||
if( world.isRemote )
|
||||
{
|
||||
NetworkHandler.instance().sendToServer( new PacketPartPlacement( pos, side, getEyeOffset( player ), hand ) );
|
||||
}
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mop != null) {
|
||||
mop.hitVec = mop.hitVec.addVector(-mop.getBlockPos().getX(), -mop.getBlockPos().getY(), -mop.getBlockPos().getZ());
|
||||
final SelectedPart sPart = selectPart(player, host, mop.hitVec);
|
||||
if (sPart != null && sPart.part != null) {
|
||||
if (sPart.part.onShiftActivate(player, hand, mop.hitVec)) {
|
||||
if (world.isRemote) {
|
||||
NetworkHandler.instance().sendToServer(new PacketPartPlacement(pos, side, getEyeOffset(player), hand));
|
||||
}
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( held.isEmpty() || !( held.getItem() instanceof IPartItem ) )
|
||||
{
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
if (held.isEmpty() || !(held.getItem() instanceof IPartItem)) {
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
|
||||
BlockPos te_pos = pos;
|
||||
BlockPos te_pos = pos;
|
||||
|
||||
final IBlockDefinition multiPart = AEApi.instance().definitions().blocks().multiPart();
|
||||
if( host == null && pass == PlaceType.PLACE_ITEM )
|
||||
{
|
||||
EnumFacing offset = null;
|
||||
final IBlockDefinition multiPart = AEApi.instance().definitions().blocks().multiPart();
|
||||
if (host == null && pass == PlaceType.PLACE_ITEM) {
|
||||
EnumFacing offset = null;
|
||||
|
||||
final Block blkID = world.getBlockState( pos ).getBlock();
|
||||
if( blkID != null && !blkID.isReplaceable( world, pos ) )
|
||||
{
|
||||
offset = side;
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
side = side.getOpposite();
|
||||
}
|
||||
}
|
||||
final Block blkID = world.getBlockState(pos).getBlock();
|
||||
if (blkID != null && !blkID.isReplaceable(world, pos)) {
|
||||
offset = side;
|
||||
if (Platform.isServer()) {
|
||||
side = side.getOpposite();
|
||||
}
|
||||
}
|
||||
|
||||
te_pos = offset == null ? pos : pos.offset( offset );
|
||||
te_pos = offset == null ? pos : pos.offset(offset);
|
||||
|
||||
tile = world.getTileEntity( te_pos );
|
||||
if( tile instanceof IPartHost )
|
||||
{
|
||||
host = (IPartHost) tile;
|
||||
}
|
||||
tile = world.getTileEntity(te_pos);
|
||||
if (tile instanceof IPartHost) {
|
||||
host = (IPartHost) tile;
|
||||
}
|
||||
|
||||
final Optional<ItemStack> maybeMultiPartStack = multiPart.maybeStack( 1 );
|
||||
final Optional<Block> maybeMultiPartBlock = multiPart.maybeBlock();
|
||||
final Optional<ItemBlock> maybeMultiPartItemBlock = multiPart.maybeItemBlock();
|
||||
final Optional<ItemStack> maybeMultiPartStack = multiPart.maybeStack(1);
|
||||
final Optional<Block> maybeMultiPartBlock = multiPart.maybeBlock();
|
||||
final Optional<ItemBlock> maybeMultiPartItemBlock = multiPart.maybeItemBlock();
|
||||
|
||||
final boolean hostIsNotPresent = host == null;
|
||||
final boolean multiPartPresent = maybeMultiPartBlock.isPresent() && maybeMultiPartStack.isPresent() && maybeMultiPartItemBlock.isPresent();
|
||||
final boolean canMultiPartBePlaced = maybeMultiPartBlock.get().canPlaceBlockAt( world, te_pos );
|
||||
final boolean hostIsNotPresent = host == null;
|
||||
final boolean multiPartPresent = maybeMultiPartBlock.isPresent() && maybeMultiPartStack.isPresent() && maybeMultiPartItemBlock.isPresent();
|
||||
final boolean canMultiPartBePlaced = maybeMultiPartBlock.get().canPlaceBlockAt(world, te_pos);
|
||||
|
||||
if( hostIsNotPresent && multiPartPresent && canMultiPartBePlaced && maybeMultiPartItemBlock.get()
|
||||
.placeBlockAt( maybeMultiPartStack.get(), player,
|
||||
world, te_pos, side, 0.5f, 0.5f, 0.5f, maybeMultiPartBlock.get().getDefaultState() ) )
|
||||
{
|
||||
if( !world.isRemote )
|
||||
{
|
||||
tile = world.getTileEntity( te_pos );
|
||||
if (hostIsNotPresent && multiPartPresent && canMultiPartBePlaced && maybeMultiPartItemBlock.get()
|
||||
.placeBlockAt(maybeMultiPartStack.get(), player,
|
||||
world, te_pos, side, 0.5f, 0.5f, 0.5f, maybeMultiPartBlock.get().getDefaultState())) {
|
||||
if (!world.isRemote) {
|
||||
tile = world.getTileEntity(te_pos);
|
||||
|
||||
if( tile instanceof IPartHost )
|
||||
{
|
||||
host = (IPartHost) tile;
|
||||
}
|
||||
if (tile instanceof IPartHost) {
|
||||
host = (IPartHost) tile;
|
||||
}
|
||||
|
||||
pass = PlaceType.INTERACT_SECOND_PASS;
|
||||
}
|
||||
else
|
||||
{
|
||||
player.swingArm( hand );
|
||||
NetworkHandler.instance().sendToServer( new PacketPartPlacement( pos, side, getEyeOffset( player ), hand ) );
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
else if( host != null && !host.canAddPart( held, AEPartLocation.fromFacing( side ) ) )
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
pass = PlaceType.INTERACT_SECOND_PASS;
|
||||
} else {
|
||||
player.swingArm(hand);
|
||||
NetworkHandler.instance().sendToServer(new PacketPartPlacement(pos, side, getEyeOffset(player), hand));
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
} else if (host != null && !host.canAddPart(held, AEPartLocation.fromFacing(side))) {
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
if( host == null )
|
||||
{
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
if (host == null) {
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
|
||||
if( !host.canAddPart( held, AEPartLocation.fromFacing( side ) ) )
|
||||
{
|
||||
if( pass == PlaceType.INTERACT_FIRST_PASS || pass == PlaceType.PLACE_ITEM )
|
||||
{
|
||||
te_pos = pos.offset( side );
|
||||
if (!host.canAddPart(held, AEPartLocation.fromFacing(side))) {
|
||||
if (pass == PlaceType.INTERACT_FIRST_PASS || pass == PlaceType.PLACE_ITEM) {
|
||||
te_pos = pos.offset(side);
|
||||
|
||||
final Block blkID = world.getBlockState( te_pos ).getBlock();
|
||||
final Block blkID = world.getBlockState(te_pos).getBlock();
|
||||
|
||||
if( blkID == null || blkID.isReplaceable( world, te_pos ) || host != null )
|
||||
{
|
||||
return place( held, te_pos, side.getOpposite(), player, hand, world,
|
||||
pass == PlaceType.INTERACT_FIRST_PASS ? PlaceType.INTERACT_SECOND_PASS : PlaceType.PLACE_ITEM, depth + 1 );
|
||||
}
|
||||
}
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
if (blkID == null || blkID.isReplaceable(world, te_pos) || host != null) {
|
||||
return place(held, te_pos, side.getOpposite(), player, hand, world,
|
||||
pass == PlaceType.INTERACT_FIRST_PASS ? PlaceType.INTERACT_SECOND_PASS : PlaceType.PLACE_ITEM, depth + 1);
|
||||
}
|
||||
}
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
|
||||
if( !world.isRemote )
|
||||
{
|
||||
final IBlockState state = world.getBlockState( pos );
|
||||
final LookDirection dir = Platform.getPlayerRay( player, getEyeOffset( player ) );
|
||||
final RayTraceResult mop = state.getBlock().collisionRayTrace( state, world, pos, dir.getA(), dir.getB() );
|
||||
if (!world.isRemote) {
|
||||
final IBlockState state = world.getBlockState(pos);
|
||||
final LookDirection dir = Platform.getPlayerRay(player, getEyeOffset(player));
|
||||
final RayTraceResult mop = state.getBlock().collisionRayTrace(state, world, pos, dir.getA(), dir.getB());
|
||||
|
||||
if( mop != null )
|
||||
{
|
||||
final SelectedPart sp = selectPart( player, host,
|
||||
mop.hitVec.addVector( -mop.getBlockPos().getX(), -mop.getBlockPos().getY(), -mop.getBlockPos().getZ() ) );
|
||||
if (mop != null) {
|
||||
final SelectedPart sp = selectPart(player, host,
|
||||
mop.hitVec.addVector(-mop.getBlockPos().getX(), -mop.getBlockPos().getY(), -mop.getBlockPos().getZ()));
|
||||
|
||||
if( sp.part != null )
|
||||
{
|
||||
if( !player.isSneaking() && sp.part.onActivate( player, hand, mop.hitVec ) )
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sp.part != null) {
|
||||
if (!player.isSneaking() && sp.part.onActivate(player, hand, mop.hitVec)) {
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final DimensionalCoord dc = host.getLocation();
|
||||
if( !Platform.hasPermissions( dc, player ) )
|
||||
{
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
final DimensionalCoord dc = host.getLocation();
|
||||
if (!Platform.hasPermissions(dc, player)) {
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
|
||||
final AEPartLocation mySide = host.addPart( held, AEPartLocation.fromFacing( side ), player, hand );
|
||||
if( mySide != null )
|
||||
{
|
||||
multiPart.maybeBlock().ifPresent( multiPartBlock ->
|
||||
{
|
||||
final SoundType ss = multiPartBlock.getSoundType( state, world, pos, player );
|
||||
final AEPartLocation mySide = host.addPart(held, AEPartLocation.fromFacing(side), player, hand);
|
||||
if (mySide != null) {
|
||||
multiPart.maybeBlock().ifPresent(multiPartBlock ->
|
||||
{
|
||||
final SoundType ss = multiPartBlock.getSoundType(state, world, pos, player);
|
||||
|
||||
world.playSound( null, pos, ss.getPlaceSound(), SoundCategory.BLOCKS, ( ss.getVolume() + 1.0F ) / 2.0F, ss.getPitch() * 0.8F );
|
||||
} );
|
||||
world.playSound(null, pos, ss.getPlaceSound(), SoundCategory.BLOCKS, (ss.getVolume() + 1.0F) / 2.0F, ss.getPitch() * 0.8F);
|
||||
});
|
||||
|
||||
if( !player.capabilities.isCreativeMode )
|
||||
{
|
||||
held.grow( -1 );
|
||||
if( held.getCount() == 0 )
|
||||
{
|
||||
player.setHeldItem( hand, ItemStack.EMPTY );
|
||||
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( player, held, hand ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player.swingArm( hand );
|
||||
}
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
held.grow(-1);
|
||||
if (held.getCount() == 0) {
|
||||
player.setHeldItem(hand, ItemStack.EMPTY);
|
||||
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held, hand));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
player.swingArm(hand);
|
||||
}
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
private static float getEyeOffset( final EntityPlayer p )
|
||||
{
|
||||
if( p.world.isRemote )
|
||||
{
|
||||
return Platform.getEyeOffset( p );
|
||||
}
|
||||
private static float getEyeOffset(final EntityPlayer p) {
|
||||
if (p.world.isRemote) {
|
||||
return Platform.getEyeOffset(p);
|
||||
}
|
||||
|
||||
return getEyeHeight();
|
||||
}
|
||||
return getEyeHeight();
|
||||
}
|
||||
|
||||
private static SelectedPart selectPart( final EntityPlayer player, final IPartHost host, final Vec3d pos )
|
||||
{
|
||||
AppEng.proxy.updateRenderMode( player );
|
||||
final SelectedPart sp = host.selectPart( pos );
|
||||
AppEng.proxy.updateRenderMode( null );
|
||||
private static SelectedPart selectPart(final EntityPlayer player, final IPartHost host, final Vec3d pos) {
|
||||
AppEng.proxy.updateRenderMode(player);
|
||||
final SelectedPart sp = host.selectPart(pos);
|
||||
AppEng.proxy.updateRenderMode(null);
|
||||
|
||||
return sp;
|
||||
}
|
||||
return sp;
|
||||
}
|
||||
|
||||
public static IFacadePart isFacade( final ItemStack held, final AEPartLocation side )
|
||||
{
|
||||
if( held.getItem() instanceof IFacadeItem )
|
||||
{
|
||||
return ( (IFacadeItem) held.getItem() ).createPartFromItemStack( held, side );
|
||||
}
|
||||
public static IFacadePart isFacade(final ItemStack held, final AEPartLocation side) {
|
||||
if (held.getItem() instanceof IFacadeItem) {
|
||||
return ((IFacadeItem) held.getItem()).createPartFromItemStack(held, side);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void playerInteract( final TickEvent.ClientTickEvent event )
|
||||
{
|
||||
this.wasCanceled = false;
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void playerInteract(final TickEvent.ClientTickEvent event) {
|
||||
this.wasCanceled = false;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void playerInteract( final PlayerInteractEvent event )
|
||||
{
|
||||
// Only handle the main hand event
|
||||
if( event.getHand() != EnumHand.MAIN_HAND )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void playerInteract(final PlayerInteractEvent event) {
|
||||
// Only handle the main hand event
|
||||
if (event.getHand() != EnumHand.MAIN_HAND) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( event instanceof PlayerInteractEvent.RightClickEmpty && event.getEntityPlayer().world.isRemote )
|
||||
{
|
||||
// re-check to see if this event was already channeled, cause these two events are really stupid...
|
||||
final RayTraceResult mop = Platform.rayTrace( event.getEntityPlayer(), true, false );
|
||||
final Minecraft mc = Minecraft.getMinecraft();
|
||||
if (event instanceof PlayerInteractEvent.RightClickEmpty && event.getEntityPlayer().world.isRemote) {
|
||||
// re-check to see if this event was already channeled, cause these two events are really stupid...
|
||||
final RayTraceResult mop = Platform.rayTrace(event.getEntityPlayer(), true, false);
|
||||
final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
final float f = 1.0F;
|
||||
final double d0 = mc.playerController.getBlockReachDistance();
|
||||
final Vec3d vec3 = mc.getRenderViewEntity().getPositionEyes( f );
|
||||
final float f = 1.0F;
|
||||
final double d0 = mc.playerController.getBlockReachDistance();
|
||||
final Vec3d vec3 = mc.getRenderViewEntity().getPositionEyes(f);
|
||||
|
||||
if( mop != null && mop.hitVec.distanceTo( vec3 ) < d0 )
|
||||
{
|
||||
final World w = event.getEntity().world;
|
||||
final TileEntity te = w.getTileEntity( mop.getBlockPos() );
|
||||
if( te instanceof IPartHost && this.wasCanceled )
|
||||
{
|
||||
event.setCanceled( true );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
final ItemStack held = event.getEntityPlayer().getHeldItem( event.getHand() );
|
||||
final IItems items = AEApi.instance().definitions().items();
|
||||
if (mop != null && mop.hitVec.distanceTo(vec3) < d0) {
|
||||
final World w = event.getEntity().world;
|
||||
final TileEntity te = w.getTileEntity(mop.getBlockPos());
|
||||
if (te instanceof IPartHost && this.wasCanceled) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
} else {
|
||||
final ItemStack held = event.getEntityPlayer().getHeldItem(event.getHand());
|
||||
final IItems items = AEApi.instance().definitions().items();
|
||||
|
||||
boolean supportedItem = items.memoryCard().isSameAs( held );
|
||||
supportedItem |= items.colorApplicator().isSameAs( held );
|
||||
boolean supportedItem = items.memoryCard().isSameAs(held);
|
||||
supportedItem |= items.colorApplicator().isSameAs(held);
|
||||
|
||||
if( event.getEntityPlayer().isSneaking() && !held.isEmpty() && supportedItem )
|
||||
{
|
||||
NetworkHandler.instance().sendToServer( new PacketClick( event.getPos(), event.getFace(), 0, 0, 0, event.getHand() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( event instanceof PlayerInteractEvent.RightClickBlock && !event.getEntityPlayer().world.isRemote )
|
||||
{
|
||||
if( this.placing.get() != null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event.getEntityPlayer().isSneaking() && !held.isEmpty() && supportedItem) {
|
||||
NetworkHandler.instance().sendToServer(new PacketClick(event.getPos(), event.getFace(), 0, 0, 0, event.getHand()));
|
||||
}
|
||||
}
|
||||
} else if (event instanceof PlayerInteractEvent.RightClickBlock && !event.getEntityPlayer().world.isRemote) {
|
||||
if (this.placing.get() != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.placing.set( event );
|
||||
this.placing.set(event);
|
||||
|
||||
final ItemStack held = event.getEntityPlayer().getHeldItem( event.getHand() );
|
||||
if( place( held, event.getPos(), event.getFace(), event.getEntityPlayer(), event.getHand(), event.getEntityPlayer().world,
|
||||
PlaceType.INTERACT_FIRST_PASS, 0 ) == EnumActionResult.SUCCESS )
|
||||
{
|
||||
event.setCanceled( true );
|
||||
this.wasCanceled = true;
|
||||
}
|
||||
final ItemStack held = event.getEntityPlayer().getHeldItem(event.getHand());
|
||||
if (place(held, event.getPos(), event.getFace(), event.getEntityPlayer(), event.getHand(), event.getEntityPlayer().world,
|
||||
PlaceType.INTERACT_FIRST_PASS, 0) == EnumActionResult.SUCCESS) {
|
||||
event.setCanceled(true);
|
||||
this.wasCanceled = true;
|
||||
}
|
||||
|
||||
this.placing.set( null );
|
||||
}
|
||||
}
|
||||
this.placing.set(null);
|
||||
}
|
||||
}
|
||||
|
||||
private static float getEyeHeight()
|
||||
{
|
||||
return eyeHeight;
|
||||
}
|
||||
private static float getEyeHeight() {
|
||||
return eyeHeight;
|
||||
}
|
||||
|
||||
public static void setEyeHeight( final float eyeHeight )
|
||||
{
|
||||
PartPlacement.eyeHeight = eyeHeight;
|
||||
}
|
||||
public static void setEyeHeight(final float eyeHeight) {
|
||||
PartPlacement.eyeHeight = eyeHeight;
|
||||
}
|
||||
|
||||
public enum PlaceType
|
||||
{
|
||||
PLACE_ITEM, INTERACT_FIRST_PASS, INTERACT_SECOND_PASS
|
||||
}
|
||||
public enum PlaceType {
|
||||
PLACE_ITEM, INTERACT_FIRST_PASS, INTERACT_SECOND_PASS
|
||||
}
|
||||
}
|
||||
@@ -19,41 +19,35 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
|
||||
public class BlockUpgradeInventory extends UpgradeInventory {
|
||||
private final Block block;
|
||||
|
||||
public class BlockUpgradeInventory extends UpgradeInventory
|
||||
{
|
||||
private final Block block;
|
||||
public BlockUpgradeInventory(final Block block, final IAEAppEngInventory parent, final int s) {
|
||||
super(parent, s);
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public BlockUpgradeInventory( final Block block, final IAEAppEngInventory parent, final int s )
|
||||
{
|
||||
super( parent, s );
|
||||
this.block = block;
|
||||
}
|
||||
@Override
|
||||
public int getMaxInstalled(final Upgrades upgrades) {
|
||||
int max = 0;
|
||||
|
||||
@Override
|
||||
public int getMaxInstalled( final Upgrades upgrades )
|
||||
{
|
||||
int max = 0;
|
||||
for (final ItemStack is : upgrades.getSupported().keySet()) {
|
||||
final Item encodedItem = is.getItem();
|
||||
|
||||
for( final ItemStack is : upgrades.getSupported().keySet() )
|
||||
{
|
||||
final Item encodedItem = is.getItem();
|
||||
if (encodedItem instanceof ItemBlock && Block.getBlockFromItem(encodedItem) == this.block) {
|
||||
max = upgrades.getSupported().get(is);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( encodedItem instanceof ItemBlock && Block.getBlockFromItem( encodedItem ) == this.block )
|
||||
{
|
||||
max = upgrades.getSupported().get( is );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,38 +19,32 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public final class DefinitionUpgradeInventory extends UpgradeInventory
|
||||
{
|
||||
private final IItemDefinition definition;
|
||||
public final class DefinitionUpgradeInventory extends UpgradeInventory {
|
||||
private final IItemDefinition definition;
|
||||
|
||||
public DefinitionUpgradeInventory( final IItemDefinition definition, final IAEAppEngInventory parent, final int s )
|
||||
{
|
||||
super( parent, s );
|
||||
public DefinitionUpgradeInventory(final IItemDefinition definition, final IAEAppEngInventory parent, final int s) {
|
||||
super(parent, s);
|
||||
|
||||
this.definition = definition;
|
||||
}
|
||||
this.definition = definition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxInstalled( final Upgrades upgrades )
|
||||
{
|
||||
int max = 0;
|
||||
@Override
|
||||
public int getMaxInstalled(final Upgrades upgrades) {
|
||||
int max = 0;
|
||||
|
||||
for( final ItemStack stack : upgrades.getSupported().keySet() )
|
||||
{
|
||||
if( this.definition.isSameAs( stack ) )
|
||||
{
|
||||
max = upgrades.getSupported().get( stack );
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (final ItemStack stack : upgrades.getSupported().keySet()) {
|
||||
if (this.definition.isSameAs(stack)) {
|
||||
max = upgrades.getSupported().get(stack);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.parts.IPart;
|
||||
@@ -23,243 +15,216 @@ import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
|
||||
public abstract class PartAbstractFormationPlane<T extends IAEStack<T>> extends PartUpgradeable implements ICellContainer, IPriorityHost, IMEInventory<T>
|
||||
{
|
||||
public abstract class PartAbstractFormationPlane<T extends IAEStack<T>> extends PartUpgradeable implements ICellContainer, IPriorityHost, IMEInventory<T> {
|
||||
|
||||
private boolean wasActive = false;
|
||||
private int priority = 0;
|
||||
protected boolean blocked = false;
|
||||
private boolean wasActive = false;
|
||||
private int priority = 0;
|
||||
protected boolean blocked = false;
|
||||
|
||||
public PartAbstractFormationPlane( ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
public PartAbstractFormationPlane(ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
protected abstract void updateHandler();
|
||||
protected abstract void updateHandler();
|
||||
|
||||
@Override
|
||||
protected int getUpgradeSlots()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
@Override
|
||||
protected int getUpgradeSlots() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upgradesChanged()
|
||||
{
|
||||
this.updateHandler();
|
||||
}
|
||||
@Override
|
||||
public void upgradesChanged() {
|
||||
this.updateHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
|
||||
{
|
||||
this.updateHandler();
|
||||
this.getHost().markForSave();
|
||||
}
|
||||
@Override
|
||||
public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) {
|
||||
this.updateHandler();
|
||||
this.getHost().markForSave();
|
||||
}
|
||||
|
||||
public void stateChanged()
|
||||
{
|
||||
final boolean currentActive = this.getProxy().isActive();
|
||||
if( this.wasActive != currentActive )
|
||||
{
|
||||
this.wasActive = currentActive;
|
||||
this.updateHandler();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
}
|
||||
public void stateChanged() {
|
||||
final boolean currentActive = this.getProxy().isActive();
|
||||
if (this.wasActive != currentActive) {
|
||||
this.wasActive = currentActive;
|
||||
this.updateHandler();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
int minX = 1;
|
||||
int minY = 1;
|
||||
int maxX = 15;
|
||||
int maxY = 15;
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
int minX = 1;
|
||||
int minY = 1;
|
||||
int maxX = 15;
|
||||
int maxY = 15;
|
||||
|
||||
final IPartHost host = this.getHost();
|
||||
if( host != null )
|
||||
{
|
||||
final TileEntity te = host.getTile();
|
||||
final IPartHost host = this.getHost();
|
||||
if (host != null) {
|
||||
final TileEntity te = host.getTile();
|
||||
|
||||
final BlockPos pos = te.getPos();
|
||||
final BlockPos pos = te.getPos();
|
||||
|
||||
final EnumFacing e = bch.getWorldX();
|
||||
final EnumFacing u = bch.getWorldY();
|
||||
final EnumFacing e = bch.getWorldX();
|
||||
final EnumFacing u = bch.getWorldY();
|
||||
|
||||
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( e.getOpposite() ) ), this.getSide() ) )
|
||||
{
|
||||
minX = 0;
|
||||
}
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(e.getOpposite())), this.getSide())) {
|
||||
minX = 0;
|
||||
}
|
||||
|
||||
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( e ) ), this.getSide() ) )
|
||||
{
|
||||
maxX = 16;
|
||||
}
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(e)), this.getSide())) {
|
||||
maxX = 16;
|
||||
}
|
||||
|
||||
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( u.getOpposite() ) ), this.getSide() ) )
|
||||
{
|
||||
minY = 0;
|
||||
}
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(u.getOpposite())), this.getSide())) {
|
||||
minY = 0;
|
||||
}
|
||||
|
||||
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( u ) ), this.getSide() ) )
|
||||
{
|
||||
maxY = 16;
|
||||
}
|
||||
}
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(u)), this.getSide())) {
|
||||
maxY = 16;
|
||||
}
|
||||
}
|
||||
|
||||
bch.addBox( 5, 5, 14, 11, 11, 15 );
|
||||
bch.addBox( minX, minY, 15, maxX, maxY, 16 );
|
||||
}
|
||||
bch.addBox(5, 5, 14, 11, 11, 15);
|
||||
bch.addBox(minX, minY, 15, maxX, maxY, 16);
|
||||
}
|
||||
|
||||
public PlaneConnections getConnections()
|
||||
{
|
||||
public PlaneConnections getConnections() {
|
||||
|
||||
final EnumFacing facingRight, facingUp;
|
||||
AEPartLocation location = this.getSide();
|
||||
switch( location )
|
||||
{
|
||||
case UP:
|
||||
facingRight = EnumFacing.EAST;
|
||||
facingUp = EnumFacing.NORTH;
|
||||
break;
|
||||
case DOWN:
|
||||
facingRight = EnumFacing.WEST;
|
||||
facingUp = EnumFacing.NORTH;
|
||||
break;
|
||||
case NORTH:
|
||||
facingRight = EnumFacing.WEST;
|
||||
facingUp = EnumFacing.UP;
|
||||
break;
|
||||
case SOUTH:
|
||||
facingRight = EnumFacing.EAST;
|
||||
facingUp = EnumFacing.UP;
|
||||
break;
|
||||
case WEST:
|
||||
facingRight = EnumFacing.SOUTH;
|
||||
facingUp = EnumFacing.UP;
|
||||
break;
|
||||
case EAST:
|
||||
facingRight = EnumFacing.NORTH;
|
||||
facingUp = EnumFacing.UP;
|
||||
break;
|
||||
default:
|
||||
case INTERNAL:
|
||||
return PlaneConnections.of( false, false, false, false );
|
||||
}
|
||||
final EnumFacing facingRight, facingUp;
|
||||
AEPartLocation location = this.getSide();
|
||||
switch (location) {
|
||||
case UP:
|
||||
facingRight = EnumFacing.EAST;
|
||||
facingUp = EnumFacing.NORTH;
|
||||
break;
|
||||
case DOWN:
|
||||
facingRight = EnumFacing.WEST;
|
||||
facingUp = EnumFacing.NORTH;
|
||||
break;
|
||||
case NORTH:
|
||||
facingRight = EnumFacing.WEST;
|
||||
facingUp = EnumFacing.UP;
|
||||
break;
|
||||
case SOUTH:
|
||||
facingRight = EnumFacing.EAST;
|
||||
facingUp = EnumFacing.UP;
|
||||
break;
|
||||
case WEST:
|
||||
facingRight = EnumFacing.SOUTH;
|
||||
facingUp = EnumFacing.UP;
|
||||
break;
|
||||
case EAST:
|
||||
facingRight = EnumFacing.NORTH;
|
||||
facingUp = EnumFacing.UP;
|
||||
break;
|
||||
default:
|
||||
case INTERNAL:
|
||||
return PlaneConnections.of(false, false, false, false);
|
||||
}
|
||||
|
||||
boolean left = false, right = false, down = false, up = false;
|
||||
boolean left = false, right = false, down = false, up = false;
|
||||
|
||||
final IPartHost host = this.getHost();
|
||||
if( host != null )
|
||||
{
|
||||
final TileEntity te = host.getTile();
|
||||
final IPartHost host = this.getHost();
|
||||
if (host != null) {
|
||||
final TileEntity te = host.getTile();
|
||||
|
||||
final BlockPos pos = te.getPos();
|
||||
final BlockPos pos = te.getPos();
|
||||
|
||||
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( facingRight.getOpposite() ) ), this.getSide() ) )
|
||||
{
|
||||
left = true;
|
||||
}
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(facingRight.getOpposite())), this.getSide())) {
|
||||
left = true;
|
||||
}
|
||||
|
||||
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( facingRight ) ), this.getSide() ) )
|
||||
{
|
||||
right = true;
|
||||
}
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(facingRight)), this.getSide())) {
|
||||
right = true;
|
||||
}
|
||||
|
||||
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( facingUp.getOpposite() ) ), this.getSide() ) )
|
||||
{
|
||||
down = true;
|
||||
}
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(facingUp.getOpposite())), this.getSide())) {
|
||||
down = true;
|
||||
}
|
||||
|
||||
if( this.isTransitionPlane( te.getWorld().getTileEntity( pos.offset( facingUp ) ), this.getSide() ) )
|
||||
{
|
||||
up = true;
|
||||
}
|
||||
}
|
||||
if (this.isTransitionPlane(te.getWorld().getTileEntity(pos.offset(facingUp)), this.getSide())) {
|
||||
up = true;
|
||||
}
|
||||
}
|
||||
|
||||
return PlaneConnections.of( up, right, down, left );
|
||||
}
|
||||
return PlaneConnections.of(up, right, down, left);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged( IBlockAccess w, BlockPos pos, BlockPos neighbor )
|
||||
{
|
||||
if( pos.offset( this.getSide().getFacing() ).equals( neighbor ) )
|
||||
{
|
||||
final TileEntity te = this.getHost().getTile();
|
||||
final AEPartLocation side = this.getSide();
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockAccess w, BlockPos pos, BlockPos neighbor) {
|
||||
if (pos.offset(this.getSide().getFacing()).equals(neighbor)) {
|
||||
final TileEntity te = this.getHost().getTile();
|
||||
final AEPartLocation side = this.getSide();
|
||||
|
||||
final BlockPos tePos = te.getPos().offset( side.getFacing() );
|
||||
final BlockPos tePos = te.getPos().offset(side.getFacing());
|
||||
|
||||
this.blocked = !w.getBlockState( tePos ).getBlock().isReplaceable( w, tePos );
|
||||
}
|
||||
}
|
||||
this.blocked = !w.getBlockState(tePos).getBlock().isReplaceable(w, tePos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
protected boolean isTransitionPlane( final TileEntity blockTileEntity, final AEPartLocation side )
|
||||
{
|
||||
if( blockTileEntity instanceof IPartHost )
|
||||
{
|
||||
final IPart p = ( (IPartHost) blockTileEntity ).getPart( side );
|
||||
return p != null && this.getClass() == p.getClass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
protected boolean isTransitionPlane(final TileEntity blockTileEntity, final AEPartLocation side) {
|
||||
if (blockTileEntity instanceof IPartHost) {
|
||||
final IPart p = ((IPartHost) blockTileEntity).getPart(side);
|
||||
return p != null && this.getClass() == p.getClass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T extractItems( final T request, final Actionable mode, final IActionSource src )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public T extractItems(final T request, final Actionable mode, final IActionSource src) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<T> getAvailableItems( final IItemList<T> out )
|
||||
{
|
||||
return out;
|
||||
}
|
||||
@Override
|
||||
public IItemList<T> getAvailableItems(final IItemList<T> out) {
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.priority = data.getInteger( "priority" );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
this.priority = data.getInteger("priority");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
data.setInteger( "priority", this.getPriority() );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
data.setInteger("priority", this.getPriority());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
{
|
||||
return this.priority;
|
||||
}
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return this.priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPriority( final int newValue )
|
||||
{
|
||||
this.priority = newValue;
|
||||
this.getHost().markForSave();
|
||||
this.updateHandler();
|
||||
}
|
||||
@Override
|
||||
public void setPriority(final int newValue) {
|
||||
this.priority = newValue;
|
||||
this.getHost().markForSave();
|
||||
this.updateHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blinkCell( final int slot )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
@Override
|
||||
public void blinkCell(final int slot) {
|
||||
// :P
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveChanges( final ICellInventory<?> cell )
|
||||
{
|
||||
// nope!
|
||||
}
|
||||
@Override
|
||||
public void saveChanges(final ICellInventory<?> cell) {
|
||||
// nope!
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,24 +19,6 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
@@ -69,515 +51,451 @@ import appeng.parts.PartBasicState;
|
||||
import appeng.util.IWorldCallable;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
|
||||
public class PartAnnihilationPlane extends PartBasicState implements IGridTickable, IWorldCallable<TickRateModulation>
|
||||
{
|
||||
|
||||
private static final PlaneModels MODELS = new PlaneModels( "part/annihilation_plane_", "part/annihilation_plane_on_" );
|
||||
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels()
|
||||
{
|
||||
return MODELS.getModels();
|
||||
}
|
||||
|
||||
private final IActionSource mySrc = new MachineSource( this );
|
||||
private boolean isAccepting = true;
|
||||
private boolean breaking = false;
|
||||
|
||||
public PartAnnihilationPlane( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation call( final World world ) throws Exception
|
||||
{
|
||||
this.breaking = false;
|
||||
return this.breakBlock( true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
int minX = 1;
|
||||
int minY = 1;
|
||||
int maxX = 15;
|
||||
int maxY = 15;
|
||||
|
||||
final IPartHost host = this.getHost();
|
||||
if( host != null )
|
||||
{
|
||||
final TileEntity te = host.getTile();
|
||||
|
||||
final BlockPos pos = te.getPos();
|
||||
|
||||
final EnumFacing e = bch.getWorldX();
|
||||
final EnumFacing u = bch.getWorldY();
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( e.getOpposite() ) ), this.getSide() ) )
|
||||
{
|
||||
minX = 0;
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( e ) ), this.getSide() ) )
|
||||
{
|
||||
maxX = 16;
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( u.getOpposite() ) ), this.getSide() ) )
|
||||
{
|
||||
minY = 0;
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( e ) ), this.getSide() ) )
|
||||
{
|
||||
maxY = 16;
|
||||
}
|
||||
}
|
||||
|
||||
bch.addBox( 5, 5, 14, 11, 11, 15 );
|
||||
// The smaller collision hitbox here is needed to allow for the entity collision event
|
||||
bch.addBox( minX, minY, 15, maxX, maxY, bch.isBBCollision() ? 15 : 16 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return An object describing which adjacent planes this plane connects to visually.
|
||||
*/
|
||||
public PlaneConnections getConnections()
|
||||
{
|
||||
|
||||
final EnumFacing facingRight, facingUp;
|
||||
AEPartLocation location = this.getSide();
|
||||
switch( location )
|
||||
{
|
||||
case UP:
|
||||
facingRight = EnumFacing.EAST;
|
||||
facingUp = EnumFacing.NORTH;
|
||||
break;
|
||||
case DOWN:
|
||||
facingRight = EnumFacing.WEST;
|
||||
facingUp = EnumFacing.NORTH;
|
||||
break;
|
||||
case NORTH:
|
||||
facingRight = EnumFacing.WEST;
|
||||
facingUp = EnumFacing.UP;
|
||||
break;
|
||||
case SOUTH:
|
||||
facingRight = EnumFacing.EAST;
|
||||
facingUp = EnumFacing.UP;
|
||||
break;
|
||||
case WEST:
|
||||
facingRight = EnumFacing.SOUTH;
|
||||
facingUp = EnumFacing.UP;
|
||||
break;
|
||||
case EAST:
|
||||
facingRight = EnumFacing.NORTH;
|
||||
facingUp = EnumFacing.UP;
|
||||
break;
|
||||
default:
|
||||
case INTERNAL:
|
||||
return PlaneConnections.of( false, false, false, false );
|
||||
}
|
||||
|
||||
boolean left = false, right = false, down = false, up = false;
|
||||
|
||||
final IPartHost host = this.getHost();
|
||||
if( host != null )
|
||||
{
|
||||
final TileEntity te = host.getTile();
|
||||
|
||||
final BlockPos pos = te.getPos();
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingRight.getOpposite() ) ), this.getSide() ) )
|
||||
{
|
||||
left = true;
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingRight ) ), this.getSide() ) )
|
||||
{
|
||||
right = true;
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingUp.getOpposite() ) ), this.getSide() ) )
|
||||
{
|
||||
down = true;
|
||||
}
|
||||
|
||||
if( this.isAnnihilationPlane( te.getWorld().getTileEntity( pos.offset( facingUp ) ), this.getSide() ) )
|
||||
{
|
||||
up = true;
|
||||
}
|
||||
}
|
||||
|
||||
return PlaneConnections.of( up, right, down, left );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged( IBlockAccess w, BlockPos pos, BlockPos neighbor )
|
||||
{
|
||||
if( pos.offset( this.getSide().getFacing() ).equals( neighbor ) )
|
||||
{
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityCollision( final Entity entity )
|
||||
{
|
||||
if( this.isAccepting && entity instanceof EntityItem && !entity.isDead && Platform.isServer() && this.getProxy().isActive() )
|
||||
{
|
||||
boolean capture = false;
|
||||
final BlockPos pos = this.getTile().getPos();
|
||||
|
||||
// This is the middle point of the entities BB, which is better suited for comparisons that don't rely on it
|
||||
// "touching" the plane
|
||||
double posYMiddle = ( entity.getEntityBoundingBox().minY + entity.getEntityBoundingBox().maxY ) / 2.0D;
|
||||
|
||||
switch( this.getSide() )
|
||||
{
|
||||
case DOWN:
|
||||
case UP:
|
||||
if( entity.posX > pos.getX() && entity.posX < pos.getX() + 1 )
|
||||
{
|
||||
if( entity.posZ > pos.getZ() && entity.posZ < pos.getZ() + 1 )
|
||||
{
|
||||
if( ( entity.posY > pos.getY() + 0.9 && this.getSide() == AEPartLocation.UP ) || ( entity.posY < pos.getY() + 0.1 && this
|
||||
.getSide() == AEPartLocation.DOWN ) )
|
||||
{
|
||||
capture = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SOUTH:
|
||||
case NORTH:
|
||||
if( entity.posX > pos.getX() && entity.posX < pos.getX() + 1 )
|
||||
{
|
||||
if( posYMiddle > pos.getY() && posYMiddle < pos.getY() + 1 )
|
||||
{
|
||||
if( ( entity.posZ > pos.getZ() + 0.9 && this.getSide() == AEPartLocation.SOUTH ) || ( entity.posZ < pos.getZ() + 0.1 && this
|
||||
.getSide() == AEPartLocation.NORTH ) )
|
||||
{
|
||||
capture = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EAST:
|
||||
case WEST:
|
||||
if( entity.posZ > pos.getZ() && entity.posZ < pos.getZ() + 1 )
|
||||
{
|
||||
if( posYMiddle > pos.getY() && posYMiddle < pos.getY() + 1 )
|
||||
{
|
||||
if( ( entity.posX > pos.getX() + 0.9 && this.getSide() == AEPartLocation.EAST ) || ( entity.posX < pos.getX() + 0.1 && this
|
||||
.getSide() == AEPartLocation.WEST ) )
|
||||
{
|
||||
capture = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// umm?
|
||||
break;
|
||||
}
|
||||
|
||||
if( capture )
|
||||
{
|
||||
final boolean changed = this.storeEntityItem( (EntityItem) entity );
|
||||
|
||||
if( changed )
|
||||
{
|
||||
AppEng.proxy.sendToAllNearExcept( null, pos.getX(), pos.getY(), pos.getZ(), 64, this.getTile().getWorld(),
|
||||
new PacketTransitionEffect( entity.posX, entity.posY, entity.posZ, this.getSide(), false ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores an {@link EntityItem} inside the network and either marks it as dead or sets it to the leftover stackSize.
|
||||
*
|
||||
* @param entityItem {@link EntityItem} to store
|
||||
*/
|
||||
private boolean storeEntityItem( final EntityItem entityItem )
|
||||
{
|
||||
if( !entityItem.isDead )
|
||||
{
|
||||
final IAEItemStack overflow = this.storeItemStack( entityItem.getItem() );
|
||||
|
||||
return this.handleOverflow( entityItem, overflow );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores an {@link ItemStack} inside the network.
|
||||
*
|
||||
* @param item {@link ItemStack} to store
|
||||
*
|
||||
* @return the leftover items, which could not be stored inside the network
|
||||
*/
|
||||
private IAEItemStack storeItemStack( final ItemStack item )
|
||||
{
|
||||
final IAEItemStack itemToStore = AEItemStack.fromItemStack( item );
|
||||
try
|
||||
{
|
||||
final IStorageGrid storage = this.getProxy().getStorage();
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
final IAEItemStack overflow = Platform.poweredInsert( energy,
|
||||
storage.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ), itemToStore, this.mySrc );
|
||||
|
||||
this.isAccepting = overflow == null;
|
||||
|
||||
return overflow;
|
||||
}
|
||||
catch( final GridAccessException e1 )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a possible overflow or none at all.
|
||||
* It will update the entity to match the leftover stack size as well as mark it as dead without any leftover
|
||||
* amount.
|
||||
*
|
||||
* @param entityItem the entity to update or destroy
|
||||
* @param overflow the leftover {@link IAEItemStack}
|
||||
*
|
||||
* @return true, if the entity was changed otherwise false.
|
||||
*/
|
||||
private boolean handleOverflow( final EntityItem entityItem, final IAEItemStack overflow )
|
||||
{
|
||||
if( overflow == null || overflow.getStackSize() == 0 )
|
||||
{
|
||||
entityItem.setDead();
|
||||
return true;
|
||||
}
|
||||
|
||||
final int oldStackSize = entityItem.getItem().getCount();
|
||||
final int newStackSize = (int) overflow.getStackSize();
|
||||
final boolean changed = oldStackSize != newStackSize;
|
||||
|
||||
entityItem.getItem().setCount( newStackSize );
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
protected boolean isAnnihilationPlane( final TileEntity blockTileEntity, final AEPartLocation side )
|
||||
{
|
||||
if( blockTileEntity instanceof IPartHost )
|
||||
{
|
||||
final IPart p = ( (IPartHost) blockTileEntity ).getPart( side );
|
||||
return p != null && p.getClass() == this.getClass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void chanRender( final MENetworkChannelsChanged c )
|
||||
{
|
||||
this.refresh();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.refresh();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
private TickRateModulation breakBlock( final boolean modulate )
|
||||
{
|
||||
if( this.isAccepting && this.getProxy().isActive() )
|
||||
{
|
||||
try
|
||||
{
|
||||
final TileEntity te = this.getTile();
|
||||
final WorldServer w = (WorldServer) te.getWorld();
|
||||
|
||||
final BlockPos pos = te.getPos().offset( this.getSide().getFacing() );
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
|
||||
if( this.canHandleBlock( w, pos ) )
|
||||
{
|
||||
final List<ItemStack> items = this.obtainBlockDrops( w, pos );
|
||||
final float requiredPower = this.calculateEnergyUsage( w, pos, items );
|
||||
|
||||
final boolean hasPower = energy.extractAEPower( requiredPower, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > requiredPower - 0.1;
|
||||
final boolean canStore = this.canStoreItemStacks( items );
|
||||
|
||||
if( hasPower && canStore )
|
||||
{
|
||||
if( modulate )
|
||||
{
|
||||
energy.extractAEPower( requiredPower, Actionable.MODULATE, PowerMultiplier.CONFIG );
|
||||
this.breakBlockAndStoreItems( w, pos );
|
||||
AppEng.proxy.sendToAllNearExcept( null, pos.getX(), pos.getY(), pos.getZ(), 64, w,
|
||||
new PacketTransitionEffect( pos.getX(), pos.getY(), pos.getZ(), this.getSide(), true ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.breaking = true;
|
||||
TickHandler.INSTANCE.addCallable( this.getTile().getWorld(), this );
|
||||
}
|
||||
return TickRateModulation.URGENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e1 )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
// nothing to do here :)
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest( final IGridNode node )
|
||||
{
|
||||
return new TickingRequest( TickRates.AnnihilationPlane.getMin(), TickRates.AnnihilationPlane.getMax(), false, true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
|
||||
{
|
||||
if( this.breaking )
|
||||
{
|
||||
return TickRateModulation.URGENT;
|
||||
}
|
||||
|
||||
this.isAccepting = true;
|
||||
return this.breakBlock( false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this plane can handle the block at the specific coordinates.
|
||||
*/
|
||||
private boolean canHandleBlock( final WorldServer w, final BlockPos pos )
|
||||
{
|
||||
final IBlockState state = w.getBlockState( pos );
|
||||
final Material material = state.getMaterial();
|
||||
final float hardness = state.getBlockHardness( w, pos );
|
||||
final boolean ignoreMaterials = material == Material.AIR || material == Material.LAVA || material == Material.WATER || material.isLiquid();
|
||||
final boolean ignoreBlocks = state.getBlock() == Blocks.BEDROCK || state.getBlock() == Blocks.END_PORTAL || state
|
||||
.getBlock() == Blocks.END_PORTAL_FRAME || state.getBlock() == Blocks.COMMAND_BLOCK;
|
||||
|
||||
return !ignoreMaterials && !ignoreBlocks && hardness >= 0f && !w.isAirBlock( pos ) && w.isBlockLoaded( pos ) && w.canMineBlockBody(
|
||||
Platform.getPlayer( w ),
|
||||
pos );
|
||||
}
|
||||
|
||||
protected List<ItemStack> obtainBlockDrops( final WorldServer w, final BlockPos pos )
|
||||
{
|
||||
final ItemStack[] out = Platform.getBlockDrops( w, pos );
|
||||
return Lists.newArrayList( out );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this plane can handle the block at the specific coordinates.
|
||||
*/
|
||||
protected float calculateEnergyUsage( final WorldServer w, final BlockPos pos, final List<ItemStack> items )
|
||||
{
|
||||
final IBlockState state = w.getBlockState( pos );
|
||||
final float hardness = state.getBlockHardness( w, pos );
|
||||
|
||||
float requiredEnergy = 1 + hardness;
|
||||
for( final ItemStack is : items )
|
||||
{
|
||||
requiredEnergy += is.getCount();
|
||||
}
|
||||
|
||||
return requiredEnergy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the network can store the possible drops.
|
||||
*
|
||||
* It also sets isAccepting to false, if the item can not be stored.
|
||||
*
|
||||
* @param itemStacks an array of {@link ItemStack} to test
|
||||
*
|
||||
* @return true, if the network can store at least a single item of all drops or no drops are reported
|
||||
*/
|
||||
private boolean canStoreItemStacks( final List<ItemStack> itemStacks )
|
||||
{
|
||||
boolean canStore = itemStacks.isEmpty();
|
||||
|
||||
try
|
||||
{
|
||||
final IStorageGrid storage = this.getProxy().getStorage();
|
||||
|
||||
for( final ItemStack itemStack : itemStacks )
|
||||
{
|
||||
final IAEItemStack itemToTest = AEItemStack.fromItemStack( itemStack );
|
||||
final IAEItemStack overflow = storage.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
|
||||
.injectItems( itemToTest, Actionable.SIMULATE, this.mySrc );
|
||||
if( overflow == null || itemToTest.getStackSize() > overflow.getStackSize() )
|
||||
{
|
||||
canStore = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
this.isAccepting = canStore;
|
||||
return canStore;
|
||||
}
|
||||
|
||||
private void breakBlockAndStoreItems( final WorldServer w, final BlockPos pos )
|
||||
{
|
||||
w.destroyBlock( pos, true );
|
||||
|
||||
final AxisAlignedBB box = new AxisAlignedBB( pos ).grow( 0.2 );
|
||||
for( final Object ei : w.getEntitiesWithinAABB( EntityItem.class, box ) )
|
||||
{
|
||||
if( ei instanceof EntityItem )
|
||||
{
|
||||
final EntityItem entityItem = (EntityItem) ei;
|
||||
this.storeEntityItem( entityItem );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void refresh()
|
||||
{
|
||||
this.isAccepting = true;
|
||||
|
||||
try
|
||||
{
|
||||
this.getProxy().getTick().alertDevice( this.getProxy().getNode() );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return MODELS.getModel( this.getConnections(), this.isPowered(), this.isActive() );
|
||||
}
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class PartAnnihilationPlane extends PartBasicState implements IGridTickable, IWorldCallable<TickRateModulation> {
|
||||
|
||||
private static final PlaneModels MODELS = new PlaneModels("part/annihilation_plane_", "part/annihilation_plane_on_");
|
||||
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels() {
|
||||
return MODELS.getModels();
|
||||
}
|
||||
|
||||
private final IActionSource mySrc = new MachineSource(this);
|
||||
private boolean isAccepting = true;
|
||||
private boolean breaking = false;
|
||||
|
||||
public PartAnnihilationPlane(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation call(final World world) throws Exception {
|
||||
this.breaking = false;
|
||||
return this.breakBlock(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
int minX = 1;
|
||||
int minY = 1;
|
||||
int maxX = 15;
|
||||
int maxY = 15;
|
||||
|
||||
final IPartHost host = this.getHost();
|
||||
if (host != null) {
|
||||
final TileEntity te = host.getTile();
|
||||
|
||||
final BlockPos pos = te.getPos();
|
||||
|
||||
final EnumFacing e = bch.getWorldX();
|
||||
final EnumFacing u = bch.getWorldY();
|
||||
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(e.getOpposite())), this.getSide())) {
|
||||
minX = 0;
|
||||
}
|
||||
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(e)), this.getSide())) {
|
||||
maxX = 16;
|
||||
}
|
||||
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(u.getOpposite())), this.getSide())) {
|
||||
minY = 0;
|
||||
}
|
||||
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(e)), this.getSide())) {
|
||||
maxY = 16;
|
||||
}
|
||||
}
|
||||
|
||||
bch.addBox(5, 5, 14, 11, 11, 15);
|
||||
// The smaller collision hitbox here is needed to allow for the entity collision event
|
||||
bch.addBox(minX, minY, 15, maxX, maxY, bch.isBBCollision() ? 15 : 16);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return An object describing which adjacent planes this plane connects to visually.
|
||||
*/
|
||||
public PlaneConnections getConnections() {
|
||||
|
||||
final EnumFacing facingRight, facingUp;
|
||||
AEPartLocation location = this.getSide();
|
||||
switch (location) {
|
||||
case UP:
|
||||
facingRight = EnumFacing.EAST;
|
||||
facingUp = EnumFacing.NORTH;
|
||||
break;
|
||||
case DOWN:
|
||||
facingRight = EnumFacing.WEST;
|
||||
facingUp = EnumFacing.NORTH;
|
||||
break;
|
||||
case NORTH:
|
||||
facingRight = EnumFacing.WEST;
|
||||
facingUp = EnumFacing.UP;
|
||||
break;
|
||||
case SOUTH:
|
||||
facingRight = EnumFacing.EAST;
|
||||
facingUp = EnumFacing.UP;
|
||||
break;
|
||||
case WEST:
|
||||
facingRight = EnumFacing.SOUTH;
|
||||
facingUp = EnumFacing.UP;
|
||||
break;
|
||||
case EAST:
|
||||
facingRight = EnumFacing.NORTH;
|
||||
facingUp = EnumFacing.UP;
|
||||
break;
|
||||
default:
|
||||
case INTERNAL:
|
||||
return PlaneConnections.of(false, false, false, false);
|
||||
}
|
||||
|
||||
boolean left = false, right = false, down = false, up = false;
|
||||
|
||||
final IPartHost host = this.getHost();
|
||||
if (host != null) {
|
||||
final TileEntity te = host.getTile();
|
||||
|
||||
final BlockPos pos = te.getPos();
|
||||
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(facingRight.getOpposite())), this.getSide())) {
|
||||
left = true;
|
||||
}
|
||||
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(facingRight)), this.getSide())) {
|
||||
right = true;
|
||||
}
|
||||
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(facingUp.getOpposite())), this.getSide())) {
|
||||
down = true;
|
||||
}
|
||||
|
||||
if (this.isAnnihilationPlane(te.getWorld().getTileEntity(pos.offset(facingUp)), this.getSide())) {
|
||||
up = true;
|
||||
}
|
||||
}
|
||||
|
||||
return PlaneConnections.of(up, right, down, left);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockAccess w, BlockPos pos, BlockPos neighbor) {
|
||||
if (pos.offset(this.getSide().getFacing()).equals(neighbor)) {
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityCollision(final Entity entity) {
|
||||
if (this.isAccepting && entity instanceof EntityItem && !entity.isDead && Platform.isServer() && this.getProxy().isActive()) {
|
||||
boolean capture = false;
|
||||
final BlockPos pos = this.getTile().getPos();
|
||||
|
||||
// This is the middle point of the entities BB, which is better suited for comparisons that don't rely on it
|
||||
// "touching" the plane
|
||||
double posYMiddle = (entity.getEntityBoundingBox().minY + entity.getEntityBoundingBox().maxY) / 2.0D;
|
||||
|
||||
switch (this.getSide()) {
|
||||
case DOWN:
|
||||
case UP:
|
||||
if (entity.posX > pos.getX() && entity.posX < pos.getX() + 1) {
|
||||
if (entity.posZ > pos.getZ() && entity.posZ < pos.getZ() + 1) {
|
||||
if ((entity.posY > pos.getY() + 0.9 && this.getSide() == AEPartLocation.UP) || (entity.posY < pos.getY() + 0.1 && this
|
||||
.getSide() == AEPartLocation.DOWN)) {
|
||||
capture = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SOUTH:
|
||||
case NORTH:
|
||||
if (entity.posX > pos.getX() && entity.posX < pos.getX() + 1) {
|
||||
if (posYMiddle > pos.getY() && posYMiddle < pos.getY() + 1) {
|
||||
if ((entity.posZ > pos.getZ() + 0.9 && this.getSide() == AEPartLocation.SOUTH) || (entity.posZ < pos.getZ() + 0.1 && this
|
||||
.getSide() == AEPartLocation.NORTH)) {
|
||||
capture = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EAST:
|
||||
case WEST:
|
||||
if (entity.posZ > pos.getZ() && entity.posZ < pos.getZ() + 1) {
|
||||
if (posYMiddle > pos.getY() && posYMiddle < pos.getY() + 1) {
|
||||
if ((entity.posX > pos.getX() + 0.9 && this.getSide() == AEPartLocation.EAST) || (entity.posX < pos.getX() + 0.1 && this
|
||||
.getSide() == AEPartLocation.WEST)) {
|
||||
capture = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// umm?
|
||||
break;
|
||||
}
|
||||
|
||||
if (capture) {
|
||||
final boolean changed = this.storeEntityItem((EntityItem) entity);
|
||||
|
||||
if (changed) {
|
||||
AppEng.proxy.sendToAllNearExcept(null, pos.getX(), pos.getY(), pos.getZ(), 64, this.getTile().getWorld(),
|
||||
new PacketTransitionEffect(entity.posX, entity.posY, entity.posZ, this.getSide(), false));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores an {@link EntityItem} inside the network and either marks it as dead or sets it to the leftover stackSize.
|
||||
*
|
||||
* @param entityItem {@link EntityItem} to store
|
||||
*/
|
||||
private boolean storeEntityItem(final EntityItem entityItem) {
|
||||
if (!entityItem.isDead) {
|
||||
final IAEItemStack overflow = this.storeItemStack(entityItem.getItem());
|
||||
|
||||
return this.handleOverflow(entityItem, overflow);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores an {@link ItemStack} inside the network.
|
||||
*
|
||||
* @param item {@link ItemStack} to store
|
||||
* @return the leftover items, which could not be stored inside the network
|
||||
*/
|
||||
private IAEItemStack storeItemStack(final ItemStack item) {
|
||||
final IAEItemStack itemToStore = AEItemStack.fromItemStack(item);
|
||||
try {
|
||||
final IStorageGrid storage = this.getProxy().getStorage();
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
final IAEItemStack overflow = Platform.poweredInsert(energy,
|
||||
storage.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)), itemToStore, this.mySrc);
|
||||
|
||||
this.isAccepting = overflow == null;
|
||||
|
||||
return overflow;
|
||||
} catch (final GridAccessException e1) {
|
||||
// :P
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a possible overflow or none at all.
|
||||
* It will update the entity to match the leftover stack size as well as mark it as dead without any leftover
|
||||
* amount.
|
||||
*
|
||||
* @param entityItem the entity to update or destroy
|
||||
* @param overflow the leftover {@link IAEItemStack}
|
||||
* @return true, if the entity was changed otherwise false.
|
||||
*/
|
||||
private boolean handleOverflow(final EntityItem entityItem, final IAEItemStack overflow) {
|
||||
if (overflow == null || overflow.getStackSize() == 0) {
|
||||
entityItem.setDead();
|
||||
return true;
|
||||
}
|
||||
|
||||
final int oldStackSize = entityItem.getItem().getCount();
|
||||
final int newStackSize = (int) overflow.getStackSize();
|
||||
final boolean changed = oldStackSize != newStackSize;
|
||||
|
||||
entityItem.getItem().setCount(newStackSize);
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
protected boolean isAnnihilationPlane(final TileEntity blockTileEntity, final AEPartLocation side) {
|
||||
if (blockTileEntity instanceof IPartHost) {
|
||||
final IPart p = ((IPartHost) blockTileEntity).getPart(side);
|
||||
return p != null && p.getClass() == this.getClass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void chanRender(final MENetworkChannelsChanged c) {
|
||||
this.refresh();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(final MENetworkPowerStatusChange c) {
|
||||
this.refresh();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
private TickRateModulation breakBlock(final boolean modulate) {
|
||||
if (this.isAccepting && this.getProxy().isActive()) {
|
||||
try {
|
||||
final TileEntity te = this.getTile();
|
||||
final WorldServer w = (WorldServer) te.getWorld();
|
||||
|
||||
final BlockPos pos = te.getPos().offset(this.getSide().getFacing());
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
|
||||
if (this.canHandleBlock(w, pos)) {
|
||||
final List<ItemStack> items = this.obtainBlockDrops(w, pos);
|
||||
final float requiredPower = this.calculateEnergyUsage(w, pos, items);
|
||||
|
||||
final boolean hasPower = energy.extractAEPower(requiredPower, Actionable.SIMULATE, PowerMultiplier.CONFIG) > requiredPower - 0.1;
|
||||
final boolean canStore = this.canStoreItemStacks(items);
|
||||
|
||||
if (hasPower && canStore) {
|
||||
if (modulate) {
|
||||
energy.extractAEPower(requiredPower, Actionable.MODULATE, PowerMultiplier.CONFIG);
|
||||
this.breakBlockAndStoreItems(w, pos);
|
||||
AppEng.proxy.sendToAllNearExcept(null, pos.getX(), pos.getY(), pos.getZ(), 64, w,
|
||||
new PacketTransitionEffect(pos.getX(), pos.getY(), pos.getZ(), this.getSide(), true));
|
||||
} else {
|
||||
this.breaking = true;
|
||||
TickHandler.INSTANCE.addCallable(this.getTile().getWorld(), this);
|
||||
}
|
||||
return TickRateModulation.URGENT;
|
||||
}
|
||||
}
|
||||
} catch (final GridAccessException e1) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
// nothing to do here :)
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(final IGridNode node) {
|
||||
return new TickingRequest(TickRates.AnnihilationPlane.getMin(), TickRates.AnnihilationPlane.getMax(), false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
|
||||
if (this.breaking) {
|
||||
return TickRateModulation.URGENT;
|
||||
}
|
||||
|
||||
this.isAccepting = true;
|
||||
return this.breakBlock(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this plane can handle the block at the specific coordinates.
|
||||
*/
|
||||
private boolean canHandleBlock(final WorldServer w, final BlockPos pos) {
|
||||
final IBlockState state = w.getBlockState(pos);
|
||||
final Material material = state.getMaterial();
|
||||
final float hardness = state.getBlockHardness(w, pos);
|
||||
final boolean ignoreMaterials = material == Material.AIR || material == Material.LAVA || material == Material.WATER || material.isLiquid();
|
||||
final boolean ignoreBlocks = state.getBlock() == Blocks.BEDROCK || state.getBlock() == Blocks.END_PORTAL || state
|
||||
.getBlock() == Blocks.END_PORTAL_FRAME || state.getBlock() == Blocks.COMMAND_BLOCK;
|
||||
|
||||
return !ignoreMaterials && !ignoreBlocks && hardness >= 0f && !w.isAirBlock(pos) && w.isBlockLoaded(pos) && w.canMineBlockBody(
|
||||
Platform.getPlayer(w),
|
||||
pos);
|
||||
}
|
||||
|
||||
protected List<ItemStack> obtainBlockDrops(final WorldServer w, final BlockPos pos) {
|
||||
final ItemStack[] out = Platform.getBlockDrops(w, pos);
|
||||
return Lists.newArrayList(out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this plane can handle the block at the specific coordinates.
|
||||
*/
|
||||
protected float calculateEnergyUsage(final WorldServer w, final BlockPos pos, final List<ItemStack> items) {
|
||||
final IBlockState state = w.getBlockState(pos);
|
||||
final float hardness = state.getBlockHardness(w, pos);
|
||||
|
||||
float requiredEnergy = 1 + hardness;
|
||||
for (final ItemStack is : items) {
|
||||
requiredEnergy += is.getCount();
|
||||
}
|
||||
|
||||
return requiredEnergy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the network can store the possible drops.
|
||||
* <p>
|
||||
* It also sets isAccepting to false, if the item can not be stored.
|
||||
*
|
||||
* @param itemStacks an array of {@link ItemStack} to test
|
||||
* @return true, if the network can store at least a single item of all drops or no drops are reported
|
||||
*/
|
||||
private boolean canStoreItemStacks(final List<ItemStack> itemStacks) {
|
||||
boolean canStore = itemStacks.isEmpty();
|
||||
|
||||
try {
|
||||
final IStorageGrid storage = this.getProxy().getStorage();
|
||||
|
||||
for (final ItemStack itemStack : itemStacks) {
|
||||
final IAEItemStack itemToTest = AEItemStack.fromItemStack(itemStack);
|
||||
final IAEItemStack overflow = storage.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class))
|
||||
.injectItems(itemToTest, Actionable.SIMULATE, this.mySrc);
|
||||
if (overflow == null || itemToTest.getStackSize() > overflow.getStackSize()) {
|
||||
canStore = true;
|
||||
}
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
|
||||
this.isAccepting = canStore;
|
||||
return canStore;
|
||||
}
|
||||
|
||||
private void breakBlockAndStoreItems(final WorldServer w, final BlockPos pos) {
|
||||
w.destroyBlock(pos, true);
|
||||
|
||||
final AxisAlignedBB box = new AxisAlignedBB(pos).grow(0.2);
|
||||
for (final Object ei : w.getEntitiesWithinAABB(EntityItem.class, box)) {
|
||||
if (ei instanceof EntityItem) {
|
||||
final EntityItem entityItem = (EntityItem) ei;
|
||||
this.storeEntityItem(entityItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
this.isAccepting = true;
|
||||
|
||||
try {
|
||||
this.getProxy().getTick().alertDevice(this.getProxy().getNode());
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return MODELS.getModel(this.getConnections(), this.isPowered(), this.isActive());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,26 +19,8 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
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.SchedulingMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.config.YesNo;
|
||||
import appeng.api.config.*;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.crafting.ICraftingGrid;
|
||||
import appeng.api.networking.crafting.ICraftingLink;
|
||||
@@ -67,344 +49,287 @@ import appeng.parts.PartModel;
|
||||
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 com.google.common.primitives.Ints;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
|
||||
public class PartExportBus extends PartSharedItemBus implements ICraftingRequester
|
||||
{
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/export_bus_base" );
|
||||
public class PartExportBus extends PartSharedItemBus implements ICraftingRequester {
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID, "part/export_bus_base");
|
||||
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/export_bus_off" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, new ResourceLocation(AppEng.MOD_ID, "part/export_bus_off"));
|
||||
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/export_bus_on" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, new ResourceLocation(AppEng.MOD_ID, "part/export_bus_on"));
|
||||
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/export_bus_has_channel" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, new ResourceLocation(AppEng.MOD_ID, "part/export_bus_has_channel"));
|
||||
|
||||
private final MultiCraftingTracker craftingTracker = new MultiCraftingTracker( this, 9 );
|
||||
private final IActionSource mySrc;
|
||||
private long itemToSend = 1;
|
||||
private boolean didSomething = false;
|
||||
private int nextSlot = 0;
|
||||
private final MultiCraftingTracker craftingTracker = new MultiCraftingTracker(this, 9);
|
||||
private final IActionSource mySrc;
|
||||
private long itemToSend = 1;
|
||||
private boolean didSomething = false;
|
||||
private int nextSlot = 0;
|
||||
|
||||
@Reflected
|
||||
public PartExportBus( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
@Reflected
|
||||
public PartExportBus(final ItemStack is) {
|
||||
super(is);
|
||||
|
||||
this.getConfigManager().registerSetting( Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
|
||||
this.getConfigManager().registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
|
||||
this.getConfigManager().registerSetting( Settings.CRAFT_ONLY, YesNo.NO );
|
||||
this.getConfigManager().registerSetting( Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT );
|
||||
this.mySrc = new MachineSource( this );
|
||||
}
|
||||
this.getConfigManager().registerSetting(Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE);
|
||||
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
|
||||
this.getConfigManager().registerSetting(Settings.CRAFT_ONLY, YesNo.NO);
|
||||
this.getConfigManager().registerSetting(Settings.SCHEDULING_MODE, SchedulingMode.DEFAULT);
|
||||
this.mySrc = new MachineSource(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound extra )
|
||||
{
|
||||
super.readFromNBT( extra );
|
||||
this.craftingTracker.readFromNBT( extra );
|
||||
this.nextSlot = extra.getInteger( "nextSlot" );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound extra) {
|
||||
super.readFromNBT(extra);
|
||||
this.craftingTracker.readFromNBT(extra);
|
||||
this.nextSlot = extra.getInteger("nextSlot");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound extra )
|
||||
{
|
||||
super.writeToNBT( extra );
|
||||
this.craftingTracker.writeToNBT( extra );
|
||||
extra.setInteger( "nextSlot", this.nextSlot );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound extra) {
|
||||
super.writeToNBT(extra);
|
||||
this.craftingTracker.writeToNBT(extra);
|
||||
extra.setInteger("nextSlot", this.nextSlot);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TickRateModulation doBusWork()
|
||||
{
|
||||
if( !this.getProxy().isActive() || !this.canDoBusWork() )
|
||||
{
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
@Override
|
||||
protected TickRateModulation doBusWork() {
|
||||
if (!this.getProxy().isActive() || !this.canDoBusWork()) {
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
this.itemToSend = this.calculateItemsToSend();
|
||||
this.didSomething = false;
|
||||
this.itemToSend = this.calculateItemsToSend();
|
||||
this.didSomething = false;
|
||||
|
||||
try
|
||||
{
|
||||
final InventoryAdaptor destination = this.getHandler();
|
||||
final IMEMonitor<IAEItemStack> inv = this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
final ICraftingGrid cg = this.getProxy().getCrafting();
|
||||
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE );
|
||||
final SchedulingMode schedulingMode = (SchedulingMode) this.getConfigManager().getSetting( Settings.SCHEDULING_MODE );
|
||||
try {
|
||||
final InventoryAdaptor destination = this.getHandler();
|
||||
final IMEMonitor<IAEItemStack> inv = this.getProxy().getStorage().getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
final ICraftingGrid cg = this.getProxy().getCrafting();
|
||||
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting(Settings.FUZZY_MODE);
|
||||
final SchedulingMode schedulingMode = (SchedulingMode) this.getConfigManager().getSetting(Settings.SCHEDULING_MODE);
|
||||
|
||||
if( destination != null )
|
||||
{
|
||||
int x = 0;
|
||||
if (destination != null) {
|
||||
int x = 0;
|
||||
|
||||
for( x = 0; x < this.availableSlots() && this.itemToSend > 0; x++ )
|
||||
{
|
||||
final int slotToExport = this.getStartingSlot( schedulingMode, x );
|
||||
for (x = 0; x < this.availableSlots() && this.itemToSend > 0; x++) {
|
||||
final int slotToExport = this.getStartingSlot(schedulingMode, x);
|
||||
|
||||
final IAEItemStack ais = this.getConfig().getAEStackInSlot( slotToExport );
|
||||
final IAEItemStack ais = this.getConfig().getAEStackInSlot(slotToExport);
|
||||
|
||||
if( ais == null || this.itemToSend <= 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (ais == null || this.itemToSend <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( this.craftOnly() )
|
||||
{
|
||||
this.didSomething = this.craftingTracker.handleCrafting( slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(), this.getProxy().getGrid(), cg, this.mySrc ) || this.didSomething;
|
||||
if (this.craftOnly()) {
|
||||
this.didSomething = this.craftingTracker.handleCrafting(slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(), this.getProxy().getGrid(), cg, this.mySrc) || this.didSomething;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
final long before = this.itemToSend;
|
||||
final long before = this.itemToSend;
|
||||
|
||||
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
{
|
||||
for( final IAEItemStack o : ImmutableList.copyOf( inv.getStorageList().findFuzzy( ais, fzMode ) ) )
|
||||
{
|
||||
this.pushItemIntoTarget( destination, energy, inv, o );
|
||||
if( this.itemToSend <= 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( inv.getStorageList().findPrecise( ais ) != null )
|
||||
{
|
||||
this.pushItemIntoTarget( destination, energy, inv, ais );
|
||||
}
|
||||
}
|
||||
if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0) {
|
||||
for (final IAEItemStack o : ImmutableList.copyOf(inv.getStorageList().findFuzzy(ais, fzMode))) {
|
||||
this.pushItemIntoTarget(destination, energy, inv, o);
|
||||
if (this.itemToSend <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (inv.getStorageList().findPrecise(ais) != null) {
|
||||
this.pushItemIntoTarget(destination, energy, inv, ais);
|
||||
}
|
||||
}
|
||||
|
||||
if( this.itemToSend == before && this.isCraftingEnabled() )
|
||||
{
|
||||
this.didSomething = this.craftingTracker.handleCrafting( slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(), this.getProxy().getGrid(), cg, this.mySrc ) || this.didSomething;
|
||||
}
|
||||
}
|
||||
if (this.itemToSend == before && this.isCraftingEnabled()) {
|
||||
this.didSomething = this.craftingTracker.handleCrafting(slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(), this.getProxy().getGrid(), cg, this.mySrc) || this.didSomething;
|
||||
}
|
||||
}
|
||||
|
||||
this.updateSchedulingMode( schedulingMode, x );
|
||||
}
|
||||
else
|
||||
{
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
this.updateSchedulingMode(schedulingMode, x);
|
||||
} else {
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
|
||||
return this.didSomething ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
}
|
||||
return this.didSomething ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final 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 );
|
||||
}
|
||||
@Override
|
||||
public void getBoxes(final 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_BUS );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
|
||||
if (Platform.isServer()) {
|
||||
Platform.openGUI(player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_BUS);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest( final IGridNode node )
|
||||
{
|
||||
return new TickingRequest( TickRates.ExportBus.getMin(), TickRates.ExportBus.getMax(), this.isSleeping(), false );
|
||||
}
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(final IGridNode node) {
|
||||
return new TickingRequest(TickRates.ExportBus.getMin(), TickRates.ExportBus.getMax(), this.isSleeping(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneMode getRSMode()
|
||||
{
|
||||
return (RedstoneMode) this.getConfigManager().getSetting( Settings.REDSTONE_CONTROLLED );
|
||||
}
|
||||
@Override
|
||||
public RedstoneMode getRSMode() {
|
||||
return (RedstoneMode) this.getConfigManager().getSetting(Settings.REDSTONE_CONTROLLED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
|
||||
{
|
||||
return this.doBusWork();
|
||||
}
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
|
||||
return this.doBusWork();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableSet<ICraftingLink> getRequestedJobs()
|
||||
{
|
||||
return this.craftingTracker.getRequestedJobs();
|
||||
}
|
||||
@Override
|
||||
public ImmutableSet<ICraftingLink> getRequestedJobs() {
|
||||
return this.craftingTracker.getRequestedJobs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectCraftedItems( final ICraftingLink link, final IAEItemStack items, final Actionable mode )
|
||||
{
|
||||
final InventoryAdaptor d = this.getHandler();
|
||||
@Override
|
||||
public IAEItemStack injectCraftedItems(final ICraftingLink link, final IAEItemStack items, final Actionable mode) {
|
||||
final InventoryAdaptor d = this.getHandler();
|
||||
|
||||
try
|
||||
{
|
||||
if( d != null && this.getProxy().isActive() )
|
||||
{
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
final double power = items.getStackSize();
|
||||
try {
|
||||
if (d != null && this.getProxy().isActive()) {
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
final double power = items.getStackSize();
|
||||
|
||||
if( energy.extractAEPower( power, mode, PowerMultiplier.CONFIG ) > power - 0.01 )
|
||||
{
|
||||
ItemStack inputStack = items.getCachedItemStack( items.getStackSize() );
|
||||
if (energy.extractAEPower(power, mode, PowerMultiplier.CONFIG) > power - 0.01) {
|
||||
ItemStack inputStack = items.getCachedItemStack(items.getStackSize());
|
||||
|
||||
ItemStack remaining;
|
||||
ItemStack remaining;
|
||||
|
||||
if( mode == Actionable.SIMULATE )
|
||||
{
|
||||
remaining = d.simulateAdd( inputStack );
|
||||
items.setCachedItemStack( inputStack );
|
||||
}
|
||||
else
|
||||
{
|
||||
remaining = d.addItems( inputStack );
|
||||
if( !remaining.isEmpty() )
|
||||
{
|
||||
items.setCachedItemStack( remaining );
|
||||
}
|
||||
}
|
||||
if (mode == Actionable.SIMULATE) {
|
||||
remaining = d.simulateAdd(inputStack);
|
||||
items.setCachedItemStack(inputStack);
|
||||
} else {
|
||||
remaining = d.addItems(inputStack);
|
||||
if (!remaining.isEmpty()) {
|
||||
items.setCachedItemStack(remaining);
|
||||
}
|
||||
}
|
||||
|
||||
if( remaining == inputStack )
|
||||
{
|
||||
return items;
|
||||
}
|
||||
if (remaining == inputStack) {
|
||||
return items;
|
||||
}
|
||||
|
||||
return AEItemStack.fromItemStack( remaining );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
AELog.debug( e );
|
||||
}
|
||||
return AEItemStack.fromItemStack(remaining);
|
||||
}
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
AELog.debug(e);
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jobStateChange( final ICraftingLink link )
|
||||
{
|
||||
this.craftingTracker.jobStateChange( link );
|
||||
}
|
||||
@Override
|
||||
public void jobStateChange(final ICraftingLink link) {
|
||||
this.craftingTracker.jobStateChange(link);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSleeping()
|
||||
{
|
||||
return this.getHandler() == null || super.isSleeping();
|
||||
}
|
||||
@Override
|
||||
protected boolean isSleeping() {
|
||||
return this.getHandler() == null || super.isSleeping();
|
||||
}
|
||||
|
||||
private boolean craftOnly()
|
||||
{
|
||||
return this.getConfigManager().getSetting( Settings.CRAFT_ONLY ) == YesNo.YES;
|
||||
}
|
||||
private boolean craftOnly() {
|
||||
return this.getConfigManager().getSetting(Settings.CRAFT_ONLY) == YesNo.YES;
|
||||
}
|
||||
|
||||
private boolean isCraftingEnabled()
|
||||
{
|
||||
return this.getInstalledUpgrades( Upgrades.CRAFTING ) > 0;
|
||||
}
|
||||
private boolean isCraftingEnabled() {
|
||||
return this.getInstalledUpgrades(Upgrades.CRAFTING) > 0;
|
||||
}
|
||||
|
||||
private void pushItemIntoTarget( final InventoryAdaptor d, final IEnergyGrid energy, final IMEInventory<IAEItemStack> inv, IAEItemStack org )
|
||||
{
|
||||
ItemStack inputStack = org.getCachedItemStack( org.getStackSize() );
|
||||
private void pushItemIntoTarget(final InventoryAdaptor d, final IEnergyGrid energy, final IMEInventory<IAEItemStack> inv, IAEItemStack org) {
|
||||
ItemStack inputStack = org.getCachedItemStack(org.getStackSize());
|
||||
|
||||
ItemStack remaining = d.simulateAdd( inputStack );
|
||||
ItemStack remaining = d.simulateAdd(inputStack);
|
||||
|
||||
// Store the stack in the cache for next time.
|
||||
if( !remaining.isEmpty() )
|
||||
{
|
||||
org.setCachedItemStack( remaining );
|
||||
if( remaining == inputStack )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Store the stack in the cache for next time.
|
||||
if (!remaining.isEmpty()) {
|
||||
org.setCachedItemStack(remaining);
|
||||
if (remaining == inputStack) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final long canFit = remaining.isEmpty() ? this.itemToSend : this.itemToSend - remaining.getCount();
|
||||
final long canFit = remaining.isEmpty() ? this.itemToSend : this.itemToSend - remaining.getCount();
|
||||
|
||||
if( canFit > 0 )
|
||||
{
|
||||
IAEItemStack ais = org.copy();
|
||||
ais.setStackSize( canFit );
|
||||
final IAEItemStack itemsToAdd = Platform.poweredExtraction( energy, inv, ais, this.mySrc );
|
||||
if (canFit > 0) {
|
||||
IAEItemStack ais = org.copy();
|
||||
ais.setStackSize(canFit);
|
||||
final IAEItemStack itemsToAdd = Platform.poweredExtraction(energy, inv, ais, this.mySrc);
|
||||
|
||||
if( itemsToAdd != null )
|
||||
{
|
||||
this.itemToSend -= itemsToAdd.getStackSize();
|
||||
if (itemsToAdd != null) {
|
||||
this.itemToSend -= itemsToAdd.getStackSize();
|
||||
|
||||
inputStack.setCount( Ints.saturatedCast( itemsToAdd.getStackSize() ) );
|
||||
inputStack.setCount(Ints.saturatedCast(itemsToAdd.getStackSize()));
|
||||
|
||||
final ItemStack failed = d.addItems( inputStack );
|
||||
if( !failed.isEmpty() )
|
||||
{
|
||||
ais.setStackSize( failed.getCount() );
|
||||
inv.injectItems( ais, Actionable.MODULATE, this.mySrc );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.didSomething = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
org.setCachedItemStack( inputStack );
|
||||
}
|
||||
}
|
||||
}
|
||||
final ItemStack failed = d.addItems(inputStack);
|
||||
if (!failed.isEmpty()) {
|
||||
ais.setStackSize(failed.getCount());
|
||||
inv.injectItems(ais, Actionable.MODULATE, this.mySrc);
|
||||
} else {
|
||||
this.didSomething = true;
|
||||
}
|
||||
} else {
|
||||
org.setCachedItemStack(inputStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int getStartingSlot( final SchedulingMode schedulingMode, final int x )
|
||||
{
|
||||
if( schedulingMode == SchedulingMode.RANDOM )
|
||||
{
|
||||
return Platform.getRandom().nextInt( this.availableSlots() );
|
||||
}
|
||||
private int getStartingSlot(final SchedulingMode schedulingMode, final int x) {
|
||||
if (schedulingMode == SchedulingMode.RANDOM) {
|
||||
return Platform.getRandom().nextInt(this.availableSlots());
|
||||
}
|
||||
|
||||
if( schedulingMode == SchedulingMode.ROUNDROBIN )
|
||||
{
|
||||
return ( this.nextSlot + x ) % this.availableSlots();
|
||||
}
|
||||
if (schedulingMode == SchedulingMode.ROUNDROBIN) {
|
||||
return (this.nextSlot + x) % this.availableSlots();
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
private void updateSchedulingMode( final SchedulingMode schedulingMode, final int x )
|
||||
{
|
||||
if( schedulingMode == SchedulingMode.ROUNDROBIN )
|
||||
{
|
||||
this.nextSlot = ( this.nextSlot + x ) % this.availableSlots();
|
||||
}
|
||||
}
|
||||
private void updateSchedulingMode(final SchedulingMode schedulingMode, final int x) {
|
||||
if (schedulingMode == SchedulingMode.ROUNDROBIN) {
|
||||
this.nextSlot = (this.nextSlot + x) % this.availableSlots();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
if( this.isActive() && this.isPowered() )
|
||||
{
|
||||
return MODELS_HAS_CHANNEL;
|
||||
}
|
||||
else if( this.isPowered() )
|
||||
{
|
||||
return MODELS_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
if (this.isActive() && this.isPowered()) {
|
||||
return MODELS_HAS_CHANNEL;
|
||||
} else if (this.isPowered()) {
|
||||
return MODELS_ON;
|
||||
} else {
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,41 +19,8 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemBlockSpecial;
|
||||
import net.minecraft.item.ItemFirework;
|
||||
import net.minecraft.item.ItemSkull;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.IPlantable;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
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.config.YesNo;
|
||||
import appeng.api.config.*;
|
||||
import appeng.api.networking.events.MENetworkCellArrayUpdate;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
@@ -77,319 +44,284 @@ import appeng.util.Platform;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.prioritylist.FuzzyPriorityList;
|
||||
import appeng.util.prioritylist.PrecisePriorityList;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.IPlantable;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class PartFormationPlane extends PartAbstractFormationPlane<IAEItemStack>
|
||||
{
|
||||
public class PartFormationPlane extends PartAbstractFormationPlane<IAEItemStack> {
|
||||
|
||||
private static final PlaneModels MODELS = new PlaneModels( "part/formation_plane_", "part/formation_plane_on_" );
|
||||
private static final PlaneModels MODELS = new PlaneModels("part/formation_plane_", "part/formation_plane_on_");
|
||||
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels()
|
||||
{
|
||||
return MODELS.getModels();
|
||||
}
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels() {
|
||||
return MODELS.getModels();
|
||||
}
|
||||
|
||||
private final MEInventoryHandler<IAEItemStack> myHandler = new MEInventoryHandler<>( this, AEApi.instance()
|
||||
.storage()
|
||||
.getStorageChannel( IItemStorageChannel.class ) );
|
||||
private final AppEngInternalAEInventory Config = new AppEngInternalAEInventory( this, 63 );
|
||||
private final MEInventoryHandler<IAEItemStack> myHandler = new MEInventoryHandler<>(this, AEApi.instance()
|
||||
.storage()
|
||||
.getStorageChannel(IItemStorageChannel.class));
|
||||
private final AppEngInternalAEInventory Config = new AppEngInternalAEInventory(this, 63);
|
||||
|
||||
public PartFormationPlane( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
public PartFormationPlane(final ItemStack is) {
|
||||
super(is);
|
||||
|
||||
this.getConfigManager().registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
|
||||
this.getConfigManager().registerSetting( Settings.PLACE_BLOCK, YesNo.YES );
|
||||
this.updateHandler();
|
||||
}
|
||||
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
|
||||
this.getConfigManager().registerSetting(Settings.PLACE_BLOCK, YesNo.YES);
|
||||
this.updateHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateHandler()
|
||||
{
|
||||
this.myHandler.setBaseAccess( AccessRestriction.WRITE );
|
||||
this.myHandler.setWhitelist( this.getInstalledUpgrades( Upgrades.INVERTER ) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST );
|
||||
this.myHandler.setPriority( this.getPriority() );
|
||||
@Override
|
||||
protected void updateHandler() {
|
||||
this.myHandler.setBaseAccess(AccessRestriction.WRITE);
|
||||
this.myHandler.setWhitelist(this.getInstalledUpgrades(Upgrades.INVERTER) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST);
|
||||
this.myHandler.setPriority(this.getPriority());
|
||||
|
||||
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
|
||||
final int slotsToUse = 18 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 9;
|
||||
for( int x = 0; x < this.Config.getSlots() && x < slotsToUse; x++ )
|
||||
{
|
||||
final IAEItemStack is = this.Config.getAEStackInSlot( x );
|
||||
if( is != null )
|
||||
{
|
||||
priorityList.add( is );
|
||||
}
|
||||
}
|
||||
final int slotsToUse = 18 + this.getInstalledUpgrades(Upgrades.CAPACITY) * 9;
|
||||
for (int x = 0; x < this.Config.getSlots() && x < slotsToUse; x++) {
|
||||
final IAEItemStack is = this.Config.getAEStackInSlot(x);
|
||||
if (is != null) {
|
||||
priorityList.add(is);
|
||||
}
|
||||
}
|
||||
|
||||
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
{
|
||||
this.myHandler.setPartitionList(
|
||||
new FuzzyPriorityList<IAEItemStack>( priorityList, (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.myHandler.setPartitionList( new PrecisePriorityList<IAEItemStack>( priorityList ) );
|
||||
}
|
||||
if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0) {
|
||||
this.myHandler.setPartitionList(
|
||||
new FuzzyPriorityList<IAEItemStack>(priorityList, (FuzzyMode) this.getConfigManager().getSetting(Settings.FUZZY_MODE)));
|
||||
} else {
|
||||
this.myHandler.setPartitionList(new PrecisePriorityList<IAEItemStack>(priorityList));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
this.getProxy().getGrid().postEvent( new MENetworkCellArrayUpdate() );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
try {
|
||||
this.getProxy().getGrid().postEvent(new MENetworkCellArrayUpdate());
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
|
||||
{
|
||||
super.onChangeInventory( inv, slot, mc, removedStack, newStack );
|
||||
@Override
|
||||
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
|
||||
super.onChangeInventory(inv, slot, mc, removedStack, newStack);
|
||||
|
||||
if( inv == this.Config )
|
||||
{
|
||||
this.updateHandler();
|
||||
}
|
||||
}
|
||||
if (inv == this.Config) {
|
||||
this.updateHandler();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.Config.readFromNBT( data, "config" );
|
||||
this.updateHandler();
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
this.Config.readFromNBT(data, "config");
|
||||
this.updateHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
this.Config.writeToNBT( data, "config" );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
this.Config.writeToNBT(data, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventoryByName( final String name )
|
||||
{
|
||||
if( name.equals( "config" ) )
|
||||
{
|
||||
return this.Config;
|
||||
}
|
||||
@Override
|
||||
public IItemHandler getInventoryByName(final String name) {
|
||||
if (name.equals("config")) {
|
||||
return this.Config;
|
||||
}
|
||||
|
||||
return super.getInventoryByName( name );
|
||||
}
|
||||
return super.getInventoryByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.stateChanged();
|
||||
}
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(final MENetworkPowerStatusChange c) {
|
||||
this.stateChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void chanRender( final MENetworkChannelsChanged changedChannels )
|
||||
{
|
||||
this.stateChanged();
|
||||
}
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void chanRender(final MENetworkChannelsChanged changedChannels) {
|
||||
this.stateChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_FORMATION_PLANE );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
|
||||
if (Platform.isServer()) {
|
||||
Platform.openGUI(player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_FORMATION_PLANE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IMEInventoryHandler> getCellArray( final IStorageChannel channel )
|
||||
{
|
||||
if( channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
|
||||
{
|
||||
final List<IMEInventoryHandler> handler = new ArrayList<>( 1 );
|
||||
handler.add( this.myHandler );
|
||||
return handler;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@Override
|
||||
public List<IMEInventoryHandler> getCellArray(final IStorageChannel channel) {
|
||||
if (channel == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)) {
|
||||
final List<IMEInventoryHandler> handler = new ArrayList<>(1);
|
||||
handler.add(this.myHandler);
|
||||
return handler;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems( final IAEItemStack input, final Actionable type, final IActionSource src )
|
||||
{
|
||||
if( this.blocked || input == null || input.getStackSize() <= 0 )
|
||||
{
|
||||
return input;
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack injectItems(final IAEItemStack input, final Actionable type, final IActionSource src) {
|
||||
if (this.blocked || input == null || input.getStackSize() <= 0) {
|
||||
return input;
|
||||
}
|
||||
|
||||
final YesNo placeBlock = (YesNo) this.getConfigManager().getSetting( Settings.PLACE_BLOCK );
|
||||
final YesNo placeBlock = (YesNo) this.getConfigManager().getSetting(Settings.PLACE_BLOCK);
|
||||
|
||||
final ItemStack is = input.createItemStack();
|
||||
final Item i = is.getItem();
|
||||
final ItemStack is = input.createItemStack();
|
||||
final Item i = is.getItem();
|
||||
|
||||
long maxStorage = Math.min( input.getStackSize(), is.getMaxStackSize() );
|
||||
boolean worked = false;
|
||||
long maxStorage = Math.min(input.getStackSize(), is.getMaxStackSize());
|
||||
boolean worked = false;
|
||||
|
||||
final TileEntity te = this.getHost().getTile();
|
||||
final World w = te.getWorld();
|
||||
final AEPartLocation side = this.getSide();
|
||||
final TileEntity te = this.getHost().getTile();
|
||||
final World w = te.getWorld();
|
||||
final AEPartLocation side = this.getSide();
|
||||
|
||||
final BlockPos tePos = te.getPos().offset( side.getFacing() );
|
||||
final BlockPos tePos = te.getPos().offset(side.getFacing());
|
||||
|
||||
if( w.getBlockState( tePos ).getBlock().isReplaceable( w, tePos ) )
|
||||
{
|
||||
if( placeBlock == YesNo.YES && ( i instanceof ItemBlock || i instanceof ItemBlockSpecial || i instanceof IPlantable || i instanceof ItemSkull || i instanceof ItemFirework || i instanceof IPartItem || i == Item
|
||||
.getItemFromBlock( Blocks.REEDS ) ) )
|
||||
{
|
||||
final EntityPlayer player = Platform.getPlayer( (WorldServer) w );
|
||||
Platform.configurePlayer( player, side, this.getTile() );
|
||||
EnumHand hand = player.getActiveHand();
|
||||
player.setHeldItem( hand, is );
|
||||
if (w.getBlockState(tePos).getBlock().isReplaceable(w, tePos)) {
|
||||
if (placeBlock == YesNo.YES && (i instanceof ItemBlock || i instanceof ItemBlockSpecial || i instanceof IPlantable || i instanceof ItemSkull || i instanceof ItemFirework || i instanceof IPartItem || i == Item
|
||||
.getItemFromBlock(Blocks.REEDS))) {
|
||||
final EntityPlayer player = Platform.getPlayer((WorldServer) w);
|
||||
Platform.configurePlayer(player, side, this.getTile());
|
||||
EnumHand hand = player.getActiveHand();
|
||||
player.setHeldItem(hand, is);
|
||||
|
||||
maxStorage = is.getCount();
|
||||
worked = true;
|
||||
if( type == Actionable.MODULATE )
|
||||
{
|
||||
if( i instanceof IPlantable || i instanceof ItemSkull || i == Item.getItemFromBlock( Blocks.REEDS ) )
|
||||
{
|
||||
boolean Worked = false;
|
||||
maxStorage = is.getCount();
|
||||
worked = true;
|
||||
if (type == Actionable.MODULATE) {
|
||||
if (i instanceof IPlantable || i instanceof ItemSkull || i == Item.getItemFromBlock(Blocks.REEDS)) {
|
||||
boolean Worked = false;
|
||||
|
||||
if( side.xOffset == 0 && side.zOffset == 0 )
|
||||
{
|
||||
Worked = i.onItemUse( player, w, tePos.offset( side.getFacing() ), hand, side.getFacing().getOpposite(), side.xOffset,
|
||||
side.yOffset, side.zOffset ) == EnumActionResult.SUCCESS;
|
||||
}
|
||||
if (side.xOffset == 0 && side.zOffset == 0) {
|
||||
Worked = i.onItemUse(player, w, tePos.offset(side.getFacing()), hand, side.getFacing().getOpposite(), side.xOffset,
|
||||
side.yOffset, side.zOffset) == EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
if( !Worked && side.xOffset == 0 && side.zOffset == 0 )
|
||||
{
|
||||
Worked = i.onItemUse( player, w, tePos.offset( side.getFacing().getOpposite() ), hand, side.getFacing(), side.xOffset,
|
||||
side.yOffset, side.zOffset ) == EnumActionResult.SUCCESS;
|
||||
}
|
||||
if (!Worked && side.xOffset == 0 && side.zOffset == 0) {
|
||||
Worked = i.onItemUse(player, w, tePos.offset(side.getFacing().getOpposite()), hand, side.getFacing(), side.xOffset,
|
||||
side.yOffset, side.zOffset) == EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
if( !Worked && side.yOffset == 0 )
|
||||
{
|
||||
Worked = i.onItemUse( player, w, tePos.offset( EnumFacing.DOWN ), hand, EnumFacing.UP, side.xOffset, side.yOffset,
|
||||
side.zOffset ) == EnumActionResult.SUCCESS;
|
||||
}
|
||||
if (!Worked && side.yOffset == 0) {
|
||||
Worked = i.onItemUse(player, w, tePos.offset(EnumFacing.DOWN), hand, EnumFacing.UP, side.xOffset, side.yOffset,
|
||||
side.zOffset) == EnumActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
if( !Worked )
|
||||
{
|
||||
i.onItemUse( player, w, tePos, hand, side.getFacing().getOpposite(), side.xOffset, side.yOffset, side.zOffset );
|
||||
}
|
||||
if (!Worked) {
|
||||
i.onItemUse(player, w, tePos, hand, side.getFacing().getOpposite(), side.xOffset, side.yOffset, side.zOffset);
|
||||
}
|
||||
|
||||
maxStorage -= is.getCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
i.onItemUse( player, w, tePos, hand, side.getFacing().getOpposite(), side.xOffset, side.yOffset, side.zOffset );
|
||||
maxStorage -= is.getCount();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
maxStorage = 1;
|
||||
}
|
||||
maxStorage -= is.getCount();
|
||||
} else {
|
||||
i.onItemUse(player, w, tePos, hand, side.getFacing().getOpposite(), side.xOffset, side.yOffset, side.zOffset);
|
||||
maxStorage -= is.getCount();
|
||||
}
|
||||
} else {
|
||||
maxStorage = 1;
|
||||
}
|
||||
|
||||
// Safe keeping
|
||||
player.setHeldItem( hand, ItemStack.EMPTY );
|
||||
}
|
||||
else
|
||||
{
|
||||
worked = true;
|
||||
// Safe keeping
|
||||
player.setHeldItem(hand, ItemStack.EMPTY);
|
||||
} else {
|
||||
worked = true;
|
||||
|
||||
final int sum = this.countEntitesAround( w, tePos );
|
||||
final int sum = this.countEntitesAround(w, tePos);
|
||||
|
||||
if( sum < AEConfig.instance().getFormationPlaneEntityLimit() )
|
||||
{
|
||||
if( type == Actionable.MODULATE )
|
||||
{
|
||||
is.setCount( (int) maxStorage );
|
||||
final double x = ( side.xOffset != 0 ? 0 : .7 * ( Platform.getRandomFloat() - .5 ) ) + side.xOffset + .5 + te.getPos().getX();
|
||||
final double y = ( side.yOffset != 0 ? 0 : .7 * ( Platform.getRandomFloat() - .5 ) ) + side.yOffset + .5 + te.getPos().getY();
|
||||
final double z = ( side.zOffset != 0 ? 0 : .7 * ( Platform.getRandomFloat() - .5 ) ) + side.zOffset + .5 + te.getPos().getZ();
|
||||
if (sum < AEConfig.instance().getFormationPlaneEntityLimit()) {
|
||||
if (type == Actionable.MODULATE) {
|
||||
is.setCount((int) maxStorage);
|
||||
final double x = (side.xOffset != 0 ? 0 : .7 * (Platform.getRandomFloat() - .5)) + side.xOffset + .5 + te.getPos().getX();
|
||||
final double y = (side.yOffset != 0 ? 0 : .7 * (Platform.getRandomFloat() - .5)) + side.yOffset + .5 + te.getPos().getY();
|
||||
final double z = (side.zOffset != 0 ? 0 : .7 * (Platform.getRandomFloat() - .5)) + side.zOffset + .5 + te.getPos().getZ();
|
||||
|
||||
final EntityItem ei = new EntityItem( w, x, y, z, is.copy() );
|
||||
final EntityItem ei = new EntityItem(w, x, y, z, is.copy());
|
||||
|
||||
Entity result = ei;
|
||||
Entity result = ei;
|
||||
|
||||
ei.motionX = side.xOffset * 0.2;
|
||||
ei.motionY = side.yOffset * 0.2;
|
||||
ei.motionZ = side.zOffset * 0.2;
|
||||
ei.motionX = side.xOffset * 0.2;
|
||||
ei.motionY = side.yOffset * 0.2;
|
||||
ei.motionZ = side.zOffset * 0.2;
|
||||
|
||||
if( is.getItem().hasCustomEntity( is ) )
|
||||
{
|
||||
result = is.getItem().createEntity( w, ei, is );
|
||||
if( result != null )
|
||||
{
|
||||
ei.setDead();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = ei;
|
||||
}
|
||||
}
|
||||
if (is.getItem().hasCustomEntity(is)) {
|
||||
result = is.getItem().createEntity(w, ei, is);
|
||||
if (result != null) {
|
||||
ei.setDead();
|
||||
} else {
|
||||
result = ei;
|
||||
}
|
||||
}
|
||||
|
||||
if( !w.spawnEntity( result ) )
|
||||
{
|
||||
result.setDead();
|
||||
worked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
worked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!w.spawnEntity(result)) {
|
||||
result.setDead();
|
||||
worked = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
worked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.blocked = !w.getBlockState( tePos ).getBlock().isReplaceable( w, tePos );
|
||||
this.blocked = !w.getBlockState(tePos).getBlock().isReplaceable(w, tePos);
|
||||
|
||||
if( worked )
|
||||
{
|
||||
final IAEItemStack out = input.copy();
|
||||
out.decStackSize( maxStorage );
|
||||
if( out.getStackSize() == 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
if (worked) {
|
||||
final IAEItemStack out = input.copy();
|
||||
out.decStackSize(maxStorage);
|
||||
if (out.getStackSize() == 0) {
|
||||
return null;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
|
||||
}
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return MODELS.getModel( this.getConnections(), this.isPowered(), this.isActive() );
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return MODELS.getModel(this.getConnections(), this.isPowered(), this.isActive());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStackRepresentation()
|
||||
{
|
||||
return AEApi.instance().definitions().parts().formationPlane().maybeStack( 1 ).orElse( ItemStack.EMPTY );
|
||||
}
|
||||
@Override
|
||||
public ItemStack getItemStackRepresentation() {
|
||||
return AEApi.instance().definitions().parts().formationPlane().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiBridge getGuiBridge()
|
||||
{
|
||||
return GuiBridge.GUI_FORMATION_PLANE;
|
||||
}
|
||||
@Override
|
||||
public GuiBridge getGuiBridge() {
|
||||
return GuiBridge.GUI_FORMATION_PLANE;
|
||||
}
|
||||
|
||||
private int countEntitesAround( World world, BlockPos pos )
|
||||
{
|
||||
final AxisAlignedBB t = new AxisAlignedBB( pos ).grow( 8 );
|
||||
final List<Entity> list = world.getEntitiesWithinAABB( Entity.class, t );
|
||||
private int countEntitesAround(World world, BlockPos pos) {
|
||||
final AxisAlignedBB t = new AxisAlignedBB(pos).grow(8);
|
||||
final List<Entity> list = world.getEntitiesWithinAABB(Entity.class, t);
|
||||
|
||||
return list.size();
|
||||
}
|
||||
return list.size();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,11 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.items.parts.PartModels;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -32,83 +34,67 @@ import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.common.util.FakePlayerFactory;
|
||||
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.items.parts.PartModels;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class PartIdentityAnnihilationPlane extends PartAnnihilationPlane
|
||||
{
|
||||
public class PartIdentityAnnihilationPlane extends PartAnnihilationPlane {
|
||||
|
||||
private static final PlaneModels MODELS = new PlaneModels( "part/identity_annihilation_plane_", "part/identity_annihilation_plane_on_" );
|
||||
private static final PlaneModels MODELS = new PlaneModels("part/identity_annihilation_plane_", "part/identity_annihilation_plane_on_");
|
||||
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels()
|
||||
{
|
||||
return MODELS.getModels();
|
||||
}
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels() {
|
||||
return MODELS.getModels();
|
||||
}
|
||||
|
||||
private static final float SILK_TOUCH_FACTOR = 16;
|
||||
private static final float SILK_TOUCH_FACTOR = 16;
|
||||
|
||||
public PartIdentityAnnihilationPlane( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
public PartIdentityAnnihilationPlane(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAnnihilationPlane( final TileEntity blockTileEntity, final AEPartLocation side )
|
||||
{
|
||||
if( blockTileEntity instanceof IPartHost )
|
||||
{
|
||||
final IPart p = ( (IPartHost) blockTileEntity ).getPart( side );
|
||||
return p != null && p.getClass() == this.getClass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
protected boolean isAnnihilationPlane(final TileEntity blockTileEntity, final AEPartLocation side) {
|
||||
if (blockTileEntity instanceof IPartHost) {
|
||||
final IPart p = ((IPartHost) blockTileEntity).getPart(side);
|
||||
return p != null && p.getClass() == this.getClass();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float calculateEnergyUsage( final WorldServer w, final BlockPos pos, final List<ItemStack> items )
|
||||
{
|
||||
final float requiredEnergy = super.calculateEnergyUsage( w, pos, items );
|
||||
@Override
|
||||
protected float calculateEnergyUsage(final WorldServer w, final BlockPos pos, final List<ItemStack> items) {
|
||||
final float requiredEnergy = super.calculateEnergyUsage(w, pos, items);
|
||||
|
||||
return requiredEnergy * SILK_TOUCH_FACTOR;
|
||||
}
|
||||
return requiredEnergy * SILK_TOUCH_FACTOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ItemStack> obtainBlockDrops( final WorldServer w, final BlockPos pos )
|
||||
{
|
||||
final FakePlayer fakePlayer = FakePlayerFactory.getMinecraft( w );
|
||||
final IBlockState state = w.getBlockState( pos );
|
||||
@Override
|
||||
protected List<ItemStack> obtainBlockDrops(final WorldServer w, final BlockPos pos) {
|
||||
final FakePlayer fakePlayer = FakePlayerFactory.getMinecraft(w);
|
||||
final IBlockState state = w.getBlockState(pos);
|
||||
|
||||
if( state.getBlock().canSilkHarvest( w, pos, state, fakePlayer ) )
|
||||
{
|
||||
final List<ItemStack> out = new ArrayList<>( 1 );
|
||||
final Item item = Item.getItemFromBlock( state.getBlock() );
|
||||
if (state.getBlock().canSilkHarvest(w, pos, state, fakePlayer)) {
|
||||
final List<ItemStack> out = new ArrayList<>(1);
|
||||
final Item item = Item.getItemFromBlock(state.getBlock());
|
||||
|
||||
if( item != Items.AIR )
|
||||
{
|
||||
int meta = 0;
|
||||
if( item.getHasSubtypes() )
|
||||
{
|
||||
meta = state.getBlock().getMetaFromState( state );
|
||||
}
|
||||
final ItemStack itemstack = new ItemStack( item, 1, meta );
|
||||
out.add( itemstack );
|
||||
}
|
||||
return out;
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.obtainBlockDrops( w, pos );
|
||||
}
|
||||
}
|
||||
if (item != Items.AIR) {
|
||||
int meta = 0;
|
||||
if (item.getHasSubtypes()) {
|
||||
meta = state.getBlock().getMetaFromState(state);
|
||||
}
|
||||
final ItemStack itemstack = new ItemStack(item, 1, meta);
|
||||
out.add(itemstack);
|
||||
}
|
||||
return out;
|
||||
} else {
|
||||
return super.obtainBlockDrops(w, pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return MODELS.getModel( this.getConnections(), this.isPowered(), this.isActive() );
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return MODELS.getModel(this.getConnections(), this.isPowered(), this.isActive());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,19 +19,8 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.config.*;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.energy.IEnergySource;
|
||||
@@ -56,286 +45,233 @@ import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.IInventoryDestination;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
|
||||
public class PartImportBus extends PartSharedItemBus implements IInventoryDestination
|
||||
{
|
||||
public class PartImportBus extends PartSharedItemBus implements IInventoryDestination {
|
||||
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/import_bus_base" );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/import_bus_off" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/import_bus_on" ) );
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/import_bus_has_channel" ) );
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID, "part/import_bus_base");
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, new ResourceLocation(AppEng.MOD_ID, "part/import_bus_off"));
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, new ResourceLocation(AppEng.MOD_ID, "part/import_bus_on"));
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, new ResourceLocation(AppEng.MOD_ID, "part/import_bus_has_channel"));
|
||||
|
||||
private final IActionSource source;
|
||||
private int itemsToSend; // used in tickingRequest
|
||||
private boolean worked; // used in tickingRequest
|
||||
private final IActionSource source;
|
||||
private int itemsToSend; // used in tickingRequest
|
||||
private boolean worked; // used in tickingRequest
|
||||
|
||||
@Reflected
|
||||
public PartImportBus( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
@Reflected
|
||||
public PartImportBus(final ItemStack is) {
|
||||
super(is);
|
||||
|
||||
this.getConfigManager().registerSetting( Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
|
||||
this.getConfigManager().registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
|
||||
this.source = new MachineSource( this );
|
||||
}
|
||||
this.getConfigManager().registerSetting(Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE);
|
||||
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
|
||||
this.source = new MachineSource(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert( final ItemStack stack )
|
||||
{
|
||||
if( stack.isEmpty() || stack.getItem() == Items.AIR )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean canInsert(final ItemStack stack) {
|
||||
if (stack.isEmpty() || stack.getItem() == Items.AIR) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
final IMEMonitor<IAEItemStack> inv = this.getProxy()
|
||||
.getStorage()
|
||||
.getInventory(
|
||||
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
|
||||
try {
|
||||
final IMEMonitor<IAEItemStack> inv = this.getProxy()
|
||||
.getStorage()
|
||||
.getInventory(
|
||||
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
|
||||
final IAEItemStack out = inv.injectItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( stack ),
|
||||
Actionable.SIMULATE,
|
||||
this.source );
|
||||
if( out == null )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return out.getStackSize() != stack.getCount();
|
||||
}
|
||||
catch( GridAccessException ex )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final IAEItemStack out = inv.injectItems(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(stack),
|
||||
Actionable.SIMULATE,
|
||||
this.source);
|
||||
if (out == null) {
|
||||
return true;
|
||||
}
|
||||
return out.getStackSize() != stack.getCount();
|
||||
} catch (GridAccessException ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final 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 void getBoxes(final 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 float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_BUS );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
|
||||
if (Platform.isServer()) {
|
||||
Platform.openGUI(player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_BUS);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest( final IGridNode node )
|
||||
{
|
||||
return new TickingRequest( TickRates.ImportBus.getMin(), TickRates.ImportBus.getMax(), this.isSleeping(), false );
|
||||
}
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(final IGridNode node) {
|
||||
return new TickingRequest(TickRates.ImportBus.getMin(), TickRates.ImportBus.getMax(), this.isSleeping(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
|
||||
{
|
||||
return this.doBusWork();
|
||||
}
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
|
||||
return this.doBusWork();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TickRateModulation doBusWork()
|
||||
{
|
||||
if( !this.getProxy().isActive() || !this.canDoBusWork() )
|
||||
{
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
@Override
|
||||
protected TickRateModulation doBusWork() {
|
||||
if (!this.getProxy().isActive() || !this.canDoBusWork()) {
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
this.worked = false;
|
||||
this.worked = false;
|
||||
|
||||
final InventoryAdaptor myAdaptor = this.getHandler();
|
||||
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE );
|
||||
final InventoryAdaptor myAdaptor = this.getHandler();
|
||||
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting(Settings.FUZZY_MODE);
|
||||
|
||||
if( myAdaptor != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
this.itemsToSend = this.calculateItemsToSend();
|
||||
if (myAdaptor != null) {
|
||||
try {
|
||||
this.itemsToSend = this.calculateItemsToSend();
|
||||
|
||||
final IMEMonitor<IAEItemStack> inv = this.getProxy()
|
||||
.getStorage()
|
||||
.getInventory(
|
||||
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
final IMEMonitor<IAEItemStack> inv = this.getProxy()
|
||||
.getStorage()
|
||||
.getInventory(
|
||||
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
|
||||
boolean Configured = false;
|
||||
for( int x = 0; x < this.availableSlots(); x++ )
|
||||
{
|
||||
final IAEItemStack ais = this.getConfig().getAEStackInSlot( x );
|
||||
if( ais != null && this.itemsToSend > 0 )
|
||||
{
|
||||
Configured = true;
|
||||
while( this.itemsToSend > 0 )
|
||||
{
|
||||
if( this.importStuff( myAdaptor, ais, inv, energy, fzMode ) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean Configured = false;
|
||||
for (int x = 0; x < this.availableSlots(); x++) {
|
||||
final IAEItemStack ais = this.getConfig().getAEStackInSlot(x);
|
||||
if (ais != null && this.itemsToSend > 0) {
|
||||
Configured = true;
|
||||
while (this.itemsToSend > 0) {
|
||||
if (this.importStuff(myAdaptor, ais, inv, energy, fzMode)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !Configured )
|
||||
{
|
||||
while( this.itemsToSend > 0 )
|
||||
{
|
||||
if( this.importStuff( myAdaptor, null, inv, energy, fzMode ) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :3
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
if (!Configured) {
|
||||
while (this.itemsToSend > 0) {
|
||||
if (this.importStuff(myAdaptor, null, inv, energy, fzMode)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// :3
|
||||
}
|
||||
} else {
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
return this.worked ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
}
|
||||
return this.worked ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
}
|
||||
|
||||
private boolean importStuff( final InventoryAdaptor myAdaptor, final IAEItemStack whatToImport, final IMEMonitor<IAEItemStack> inv, final IEnergySource energy, final FuzzyMode fzMode )
|
||||
{
|
||||
final int toSend = this.calculateMaximumAmountToImport( myAdaptor, whatToImport, inv, fzMode );
|
||||
private boolean importStuff(final InventoryAdaptor myAdaptor, final IAEItemStack whatToImport, final IMEMonitor<IAEItemStack> inv, final IEnergySource energy, final FuzzyMode fzMode) {
|
||||
final int toSend = this.calculateMaximumAmountToImport(myAdaptor, whatToImport, inv, fzMode);
|
||||
|
||||
if( toSend == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (toSend == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final ItemStack newItems;
|
||||
final ItemStack newItems;
|
||||
|
||||
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
{
|
||||
newItems = myAdaptor.removeSimilarItems( toSend, whatToImport == null ? ItemStack.EMPTY : whatToImport.getDefinition(), fzMode, this );
|
||||
}
|
||||
else
|
||||
{
|
||||
newItems = myAdaptor.removeItems( toSend, whatToImport == null ? ItemStack.EMPTY : whatToImport.getDefinition(), this );
|
||||
}
|
||||
if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0) {
|
||||
newItems = myAdaptor.removeSimilarItems(toSend, whatToImport == null ? ItemStack.EMPTY : whatToImport.getDefinition(), fzMode, this);
|
||||
} else {
|
||||
newItems = myAdaptor.removeItems(toSend, whatToImport == null ? ItemStack.EMPTY : whatToImport.getDefinition(), this);
|
||||
}
|
||||
|
||||
if( !newItems.isEmpty() )
|
||||
{
|
||||
final IAEItemStack aeStack = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( newItems );
|
||||
final IAEItemStack failed = Platform.poweredInsert( energy, inv, aeStack, this.source );
|
||||
if (!newItems.isEmpty()) {
|
||||
final IAEItemStack aeStack = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(newItems);
|
||||
final IAEItemStack failed = Platform.poweredInsert(energy, inv, aeStack, this.source);
|
||||
|
||||
if( failed != null )
|
||||
{
|
||||
// try unpowered insert, better be a bit lenient then void items
|
||||
final IAEItemStack spill = inv.injectItems( failed, Actionable.MODULATE, this.source );
|
||||
if( spill != null )
|
||||
{
|
||||
// last resort try to put it back .. lets hope it's a chest type of thing
|
||||
myAdaptor.addItems( spill.createItemStack() );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.itemsToSend -= newItems.getCount();
|
||||
this.worked = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (failed != null) {
|
||||
// try unpowered insert, better be a bit lenient then void items
|
||||
final IAEItemStack spill = inv.injectItems(failed, Actionable.MODULATE, this.source);
|
||||
if (spill != null) {
|
||||
// last resort try to put it back .. lets hope it's a chest type of thing
|
||||
myAdaptor.addItems(spill.createItemStack());
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
this.itemsToSend -= newItems.getCount();
|
||||
this.worked = true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int calculateMaximumAmountToImport( final InventoryAdaptor myAdaptor, final IAEItemStack whatToImport, final IMEMonitor<IAEItemStack> inv, final FuzzyMode fzMode )
|
||||
{
|
||||
final int toSend = Math.min( this.itemsToSend, 64 );
|
||||
final ItemStack itemStackToImport;
|
||||
private int calculateMaximumAmountToImport(final InventoryAdaptor myAdaptor, final IAEItemStack whatToImport, final IMEMonitor<IAEItemStack> inv, final FuzzyMode fzMode) {
|
||||
final int toSend = Math.min(this.itemsToSend, 64);
|
||||
final ItemStack itemStackToImport;
|
||||
|
||||
if( whatToImport == null )
|
||||
{
|
||||
itemStackToImport = ItemStack.EMPTY;
|
||||
}
|
||||
else
|
||||
{
|
||||
itemStackToImport = whatToImport.getDefinition();
|
||||
}
|
||||
if (whatToImport == null) {
|
||||
itemStackToImport = ItemStack.EMPTY;
|
||||
} else {
|
||||
itemStackToImport = whatToImport.getDefinition();
|
||||
}
|
||||
|
||||
final IAEItemStack itemAmountNotStorable;
|
||||
final ItemStack simResult;
|
||||
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
{
|
||||
simResult = myAdaptor.simulateSimilarRemove( toSend, itemStackToImport, fzMode, null );
|
||||
itemAmountNotStorable = inv.injectItems( AEItemStack.fromItemStack( simResult ), Actionable.SIMULATE, this.source );
|
||||
}
|
||||
else
|
||||
{
|
||||
simResult = myAdaptor.simulateRemove( toSend, itemStackToImport, null );
|
||||
itemAmountNotStorable = inv.injectItems( AEItemStack.fromItemStack( simResult ), Actionable.SIMULATE, this.source );
|
||||
}
|
||||
final IAEItemStack itemAmountNotStorable;
|
||||
final ItemStack simResult;
|
||||
if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0) {
|
||||
simResult = myAdaptor.simulateSimilarRemove(toSend, itemStackToImport, fzMode, null);
|
||||
itemAmountNotStorable = inv.injectItems(AEItemStack.fromItemStack(simResult), Actionable.SIMULATE, this.source);
|
||||
} else {
|
||||
simResult = myAdaptor.simulateRemove(toSend, itemStackToImport, null);
|
||||
itemAmountNotStorable = inv.injectItems(AEItemStack.fromItemStack(simResult), Actionable.SIMULATE, this.source);
|
||||
}
|
||||
|
||||
if( simResult.isEmpty() )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (simResult.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( itemAmountNotStorable != null )
|
||||
{
|
||||
if( simResult.getCount() == itemAmountNotStorable.getStackSize() )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return (int) Math.min( simResult.getCount() - itemAmountNotStorable.getStackSize(), toSend );
|
||||
}
|
||||
if (itemAmountNotStorable != null) {
|
||||
if (simResult.getCount() == itemAmountNotStorable.getStackSize()) {
|
||||
return 0;
|
||||
}
|
||||
return (int) Math.min(simResult.getCount() - itemAmountNotStorable.getStackSize(), toSend);
|
||||
}
|
||||
|
||||
return toSend;
|
||||
}
|
||||
return toSend;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSleeping()
|
||||
{
|
||||
return this.getHandler() == null || super.isSleeping();
|
||||
}
|
||||
@Override
|
||||
protected boolean isSleeping() {
|
||||
return this.getHandler() == null || super.isSleeping();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneMode getRSMode()
|
||||
{
|
||||
return (RedstoneMode) this.getConfigManager().getSetting( Settings.REDSTONE_CONTROLLED );
|
||||
}
|
||||
@Override
|
||||
public RedstoneMode getRSMode() {
|
||||
return (RedstoneMode) this.getConfigManager().getSetting(Settings.REDSTONE_CONTROLLED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
if( this.isActive() && this.isPowered() )
|
||||
{
|
||||
return MODELS_HAS_CHANNEL;
|
||||
}
|
||||
else if( this.isPowered() )
|
||||
{
|
||||
return MODELS_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
if (this.isActive() && this.isPowered()) {
|
||||
return MODELS_HAS_CHANNEL;
|
||||
} else if (this.isPowered()) {
|
||||
return MODELS_ON;
|
||||
} else {
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,8 +55,6 @@ import appeng.parts.PartModel;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.item.OreHelper;
|
||||
import appeng.util.item.OreReference;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -70,503 +68,406 @@ import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherHost, IStackWatcherHost, ICraftingWatcherHost, IMEMonitorHandlerReceiver<IAEItemStack>, ICraftingProvider
|
||||
{
|
||||
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE_OFF = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_base_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE_ON = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_base_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_status_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_status_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation( AppEng.MOD_ID, "part/level_emitter_status_has_channel" );
|
||||
|
||||
public static final PartModel MODEL_OFF_OFF = new PartModel( MODEL_BASE_OFF, MODEL_STATUS_OFF );
|
||||
public static final PartModel MODEL_OFF_ON = new PartModel( MODEL_BASE_OFF, MODEL_STATUS_ON );
|
||||
public static final PartModel MODEL_OFF_HAS_CHANNEL = new PartModel( MODEL_BASE_OFF, MODEL_STATUS_HAS_CHANNEL );
|
||||
public static final PartModel MODEL_ON_OFF = new PartModel( MODEL_BASE_ON, MODEL_STATUS_OFF );
|
||||
public static final PartModel MODEL_ON_ON = new PartModel( MODEL_BASE_ON, MODEL_STATUS_ON );
|
||||
public static final PartModel MODEL_ON_HAS_CHANNEL = new PartModel( MODEL_BASE_ON, MODEL_STATUS_HAS_CHANNEL );
|
||||
|
||||
private static final int FLAG_ON = 4;
|
||||
|
||||
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 1 );
|
||||
|
||||
private boolean prevState = false;
|
||||
|
||||
private long lastReportedValue = 0;
|
||||
private long reportingValue = 0;
|
||||
|
||||
private IStackWatcher myWatcher;
|
||||
private IEnergyWatcher myEnergyWatcher;
|
||||
private ICraftingWatcher myCraftingWatcher;
|
||||
private double centerX;
|
||||
private double centerY;
|
||||
private double centerZ;
|
||||
|
||||
@Reflected
|
||||
public PartLevelEmitter( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
|
||||
this.getConfigManager().registerSetting( Settings.REDSTONE_EMITTER, RedstoneMode.HIGH_SIGNAL );
|
||||
this.getConfigManager().registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
|
||||
this.getConfigManager().registerSetting( Settings.LEVEL_TYPE, LevelType.ITEM_LEVEL );
|
||||
this.getConfigManager().registerSetting( Settings.CRAFT_VIA_REDSTONE, YesNo.NO );
|
||||
}
|
||||
|
||||
public long getReportingValue()
|
||||
{
|
||||
return this.reportingValue;
|
||||
}
|
||||
|
||||
public void setReportingValue( final long v )
|
||||
{
|
||||
this.reportingValue = v;
|
||||
if( this.getConfigManager().getSetting( Settings.LEVEL_TYPE ) == LevelType.ENERGY_LEVEL )
|
||||
{
|
||||
this.configureWatchers();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.updateState();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
final boolean isOn = this.isLevelEmitterOn();
|
||||
if( this.prevState != isOn )
|
||||
{
|
||||
this.getHost().markForUpdate();
|
||||
final TileEntity te = this.getHost().getTile();
|
||||
this.prevState = isOn;
|
||||
Platform.notifyBlocksOfNeighbors( te.getWorld(), te.getPos() );
|
||||
Platform.notifyBlocksOfNeighbors( te.getWorld(), te.getPos().offset( this.getSide().getFacing() ) );
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Make private again
|
||||
public boolean isLevelEmitterOn()
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return ( this.getClientFlags() & FLAG_ON ) == FLAG_ON;
|
||||
}
|
||||
|
||||
if( !this.getProxy().isActive() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( this.getInstalledUpgrades( Upgrades.CRAFTING ) > 0 )
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.getProxy().getCrafting().isRequesting( this.config.getAEStackInSlot( 0 ) );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
return this.prevState;
|
||||
}
|
||||
|
||||
final boolean flipState = this.getConfigManager().getSetting( Settings.REDSTONE_EMITTER ) == RedstoneMode.LOW_SIGNAL;
|
||||
return flipState ? this.reportingValue >= this.lastReportedValue + 1 : this.reportingValue < this.lastReportedValue + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender( final MENetworkPowerStatusChange powerEvent )
|
||||
{
|
||||
if (this.getProxy().isActive())
|
||||
{
|
||||
onListUpdate();
|
||||
}
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void chanRender( final MENetworkChannelsChanged c )
|
||||
{
|
||||
if (this.getProxy().isActive())
|
||||
{
|
||||
onListUpdate();
|
||||
}
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int populateFlags( final int cf )
|
||||
{
|
||||
return cf | ( this.prevState ? FLAG_ON : 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatcher( final ICraftingWatcher newWatcher )
|
||||
{
|
||||
this.myCraftingWatcher = newWatcher;
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestChange( final ICraftingGrid craftingGrid, final IAEItemStack what )
|
||||
{
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
// update the system...
|
||||
private void configureWatchers()
|
||||
{
|
||||
final IAEItemStack myStack = this.config.getAEStackInSlot( 0 );
|
||||
|
||||
if( this.myWatcher != null )
|
||||
{
|
||||
this.myWatcher.reset();
|
||||
}
|
||||
|
||||
if( this.myEnergyWatcher != null )
|
||||
{
|
||||
this.myEnergyWatcher.reset();
|
||||
}
|
||||
|
||||
if( this.myCraftingWatcher != null )
|
||||
{
|
||||
this.myCraftingWatcher.reset();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
this.getProxy().getGrid().postEvent( new MENetworkCraftingPatternChange( this, this.getProxy().getNode() ) );
|
||||
}
|
||||
catch( final GridAccessException e1 )
|
||||
{
|
||||
// :/
|
||||
}
|
||||
|
||||
if( this.getInstalledUpgrades( Upgrades.CRAFTING ) > 0 )
|
||||
{
|
||||
if( this.myCraftingWatcher != null && myStack != null )
|
||||
{
|
||||
this.myCraftingWatcher.add( myStack );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if( this.getConfigManager().getSetting( Settings.LEVEL_TYPE ) == LevelType.ENERGY_LEVEL )
|
||||
{
|
||||
if( this.myEnergyWatcher != null )
|
||||
{
|
||||
this.myEnergyWatcher.add( this.reportingValue );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// update to power...
|
||||
this.lastReportedValue = (long) this.getProxy().getEnergy().getStoredPower();
|
||||
this.updateState();
|
||||
|
||||
// no more item stuff..
|
||||
this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ).removeListener( this );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 || myStack == null )
|
||||
{
|
||||
this.getProxy()
|
||||
.getStorage()
|
||||
.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
|
||||
.addListener( this,
|
||||
this.getProxy().getGrid() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ).removeListener( this );
|
||||
|
||||
if( this.myWatcher != null )
|
||||
{
|
||||
this.myWatcher.add( myStack );
|
||||
}
|
||||
}
|
||||
|
||||
this.updateReportingValue( this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// >.>
|
||||
}
|
||||
}
|
||||
|
||||
private void updateReportingValue( final IMEMonitor<IAEItemStack> monitor )
|
||||
{
|
||||
final IAEItemStack myStack = this.config.getAEStackInSlot( 0 );
|
||||
|
||||
if( myStack == null )
|
||||
{
|
||||
if( monitor instanceof NetworkMonitor )
|
||||
{
|
||||
this.lastReportedValue = ( (NetworkMonitor<IAEItemStack>) monitor ).getGridCurrentCount();
|
||||
}
|
||||
}
|
||||
|
||||
else if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
{
|
||||
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE );
|
||||
|
||||
this.lastReportedValue = 0;
|
||||
monitor.getStorageList().findFuzzy( myStack, fzMode ).forEach( iaeItemStack -> lastReportedValue += iaeItemStack.getStackSize() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.lastReportedValue = 0;
|
||||
IAEItemStack precise = monitor.getStorageList().findPrecise( myStack );
|
||||
if( precise != null ) lastReportedValue = precise.getStackSize();
|
||||
}
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatcher( final IStackWatcher newWatcher )
|
||||
{
|
||||
this.myWatcher = newWatcher;
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStackChange( final IItemList o, final IAEStack fullStack, final IAEStack diffStack, final IActionSource src, final IStorageChannel chan )
|
||||
{
|
||||
if( chan == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) && fullStack.equals( this.config.getAEStackInSlot( 0 ) ) && this.getInstalledUpgrades( Upgrades.FUZZY ) == 0 )
|
||||
{
|
||||
this.lastReportedValue = fullStack.getStackSize();
|
||||
this.updateState();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatcher( final IEnergyWatcher newWatcher )
|
||||
{
|
||||
this.myEnergyWatcher = newWatcher;
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onThresholdPass( final IEnergyGrid energyGrid )
|
||||
{
|
||||
this.lastReportedValue = (long) energyGrid.getStoredPower();
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid( final Object effectiveGrid )
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.getProxy().getGrid() == effectiveGrid;
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postChange( final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource actionSource )
|
||||
{
|
||||
this.updateReportingValue( (IMEMonitor<IAEItemStack>) monitor );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListUpdate()
|
||||
{
|
||||
try
|
||||
{
|
||||
this.updateReportingValue( this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// ;P
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType( final AEPartLocation dir )
|
||||
{
|
||||
return AECableType.SMART;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
bch.addBox( 7, 7, 11, 9, 9, 16 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower()
|
||||
{
|
||||
return this.prevState ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower()
|
||||
{
|
||||
return this.prevState ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomDisplayTick( final World world, final BlockPos pos, final Random r )
|
||||
{
|
||||
if( this.isLevelEmitterOn() )
|
||||
{
|
||||
final AEPartLocation d = this.getSide();
|
||||
|
||||
final double d0 = d.xOffset * 0.45F + ( r.nextFloat() - 0.5F ) * 0.2D;
|
||||
final double d1 = d.yOffset * 0.45F + ( r.nextFloat() - 0.5F ) * 0.2D;
|
||||
final double d2 = d.zOffset * 0.45F + ( r.nextFloat() - 0.5F ) * 0.2D;
|
||||
|
||||
world.spawnParticle( EnumParticleTypes.REDSTONE, 0.5 + pos.getX() + d0, 0.5 + pos.getY() + d1, 0.5 + pos.getZ() + d2, 0.0D, 0.0D, 0.0D,
|
||||
new int[0] );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_LEVEL_EMITTER );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
|
||||
{
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
|
||||
{
|
||||
if( inv == this.config )
|
||||
{
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
super.onChangeInventory( inv, slot, mc, removedStack, newStack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upgradesChanged()
|
||||
{
|
||||
this.configureWatchers();
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.lastReportedValue = data.getLong( "lastReportedValue" );
|
||||
this.reportingValue = data.getLong( "reportingValue" );
|
||||
this.prevState = data.getBoolean( "prevState" );
|
||||
this.config.readFromNBT( data, "config" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
data.setLong( "lastReportedValue", this.lastReportedValue );
|
||||
data.setLong( "reportingValue", this.reportingValue );
|
||||
data.setBoolean( "prevState", this.prevState );
|
||||
this.config.writeToNBT( data, "config" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventoryByName( final String name )
|
||||
{
|
||||
if( name.equals( "config" ) )
|
||||
{
|
||||
return this.config;
|
||||
}
|
||||
|
||||
return super.getInventoryByName( name );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pushPattern( final ICraftingPatternDetails patternDetails, final InventoryCrafting table )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBusy()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provideCrafting( final ICraftingProviderHelper craftingTracker )
|
||||
{
|
||||
if( this.getInstalledUpgrades( Upgrades.CRAFTING ) > 0 )
|
||||
{
|
||||
if( this.getConfigManager().getSetting( Settings.CRAFT_VIA_REDSTONE ) == YesNo.YES )
|
||||
{
|
||||
final IAEItemStack what = this.config.getAEStackInSlot( 0 );
|
||||
if( what != null )
|
||||
{
|
||||
craftingTracker.setEmitable( what );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
if( this.isActive() && this.isPowered() )
|
||||
{
|
||||
return this.isLevelEmitterOn() ? MODEL_ON_HAS_CHANNEL : MODEL_OFF_HAS_CHANNEL;
|
||||
}
|
||||
else if( this.isPowered() )
|
||||
{
|
||||
return this.isLevelEmitterOn() ? MODEL_ON_ON : MODEL_OFF_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.isLevelEmitterOn() ? MODEL_ON_OFF : MODEL_OFF_OFF;
|
||||
}
|
||||
}
|
||||
public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherHost, IStackWatcherHost, ICraftingWatcherHost, IMEMonitorHandlerReceiver<IAEItemStack>, ICraftingProvider {
|
||||
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE_OFF = new ResourceLocation(AppEng.MOD_ID, "part/level_emitter_base_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE_ON = new ResourceLocation(AppEng.MOD_ID, "part/level_emitter_base_on");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation(AppEng.MOD_ID, "part/level_emitter_status_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation(AppEng.MOD_ID, "part/level_emitter_status_on");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation(AppEng.MOD_ID, "part/level_emitter_status_has_channel");
|
||||
|
||||
public static final PartModel MODEL_OFF_OFF = new PartModel(MODEL_BASE_OFF, MODEL_STATUS_OFF);
|
||||
public static final PartModel MODEL_OFF_ON = new PartModel(MODEL_BASE_OFF, MODEL_STATUS_ON);
|
||||
public static final PartModel MODEL_OFF_HAS_CHANNEL = new PartModel(MODEL_BASE_OFF, MODEL_STATUS_HAS_CHANNEL);
|
||||
public static final PartModel MODEL_ON_OFF = new PartModel(MODEL_BASE_ON, MODEL_STATUS_OFF);
|
||||
public static final PartModel MODEL_ON_ON = new PartModel(MODEL_BASE_ON, MODEL_STATUS_ON);
|
||||
public static final PartModel MODEL_ON_HAS_CHANNEL = new PartModel(MODEL_BASE_ON, MODEL_STATUS_HAS_CHANNEL);
|
||||
|
||||
private static final int FLAG_ON = 4;
|
||||
|
||||
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory(this, 1);
|
||||
|
||||
private boolean prevState = false;
|
||||
|
||||
private long lastReportedValue = 0;
|
||||
private long reportingValue = 0;
|
||||
|
||||
private IStackWatcher myWatcher;
|
||||
private IEnergyWatcher myEnergyWatcher;
|
||||
private ICraftingWatcher myCraftingWatcher;
|
||||
private double centerX;
|
||||
private double centerY;
|
||||
private double centerZ;
|
||||
|
||||
@Reflected
|
||||
public PartLevelEmitter(final ItemStack is) {
|
||||
super(is);
|
||||
|
||||
this.getConfigManager().registerSetting(Settings.REDSTONE_EMITTER, RedstoneMode.HIGH_SIGNAL);
|
||||
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
|
||||
this.getConfigManager().registerSetting(Settings.LEVEL_TYPE, LevelType.ITEM_LEVEL);
|
||||
this.getConfigManager().registerSetting(Settings.CRAFT_VIA_REDSTONE, YesNo.NO);
|
||||
}
|
||||
|
||||
public long getReportingValue() {
|
||||
return this.reportingValue;
|
||||
}
|
||||
|
||||
public void setReportingValue(final long v) {
|
||||
this.reportingValue = v;
|
||||
if (this.getConfigManager().getSetting(Settings.LEVEL_TYPE) == LevelType.ENERGY_LEVEL) {
|
||||
this.configureWatchers();
|
||||
} else {
|
||||
this.updateState();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateState() {
|
||||
final boolean isOn = this.isLevelEmitterOn();
|
||||
if (this.prevState != isOn) {
|
||||
this.getHost().markForUpdate();
|
||||
final TileEntity te = this.getHost().getTile();
|
||||
this.prevState = isOn;
|
||||
Platform.notifyBlocksOfNeighbors(te.getWorld(), te.getPos());
|
||||
Platform.notifyBlocksOfNeighbors(te.getWorld(), te.getPos().offset(this.getSide().getFacing()));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Make private again
|
||||
public boolean isLevelEmitterOn() {
|
||||
if (Platform.isClient()) {
|
||||
return (this.getClientFlags() & FLAG_ON) == FLAG_ON;
|
||||
}
|
||||
|
||||
if (!this.getProxy().isActive()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.getInstalledUpgrades(Upgrades.CRAFTING) > 0) {
|
||||
try {
|
||||
return this.getProxy().getCrafting().isRequesting(this.config.getAEStackInSlot(0));
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
|
||||
return this.prevState;
|
||||
}
|
||||
|
||||
final boolean flipState = this.getConfigManager().getSetting(Settings.REDSTONE_EMITTER) == RedstoneMode.LOW_SIGNAL;
|
||||
return flipState == (this.reportingValue >= this.lastReportedValue + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(final MENetworkPowerStatusChange powerEvent) {
|
||||
if (this.getProxy().isActive()) {
|
||||
onListUpdate();
|
||||
}
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void chanRender(final MENetworkChannelsChanged c) {
|
||||
if (this.getProxy().isActive()) {
|
||||
onListUpdate();
|
||||
}
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int populateFlags(final int cf) {
|
||||
return cf | (this.prevState ? FLAG_ON : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatcher(final ICraftingWatcher newWatcher) {
|
||||
this.myCraftingWatcher = newWatcher;
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestChange(final ICraftingGrid craftingGrid, final IAEItemStack what) {
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
// update the system...
|
||||
private void configureWatchers() {
|
||||
final IAEItemStack myStack = this.config.getAEStackInSlot(0);
|
||||
|
||||
if (this.myWatcher != null) {
|
||||
this.myWatcher.reset();
|
||||
}
|
||||
|
||||
if (this.myEnergyWatcher != null) {
|
||||
this.myEnergyWatcher.reset();
|
||||
}
|
||||
|
||||
if (this.myCraftingWatcher != null) {
|
||||
this.myCraftingWatcher.reset();
|
||||
}
|
||||
|
||||
try {
|
||||
this.getProxy().getGrid().postEvent(new MENetworkCraftingPatternChange(this, this.getProxy().getNode()));
|
||||
} catch (final GridAccessException e1) {
|
||||
// :/
|
||||
}
|
||||
|
||||
if (this.getInstalledUpgrades(Upgrades.CRAFTING) > 0) {
|
||||
if (this.myCraftingWatcher != null && myStack != null) {
|
||||
this.myCraftingWatcher.add(myStack);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.getConfigManager().getSetting(Settings.LEVEL_TYPE) == LevelType.ENERGY_LEVEL) {
|
||||
if (this.myEnergyWatcher != null) {
|
||||
this.myEnergyWatcher.add(this.reportingValue);
|
||||
}
|
||||
|
||||
try {
|
||||
// update to power...
|
||||
this.lastReportedValue = (long) this.getProxy().getEnergy().getStoredPower();
|
||||
this.updateState();
|
||||
|
||||
// no more item stuff..
|
||||
this.getProxy().getStorage().getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)).removeListener(this);
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0 || myStack == null) {
|
||||
this.getProxy()
|
||||
.getStorage()
|
||||
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class))
|
||||
.addListener(this,
|
||||
this.getProxy().getGrid());
|
||||
} else {
|
||||
this.getProxy().getStorage().getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)).removeListener(this);
|
||||
|
||||
if (this.myWatcher != null) {
|
||||
this.myWatcher.add(myStack);
|
||||
}
|
||||
}
|
||||
|
||||
this.updateReportingValue(this.getProxy().getStorage().getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)));
|
||||
} catch (final GridAccessException e) {
|
||||
// >.>
|
||||
}
|
||||
}
|
||||
|
||||
private void updateReportingValue(final IMEMonitor<IAEItemStack> monitor) {
|
||||
final IAEItemStack myStack = this.config.getAEStackInSlot(0);
|
||||
|
||||
if (myStack == null) {
|
||||
if (monitor instanceof NetworkMonitor) {
|
||||
this.lastReportedValue = ((NetworkMonitor<IAEItemStack>) monitor).getGridCurrentCount();
|
||||
}
|
||||
} else if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0) {
|
||||
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting(Settings.FUZZY_MODE);
|
||||
|
||||
this.lastReportedValue = 0;
|
||||
monitor.getStorageList().findFuzzy(myStack, fzMode).forEach(iaeItemStack -> lastReportedValue += iaeItemStack.getStackSize());
|
||||
} else {
|
||||
this.lastReportedValue = 0;
|
||||
IAEItemStack precise = monitor.getStorageList().findPrecise(myStack);
|
||||
if (precise != null) lastReportedValue = precise.getStackSize();
|
||||
}
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatcher(final IStackWatcher newWatcher) {
|
||||
this.myWatcher = newWatcher;
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStackChange(final IItemList o, final IAEStack fullStack, final IAEStack diffStack, final IActionSource src, final IStorageChannel chan) {
|
||||
if (chan == AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class) && fullStack.equals(this.config.getAEStackInSlot(0)) && this.getInstalledUpgrades(Upgrades.FUZZY) == 0) {
|
||||
this.lastReportedValue = fullStack.getStackSize();
|
||||
this.updateState();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatcher(final IEnergyWatcher newWatcher) {
|
||||
this.myEnergyWatcher = newWatcher;
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onThresholdPass(final IEnergyGrid energyGrid) {
|
||||
this.lastReportedValue = (long) energyGrid.getStoredPower();
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(final Object effectiveGrid) {
|
||||
try {
|
||||
return this.getProxy().getGrid() == effectiveGrid;
|
||||
} catch (final GridAccessException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postChange(final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource actionSource) {
|
||||
this.updateReportingValue((IMEMonitor<IAEItemStack>) monitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListUpdate() {
|
||||
try {
|
||||
this.updateReportingValue(this.getProxy().getStorage().getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)));
|
||||
} catch (final GridAccessException e) {
|
||||
// ;P
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType(final AEPartLocation dir) {
|
||||
return AECableType.SMART;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(7, 7, 11, 9, 9, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower() {
|
||||
return this.prevState ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower() {
|
||||
return this.prevState ? 15 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomDisplayTick(final World world, final BlockPos pos, final Random r) {
|
||||
if (this.isLevelEmitterOn()) {
|
||||
final AEPartLocation d = this.getSide();
|
||||
|
||||
final double d0 = d.xOffset * 0.45F + (r.nextFloat() - 0.5F) * 0.2D;
|
||||
final double d1 = d.yOffset * 0.45F + (r.nextFloat() - 0.5F) * 0.2D;
|
||||
final double d2 = d.zOffset * 0.45F + (r.nextFloat() - 0.5F) * 0.2D;
|
||||
|
||||
world.spawnParticle(EnumParticleTypes.REDSTONE, 0.5 + pos.getX() + d0, 0.5 + pos.getY() + d1, 0.5 + pos.getZ() + d2, 0.0D, 0.0D, 0.0D
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
|
||||
if (Platform.isServer()) {
|
||||
Platform.openGUI(player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_LEVEL_EMITTER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) {
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
|
||||
if (inv == this.config) {
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
super.onChangeInventory(inv, slot, mc, removedStack, newStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upgradesChanged() {
|
||||
this.configureWatchers();
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
this.lastReportedValue = data.getLong("lastReportedValue");
|
||||
this.reportingValue = data.getLong("reportingValue");
|
||||
this.prevState = data.getBoolean("prevState");
|
||||
this.config.readFromNBT(data, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
data.setLong("lastReportedValue", this.lastReportedValue);
|
||||
data.setLong("reportingValue", this.reportingValue);
|
||||
data.setBoolean("prevState", this.prevState);
|
||||
this.config.writeToNBT(data, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventoryByName(final String name) {
|
||||
if (name.equals("config")) {
|
||||
return this.config;
|
||||
}
|
||||
|
||||
return super.getInventoryByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pushPattern(final ICraftingPatternDetails patternDetails, final InventoryCrafting table) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBusy() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provideCrafting(final ICraftingProviderHelper craftingTracker) {
|
||||
if (this.getInstalledUpgrades(Upgrades.CRAFTING) > 0) {
|
||||
if (this.getConfigManager().getSetting(Settings.CRAFT_VIA_REDSTONE) == YesNo.YES) {
|
||||
final IAEItemStack what = this.config.getAEStackInSlot(0);
|
||||
if (what != null) {
|
||||
craftingTracker.setEmitable(what);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
if (this.isActive() && this.isPowered()) {
|
||||
return this.isLevelEmitterOn() ? MODEL_ON_HAS_CHANNEL : MODEL_OFF_HAS_CHANNEL;
|
||||
} else if (this.isPowered()) {
|
||||
return this.isLevelEmitterOn() ? MODEL_ON_ON : MODEL_OFF_ON;
|
||||
} else {
|
||||
return this.isLevelEmitterOn() ? MODEL_ON_OFF : MODEL_OFF_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,13 +19,6 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
@@ -33,148 +26,129 @@ import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
|
||||
public abstract class PartSharedItemBus extends PartUpgradeable implements IGridTickable
|
||||
{
|
||||
public abstract class PartSharedItemBus extends PartUpgradeable implements IGridTickable {
|
||||
|
||||
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 9 );
|
||||
private boolean lastRedstone = false;
|
||||
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory(this, 9);
|
||||
private boolean lastRedstone = false;
|
||||
|
||||
public PartSharedItemBus( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
public PartSharedItemBus(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upgradesChanged()
|
||||
{
|
||||
this.updateState();
|
||||
}
|
||||
@Override
|
||||
public void upgradesChanged() {
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final net.minecraft.nbt.NBTTagCompound extra )
|
||||
{
|
||||
super.readFromNBT( extra );
|
||||
this.getConfig().readFromNBT( extra, "config" );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final net.minecraft.nbt.NBTTagCompound extra) {
|
||||
super.readFromNBT(extra);
|
||||
this.getConfig().readFromNBT(extra, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final net.minecraft.nbt.NBTTagCompound extra )
|
||||
{
|
||||
super.writeToNBT( extra );
|
||||
this.getConfig().writeToNBT( extra, "config" );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final net.minecraft.nbt.NBTTagCompound extra) {
|
||||
super.writeToNBT(extra);
|
||||
this.getConfig().writeToNBT(extra, "config");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventoryByName( final String name )
|
||||
{
|
||||
if( name.equals( "config" ) )
|
||||
{
|
||||
return this.getConfig();
|
||||
}
|
||||
@Override
|
||||
public IItemHandler getInventoryByName(final String name) {
|
||||
if (name.equals("config")) {
|
||||
return this.getConfig();
|
||||
}
|
||||
|
||||
return super.getInventoryByName( name );
|
||||
}
|
||||
return super.getInventoryByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged( IBlockAccess w, BlockPos pos, BlockPos neighbor )
|
||||
{
|
||||
this.updateState();
|
||||
if( this.lastRedstone != this.getHost().hasRedstone( this.getSide() ) )
|
||||
{
|
||||
this.lastRedstone = !this.lastRedstone;
|
||||
if( this.lastRedstone && this.getRSMode() == RedstoneMode.SIGNAL_PULSE )
|
||||
{
|
||||
this.doBusWork();
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockAccess w, BlockPos pos, BlockPos neighbor) {
|
||||
this.updateState();
|
||||
if (this.lastRedstone != this.getHost().hasRedstone(this.getSide())) {
|
||||
this.lastRedstone = !this.lastRedstone;
|
||||
if (this.lastRedstone && this.getRSMode() == RedstoneMode.SIGNAL_PULSE) {
|
||||
this.doBusWork();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected InventoryAdaptor getHandler()
|
||||
{
|
||||
final TileEntity self = this.getHost().getTile();
|
||||
final TileEntity target = this.getTileEntity( self, self.getPos().offset( this.getSide().getFacing() ) );
|
||||
protected InventoryAdaptor getHandler() {
|
||||
final TileEntity self = this.getHost().getTile();
|
||||
final TileEntity target = this.getTileEntity(self, self.getPos().offset(this.getSide().getFacing()));
|
||||
|
||||
return InventoryAdaptor.getAdaptor( target, this.getSide().getFacing().getOpposite() );
|
||||
}
|
||||
return InventoryAdaptor.getAdaptor(target, this.getSide().getFacing().getOpposite());
|
||||
}
|
||||
|
||||
private TileEntity getTileEntity( final TileEntity self, final BlockPos pos )
|
||||
{
|
||||
final World w = self.getWorld();
|
||||
private TileEntity getTileEntity(final TileEntity self, final BlockPos pos) {
|
||||
final World w = self.getWorld();
|
||||
|
||||
if( w.getChunkProvider().getLoadedChunk( pos.getX() >> 4, pos.getZ() >> 4 ) != null )
|
||||
{
|
||||
return w.getTileEntity( pos );
|
||||
}
|
||||
if (w.getChunkProvider().getLoadedChunk(pos.getX() >> 4, pos.getZ() >> 4) != null) {
|
||||
return w.getTileEntity(pos);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected int availableSlots()
|
||||
{
|
||||
return Math.min( 1 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 4, this.getConfig().getSlots() );
|
||||
}
|
||||
protected int availableSlots() {
|
||||
return Math.min(1 + this.getInstalledUpgrades(Upgrades.CAPACITY) * 4, this.getConfig().getSlots());
|
||||
}
|
||||
|
||||
protected int calculateItemsToSend()
|
||||
{
|
||||
switch( this.getInstalledUpgrades( Upgrades.SPEED ) )
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
return 1;
|
||||
case 1:
|
||||
return 8;
|
||||
case 2:
|
||||
return 32;
|
||||
case 3:
|
||||
return 64;
|
||||
case 4:
|
||||
return 96;
|
||||
}
|
||||
}
|
||||
protected int calculateItemsToSend() {
|
||||
switch (this.getInstalledUpgrades(Upgrades.SPEED)) {
|
||||
default:
|
||||
case 0:
|
||||
return 1;
|
||||
case 1:
|
||||
return 8;
|
||||
case 2:
|
||||
return 32;
|
||||
case 3:
|
||||
return 64;
|
||||
case 4:
|
||||
return 96;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the bus can actually do something.
|
||||
*
|
||||
* Currently this tests if the chunk for the target is actually loaded.
|
||||
*
|
||||
* @return true, if the the bus should do its work.
|
||||
*/
|
||||
protected boolean canDoBusWork()
|
||||
{
|
||||
final TileEntity self = this.getHost().getTile();
|
||||
final BlockPos selfPos = self.getPos().offset( this.getSide().getFacing() );
|
||||
final int xCoordinate = selfPos.getX();
|
||||
final int zCoordinate = selfPos.getZ();
|
||||
final World world = self.getWorld();
|
||||
/**
|
||||
* Checks if the bus can actually do something.
|
||||
* <p>
|
||||
* Currently this tests if the chunk for the target is actually loaded.
|
||||
*
|
||||
* @return true, if the the bus should do its work.
|
||||
*/
|
||||
protected boolean canDoBusWork() {
|
||||
final TileEntity self = this.getHost().getTile();
|
||||
final BlockPos selfPos = self.getPos().offset(this.getSide().getFacing());
|
||||
final int xCoordinate = selfPos.getX();
|
||||
final int zCoordinate = selfPos.getZ();
|
||||
final World world = self.getWorld();
|
||||
|
||||
return world != null && world.getChunkProvider().getLoadedChunk( xCoordinate >> 4, zCoordinate >> 4 ) != null;
|
||||
}
|
||||
return world != null && world.getChunkProvider().getLoadedChunk(xCoordinate >> 4, zCoordinate >> 4) != null;
|
||||
}
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
try
|
||||
{
|
||||
if( !this.isSleeping() )
|
||||
{
|
||||
this.getProxy().getTick().wakeDevice( this.getProxy().getNode() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getProxy().getTick().sleepDevice( this.getProxy().getNode() );
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
private void updateState() {
|
||||
try {
|
||||
if (!this.isSleeping()) {
|
||||
this.getProxy().getTick().wakeDevice(this.getProxy().getNode());
|
||||
} else {
|
||||
this.getProxy().getTick().sleepDevice(this.getProxy().getNode());
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract TickRateModulation doBusWork();
|
||||
protected abstract TickRateModulation doBusWork();
|
||||
|
||||
AppEngInternalAEInventory getConfig()
|
||||
{
|
||||
return this.config;
|
||||
}
|
||||
AppEngInternalAEInventory getConfig() {
|
||||
return this.config;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,6 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.util.IConfigManager;
|
||||
@@ -32,140 +27,121 @@ import appeng.util.ConfigManager;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public abstract class PartUpgradeable extends PartBasicState implements IAEAppEngInventory, IConfigManagerHost
|
||||
{
|
||||
private final IConfigManager manager;
|
||||
private final UpgradeInventory upgrades;
|
||||
public abstract class PartUpgradeable extends PartBasicState implements IAEAppEngInventory, IConfigManagerHost {
|
||||
private final IConfigManager manager;
|
||||
private final UpgradeInventory upgrades;
|
||||
|
||||
public PartUpgradeable( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
this.upgrades = new StackUpgradeInventory( this.getItemStack(), this, this.getUpgradeSlots() );
|
||||
this.manager = new ConfigManager( this );
|
||||
}
|
||||
public PartUpgradeable(final ItemStack is) {
|
||||
super(is);
|
||||
this.upgrades = new StackUpgradeInventory(this.getItemStack(), this, this.getUpgradeSlots());
|
||||
this.manager = new ConfigManager(this);
|
||||
}
|
||||
|
||||
protected int getUpgradeSlots()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
protected int getUpgradeSlots() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
|
||||
{
|
||||
@Override
|
||||
public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
|
||||
{
|
||||
if( inv == this.upgrades )
|
||||
{
|
||||
this.upgradesChanged();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
|
||||
if (inv == this.upgrades) {
|
||||
this.upgradesChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void upgradesChanged()
|
||||
{
|
||||
public void upgradesChanged() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isSleeping()
|
||||
{
|
||||
if( this.getInstalledUpgrades( Upgrades.REDSTONE ) > 0 )
|
||||
{
|
||||
switch( this.getRSMode() )
|
||||
{
|
||||
case IGNORE:
|
||||
return false;
|
||||
protected boolean isSleeping() {
|
||||
if (this.getInstalledUpgrades(Upgrades.REDSTONE) > 0) {
|
||||
switch (this.getRSMode()) {
|
||||
case IGNORE:
|
||||
return false;
|
||||
|
||||
case HIGH_SIGNAL:
|
||||
if( this.getHost().hasRedstone( this.getSide() ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
case HIGH_SIGNAL:
|
||||
if (this.getHost().hasRedstone(this.getSide())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
case LOW_SIGNAL:
|
||||
if( !this.getHost().hasRedstone( this.getSide() ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
case LOW_SIGNAL:
|
||||
if (!this.getHost().hasRedstone(this.getSide())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
case SIGNAL_PULSE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
case SIGNAL_PULSE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInstalledUpgrades( final Upgrades u )
|
||||
{
|
||||
return this.upgrades.getInstalledUpgrades( u );
|
||||
}
|
||||
@Override
|
||||
public int getInstalledUpgrades(final Upgrades u) {
|
||||
return this.upgrades.getInstalledUpgrades(u);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone()
|
||||
{
|
||||
return this.upgrades.getMaxInstalled( Upgrades.REDSTONE ) > 0;
|
||||
}
|
||||
@Override
|
||||
public boolean canConnectRedstone() {
|
||||
return this.upgrades.getMaxInstalled(Upgrades.REDSTONE) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final net.minecraft.nbt.NBTTagCompound extra )
|
||||
{
|
||||
super.readFromNBT( extra );
|
||||
this.manager.readFromNBT( extra );
|
||||
this.upgrades.readFromNBT( extra, "upgrades" );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final net.minecraft.nbt.NBTTagCompound extra) {
|
||||
super.readFromNBT(extra);
|
||||
this.manager.readFromNBT(extra);
|
||||
this.upgrades.readFromNBT(extra, "upgrades");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final net.minecraft.nbt.NBTTagCompound extra )
|
||||
{
|
||||
super.writeToNBT( extra );
|
||||
this.manager.writeToNBT( extra );
|
||||
this.upgrades.writeToNBT( extra, "upgrades" );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final net.minecraft.nbt.NBTTagCompound extra) {
|
||||
super.writeToNBT(extra);
|
||||
this.manager.writeToNBT(extra);
|
||||
this.upgrades.writeToNBT(extra, "upgrades");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops( final List<ItemStack> drops, final boolean wrenched )
|
||||
{
|
||||
for( final ItemStack is : this.upgrades )
|
||||
{
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
drops.add( is );
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
|
||||
for (final ItemStack is : this.upgrades) {
|
||||
if (!is.isEmpty()) {
|
||||
drops.add(is);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
return this.manager;
|
||||
}
|
||||
@Override
|
||||
public IConfigManager getConfigManager() {
|
||||
return this.manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventoryByName( final String name )
|
||||
{
|
||||
if( name.equals( "upgrades" ) )
|
||||
{
|
||||
return this.upgrades;
|
||||
}
|
||||
@Override
|
||||
public IItemHandler getInventoryByName(final String name) {
|
||||
if (name.equals("upgrades")) {
|
||||
return this.upgrades;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public RedstoneMode getRSMode()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public RedstoneMode getRSMode() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,14 +19,8 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.client.render.cablebus.CubeBuilder;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
@@ -36,87 +30,78 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import appeng.client.render.cablebus.CubeBuilder;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Built-in model for annihilation planes that supports connected textures.
|
||||
*/
|
||||
public class PlaneBakedModel implements IBakedModel
|
||||
{
|
||||
public class PlaneBakedModel implements IBakedModel {
|
||||
|
||||
private final TextureAtlasSprite frontTexture;
|
||||
private final TextureAtlasSprite frontTexture;
|
||||
|
||||
private final List<BakedQuad> quads;
|
||||
private final List<BakedQuad> quads;
|
||||
|
||||
PlaneBakedModel( VertexFormat format, TextureAtlasSprite frontTexture, TextureAtlasSprite sidesTexture, TextureAtlasSprite backTexture, PlaneConnections connections )
|
||||
{
|
||||
this.frontTexture = frontTexture;
|
||||
PlaneBakedModel(VertexFormat format, TextureAtlasSprite frontTexture, TextureAtlasSprite sidesTexture, TextureAtlasSprite backTexture, PlaneConnections connections) {
|
||||
this.frontTexture = frontTexture;
|
||||
|
||||
List<BakedQuad> quads = new ArrayList<>( 4 * 6 );
|
||||
List<BakedQuad> quads = new ArrayList<>(4 * 6);
|
||||
|
||||
CubeBuilder builder = new CubeBuilder( format, quads );
|
||||
CubeBuilder builder = new CubeBuilder(format, quads);
|
||||
|
||||
builder.setTextures( sidesTexture, sidesTexture, frontTexture, backTexture, sidesTexture, sidesTexture );
|
||||
builder.setTextures(sidesTexture, sidesTexture, frontTexture, backTexture, sidesTexture, sidesTexture);
|
||||
|
||||
// Keep the orientation of the X axis in mind here. When looking at a quad facing north from the front,
|
||||
// The X-axis points left
|
||||
int minX = connections.isRight() ? 0 : 1;
|
||||
int maxX = connections.isLeft() ? 16 : 15;
|
||||
int minY = connections.isDown() ? 0 : 1;
|
||||
int maxY = connections.isUp() ? 16 : 15;
|
||||
// Keep the orientation of the X axis in mind here. When looking at a quad facing north from the front,
|
||||
// The X-axis points left
|
||||
int minX = connections.isRight() ? 0 : 1;
|
||||
int maxX = connections.isLeft() ? 16 : 15;
|
||||
int minY = connections.isDown() ? 0 : 1;
|
||||
int maxY = connections.isUp() ? 16 : 15;
|
||||
|
||||
builder.addCube( minX, minY, 0, maxX, maxY, 1 );
|
||||
builder.addCube(minX, minY, 0, maxX, maxY, 1);
|
||||
|
||||
this.quads = ImmutableList.copyOf( quads );
|
||||
}
|
||||
this.quads = ImmutableList.copyOf(quads);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads( @Nullable IBlockState state, @Nullable EnumFacing side, long rand )
|
||||
{
|
||||
if( side == null )
|
||||
{
|
||||
return this.quads;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
|
||||
if (side == null) {
|
||||
return this.quads;
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isAmbientOcclusion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isGui3d() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isBuiltInRenderer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleTexture()
|
||||
{
|
||||
return this.frontTexture;
|
||||
}
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleTexture() {
|
||||
return this.frontTexture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemCameraTransforms getItemCameraTransforms()
|
||||
{
|
||||
return ItemCameraTransforms.DEFAULT;
|
||||
}
|
||||
@Override
|
||||
public ItemCameraTransforms getItemCameraTransforms() {
|
||||
return ItemCameraTransforms.DEFAULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
return ItemOverrideList.NONE;
|
||||
}
|
||||
@Override
|
||||
public ItemOverrideList getOverrides() {
|
||||
return ItemOverrideList.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,122 +19,106 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
|
||||
/**
|
||||
* Models in which directions - looking at the front face - a plane (annihilation, formation, etc.) is connected to
|
||||
* other planes of the same type.
|
||||
*/
|
||||
public final class PlaneConnections
|
||||
{
|
||||
public final class PlaneConnections {
|
||||
|
||||
private final boolean up;
|
||||
private final boolean right;
|
||||
private final boolean down;
|
||||
private final boolean left;
|
||||
private final boolean up;
|
||||
private final boolean right;
|
||||
private final boolean down;
|
||||
private final boolean left;
|
||||
|
||||
private static final int BITMASK_UP = 8;
|
||||
private static final int BITMASK_RIGHT = 4;
|
||||
private static final int BITMASK_DOWN = 2;
|
||||
private static final int BITMASK_LEFT = 1;
|
||||
private static final int BITMASK_UP = 8;
|
||||
private static final int BITMASK_RIGHT = 4;
|
||||
private static final int BITMASK_DOWN = 2;
|
||||
private static final int BITMASK_LEFT = 1;
|
||||
|
||||
public static final List<PlaneConnections> PERMUTATIONS = generatePermutations();
|
||||
public static final List<PlaneConnections> PERMUTATIONS = generatePermutations();
|
||||
|
||||
private static List<PlaneConnections> generatePermutations()
|
||||
{
|
||||
List<PlaneConnections> connections = new ArrayList<>( 16 );
|
||||
private static List<PlaneConnections> generatePermutations() {
|
||||
List<PlaneConnections> connections = new ArrayList<>(16);
|
||||
|
||||
for( int i = 0; i < 16; i++ )
|
||||
{
|
||||
boolean up = ( i & BITMASK_UP ) != 0;
|
||||
boolean right = ( i & BITMASK_RIGHT ) != 0;
|
||||
boolean down = ( i & BITMASK_DOWN ) != 0;
|
||||
boolean left = ( i & BITMASK_LEFT ) != 0;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
boolean up = (i & BITMASK_UP) != 0;
|
||||
boolean right = (i & BITMASK_RIGHT) != 0;
|
||||
boolean down = (i & BITMASK_DOWN) != 0;
|
||||
boolean left = (i & BITMASK_LEFT) != 0;
|
||||
|
||||
connections.add( new PlaneConnections( up, right, down, left ) );
|
||||
}
|
||||
connections.add(new PlaneConnections(up, right, down, left));
|
||||
}
|
||||
|
||||
return connections;
|
||||
}
|
||||
return connections;
|
||||
}
|
||||
|
||||
private PlaneConnections( boolean up, boolean right, boolean down, boolean left )
|
||||
{
|
||||
this.up = up;
|
||||
this.right = right;
|
||||
this.down = down;
|
||||
this.left = left;
|
||||
}
|
||||
private PlaneConnections(boolean up, boolean right, boolean down, boolean left) {
|
||||
this.up = up;
|
||||
this.right = right;
|
||||
this.down = down;
|
||||
this.left = left;
|
||||
}
|
||||
|
||||
public static PlaneConnections of( boolean up, boolean right, boolean down, boolean left )
|
||||
{
|
||||
return PERMUTATIONS.get( getIndex( up, right, down, left ) );
|
||||
}
|
||||
public static PlaneConnections of(boolean up, boolean right, boolean down, boolean left) {
|
||||
return PERMUTATIONS.get(getIndex(up, right, down, left));
|
||||
}
|
||||
|
||||
public boolean isUp()
|
||||
{
|
||||
return this.up;
|
||||
}
|
||||
public boolean isUp() {
|
||||
return this.up;
|
||||
}
|
||||
|
||||
public boolean isRight()
|
||||
{
|
||||
return this.right;
|
||||
}
|
||||
public boolean isRight() {
|
||||
return this.right;
|
||||
}
|
||||
|
||||
public boolean isDown()
|
||||
{
|
||||
return this.down;
|
||||
}
|
||||
public boolean isDown() {
|
||||
return this.down;
|
||||
}
|
||||
|
||||
public boolean isLeft()
|
||||
{
|
||||
return this.left;
|
||||
}
|
||||
public boolean isLeft() {
|
||||
return this.left;
|
||||
}
|
||||
|
||||
// The combination of connections expressed as a number ranging from [0,15]
|
||||
public int getIndex()
|
||||
{
|
||||
return getIndex( this.up, this.right, this.down, this.left );
|
||||
}
|
||||
// The combination of connections expressed as a number ranging from [0,15]
|
||||
public int getIndex() {
|
||||
return getIndex(this.up, this.right, this.down, this.left);
|
||||
}
|
||||
|
||||
private static int getIndex( boolean up, boolean right, boolean down, boolean left )
|
||||
{
|
||||
return ( up ? BITMASK_UP : 0 ) + ( right ? BITMASK_RIGHT : 0 ) + ( left ? BITMASK_LEFT : 0 ) + ( down ? BITMASK_DOWN : 0 );
|
||||
}
|
||||
private static int getIndex(boolean up, boolean right, boolean down, boolean left) {
|
||||
return (up ? BITMASK_UP : 0) + (right ? BITMASK_RIGHT : 0) + (left ? BITMASK_LEFT : 0) + (down ? BITMASK_DOWN : 0);
|
||||
}
|
||||
|
||||
// Returns a suffix that expresses the connection states as a string
|
||||
public String getFilenameSuffix()
|
||||
{
|
||||
String suffix = Integer.toBinaryString( this.getIndex() );
|
||||
return Strings.padStart( suffix, 4, '0' );
|
||||
}
|
||||
// Returns a suffix that expresses the connection states as a string
|
||||
public String getFilenameSuffix() {
|
||||
String suffix = Integer.toBinaryString(this.getIndex());
|
||||
return Strings.padStart(suffix, 4, '0');
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
if( this == o )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if( o == null || this.getClass() != o.getClass() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || this.getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PlaneConnections that = (PlaneConnections) o;
|
||||
return this.up == that.up && this.right == that.right && this.down == that.down && this.left == that.left;
|
||||
}
|
||||
PlaneConnections that = (PlaneConnections) o;
|
||||
return this.up == that.up && this.right == that.right && this.down == that.down && this.left == that.left;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result = ( this.up ? 1 : 0 );
|
||||
result = 31 * result + ( this.right ? 1 : 0 );
|
||||
result = 31 * result + ( this.down ? 1 : 0 );
|
||||
result = 31 * result + ( this.left ? 1 : 0 );
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = (this.up ? 1 : 0);
|
||||
result = 31 * result + (this.right ? 1 : 0);
|
||||
result = 31 * result + (this.down ? 1 : 0);
|
||||
result = 31 * result + (this.left ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,7 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
@@ -33,52 +28,50 @@ import net.minecraftforge.client.model.IModel;
|
||||
import net.minecraftforge.common.model.IModelState;
|
||||
import net.minecraftforge.common.model.TRSRTransformation;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
/**
|
||||
* Built-in model for annihilation planes that supports connected textures.
|
||||
*/
|
||||
public class PlaneModel implements IModel
|
||||
{
|
||||
public class PlaneModel implements IModel {
|
||||
|
||||
private final ResourceLocation frontTexture;
|
||||
private final ResourceLocation sidesTexture;
|
||||
private final ResourceLocation backTexture;
|
||||
private final PlaneConnections connections;
|
||||
private final ResourceLocation frontTexture;
|
||||
private final ResourceLocation sidesTexture;
|
||||
private final ResourceLocation backTexture;
|
||||
private final PlaneConnections connections;
|
||||
|
||||
public PlaneModel( ResourceLocation frontTexture, ResourceLocation sidesTexture, ResourceLocation backTexture, PlaneConnections connections )
|
||||
{
|
||||
this.frontTexture = frontTexture;
|
||||
this.sidesTexture = sidesTexture;
|
||||
this.backTexture = backTexture;
|
||||
this.connections = connections;
|
||||
}
|
||||
public PlaneModel(ResourceLocation frontTexture, ResourceLocation sidesTexture, ResourceLocation backTexture, PlaneConnections connections) {
|
||||
this.frontTexture = frontTexture;
|
||||
this.sidesTexture = sidesTexture;
|
||||
this.backTexture = backTexture;
|
||||
this.connections = connections;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getDependencies()
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@Override
|
||||
public Collection<ResourceLocation> getDependencies() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getTextures()
|
||||
{
|
||||
return Lists.newArrayList( this.frontTexture, this.sidesTexture, this.backTexture );
|
||||
}
|
||||
@Override
|
||||
public Collection<ResourceLocation> getTextures() {
|
||||
return Lists.newArrayList(this.frontTexture, this.sidesTexture, this.backTexture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel bake( IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter )
|
||||
{
|
||||
TextureAtlasSprite frontSprite = bakedTextureGetter.apply( this.frontTexture );
|
||||
TextureAtlasSprite sidesSprite = bakedTextureGetter.apply( this.sidesTexture );
|
||||
TextureAtlasSprite backSprite = bakedTextureGetter.apply( this.backTexture );
|
||||
@Override
|
||||
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
|
||||
TextureAtlasSprite frontSprite = bakedTextureGetter.apply(this.frontTexture);
|
||||
TextureAtlasSprite sidesSprite = bakedTextureGetter.apply(this.sidesTexture);
|
||||
TextureAtlasSprite backSprite = bakedTextureGetter.apply(this.backTexture);
|
||||
|
||||
return new PlaneBakedModel( format, frontSprite, sidesSprite, backSprite, this.connections );
|
||||
}
|
||||
return new PlaneBakedModel(format, frontSprite, sidesSprite, backSprite, this.connections);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IModelState getDefaultState()
|
||||
{
|
||||
return TRSRTransformation.identity();
|
||||
}
|
||||
@Override
|
||||
public IModelState getDefaultState() {
|
||||
return TRSRTransformation.identity();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,80 +19,68 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.parts.PartModel;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.parts.PartModel;
|
||||
|
||||
|
||||
/**
|
||||
* Contains a mapping from a Plane's connections to the models to use for that state.
|
||||
*/
|
||||
public class PlaneModels
|
||||
{
|
||||
public class PlaneModels {
|
||||
|
||||
public static final ResourceLocation MODEL_CHASSIS_OFF = new ResourceLocation( AppEng.MOD_ID, "part/transition_plane_off" );
|
||||
public static final ResourceLocation MODEL_CHASSIS_ON = new ResourceLocation( AppEng.MOD_ID, "part/transition_plane_on" );
|
||||
public static final ResourceLocation MODEL_CHASSIS_HAS_CHANNEL = new ResourceLocation( AppEng.MOD_ID, "part/transition_plane_has_channel" );
|
||||
public static final ResourceLocation MODEL_CHASSIS_OFF = new ResourceLocation(AppEng.MOD_ID, "part/transition_plane_off");
|
||||
public static final ResourceLocation MODEL_CHASSIS_ON = new ResourceLocation(AppEng.MOD_ID, "part/transition_plane_on");
|
||||
public static final ResourceLocation MODEL_CHASSIS_HAS_CHANNEL = new ResourceLocation(AppEng.MOD_ID, "part/transition_plane_has_channel");
|
||||
|
||||
private final Map<PlaneConnections, IPartModel> modelsOff;
|
||||
private final Map<PlaneConnections, IPartModel> modelsOff;
|
||||
|
||||
private final Map<PlaneConnections, IPartModel> modelsOn;
|
||||
private final Map<PlaneConnections, IPartModel> modelsOn;
|
||||
|
||||
private final Map<PlaneConnections, IPartModel> modelsHasChannel;
|
||||
private final Map<PlaneConnections, IPartModel> modelsHasChannel;
|
||||
|
||||
public PlaneModels( String prefixOff, String prefixOn )
|
||||
{
|
||||
Map<PlaneConnections, IPartModel> modelsOff = new HashMap<>();
|
||||
Map<PlaneConnections, IPartModel> modelsOn = new HashMap<>();
|
||||
Map<PlaneConnections, IPartModel> modelsHasChannel = new HashMap<>();
|
||||
public PlaneModels(String prefixOff, String prefixOn) {
|
||||
Map<PlaneConnections, IPartModel> modelsOff = new HashMap<>();
|
||||
Map<PlaneConnections, IPartModel> modelsOn = new HashMap<>();
|
||||
Map<PlaneConnections, IPartModel> modelsHasChannel = new HashMap<>();
|
||||
|
||||
for( PlaneConnections permutation : PlaneConnections.PERMUTATIONS )
|
||||
{
|
||||
ResourceLocation planeOff = new ResourceLocation( AppEng.MOD_ID, prefixOff + permutation.getFilenameSuffix() );
|
||||
ResourceLocation planeOn = new ResourceLocation( AppEng.MOD_ID, prefixOn + permutation.getFilenameSuffix() );
|
||||
for (PlaneConnections permutation : PlaneConnections.PERMUTATIONS) {
|
||||
ResourceLocation planeOff = new ResourceLocation(AppEng.MOD_ID, prefixOff + permutation.getFilenameSuffix());
|
||||
ResourceLocation planeOn = new ResourceLocation(AppEng.MOD_ID, prefixOn + permutation.getFilenameSuffix());
|
||||
|
||||
modelsOff.put( permutation, new PartModel( MODEL_CHASSIS_OFF, planeOff ) );
|
||||
modelsOn.put( permutation, new PartModel( MODEL_CHASSIS_ON, planeOff ) );
|
||||
modelsHasChannel.put( permutation, new PartModel( MODEL_CHASSIS_HAS_CHANNEL, planeOn ) );
|
||||
}
|
||||
modelsOff.put(permutation, new PartModel(MODEL_CHASSIS_OFF, planeOff));
|
||||
modelsOn.put(permutation, new PartModel(MODEL_CHASSIS_ON, planeOff));
|
||||
modelsHasChannel.put(permutation, new PartModel(MODEL_CHASSIS_HAS_CHANNEL, planeOn));
|
||||
}
|
||||
|
||||
this.modelsOff = ImmutableMap.copyOf( modelsOff );
|
||||
this.modelsOn = ImmutableMap.copyOf( modelsOn );
|
||||
this.modelsHasChannel = ImmutableMap.copyOf( modelsHasChannel );
|
||||
}
|
||||
this.modelsOff = ImmutableMap.copyOf(modelsOff);
|
||||
this.modelsOn = ImmutableMap.copyOf(modelsOn);
|
||||
this.modelsHasChannel = ImmutableMap.copyOf(modelsHasChannel);
|
||||
}
|
||||
|
||||
public IPartModel getModel( PlaneConnections connections, boolean hasPower, boolean hasChannel )
|
||||
{
|
||||
if( hasPower && hasChannel )
|
||||
{
|
||||
return this.modelsHasChannel.get( connections );
|
||||
}
|
||||
else if( hasPower )
|
||||
{
|
||||
return this.modelsOn.get( connections );
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.modelsOff.get( connections );
|
||||
}
|
||||
}
|
||||
public IPartModel getModel(PlaneConnections connections, boolean hasPower, boolean hasChannel) {
|
||||
if (hasPower && hasChannel) {
|
||||
return this.modelsHasChannel.get(connections);
|
||||
} else if (hasPower) {
|
||||
return this.modelsOn.get(connections);
|
||||
} else {
|
||||
return this.modelsOff.get(connections);
|
||||
}
|
||||
}
|
||||
|
||||
public List<IPartModel> getModels()
|
||||
{
|
||||
List<IPartModel> result = new ArrayList<>();
|
||||
this.modelsOff.values().forEach( result::add );
|
||||
this.modelsOn.values().forEach( result::add );
|
||||
this.modelsHasChannel.values().forEach( result::add );
|
||||
return result;
|
||||
}
|
||||
public List<IPartModel> getModels() {
|
||||
List<IPartModel> result = new ArrayList<>();
|
||||
this.modelsOff.values().forEach(result::add);
|
||||
this.modelsOn.values().forEach(result::add);
|
||||
this.modelsHasChannel.values().forEach(result::add);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,36 +19,30 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public class StackUpgradeInventory extends UpgradeInventory
|
||||
{
|
||||
private final ItemStack stack;
|
||||
public class StackUpgradeInventory extends UpgradeInventory {
|
||||
private final ItemStack stack;
|
||||
|
||||
public StackUpgradeInventory( final ItemStack stack, final IAEAppEngInventory inventory, final int s )
|
||||
{
|
||||
super( inventory, s );
|
||||
this.stack = stack;
|
||||
}
|
||||
public StackUpgradeInventory(final ItemStack stack, final IAEAppEngInventory inventory, final int s) {
|
||||
super(inventory, s);
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxInstalled( final Upgrades upgrades )
|
||||
{
|
||||
int max = 0;
|
||||
@Override
|
||||
public int getMaxInstalled(final Upgrades upgrades) {
|
||||
int max = 0;
|
||||
|
||||
for( final ItemStack is : upgrades.getSupported().keySet() )
|
||||
{
|
||||
if( ItemStack.areItemsEqual( this.stack, is ) )
|
||||
{
|
||||
max = upgrades.getSupported().get( is );
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (final ItemStack is : upgrades.getSupported().keySet()) {
|
||||
if (ItemStack.areItemsEqual(this.stack, is)) {
|
||||
max = upgrades.getSupported().get(is);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,22 +19,6 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.container.slot.SlotRestrictedInput;
|
||||
import appeng.core.Api;
|
||||
import appeng.helpers.DualityInterface;
|
||||
import appeng.util.inv.ItemHandlerIterator;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.implementations.items.IUpgradeModule;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
@@ -42,177 +26,159 @@ import appeng.util.Platform;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
||||
public abstract class UpgradeInventory extends AppEngInternalInventory implements IAEAppEngInventory
|
||||
{
|
||||
private final IAEAppEngInventory parent;
|
||||
public abstract class UpgradeInventory extends AppEngInternalInventory implements IAEAppEngInventory {
|
||||
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;
|
||||
private int patternExpansionUpgrades = 0;
|
||||
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;
|
||||
private int patternExpansionUpgrades = 0;
|
||||
|
||||
public UpgradeInventory( final IAEAppEngInventory parent, final int s )
|
||||
{
|
||||
super( null, s, 1 );
|
||||
this.setTileEntity( this );
|
||||
this.parent = parent;
|
||||
this.setFilter( new UpgradeInvFilter() );
|
||||
}
|
||||
public UpgradeInventory(final IAEAppEngInventory parent, final int s) {
|
||||
super(null, s, 1);
|
||||
this.setTileEntity(this);
|
||||
this.parent = parent;
|
||||
this.setFilter(new UpgradeInvFilter());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean eventsEnabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
protected boolean eventsEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getInstalledUpgrades( final Upgrades u )
|
||||
{
|
||||
if( !this.cached )
|
||||
{
|
||||
this.updateUpgradeInfo();
|
||||
}
|
||||
public int getInstalledUpgrades(final Upgrades u) {
|
||||
if (!this.cached) {
|
||||
this.updateUpgradeInfo();
|
||||
}
|
||||
|
||||
switch( u )
|
||||
{
|
||||
case CAPACITY:
|
||||
return this.capacityUpgrades;
|
||||
case FUZZY:
|
||||
return this.fuzzyUpgrades;
|
||||
case REDSTONE:
|
||||
return this.redstoneUpgrades;
|
||||
case SPEED:
|
||||
return this.speedUpgrades;
|
||||
case INVERTER:
|
||||
return this.inverterUpgrades;
|
||||
case CRAFTING:
|
||||
return this.craftingUpgrades;
|
||||
case PATTERN_EXPANSION:
|
||||
return this.patternExpansionUpgrades;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
switch (u) {
|
||||
case CAPACITY:
|
||||
return this.capacityUpgrades;
|
||||
case FUZZY:
|
||||
return this.fuzzyUpgrades;
|
||||
case REDSTONE:
|
||||
return this.redstoneUpgrades;
|
||||
case SPEED:
|
||||
return this.speedUpgrades;
|
||||
case INVERTER:
|
||||
return this.inverterUpgrades;
|
||||
case CRAFTING:
|
||||
return this.craftingUpgrades;
|
||||
case PATTERN_EXPANSION:
|
||||
return this.patternExpansionUpgrades;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract int getMaxInstalled( Upgrades upgrades );
|
||||
public abstract int getMaxInstalled(Upgrades upgrades);
|
||||
|
||||
private void updateUpgradeInfo()
|
||||
{
|
||||
this.cached = true;
|
||||
this.patternExpansionUpgrades = this.inverterUpgrades = this.capacityUpgrades = this.redstoneUpgrades = this.speedUpgrades = this.fuzzyUpgrades = this.craftingUpgrades = 0;
|
||||
private void updateUpgradeInfo() {
|
||||
this.cached = true;
|
||||
this.patternExpansionUpgrades = this.inverterUpgrades = this.capacityUpgrades = this.redstoneUpgrades = this.speedUpgrades = this.fuzzyUpgrades = this.craftingUpgrades = 0;
|
||||
|
||||
for( final ItemStack is : this )
|
||||
{
|
||||
if( is == null || is.getItem() == Items.AIR || !( is.getItem() instanceof IUpgradeModule ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (final ItemStack is : this) {
|
||||
if (is == null || is.getItem() == Items.AIR || !(is.getItem() instanceof IUpgradeModule)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final Upgrades myUpgrade = ( (IUpgradeModule) is.getItem() ).getType( is );
|
||||
switch( myUpgrade )
|
||||
{
|
||||
case CAPACITY:
|
||||
this.capacityUpgrades++;
|
||||
break;
|
||||
case FUZZY:
|
||||
this.fuzzyUpgrades++;
|
||||
break;
|
||||
case REDSTONE:
|
||||
this.redstoneUpgrades++;
|
||||
break;
|
||||
case SPEED:
|
||||
this.speedUpgrades++;
|
||||
break;
|
||||
case INVERTER:
|
||||
this.inverterUpgrades++;
|
||||
break;
|
||||
case CRAFTING:
|
||||
this.craftingUpgrades++;
|
||||
break;
|
||||
case PATTERN_EXPANSION:
|
||||
this.patternExpansionUpgrades++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
final Upgrades myUpgrade = ((IUpgradeModule) is.getItem()).getType(is);
|
||||
switch (myUpgrade) {
|
||||
case CAPACITY:
|
||||
this.capacityUpgrades++;
|
||||
break;
|
||||
case FUZZY:
|
||||
this.fuzzyUpgrades++;
|
||||
break;
|
||||
case REDSTONE:
|
||||
this.redstoneUpgrades++;
|
||||
break;
|
||||
case SPEED:
|
||||
this.speedUpgrades++;
|
||||
break;
|
||||
case INVERTER:
|
||||
this.inverterUpgrades++;
|
||||
break;
|
||||
case CRAFTING:
|
||||
this.craftingUpgrades++;
|
||||
break;
|
||||
case PATTERN_EXPANSION:
|
||||
this.patternExpansionUpgrades++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.capacityUpgrades = Math.min( this.capacityUpgrades, this.getMaxInstalled( Upgrades.CAPACITY ) );
|
||||
this.fuzzyUpgrades = Math.min( this.fuzzyUpgrades, this.getMaxInstalled( Upgrades.FUZZY ) );
|
||||
this.redstoneUpgrades = Math.min( this.redstoneUpgrades, this.getMaxInstalled( Upgrades.REDSTONE ) );
|
||||
this.speedUpgrades = Math.min( this.speedUpgrades, this.getMaxInstalled( Upgrades.SPEED ) );
|
||||
this.inverterUpgrades = Math.min( this.inverterUpgrades, this.getMaxInstalled( Upgrades.INVERTER ) );
|
||||
this.craftingUpgrades = Math.min( this.craftingUpgrades, this.getMaxInstalled( Upgrades.CRAFTING ) );
|
||||
this.patternExpansionUpgrades = Math.min( this.patternExpansionUpgrades, this.getMaxInstalled( Upgrades.PATTERN_EXPANSION ) );
|
||||
}
|
||||
this.capacityUpgrades = Math.min(this.capacityUpgrades, this.getMaxInstalled(Upgrades.CAPACITY));
|
||||
this.fuzzyUpgrades = Math.min(this.fuzzyUpgrades, this.getMaxInstalled(Upgrades.FUZZY));
|
||||
this.redstoneUpgrades = Math.min(this.redstoneUpgrades, this.getMaxInstalled(Upgrades.REDSTONE));
|
||||
this.speedUpgrades = Math.min(this.speedUpgrades, this.getMaxInstalled(Upgrades.SPEED));
|
||||
this.inverterUpgrades = Math.min(this.inverterUpgrades, this.getMaxInstalled(Upgrades.INVERTER));
|
||||
this.craftingUpgrades = Math.min(this.craftingUpgrades, this.getMaxInstalled(Upgrades.CRAFTING));
|
||||
this.patternExpansionUpgrades = Math.min(this.patternExpansionUpgrades, this.getMaxInstalled(Upgrades.PATTERN_EXPANSION));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound target )
|
||||
{
|
||||
super.readFromNBT( target );
|
||||
this.updateUpgradeInfo();
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound target) {
|
||||
super.readFromNBT(target);
|
||||
this.updateUpgradeInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveChanges()
|
||||
{
|
||||
if( this.parent != null )
|
||||
{
|
||||
this.parent.saveChanges();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void saveChanges() {
|
||||
if (this.parent != null) {
|
||||
this.parent.saveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
|
||||
{
|
||||
this.cached = false;
|
||||
if( this.parent != null && Platform.isServer() )
|
||||
{
|
||||
this.parent.onChangeInventory( inv, slot, mc, removedStack, newStack );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
|
||||
this.cached = false;
|
||||
if (this.parent != null && Platform.isServer()) {
|
||||
this.parent.onChangeInventory(inv, slot, mc, removedStack, newStack);
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack extractItem( int slot, int amount, boolean simulate )
|
||||
{
|
||||
return super.extractItem( slot, amount, simulate );
|
||||
}
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
return super.extractItem(slot, amount, simulate);
|
||||
}
|
||||
|
||||
private class UpgradeInvFilter implements IAEItemFilter
|
||||
{
|
||||
private class UpgradeInvFilter implements IAEItemFilter {
|
||||
|
||||
@Override
|
||||
public boolean allowExtract( IItemHandler inv, int slot, int amount )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean allowExtract(IItemHandler inv, int slot, int amount) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowInsert( IItemHandler inv, int slot, ItemStack itemstack )
|
||||
{
|
||||
if( itemstack.isEmpty() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
final Item it = itemstack.getItem();
|
||||
if( it instanceof IUpgradeModule )
|
||||
{
|
||||
final Upgrades u = ( (IUpgradeModule) it ).getType( itemstack );
|
||||
if( u != null )
|
||||
{
|
||||
return UpgradeInventory.this.getInstalledUpgrades( u ) < UpgradeInventory.this.getMaxInstalled( u );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean allowInsert(IItemHandler inv, int slot, ItemStack itemstack) {
|
||||
if (itemstack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
final Item it = itemstack.getItem();
|
||||
if (it instanceof IUpgradeModule) {
|
||||
final Upgrades u = ((IUpgradeModule) it).getType(itemstack);
|
||||
if (u != null) {
|
||||
return UpgradeInventory.this.getInstalledUpgrades(u) < UpgradeInventory.this.getMaxInstalled(u);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,312 +51,254 @@ import java.util.*;
|
||||
/**
|
||||
* Wraps an Item Handler in such a way that it can be used as an IMEInventory for items.
|
||||
*/
|
||||
class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAEItemStack>, ITickingMonitor
|
||||
{
|
||||
private final Object2ObjectMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new Object2ObjectOpenHashMap<>();
|
||||
private IActionSource mySource;
|
||||
private final IItemHandler itemHandler;
|
||||
private final IGridProxyable proxyable;
|
||||
private final InventoryCache cache;
|
||||
private StorageFilter mode;
|
||||
private AccessRestriction access;
|
||||
class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAEItemStack>, ITickingMonitor {
|
||||
private final Object2ObjectMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new Object2ObjectOpenHashMap<>();
|
||||
private IActionSource mySource;
|
||||
private final IItemHandler itemHandler;
|
||||
private final IGridProxyable proxyable;
|
||||
private final InventoryCache cache;
|
||||
private StorageFilter mode;
|
||||
private AccessRestriction access;
|
||||
|
||||
ItemHandlerAdapter( IItemHandler itemHandler, IGridProxyable proxy )
|
||||
{
|
||||
this.itemHandler = itemHandler;
|
||||
this.proxyable = proxy;
|
||||
if( this.proxyable instanceof PartStorageBus )
|
||||
{
|
||||
PartStorageBus partStorageBus = (PartStorageBus) this.proxyable;
|
||||
this.mode = ( (StorageFilter) partStorageBus.getConfigManager().getSetting( Settings.STORAGE_FILTER ) );
|
||||
this.access = ( (AccessRestriction) partStorageBus.getConfigManager().getSetting( Settings.ACCESS ) );
|
||||
}
|
||||
this.cache = new InventoryCache( this.itemHandler, this.mode );
|
||||
this.cache.update();
|
||||
}
|
||||
ItemHandlerAdapter(IItemHandler itemHandler, IGridProxyable proxy) {
|
||||
this.itemHandler = itemHandler;
|
||||
this.proxyable = proxy;
|
||||
if (this.proxyable instanceof PartStorageBus) {
|
||||
PartStorageBus partStorageBus = (PartStorageBus) this.proxyable;
|
||||
this.mode = ((StorageFilter) partStorageBus.getConfigManager().getSetting(Settings.STORAGE_FILTER));
|
||||
this.access = ((AccessRestriction) partStorageBus.getConfigManager().getSetting(Settings.ACCESS));
|
||||
}
|
||||
this.cache = new InventoryCache(this.itemHandler, this.mode);
|
||||
this.cache.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems( IAEItemStack iox, Actionable type, IActionSource src )
|
||||
{
|
||||
// Try to reuse the cached stack
|
||||
ItemStack inputStack = iox.getCachedItemStack( iox.getStackSize() );
|
||||
@Override
|
||||
public IAEItemStack injectItems(IAEItemStack iox, Actionable type, IActionSource src) {
|
||||
// Try to reuse the cached stack
|
||||
ItemStack inputStack = iox.getCachedItemStack(iox.getStackSize());
|
||||
|
||||
ItemStack remaining = inputStack;
|
||||
ItemStack remaining = inputStack;
|
||||
|
||||
int slotCount = this.itemHandler.getSlots();
|
||||
for( int i = 0; i < slotCount && !remaining.isEmpty(); i++ )
|
||||
{
|
||||
remaining = this.itemHandler.insertItem( i, remaining, type == Actionable.SIMULATE );
|
||||
}
|
||||
int slotCount = this.itemHandler.getSlots();
|
||||
for (int i = 0; i < slotCount && !remaining.isEmpty(); i++) {
|
||||
remaining = this.itemHandler.insertItem(i, remaining, type == Actionable.SIMULATE);
|
||||
}
|
||||
|
||||
// Store the stack in the cache for next time.
|
||||
if( type == Actionable.SIMULATE )
|
||||
{
|
||||
iox.setCachedItemStack( inputStack );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !remaining.isEmpty() )
|
||||
{
|
||||
iox.setCachedItemStack( remaining );
|
||||
}
|
||||
}
|
||||
// Store the stack in the cache for next time.
|
||||
if (type == Actionable.SIMULATE) {
|
||||
iox.setCachedItemStack(inputStack);
|
||||
} else {
|
||||
if (!remaining.isEmpty()) {
|
||||
iox.setCachedItemStack(remaining);
|
||||
}
|
||||
}
|
||||
|
||||
// At this point, we still have some items left...
|
||||
if( remaining == inputStack )
|
||||
{
|
||||
// The stack remained unmodified, target inventory is full
|
||||
return iox;
|
||||
}
|
||||
// At this point, we still have some items left...
|
||||
if (remaining == inputStack) {
|
||||
// The stack remained unmodified, target inventory is full
|
||||
return iox;
|
||||
}
|
||||
|
||||
if( type == Actionable.MODULATE )
|
||||
{
|
||||
IAEItemStack added = iox.copy().setStackSize( iox.getStackSize() - remaining.getCount() );
|
||||
this.cache.currentlyCached.add( added );
|
||||
this.postDifference( Collections.singletonList( added ) );
|
||||
try
|
||||
{
|
||||
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
|
||||
}
|
||||
catch( GridAccessException ex )
|
||||
{
|
||||
// meh
|
||||
}
|
||||
}
|
||||
if (type == Actionable.MODULATE) {
|
||||
IAEItemStack added = iox.copy().setStackSize(iox.getStackSize() - remaining.getCount());
|
||||
this.cache.currentlyCached.add(added);
|
||||
this.postDifference(Collections.singletonList(added));
|
||||
try {
|
||||
this.proxyable.getProxy().getTick().alertDevice(this.proxyable.getProxy().getNode());
|
||||
} catch (GridAccessException ex) {
|
||||
// meh
|
||||
}
|
||||
}
|
||||
|
||||
return AEItemStack.fromItemStack( remaining );
|
||||
}
|
||||
return AEItemStack.fromItemStack(remaining);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, IActionSource src )
|
||||
{
|
||||
int remainingSize = Ints.saturatedCast( request.getStackSize() );
|
||||
@Override
|
||||
public IAEItemStack extractItems(IAEItemStack request, Actionable mode, IActionSource src) {
|
||||
int remainingSize = Ints.saturatedCast(request.getStackSize());
|
||||
|
||||
// Use this to gather the requested items
|
||||
ItemStack gathered = ItemStack.EMPTY;
|
||||
// Use this to gather the requested items
|
||||
ItemStack gathered = ItemStack.EMPTY;
|
||||
|
||||
final boolean simulate = ( mode == Actionable.SIMULATE );
|
||||
for( int i = 0; i < this.itemHandler.getSlots(); i++ )
|
||||
{
|
||||
ItemStack stackInInventorySlot = this.itemHandler.getStackInSlot( i );
|
||||
final boolean simulate = (mode == Actionable.SIMULATE);
|
||||
for (int i = 0; i < this.itemHandler.getSlots(); i++) {
|
||||
ItemStack stackInInventorySlot = this.itemHandler.getStackInSlot(i);
|
||||
|
||||
if( !request.isSameType( stackInInventorySlot ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!request.isSameType(stackInInventorySlot)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack extracted;
|
||||
ItemStack extracted;
|
||||
|
||||
int stackSizeCurrentSlot = stackInInventorySlot.getCount();
|
||||
int remainingCurrentSlot = Math.min( remainingSize, stackSizeCurrentSlot );
|
||||
int stackSizeCurrentSlot = stackInInventorySlot.getCount();
|
||||
int remainingCurrentSlot = Math.min(remainingSize, stackSizeCurrentSlot);
|
||||
|
||||
// We have to loop here because according to the docs, the handler shouldn't return a stack with size >
|
||||
// maxSize, even if we request more. So even if it returns a valid stack, it might have more stuff.
|
||||
do
|
||||
{
|
||||
extracted = this.itemHandler.extractItem( i, remainingCurrentSlot, simulate );
|
||||
if( !extracted.isEmpty() )
|
||||
{
|
||||
// In order to guard against broken IItemHandler implementations, we'll try to guess if the returned
|
||||
// stack (especially in simulate mode) is the same that was returned by getStackInSlot. This is
|
||||
// obviously not a precise science, but it would catch the previous Forge bug:
|
||||
// https://github.com/MinecraftForge/MinecraftForge/pull/6580
|
||||
if( extracted == stackInInventorySlot )
|
||||
{
|
||||
extracted = extracted.copy();
|
||||
}
|
||||
// We have to loop here because according to the docs, the handler shouldn't return a stack with size >
|
||||
// maxSize, even if we request more. So even if it returns a valid stack, it might have more stuff.
|
||||
do {
|
||||
extracted = this.itemHandler.extractItem(i, remainingCurrentSlot, simulate);
|
||||
if (!extracted.isEmpty()) {
|
||||
// In order to guard against broken IItemHandler implementations, we'll try to guess if the returned
|
||||
// stack (especially in simulate mode) is the same that was returned by getStackInSlot. This is
|
||||
// obviously not a precise science, but it would catch the previous Forge bug:
|
||||
// https://github.com/MinecraftForge/MinecraftForge/pull/6580
|
||||
if (extracted == stackInInventorySlot) {
|
||||
extracted = extracted.copy();
|
||||
}
|
||||
|
||||
if( extracted.getCount() > remainingCurrentSlot )
|
||||
{
|
||||
// Something broke. It should never return more than we requested...
|
||||
// We're going to silently eat the remainder
|
||||
AELog.warn( "Mod that provided item handler %s is broken. Returned %s items while only requesting %d.", this.itemHandler.getClass().getName(), extracted.toString(), remainingCurrentSlot );
|
||||
extracted.setCount( remainingCurrentSlot );
|
||||
}
|
||||
if (extracted.getCount() > remainingCurrentSlot) {
|
||||
// Something broke. It should never return more than we requested...
|
||||
// We're going to silently eat the remainder
|
||||
AELog.warn("Mod that provided item handler %s is broken. Returned %s items while only requesting %d.", this.itemHandler.getClass().getName(), extracted.toString(), remainingCurrentSlot);
|
||||
extracted.setCount(remainingCurrentSlot);
|
||||
}
|
||||
|
||||
// Heuristic for simulation: looping in case of simulations is pointless, since the state of the
|
||||
// underlying inventory does not change after a simulated extraction. To still support inventories
|
||||
// that report stacks that are larger than maxStackSize, we use this heuristic
|
||||
if( simulate && extracted.getCount() == extracted.getMaxStackSize() && remainingCurrentSlot > extracted.getMaxStackSize() )
|
||||
{
|
||||
extracted.setCount( remainingCurrentSlot );
|
||||
}
|
||||
// Heuristic for simulation: looping in case of simulations is pointless, since the state of the
|
||||
// underlying inventory does not change after a simulated extraction. To still support inventories
|
||||
// that report stacks that are larger than maxStackSize, we use this heuristic
|
||||
if (simulate && extracted.getCount() == extracted.getMaxStackSize() && remainingCurrentSlot > extracted.getMaxStackSize()) {
|
||||
extracted.setCount(remainingCurrentSlot);
|
||||
}
|
||||
|
||||
if( gathered.isEmpty() )
|
||||
{
|
||||
gathered = extracted;
|
||||
}
|
||||
else
|
||||
{
|
||||
gathered.grow( extracted.getCount() );
|
||||
}
|
||||
remainingCurrentSlot -= extracted.getCount();
|
||||
}
|
||||
} while ( !simulate && !extracted.isEmpty() && remainingCurrentSlot > 0 );
|
||||
if (gathered.isEmpty()) {
|
||||
gathered = extracted;
|
||||
} else {
|
||||
gathered.grow(extracted.getCount());
|
||||
}
|
||||
remainingCurrentSlot -= extracted.getCount();
|
||||
}
|
||||
} while (!simulate && !extracted.isEmpty() && remainingCurrentSlot > 0);
|
||||
|
||||
remainingSize -= stackSizeCurrentSlot - remainingCurrentSlot;
|
||||
if( remainingSize <= 0 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
remainingSize -= stackSizeCurrentSlot - remainingCurrentSlot;
|
||||
if (remainingSize <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( !gathered.isEmpty() )
|
||||
{
|
||||
IAEItemStack gatheredAEItemStack = AEItemStack.fromItemStack( gathered );
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
IAEItemStack cachedStack = this.cache.currentlyCached.findPrecise( request );
|
||||
if( cachedStack != null )
|
||||
{
|
||||
cachedStack.decStackSize( gatheredAEItemStack.getStackSize() );
|
||||
this.postDifference( Collections.singletonList( gatheredAEItemStack.copy().setStackSize( -gatheredAEItemStack.getStackSize() ) ) );
|
||||
}
|
||||
try
|
||||
{
|
||||
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
|
||||
}
|
||||
catch( GridAccessException ex )
|
||||
{
|
||||
// meh
|
||||
}
|
||||
}
|
||||
if (!gathered.isEmpty()) {
|
||||
IAEItemStack gatheredAEItemStack = AEItemStack.fromItemStack(gathered);
|
||||
if (mode == Actionable.MODULATE) {
|
||||
IAEItemStack cachedStack = this.cache.currentlyCached.findPrecise(request);
|
||||
if (cachedStack != null) {
|
||||
cachedStack.decStackSize(gatheredAEItemStack.getStackSize());
|
||||
this.postDifference(Collections.singletonList(gatheredAEItemStack.copy().setStackSize(-gatheredAEItemStack.getStackSize())));
|
||||
}
|
||||
try {
|
||||
this.proxyable.getProxy().getTick().alertDevice(this.proxyable.getProxy().getNode());
|
||||
} catch (GridAccessException ex) {
|
||||
// meh
|
||||
}
|
||||
}
|
||||
|
||||
return gatheredAEItemStack;
|
||||
}
|
||||
return gatheredAEItemStack;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation onTick()
|
||||
{
|
||||
List<IAEItemStack> changes = this.cache.update();
|
||||
if( !changes.isEmpty() && access.hasPermission( AccessRestriction.READ ) )
|
||||
{
|
||||
this.postDifference( changes );
|
||||
return TickRateModulation.URGENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public TickRateModulation onTick() {
|
||||
List<IAEItemStack> changes = this.cache.update();
|
||||
if (!changes.isEmpty() && access.hasPermission(AccessRestriction.READ)) {
|
||||
this.postDifference(changes);
|
||||
return TickRateModulation.URGENT;
|
||||
} else {
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActionSource( final IActionSource mySource )
|
||||
{
|
||||
this.mySource = mySource;
|
||||
}
|
||||
@Override
|
||||
public void setActionSource(final IActionSource mySource) {
|
||||
this.mySource = mySource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getAvailableItems( IItemList<IAEItemStack> out )
|
||||
{
|
||||
return this.cache.getAvailableItems( out );
|
||||
}
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getAvailableItems(IItemList<IAEItemStack> out) {
|
||||
return this.cache.getAvailableItems(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStorageChannel getChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
|
||||
}
|
||||
@Override
|
||||
public IItemStorageChannel getChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener( final IMEMonitorHandlerReceiver<IAEItemStack> l, final Object verificationToken )
|
||||
{
|
||||
this.listeners.put( l, verificationToken );
|
||||
}
|
||||
@Override
|
||||
public void addListener(final IMEMonitorHandlerReceiver<IAEItemStack> l, final Object verificationToken) {
|
||||
this.listeners.put(l, verificationToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener( final IMEMonitorHandlerReceiver<IAEItemStack> l )
|
||||
{
|
||||
this.listeners.remove( l );
|
||||
}
|
||||
@Override
|
||||
public void removeListener(final IMEMonitorHandlerReceiver<IAEItemStack> l) {
|
||||
this.listeners.remove(l);
|
||||
}
|
||||
|
||||
private void postDifference( Iterable<IAEItemStack> a )
|
||||
{
|
||||
final Iterator<Map.Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object>> i = this.listeners.entrySet().iterator();
|
||||
while ( i.hasNext() )
|
||||
{
|
||||
final Map.Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object> l = i.next();
|
||||
final IMEMonitorHandlerReceiver<IAEItemStack> key = l.getKey();
|
||||
if( key.isValid( l.getValue() ) )
|
||||
{
|
||||
key.postChange( this, a, this.mySource );
|
||||
}
|
||||
else
|
||||
{
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void postDifference(Iterable<IAEItemStack> a) {
|
||||
final Iterator<Map.Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object>> i = this.listeners.entrySet().iterator();
|
||||
while (i.hasNext()) {
|
||||
final Map.Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object> l = i.next();
|
||||
final IMEMonitorHandlerReceiver<IAEItemStack> key = l.getKey();
|
||||
if (key.isValid(l.getValue())) {
|
||||
key.postChange(this, a, this.mySource);
|
||||
} else {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class InventoryCache implements Iterable<ItemSlot>
|
||||
{
|
||||
private final IItemHandler itemHandler;
|
||||
private final StorageFilter mode;
|
||||
IItemList<IAEItemStack> currentlyCached = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
private static class InventoryCache implements Iterable<ItemSlot> {
|
||||
private final IItemHandler itemHandler;
|
||||
private final StorageFilter mode;
|
||||
IItemList<IAEItemStack> currentlyCached = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
|
||||
public InventoryCache( IItemHandler itemHandler, StorageFilter mode )
|
||||
{
|
||||
this.mode = mode;
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
public InventoryCache(IItemHandler itemHandler, StorageFilter mode) {
|
||||
this.mode = mode;
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
|
||||
public IItemList<IAEItemStack> getAvailableItems( IItemList<IAEItemStack> out )
|
||||
{
|
||||
currentlyCached.iterator().forEachRemaining( out::add );
|
||||
return out;
|
||||
}
|
||||
public IItemList<IAEItemStack> getAvailableItems(IItemList<IAEItemStack> out) {
|
||||
currentlyCached.iterator().forEachRemaining(out::add);
|
||||
return out;
|
||||
}
|
||||
|
||||
private StorageFilter getMode()
|
||||
{
|
||||
return this.mode;
|
||||
}
|
||||
private StorageFilter getMode() {
|
||||
return this.mode;
|
||||
}
|
||||
|
||||
public List<IAEItemStack> update()
|
||||
{
|
||||
final List<IAEItemStack> changes = new ArrayList<>();
|
||||
public List<IAEItemStack> update() {
|
||||
final List<IAEItemStack> changes = new ArrayList<>();
|
||||
|
||||
IItemList<IAEItemStack> currentlyOnStorage = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
IItemList<IAEItemStack> currentlyOnStorage = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
|
||||
for( final ItemSlot is : this )
|
||||
{
|
||||
if( this.mode == StorageFilter.EXTRACTABLE_ONLY && !is.isExtractable() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
currentlyOnStorage.add( is.getAEItemStack() );
|
||||
}
|
||||
for (final ItemSlot is : this) {
|
||||
if (this.mode == StorageFilter.EXTRACTABLE_ONLY && !is.isExtractable()) {
|
||||
continue;
|
||||
}
|
||||
currentlyOnStorage.add(is.getAEItemStack());
|
||||
}
|
||||
|
||||
for( final IAEItemStack is : currentlyCached )
|
||||
{
|
||||
is.setStackSize( -is.getStackSize() );
|
||||
}
|
||||
for (final IAEItemStack is : currentlyCached) {
|
||||
is.setStackSize(-is.getStackSize());
|
||||
}
|
||||
|
||||
for( final IAEItemStack is : currentlyOnStorage )
|
||||
{
|
||||
currentlyCached.add( is );
|
||||
}
|
||||
for (final IAEItemStack is : currentlyOnStorage) {
|
||||
currentlyCached.add(is);
|
||||
}
|
||||
|
||||
for( final IAEItemStack is : currentlyCached )
|
||||
{
|
||||
if( is.getStackSize() != 0 )
|
||||
{
|
||||
changes.add( is );
|
||||
}
|
||||
}
|
||||
for (final IAEItemStack is : currentlyCached) {
|
||||
if (is.getStackSize() != 0) {
|
||||
changes.add(is);
|
||||
}
|
||||
}
|
||||
|
||||
currentlyCached = currentlyOnStorage;
|
||||
currentlyCached = currentlyOnStorage;
|
||||
|
||||
return changes;
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new ItemHandlerIterator( this.itemHandler );
|
||||
}
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator() {
|
||||
return new ItemHandlerIterator(this.itemHandler);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package appeng.parts.misc;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
@@ -33,227 +32,184 @@ import java.util.*;
|
||||
* Used by the Storage Bus
|
||||
*/
|
||||
|
||||
class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAEItemStack>, ITickingMonitor
|
||||
{
|
||||
private final Object2ObjectMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new Object2ObjectOpenHashMap<>();
|
||||
private IActionSource mySource;
|
||||
private final IItemRepository itemRepository;
|
||||
private final IGridProxyable proxyable;
|
||||
private final InventoryCache cache;
|
||||
private AccessRestriction access;
|
||||
class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAEItemStack>, ITickingMonitor {
|
||||
private final Object2ObjectMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new Object2ObjectOpenHashMap<>();
|
||||
private IActionSource mySource;
|
||||
private final IItemRepository itemRepository;
|
||||
private final IGridProxyable proxyable;
|
||||
private final InventoryCache cache;
|
||||
private AccessRestriction access;
|
||||
|
||||
ItemRepositoryAdapter( IItemRepository itemRepository, IGridProxyable proxy )
|
||||
{
|
||||
this.itemRepository = itemRepository;
|
||||
this.proxyable = proxy;
|
||||
this.cache = new InventoryCache( this.itemRepository );
|
||||
if( this.proxyable instanceof PartStorageBus )
|
||||
{
|
||||
PartStorageBus partStorageBus = (PartStorageBus) this.proxyable;
|
||||
this.access = ( (AccessRestriction) partStorageBus.getConfigManager().getSetting( Settings.ACCESS ) );
|
||||
}
|
||||
this.cache.update();
|
||||
}
|
||||
ItemRepositoryAdapter(IItemRepository itemRepository, IGridProxyable proxy) {
|
||||
this.itemRepository = itemRepository;
|
||||
this.proxyable = proxy;
|
||||
this.cache = new InventoryCache(this.itemRepository);
|
||||
if (this.proxyable instanceof PartStorageBus) {
|
||||
PartStorageBus partStorageBus = (PartStorageBus) this.proxyable;
|
||||
this.access = ((AccessRestriction) partStorageBus.getConfigManager().getSetting(Settings.ACCESS));
|
||||
}
|
||||
this.cache.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems( IAEItemStack iox, Actionable type, IActionSource src )
|
||||
{
|
||||
// Try to reuse the cached stack
|
||||
ItemStack inputStack = iox.getCachedItemStack( iox.getStackSize() );
|
||||
@Override
|
||||
public IAEItemStack injectItems(IAEItemStack iox, Actionable type, IActionSource src) {
|
||||
// Try to reuse the cached stack
|
||||
ItemStack inputStack = iox.getCachedItemStack(iox.getStackSize());
|
||||
|
||||
ItemStack remaining;
|
||||
ItemStack remaining;
|
||||
|
||||
remaining = this.itemRepository.insertItem( inputStack, type == Actionable.SIMULATE );
|
||||
remaining = this.itemRepository.insertItem(inputStack, type == Actionable.SIMULATE);
|
||||
|
||||
// Store the stack in the cache for next time.
|
||||
if( type == Actionable.SIMULATE )
|
||||
{
|
||||
iox.setCachedItemStack( inputStack );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !remaining.isEmpty() )
|
||||
{
|
||||
iox.setCachedItemStack( remaining );
|
||||
}
|
||||
}
|
||||
// Store the stack in the cache for next time.
|
||||
if (type == Actionable.SIMULATE) {
|
||||
iox.setCachedItemStack(inputStack);
|
||||
} else {
|
||||
if (!remaining.isEmpty()) {
|
||||
iox.setCachedItemStack(remaining);
|
||||
}
|
||||
}
|
||||
|
||||
// At this point, we still have some items left...
|
||||
if( remaining == inputStack )
|
||||
{
|
||||
// The stack remained unmodified, target inventory is full
|
||||
return iox;
|
||||
}
|
||||
// At this point, we still have some items left...
|
||||
if (remaining == inputStack) {
|
||||
// The stack remained unmodified, target inventory is full
|
||||
return iox;
|
||||
}
|
||||
|
||||
if( type == Actionable.MODULATE )
|
||||
{
|
||||
IAEItemStack added = iox.copy().setStackSize( iox.getStackSize() - remaining.getCount() );
|
||||
this.cache.currentlyCached.add( added );
|
||||
this.postDifference( Collections.singletonList( added ) );
|
||||
try
|
||||
{
|
||||
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
|
||||
}
|
||||
catch( GridAccessException ex )
|
||||
{
|
||||
// meh
|
||||
}
|
||||
}
|
||||
if (type == Actionable.MODULATE) {
|
||||
IAEItemStack added = iox.copy().setStackSize(iox.getStackSize() - remaining.getCount());
|
||||
this.cache.currentlyCached.add(added);
|
||||
this.postDifference(Collections.singletonList(added));
|
||||
try {
|
||||
this.proxyable.getProxy().getTick().alertDevice(this.proxyable.getProxy().getNode());
|
||||
} catch (GridAccessException ex) {
|
||||
// meh
|
||||
}
|
||||
}
|
||||
|
||||
return AEItemStack.fromItemStack( remaining );
|
||||
return AEItemStack.fromItemStack(remaining);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, IActionSource src )
|
||||
{
|
||||
int remainingSize = Ints.saturatedCast( request.getStackSize() );
|
||||
@Override
|
||||
public IAEItemStack extractItems(IAEItemStack request, Actionable mode, IActionSource src) {
|
||||
int remainingSize = Ints.saturatedCast(request.getStackSize());
|
||||
|
||||
final boolean simulate = ( mode == Actionable.SIMULATE );
|
||||
final boolean simulate = (mode == Actionable.SIMULATE);
|
||||
|
||||
ItemStack extracted = this.itemRepository.extractItem( request.getDefinition(), remainingSize, simulate );
|
||||
ItemStack extracted = this.itemRepository.extractItem(request.getDefinition(), remainingSize, simulate);
|
||||
|
||||
if( extracted.getCount() > remainingSize )
|
||||
{
|
||||
// Something broke. It should never return more than we requested...
|
||||
// We're going to silently eat the remainder
|
||||
AELog.warn( "Mod that provided item handler %s is broken. Returned %s items while only requesting %d.", this.itemRepository.getClass().getName(), extracted.toString(), remainingSize );
|
||||
extracted.setCount( remainingSize );
|
||||
}
|
||||
if (extracted.getCount() > remainingSize) {
|
||||
// Something broke. It should never return more than we requested...
|
||||
// We're going to silently eat the remainder
|
||||
AELog.warn("Mod that provided item handler %s is broken. Returned %s items while only requesting %d.", this.itemRepository.getClass().getName(), extracted.toString(), remainingSize);
|
||||
extracted.setCount(remainingSize);
|
||||
}
|
||||
|
||||
if( !extracted.isEmpty() )
|
||||
{
|
||||
IAEItemStack extractedAEItemStack = AEItemStack.fromItemStack( extracted );
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
IAEItemStack cachedStack = this.cache.currentlyCached.findPrecise( request );
|
||||
if( cachedStack != null )
|
||||
{
|
||||
cachedStack.decStackSize( extractedAEItemStack.getStackSize() );
|
||||
this.postDifference( Collections.singletonList( extractedAEItemStack.copy().setStackSize( -extractedAEItemStack.getStackSize() ) ) );
|
||||
}
|
||||
try
|
||||
{
|
||||
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
|
||||
}
|
||||
catch( GridAccessException ex )
|
||||
{
|
||||
// meh
|
||||
}
|
||||
}
|
||||
return extractedAEItemStack;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (!extracted.isEmpty()) {
|
||||
IAEItemStack extractedAEItemStack = AEItemStack.fromItemStack(extracted);
|
||||
if (mode == Actionable.MODULATE) {
|
||||
IAEItemStack cachedStack = this.cache.currentlyCached.findPrecise(request);
|
||||
if (cachedStack != null) {
|
||||
cachedStack.decStackSize(extractedAEItemStack.getStackSize());
|
||||
this.postDifference(Collections.singletonList(extractedAEItemStack.copy().setStackSize(-extractedAEItemStack.getStackSize())));
|
||||
}
|
||||
try {
|
||||
this.proxyable.getProxy().getTick().alertDevice(this.proxyable.getProxy().getNode());
|
||||
} catch (GridAccessException ex) {
|
||||
// meh
|
||||
}
|
||||
}
|
||||
return extractedAEItemStack;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getAvailableItems( IItemList<IAEItemStack> out )
|
||||
{
|
||||
return this.cache.getAvailableItems( out );
|
||||
}
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getAvailableItems(IItemList<IAEItemStack> out) {
|
||||
return this.cache.getAvailableItems(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
|
||||
}
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener( IMEMonitorHandlerReceiver<IAEItemStack> l, Object verificationToken )
|
||||
{
|
||||
this.listeners.put( l, verificationToken );
|
||||
}
|
||||
@Override
|
||||
public void addListener(IMEMonitorHandlerReceiver<IAEItemStack> l, Object verificationToken) {
|
||||
this.listeners.put(l, verificationToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener( IMEMonitorHandlerReceiver<IAEItemStack> l )
|
||||
{
|
||||
this.listeners.remove( l );
|
||||
}
|
||||
@Override
|
||||
public void removeListener(IMEMonitorHandlerReceiver<IAEItemStack> l) {
|
||||
this.listeners.remove(l);
|
||||
}
|
||||
|
||||
private void postDifference( Iterable<IAEItemStack> a )
|
||||
{
|
||||
final Iterator<Map.Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object>> i = this.listeners.entrySet().iterator();
|
||||
while ( i.hasNext() )
|
||||
{
|
||||
final Map.Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object> l = i.next();
|
||||
final IMEMonitorHandlerReceiver<IAEItemStack> key = l.getKey();
|
||||
if( key.isValid( l.getValue() ) )
|
||||
{
|
||||
key.postChange( this, a, this.mySource );
|
||||
}
|
||||
else
|
||||
{
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void postDifference(Iterable<IAEItemStack> a) {
|
||||
final Iterator<Map.Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object>> i = this.listeners.entrySet().iterator();
|
||||
while (i.hasNext()) {
|
||||
final Map.Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object> l = i.next();
|
||||
final IMEMonitorHandlerReceiver<IAEItemStack> key = l.getKey();
|
||||
if (key.isValid(l.getValue())) {
|
||||
key.postChange(this, a, this.mySource);
|
||||
} else {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation onTick()
|
||||
{
|
||||
List<IAEItemStack> changes = this.cache.update();
|
||||
if( !changes.isEmpty() && access.hasPermission( AccessRestriction.READ ) )
|
||||
{
|
||||
this.postDifference( changes );
|
||||
return TickRateModulation.URGENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public TickRateModulation onTick() {
|
||||
List<IAEItemStack> changes = this.cache.update();
|
||||
if (!changes.isEmpty() && access.hasPermission(AccessRestriction.READ)) {
|
||||
this.postDifference(changes);
|
||||
return TickRateModulation.URGENT;
|
||||
} else {
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActionSource( final IActionSource mySource )
|
||||
{
|
||||
this.mySource = mySource;
|
||||
}
|
||||
@Override
|
||||
public void setActionSource(final IActionSource mySource) {
|
||||
this.mySource = mySource;
|
||||
}
|
||||
|
||||
private static class InventoryCache
|
||||
{
|
||||
private IItemList<IAEItemStack> currentlyCached = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
private final IItemRepository iItemRepository;
|
||||
private static class InventoryCache {
|
||||
private IItemList<IAEItemStack> currentlyCached = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
private final IItemRepository iItemRepository;
|
||||
|
||||
public InventoryCache( IItemRepository iItemRepository )
|
||||
{
|
||||
this.iItemRepository = iItemRepository;
|
||||
}
|
||||
public InventoryCache(IItemRepository iItemRepository) {
|
||||
this.iItemRepository = iItemRepository;
|
||||
}
|
||||
|
||||
public IItemList<IAEItemStack> getAvailableItems( IItemList<IAEItemStack> out )
|
||||
{
|
||||
currentlyCached.iterator().forEachRemaining( out::add );
|
||||
return out;
|
||||
}
|
||||
public IItemList<IAEItemStack> getAvailableItems(IItemList<IAEItemStack> out) {
|
||||
currentlyCached.iterator().forEachRemaining(out::add);
|
||||
return out;
|
||||
}
|
||||
|
||||
public List<IAEItemStack> update()
|
||||
{
|
||||
final List<IAEItemStack> changes = new ArrayList<>();
|
||||
public List<IAEItemStack> update() {
|
||||
final List<IAEItemStack> changes = new ArrayList<>();
|
||||
|
||||
IItemList<IAEItemStack> currentlyOnStorage = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
this.iItemRepository.getAllItems().stream().map( s -> AEItemStack.fromItemStack( s.itemPrototype ).setStackSize( s.count ) ).forEach( currentlyOnStorage::add );
|
||||
IItemList<IAEItemStack> currentlyOnStorage = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
this.iItemRepository.getAllItems().stream().map(s -> AEItemStack.fromItemStack(s.itemPrototype).setStackSize(s.count)).forEach(currentlyOnStorage::add);
|
||||
|
||||
for( final IAEItemStack is : currentlyCached )
|
||||
{
|
||||
is.setStackSize( -is.getStackSize() );
|
||||
}
|
||||
for (final IAEItemStack is : currentlyCached) {
|
||||
is.setStackSize(-is.getStackSize());
|
||||
}
|
||||
|
||||
for( final IAEItemStack is : currentlyOnStorage )
|
||||
{
|
||||
currentlyCached.add( is );
|
||||
}
|
||||
for (final IAEItemStack is : currentlyOnStorage) {
|
||||
currentlyCached.add(is);
|
||||
}
|
||||
|
||||
for( final IAEItemStack is : currentlyCached )
|
||||
{
|
||||
if( is.getStackSize() != 0 )
|
||||
{
|
||||
changes.add( is );
|
||||
}
|
||||
}
|
||||
for (final IAEItemStack is : currentlyCached) {
|
||||
if (is.getStackSize() != 0) {
|
||||
changes.add(is);
|
||||
}
|
||||
}
|
||||
|
||||
currentlyCached = currentlyOnStorage;
|
||||
currentlyCached = currentlyOnStorage;
|
||||
|
||||
return changes;
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,14 @@
|
||||
package appeng.parts.misc;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.parts.*;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.parts.PartModel;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -38,219 +40,174 @@ import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
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.IPartModel;
|
||||
import appeng.api.parts.PartItemStack;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.parts.PartModel;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class PartCableAnchor implements IPart
|
||||
{
|
||||
public class PartCableAnchor implements IPart {
|
||||
|
||||
@PartModels
|
||||
public static final PartModel DEFAULT_MODELS = new PartModel( false, new ResourceLocation( AppEng.MOD_ID, "part/cable_anchor" ) );
|
||||
@PartModels
|
||||
public static final PartModel DEFAULT_MODELS = new PartModel(false, new ResourceLocation(AppEng.MOD_ID, "part/cable_anchor"));
|
||||
|
||||
@PartModels
|
||||
public static final PartModel FACADE_MODELS = new PartModel( false, new ResourceLocation( AppEng.MOD_ID, "part/cable_anchor_short" ) );
|
||||
@PartModels
|
||||
public static final PartModel FACADE_MODELS = new PartModel(false, new ResourceLocation(AppEng.MOD_ID, "part/cable_anchor_short"));
|
||||
|
||||
private ItemStack is = ItemStack.EMPTY;
|
||||
private IPartHost host = null;
|
||||
private AEPartLocation mySide = AEPartLocation.UP;
|
||||
private ItemStack is = ItemStack.EMPTY;
|
||||
private IPartHost host = null;
|
||||
private AEPartLocation mySide = AEPartLocation.UP;
|
||||
|
||||
public PartCableAnchor( final ItemStack is )
|
||||
{
|
||||
this.is = is;
|
||||
}
|
||||
public PartCableAnchor(final ItemStack is) {
|
||||
this.is = is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
if( this.host != null && this.host.getFacadeContainer().getFacade( this.mySide ) != null )
|
||||
{
|
||||
bch.addBox( 7, 7, 10, 9, 9, 14 );
|
||||
}
|
||||
else
|
||||
{
|
||||
bch.addBox( 7, 7, 10, 9, 9, 16 );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
if (this.host != null && this.host.getFacadeContainer().getFacade(this.mySide) != null) {
|
||||
bch.addBox(7, 7, 10, 9, 9, 14);
|
||||
} else {
|
||||
bch.addBox(7, 7, 10, 9, 9, 16);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack( final PartItemStack wrenched )
|
||||
{
|
||||
return this.is;
|
||||
}
|
||||
@Override
|
||||
public ItemStack getItemStack(final PartItemStack wrenched) {
|
||||
return this.is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requireDynamicRender()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean requireDynamicRender() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isSolid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean canConnectRedstone() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound data )
|
||||
{
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound data) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound data )
|
||||
{
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound data) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightLevel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int getLightLevel() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLadder( final EntityLivingBase entity )
|
||||
{
|
||||
return this.mySide.yOffset == 0 && ( entity.collidedHorizontally || !entity.onGround );
|
||||
}
|
||||
@Override
|
||||
public boolean isLadder(final EntityLivingBase entity) {
|
||||
return this.mySide.yOffset == 0 && (entity.collidedHorizontally || !entity.onGround);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged( IBlockAccess w, BlockPos pos, BlockPos neighbor )
|
||||
{
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockAccess w, BlockPos pos, BlockPos neighbor) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int isProvidingStrongPower() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int isProvidingWeakPower() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream( final ByteBuf data ) throws IOException
|
||||
{
|
||||
@Override
|
||||
public void writeToStream(final ByteBuf data) throws IOException {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream( final ByteBuf data ) throws IOException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean readFromStream(final ByteBuf data) throws IOException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode getGridNode()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public IGridNode getGridNode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityCollision( final Entity entity )
|
||||
{
|
||||
@Override
|
||||
public void onEntityCollision(final Entity entity) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFromWorld()
|
||||
{
|
||||
@Override
|
||||
public void removeFromWorld() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToWorld()
|
||||
{
|
||||
@Override
|
||||
public void addToWorld() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode getExternalFacingNode()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public IGridNode getExternalFacingNode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPartHostInfo( final AEPartLocation side, final IPartHost host, final TileEntity tile )
|
||||
{
|
||||
this.host = host;
|
||||
this.mySide = side;
|
||||
}
|
||||
@Override
|
||||
public void setPartHostInfo(final AEPartLocation side, final IPartHost host, final TileEntity tile) {
|
||||
this.host = host;
|
||||
this.mySide = side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean onActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onShiftActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean onShiftActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops( final List<ItemStack> drops, final boolean wrenched )
|
||||
{
|
||||
@Override
|
||||
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomDisplayTick( final World world, final BlockPos pos, final Random r )
|
||||
{
|
||||
@Override
|
||||
public void randomDisplayTick(final World world, final BlockPos pos, final Random r) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlacement( final EntityPlayer player, final EnumHand hand, final ItemStack held, final AEPartLocation side )
|
||||
{
|
||||
@Override
|
||||
public void onPlacement(final EntityPlayer player, final EnumHand hand, final ItemStack held, final AEPartLocation side) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBePlacedOn( final BusSupport what )
|
||||
{
|
||||
return what == BusSupport.CABLE || what == BusSupport.DENSE_CABLE;
|
||||
}
|
||||
@Override
|
||||
public boolean canBePlacedOn(final BusSupport what) {
|
||||
return what == BusSupport.CABLE || what == BusSupport.DENSE_CABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
if( this.host != null && this.host.getFacadeContainer().getFacade( this.mySide ) != null )
|
||||
{
|
||||
return FACADE_MODELS;
|
||||
}
|
||||
else
|
||||
{
|
||||
return DEFAULT_MODELS;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
if (this.host != null && this.host.getFacadeContainer().getFacade(this.mySide) != null) {
|
||||
return FACADE_MODELS;
|
||||
} else {
|
||||
return DEFAULT_MODELS;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,23 +19,6 @@
|
||||
package appeng.parts.misc;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.Upgrades;
|
||||
@@ -71,252 +54,225 @@ import appeng.util.Platform;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.IInventoryDestination;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class PartInterface extends PartBasicState implements IGridTickable, IStorageMonitorable, IInventoryDestination, IInterfaceHost, IAEAppEngInventory, IPriorityHost
|
||||
{
|
||||
public class PartInterface extends PartBasicState implements IGridTickable, IStorageMonitorable, IInventoryDestination, IInterfaceHost, IAEAppEngInventory, IPriorityHost {
|
||||
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/interface_base" );
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID, "part/interface_base");
|
||||
|
||||
@PartModels
|
||||
public static final PartModel MODELS_OFF = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/interface_off" ) );
|
||||
@PartModels
|
||||
public static final PartModel MODELS_OFF = new PartModel(MODEL_BASE, new ResourceLocation(AppEng.MOD_ID, "part/interface_off"));
|
||||
|
||||
@PartModels
|
||||
public static final PartModel MODELS_ON = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/interface_on" ) );
|
||||
@PartModels
|
||||
public static final PartModel MODELS_ON = new PartModel(MODEL_BASE, new ResourceLocation(AppEng.MOD_ID, "part/interface_on"));
|
||||
|
||||
@PartModels
|
||||
public static final PartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/interface_has_channel" ) );
|
||||
@PartModels
|
||||
public static final PartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, new ResourceLocation(AppEng.MOD_ID, "part/interface_has_channel"));
|
||||
|
||||
private final DualityInterface duality = new DualityInterface( this.getProxy(), this );
|
||||
private final DualityInterface duality = new DualityInterface(this.getProxy(), this);
|
||||
|
||||
@Reflected
|
||||
public PartInterface( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
@Reflected
|
||||
public PartInterface(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void chanRender( final MENetworkChannelsChanged c )
|
||||
{
|
||||
this.duality.notifyNeighbors();
|
||||
}
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void chanRender(final MENetworkChannelsChanged c) {
|
||||
this.duality.notifyNeighbors();
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.duality.notifyNeighbors();
|
||||
}
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(final MENetworkPowerStatusChange c) {
|
||||
this.duality.notifyNeighbors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
bch.addBox( 2, 2, 14, 14, 14, 16 );
|
||||
bch.addBox( 5, 5, 12, 11, 11, 14 );
|
||||
}
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(2, 2, 14, 14, 14, 16);
|
||||
bch.addBox(5, 5, 12, 11, 11, 14);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInstalledUpgrades( final Upgrades u )
|
||||
{
|
||||
return this.duality.getInstalledUpgrades( u );
|
||||
}
|
||||
@Override
|
||||
public int getInstalledUpgrades(final Upgrades u) {
|
||||
return this.duality.getInstalledUpgrades(u);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gridChanged()
|
||||
{
|
||||
this.duality.gridChanged();
|
||||
}
|
||||
@Override
|
||||
public void gridChanged() {
|
||||
this.duality.gridChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.duality.readFromNBT( data );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
this.duality.readFromNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
this.duality.writeToNBT( data );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
this.duality.writeToNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToWorld()
|
||||
{
|
||||
super.addToWorld();
|
||||
this.duality.initialize();
|
||||
}
|
||||
@Override
|
||||
public void addToWorld() {
|
||||
super.addToWorld();
|
||||
this.duality.initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops( final List<ItemStack> drops, final boolean wrenched )
|
||||
{
|
||||
this.duality.addDrops( drops );
|
||||
}
|
||||
@Override
|
||||
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
|
||||
this.duality.addDrops(drops);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
return this.duality.getConfigManager();
|
||||
}
|
||||
@Override
|
||||
public IConfigManager getConfigManager() {
|
||||
return this.duality.getConfigManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventoryByName( final String name )
|
||||
{
|
||||
return this.duality.getInventoryByName( name );
|
||||
}
|
||||
@Override
|
||||
public IItemHandler getInventoryByName(final String name) {
|
||||
return this.duality.getInventoryByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final EntityPlayer p, final EnumHand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
Platform.openGUI( p, this.getTileEntity(), this.getSide(), GuiBridge.GUI_INTERFACE );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final EntityPlayer p, final EnumHand hand, final Vec3d pos) {
|
||||
if (Platform.isServer()) {
|
||||
Platform.openGUI(p, this.getTileEntity(), this.getSide(), GuiBridge.GUI_INTERFACE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert( final ItemStack stack )
|
||||
{
|
||||
return this.duality.canInsert( stack );
|
||||
}
|
||||
@Override
|
||||
public boolean canInsert(final ItemStack stack) {
|
||||
return this.duality.canInsert(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends IAEStack<T>> IMEMonitor<T> getInventory( IStorageChannel<T> channel )
|
||||
{
|
||||
return this.duality.getInventory( channel );
|
||||
}
|
||||
@Override
|
||||
public <T extends IAEStack<T>> IMEMonitor<T> getInventory(IStorageChannel<T> channel) {
|
||||
return this.duality.getInventory(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest( final IGridNode node )
|
||||
{
|
||||
return this.duality.getTickingRequest( node );
|
||||
}
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(final IGridNode node) {
|
||||
return this.duality.getTickingRequest(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
|
||||
{
|
||||
return this.duality.tickingRequest( node, ticksSinceLastCall );
|
||||
}
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
|
||||
return this.duality.tickingRequest(node, ticksSinceLastCall);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
|
||||
{
|
||||
this.duality.onChangeInventory( inv, slot, mc, removedStack, newStack );
|
||||
}
|
||||
@Override
|
||||
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
|
||||
this.duality.onChangeInventory(inv, slot, mc, removedStack, newStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DualityInterface getInterfaceDuality()
|
||||
{
|
||||
return this.duality;
|
||||
}
|
||||
@Override
|
||||
public DualityInterface getInterfaceDuality() {
|
||||
return this.duality;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<EnumFacing> getTargets()
|
||||
{
|
||||
return EnumSet.of( this.getSide().getFacing() );
|
||||
}
|
||||
@Override
|
||||
public EnumSet<EnumFacing> getTargets() {
|
||||
return EnumSet.of(this.getSide().getFacing());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getTileEntity()
|
||||
{
|
||||
return super.getHost().getTile();
|
||||
}
|
||||
@Override
|
||||
public TileEntity getTileEntity() {
|
||||
return super.getHost().getTile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pushPattern( final ICraftingPatternDetails patternDetails, final InventoryCrafting table )
|
||||
{
|
||||
return this.duality.pushPattern( patternDetails, table );
|
||||
}
|
||||
@Override
|
||||
public boolean pushPattern(final ICraftingPatternDetails patternDetails, final InventoryCrafting table) {
|
||||
return this.duality.pushPattern(patternDetails, table);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBusy()
|
||||
{
|
||||
return this.duality.isBusy();
|
||||
}
|
||||
@Override
|
||||
public boolean isBusy() {
|
||||
return this.duality.isBusy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void provideCrafting( final ICraftingProviderHelper craftingTracker )
|
||||
{
|
||||
this.duality.provideCrafting( craftingTracker );
|
||||
}
|
||||
@Override
|
||||
public void provideCrafting(final ICraftingProviderHelper craftingTracker) {
|
||||
this.duality.provideCrafting(craftingTracker);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableSet<ICraftingLink> getRequestedJobs()
|
||||
{
|
||||
return this.duality.getRequestedJobs();
|
||||
}
|
||||
@Override
|
||||
public ImmutableSet<ICraftingLink> getRequestedJobs() {
|
||||
return this.duality.getRequestedJobs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectCraftedItems( final ICraftingLink link, final IAEItemStack items, final Actionable mode )
|
||||
{
|
||||
return this.duality.injectCraftedItems( link, items, mode );
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack injectCraftedItems(final ICraftingLink link, final IAEItemStack items, final Actionable mode) {
|
||||
return this.duality.injectCraftedItems(link, items, mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jobStateChange( final ICraftingLink link )
|
||||
{
|
||||
this.duality.jobStateChange( link );
|
||||
}
|
||||
@Override
|
||||
public void jobStateChange(final ICraftingLink link) {
|
||||
this.duality.jobStateChange(link);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority()
|
||||
{
|
||||
return this.duality.getPriority();
|
||||
}
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return this.duality.getPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPriority( final int newValue )
|
||||
{
|
||||
this.duality.setPriority( newValue );
|
||||
}
|
||||
@Override
|
||||
public void setPriority(final int newValue) {
|
||||
this.duality.setPriority(newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
if( this.isActive() && this.isPowered() )
|
||||
{
|
||||
return MODELS_HAS_CHANNEL;
|
||||
}
|
||||
else if( this.isPowered() )
|
||||
{
|
||||
return MODELS_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
if (this.isActive() && this.isPowered()) {
|
||||
return MODELS_HAS_CHANNEL;
|
||||
} else if (this.isPowered()) {
|
||||
return MODELS_ON;
|
||||
} else {
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability( Capability<?> capabilityClass )
|
||||
{
|
||||
return this.duality.hasCapability( capabilityClass, this.getSide().getFacing() );
|
||||
}
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capabilityClass) {
|
||||
return this.duality.hasCapability(capabilityClass, this.getSide().getFacing());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getCapability( Capability<T> capabilityClass )
|
||||
{
|
||||
return this.duality.getCapability( capabilityClass, this.getSide().getFacing() );
|
||||
}
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capabilityClass) {
|
||||
return this.duality.getCapability(capabilityClass, this.getSide().getFacing());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStackRepresentation()
|
||||
{
|
||||
return AEApi.instance().definitions().parts().iface().maybeStack( 1 ).orElse( ItemStack.EMPTY );
|
||||
}
|
||||
@Override
|
||||
public ItemStack getItemStackRepresentation() {
|
||||
return AEApi.instance().definitions().parts().iface().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiBridge getGuiBridge()
|
||||
{
|
||||
return GuiBridge.GUI_INTERFACE;
|
||||
}
|
||||
@Override
|
||||
public GuiBridge getGuiBridge() {
|
||||
return GuiBridge.GUI_INTERFACE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,56 +19,46 @@
|
||||
package appeng.parts.misc;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.parts.PartModel;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
|
||||
public class PartInvertedToggleBus extends PartToggleBus
|
||||
{
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/inverted_toggle_bus_base" );
|
||||
public class PartInvertedToggleBus extends PartToggleBus {
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID, "part/inverted_toggle_bus_base");
|
||||
|
||||
public static final PartModel MODELS_OFF = new PartModel( MODEL_BASE, MODEL_STATUS_OFF );
|
||||
public static final PartModel MODELS_ON = new PartModel( MODEL_BASE, MODEL_STATUS_ON );
|
||||
public static final PartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, MODEL_STATUS_HAS_CHANNEL );
|
||||
public static final PartModel MODELS_OFF = new PartModel(MODEL_BASE, MODEL_STATUS_OFF);
|
||||
public static final PartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_STATUS_ON);
|
||||
public static final PartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, MODEL_STATUS_HAS_CHANNEL);
|
||||
|
||||
@Reflected
|
||||
public PartInvertedToggleBus( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
this.getProxy().setIdlePowerUsage( 0.0 );
|
||||
this.getOuterProxy().setIdlePowerUsage( 0.0 );
|
||||
this.getProxy().setFlags();
|
||||
this.getOuterProxy().setFlags();
|
||||
}
|
||||
@Reflected
|
||||
public PartInvertedToggleBus(final ItemStack is) {
|
||||
super(is);
|
||||
this.getProxy().setIdlePowerUsage(0.0);
|
||||
this.getOuterProxy().setIdlePowerUsage(0.0);
|
||||
this.getProxy().setFlags();
|
||||
this.getOuterProxy().setFlags();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean getIntention()
|
||||
{
|
||||
return !super.getIntention();
|
||||
}
|
||||
@Override
|
||||
protected boolean getIntention() {
|
||||
return !super.getIntention();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
if( this.hasRedstoneFlag() && this.isActive() && this.isPowered() )
|
||||
{
|
||||
return MODELS_HAS_CHANNEL;
|
||||
}
|
||||
else if( this.hasRedstoneFlag() && this.isPowered() )
|
||||
{
|
||||
return MODELS_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
if (this.hasRedstoneFlag() && this.isActive() && this.isPowered()) {
|
||||
return MODELS_HAS_CHANNEL;
|
||||
} else if (this.hasRedstoneFlag() && this.isPowered()) {
|
||||
return MODELS_ON;
|
||||
} else {
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,60 +31,51 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
|
||||
public class PartOreDicStorageBus extends PartStorageBus
|
||||
{
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/oredict_storage_bus_base" );
|
||||
public class PartOreDicStorageBus extends PartStorageBus {
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID, "part/oredict_storage_bus_base");
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/storage_bus_off" ) );
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, new ResourceLocation(AppEng.MOD_ID, "part/storage_bus_off"));
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/storage_bus_on" ) );
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, new ResourceLocation(AppEng.MOD_ID, "part/storage_bus_on"));
|
||||
@PartModels
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, new ResourceLocation( AppEng.MOD_ID, "part/storage_bus_has_channel" ) );
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, new ResourceLocation(AppEng.MOD_ID, "part/storage_bus_has_channel"));
|
||||
|
||||
public String oreExp = "";
|
||||
OreDictPriorityList<IAEItemStack> priorityList;
|
||||
|
||||
public PartOreDicStorageBus( ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
public PartOreDicStorageBus(ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( NBTTagCompound data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.oreExp = data.getString( "oreMatch" );
|
||||
this.priorityList = new OreDictPriorityList<>( OreHelper.INSTANCE.getMatchingOre( oreExp ), oreExp );
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
this.oreExp = data.getString("oreMatch");
|
||||
this.priorityList = new OreDictPriorityList<>(OreHelper.INSTANCE.getMatchingOre(oreExp), oreExp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( NBTTagCompound data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
data.setString( "oreMatch", getOreExp() );
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
data.setString("oreMatch", getOreExp());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_OREDICTSTORAGEBUS );
|
||||
public boolean onPartActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
|
||||
if (Platform.isServer()) {
|
||||
Platform.openGUI(player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_OREDICTSTORAGEBUS);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiBridge getGuiBridge()
|
||||
{
|
||||
public GuiBridge getGuiBridge() {
|
||||
return GuiBridge.GUI_OREDICTSTORAGEBUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MEInventoryHandler<IAEItemStack> getInternalHandler()
|
||||
{
|
||||
if( this.cached )
|
||||
{
|
||||
public MEInventoryHandler<IAEItemStack> getInternalHandler() {
|
||||
if (this.cached) {
|
||||
return this.handler;
|
||||
}
|
||||
|
||||
@@ -92,132 +83,102 @@ public class PartOreDicStorageBus extends PartStorageBus
|
||||
|
||||
this.cached = true;
|
||||
final TileEntity self = this.getHost().getTile();
|
||||
final TileEntity target = self.getWorld().getTileEntity( self.getPos().offset( this.getSide().getFacing() ) );
|
||||
final int newHandlerHash = this.createHandlerHash( target );
|
||||
final TileEntity target = self.getWorld().getTileEntity(self.getPos().offset(this.getSide().getFacing()));
|
||||
final int newHandlerHash = this.createHandlerHash(target);
|
||||
|
||||
if( newHandlerHash != 0 && newHandlerHash == this.handlerHash )
|
||||
{
|
||||
if (newHandlerHash != 0 && newHandlerHash == this.handlerHash) {
|
||||
return this.handler;
|
||||
}
|
||||
|
||||
this.handlerHash = newHandlerHash;
|
||||
this.handler = null;
|
||||
if( this.monitor != null )
|
||||
{
|
||||
( (IBaseMonitor<IAEItemStack>) monitor ).removeListener( this );
|
||||
if (this.monitor != null) {
|
||||
((IBaseMonitor<IAEItemStack>) monitor).removeListener(this);
|
||||
}
|
||||
this.monitor = null;
|
||||
if( target != null )
|
||||
{
|
||||
IMEInventory<IAEItemStack> inv = this.getInventoryWrapper( target );
|
||||
if (target != null) {
|
||||
IMEInventory<IAEItemStack> inv = this.getInventoryWrapper(target);
|
||||
|
||||
if( inv instanceof ITickingMonitor )
|
||||
{
|
||||
if (inv instanceof ITickingMonitor) {
|
||||
this.monitor = (ITickingMonitor) inv;
|
||||
this.monitor.setActionSource( mySrc );
|
||||
this.monitor.setMode( (StorageFilter) this.getConfigManager().getSetting( Settings.STORAGE_FILTER ) );
|
||||
this.monitor.setActionSource(mySrc);
|
||||
this.monitor.setMode((StorageFilter) this.getConfigManager().getSetting(Settings.STORAGE_FILTER));
|
||||
}
|
||||
|
||||
if( inv != null )
|
||||
{
|
||||
this.handler = new MEInventoryHandler<>( inv, AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
|
||||
if (inv != null) {
|
||||
this.handler = new MEInventoryHandler<>(inv, AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
|
||||
this.handler.setBaseAccess( (AccessRestriction) this.getConfigManager().getSetting( Settings.ACCESS ) );
|
||||
this.handler.setWhitelist( this.getInstalledUpgrades( Upgrades.INVERTER ) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST );
|
||||
this.handler.setPriority( this.priority );
|
||||
this.handler.setBaseAccess((AccessRestriction) this.getConfigManager().getSetting(Settings.ACCESS));
|
||||
this.handler.setWhitelist(this.getInstalledUpgrades(Upgrades.INVERTER) > 0 ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST);
|
||||
this.handler.setPriority(this.priority);
|
||||
|
||||
this.handler.setPartitionList( this.getPriorityList() );
|
||||
this.handler.setPartitionList(this.getPriorityList());
|
||||
|
||||
if( inv instanceof IBaseMonitor )
|
||||
{
|
||||
if( ( (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getSetting( Settings.ACCESS ) ).hasPermission( AccessRestriction.READ ) )
|
||||
{
|
||||
( (IBaseMonitor<IAEItemStack>) inv ).addListener( this, this.handler );
|
||||
if (inv instanceof IBaseMonitor) {
|
||||
if (((AccessRestriction) ((ConfigManager) this.getConfigManager()).getSetting(Settings.ACCESS)).hasPermission(AccessRestriction.READ)) {
|
||||
((IBaseMonitor<IAEItemStack>) inv).addListener(this, this.handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update sleep state...
|
||||
if( wasSleeping != ( this.monitor == null ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
if (wasSleeping != (this.monitor == null)) {
|
||||
try {
|
||||
final ITickManager tm = this.getProxy().getTick();
|
||||
if( this.monitor == null )
|
||||
{
|
||||
tm.sleepDevice( this.getProxy().getNode() );
|
||||
if (this.monitor == null) {
|
||||
tm.sleepDevice(this.getProxy().getNode());
|
||||
} else {
|
||||
tm.wakeDevice(this.getProxy().getNode());
|
||||
}
|
||||
else
|
||||
{
|
||||
tm.wakeDevice( this.getProxy().getNode() );
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
} catch (final GridAccessException e) {
|
||||
// :(
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
// force grid to update handlers...
|
||||
( (GridStorageCache) this.getProxy().getGrid().getCache( IStorageGrid.class ) ).cellUpdate( null );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
((GridStorageCache) this.getProxy().getGrid().getCache(IStorageGrid.class)).cellUpdate(null);
|
||||
} catch (final GridAccessException e) {
|
||||
// :3
|
||||
}
|
||||
|
||||
return this.handler;
|
||||
}
|
||||
|
||||
private IPartitionList<IAEItemStack> getPriorityList()
|
||||
{
|
||||
if( priorityList == null )
|
||||
{
|
||||
this.priorityList = new OreDictPriorityList<>( OreHelper.INSTANCE.getMatchingOre( oreExp ), oreExp );
|
||||
private IPartitionList<IAEItemStack> getPriorityList() {
|
||||
if (priorityList == null) {
|
||||
this.priorityList = new OreDictPriorityList<>(OreHelper.INSTANCE.getMatchingOre(oreExp), oreExp);
|
||||
}
|
||||
return priorityList;
|
||||
}
|
||||
|
||||
public String getOreExp()
|
||||
{
|
||||
if( this.oreExp == null )
|
||||
{
|
||||
public String getOreExp() {
|
||||
if (this.oreExp == null) {
|
||||
return "";
|
||||
}
|
||||
return oreExp;
|
||||
}
|
||||
|
||||
public void saveOreMatch( String oreMatch )
|
||||
{
|
||||
if( !this.oreExp.equals( oreMatch ) )
|
||||
{
|
||||
public void saveOreMatch(String oreMatch) {
|
||||
if (!this.oreExp.equals(oreMatch)) {
|
||||
this.oreExp = oreMatch;
|
||||
|
||||
this.priorityList = new OreDictPriorityList<>( OreHelper.INSTANCE.getMatchingOre( oreExp ), oreExp );
|
||||
if( this.handler != null )
|
||||
{
|
||||
handler.setPartitionList( this.priorityList );
|
||||
this.priorityList = new OreDictPriorityList<>(OreHelper.INSTANCE.getMatchingOre(oreExp), oreExp);
|
||||
if (this.handler != null) {
|
||||
handler.setPartitionList(this.priorityList);
|
||||
}
|
||||
this.getHost().markForSave();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
if( this.isActive() && this.isPowered() )
|
||||
{
|
||||
public IPartModel getStaticModels() {
|
||||
if (this.isActive() && this.isPowered()) {
|
||||
return MODELS_HAS_CHANNEL;
|
||||
}
|
||||
else if( this.isPowered() )
|
||||
{
|
||||
} else if (this.isPowered()) {
|
||||
return MODELS_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,17 +19,6 @@
|
||||
package appeng.parts.misc;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
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.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.exceptions.FailedConnectionException;
|
||||
import appeng.api.networking.IGridConnection;
|
||||
@@ -46,184 +35,161 @@ import appeng.items.parts.PartModels;
|
||||
import appeng.me.helpers.AENetworkProxy;
|
||||
import appeng.parts.PartBasicState;
|
||||
import appeng.parts.PartModel;
|
||||
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.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
|
||||
public class PartToggleBus extends PartBasicState
|
||||
{
|
||||
public class PartToggleBus extends PartBasicState {
|
||||
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/toggle_bus_base" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation( AppEng.MOD_ID, "part/toggle_bus_status_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation( AppEng.MOD_ID, "part/toggle_bus_status_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation( AppEng.MOD_ID, "part/toggle_bus_status_has_channel" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID, "part/toggle_bus_base");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation(AppEng.MOD_ID, "part/toggle_bus_status_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation(AppEng.MOD_ID, "part/toggle_bus_status_on");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation(AppEng.MOD_ID, "part/toggle_bus_status_has_channel");
|
||||
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, MODEL_STATUS_OFF );
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, MODEL_STATUS_ON );
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, MODEL_STATUS_HAS_CHANNEL );
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, MODEL_STATUS_OFF);
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_STATUS_ON);
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, MODEL_STATUS_HAS_CHANNEL);
|
||||
|
||||
private static final int REDSTONE_FLAG = 4;
|
||||
private final AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", ItemStack.EMPTY, true );
|
||||
private IGridConnection connection;
|
||||
private boolean hasRedstone = false;
|
||||
private static final int REDSTONE_FLAG = 4;
|
||||
private final AENetworkProxy outerProxy = new AENetworkProxy(this, "outer", ItemStack.EMPTY, true);
|
||||
private IGridConnection connection;
|
||||
private boolean hasRedstone = false;
|
||||
|
||||
@Reflected
|
||||
public PartToggleBus( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
@Reflected
|
||||
public PartToggleBus(final ItemStack is) {
|
||||
super(is);
|
||||
|
||||
this.getProxy().setIdlePowerUsage( 0.0 );
|
||||
this.getOuterProxy().setIdlePowerUsage( 0.0 );
|
||||
this.getProxy().setFlags();
|
||||
this.getOuterProxy().setFlags();
|
||||
}
|
||||
this.getProxy().setIdlePowerUsage(0.0);
|
||||
this.getOuterProxy().setIdlePowerUsage(0.0);
|
||||
this.getProxy().setFlags();
|
||||
this.getOuterProxy().setFlags();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int populateFlags( final int cf )
|
||||
{
|
||||
return cf | ( this.getIntention() ? REDSTONE_FLAG : 0 );
|
||||
}
|
||||
@Override
|
||||
protected int populateFlags(final int cf) {
|
||||
return cf | (this.getIntention() ? REDSTONE_FLAG : 0);
|
||||
}
|
||||
|
||||
public boolean hasRedstoneFlag()
|
||||
{
|
||||
return ( this.getClientFlags() & REDSTONE_FLAG ) == REDSTONE_FLAG;
|
||||
}
|
||||
public boolean hasRedstoneFlag() {
|
||||
return (this.getClientFlags() & REDSTONE_FLAG) == REDSTONE_FLAG;
|
||||
}
|
||||
|
||||
protected boolean getIntention()
|
||||
{
|
||||
return this.getHost().hasRedstone( this.getSide() );
|
||||
}
|
||||
protected boolean getIntention() {
|
||||
return this.getHost().hasRedstone(this.getSide());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType( final AEPartLocation dir )
|
||||
{
|
||||
return AECableType.GLASS;
|
||||
}
|
||||
@Override
|
||||
public AECableType getCableConnectionType(final AEPartLocation dir) {
|
||||
return AECableType.GLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
bch.addBox( 6, 6, 11, 10, 10, 16 );
|
||||
}
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(6, 6, 11, 10, 10, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged( IBlockAccess w, BlockPos pos, BlockPos neighbor )
|
||||
{
|
||||
final boolean oldHasRedstone = this.hasRedstone;
|
||||
this.hasRedstone = this.getHost().hasRedstone( this.getSide() );
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockAccess w, BlockPos pos, BlockPos neighbor) {
|
||||
final boolean oldHasRedstone = this.hasRedstone;
|
||||
this.hasRedstone = this.getHost().hasRedstone(this.getSide());
|
||||
|
||||
if( this.hasRedstone != oldHasRedstone )
|
||||
{
|
||||
this.updateInternalState();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
}
|
||||
if (this.hasRedstone != oldHasRedstone) {
|
||||
this.updateInternalState();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound extra )
|
||||
{
|
||||
super.readFromNBT( extra );
|
||||
this.getOuterProxy().readFromNBT( extra );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound extra) {
|
||||
super.readFromNBT(extra);
|
||||
this.getOuterProxy().readFromNBT(extra);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound extra )
|
||||
{
|
||||
super.writeToNBT( extra );
|
||||
this.getOuterProxy().writeToNBT( extra );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound extra) {
|
||||
super.writeToNBT(extra);
|
||||
this.getOuterProxy().writeToNBT(extra);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFromWorld()
|
||||
{
|
||||
super.removeFromWorld();
|
||||
this.getOuterProxy().invalidate();
|
||||
}
|
||||
@Override
|
||||
public void removeFromWorld() {
|
||||
super.removeFromWorld();
|
||||
this.getOuterProxy().invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToWorld()
|
||||
{
|
||||
super.addToWorld();
|
||||
this.getOuterProxy().onReady();
|
||||
this.hasRedstone = this.getHost().hasRedstone( this.getSide() );
|
||||
this.updateInternalState();
|
||||
}
|
||||
@Override
|
||||
public void addToWorld() {
|
||||
super.addToWorld();
|
||||
this.getOuterProxy().onReady();
|
||||
this.hasRedstone = this.getHost().hasRedstone(this.getSide());
|
||||
this.updateInternalState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPartHostInfo( final AEPartLocation side, final IPartHost host, final TileEntity tile )
|
||||
{
|
||||
super.setPartHostInfo( side, host, tile );
|
||||
this.outerProxy.setValidSides( EnumSet.of( side.getFacing() ) );
|
||||
}
|
||||
@Override
|
||||
public void setPartHostInfo(final AEPartLocation side, final IPartHost host, final TileEntity tile) {
|
||||
super.setPartHostInfo(side, host, tile);
|
||||
this.outerProxy.setValidSides(EnumSet.of(side.getFacing()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode getExternalFacingNode()
|
||||
{
|
||||
return this.getOuterProxy().getNode();
|
||||
}
|
||||
@Override
|
||||
public IGridNode getExternalFacingNode() {
|
||||
return this.getOuterProxy().getNode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlacement( final EntityPlayer player, final EnumHand hand, final ItemStack held, final AEPartLocation side )
|
||||
{
|
||||
super.onPlacement( player, hand, held, side );
|
||||
this.getOuterProxy().setOwner( player );
|
||||
}
|
||||
@Override
|
||||
public void onPlacement(final EntityPlayer player, final EnumHand hand, final ItemStack held, final AEPartLocation side) {
|
||||
super.onPlacement(player, hand, held, side);
|
||||
this.getOuterProxy().setOwner(player);
|
||||
}
|
||||
|
||||
private void updateInternalState()
|
||||
{
|
||||
final boolean intention = this.getIntention();
|
||||
if( intention == ( this.connection == null ) )
|
||||
{
|
||||
if( this.getProxy().getNode() != null && this.getOuterProxy().getNode() != null )
|
||||
{
|
||||
if( intention )
|
||||
{
|
||||
try
|
||||
{
|
||||
this.connection = AEApi.instance().grid().createGridConnection( this.getProxy().getNode(), this.getOuterProxy().getNode() );
|
||||
}
|
||||
catch( final FailedConnectionException e )
|
||||
{
|
||||
// :(
|
||||
AELog.debug( e );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.connection.destroy();
|
||||
this.connection = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void updateInternalState() {
|
||||
final boolean intention = this.getIntention();
|
||||
if (intention == (this.connection == null)) {
|
||||
if (this.getProxy().getNode() != null && this.getOuterProxy().getNode() != null) {
|
||||
if (intention) {
|
||||
try {
|
||||
this.connection = AEApi.instance().grid().createGridConnection(this.getProxy().getNode(), this.getOuterProxy().getNode());
|
||||
} catch (final FailedConnectionException e) {
|
||||
// :(
|
||||
AELog.debug(e);
|
||||
}
|
||||
} else {
|
||||
this.connection.destroy();
|
||||
this.connection = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AENetworkProxy getOuterProxy()
|
||||
{
|
||||
return this.outerProxy;
|
||||
}
|
||||
AENetworkProxy getOuterProxy() {
|
||||
return this.outerProxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
if( this.hasRedstoneFlag() && this.isActive() && this.isPowered() )
|
||||
{
|
||||
return MODELS_HAS_CHANNEL;
|
||||
}
|
||||
else if( this.hasRedstoneFlag() && this.isPowered() )
|
||||
{
|
||||
return MODELS_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
if (this.hasRedstoneFlag() && this.isActive() && this.isPowered()) {
|
||||
return MODELS_HAS_CHANNEL;
|
||||
} else if (this.hasRedstoneFlag() && this.isPowered()) {
|
||||
return MODELS_ON;
|
||||
} else {
|
||||
return MODELS_OFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,18 +19,6 @@
|
||||
package appeng.parts.networking;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.definitions.IParts;
|
||||
@@ -51,386 +39,318 @@ import appeng.items.parts.ItemPart;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.AEBasePart;
|
||||
import appeng.util.Platform;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
|
||||
|
||||
public class PartCable extends AEBasePart implements IPartCable
|
||||
{
|
||||
public class PartCable extends AEBasePart implements IPartCable {
|
||||
|
||||
private static final ImmutableSet<AEPartLocation> STRAIGHT_PART_LOCATIONS = ImmutableSet.of( AEPartLocation.DOWN, AEPartLocation.NORTH,
|
||||
AEPartLocation.EAST );
|
||||
private static final ImmutableSet<AEPartLocation> STRAIGHT_PART_LOCATIONS = ImmutableSet.of(AEPartLocation.DOWN, AEPartLocation.NORTH,
|
||||
AEPartLocation.EAST);
|
||||
|
||||
private final int[] channelsOnSide = { 0, 0, 0, 0, 0, 0 };
|
||||
private final int[] channelsOnSide = {0, 0, 0, 0, 0, 0};
|
||||
|
||||
private EnumSet<AEPartLocation> connections = EnumSet.noneOf( AEPartLocation.class );
|
||||
private boolean powered = false;
|
||||
private EnumSet<AEPartLocation> connections = EnumSet.noneOf(AEPartLocation.class);
|
||||
private boolean powered = false;
|
||||
|
||||
public PartCable( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
this.getProxy().setFlags( GridFlags.PREFERRED );
|
||||
this.getProxy().setIdlePowerUsage( 0.0 );
|
||||
this.getProxy().setColor( AEColor.values()[( (ItemPart) is.getItem() ).variantOf( is.getItemDamage() )] );
|
||||
}
|
||||
public PartCable(final ItemStack is) {
|
||||
super(is);
|
||||
this.getProxy().setFlags(GridFlags.PREFERRED);
|
||||
this.getProxy().setIdlePowerUsage(0.0);
|
||||
this.getProxy().setColor(AEColor.values()[((ItemPart) is.getItem()).variantOf(is.getItemDamage())]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BusSupport supportsBuses()
|
||||
{
|
||||
return BusSupport.CABLE;
|
||||
}
|
||||
@Override
|
||||
public BusSupport supportsBuses() {
|
||||
return BusSupport.CABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AEColor getCableColor()
|
||||
{
|
||||
return this.getProxy().getColor();
|
||||
}
|
||||
@Override
|
||||
public AEColor getCableColor() {
|
||||
return this.getProxy().getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType()
|
||||
{
|
||||
return AECableType.GLASS;
|
||||
}
|
||||
@Override
|
||||
public AECableType getCableConnectionType() {
|
||||
return AECableType.GLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
if( cable == this.getCableConnectionType() )
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
else if( cable.ordinal() >= this.getCableConnectionType().ordinal() )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
if (cable == this.getCableConnectionType()) {
|
||||
return 4;
|
||||
} else if (cable.ordinal() >= this.getCableConnectionType().ordinal()) {
|
||||
return -1;
|
||||
} else {
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean changeColor( final AEColor newColor, final EntityPlayer who )
|
||||
{
|
||||
if( this.getCableColor() != newColor )
|
||||
{
|
||||
ItemStack newPart = null;
|
||||
@Override
|
||||
public boolean changeColor(final AEColor newColor, final EntityPlayer who) {
|
||||
if (this.getCableColor() != newColor) {
|
||||
ItemStack newPart = null;
|
||||
|
||||
final IParts parts = AEApi.instance().definitions().parts();
|
||||
final IParts parts = AEApi.instance().definitions().parts();
|
||||
|
||||
if( this.getCableConnectionType() == AECableType.GLASS )
|
||||
{
|
||||
newPart = parts.cableGlass().stack( newColor, 1 );
|
||||
}
|
||||
else if( this.getCableConnectionType() == AECableType.COVERED )
|
||||
{
|
||||
newPart = parts.cableCovered().stack( newColor, 1 );
|
||||
}
|
||||
else if( this.getCableConnectionType() == AECableType.SMART )
|
||||
{
|
||||
newPart = parts.cableSmart().stack( newColor, 1 );
|
||||
}
|
||||
else if( this.getCableConnectionType() == AECableType.DENSE_COVERED )
|
||||
{
|
||||
newPart = parts.cableDenseCovered().stack( newColor, 1 );
|
||||
}
|
||||
else if( this.getCableConnectionType() == AECableType.DENSE_SMART )
|
||||
{
|
||||
newPart = parts.cableDenseSmart().stack( newColor, 1 );
|
||||
}
|
||||
if (this.getCableConnectionType() == AECableType.GLASS) {
|
||||
newPart = parts.cableGlass().stack(newColor, 1);
|
||||
} else if (this.getCableConnectionType() == AECableType.COVERED) {
|
||||
newPart = parts.cableCovered().stack(newColor, 1);
|
||||
} else if (this.getCableConnectionType() == AECableType.SMART) {
|
||||
newPart = parts.cableSmart().stack(newColor, 1);
|
||||
} else if (this.getCableConnectionType() == AECableType.DENSE_COVERED) {
|
||||
newPart = parts.cableDenseCovered().stack(newColor, 1);
|
||||
} else if (this.getCableConnectionType() == AECableType.DENSE_SMART) {
|
||||
newPart = parts.cableDenseSmart().stack(newColor, 1);
|
||||
}
|
||||
|
||||
boolean hasPermission = true;
|
||||
boolean hasPermission = true;
|
||||
|
||||
try
|
||||
{
|
||||
hasPermission = this.getProxy().getSecurity().hasPermission( who, SecurityPermissions.BUILD );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
try {
|
||||
hasPermission = this.getProxy().getSecurity().hasPermission(who, SecurityPermissions.BUILD);
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
|
||||
if( newPart != null && hasPermission )
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (newPart != null && hasPermission) {
|
||||
if (Platform.isClient()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
this.getHost().removePart( AEPartLocation.INTERNAL, true );
|
||||
this.getHost().addPart( newPart, AEPartLocation.INTERNAL, who, null );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
this.getHost().removePart(AEPartLocation.INTERNAL, true);
|
||||
this.getHost().addPart(newPart, AEPartLocation.INTERNAL, who, null);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValidSides( final EnumSet<EnumFacing> sides )
|
||||
{
|
||||
this.getProxy().setValidSides( sides );
|
||||
}
|
||||
@Override
|
||||
public void setValidSides(final EnumSet<EnumFacing> sides) {
|
||||
this.getProxy().setValidSides(sides);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected( final EnumFacing side )
|
||||
{
|
||||
return this.getConnections().contains( AEPartLocation.fromFacing( side ) );
|
||||
}
|
||||
@Override
|
||||
public boolean isConnected(final EnumFacing side) {
|
||||
return this.getConnections().contains(AEPartLocation.fromFacing(side));
|
||||
}
|
||||
|
||||
public void markForUpdate()
|
||||
{
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
public void markForUpdate() {
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
bch.addBox( 6.0, 6.0, 6.0, 10.0, 10.0, 10.0 );
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(6.0, 6.0, 6.0, 10.0, 10.0, 10.0);
|
||||
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
final IGridNode n = this.getGridNode();
|
||||
if( n != null )
|
||||
{
|
||||
this.setConnections( n.getConnectedSides() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getConnections().clear();
|
||||
}
|
||||
}
|
||||
if (Platform.isServer()) {
|
||||
final IGridNode n = this.getGridNode();
|
||||
if (n != null) {
|
||||
this.setConnections(n.getConnectedSides());
|
||||
} else {
|
||||
this.getConnections().clear();
|
||||
}
|
||||
}
|
||||
|
||||
final IPartHost ph = this.getHost();
|
||||
if( ph != null )
|
||||
{
|
||||
for( final AEPartLocation dir : AEPartLocation.SIDE_LOCATIONS )
|
||||
{
|
||||
final IPart p = ph.getPart( dir );
|
||||
if( p instanceof IGridHost )
|
||||
{
|
||||
final double dist = p.getCableConnectionLength( this.getCableConnectionType() );
|
||||
final IPartHost ph = this.getHost();
|
||||
if (ph != null) {
|
||||
for (final AEPartLocation dir : AEPartLocation.SIDE_LOCATIONS) {
|
||||
final IPart p = ph.getPart(dir);
|
||||
if (p instanceof IGridHost) {
|
||||
final double dist = p.getCableConnectionLength(this.getCableConnectionType());
|
||||
|
||||
if( dist > 8 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (dist > 8) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch( dir )
|
||||
{
|
||||
case DOWN:
|
||||
bch.addBox( 6.0, dist, 6.0, 10.0, 6.0, 10.0 );
|
||||
break;
|
||||
case EAST:
|
||||
bch.addBox( 10.0, 6.0, 6.0, 16.0 - dist, 10.0, 10.0 );
|
||||
break;
|
||||
case NORTH:
|
||||
bch.addBox( 6.0, 6.0, dist, 10.0, 10.0, 6.0 );
|
||||
break;
|
||||
case SOUTH:
|
||||
bch.addBox( 6.0, 6.0, 10.0, 10.0, 10.0, 16.0 - dist );
|
||||
break;
|
||||
case UP:
|
||||
bch.addBox( 6.0, 10.0, 6.0, 10.0, 16.0 - dist, 10.0 );
|
||||
break;
|
||||
case WEST:
|
||||
bch.addBox( dist, 6.0, 6.0, 6.0, 10.0, 10.0 );
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (dir) {
|
||||
case DOWN:
|
||||
bch.addBox(6.0, dist, 6.0, 10.0, 6.0, 10.0);
|
||||
break;
|
||||
case EAST:
|
||||
bch.addBox(10.0, 6.0, 6.0, 16.0 - dist, 10.0, 10.0);
|
||||
break;
|
||||
case NORTH:
|
||||
bch.addBox(6.0, 6.0, dist, 10.0, 10.0, 6.0);
|
||||
break;
|
||||
case SOUTH:
|
||||
bch.addBox(6.0, 6.0, 10.0, 10.0, 10.0, 16.0 - dist);
|
||||
break;
|
||||
case UP:
|
||||
bch.addBox(6.0, 10.0, 6.0, 10.0, 16.0 - dist, 10.0);
|
||||
break;
|
||||
case WEST:
|
||||
bch.addBox(dist, 6.0, 6.0, 6.0, 10.0, 10.0);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( final AEPartLocation of : this.getConnections() )
|
||||
{
|
||||
switch( of )
|
||||
{
|
||||
case DOWN:
|
||||
bch.addBox( 6.0, 0.0, 6.0, 10.0, 6.0, 10.0 );
|
||||
break;
|
||||
case EAST:
|
||||
bch.addBox( 10.0, 6.0, 6.0, 16.0, 10.0, 10.0 );
|
||||
break;
|
||||
case NORTH:
|
||||
bch.addBox( 6.0, 6.0, 0.0, 10.0, 10.0, 6.0 );
|
||||
break;
|
||||
case SOUTH:
|
||||
bch.addBox( 6.0, 6.0, 10.0, 10.0, 10.0, 16.0 );
|
||||
break;
|
||||
case UP:
|
||||
bch.addBox( 6.0, 10.0, 6.0, 10.0, 16.0, 10.0 );
|
||||
break;
|
||||
case WEST:
|
||||
bch.addBox( 0.0, 6.0, 6.0, 6.0, 10.0, 10.0 );
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final AEPartLocation of : this.getConnections()) {
|
||||
switch (of) {
|
||||
case DOWN:
|
||||
bch.addBox(6.0, 0.0, 6.0, 10.0, 6.0, 10.0);
|
||||
break;
|
||||
case EAST:
|
||||
bch.addBox(10.0, 6.0, 6.0, 16.0, 10.0, 10.0);
|
||||
break;
|
||||
case NORTH:
|
||||
bch.addBox(6.0, 6.0, 0.0, 10.0, 10.0, 6.0);
|
||||
break;
|
||||
case SOUTH:
|
||||
bch.addBox(6.0, 6.0, 10.0, 10.0, 10.0, 16.0);
|
||||
break;
|
||||
case UP:
|
||||
bch.addBox(6.0, 10.0, 6.0, 10.0, 16.0, 10.0);
|
||||
break;
|
||||
case WEST:
|
||||
bch.addBox(0.0, 6.0, 6.0, 6.0, 10.0, 10.0);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
final IGridNode node = this.getGridNode();
|
||||
if (Platform.isServer()) {
|
||||
final IGridNode node = this.getGridNode();
|
||||
|
||||
if( node != null )
|
||||
{
|
||||
int howMany = 0;
|
||||
for( final IGridConnection gc : node.getConnections() )
|
||||
{
|
||||
howMany = Math.max( gc.getUsedChannels(), howMany );
|
||||
}
|
||||
if (node != null) {
|
||||
int howMany = 0;
|
||||
for (final IGridConnection gc : node.getConnections()) {
|
||||
howMany = Math.max(gc.getUsedChannels(), howMany);
|
||||
}
|
||||
|
||||
data.setByte( "usedChannels", (byte) howMany );
|
||||
}
|
||||
}
|
||||
}
|
||||
data.setByte("usedChannels", (byte) howMany);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream( final ByteBuf data ) throws IOException
|
||||
{
|
||||
int flags = 0;
|
||||
boolean[] writeSide = new boolean[EnumFacing.values().length];
|
||||
int[] channelsPerSide = new int[EnumFacing.values().length];
|
||||
@Override
|
||||
public void writeToStream(final ByteBuf data) throws IOException {
|
||||
int flags = 0;
|
||||
boolean[] writeSide = new boolean[EnumFacing.values().length];
|
||||
int[] channelsPerSide = new int[EnumFacing.values().length];
|
||||
|
||||
for( EnumFacing thisSide : EnumFacing.values() )
|
||||
{
|
||||
final IPart part = this.getHost().getPart( thisSide );
|
||||
if( part != null )
|
||||
{
|
||||
writeSide[thisSide.ordinal()] = true;
|
||||
int channels = 0;
|
||||
if( part.getGridNode() != null )
|
||||
{
|
||||
final IReadOnlyCollection<IGridConnection> set = part.getGridNode().getConnections();
|
||||
for( final IGridConnection gc : set )
|
||||
{
|
||||
channels = Math.max( channels, gc.getUsedChannels() );
|
||||
}
|
||||
}
|
||||
channelsPerSide[thisSide.ordinal()] = channels;
|
||||
}
|
||||
}
|
||||
for (EnumFacing thisSide : EnumFacing.values()) {
|
||||
final IPart part = this.getHost().getPart(thisSide);
|
||||
if (part != null) {
|
||||
writeSide[thisSide.ordinal()] = true;
|
||||
int channels = 0;
|
||||
if (part.getGridNode() != null) {
|
||||
final IReadOnlyCollection<IGridConnection> set = part.getGridNode().getConnections();
|
||||
for (final IGridConnection gc : set) {
|
||||
channels = Math.max(channels, gc.getUsedChannels());
|
||||
}
|
||||
}
|
||||
channelsPerSide[thisSide.ordinal()] = channels;
|
||||
}
|
||||
}
|
||||
|
||||
IGridNode n = this.getGridNode();
|
||||
if( n != null )
|
||||
{
|
||||
for( final IGridConnection gc : n.getConnections() )
|
||||
{
|
||||
final AEPartLocation side = gc.getDirection( n );
|
||||
if( side != AEPartLocation.INTERNAL )
|
||||
{
|
||||
writeSide[side.ordinal()] = true;
|
||||
channelsPerSide[side.ordinal()] = gc.getUsedChannels();
|
||||
flags |= ( 1 << side.ordinal() );
|
||||
}
|
||||
}
|
||||
}
|
||||
IGridNode n = this.getGridNode();
|
||||
if (n != null) {
|
||||
for (final IGridConnection gc : n.getConnections()) {
|
||||
final AEPartLocation side = gc.getDirection(n);
|
||||
if (side != AEPartLocation.INTERNAL) {
|
||||
writeSide[side.ordinal()] = true;
|
||||
channelsPerSide[side.ordinal()] = gc.getUsedChannels();
|
||||
flags |= (1 << side.ordinal());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if( this.getProxy().getEnergy().isNetworkPowered() )
|
||||
{
|
||||
flags |= ( 1 << AEPartLocation.INTERNAL.ordinal() );
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// aww...
|
||||
}
|
||||
try {
|
||||
if (this.getProxy().getEnergy().isNetworkPowered()) {
|
||||
flags |= (1 << AEPartLocation.INTERNAL.ordinal());
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// aww...
|
||||
}
|
||||
|
||||
data.writeByte( (byte) flags );
|
||||
// Only write the used channels for sides where we have a part or another cable
|
||||
for( int i = 0; i < writeSide.length; i++ )
|
||||
{
|
||||
if( writeSide[i] )
|
||||
{
|
||||
data.writeByte( channelsPerSide[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
data.writeByte((byte) flags);
|
||||
// Only write the used channels for sides where we have a part or another cable
|
||||
for (int i = 0; i < writeSide.length; i++) {
|
||||
if (writeSide[i]) {
|
||||
data.writeByte(channelsPerSide[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream( final ByteBuf data ) throws IOException
|
||||
{
|
||||
int cs = data.readByte();
|
||||
final EnumSet<AEPartLocation> myC = this.getConnections().clone();
|
||||
final boolean wasPowered = this.powered;
|
||||
this.powered = false;
|
||||
boolean channelsChanged = false;
|
||||
@Override
|
||||
public boolean readFromStream(final ByteBuf data) throws IOException {
|
||||
int cs = data.readByte();
|
||||
final EnumSet<AEPartLocation> myC = this.getConnections().clone();
|
||||
final boolean wasPowered = this.powered;
|
||||
this.powered = false;
|
||||
boolean channelsChanged = false;
|
||||
|
||||
for( final AEPartLocation d : AEPartLocation.values() )
|
||||
{
|
||||
if( d == AEPartLocation.INTERNAL )
|
||||
{
|
||||
final int id = 1 << d.ordinal();
|
||||
if( id == ( cs & id ) )
|
||||
{
|
||||
this.powered = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean conOnSide = ( cs & ( 1 << d.ordinal() ) ) != 0;
|
||||
if( conOnSide )
|
||||
{
|
||||
this.getConnections().add( d );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getConnections().remove( d );
|
||||
}
|
||||
for (final AEPartLocation d : AEPartLocation.values()) {
|
||||
if (d == AEPartLocation.INTERNAL) {
|
||||
final int id = 1 << d.ordinal();
|
||||
if (id == (cs & id)) {
|
||||
this.powered = true;
|
||||
}
|
||||
} else {
|
||||
boolean conOnSide = (cs & (1 << d.ordinal())) != 0;
|
||||
if (conOnSide) {
|
||||
this.getConnections().add(d);
|
||||
} else {
|
||||
this.getConnections().remove(d);
|
||||
}
|
||||
|
||||
int ch = 0;
|
||||
int ch = 0;
|
||||
|
||||
// Only read channels if there's a part on this side or a cable connection
|
||||
// This works only because cables are always read *last* from the packet update for
|
||||
// a cable bus
|
||||
if( conOnSide || this.getHost().getPart( d ) != null )
|
||||
{
|
||||
ch = ( data.readByte() ) & 0xFF;
|
||||
}
|
||||
// Only read channels if there's a part on this side or a cable connection
|
||||
// This works only because cables are always read *last* from the packet update for
|
||||
// a cable bus
|
||||
if (conOnSide || this.getHost().getPart(d) != null) {
|
||||
ch = (data.readByte()) & 0xFF;
|
||||
}
|
||||
|
||||
if( ch != this.getChannelsOnSide( d.ordinal() ) )
|
||||
{
|
||||
channelsChanged = true;
|
||||
this.setChannelsOnSide( d.ordinal(), ch );
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ch != this.getChannelsOnSide(d.ordinal())) {
|
||||
channelsChanged = true;
|
||||
this.setChannelsOnSide(d.ordinal(), ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !myC.equals( this.getConnections() ) || wasPowered != this.powered || channelsChanged;
|
||||
}
|
||||
return !myC.equals(this.getConnections()) || wasPowered != this.powered || channelsChanged;
|
||||
}
|
||||
|
||||
int getChannelsOnSide( final int i )
|
||||
{
|
||||
return this.channelsOnSide[i];
|
||||
}
|
||||
int getChannelsOnSide(final int i) {
|
||||
return this.channelsOnSide[i];
|
||||
}
|
||||
|
||||
public int getChannelsOnSide( EnumFacing side )
|
||||
{
|
||||
if( !this.powered )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return this.channelsOnSide[side.ordinal()];
|
||||
}
|
||||
public int getChannelsOnSide(EnumFacing side) {
|
||||
if (!this.powered) {
|
||||
return 0;
|
||||
}
|
||||
return this.channelsOnSide[side.ordinal()];
|
||||
}
|
||||
|
||||
void setChannelsOnSide( final int i, final int channels )
|
||||
{
|
||||
this.channelsOnSide[i] = channels;
|
||||
}
|
||||
void setChannelsOnSide(final int i, final int channels) {
|
||||
this.channelsOnSide[i] = channels;
|
||||
}
|
||||
|
||||
EnumSet<AEPartLocation> getConnections()
|
||||
{
|
||||
return this.connections;
|
||||
}
|
||||
EnumSet<AEPartLocation> getConnections() {
|
||||
return this.connections;
|
||||
}
|
||||
|
||||
void setConnections( final EnumSet<AEPartLocation> connections )
|
||||
{
|
||||
this.connections = connections;
|
||||
}
|
||||
void setConnections(final EnumSet<AEPartLocation> connections) {
|
||||
this.connections = connections;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
package appeng.parts.networking;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
@@ -30,76 +28,65 @@ import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public class PartCableCovered extends PartCable
|
||||
{
|
||||
@Reflected
|
||||
public PartCableCovered( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
public class PartCableCovered extends PartCable {
|
||||
@Reflected
|
||||
public PartCableCovered(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void channelUpdated( final MENetworkChannelsChanged c )
|
||||
{
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void channelUpdated(final MENetworkChannelsChanged c) {
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(final MENetworkPowerStatusChange c) {
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType()
|
||||
{
|
||||
return AECableType.COVERED;
|
||||
}
|
||||
@Override
|
||||
public AECableType getCableConnectionType() {
|
||||
return AECableType.COVERED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
bch.addBox( 5.0, 5.0, 5.0, 11.0, 11.0, 11.0 );
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(5.0, 5.0, 5.0, 11.0, 11.0, 11.0);
|
||||
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
final IGridNode n = this.getGridNode();
|
||||
if( n != null )
|
||||
{
|
||||
this.setConnections( n.getConnectedSides() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getConnections().clear();
|
||||
}
|
||||
}
|
||||
if (Platform.isServer()) {
|
||||
final IGridNode n = this.getGridNode();
|
||||
if (n != null) {
|
||||
this.setConnections(n.getConnectedSides());
|
||||
} else {
|
||||
this.getConnections().clear();
|
||||
}
|
||||
}
|
||||
|
||||
for( final AEPartLocation of : this.getConnections() )
|
||||
{
|
||||
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:
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final AEPartLocation of : this.getConnections()) {
|
||||
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:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,16 +19,13 @@
|
||||
package appeng.parts.networking;
|
||||
|
||||
|
||||
import appeng.helpers.Reflected;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.helpers.Reflected;
|
||||
|
||||
|
||||
public class PartCableGlass extends PartCable
|
||||
{
|
||||
@Reflected
|
||||
public PartCableGlass( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
public class PartCableGlass extends PartCable {
|
||||
@Reflected
|
||||
public PartCableGlass(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
package appeng.parts.networking;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
@@ -30,76 +28,65 @@ import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public class PartCableSmart extends PartCable
|
||||
{
|
||||
@Reflected
|
||||
public PartCableSmart( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
public class PartCableSmart extends PartCable {
|
||||
@Reflected
|
||||
public PartCableSmart(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void channelUpdated( final MENetworkChannelsChanged c )
|
||||
{
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void channelUpdated(final MENetworkChannelsChanged c) {
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(final MENetworkPowerStatusChange c) {
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType()
|
||||
{
|
||||
return AECableType.SMART;
|
||||
}
|
||||
@Override
|
||||
public AECableType getCableConnectionType() {
|
||||
return AECableType.SMART;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
bch.addBox( 5.0, 5.0, 5.0, 11.0, 11.0, 11.0 );
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(5.0, 5.0, 5.0, 11.0, 11.0, 11.0);
|
||||
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
final IGridNode n = this.getGridNode();
|
||||
if( n != null )
|
||||
{
|
||||
this.setConnections( n.getConnectedSides() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getConnections().clear();
|
||||
}
|
||||
}
|
||||
if (Platform.isServer()) {
|
||||
final IGridNode n = this.getGridNode();
|
||||
if (n != null) {
|
||||
this.setConnections(n.getConnectedSides());
|
||||
} else {
|
||||
this.getConnections().clear();
|
||||
}
|
||||
}
|
||||
|
||||
for( final AEPartLocation of : this.getConnections() )
|
||||
{
|
||||
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:
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final AEPartLocation of : this.getConnections()) {
|
||||
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:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,6 @@
|
||||
package appeng.parts.networking;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
@@ -34,123 +31,107 @@ import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
|
||||
public abstract class PartDenseCable extends PartCable
|
||||
{
|
||||
@Reflected
|
||||
public PartDenseCable( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
public abstract class PartDenseCable extends PartCable {
|
||||
@Reflected
|
||||
public PartDenseCable(final ItemStack is) {
|
||||
super(is);
|
||||
|
||||
this.getProxy().setFlags( GridFlags.DENSE_CAPACITY, GridFlags.PREFERRED );
|
||||
}
|
||||
this.getProxy().setFlags(GridFlags.DENSE_CAPACITY, GridFlags.PREFERRED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BusSupport supportsBuses()
|
||||
{
|
||||
return BusSupport.DENSE_CABLE;
|
||||
}
|
||||
@Override
|
||||
public BusSupport supportsBuses() {
|
||||
return BusSupport.DENSE_CABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
final boolean noLadder = !bch.isBBCollision();
|
||||
final double min = noLadder ? 3.0 : 4.9;
|
||||
final double max = noLadder ? 13.0 : 11.1;
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
final boolean noLadder = !bch.isBBCollision();
|
||||
final double min = noLadder ? 3.0 : 4.9;
|
||||
final double max = noLadder ? 13.0 : 11.1;
|
||||
|
||||
bch.addBox( min, min, min, max, max, max );
|
||||
bch.addBox(min, min, min, max, max, max);
|
||||
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
final IGridNode n = this.getGridNode();
|
||||
if( n != null )
|
||||
{
|
||||
this.setConnections( n.getConnectedSides() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getConnections().clear();
|
||||
}
|
||||
}
|
||||
if (Platform.isServer()) {
|
||||
final IGridNode n = this.getGridNode();
|
||||
if (n != null) {
|
||||
this.setConnections(n.getConnectedSides());
|
||||
} else {
|
||||
this.getConnections().clear();
|
||||
}
|
||||
}
|
||||
|
||||
for( final AEPartLocation of : this.getConnections() )
|
||||
{
|
||||
if( this.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:
|
||||
}
|
||||
}
|
||||
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:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final AEPartLocation of : this.getConnections()) {
|
||||
if (this.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:
|
||||
}
|
||||
} 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:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDense( final AEPartLocation of )
|
||||
{
|
||||
final TileEntity te = this.getTile().getWorld().getTileEntity( this.getTile().getPos().offset( of.getFacing() ) );
|
||||
private boolean isDense(final AEPartLocation of) {
|
||||
final TileEntity te = this.getTile().getWorld().getTileEntity(this.getTile().getPos().offset(of.getFacing()));
|
||||
|
||||
if( te instanceof IGridHost )
|
||||
{
|
||||
final AECableType t = ( (IGridHost) te ).getCableConnectionType( of.getOpposite() );
|
||||
return t.isDense();
|
||||
}
|
||||
if (te instanceof IGridHost) {
|
||||
final AECableType t = ((IGridHost) te).getCableConnectionType(of.getOpposite());
|
||||
return t.isDense();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void channelUpdated( final MENetworkChannelsChanged c )
|
||||
{
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void channelUpdated(final MENetworkChannelsChanged c) {
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(final MENetworkPowerStatusChange c) {
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,23 +19,19 @@
|
||||
package appeng.parts.networking;
|
||||
|
||||
|
||||
import appeng.api.util.AECableType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.util.AECableType;
|
||||
|
||||
public class PartDenseCableCovered extends PartDenseCable {
|
||||
|
||||
public class PartDenseCableCovered extends PartDenseCable
|
||||
{
|
||||
public PartDenseCableCovered(ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
public PartDenseCableCovered( ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType()
|
||||
{
|
||||
return AECableType.DENSE_COVERED;
|
||||
}
|
||||
@Override
|
||||
public AECableType getCableConnectionType() {
|
||||
return AECableType.DENSE_COVERED;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,22 +19,18 @@
|
||||
package appeng.parts.networking;
|
||||
|
||||
|
||||
import appeng.api.util.AECableType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.util.AECableType;
|
||||
|
||||
public class PartDenseCableSmart extends PartDenseCable {
|
||||
|
||||
public class PartDenseCableSmart extends PartDenseCable
|
||||
{
|
||||
public PartDenseCableSmart(ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
public PartDenseCableSmart( ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType()
|
||||
{
|
||||
return AECableType.DENSE_SMART;
|
||||
}
|
||||
@Override
|
||||
public AECableType getCableConnectionType() {
|
||||
return AECableType.DENSE_SMART;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,17 +19,6 @@
|
||||
package appeng.parts.networking;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
|
||||
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.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.IGridNode;
|
||||
@@ -46,154 +35,139 @@ import appeng.me.GridAccessException;
|
||||
import appeng.me.helpers.AENetworkProxy;
|
||||
import appeng.parts.AEBasePart;
|
||||
import appeng.parts.PartModel;
|
||||
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.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
|
||||
|
||||
public class PartQuartzFiber extends AEBasePart implements IEnergyGridProvider
|
||||
{
|
||||
public class PartQuartzFiber extends AEBasePart implements IEnergyGridProvider {
|
||||
|
||||
@PartModels
|
||||
private static final IPartModel MODELS = new PartModel( new ResourceLocation( AppEng.MOD_ID, "part/quartz_fiber" ) );
|
||||
@PartModels
|
||||
private static final IPartModel MODELS = new PartModel(new ResourceLocation(AppEng.MOD_ID, "part/quartz_fiber"));
|
||||
|
||||
private final AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", this.getProxy().getMachineRepresentation(), true );
|
||||
private final AENetworkProxy outerProxy = new AENetworkProxy(this, "outer", this.getProxy().getMachineRepresentation(), true);
|
||||
|
||||
public PartQuartzFiber( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
this.getProxy().setIdlePowerUsage( 0 );
|
||||
this.getProxy().setFlags( GridFlags.CANNOT_CARRY );
|
||||
this.outerProxy.setIdlePowerUsage( 0 );
|
||||
this.outerProxy.setFlags( GridFlags.CANNOT_CARRY );
|
||||
}
|
||||
public PartQuartzFiber(final ItemStack is) {
|
||||
super(is);
|
||||
this.getProxy().setIdlePowerUsage(0);
|
||||
this.getProxy().setFlags(GridFlags.CANNOT_CARRY);
|
||||
this.outerProxy.setIdlePowerUsage(0);
|
||||
this.outerProxy.setFlags(GridFlags.CANNOT_CARRY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType( final AEPartLocation dir )
|
||||
{
|
||||
return AECableType.GLASS;
|
||||
}
|
||||
@Override
|
||||
public AECableType getCableConnectionType(final AEPartLocation dir) {
|
||||
return AECableType.GLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
bch.addBox( 6, 6, 10, 10, 10, 16 );
|
||||
}
|
||||
@Override
|
||||
public void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(6, 6, 10, 10, 10, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound extra )
|
||||
{
|
||||
super.readFromNBT( extra );
|
||||
this.outerProxy.readFromNBT( extra );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound extra) {
|
||||
super.readFromNBT(extra);
|
||||
this.outerProxy.readFromNBT(extra);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound extra )
|
||||
{
|
||||
super.writeToNBT( extra );
|
||||
this.outerProxy.writeToNBT( extra );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound extra) {
|
||||
super.writeToNBT(extra);
|
||||
this.outerProxy.writeToNBT(extra);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFromWorld()
|
||||
{
|
||||
super.removeFromWorld();
|
||||
this.outerProxy.invalidate();
|
||||
}
|
||||
@Override
|
||||
public void removeFromWorld() {
|
||||
super.removeFromWorld();
|
||||
this.outerProxy.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToWorld()
|
||||
{
|
||||
super.addToWorld();
|
||||
this.outerProxy.onReady();
|
||||
}
|
||||
@Override
|
||||
public void addToWorld() {
|
||||
super.addToWorld();
|
||||
this.outerProxy.onReady();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPartHostInfo( final AEPartLocation side, final IPartHost host, final TileEntity tile )
|
||||
{
|
||||
super.setPartHostInfo( side, host, tile );
|
||||
this.outerProxy.setValidSides( EnumSet.of( side.getFacing() ) );
|
||||
}
|
||||
@Override
|
||||
public void setPartHostInfo(final AEPartLocation side, final IPartHost host, final TileEntity tile) {
|
||||
super.setPartHostInfo(side, host, tile);
|
||||
this.outerProxy.setValidSides(EnumSet.of(side.getFacing()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode getExternalFacingNode()
|
||||
{
|
||||
return this.outerProxy.getNode();
|
||||
}
|
||||
@Override
|
||||
public IGridNode getExternalFacingNode() {
|
||||
return this.outerProxy.getNode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlacement( final EntityPlayer player, final EnumHand hand, final ItemStack held, final AEPartLocation side )
|
||||
{
|
||||
super.onPlacement( player, hand, held, side );
|
||||
this.outerProxy.setOwner( player );
|
||||
}
|
||||
@Override
|
||||
public void onPlacement(final EntityPlayer player, final EnumHand hand, final ItemStack held, final AEPartLocation side) {
|
||||
super.onPlacement(player, hand, held, side);
|
||||
this.outerProxy.setOwner(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IEnergyGridProvider> providers()
|
||||
{
|
||||
Collection<IEnergyGridProvider> providers = new ArrayList<>();
|
||||
@Override
|
||||
public Collection<IEnergyGridProvider> providers() {
|
||||
Collection<IEnergyGridProvider> providers = new ArrayList<>();
|
||||
|
||||
try
|
||||
{
|
||||
final IEnergyGrid eg = this.getProxy().getEnergy();
|
||||
try {
|
||||
final IEnergyGrid eg = this.getProxy().getEnergy();
|
||||
|
||||
providers.add( eg );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
providers.add(eg);
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
final IEnergyGrid eg = this.outerProxy.getEnergy();
|
||||
try {
|
||||
final IEnergyGrid eg = this.outerProxy.getEnergy();
|
||||
|
||||
providers.add( eg );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
providers.add(eg);
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
|
||||
return providers;
|
||||
}
|
||||
return providers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double extractProviderPower( final double amt, final Actionable mode )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public double extractProviderPower(final double amt, final Actionable mode) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double injectProviderPower( final double amt, final Actionable mode )
|
||||
{
|
||||
return amt;
|
||||
}
|
||||
@Override
|
||||
public double injectProviderPower(final double amt, final Actionable mode) {
|
||||
return amt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getProviderEnergyDemand( final double amt )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public double getProviderEnergyDemand(final double amt) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getProviderStoredEnergy()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public double getProviderStoredEnergy() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getProviderMaxEnergy()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public double getProviderMaxEnergy() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return MODELS;
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return MODELS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,63 +19,53 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.parts.PartModel;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Helper for maintaining the models used for a variant of the P2P bus.
|
||||
*/
|
||||
class P2PModels
|
||||
{
|
||||
class P2PModels {
|
||||
|
||||
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation( AppEng.MOD_ID, "part/p2p/p2p_tunnel_status_off" );
|
||||
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation( AppEng.MOD_ID, "part/p2p/p2p_tunnel_status_on" );
|
||||
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation( AppEng.MOD_ID, "part/p2p/p2p_tunnel_status_has_channel" );
|
||||
public static final ResourceLocation MODEL_FREQUENCY = new ResourceLocation( AppEng.MOD_ID, "part/builtin/p2p_tunnel_frequency" );
|
||||
public static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation(AppEng.MOD_ID, "part/p2p/p2p_tunnel_status_off");
|
||||
public static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation(AppEng.MOD_ID, "part/p2p/p2p_tunnel_status_on");
|
||||
public static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation(AppEng.MOD_ID, "part/p2p/p2p_tunnel_status_has_channel");
|
||||
public static final ResourceLocation MODEL_FREQUENCY = new ResourceLocation(AppEng.MOD_ID, "part/builtin/p2p_tunnel_frequency");
|
||||
|
||||
private final IPartModel modelsOff;
|
||||
private final IPartModel modelsOn;
|
||||
private final IPartModel modelsHasChannel;
|
||||
private final IPartModel modelsOff;
|
||||
private final IPartModel modelsOn;
|
||||
private final IPartModel modelsHasChannel;
|
||||
|
||||
public P2PModels( String frontModelPath )
|
||||
{
|
||||
ResourceLocation frontModel = new ResourceLocation( AppEng.MOD_ID, frontModelPath );
|
||||
public P2PModels(String frontModelPath) {
|
||||
ResourceLocation frontModel = new ResourceLocation(AppEng.MOD_ID, frontModelPath);
|
||||
|
||||
this.modelsOff = new PartModel( MODEL_STATUS_OFF, MODEL_FREQUENCY, frontModel );
|
||||
this.modelsOn = new PartModel( MODEL_STATUS_ON, MODEL_FREQUENCY, frontModel );
|
||||
this.modelsHasChannel = new PartModel( MODEL_STATUS_HAS_CHANNEL, MODEL_FREQUENCY, frontModel );
|
||||
}
|
||||
this.modelsOff = new PartModel(MODEL_STATUS_OFF, MODEL_FREQUENCY, frontModel);
|
||||
this.modelsOn = new PartModel(MODEL_STATUS_ON, MODEL_FREQUENCY, frontModel);
|
||||
this.modelsHasChannel = new PartModel(MODEL_STATUS_HAS_CHANNEL, MODEL_FREQUENCY, frontModel);
|
||||
}
|
||||
|
||||
public IPartModel getModel( boolean hasPower, boolean hasChannel )
|
||||
{
|
||||
if( hasPower && hasChannel )
|
||||
{
|
||||
return this.modelsHasChannel;
|
||||
}
|
||||
else if( hasPower )
|
||||
{
|
||||
return this.modelsOn;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.modelsOff;
|
||||
}
|
||||
}
|
||||
public IPartModel getModel(boolean hasPower, boolean hasChannel) {
|
||||
if (hasPower && hasChannel) {
|
||||
return this.modelsHasChannel;
|
||||
} else if (hasPower) {
|
||||
return this.modelsOn;
|
||||
} else {
|
||||
return this.modelsOff;
|
||||
}
|
||||
}
|
||||
|
||||
public List<IPartModel> getModels()
|
||||
{
|
||||
List<IPartModel> result = new ArrayList<>();
|
||||
result.add( this.modelsOff );
|
||||
result.add( this.modelsOn );
|
||||
result.add( this.modelsHasChannel );
|
||||
return result;
|
||||
}
|
||||
public List<IPartModel> getModels() {
|
||||
List<IPartModel> result = new ArrayList<>();
|
||||
result.add(this.modelsOff);
|
||||
result.add(this.modelsOn);
|
||||
result.add(this.modelsHasChannel);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,305 +19,252 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.me.cache.helpers.TunnelCollection;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.capabilities.Capabilities;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.me.GridAccessException;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
|
||||
|
||||
public class PartP2PFEPower extends PartP2PTunnel<PartP2PFEPower>
|
||||
{
|
||||
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_fe" );
|
||||
private static final IEnergyStorage NULL_ENERGY_STORAGE = new NullEnergyStorage();
|
||||
private final IEnergyStorage inputHandler = new InputEnergyStorage();
|
||||
private final IEnergyStorage outputHandler = new OutputEnergyStorage();
|
||||
private final Queue<PartP2PFEPower> outputs = new ArrayDeque<>();
|
||||
public class PartP2PFEPower extends PartP2PTunnel<PartP2PFEPower> {
|
||||
private static final P2PModels MODELS = new P2PModels("part/p2p/p2p_tunnel_fe");
|
||||
private static final IEnergyStorage NULL_ENERGY_STORAGE = new NullEnergyStorage();
|
||||
private final IEnergyStorage inputHandler = new InputEnergyStorage();
|
||||
private final IEnergyStorage outputHandler = new OutputEnergyStorage();
|
||||
private final Queue<PartP2PFEPower> outputs = new ArrayDeque<>();
|
||||
|
||||
public PartP2PFEPower( ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
public PartP2PFEPower(ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels()
|
||||
{
|
||||
return MODELS.getModels();
|
||||
}
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels() {
|
||||
return MODELS.getModels();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return MODELS.getModel( this.isPowered(), this.isActive() );
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return MODELS.getModel(this.isPowered(), this.isActive());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
this.getHost().notifyNeighbors();
|
||||
}
|
||||
@Override
|
||||
public void onTunnelNetworkChange() {
|
||||
this.getHost().notifyNeighbors();
|
||||
}
|
||||
|
||||
private IEnergyStorage getAttachedEnergyStorage()
|
||||
{
|
||||
if( this.isActive() )
|
||||
{
|
||||
final TileEntity self = this.getTile();
|
||||
final TileEntity te = self.getWorld().getTileEntity( self.getPos().offset( this.getSide().getFacing() ) );
|
||||
private IEnergyStorage getAttachedEnergyStorage() {
|
||||
if (this.isActive()) {
|
||||
final TileEntity self = this.getTile();
|
||||
final TileEntity te = self.getWorld().getTileEntity(self.getPos().offset(this.getSide().getFacing()));
|
||||
|
||||
if( te != null && te.hasCapability( Capabilities.FORGE_ENERGY, this.getSide().getOpposite().getFacing() ) )
|
||||
{
|
||||
return te.getCapability( Capabilities.FORGE_ENERGY, this.getSide().getOpposite().getFacing() );
|
||||
}
|
||||
}
|
||||
return NULL_ENERGY_STORAGE;
|
||||
}
|
||||
if (te != null && te.hasCapability(Capabilities.FORGE_ENERGY, this.getSide().getOpposite().getFacing())) {
|
||||
return te.getCapability(Capabilities.FORGE_ENERGY, this.getSide().getOpposite().getFacing());
|
||||
}
|
||||
}
|
||||
return NULL_ENERGY_STORAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability( @Nonnull Capability<?> capability )
|
||||
{
|
||||
if( capability == Capabilities.FORGE_ENERGY )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return super.hasCapability( capability );
|
||||
}
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability) {
|
||||
if (capability == Capabilities.FORGE_ENERGY) {
|
||||
return true;
|
||||
}
|
||||
return super.hasCapability(capability);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T> T getCapability( @Nonnull Capability<T> capability )
|
||||
{
|
||||
if( capability == Capabilities.FORGE_ENERGY )
|
||||
{
|
||||
if( this.isOutput() )
|
||||
{
|
||||
return (T) this.outputHandler;
|
||||
}
|
||||
return (T) this.inputHandler;
|
||||
}
|
||||
return super.getCapability( capability );
|
||||
}
|
||||
@Nullable
|
||||
@Override
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability) {
|
||||
if (capability == Capabilities.FORGE_ENERGY) {
|
||||
if (this.isOutput()) {
|
||||
return (T) this.outputHandler;
|
||||
}
|
||||
return (T) this.inputHandler;
|
||||
}
|
||||
return super.getCapability(capability);
|
||||
}
|
||||
|
||||
private class InputEnergyStorage implements IEnergyStorage
|
||||
{
|
||||
private boolean iteratingOutputs;
|
||||
private class InputEnergyStorage implements IEnergyStorage {
|
||||
private boolean iteratingOutputs;
|
||||
|
||||
@Override
|
||||
public int extractEnergy( int maxExtract, boolean simulate )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int extractEnergy(int maxExtract, boolean simulate) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy( int maxReceive, boolean simulate )
|
||||
{
|
||||
int total = 0;
|
||||
@Override
|
||||
public int receiveEnergy(int maxReceive, boolean simulate) {
|
||||
int total = 0;
|
||||
|
||||
try
|
||||
{
|
||||
final int outputTunnels = PartP2PFEPower.this.getOutputs().size();
|
||||
try {
|
||||
final int outputTunnels = PartP2PFEPower.this.getOutputs().size();
|
||||
|
||||
if( outputTunnels == 0 | maxReceive == 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (outputTunnels == 0 | maxReceive == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
final int amountPerOutput = maxReceive / outputTunnels;
|
||||
int overflow = 0;
|
||||
final int amountPerOutput = maxReceive / outputTunnels;
|
||||
int overflow = 0;
|
||||
|
||||
for( PartP2PFEPower o : PartP2PFEPower.this.getOutputs() )
|
||||
outputs.add( o );
|
||||
for (PartP2PFEPower o : PartP2PFEPower.this.getOutputs())
|
||||
outputs.add(o);
|
||||
|
||||
while( !outputs.isEmpty() )
|
||||
{
|
||||
PartP2PFEPower target = outputs.poll();
|
||||
final IEnergyStorage output = target.getAttachedEnergyStorage();
|
||||
final int received = output.receiveEnergy( amountPerOutput, simulate );
|
||||
while (!outputs.isEmpty()) {
|
||||
PartP2PFEPower target = outputs.poll();
|
||||
final IEnergyStorage output = target.getAttachedEnergyStorage();
|
||||
final int received = output.receiveEnergy(amountPerOutput, simulate);
|
||||
|
||||
overflow += amountPerOutput - received;
|
||||
total += received;
|
||||
}
|
||||
overflow += amountPerOutput - received;
|
||||
total += received;
|
||||
}
|
||||
|
||||
if( overflow > 0 )
|
||||
{
|
||||
for( PartP2PFEPower o : PartP2PFEPower.this.getOutputs() )
|
||||
outputs.add( o );
|
||||
if (overflow > 0) {
|
||||
for (PartP2PFEPower o : PartP2PFEPower.this.getOutputs())
|
||||
outputs.add(o);
|
||||
|
||||
while( !outputs.isEmpty() )
|
||||
{
|
||||
PartP2PFEPower target = outputs.poll();
|
||||
final IEnergyStorage output = target.getAttachedEnergyStorage();
|
||||
final int received = output.receiveEnergy( overflow, simulate );
|
||||
while (!outputs.isEmpty()) {
|
||||
PartP2PFEPower target = outputs.poll();
|
||||
final IEnergyStorage output = target.getAttachedEnergyStorage();
|
||||
final int received = output.receiveEnergy(overflow, simulate);
|
||||
|
||||
overflow -= received;
|
||||
total += received;
|
||||
if( overflow == 0 )
|
||||
{
|
||||
outputs.clear();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
overflow -= received;
|
||||
total += received;
|
||||
if (overflow == 0) {
|
||||
outputs.clear();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !simulate )
|
||||
{
|
||||
PartP2PFEPower.this.queueTunnelDrain( PowerUnits.RF, total );
|
||||
}
|
||||
}
|
||||
catch( GridAccessException ignored )
|
||||
{
|
||||
}
|
||||
if (!simulate) {
|
||||
PartP2PFEPower.this.queueTunnelDrain(PowerUnits.RF, total);
|
||||
}
|
||||
} catch (GridAccessException ignored) {
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtract()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean canExtract() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceive()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean canReceive() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored()
|
||||
{
|
||||
int total = 0;
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
int total = 0;
|
||||
|
||||
try
|
||||
{
|
||||
for( PartP2PFEPower t : PartP2PFEPower.this.getOutputs() )
|
||||
{
|
||||
total += t.getAttachedEnergyStorage().getMaxEnergyStored();
|
||||
}
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
for (PartP2PFEPower t : PartP2PFEPower.this.getOutputs()) {
|
||||
total += t.getAttachedEnergyStorage().getMaxEnergyStored();
|
||||
}
|
||||
} catch (GridAccessException e) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored()
|
||||
{
|
||||
int total = 0;
|
||||
@Override
|
||||
public int getEnergyStored() {
|
||||
int total = 0;
|
||||
|
||||
try
|
||||
{
|
||||
for( PartP2PFEPower t : PartP2PFEPower.this.getOutputs() )
|
||||
{
|
||||
total += t.getAttachedEnergyStorage().getEnergyStored();
|
||||
}
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
for (PartP2PFEPower t : PartP2PFEPower.this.getOutputs()) {
|
||||
total += t.getAttachedEnergyStorage().getEnergyStored();
|
||||
}
|
||||
} catch (GridAccessException e) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
}
|
||||
|
||||
private class OutputEnergyStorage implements IEnergyStorage
|
||||
{
|
||||
@Override
|
||||
public int extractEnergy( int maxExtract, boolean simulate )
|
||||
{
|
||||
final int total = PartP2PFEPower.this.getAttachedEnergyStorage().extractEnergy( maxExtract, simulate );
|
||||
private class OutputEnergyStorage implements IEnergyStorage {
|
||||
@Override
|
||||
public int extractEnergy(int maxExtract, boolean simulate) {
|
||||
final int total = PartP2PFEPower.this.getAttachedEnergyStorage().extractEnergy(maxExtract, simulate);
|
||||
|
||||
if( !simulate )
|
||||
{
|
||||
PartP2PFEPower.this.queueTunnelDrain( PowerUnits.RF, total );
|
||||
}
|
||||
if (!simulate) {
|
||||
PartP2PFEPower.this.queueTunnelDrain(PowerUnits.RF, total);
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy( int maxReceive, boolean simulate )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int receiveEnergy(int maxReceive, boolean simulate) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtract()
|
||||
{
|
||||
return PartP2PFEPower.this.getAttachedEnergyStorage().canExtract();
|
||||
}
|
||||
@Override
|
||||
public boolean canExtract() {
|
||||
return PartP2PFEPower.this.getAttachedEnergyStorage().canExtract();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceive()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean canReceive() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored()
|
||||
{
|
||||
return PartP2PFEPower.this.getAttachedEnergyStorage().getMaxEnergyStored();
|
||||
}
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
return PartP2PFEPower.this.getAttachedEnergyStorage().getMaxEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored()
|
||||
{
|
||||
return PartP2PFEPower.this.getAttachedEnergyStorage().getEnergyStored();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getEnergyStored() {
|
||||
return PartP2PFEPower.this.getAttachedEnergyStorage().getEnergyStored();
|
||||
}
|
||||
}
|
||||
|
||||
private static class NullEnergyStorage implements IEnergyStorage
|
||||
{
|
||||
private static class NullEnergyStorage implements IEnergyStorage {
|
||||
|
||||
@Override
|
||||
public int receiveEnergy( int maxReceive, boolean simulate )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int receiveEnergy(int maxReceive, boolean simulate) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy( int maxExtract, boolean simulate )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int extractEnergy(int maxExtract, boolean simulate) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int getEnergyStored() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtract()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean canExtract() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceive()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean canReceive() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,9 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Deque;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.me.GridAccessException;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -37,290 +34,230 @@ import net.minecraftforge.fluids.capability.FluidTankProperties;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidTankProperties;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.me.GridAccessException;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class PartP2PFluids extends PartP2PTunnel<PartP2PFluids> implements IFluidHandler
|
||||
{
|
||||
public class PartP2PFluids extends PartP2PTunnel<PartP2PFluids> implements IFluidHandler {
|
||||
|
||||
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_fluids" );
|
||||
private static final P2PModels MODELS = new P2PModels("part/p2p/p2p_tunnel_fluids");
|
||||
|
||||
private static final ThreadLocal<Deque<PartP2PFluids>> DEPTH = new ThreadLocal<>();
|
||||
private static final FluidTankProperties[] ACTIVE_TANK = { new FluidTankProperties( null, 10000, true, false ) };
|
||||
private static final FluidTankProperties[] INACTIVE_TANK = { new FluidTankProperties( null, 0, false, false ) };
|
||||
private static final ThreadLocal<Deque<PartP2PFluids>> DEPTH = new ThreadLocal<>();
|
||||
private static final FluidTankProperties[] ACTIVE_TANK = {new FluidTankProperties(null, 10000, true, false)};
|
||||
private static final FluidTankProperties[] INACTIVE_TANK = {new FluidTankProperties(null, 0, false, false)};
|
||||
|
||||
private IFluidHandler cachedTank;
|
||||
private int tmpUsed;
|
||||
private IFluidHandler cachedTank;
|
||||
private int tmpUsed;
|
||||
|
||||
public PartP2PFluids( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
public PartP2PFluids(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels()
|
||||
{
|
||||
return MODELS.getModels();
|
||||
}
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels() {
|
||||
return MODELS.getModels();
|
||||
}
|
||||
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
return 2.0f;
|
||||
}
|
||||
public float getPowerDrainPerTick() {
|
||||
return 2.0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
this.cachedTank = null;
|
||||
}
|
||||
@Override
|
||||
public void onTunnelNetworkChange() {
|
||||
this.cachedTank = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged( IBlockAccess w, BlockPos pos, BlockPos neighbor )
|
||||
{
|
||||
this.cachedTank = null;
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockAccess w, BlockPos pos, BlockPos neighbor) {
|
||||
this.cachedTank = null;
|
||||
|
||||
if( this.isOutput() )
|
||||
{
|
||||
try
|
||||
{
|
||||
for( PartP2PFluids in : this.getInputs() )
|
||||
{
|
||||
if( in != null )
|
||||
{
|
||||
in.onTunnelNetworkChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.isOutput()) {
|
||||
try {
|
||||
for (PartP2PFluids in : this.getInputs()) {
|
||||
if (in != null) {
|
||||
in.onTunnelNetworkChange();
|
||||
}
|
||||
}
|
||||
} catch (GridAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability( Capability<?> capabilityClass )
|
||||
{
|
||||
if( capabilityClass == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capabilityClass) {
|
||||
if (capabilityClass == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.hasCapability( capabilityClass );
|
||||
}
|
||||
return super.hasCapability(capabilityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getCapability( Capability<T> capabilityClass )
|
||||
{
|
||||
if( capabilityClass == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY )
|
||||
{
|
||||
return (T) this;
|
||||
}
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capabilityClass) {
|
||||
if (capabilityClass == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
return super.getCapability( capabilityClass );
|
||||
}
|
||||
return super.getCapability(capabilityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return MODELS.getModel( this.isPowered(), this.isActive() );
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return MODELS.getModel(this.isPowered(), this.isActive());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFluidTankProperties[] getTankProperties()
|
||||
{
|
||||
if( !this.isOutput() )
|
||||
{
|
||||
try
|
||||
{
|
||||
for( PartP2PFluids tun : this.getInputs() )
|
||||
{
|
||||
if( tun != null )
|
||||
{
|
||||
return ACTIVE_TANK;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return INACTIVE_TANK;
|
||||
}
|
||||
@Override
|
||||
public IFluidTankProperties[] getTankProperties() {
|
||||
if (!this.isOutput()) {
|
||||
try {
|
||||
for (PartP2PFluids tun : this.getInputs()) {
|
||||
if (tun != null) {
|
||||
return ACTIVE_TANK;
|
||||
}
|
||||
}
|
||||
} catch (GridAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return INACTIVE_TANK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill( FluidStack resource, boolean doFill )
|
||||
{
|
||||
final Deque<PartP2PFluids> stack = this.getDepth();
|
||||
@Override
|
||||
public int fill(FluidStack resource, boolean doFill) {
|
||||
final Deque<PartP2PFluids> stack = this.getDepth();
|
||||
|
||||
for( final PartP2PFluids t : stack )
|
||||
{
|
||||
if( t == this )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
for (final PartP2PFluids t : stack) {
|
||||
if (t == this) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
stack.push( this );
|
||||
stack.push(this);
|
||||
|
||||
final List<PartP2PFluids> list = this.getOutputs( resource.getFluid() );
|
||||
int requestTotal = 0;
|
||||
final List<PartP2PFluids> list = this.getOutputs(resource.getFluid());
|
||||
int requestTotal = 0;
|
||||
|
||||
Iterator<PartP2PFluids> i = list.iterator();
|
||||
Iterator<PartP2PFluids> i = list.iterator();
|
||||
|
||||
while( i.hasNext() )
|
||||
{
|
||||
final PartP2PFluids l = i.next();
|
||||
final IFluidHandler tank = l.getTarget();
|
||||
if( tank != null )
|
||||
{
|
||||
l.tmpUsed = tank.fill( resource.copy(), false );
|
||||
}
|
||||
else
|
||||
{
|
||||
l.tmpUsed = 0;
|
||||
}
|
||||
while (i.hasNext()) {
|
||||
final PartP2PFluids l = i.next();
|
||||
final IFluidHandler tank = l.getTarget();
|
||||
if (tank != null) {
|
||||
l.tmpUsed = tank.fill(resource.copy(), false);
|
||||
} else {
|
||||
l.tmpUsed = 0;
|
||||
}
|
||||
|
||||
if( l.tmpUsed <= 0 )
|
||||
{
|
||||
i.remove();
|
||||
}
|
||||
else
|
||||
{
|
||||
requestTotal += l.tmpUsed;
|
||||
}
|
||||
}
|
||||
if (l.tmpUsed <= 0) {
|
||||
i.remove();
|
||||
} else {
|
||||
requestTotal += l.tmpUsed;
|
||||
}
|
||||
}
|
||||
|
||||
if( requestTotal <= 0 )
|
||||
{
|
||||
if( stack.pop() != this )
|
||||
{
|
||||
throw new IllegalStateException( "Invalid Recursion detected." );
|
||||
}
|
||||
if (requestTotal <= 0) {
|
||||
if (stack.pop() != this) {
|
||||
throw new IllegalStateException("Invalid Recursion detected.");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( !doFill )
|
||||
{
|
||||
if( stack.pop() != this )
|
||||
{
|
||||
throw new IllegalStateException( "Invalid Recursion detected." );
|
||||
}
|
||||
if (!doFill) {
|
||||
if (stack.pop() != this) {
|
||||
throw new IllegalStateException("Invalid Recursion detected.");
|
||||
}
|
||||
|
||||
return Math.min( resource.amount, requestTotal );
|
||||
}
|
||||
return Math.min(resource.amount, requestTotal);
|
||||
}
|
||||
|
||||
int available = resource.amount;
|
||||
int available = resource.amount;
|
||||
|
||||
i = list.iterator();
|
||||
int used = 0;
|
||||
i = list.iterator();
|
||||
int used = 0;
|
||||
|
||||
while( i.hasNext() && available > 0 )
|
||||
{
|
||||
final PartP2PFluids l = i.next();
|
||||
while (i.hasNext() && available > 0) {
|
||||
final PartP2PFluids l = i.next();
|
||||
|
||||
final FluidStack insert = resource.copy();
|
||||
insert.amount = (int) Math.ceil( insert.amount * ( (double) l.tmpUsed / (double) requestTotal ) );
|
||||
if( insert.amount > available )
|
||||
{
|
||||
insert.amount = available;
|
||||
}
|
||||
final FluidStack insert = resource.copy();
|
||||
insert.amount = (int) Math.ceil(insert.amount * ((double) l.tmpUsed / (double) requestTotal));
|
||||
if (insert.amount > available) {
|
||||
insert.amount = available;
|
||||
}
|
||||
|
||||
final IFluidHandler tank = l.getTarget();
|
||||
if( tank != null )
|
||||
{
|
||||
l.tmpUsed = tank.fill( insert.copy(), true );
|
||||
}
|
||||
else
|
||||
{
|
||||
l.tmpUsed = 0;
|
||||
}
|
||||
final IFluidHandler tank = l.getTarget();
|
||||
if (tank != null) {
|
||||
l.tmpUsed = tank.fill(insert.copy(), true);
|
||||
} else {
|
||||
l.tmpUsed = 0;
|
||||
}
|
||||
|
||||
available -= insert.amount;
|
||||
used += l.tmpUsed;
|
||||
}
|
||||
available -= insert.amount;
|
||||
used += l.tmpUsed;
|
||||
}
|
||||
|
||||
if( stack.pop() != this )
|
||||
{
|
||||
throw new IllegalStateException( "Invalid Recursion detected." );
|
||||
}
|
||||
if (stack.pop() != this) {
|
||||
throw new IllegalStateException("Invalid Recursion detected.");
|
||||
}
|
||||
|
||||
return used;
|
||||
}
|
||||
return used;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain( FluidStack resource, boolean doDrain )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public FluidStack drain(FluidStack resource, boolean doDrain) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain( int maxDrain, boolean doDrain )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public FluidStack drain(int maxDrain, boolean doDrain) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Deque<PartP2PFluids> getDepth()
|
||||
{
|
||||
Deque<PartP2PFluids> s = DEPTH.get();
|
||||
private Deque<PartP2PFluids> getDepth() {
|
||||
Deque<PartP2PFluids> s = DEPTH.get();
|
||||
|
||||
if( s == null )
|
||||
{
|
||||
DEPTH.set( s = new ArrayDeque<>() );
|
||||
}
|
||||
if (s == null) {
|
||||
DEPTH.set(s = new ArrayDeque<>());
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private List<PartP2PFluids> getOutputs( final Fluid input )
|
||||
{
|
||||
final List<PartP2PFluids> outs = new ArrayList<>();
|
||||
private List<PartP2PFluids> getOutputs(final Fluid input) {
|
||||
final List<PartP2PFluids> outs = new ArrayList<>();
|
||||
|
||||
try
|
||||
{
|
||||
for( final PartP2PFluids l : this.getOutputs() )
|
||||
{
|
||||
final IFluidHandler handler = l.getTarget();
|
||||
try {
|
||||
for (final PartP2PFluids l : this.getOutputs()) {
|
||||
final IFluidHandler handler = l.getTarget();
|
||||
|
||||
if( handler != null )
|
||||
{
|
||||
outs.add( l );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
if (handler != null) {
|
||||
outs.add(l);
|
||||
}
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
|
||||
return outs;
|
||||
}
|
||||
return outs;
|
||||
}
|
||||
|
||||
private IFluidHandler getTarget()
|
||||
{
|
||||
if( !this.getProxy().isActive() )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
private IFluidHandler getTarget() {
|
||||
if (!this.getProxy().isActive()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if( this.cachedTank != null )
|
||||
{
|
||||
return this.cachedTank;
|
||||
}
|
||||
if (this.cachedTank != null) {
|
||||
return this.cachedTank;
|
||||
}
|
||||
|
||||
final TileEntity te = this.getTile().getWorld().getTileEntity( this.getTile().getPos().offset( this.getSide().getFacing() ) );
|
||||
final TileEntity te = this.getTile().getWorld().getTileEntity(this.getTile().getPos().offset(this.getSide().getFacing()));
|
||||
|
||||
if( te != null && te.hasCapability( CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, this.getSide().getFacing().getOpposite() ) )
|
||||
{
|
||||
return this.cachedTank = te.getCapability( CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,
|
||||
this.getSide().getFacing().getOpposite() );
|
||||
}
|
||||
if (te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, this.getSide().getFacing().getOpposite())) {
|
||||
return this.cachedTank = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,
|
||||
this.getSide().getFacing().getOpposite());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.me.GridAccessException;
|
||||
@@ -12,245 +9,199 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.fml.common.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
|
||||
public class PartP2PGTCEPower extends PartP2PTunnel<PartP2PGTCEPower> {
|
||||
private static final P2PModels MODELS = new P2PModels("part/p2p/p2p_tunnel_gteu");
|
||||
private static final IEnergyContainer NULL_ENERGY_STORAGE = new NullEnergyStorage();
|
||||
private final IEnergyContainer inputHandler = new InputEnergyStorage();
|
||||
private final Queue<PartP2PGTCEPower> outputs = new ArrayDeque<>();
|
||||
|
||||
public class PartP2PGTCEPower extends PartP2PTunnel<PartP2PGTCEPower>
|
||||
{
|
||||
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_gteu" );
|
||||
private static final IEnergyContainer NULL_ENERGY_STORAGE = new NullEnergyStorage();
|
||||
private final IEnergyContainer inputHandler = new InputEnergyStorage();
|
||||
private final Queue<PartP2PGTCEPower> outputs = new ArrayDeque<>();
|
||||
public PartP2PGTCEPower(ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
public PartP2PGTCEPower( ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels() {
|
||||
return MODELS.getModels();
|
||||
}
|
||||
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels()
|
||||
{
|
||||
return MODELS.getModels();
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return MODELS.getModel(this.isPowered(), this.isActive());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return MODELS.getModel( this.isPowered(), this.isActive() );
|
||||
}
|
||||
@Override
|
||||
public void onTunnelNetworkChange() {
|
||||
this.getHost().notifyNeighbors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
this.getHost().notifyNeighbors();
|
||||
}
|
||||
private IEnergyContainer getAttachedEnergyStorage() {
|
||||
if (this.isActive()) {
|
||||
final TileEntity self = this.getTile();
|
||||
final TileEntity te = self.getWorld().getTileEntity(self.getPos().offset(this.getSide().getFacing()));
|
||||
|
||||
private IEnergyContainer getAttachedEnergyStorage()
|
||||
{
|
||||
if( this.isActive() )
|
||||
{
|
||||
final TileEntity self = this.getTile();
|
||||
final TileEntity te = self.getWorld().getTileEntity( self.getPos().offset( this.getSide().getFacing() ) );
|
||||
if (te != null && te.hasCapability(GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER, this.getSide().getOpposite().getFacing())) {
|
||||
return te.getCapability(GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER, this.getSide().getOpposite().getFacing());
|
||||
}
|
||||
}
|
||||
return NULL_ENERGY_STORAGE;
|
||||
}
|
||||
|
||||
if( te != null && te.hasCapability( GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER, this.getSide().getOpposite().getFacing() ) )
|
||||
{
|
||||
return te.getCapability( GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER, this.getSide().getOpposite().getFacing() );
|
||||
}
|
||||
}
|
||||
return NULL_ENERGY_STORAGE;
|
||||
}
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability) {
|
||||
if (!this.isOutput()) {
|
||||
if (capability == GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.hasCapability(capability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability( @Nonnull Capability<?> capability )
|
||||
{
|
||||
if( !this.isOutput() )
|
||||
{
|
||||
if( capability == GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.hasCapability( capability );
|
||||
}
|
||||
@Nullable
|
||||
@Override
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability) {
|
||||
if (capability == GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER) {
|
||||
if (this.isOutput()) {
|
||||
return null;
|
||||
}
|
||||
return (T) this.inputHandler;
|
||||
}
|
||||
return super.getCapability(capability);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <T> T getCapability( @Nonnull Capability<T> capability )
|
||||
{
|
||||
if( capability == GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER )
|
||||
{
|
||||
if( this.isOutput() )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return (T) this.inputHandler;
|
||||
}
|
||||
return super.getCapability( capability );
|
||||
}
|
||||
class InputEnergyStorage implements IEnergyContainer {
|
||||
@Override
|
||||
public long getEnergyCanBeInserted() {
|
||||
long canInsert = 0;
|
||||
if (outputs.isEmpty()) {
|
||||
try {
|
||||
for (PartP2PGTCEPower o : PartP2PGTCEPower.this.getOutputs())
|
||||
outputs.add(o);
|
||||
} catch (GridAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
class InputEnergyStorage implements IEnergyContainer
|
||||
{
|
||||
@Override
|
||||
public long getEnergyCanBeInserted()
|
||||
{
|
||||
long canInsert = 0;
|
||||
if( outputs.isEmpty() )
|
||||
{
|
||||
try
|
||||
{
|
||||
for( PartP2PGTCEPower o : PartP2PGTCEPower.this.getOutputs() )
|
||||
outputs.add( o );
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
while (!outputs.isEmpty()) {
|
||||
PartP2PGTCEPower target = outputs.poll();
|
||||
final IEnergyContainer output = target.getAttachedEnergyStorage();
|
||||
if (output == this) {
|
||||
return 0;
|
||||
}
|
||||
if (output == null || output.getEnergyCanBeInserted() <= 0) {
|
||||
continue;
|
||||
}
|
||||
canInsert += output.getEnergyCanBeInserted();
|
||||
}
|
||||
return canInsert;
|
||||
}
|
||||
|
||||
while ( !outputs.isEmpty() )
|
||||
{
|
||||
PartP2PGTCEPower target = outputs.poll();
|
||||
final IEnergyContainer output = target.getAttachedEnergyStorage();
|
||||
if( output == this )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if( output == null || output.getEnergyCanBeInserted() <= 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
canInsert += output.getEnergyCanBeInserted();
|
||||
}
|
||||
return canInsert;
|
||||
}
|
||||
@Override
|
||||
public long acceptEnergyFromNetwork(EnumFacing facing, long voltage, long amperage) {
|
||||
long amperesUsed = 0L;
|
||||
|
||||
@Override
|
||||
public long acceptEnergyFromNetwork( EnumFacing facing, long voltage, long amperage )
|
||||
{
|
||||
long amperesUsed = 0L;
|
||||
if (outputs.isEmpty()) {
|
||||
try {
|
||||
for (PartP2PGTCEPower o : PartP2PGTCEPower.this.getOutputs())
|
||||
outputs.add(o);
|
||||
} catch (GridAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if( outputs.isEmpty() )
|
||||
{
|
||||
try
|
||||
{
|
||||
for( PartP2PGTCEPower o : PartP2PGTCEPower.this.getOutputs() )
|
||||
outputs.add( o );
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
voltage = (long) (voltage * 0.95);
|
||||
|
||||
voltage = (long) ( voltage * 0.95 );
|
||||
if (voltage > 0) {
|
||||
while (!outputs.isEmpty()) {
|
||||
PartP2PGTCEPower target = outputs.poll();
|
||||
final IEnergyContainer output = target.getAttachedEnergyStorage();
|
||||
|
||||
if( voltage > 0 )
|
||||
{
|
||||
while ( !outputs.isEmpty() )
|
||||
{
|
||||
PartP2PGTCEPower target = outputs.poll();
|
||||
final IEnergyContainer output = target.getAttachedEnergyStorage();
|
||||
if (output == null || !output.inputsEnergy(target.getSide().getFacing().getOpposite()) || output.getEnergyCanBeInserted() <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( output == null || !output.inputsEnergy( target.getSide().getFacing().getOpposite() ) || output.getEnergyCanBeInserted() <= 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
amperesUsed += output.acceptEnergyFromNetwork(target.getSide().getFacing().getOpposite(), voltage, amperage - amperesUsed);
|
||||
|
||||
amperesUsed += output.acceptEnergyFromNetwork( target.getSide().getFacing().getOpposite(), voltage, amperage - amperesUsed );
|
||||
if (amperesUsed == amperage) {
|
||||
outputs.clear();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return amperesUsed;
|
||||
}
|
||||
|
||||
if( amperesUsed == amperage)
|
||||
{
|
||||
outputs.clear();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return amperesUsed;
|
||||
}
|
||||
@Override
|
||||
public boolean inputsEnergy(EnumFacing enumFacing) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inputsEnergy( EnumFacing enumFacing )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public long changeEnergy(long l) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long changeEnergy( long l )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public long getEnergyStored() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEnergyStored()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public long getEnergyCapacity() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEnergyCapacity()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public long getInputAmperage() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getInputAmperage()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public long getInputVoltage() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getInputVoltage()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
static class NullEnergyStorage implements IEnergyContainer {
|
||||
@Override
|
||||
public long acceptEnergyFromNetwork(EnumFacing enumFacing, long l, long l1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static class NullEnergyStorage implements IEnergyContainer
|
||||
{
|
||||
@Override
|
||||
public long acceptEnergyFromNetwork( EnumFacing enumFacing, long l, long l1 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public boolean inputsEnergy(EnumFacing enumFacing) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inputsEnergy( EnumFacing enumFacing )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public long changeEnergy(long l) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long changeEnergy( long l )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public long getEnergyStored() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEnergyStored()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public long getEnergyCapacity() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEnergyCapacity()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public long getInputAmperage() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getInputAmperage()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getInputVoltage()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public long getInputVoltage() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,269 +19,223 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import ic2.api.energy.prefab.BasicSinkSource;
|
||||
import ic2.api.energy.tile.IEnergyAcceptor;
|
||||
import ic2.api.energy.tile.IEnergyEmitter;
|
||||
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cache.helpers.TunnelCollection;
|
||||
import appeng.util.Platform;
|
||||
import ic2.api.energy.prefab.BasicSinkSource;
|
||||
import ic2.api.energy.tile.IEnergyAcceptor;
|
||||
import ic2.api.energy.tile.IEnergyEmitter;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power>
|
||||
{
|
||||
public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> {
|
||||
|
||||
private static final String TAG_BUFFERED_ENERGY_1 = "bufferedEnergy1";
|
||||
private static final String TAG_BUFFERED_ENERGY_2 = "bufferedEnergy2";
|
||||
private static final String TAG_BUFFERED_VOLTAGE_1 = "outputPacket1";
|
||||
private static final String TAG_BUFFERED_VOLTAGE_2 = "outputPacket2";
|
||||
private static final String TAG_BUFFERED_ENERGY_1 = "bufferedEnergy1";
|
||||
private static final String TAG_BUFFERED_ENERGY_2 = "bufferedEnergy2";
|
||||
private static final String TAG_BUFFERED_VOLTAGE_1 = "outputPacket1";
|
||||
private static final String TAG_BUFFERED_VOLTAGE_2 = "outputPacket2";
|
||||
|
||||
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_ic2" );
|
||||
private static final P2PModels MODELS = new P2PModels("part/p2p/p2p_tunnel_ic2");
|
||||
|
||||
// Buffer the energy + voltage for two IC2 ENET packets
|
||||
private double bufferedEnergy1;
|
||||
private double bufferedVoltage1;
|
||||
private double bufferedEnergy2;
|
||||
private double bufferedVoltage2;
|
||||
// Buffer the energy + voltage for two IC2 ENET packets
|
||||
private double bufferedEnergy1;
|
||||
private double bufferedVoltage1;
|
||||
private double bufferedEnergy2;
|
||||
private double bufferedVoltage2;
|
||||
|
||||
private BasicSinkSource sinkSource;
|
||||
private BasicSinkSource sinkSource;
|
||||
|
||||
public PartP2PIC2Power( ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
public PartP2PIC2Power(ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( NBTTagCompound tag )
|
||||
{
|
||||
super.readFromNBT( tag );
|
||||
this.bufferedEnergy1 = tag.getDouble( TAG_BUFFERED_ENERGY_1 );
|
||||
this.bufferedEnergy2 = tag.getDouble( TAG_BUFFERED_ENERGY_2 );
|
||||
this.bufferedVoltage1 = tag.getDouble( TAG_BUFFERED_VOLTAGE_1 );
|
||||
this.bufferedVoltage2 = tag.getDouble( TAG_BUFFERED_VOLTAGE_2 );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
this.bufferedEnergy1 = tag.getDouble(TAG_BUFFERED_ENERGY_1);
|
||||
this.bufferedEnergy2 = tag.getDouble(TAG_BUFFERED_ENERGY_2);
|
||||
this.bufferedVoltage1 = tag.getDouble(TAG_BUFFERED_VOLTAGE_1);
|
||||
this.bufferedVoltage2 = tag.getDouble(TAG_BUFFERED_VOLTAGE_2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( NBTTagCompound tag )
|
||||
{
|
||||
super.writeToNBT( tag );
|
||||
tag.setDouble( TAG_BUFFERED_ENERGY_1, this.bufferedEnergy1 );
|
||||
tag.setDouble( TAG_BUFFERED_ENERGY_2, this.bufferedEnergy2 );
|
||||
tag.setDouble( TAG_BUFFERED_VOLTAGE_1, this.bufferedVoltage1 );
|
||||
tag.setDouble( TAG_BUFFERED_VOLTAGE_2, this.bufferedVoltage2 );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
tag.setDouble(TAG_BUFFERED_ENERGY_1, this.bufferedEnergy1);
|
||||
tag.setDouble(TAG_BUFFERED_ENERGY_2, this.bufferedEnergy2);
|
||||
tag.setDouble(TAG_BUFFERED_VOLTAGE_1, this.bufferedVoltage1);
|
||||
tag.setDouble(TAG_BUFFERED_VOLTAGE_2, this.bufferedVoltage2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelConfigChange()
|
||||
{
|
||||
this.updateSinkSource();
|
||||
this.getHost().partChanged();
|
||||
}
|
||||
@Override
|
||||
public void onTunnelConfigChange() {
|
||||
this.updateSinkSource();
|
||||
this.getHost().partChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
this.updateSinkSource();
|
||||
this.getHost().notifyNeighbors();
|
||||
}
|
||||
@Override
|
||||
public void onTunnelNetworkChange() {
|
||||
this.updateSinkSource();
|
||||
this.getHost().notifyNeighbors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFromWorld()
|
||||
{
|
||||
super.removeFromWorld();
|
||||
this.invalidateSinkSource();
|
||||
}
|
||||
@Override
|
||||
public void removeFromWorld() {
|
||||
super.removeFromWorld();
|
||||
this.invalidateSinkSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToWorld()
|
||||
{
|
||||
super.addToWorld();
|
||||
this.updateSinkSource();
|
||||
}
|
||||
@Override
|
||||
public void addToWorld() {
|
||||
super.addToWorld();
|
||||
this.updateSinkSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return MODELS.getModel( this.isPowered(), this.isActive() );
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return MODELS.getModel(this.isPowered(), this.isActive());
|
||||
}
|
||||
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels()
|
||||
{
|
||||
return MODELS.getModels();
|
||||
}
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels() {
|
||||
return MODELS.getModels();
|
||||
}
|
||||
|
||||
private void updateSinkSource()
|
||||
{
|
||||
if( this.sinkSource == null )
|
||||
{
|
||||
this.sinkSource = new SinkSource( this.getHost().getTile().getWorld(), this.getHost().getLocation().getPos(), 2048, 4, 4 );
|
||||
}
|
||||
private void updateSinkSource() {
|
||||
if (this.sinkSource == null) {
|
||||
this.sinkSource = new SinkSource(this.getHost().getTile().getWorld(), this.getHost().getLocation().getPos(), 2048, 4, 4);
|
||||
}
|
||||
|
||||
this.sinkSource.update();
|
||||
}
|
||||
this.sinkSource.update();
|
||||
}
|
||||
|
||||
private void invalidateSinkSource()
|
||||
{
|
||||
if( this.sinkSource != null )
|
||||
{
|
||||
this.sinkSource.invalidate();
|
||||
}
|
||||
}
|
||||
private void invalidateSinkSource() {
|
||||
if (this.sinkSource != null) {
|
||||
this.sinkSource.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private class SinkSource extends BasicSinkSource
|
||||
{
|
||||
private class SinkSource extends BasicSinkSource {
|
||||
|
||||
SinkSource( World world, BlockPos pos, int i, int j, int k )
|
||||
{
|
||||
super( world, pos, i, j, k );
|
||||
}
|
||||
SinkSource(World world, BlockPos pos, int i, int j, int k) {
|
||||
super(world, pos, i, j, k);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean emitsEnergyTo( IEnergyAcceptor receiver, EnumFacing side )
|
||||
{
|
||||
return PartP2PIC2Power.this.isOutput() && side == PartP2PIC2Power.this.getSide().getFacing();
|
||||
}
|
||||
@Override
|
||||
public boolean emitsEnergyTo(IEnergyAcceptor receiver, EnumFacing side) {
|
||||
return PartP2PIC2Power.this.isOutput() && side == PartP2PIC2Power.this.getSide().getFacing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom( IEnergyEmitter emitter, EnumFacing side )
|
||||
{
|
||||
return !PartP2PIC2Power.this.isOutput() && side == PartP2PIC2Power.this.getSide().getFacing();
|
||||
}
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(IEnergyEmitter emitter, EnumFacing side) {
|
||||
return !PartP2PIC2Power.this.isOutput() && side == PartP2PIC2Power.this.getSide().getFacing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDemandedEnergy()
|
||||
{
|
||||
if( PartP2PIC2Power.this.isOutput() )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public double getDemandedEnergy() {
|
||||
if (PartP2PIC2Power.this.isOutput()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
for( PartP2PIC2Power t : PartP2PIC2Power.this.getOutputs() )
|
||||
{
|
||||
if( t.bufferedEnergy1 <= 0.0001 || t.bufferedEnergy2 <= 0.0001 )
|
||||
{
|
||||
return 2048;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
for (PartP2PIC2Power t : PartP2PIC2Power.this.getOutputs()) {
|
||||
if (t.bufferedEnergy1 <= 0.0001 || t.bufferedEnergy2 <= 0.0001) {
|
||||
return 2048;
|
||||
}
|
||||
}
|
||||
} catch (GridAccessException e) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double injectEnergy( EnumFacing directionFrom, double amount, double voltage )
|
||||
{
|
||||
TunnelCollection<PartP2PIC2Power> outs;
|
||||
try
|
||||
{
|
||||
outs = PartP2PIC2Power.this.getOutputs();
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
return amount;
|
||||
}
|
||||
@Override
|
||||
public double injectEnergy(EnumFacing directionFrom, double amount, double voltage) {
|
||||
TunnelCollection<PartP2PIC2Power> outs;
|
||||
try {
|
||||
outs = PartP2PIC2Power.this.getOutputs();
|
||||
} catch (GridAccessException e) {
|
||||
return amount;
|
||||
}
|
||||
|
||||
if( outs.isEmpty() )
|
||||
{
|
||||
return amount;
|
||||
}
|
||||
if (outs.isEmpty()) {
|
||||
return amount;
|
||||
}
|
||||
|
||||
List<PartP2PIC2Power> options = new ArrayList<>();
|
||||
for( PartP2PIC2Power o : outs )
|
||||
{
|
||||
if( o.bufferedEnergy1 <= 0.01 )
|
||||
{
|
||||
options.add( o );
|
||||
}
|
||||
}
|
||||
List<PartP2PIC2Power> options = new ArrayList<>();
|
||||
for (PartP2PIC2Power o : outs) {
|
||||
if (o.bufferedEnergy1 <= 0.01) {
|
||||
options.add(o);
|
||||
}
|
||||
}
|
||||
|
||||
if( options.isEmpty() )
|
||||
{
|
||||
for( PartP2PIC2Power o : outs )
|
||||
{
|
||||
if( o.bufferedEnergy2 <= 0.01 )
|
||||
{
|
||||
options.add( o );
|
||||
}
|
||||
}
|
||||
}
|
||||
if (options.isEmpty()) {
|
||||
for (PartP2PIC2Power o : outs) {
|
||||
if (o.bufferedEnergy2 <= 0.01) {
|
||||
options.add(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( options.isEmpty() )
|
||||
{
|
||||
for( PartP2PIC2Power o : outs )
|
||||
{
|
||||
options.add( o );
|
||||
}
|
||||
}
|
||||
if (options.isEmpty()) {
|
||||
for (PartP2PIC2Power o : outs) {
|
||||
options.add(o);
|
||||
}
|
||||
}
|
||||
|
||||
if( options.isEmpty() )
|
||||
{
|
||||
return amount;
|
||||
}
|
||||
if (options.isEmpty()) {
|
||||
return amount;
|
||||
}
|
||||
|
||||
PartP2PIC2Power x = Platform.pickRandom( options );
|
||||
PartP2PIC2Power x = Platform.pickRandom(options);
|
||||
|
||||
if( x != null && x.bufferedEnergy1 <= 0.001 )
|
||||
{
|
||||
PartP2PIC2Power.this.queueTunnelDrain( PowerUnits.EU, amount );
|
||||
x.bufferedEnergy1 = amount;
|
||||
x.bufferedVoltage1 = voltage;
|
||||
return 0;
|
||||
}
|
||||
if (x != null && x.bufferedEnergy1 <= 0.001) {
|
||||
PartP2PIC2Power.this.queueTunnelDrain(PowerUnits.EU, amount);
|
||||
x.bufferedEnergy1 = amount;
|
||||
x.bufferedVoltage1 = voltage;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( x != null && x.bufferedEnergy2 <= 0.001 )
|
||||
{
|
||||
PartP2PIC2Power.this.queueTunnelDrain( PowerUnits.EU, amount );
|
||||
x.bufferedEnergy2 = amount;
|
||||
x.bufferedVoltage2 = voltage;
|
||||
return 0;
|
||||
}
|
||||
if (x != null && x.bufferedEnergy2 <= 0.001) {
|
||||
PartP2PIC2Power.this.queueTunnelDrain(PowerUnits.EU, amount);
|
||||
x.bufferedEnergy2 = amount;
|
||||
x.bufferedVoltage2 = voltage;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getOfferedEnergy()
|
||||
{
|
||||
if( PartP2PIC2Power.this.isOutput() )
|
||||
{
|
||||
return PartP2PIC2Power.this.bufferedEnergy1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public double getOfferedEnergy() {
|
||||
if (PartP2PIC2Power.this.isOutput()) {
|
||||
return PartP2PIC2Power.this.bufferedEnergy1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEnergy( double amount )
|
||||
{
|
||||
PartP2PIC2Power.this.bufferedEnergy1 -= amount;
|
||||
if( PartP2PIC2Power.this.bufferedEnergy1 < 0.001 )
|
||||
{
|
||||
PartP2PIC2Power.this.bufferedEnergy1 = PartP2PIC2Power.this.bufferedEnergy2;
|
||||
PartP2PIC2Power.this.bufferedEnergy2 = 0;
|
||||
@Override
|
||||
public void drawEnergy(double amount) {
|
||||
PartP2PIC2Power.this.bufferedEnergy1 -= amount;
|
||||
if (PartP2PIC2Power.this.bufferedEnergy1 < 0.001) {
|
||||
PartP2PIC2Power.this.bufferedEnergy1 = PartP2PIC2Power.this.bufferedEnergy2;
|
||||
PartP2PIC2Power.this.bufferedEnergy2 = 0;
|
||||
|
||||
PartP2PIC2Power.this.bufferedVoltage1 = PartP2PIC2Power.this.bufferedVoltage2;
|
||||
PartP2PIC2Power.this.bufferedVoltage2 = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
PartP2PIC2Power.this.bufferedVoltage1 = PartP2PIC2Power.this.bufferedVoltage2;
|
||||
PartP2PIC2Power.this.bufferedVoltage2 = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,19 +19,6 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.EmptyHandler;
|
||||
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
@@ -43,226 +30,190 @@ import appeng.me.GridAccessException;
|
||||
import appeng.me.cache.helpers.TunnelCollection;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.WrapperChainedItemHandler;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.EmptyHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements IItemHandler, IGridTickable
|
||||
{
|
||||
private static final float POWER_DRAIN = 2.0f;
|
||||
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_items" );
|
||||
private boolean partVisited = false;
|
||||
public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements IItemHandler, IGridTickable {
|
||||
private static final float POWER_DRAIN = 2.0f;
|
||||
private static final P2PModels MODELS = new P2PModels("part/p2p/p2p_tunnel_items");
|
||||
private boolean partVisited = false;
|
||||
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels()
|
||||
{
|
||||
return MODELS.getModels();
|
||||
}
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels() {
|
||||
return MODELS.getModels();
|
||||
}
|
||||
|
||||
private int oldSize = 0;
|
||||
private boolean requested;
|
||||
private IItemHandler cachedInv;
|
||||
private int oldSize = 0;
|
||||
private boolean requested;
|
||||
private IItemHandler cachedInv;
|
||||
|
||||
public PartP2PItems( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
public PartP2PItems(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged( IBlockAccess w, BlockPos pos, BlockPos neighbor )
|
||||
{
|
||||
this.cachedInv = null;
|
||||
try
|
||||
{
|
||||
if( this.isOutput() )
|
||||
{
|
||||
for( PartP2PItems input : this.getInputs() )
|
||||
{
|
||||
if( input != null )
|
||||
{
|
||||
input.onTunnelNetworkChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockAccess w, BlockPos pos, BlockPos neighbor) {
|
||||
this.cachedInv = null;
|
||||
try {
|
||||
if (this.isOutput()) {
|
||||
for (PartP2PItems input : this.getInputs()) {
|
||||
if (input != null) {
|
||||
input.onTunnelNetworkChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (GridAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private IItemHandler getDestination()
|
||||
{
|
||||
this.requested = true;
|
||||
private IItemHandler getDestination() {
|
||||
this.requested = true;
|
||||
|
||||
if( this.cachedInv != null )
|
||||
{
|
||||
return this.cachedInv;
|
||||
}
|
||||
if (this.cachedInv != null) {
|
||||
return this.cachedInv;
|
||||
}
|
||||
|
||||
final List<IItemHandler> outs = new ArrayList<IItemHandler>();
|
||||
final TunnelCollection<PartP2PItems> itemTunnels;
|
||||
final List<IItemHandler> outs = new ArrayList<IItemHandler>();
|
||||
final TunnelCollection<PartP2PItems> itemTunnels;
|
||||
|
||||
try
|
||||
{
|
||||
itemTunnels = this.getOutputs();
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
return EmptyHandler.INSTANCE;
|
||||
}
|
||||
try {
|
||||
itemTunnels = this.getOutputs();
|
||||
} catch (final GridAccessException e) {
|
||||
return EmptyHandler.INSTANCE;
|
||||
}
|
||||
|
||||
for( final PartP2PItems t : itemTunnels )
|
||||
{
|
||||
final IItemHandler inv = t.getOutputInv();
|
||||
if( inv != null && inv != this )
|
||||
{
|
||||
if( Platform.getRandomInt() % 2 == 0 )
|
||||
{
|
||||
outs.add( inv );
|
||||
}
|
||||
else
|
||||
{
|
||||
outs.add( 0, inv );
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final PartP2PItems t : itemTunnels) {
|
||||
final IItemHandler inv = t.getOutputInv();
|
||||
if (inv != null && inv != this) {
|
||||
if (Platform.getRandomInt() % 2 == 0) {
|
||||
outs.add(inv);
|
||||
} else {
|
||||
outs.add(0, inv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.cachedInv = new WrapperChainedItemHandler( outs.toArray( new IItemHandler[outs.size()] ) );
|
||||
}
|
||||
return this.cachedInv = new WrapperChainedItemHandler(outs.toArray(new IItemHandler[outs.size()]));
|
||||
}
|
||||
|
||||
private IItemHandler getOutputInv()
|
||||
{
|
||||
IItemHandler ret = null;
|
||||
if( !this.partVisited )
|
||||
{
|
||||
this.partVisited = true;
|
||||
if( this.getProxy().isActive() )
|
||||
{
|
||||
final EnumFacing facing = this.getSide().getFacing();
|
||||
final TileEntity te = this.getTile().getWorld().getTileEntity( this.getTile().getPos().offset( facing ) );
|
||||
private IItemHandler getOutputInv() {
|
||||
IItemHandler ret = null;
|
||||
if (!this.partVisited) {
|
||||
this.partVisited = true;
|
||||
if (this.getProxy().isActive()) {
|
||||
final EnumFacing facing = this.getSide().getFacing();
|
||||
final TileEntity te = this.getTile().getWorld().getTileEntity(this.getTile().getPos().offset(facing));
|
||||
|
||||
if( te != null && te.hasCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite() ) )
|
||||
{
|
||||
ret = te.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite() );
|
||||
}
|
||||
}
|
||||
this.partVisited = false;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
if (te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite())) {
|
||||
ret = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite());
|
||||
}
|
||||
}
|
||||
this.partVisited = false;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest( final IGridNode node )
|
||||
{
|
||||
return new TickingRequest( TickRates.ItemTunnel.getMin(), TickRates.ItemTunnel.getMax(), false, false );
|
||||
}
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(final IGridNode node) {
|
||||
return new TickingRequest(TickRates.ItemTunnel.getMin(), TickRates.ItemTunnel.getMax(), false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
|
||||
{
|
||||
final boolean wasReq = this.requested;
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
|
||||
final boolean wasReq = this.requested;
|
||||
|
||||
if( this.requested && this.cachedInv != null )
|
||||
{
|
||||
( (WrapperChainedItemHandler) this.cachedInv ).cycleOrder();
|
||||
}
|
||||
if (this.requested && this.cachedInv != null) {
|
||||
((WrapperChainedItemHandler) this.cachedInv).cycleOrder();
|
||||
}
|
||||
|
||||
this.requested = false;
|
||||
return wasReq ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
}
|
||||
this.requested = false;
|
||||
return wasReq ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
if( !this.isOutput() )
|
||||
{
|
||||
this.cachedInv = null;
|
||||
final int olderSize = this.oldSize;
|
||||
this.oldSize = this.getDestination().getSlots();
|
||||
if( olderSize != this.oldSize )
|
||||
{
|
||||
this.getHost().notifyNeighbors();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
for( PartP2PItems input : this.getInputs() )
|
||||
{
|
||||
if( input != null )
|
||||
{
|
||||
input.getHost().notifyNeighbors();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onTunnelNetworkChange() {
|
||||
if (!this.isOutput()) {
|
||||
this.cachedInv = null;
|
||||
final int olderSize = this.oldSize;
|
||||
this.oldSize = this.getDestination().getSlots();
|
||||
if (olderSize != this.oldSize) {
|
||||
this.getHost().notifyNeighbors();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
for (PartP2PItems input : this.getInputs()) {
|
||||
if (input != null) {
|
||||
input.getHost().notifyNeighbors();
|
||||
}
|
||||
}
|
||||
} catch (GridAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability( Capability<?> capabilityClass )
|
||||
{
|
||||
if( capabilityClass == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capabilityClass) {
|
||||
if (capabilityClass == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.hasCapability( capabilityClass );
|
||||
}
|
||||
return super.hasCapability(capabilityClass);
|
||||
}
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
@Override
|
||||
public <T> T getCapability( Capability<T> capabilityClass )
|
||||
{
|
||||
if( capabilityClass == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY )
|
||||
{
|
||||
return (T) this;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capabilityClass) {
|
||||
if (capabilityClass == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
return super.getCapability( capabilityClass );
|
||||
}
|
||||
return super.getCapability(capabilityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
return this.getDestination().getSlots();
|
||||
}
|
||||
@Override
|
||||
public int getSlots() {
|
||||
return this.getDestination().getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot( final int i )
|
||||
{
|
||||
return this.getDestination().getStackInSlot( i );
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStackInSlot(final int i) {
|
||||
return this.getDestination().getStackInSlot(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack insertItem( final int slot, final ItemStack stack, boolean simulate )
|
||||
{
|
||||
return this.getDestination().insertItem( slot, stack, simulate );
|
||||
}
|
||||
@Override
|
||||
public ItemStack insertItem(final int slot, final ItemStack stack, boolean simulate) {
|
||||
return this.getDestination().insertItem(slot, stack, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack extractItem( final int slot, final int amount, boolean simulate )
|
||||
{
|
||||
return this.getDestination().extractItem( slot, amount, simulate );
|
||||
}
|
||||
@Override
|
||||
public ItemStack extractItem(final int slot, final int amount, boolean simulate) {
|
||||
return this.getDestination().extractItem(slot, amount, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit( int slot )
|
||||
{
|
||||
return this.getDestination().getSlotLimit( slot );
|
||||
}
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
return this.getDestination().getSlotLimit(slot);
|
||||
}
|
||||
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
return POWER_DRAIN;
|
||||
}
|
||||
public float getPowerDrainPerTick() {
|
||||
return POWER_DRAIN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return MODELS.getModel( this.isPowered(), this.isActive() );
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return MODELS.getModel(this.isPowered(), this.isActive());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,18 +19,6 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
@@ -39,200 +27,171 @@ import appeng.api.parts.IPartModel;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.me.GridAccessException;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTickable
|
||||
{
|
||||
public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTickable {
|
||||
|
||||
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_light" );
|
||||
private static final P2PModels MODELS = new P2PModels("part/p2p/p2p_tunnel_light");
|
||||
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels()
|
||||
{
|
||||
return MODELS.getModels();
|
||||
}
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels() {
|
||||
return MODELS.getModels();
|
||||
}
|
||||
|
||||
private int lastValue = 0;
|
||||
private int opacity = -1;
|
||||
private int lastValue = 0;
|
||||
private int opacity = -1;
|
||||
|
||||
public PartP2PLight( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
public PartP2PLight(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream( final ByteBuf data ) throws IOException
|
||||
{
|
||||
super.writeToStream( data );
|
||||
data.writeInt( this.isOutput() ? this.lastValue : 0 );
|
||||
data.writeInt( this.opacity );
|
||||
}
|
||||
@Override
|
||||
public void writeToStream(final ByteBuf data) throws IOException {
|
||||
super.writeToStream(data);
|
||||
data.writeInt(this.isOutput() ? this.lastValue : 0);
|
||||
data.writeInt(this.opacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream( final ByteBuf data ) throws IOException
|
||||
{
|
||||
super.readFromStream( data );
|
||||
final int oldValue = this.lastValue;
|
||||
final int oldOpacity = this.opacity;
|
||||
@Override
|
||||
public boolean readFromStream(final ByteBuf data) throws IOException {
|
||||
super.readFromStream(data);
|
||||
final int oldValue = this.lastValue;
|
||||
final int oldOpacity = this.opacity;
|
||||
|
||||
this.lastValue = data.readInt();
|
||||
this.opacity = data.readInt();
|
||||
this.lastValue = data.readInt();
|
||||
this.opacity = data.readInt();
|
||||
|
||||
this.setOutput( this.lastValue > 0 );
|
||||
return this.lastValue != oldValue || oldOpacity != this.opacity;
|
||||
}
|
||||
this.setOutput(this.lastValue > 0);
|
||||
return this.lastValue != oldValue || oldOpacity != this.opacity;
|
||||
}
|
||||
|
||||
private boolean doWork()
|
||||
{
|
||||
if( this.isOutput() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
private boolean doWork() {
|
||||
if (this.isOutput()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final TileEntity te = this.getTile();
|
||||
final World w = te.getWorld();
|
||||
final TileEntity te = this.getTile();
|
||||
final World w = te.getWorld();
|
||||
|
||||
final int newLevel = w.getLightFromNeighbors( te.getPos().offset( this.getSide().getFacing() ) );
|
||||
final int newLevel = w.getLightFromNeighbors(te.getPos().offset(this.getSide().getFacing()));
|
||||
|
||||
if( this.lastValue != newLevel && this.getProxy().isActive() )
|
||||
{
|
||||
this.lastValue = newLevel;
|
||||
try
|
||||
{
|
||||
int light = 0;
|
||||
for( PartP2PLight src : this.getInputs() )
|
||||
{
|
||||
if( src != null && src.getProxy().isActive() )
|
||||
{
|
||||
light = Math.max( light, src.lastValue );
|
||||
}
|
||||
}
|
||||
for( final PartP2PLight out : this.getOutputs() )
|
||||
{
|
||||
out.setLightLevel( light );
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (this.lastValue != newLevel && this.getProxy().isActive()) {
|
||||
this.lastValue = newLevel;
|
||||
try {
|
||||
int light = 0;
|
||||
for (PartP2PLight src : this.getInputs()) {
|
||||
if (src != null && src.getProxy().isActive()) {
|
||||
light = Math.max(light, src.lastValue);
|
||||
}
|
||||
}
|
||||
for (final PartP2PLight out : this.getOutputs()) {
|
||||
out.setLightLevel(light);
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged( IBlockAccess w, BlockPos pos, BlockPos neighbor )
|
||||
{
|
||||
if( this.isOutput() && pos.offset( this.getSide().getFacing() ).equals( neighbor ) )
|
||||
{
|
||||
this.opacity = -1;
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.doWork();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockAccess w, BlockPos pos, BlockPos neighbor) {
|
||||
if (this.isOutput() && pos.offset(this.getSide().getFacing()).equals(neighbor)) {
|
||||
this.opacity = -1;
|
||||
this.getHost().markForUpdate();
|
||||
} else {
|
||||
this.doWork();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightLevel()
|
||||
{
|
||||
if( this.isOutput() && this.isPowered() )
|
||||
{
|
||||
return this.blockLight( this.lastValue );
|
||||
}
|
||||
@Override
|
||||
public int getLightLevel() {
|
||||
if (this.isOutput() && this.isPowered()) {
|
||||
return this.blockLight(this.lastValue);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void setLightLevel( final int out )
|
||||
{
|
||||
this.lastValue = out;
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
private void setLightLevel(final int out) {
|
||||
this.lastValue = out;
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
private int blockLight( final int emit )
|
||||
{
|
||||
if( this.opacity < 0 )
|
||||
{
|
||||
final TileEntity te = this.getTile();
|
||||
this.opacity = 255 - te.getWorld().getBlockLightOpacity( te.getPos().offset( this.getSide().getFacing() ) );
|
||||
}
|
||||
private int blockLight(final int emit) {
|
||||
if (this.opacity < 0) {
|
||||
final TileEntity te = this.getTile();
|
||||
this.opacity = 255 - te.getWorld().getBlockLightOpacity(te.getPos().offset(this.getSide().getFacing()));
|
||||
}
|
||||
|
||||
return (int) ( emit * ( this.opacity / 255.0f ) );
|
||||
}
|
||||
return (int) (emit * (this.opacity / 255.0f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound tag )
|
||||
{
|
||||
super.readFromNBT( tag );
|
||||
this.lastValue = tag.getInteger( "lastValue" );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
this.lastValue = tag.getInteger("lastValue");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound tag )
|
||||
{
|
||||
super.writeToNBT( tag );
|
||||
tag.setInteger( "lastValue", this.lastValue );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
tag.setInteger("lastValue", this.lastValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelConfigChange()
|
||||
{
|
||||
this.onTunnelNetworkChange();
|
||||
}
|
||||
@Override
|
||||
public void onTunnelConfigChange() {
|
||||
this.onTunnelNetworkChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
if( this.isOutput() )
|
||||
{
|
||||
try
|
||||
{
|
||||
int light = 0;
|
||||
for( PartP2PLight src : this.getInputs() )
|
||||
{
|
||||
if( src != null && src.getProxy().isActive() )
|
||||
{
|
||||
light = Math.max( light, src.lastValue );
|
||||
}
|
||||
}
|
||||
this.setLightLevel( light );
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.doWork();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onTunnelNetworkChange() {
|
||||
if (this.isOutput()) {
|
||||
try {
|
||||
int light = 0;
|
||||
for (PartP2PLight src : this.getInputs()) {
|
||||
if (src != null && src.getProxy().isActive()) {
|
||||
light = Math.max(light, src.lastValue);
|
||||
}
|
||||
}
|
||||
this.setLightLevel(light);
|
||||
this.getHost().markForUpdate();
|
||||
} catch (GridAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
this.doWork();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest( final IGridNode node )
|
||||
{
|
||||
return new TickingRequest( TickRates.LightTunnel.getMin(), TickRates.LightTunnel.getMax(), false, false );
|
||||
}
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(final IGridNode node) {
|
||||
return new TickingRequest(TickRates.LightTunnel.getMin(), TickRates.LightTunnel.getMax(), false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
|
||||
{
|
||||
return this.doWork() ? TickRateModulation.URGENT : TickRateModulation.SLOWER;
|
||||
}
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
|
||||
return this.doWork() ? TickRateModulation.URGENT : TickRateModulation.SLOWER;
|
||||
}
|
||||
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
return 0.5f;
|
||||
}
|
||||
public float getPowerDrainPerTick() {
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return MODELS.getModel( this.isPowered(), this.isActive() );
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return MODELS.getModel(this.isPowered(), this.isActive());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,8 +19,10 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRedstoneWire;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -31,200 +33,154 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.util.Platform;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class PartP2PRedstone extends PartP2PTunnel<PartP2PRedstone>
|
||||
{
|
||||
public class PartP2PRedstone extends PartP2PTunnel<PartP2PRedstone> {
|
||||
|
||||
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_redstone" );
|
||||
private static final P2PModels MODELS = new P2PModels("part/p2p/p2p_tunnel_redstone");
|
||||
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels()
|
||||
{
|
||||
return MODELS.getModels();
|
||||
}
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels() {
|
||||
return MODELS.getModels();
|
||||
}
|
||||
|
||||
private int power;
|
||||
private boolean recursive = false;
|
||||
private int power;
|
||||
private boolean recursive = false;
|
||||
|
||||
public PartP2PRedstone( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
public PartP2PRedstone(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
private void setNetworkReady()
|
||||
{
|
||||
if( this.isOutput() )
|
||||
{
|
||||
try
|
||||
{
|
||||
int power = 0;
|
||||
for( PartP2PRedstone in : this.getInputs() )
|
||||
{
|
||||
if( in != null )
|
||||
{
|
||||
power = Math.max( power, in.power );
|
||||
}
|
||||
}
|
||||
this.putInput( power );
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void setNetworkReady() {
|
||||
if (this.isOutput()) {
|
||||
try {
|
||||
int power = 0;
|
||||
for (PartP2PRedstone in : this.getInputs()) {
|
||||
if (in != null) {
|
||||
power = Math.max(power, in.power);
|
||||
}
|
||||
}
|
||||
this.putInput(power);
|
||||
} catch (GridAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void putInput( final Object o )
|
||||
{
|
||||
if( this.recursive )
|
||||
{
|
||||
return;
|
||||
}
|
||||
private void putInput(final Object o) {
|
||||
if (this.recursive) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.recursive = true;
|
||||
if( this.isOutput() )
|
||||
{
|
||||
if( this.getProxy().isActive() )
|
||||
{
|
||||
final int newPower = (Integer) o;
|
||||
if( this.power != newPower )
|
||||
{
|
||||
this.power = newPower;
|
||||
this.notifyNeighbors();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.power = 0;
|
||||
this.notifyNeighbors();
|
||||
}
|
||||
}
|
||||
this.recursive = false;
|
||||
}
|
||||
this.recursive = true;
|
||||
if (this.isOutput()) {
|
||||
if (this.getProxy().isActive()) {
|
||||
final int newPower = (Integer) o;
|
||||
if (this.power != newPower) {
|
||||
this.power = newPower;
|
||||
this.notifyNeighbors();
|
||||
}
|
||||
} else {
|
||||
this.power = 0;
|
||||
this.notifyNeighbors();
|
||||
}
|
||||
}
|
||||
this.recursive = false;
|
||||
}
|
||||
|
||||
private void notifyNeighbors()
|
||||
{
|
||||
final World world = this.getTile().getWorld();
|
||||
private void notifyNeighbors() {
|
||||
final World world = this.getTile().getWorld();
|
||||
|
||||
Platform.notifyBlocksOfNeighbors( world, this.getTile().getPos() );
|
||||
Platform.notifyBlocksOfNeighbors(world, this.getTile().getPos());
|
||||
|
||||
// and this cause sometimes it can go thought walls.
|
||||
for( final EnumFacing face : EnumFacing.VALUES )
|
||||
{
|
||||
Platform.notifyBlocksOfNeighbors( world, this.getTile().getPos().offset( face ) );
|
||||
}
|
||||
}
|
||||
// and this cause sometimes it can go thought walls.
|
||||
for (final EnumFacing face : EnumFacing.VALUES) {
|
||||
Platform.notifyBlocksOfNeighbors(world, this.getTile().getPos().offset(face));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound tag )
|
||||
{
|
||||
super.readFromNBT( tag );
|
||||
this.power = tag.getInteger( "power" );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
this.power = tag.getInteger("power");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound tag )
|
||||
{
|
||||
super.writeToNBT( tag );
|
||||
tag.setInteger( "power", this.power );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
tag.setInteger("power", this.power);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
this.setNetworkReady();
|
||||
}
|
||||
@Override
|
||||
public void onTunnelNetworkChange() {
|
||||
this.setNetworkReady();
|
||||
}
|
||||
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
return 0.5f;
|
||||
}
|
||||
public float getPowerDrainPerTick() {
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged( IBlockAccess w, BlockPos pos, BlockPos neighbor )
|
||||
{
|
||||
if( !this.isOutput() )
|
||||
{
|
||||
final BlockPos target = this.getTile().getPos().offset( this.getSide().getFacing() );
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockAccess w, BlockPos pos, BlockPos neighbor) {
|
||||
if (!this.isOutput()) {
|
||||
final BlockPos target = this.getTile().getPos().offset(this.getSide().getFacing());
|
||||
|
||||
final IBlockState state = this.getTile().getWorld().getBlockState( target );
|
||||
final Block b = state.getBlock();
|
||||
if( b != null && !this.isOutput() )
|
||||
{
|
||||
EnumFacing srcSide = this.getSide().getFacing();
|
||||
if( b instanceof BlockRedstoneWire )
|
||||
{
|
||||
srcSide = EnumFacing.UP;
|
||||
}
|
||||
final IBlockState state = this.getTile().getWorld().getBlockState(target);
|
||||
final Block b = state.getBlock();
|
||||
if (b != null && !this.isOutput()) {
|
||||
EnumFacing srcSide = this.getSide().getFacing();
|
||||
if (b instanceof BlockRedstoneWire) {
|
||||
srcSide = EnumFacing.UP;
|
||||
}
|
||||
|
||||
this.power = b.getWeakPower( state, this.getTile().getWorld(), target, srcSide );
|
||||
this.power = Math.max( this.power, b.getWeakPower( state, this.getTile().getWorld(), target, srcSide ) );
|
||||
int powerOut = this.power;
|
||||
try
|
||||
{
|
||||
for( PartP2PRedstone in : this.getInputs() )
|
||||
{
|
||||
if( in != null )
|
||||
{
|
||||
powerOut = Math.max( in.power, powerOut );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.sendToOutput( powerOut );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.sendToOutput( 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
this.power = b.getWeakPower(state, this.getTile().getWorld(), target, srcSide);
|
||||
this.power = Math.max(this.power, b.getWeakPower(state, this.getTile().getWorld(), target, srcSide));
|
||||
int powerOut = this.power;
|
||||
try {
|
||||
for (PartP2PRedstone in : this.getInputs()) {
|
||||
if (in != null) {
|
||||
powerOut = Math.max(in.power, powerOut);
|
||||
}
|
||||
}
|
||||
} catch (GridAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.sendToOutput(powerOut);
|
||||
} else {
|
||||
this.sendToOutput(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean canConnectRedstone() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower()
|
||||
{
|
||||
return this.isOutput() ? this.power : 0;
|
||||
}
|
||||
@Override
|
||||
public int isProvidingStrongPower() {
|
||||
return this.isOutput() ? this.power : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower()
|
||||
{
|
||||
return this.isOutput() ? this.power : 0;
|
||||
}
|
||||
@Override
|
||||
public int isProvidingWeakPower() {
|
||||
return this.isOutput() ? this.power : 0;
|
||||
}
|
||||
|
||||
private void sendToOutput( final int power )
|
||||
{
|
||||
try
|
||||
{
|
||||
for( final PartP2PRedstone rs : this.getOutputs() )
|
||||
{
|
||||
rs.putInput( power );
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
private void sendToOutput(final int power) {
|
||||
try {
|
||||
for (final PartP2PRedstone rs : this.getOutputs()) {
|
||||
rs.putInput(power);
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return MODELS.getModel( this.isPowered(), this.isActive() );
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return MODELS.getModel(this.isPowered(), this.isActive());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,23 +19,6 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
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 io.netty.buffer.ByteBuf;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
@@ -44,6 +27,10 @@ import appeng.api.config.TunnelType;
|
||||
import appeng.api.definitions.IParts;
|
||||
import appeng.api.implementations.items.IMemoryCard;
|
||||
import appeng.api.implementations.items.MemoryCardMessages;
|
||||
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.parts.IPart;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartItem;
|
||||
@@ -57,484 +44,415 @@ import appeng.me.cache.P2PCache;
|
||||
import appeng.me.cache.helpers.TunnelCollection;
|
||||
import appeng.parts.PartBasicState;
|
||||
import appeng.util.Platform;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
|
||||
public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
|
||||
{
|
||||
private final TunnelCollection type = new TunnelCollection<T>( null, this.getClass() );
|
||||
private boolean output;
|
||||
private short freq;
|
||||
|
||||
public PartP2PTunnel( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
|
||||
public TunnelCollection<T> getCollection( final Collection<PartP2PTunnel> collection, final Class<? extends PartP2PTunnel> c )
|
||||
{
|
||||
if( this.type.matches( c ) )
|
||||
{
|
||||
this.type.setSource( collection );
|
||||
return this.type;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public TunnelCollection<T> getInputs() throws GridAccessException
|
||||
{
|
||||
if( this.getProxy().isActive() && this.getFrequency() != 0 )
|
||||
{
|
||||
return (TunnelCollection<T>) this.getProxy().getP2P().getInputs( this.getFrequency(), this.getClass() );
|
||||
}
|
||||
return new TunnelCollection( new ArrayList(), this.getClass() );
|
||||
}
|
||||
|
||||
public TunnelCollection<T> getOutputs() throws GridAccessException
|
||||
{
|
||||
if( this.getProxy().isActive() )
|
||||
{
|
||||
return (TunnelCollection<T>) this.getProxy().getP2P().getOutputs( this.getFrequency(), this.getClass() );
|
||||
}
|
||||
return new TunnelCollection( new ArrayList(), this.getClass() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes( final 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 ItemStack getItemStack( final PartItemStack type )
|
||||
{
|
||||
if( type == PartItemStack.WORLD || type == PartItemStack.NETWORK || type == PartItemStack.WRENCH || type == PartItemStack.PICK )
|
||||
{
|
||||
return super.getItemStack( type );
|
||||
}
|
||||
|
||||
final Optional<ItemStack> maybeMEStack = AEApi.instance().definitions().parts().p2PTunnelME().maybeStack( 1 );
|
||||
if( maybeMEStack.isPresent() )
|
||||
{
|
||||
return maybeMEStack.get();
|
||||
}
|
||||
|
||||
return super.getItemStack( type );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.setOutput( data.getBoolean( "output" ) );
|
||||
this.freq = data.getShort( "freq" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
data.setBoolean( "output", this.isOutput() );
|
||||
data.setShort( "freq", this.getFrequency() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream( ByteBuf data ) throws IOException
|
||||
{
|
||||
final boolean c = super.readFromStream( data );
|
||||
final short oldf = this.freq;
|
||||
this.freq = data.readShort();
|
||||
return c || oldf != this.freq;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream( ByteBuf data ) throws IOException
|
||||
{
|
||||
super.writeToStream( data );
|
||||
data.writeShort( this.getFrequency() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void chanRender( final MENetworkChannelsChanged c )
|
||||
{
|
||||
this.onTunnelNetworkChange();
|
||||
super.chanRender( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.onTunnelNetworkChange();
|
||||
super.powerRender( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void bootingRender( final MENetworkBootingStatusChange bs )
|
||||
{
|
||||
this.onTunnelNetworkChange();
|
||||
super.bootingRender( bs );
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength( AECableType cable )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useStandardMemoryCard()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if( hand == EnumHand.OFF_HAND )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean pasteAsOutput = true;
|
||||
ItemStack is = player.getHeldItem( hand );
|
||||
if( is.isEmpty() )
|
||||
{
|
||||
pasteAsOutput = false;
|
||||
is = player.getHeldItemOffhand();
|
||||
}
|
||||
|
||||
// UniqueIdentifier id = GameRegistry.findUniqueIdentifierFor( is.getItem() );
|
||||
// AELog.info( "ID:" + id.toString() + " : " + is.getItemDamage() );
|
||||
|
||||
final TunnelType tt = AEApi.instance().registries().p2pTunnel().getTunnelTypeByItem( is );
|
||||
if( !is.isEmpty() && is.getItem() instanceof IMemoryCard )
|
||||
{
|
||||
final IMemoryCard mc = (IMemoryCard) is.getItem();
|
||||
final NBTTagCompound data = mc.getData( is );
|
||||
|
||||
final ItemStack newType = new ItemStack( data );
|
||||
final short freq = data.getShort( "freq" );
|
||||
|
||||
if( !newType.isEmpty() )
|
||||
{
|
||||
if( newType.getItem() instanceof IPartItem )
|
||||
{
|
||||
final IPart testPart = ( (IPartItem) newType.getItem() ).createPartFromItemStack( newType );
|
||||
if( testPart instanceof PartP2PTunnel )
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
this.getProxy().getP2P().removeTunnel( this, this.getFrequency() );
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.getHost().removePart( this.getSide(), true );
|
||||
|
||||
final AEPartLocation dir = this.getHost().addPart( newType, this.getSide(), player, hand );
|
||||
final IPart newBus = this.getHost().getPart( dir );
|
||||
|
||||
if( newBus instanceof PartP2PTunnel )
|
||||
{
|
||||
final PartP2PTunnel newTunnel = (PartP2PTunnel) newBus;
|
||||
|
||||
if( pasteAsOutput )
|
||||
{
|
||||
newTunnel.setOutput( true );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
final P2PCache p2p = newTunnel.getProxy().getP2P();
|
||||
p2p.updateFreq( newTunnel, freq );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
newTunnel.onTunnelNetworkChange();
|
||||
}
|
||||
|
||||
mc.notifyUser( player, MemoryCardMessages.SETTINGS_LOADED );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
mc.notifyUser( player, MemoryCardMessages.INVALID_MACHINE );
|
||||
}
|
||||
else if( tt != null ) // attunement
|
||||
{
|
||||
final ItemStack newType;
|
||||
|
||||
final IParts parts = AEApi.instance().definitions().parts();
|
||||
|
||||
switch ( tt )
|
||||
{
|
||||
case LIGHT:
|
||||
newType = parts.p2PTunnelLight().maybeStack( 1 ).orElse( ItemStack.EMPTY );
|
||||
break;
|
||||
|
||||
case FE_POWER:
|
||||
newType = parts.p2PTunnelFE().maybeStack( 1 ).orElse( ItemStack.EMPTY );
|
||||
break;
|
||||
|
||||
case GTEU_POWER:
|
||||
newType = parts.p2PTunnelGTEU().maybeStack( 1 ).orElse( ItemStack.EMPTY );
|
||||
break;
|
||||
|
||||
case FLUID:
|
||||
newType = parts.p2PTunnelFluids().maybeStack( 1 ).orElse( ItemStack.EMPTY );
|
||||
break;
|
||||
|
||||
case IC2_POWER:
|
||||
newType = parts.p2PTunnelEU().maybeStack( 1 ).orElse( ItemStack.EMPTY );
|
||||
break;
|
||||
|
||||
case ITEM:
|
||||
newType = parts.p2PTunnelItems().maybeStack( 1 ).orElse( ItemStack.EMPTY );
|
||||
break;
|
||||
|
||||
case ME:
|
||||
newType = parts.p2PTunnelME().maybeStack( 1 ).orElse( ItemStack.EMPTY );
|
||||
break;
|
||||
|
||||
case REDSTONE:
|
||||
newType = parts.p2PTunnelRedstone().maybeStack( 1 ).orElse( ItemStack.EMPTY );
|
||||
break;
|
||||
|
||||
/*
|
||||
* case COMPUTER_MESSAGE:
|
||||
* for( ItemStack stack : parts.p2PTunnelOpenComputers().maybeStack( 1 ).asSet() )
|
||||
* {
|
||||
* newType = stack;
|
||||
* }
|
||||
* break;
|
||||
*/
|
||||
|
||||
default:
|
||||
newType = ItemStack.EMPTY;
|
||||
break;
|
||||
}
|
||||
|
||||
if( !newType.isEmpty() && !ItemStack.areItemsEqual( newType, this.getItemStack() ) )
|
||||
{
|
||||
final boolean oldOutput = this.isOutput();
|
||||
final short myFreq = this.getFrequency();
|
||||
|
||||
try
|
||||
{
|
||||
this.getProxy().getP2P().removeTunnel( this, this.getFrequency() );
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.getHost().removePart( this.getSide(), false );
|
||||
|
||||
final AEPartLocation dir = this.getHost().addPart( newType, this.getSide(), player, hand );
|
||||
final IPart newBus = this.getHost().getPart( dir );
|
||||
|
||||
if( newBus instanceof PartP2PTunnel )
|
||||
{
|
||||
final PartP2PTunnel newTunnel = (PartP2PTunnel) newBus;
|
||||
newTunnel.setOutput( oldOutput );
|
||||
|
||||
try
|
||||
{
|
||||
final P2PCache p2p = newTunnel.getProxy().getP2P();
|
||||
p2p.updateFreq( newTunnel, myFreq );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
newTunnel.onTunnelNetworkChange();
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartShiftActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
|
||||
{
|
||||
final ItemStack is = player.inventory.getCurrentItem();
|
||||
if( !is.isEmpty() && is.getItem() instanceof IMemoryCard )
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
final IMemoryCard mc = (IMemoryCard) is.getItem();
|
||||
final NBTTagCompound data = mc.getData( is );
|
||||
final short storedFrequency = data.getShort( "freq" );
|
||||
|
||||
short newFreq = this.getFrequency();
|
||||
final boolean wasOutput = this.isOutput();
|
||||
this.setOutput( false );
|
||||
|
||||
final boolean needsNewFrequency = wasOutput || this.getFrequency() == 0 || storedFrequency == newFreq;
|
||||
|
||||
try
|
||||
{
|
||||
if( needsNewFrequency )
|
||||
{
|
||||
newFreq = this.getProxy().getP2P().newFrequency();
|
||||
|
||||
final ItemStack newType = this.getHost().getPart( this.getSide() ).getItemStack( PartItemStack.WRENCH );
|
||||
|
||||
try
|
||||
{
|
||||
this.getProxy().getP2P().removeTunnel( this, this.getFrequency() );
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.getHost().removePart( this.getSide(), false );
|
||||
|
||||
final AEPartLocation dir = this.getHost().addPart( newType, this.getSide(), player, hand );
|
||||
final IPart newBus = this.getHost().getPart( dir );
|
||||
|
||||
if( newBus instanceof PartP2PTunnel )
|
||||
{
|
||||
final PartP2PTunnel newTunnel = (PartP2PTunnel) newBus;
|
||||
newTunnel.setOutput( false );
|
||||
newTunnel.getProxy().getP2P().updateFreq( newTunnel, newFreq );
|
||||
|
||||
newTunnel.onTunnelNetworkChange();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getProxy().getP2P().updateFreq( this, newFreq );
|
||||
this.onTunnelNetworkChange();
|
||||
}
|
||||
Platform.notifyBlocksOfNeighbors( this.getTile().getWorld(), this.getTile().getPos() );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
this.onTunnelConfigChange();
|
||||
|
||||
final ItemStack p2pItem = this.getItemStack( PartItemStack.WRENCH );
|
||||
final String type = p2pItem.getUnlocalizedName();
|
||||
|
||||
p2pItem.writeToNBT( data );
|
||||
if( needsNewFrequency )
|
||||
{
|
||||
data.setShort( "freq", newFreq );
|
||||
}
|
||||
else
|
||||
{
|
||||
data.setShort( "freq", this.getFrequency() );
|
||||
}
|
||||
|
||||
final AEColor[] colors = Platform.p2p().toColors( this.getFrequency() );
|
||||
final int[] colorCode = new int[]{
|
||||
colors[0].ordinal(), colors[0].ordinal(),
|
||||
colors[1].ordinal(), colors[1].ordinal(),
|
||||
colors[2].ordinal(), colors[2].ordinal(),
|
||||
colors[3].ordinal(), colors[3].ordinal(),
|
||||
};
|
||||
|
||||
data.setIntArray( "colorCode", colorCode );
|
||||
|
||||
mc.setMemoryCardContents( is, type + ".name", data );
|
||||
if( needsNewFrequency )
|
||||
{
|
||||
mc.notifyUser( player, MemoryCardMessages.SETTINGS_RESET );
|
||||
}
|
||||
else
|
||||
{
|
||||
mc.notifyUser( player, MemoryCardMessages.SETTINGS_SAVED );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onTunnelConfigChange()
|
||||
{
|
||||
}
|
||||
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
}
|
||||
|
||||
protected void queueTunnelDrain( final PowerUnits unit, final double f )
|
||||
{
|
||||
final double ae_to_tax = unit.convertTo( PowerUnits.AE, f * AEConfig.TUNNEL_POWER_LOSS );
|
||||
|
||||
try
|
||||
{
|
||||
this.getProxy().getEnergy().extractAEPower( ae_to_tax, Actionable.MODULATE, PowerMultiplier.ONE );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
public short getFrequency()
|
||||
{
|
||||
return this.freq;
|
||||
}
|
||||
|
||||
public void setFrequency( final short freq )
|
||||
{
|
||||
final short oldf = this.freq;
|
||||
this.freq = freq;
|
||||
if( oldf != this.freq )
|
||||
{
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isOutput()
|
||||
{
|
||||
return this.output;
|
||||
}
|
||||
|
||||
void setOutput( final boolean output )
|
||||
{
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getRenderFlag()
|
||||
{
|
||||
long ret = Short.toUnsignedLong( this.getFrequency() );
|
||||
|
||||
if( this.isActive() && this.isPowered() )
|
||||
{
|
||||
ret |= 0x10000L;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public abstract class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState {
|
||||
private final TunnelCollection type = new TunnelCollection<T>(null, this.getClass());
|
||||
private boolean output;
|
||||
private short freq;
|
||||
|
||||
public PartP2PTunnel(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
public TunnelCollection<T> getCollection(final Collection<PartP2PTunnel> collection, final Class<? extends PartP2PTunnel> c) {
|
||||
if (this.type.matches(c)) {
|
||||
this.type.setSource(collection);
|
||||
return this.type;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public TunnelCollection<T> getInputs() throws GridAccessException {
|
||||
if (this.getProxy().isActive() && this.getFrequency() != 0) {
|
||||
return (TunnelCollection<T>) this.getProxy().getP2P().getInputs(this.getFrequency(), this.getClass());
|
||||
}
|
||||
return new TunnelCollection(new ArrayList(), this.getClass());
|
||||
}
|
||||
|
||||
public TunnelCollection<T> getOutputs() throws GridAccessException {
|
||||
if (this.getProxy().isActive()) {
|
||||
return (TunnelCollection<T>) this.getProxy().getP2P().getOutputs(this.getFrequency(), this.getClass());
|
||||
}
|
||||
return new TunnelCollection(new ArrayList(), this.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(final 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 ItemStack getItemStack(final PartItemStack type) {
|
||||
if (type == PartItemStack.WORLD || type == PartItemStack.NETWORK || type == PartItemStack.WRENCH || type == PartItemStack.PICK) {
|
||||
return super.getItemStack(type);
|
||||
}
|
||||
|
||||
final Optional<ItemStack> maybeMEStack = AEApi.instance().definitions().parts().p2PTunnelME().maybeStack(1);
|
||||
if (maybeMEStack.isPresent()) {
|
||||
return maybeMEStack.get();
|
||||
}
|
||||
|
||||
return super.getItemStack(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
this.setOutput(data.getBoolean("output"));
|
||||
this.freq = data.getShort("freq");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
data.setBoolean("output", this.isOutput());
|
||||
data.setShort("freq", this.getFrequency());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream(ByteBuf data) throws IOException {
|
||||
final boolean c = super.readFromStream(data);
|
||||
final short oldf = this.freq;
|
||||
this.freq = data.readShort();
|
||||
return c || oldf != this.freq;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(ByteBuf data) throws IOException {
|
||||
super.writeToStream(data);
|
||||
data.writeShort(this.getFrequency());
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void chanRender(final MENetworkChannelsChanged c) {
|
||||
this.onTunnelNetworkChange();
|
||||
super.chanRender(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerRender(final MENetworkPowerStatusChange c) {
|
||||
this.onTunnelNetworkChange();
|
||||
super.powerRender(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void bootingRender(final MENetworkBootingStatusChange bs) {
|
||||
this.onTunnelNetworkChange();
|
||||
super.bootingRender(bs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getCableConnectionLength(AECableType cable) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useStandardMemoryCard() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
|
||||
if (Platform.isClient()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hand == EnumHand.OFF_HAND) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean pasteAsOutput = true;
|
||||
ItemStack is = player.getHeldItem(hand);
|
||||
if (is.isEmpty()) {
|
||||
pasteAsOutput = false;
|
||||
is = player.getHeldItemOffhand();
|
||||
}
|
||||
|
||||
// UniqueIdentifier id = GameRegistry.findUniqueIdentifierFor( is.getItem() );
|
||||
// AELog.info( "ID:" + id.toString() + " : " + is.getItemDamage() );
|
||||
|
||||
final TunnelType tt = AEApi.instance().registries().p2pTunnel().getTunnelTypeByItem(is);
|
||||
if (!is.isEmpty() && is.getItem() instanceof IMemoryCard) {
|
||||
final IMemoryCard mc = (IMemoryCard) is.getItem();
|
||||
final NBTTagCompound data = mc.getData(is);
|
||||
|
||||
final ItemStack newType = new ItemStack(data);
|
||||
final short freq = data.getShort("freq");
|
||||
|
||||
if (!newType.isEmpty()) {
|
||||
if (newType.getItem() instanceof IPartItem) {
|
||||
final IPart testPart = ((IPartItem) newType.getItem()).createPartFromItemStack(newType);
|
||||
if (testPart instanceof PartP2PTunnel) {
|
||||
|
||||
try {
|
||||
this.getProxy().getP2P().removeTunnel(this, this.getFrequency());
|
||||
} catch (GridAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.getHost().removePart(this.getSide(), true);
|
||||
|
||||
final AEPartLocation dir = this.getHost().addPart(newType, this.getSide(), player, hand);
|
||||
final IPart newBus = this.getHost().getPart(dir);
|
||||
|
||||
if (newBus instanceof PartP2PTunnel) {
|
||||
final PartP2PTunnel newTunnel = (PartP2PTunnel) newBus;
|
||||
|
||||
if (pasteAsOutput) {
|
||||
newTunnel.setOutput(true);
|
||||
}
|
||||
|
||||
try {
|
||||
final P2PCache p2p = newTunnel.getProxy().getP2P();
|
||||
p2p.updateFreq(newTunnel, freq);
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
|
||||
newTunnel.onTunnelNetworkChange();
|
||||
}
|
||||
|
||||
mc.notifyUser(player, MemoryCardMessages.SETTINGS_LOADED);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
mc.notifyUser(player, MemoryCardMessages.INVALID_MACHINE);
|
||||
} else if (tt != null) // attunement
|
||||
{
|
||||
final ItemStack newType;
|
||||
|
||||
final IParts parts = AEApi.instance().definitions().parts();
|
||||
|
||||
switch (tt) {
|
||||
case LIGHT:
|
||||
newType = parts.p2PTunnelLight().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
break;
|
||||
|
||||
case FE_POWER:
|
||||
newType = parts.p2PTunnelFE().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
break;
|
||||
|
||||
case GTEU_POWER:
|
||||
newType = parts.p2PTunnelGTEU().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
break;
|
||||
|
||||
case FLUID:
|
||||
newType = parts.p2PTunnelFluids().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
break;
|
||||
|
||||
case IC2_POWER:
|
||||
newType = parts.p2PTunnelEU().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
break;
|
||||
|
||||
case ITEM:
|
||||
newType = parts.p2PTunnelItems().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
break;
|
||||
|
||||
case ME:
|
||||
newType = parts.p2PTunnelME().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
break;
|
||||
|
||||
case REDSTONE:
|
||||
newType = parts.p2PTunnelRedstone().maybeStack(1).orElse(ItemStack.EMPTY);
|
||||
break;
|
||||
|
||||
/*
|
||||
* case COMPUTER_MESSAGE:
|
||||
* for( ItemStack stack : parts.p2PTunnelOpenComputers().maybeStack( 1 ).asSet() )
|
||||
* {
|
||||
* newType = stack;
|
||||
* }
|
||||
* break;
|
||||
*/
|
||||
|
||||
default:
|
||||
newType = ItemStack.EMPTY;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!newType.isEmpty() && !ItemStack.areItemsEqual(newType, this.getItemStack())) {
|
||||
final boolean oldOutput = this.isOutput();
|
||||
final short myFreq = this.getFrequency();
|
||||
|
||||
try {
|
||||
this.getProxy().getP2P().removeTunnel(this, this.getFrequency());
|
||||
} catch (GridAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.getHost().removePart(this.getSide(), false);
|
||||
|
||||
final AEPartLocation dir = this.getHost().addPart(newType, this.getSide(), player, hand);
|
||||
final IPart newBus = this.getHost().getPart(dir);
|
||||
|
||||
if (newBus instanceof PartP2PTunnel) {
|
||||
final PartP2PTunnel newTunnel = (PartP2PTunnel) newBus;
|
||||
newTunnel.setOutput(oldOutput);
|
||||
|
||||
try {
|
||||
final P2PCache p2p = newTunnel.getProxy().getP2P();
|
||||
p2p.updateFreq(newTunnel, myFreq);
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
newTunnel.onTunnelNetworkChange();
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartShiftActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
|
||||
final ItemStack is = player.inventory.getCurrentItem();
|
||||
if (!is.isEmpty() && is.getItem() instanceof IMemoryCard) {
|
||||
if (Platform.isClient()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final IMemoryCard mc = (IMemoryCard) is.getItem();
|
||||
final NBTTagCompound data = mc.getData(is);
|
||||
final short storedFrequency = data.getShort("freq");
|
||||
|
||||
short newFreq = this.getFrequency();
|
||||
final boolean wasOutput = this.isOutput();
|
||||
this.setOutput(false);
|
||||
|
||||
final boolean needsNewFrequency = wasOutput || this.getFrequency() == 0 || storedFrequency == newFreq;
|
||||
|
||||
try {
|
||||
if (needsNewFrequency) {
|
||||
newFreq = this.getProxy().getP2P().newFrequency();
|
||||
|
||||
final ItemStack newType = this.getHost().getPart(this.getSide()).getItemStack(PartItemStack.WRENCH);
|
||||
|
||||
try {
|
||||
this.getProxy().getP2P().removeTunnel(this, this.getFrequency());
|
||||
} catch (GridAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
this.getHost().removePart(this.getSide(), false);
|
||||
|
||||
final AEPartLocation dir = this.getHost().addPart(newType, this.getSide(), player, hand);
|
||||
final IPart newBus = this.getHost().getPart(dir);
|
||||
|
||||
if (newBus instanceof PartP2PTunnel) {
|
||||
final PartP2PTunnel newTunnel = (PartP2PTunnel) newBus;
|
||||
newTunnel.setOutput(false);
|
||||
newTunnel.getProxy().getP2P().updateFreq(newTunnel, newFreq);
|
||||
|
||||
newTunnel.onTunnelNetworkChange();
|
||||
}
|
||||
} else {
|
||||
this.getProxy().getP2P().updateFreq(this, newFreq);
|
||||
this.onTunnelNetworkChange();
|
||||
}
|
||||
Platform.notifyBlocksOfNeighbors(this.getTile().getWorld(), this.getTile().getPos());
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
|
||||
this.onTunnelConfigChange();
|
||||
|
||||
final ItemStack p2pItem = this.getItemStack(PartItemStack.WRENCH);
|
||||
final String type = p2pItem.getUnlocalizedName();
|
||||
|
||||
p2pItem.writeToNBT(data);
|
||||
if (needsNewFrequency) {
|
||||
data.setShort("freq", newFreq);
|
||||
} else {
|
||||
data.setShort("freq", this.getFrequency());
|
||||
}
|
||||
|
||||
final AEColor[] colors = Platform.p2p().toColors(this.getFrequency());
|
||||
final int[] colorCode = new int[]{
|
||||
colors[0].ordinal(), colors[0].ordinal(),
|
||||
colors[1].ordinal(), colors[1].ordinal(),
|
||||
colors[2].ordinal(), colors[2].ordinal(),
|
||||
colors[3].ordinal(), colors[3].ordinal(),
|
||||
};
|
||||
|
||||
data.setIntArray("colorCode", colorCode);
|
||||
|
||||
mc.setMemoryCardContents(is, type + ".name", data);
|
||||
if (needsNewFrequency) {
|
||||
mc.notifyUser(player, MemoryCardMessages.SETTINGS_RESET);
|
||||
} else {
|
||||
mc.notifyUser(player, MemoryCardMessages.SETTINGS_SAVED);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onTunnelConfigChange() {
|
||||
}
|
||||
|
||||
public void onTunnelNetworkChange() {
|
||||
}
|
||||
|
||||
protected void queueTunnelDrain(final PowerUnits unit, final double f) {
|
||||
final double ae_to_tax = unit.convertTo(PowerUnits.AE, f * AEConfig.TUNNEL_POWER_LOSS);
|
||||
|
||||
try {
|
||||
this.getProxy().getEnergy().extractAEPower(ae_to_tax, Actionable.MODULATE, PowerMultiplier.ONE);
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
public short getFrequency() {
|
||||
return this.freq;
|
||||
}
|
||||
|
||||
public void setFrequency(final short freq) {
|
||||
final short oldf = this.freq;
|
||||
this.freq = freq;
|
||||
if (oldf != this.freq) {
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isOutput() {
|
||||
return this.output;
|
||||
}
|
||||
|
||||
void setOutput(final boolean output) {
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getRenderFlag() {
|
||||
long ret = Short.toUnsignedLong(this.getFrequency());
|
||||
|
||||
if (this.isActive() && this.isPowered()) {
|
||||
ret |= 0x10000L;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,17 +19,6 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
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.EnumHand;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.exceptions.FailedConnectionException;
|
||||
import appeng.api.networking.GridFlags;
|
||||
@@ -49,228 +38,188 @@ import appeng.me.GridAccessException;
|
||||
import appeng.me.cache.helpers.Connections;
|
||||
import appeng.me.cache.helpers.TunnelConnection;
|
||||
import appeng.me.helpers.AENetworkProxy;
|
||||
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.EnumHand;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements IGridTickable
|
||||
{
|
||||
public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements IGridTickable {
|
||||
|
||||
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_me" );
|
||||
private static final P2PModels MODELS = new P2PModels("part/p2p/p2p_tunnel_me");
|
||||
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels()
|
||||
{
|
||||
return MODELS.getModels();
|
||||
}
|
||||
@PartModels
|
||||
public static List<IPartModel> getModels() {
|
||||
return MODELS.getModels();
|
||||
}
|
||||
|
||||
private final Connections connection = new Connections( this );
|
||||
private final AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", ItemStack.EMPTY, true );
|
||||
private final Connections connection = new Connections(this);
|
||||
private final AENetworkProxy outerProxy = new AENetworkProxy(this, "outer", ItemStack.EMPTY, true);
|
||||
|
||||
public PartP2PTunnelME( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
this.getProxy().setFlags( GridFlags.REQUIRE_CHANNEL, GridFlags.COMPRESSED_CHANNEL );
|
||||
this.outerProxy.setFlags( GridFlags.DENSE_CAPACITY, GridFlags.CANNOT_CARRY_COMPRESSED );
|
||||
}
|
||||
public PartP2PTunnelME(final ItemStack is) {
|
||||
super(is);
|
||||
this.getProxy().setFlags(GridFlags.REQUIRE_CHANNEL, GridFlags.COMPRESSED_CHANNEL);
|
||||
this.outerProxy.setFlags(GridFlags.DENSE_CAPACITY, GridFlags.CANNOT_CARRY_COMPRESSED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound extra )
|
||||
{
|
||||
super.readFromNBT( extra );
|
||||
this.outerProxy.readFromNBT( extra );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound extra) {
|
||||
super.readFromNBT(extra);
|
||||
this.outerProxy.readFromNBT(extra);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound extra )
|
||||
{
|
||||
super.writeToNBT( extra );
|
||||
this.outerProxy.writeToNBT( extra );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound extra) {
|
||||
super.writeToNBT(extra);
|
||||
this.outerProxy.writeToNBT(extra);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
super.onTunnelNetworkChange();
|
||||
if( !this.isOutput() )
|
||||
{
|
||||
try
|
||||
{
|
||||
this.getProxy().getTick().wakeDevice( this.getProxy().getNode() );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onTunnelNetworkChange() {
|
||||
super.onTunnelNetworkChange();
|
||||
if (!this.isOutput()) {
|
||||
try {
|
||||
this.getProxy().getTick().wakeDevice(this.getProxy().getNode());
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType( final AEPartLocation dir )
|
||||
{
|
||||
return AECableType.DENSE_SMART;
|
||||
}
|
||||
@Override
|
||||
public AECableType getCableConnectionType(final AEPartLocation dir) {
|
||||
return AECableType.DENSE_SMART;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFromWorld()
|
||||
{
|
||||
super.removeFromWorld();
|
||||
this.outerProxy.invalidate();
|
||||
}
|
||||
@Override
|
||||
public void removeFromWorld() {
|
||||
super.removeFromWorld();
|
||||
this.outerProxy.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToWorld()
|
||||
{
|
||||
super.addToWorld();
|
||||
this.outerProxy.onReady();
|
||||
}
|
||||
@Override
|
||||
public void addToWorld() {
|
||||
super.addToWorld();
|
||||
this.outerProxy.onReady();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPartHostInfo( final AEPartLocation side, final IPartHost host, final TileEntity tile )
|
||||
{
|
||||
super.setPartHostInfo( side, host, tile );
|
||||
this.outerProxy.setValidSides( EnumSet.of( side.getFacing() ) );
|
||||
}
|
||||
@Override
|
||||
public void setPartHostInfo(final AEPartLocation side, final IPartHost host, final TileEntity tile) {
|
||||
super.setPartHostInfo(side, host, tile);
|
||||
this.outerProxy.setValidSides(EnumSet.of(side.getFacing()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode getExternalFacingNode()
|
||||
{
|
||||
return this.outerProxy.getNode();
|
||||
}
|
||||
@Override
|
||||
public IGridNode getExternalFacingNode() {
|
||||
return this.outerProxy.getNode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlacement( final EntityPlayer player, final EnumHand hand, final ItemStack held, final AEPartLocation side )
|
||||
{
|
||||
super.onPlacement( player, hand, held, side );
|
||||
this.outerProxy.setOwner( player );
|
||||
}
|
||||
@Override
|
||||
public void onPlacement(final EntityPlayer player, final EnumHand hand, final ItemStack held, final AEPartLocation side) {
|
||||
super.onPlacement(player, hand, held, side);
|
||||
this.outerProxy.setOwner(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest( final IGridNode node )
|
||||
{
|
||||
return new TickingRequest( TickRates.METunnel.getMin(), TickRates.METunnel.getMax(), true, false );
|
||||
}
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(final IGridNode node) {
|
||||
return new TickingRequest(TickRates.METunnel.getMin(), TickRates.METunnel.getMax(), true, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
|
||||
{
|
||||
// just move on...
|
||||
try
|
||||
{
|
||||
if( !this.getProxy().getPath().isNetworkBooting() )
|
||||
{
|
||||
if( !this.getProxy().getEnergy().isNetworkPowered() )
|
||||
{
|
||||
this.connection.markDestroy();
|
||||
TickHandler.INSTANCE.addCallable( this.getTile().getWorld(), this.connection );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( this.getProxy().isActive() )
|
||||
{
|
||||
this.connection.markCreate();
|
||||
TickHandler.INSTANCE.addCallable( this.getTile().getWorld(), this.connection );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.connection.markDestroy();
|
||||
TickHandler.INSTANCE.addCallable( this.getTile().getWorld(), this.connection );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
|
||||
// just move on...
|
||||
try {
|
||||
if (!this.getProxy().getPath().isNetworkBooting()) {
|
||||
if (!this.getProxy().getEnergy().isNetworkPowered()) {
|
||||
this.connection.markDestroy();
|
||||
TickHandler.INSTANCE.addCallable(this.getTile().getWorld(), this.connection);
|
||||
} else {
|
||||
if (this.getProxy().isActive()) {
|
||||
this.connection.markCreate();
|
||||
TickHandler.INSTANCE.addCallable(this.getTile().getWorld(), this.connection);
|
||||
} else {
|
||||
this.connection.markDestroy();
|
||||
TickHandler.INSTANCE.addCallable(this.getTile().getWorld(), this.connection);
|
||||
}
|
||||
}
|
||||
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// meh?
|
||||
}
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// meh?
|
||||
}
|
||||
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
public void updateConnections( final Connections connections )
|
||||
{
|
||||
if( connections.isDestroy() )
|
||||
{
|
||||
for( final TunnelConnection cw : this.connection.getConnections().values() )
|
||||
{
|
||||
cw.getConnection().destroy();
|
||||
}
|
||||
public void updateConnections(final Connections connections) {
|
||||
if (connections.isDestroy()) {
|
||||
for (final TunnelConnection cw : this.connection.getConnections().values()) {
|
||||
cw.getConnection().destroy();
|
||||
}
|
||||
|
||||
this.connection.getConnections().clear();
|
||||
}
|
||||
else if( connections.isCreate() )
|
||||
{
|
||||
this.connection.getConnections().clear();
|
||||
} else if (connections.isCreate()) {
|
||||
|
||||
final Iterator<TunnelConnection> i = this.connection.getConnections().values().iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
final TunnelConnection cw = i.next();
|
||||
try
|
||||
{
|
||||
if( cw.getTunnel().getProxy().getGrid() != this.getProxy().getGrid() )
|
||||
{
|
||||
cw.getConnection().destroy();
|
||||
i.remove();
|
||||
}
|
||||
else if( !cw.getTunnel().getProxy().isActive() )
|
||||
{
|
||||
cw.getConnection().destroy();
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
final Iterator<TunnelConnection> i = this.connection.getConnections().values().iterator();
|
||||
while (i.hasNext()) {
|
||||
final TunnelConnection cw = i.next();
|
||||
try {
|
||||
if (cw.getTunnel().getProxy().getGrid() != this.getProxy().getGrid()) {
|
||||
cw.getConnection().destroy();
|
||||
i.remove();
|
||||
} else if (!cw.getTunnel().getProxy().isActive()) {
|
||||
cw.getConnection().destroy();
|
||||
i.remove();
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
final List<PartP2PTunnelME> newSides = new ArrayList<>();
|
||||
try
|
||||
{
|
||||
for( final PartP2PTunnelME me : this.getOutputs() )
|
||||
{
|
||||
if( me.getProxy().isActive() && connections.getConnections().get( me.getGridNode() ) == null )
|
||||
{
|
||||
newSides.add( me );
|
||||
}
|
||||
}
|
||||
final List<PartP2PTunnelME> newSides = new ArrayList<>();
|
||||
try {
|
||||
for (final PartP2PTunnelME me : this.getOutputs()) {
|
||||
if (me.getProxy().isActive() && connections.getConnections().get(me.getGridNode()) == null) {
|
||||
newSides.add(me);
|
||||
}
|
||||
}
|
||||
|
||||
for( final PartP2PTunnelME me : newSides )
|
||||
{
|
||||
try
|
||||
{
|
||||
connections.getConnections()
|
||||
.put( me.getGridNode(),
|
||||
new TunnelConnection( me, AEApi.instance()
|
||||
.grid()
|
||||
.createGridConnection( this.outerProxy.getNode(),
|
||||
me.outerProxy.getNode() ) ) );
|
||||
}
|
||||
catch( final FailedConnectionException e )
|
||||
{
|
||||
final TileEntity start = this.getTile();
|
||||
final TileEntity end = me.getTile();
|
||||
for (final PartP2PTunnelME me : newSides) {
|
||||
try {
|
||||
connections.getConnections()
|
||||
.put(me.getGridNode(),
|
||||
new TunnelConnection(me, AEApi.instance()
|
||||
.grid()
|
||||
.createGridConnection(this.outerProxy.getNode(),
|
||||
me.outerProxy.getNode())));
|
||||
} catch (final FailedConnectionException e) {
|
||||
final TileEntity start = this.getTile();
|
||||
final TileEntity end = me.getTile();
|
||||
|
||||
AELog.debug( e );
|
||||
AELog.debug(e);
|
||||
|
||||
AELog.warn( "Failed to establish a ME P2P Tunnel between the tunnels at [x=%d, y=%d, z=%d] and [x=%d, y=%d, z=%d]",
|
||||
start.getPos().getX(), start.getPos().getY(), start.getPos().getZ(), end.getPos().getX(), end.getPos().getY(),
|
||||
end.getPos().getZ() );
|
||||
// :(
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
AELog.debug( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
AELog.warn("Failed to establish a ME P2P Tunnel between the tunnels at [x=%d, y=%d, z=%d] and [x=%d, y=%d, z=%d]",
|
||||
start.getPos().getX(), start.getPos().getY(), start.getPos().getZ(), end.getPos().getX(), end.getPos().getY(),
|
||||
end.getPos().getZ());
|
||||
// :(
|
||||
}
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
AELog.debug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return MODELS.getModel( this.isPowered(), this.isActive() );
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return MODELS.getModel(this.isPowered(), this.isActive());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,16 +19,15 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import appeng.core.AppEng;
|
||||
import appeng.items.parts.PartModels;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
|
||||
/**
|
||||
* A more sophisticated part overlapping all 3 textures.
|
||||
*
|
||||
* <p>
|
||||
* Subclass this if you need want a new part and need all 3 textures.
|
||||
* For more concrete implementations, the direct abstract subclasses might be a better alternative.
|
||||
*
|
||||
@@ -37,30 +36,27 @@ import appeng.items.parts.PartModels;
|
||||
* @version rv3
|
||||
* @since rv3
|
||||
*/
|
||||
public abstract class AbstractPartDisplay extends AbstractPartReporting
|
||||
{
|
||||
public abstract class AbstractPartDisplay extends AbstractPartReporting {
|
||||
|
||||
// The base chassis of all display parts
|
||||
@PartModels
|
||||
protected static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/display_base" );
|
||||
// The base chassis of all display parts
|
||||
@PartModels
|
||||
protected static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID, "part/display_base");
|
||||
|
||||
// Models that contain the status indicator light
|
||||
@PartModels
|
||||
protected static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation( AppEng.MOD_ID, "part/display_status_off" );
|
||||
@PartModels
|
||||
protected static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation( AppEng.MOD_ID, "part/display_status_on" );
|
||||
@PartModels
|
||||
protected static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation( AppEng.MOD_ID, "part/display_status_has_channel" );
|
||||
// Models that contain the status indicator light
|
||||
@PartModels
|
||||
protected static final ResourceLocation MODEL_STATUS_OFF = new ResourceLocation(AppEng.MOD_ID, "part/display_status_off");
|
||||
@PartModels
|
||||
protected static final ResourceLocation MODEL_STATUS_ON = new ResourceLocation(AppEng.MOD_ID, "part/display_status_on");
|
||||
@PartModels
|
||||
protected static final ResourceLocation MODEL_STATUS_HAS_CHANNEL = new ResourceLocation(AppEng.MOD_ID, "part/display_status_has_channel");
|
||||
|
||||
public AbstractPartDisplay( final ItemStack is )
|
||||
{
|
||||
super( is, true );
|
||||
}
|
||||
public AbstractPartDisplay(final ItemStack is) {
|
||||
super(is, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLightSource()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isLightSource() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,18 +19,33 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.implementations.parts.IPartStorageMonitor;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.networking.storage.IStackWatcher;
|
||||
import appeng.api.networking.storage.IStackWatcherHost;
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IFluidStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.client.render.TesrRenderHelper;
|
||||
import appeng.core.localization.PlayerMessages;
|
||||
import appeng.fluids.util.AEFluidStack;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.util.IWideReadableNumberConverter;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.ReadableNumberConverter;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -45,29 +60,12 @@ import net.minecraftforge.fluids.capability.IFluidHandlerItem;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.implementations.parts.IPartStorageMonitor;
|
||||
import appeng.api.networking.storage.IStackWatcher;
|
||||
import appeng.api.networking.storage.IStackWatcherHost;
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.client.render.TesrRenderHelper;
|
||||
import appeng.core.localization.PlayerMessages;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.util.IWideReadableNumberConverter;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.ReadableNumberConverter;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* A basic subclass for any item monitor like display with an item icon and an amount.
|
||||
*
|
||||
* <p>
|
||||
* It can also be used to extract items from somewhere and spawned into the world.
|
||||
*
|
||||
* @author AlgorithmX2
|
||||
@@ -76,401 +74,315 @@ import appeng.util.item.AEItemStack;
|
||||
* @version rv3
|
||||
* @since rv3
|
||||
*/
|
||||
public abstract class AbstractPartMonitor extends AbstractPartDisplay implements IPartStorageMonitor, IStackWatcherHost
|
||||
{
|
||||
private static final IWideReadableNumberConverter NUMBER_CONVERTER = ReadableNumberConverter.INSTANCE;
|
||||
public abstract class AbstractPartMonitor extends AbstractPartDisplay implements IPartStorageMonitor, IStackWatcherHost {
|
||||
private static final IWideReadableNumberConverter NUMBER_CONVERTER = ReadableNumberConverter.INSTANCE;
|
||||
|
||||
private IAEItemStack configuredItem;
|
||||
private IAEFluidStack configuredFluid;
|
||||
private long configuredAmount;
|
||||
private String lastHumanReadableText;
|
||||
private boolean isLocked;
|
||||
private IStackWatcher myWatcher;
|
||||
private IAEItemStack configuredItem;
|
||||
private IAEFluidStack configuredFluid;
|
||||
private long configuredAmount;
|
||||
private String lastHumanReadableText;
|
||||
private boolean isLocked;
|
||||
private IStackWatcher myWatcher;
|
||||
|
||||
@Reflected
|
||||
public AbstractPartMonitor( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
@Reflected
|
||||
public AbstractPartMonitor(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
|
||||
this.isLocked = data.getBoolean( "isLocked" );
|
||||
this.isLocked = data.getBoolean("isLocked");
|
||||
|
||||
final NBTTagCompound myItem = data.getCompoundTag( "configuredItem" );
|
||||
this.configuredItem = AEItemStack.fromNBT( myItem );
|
||||
final NBTTagCompound myItem = data.getCompoundTag("configuredItem");
|
||||
this.configuredItem = AEItemStack.fromNBT(myItem);
|
||||
|
||||
final NBTTagCompound myFluid = data.getCompoundTag( "configuredFluid" );
|
||||
this.configuredFluid = AEFluidStack.fromNBT( myFluid );
|
||||
}
|
||||
final NBTTagCompound myFluid = data.getCompoundTag("configuredFluid");
|
||||
this.configuredFluid = AEFluidStack.fromNBT(myFluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
|
||||
data.setBoolean( "isLocked", this.isLocked );
|
||||
data.setBoolean("isLocked", this.isLocked);
|
||||
|
||||
final NBTTagCompound myItem = new NBTTagCompound();
|
||||
if( this.configuredItem != null )
|
||||
{
|
||||
this.configuredItem.writeToNBT( myItem );
|
||||
}
|
||||
final NBTTagCompound myFluid = new NBTTagCompound();
|
||||
if( this.configuredFluid != null )
|
||||
{
|
||||
this.configuredFluid.writeToNBT( myFluid );
|
||||
}
|
||||
final NBTTagCompound myItem = new NBTTagCompound();
|
||||
if (this.configuredItem != null) {
|
||||
this.configuredItem.writeToNBT(myItem);
|
||||
}
|
||||
final NBTTagCompound myFluid = new NBTTagCompound();
|
||||
if (this.configuredFluid != null) {
|
||||
this.configuredFluid.writeToNBT(myFluid);
|
||||
}
|
||||
|
||||
data.setTag( "configuredItem", myItem );
|
||||
data.setTag( "configuredFluid", myFluid );
|
||||
data.setTag("configuredItem", myItem);
|
||||
data.setTag("configuredFluid", myFluid);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream( final ByteBuf data ) throws IOException
|
||||
{
|
||||
super.writeToStream( data );
|
||||
@Override
|
||||
public void writeToStream(final ByteBuf data) throws IOException {
|
||||
super.writeToStream(data);
|
||||
|
||||
data.writeBoolean( this.isLocked );
|
||||
//is configured
|
||||
data.writeBoolean( this.configuredItem != null);
|
||||
data.writeBoolean( this.configuredFluid != null);
|
||||
if( this.configuredItem != null )
|
||||
{
|
||||
this.configuredItem.writeToPacket( data );
|
||||
}
|
||||
else if( this.configuredFluid != null )
|
||||
{
|
||||
this.configuredFluid.writeToPacket( data );
|
||||
}
|
||||
}
|
||||
data.writeBoolean(this.isLocked);
|
||||
//is configured
|
||||
data.writeBoolean(this.configuredItem != null);
|
||||
data.writeBoolean(this.configuredFluid != null);
|
||||
if (this.configuredItem != null) {
|
||||
this.configuredItem.writeToPacket(data);
|
||||
} else if (this.configuredFluid != null) {
|
||||
this.configuredFluid.writeToPacket(data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream( final ByteBuf data ) throws IOException
|
||||
{
|
||||
boolean needRedraw = super.readFromStream( data );
|
||||
@Override
|
||||
public boolean readFromStream(final ByteBuf data) throws IOException {
|
||||
boolean needRedraw = super.readFromStream(data);
|
||||
|
||||
final boolean isLocked = data.readBoolean();
|
||||
needRedraw = this.isLocked != isLocked;
|
||||
final boolean isLocked = data.readBoolean();
|
||||
needRedraw = this.isLocked != isLocked;
|
||||
|
||||
this.isLocked = isLocked;
|
||||
this.isLocked = isLocked;
|
||||
|
||||
final boolean isItem = data.readBoolean();
|
||||
final boolean isFluid = data.readBoolean();
|
||||
if( isItem )
|
||||
{
|
||||
this.configuredItem = AEItemStack.fromPacket( data );
|
||||
this.configuredFluid = null;
|
||||
}
|
||||
else if( isFluid )
|
||||
{
|
||||
this.configuredFluid = AEFluidStack.fromPacket( data );
|
||||
this.configuredItem = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.configuredItem = null;
|
||||
this.configuredFluid = null;
|
||||
}
|
||||
final boolean isItem = data.readBoolean();
|
||||
final boolean isFluid = data.readBoolean();
|
||||
if (isItem) {
|
||||
this.configuredItem = AEItemStack.fromPacket(data);
|
||||
this.configuredFluid = null;
|
||||
} else if (isFluid) {
|
||||
this.configuredFluid = AEFluidStack.fromPacket(data);
|
||||
this.configuredItem = null;
|
||||
} else {
|
||||
this.configuredItem = null;
|
||||
this.configuredFluid = null;
|
||||
}
|
||||
|
||||
return needRedraw;
|
||||
}
|
||||
return needRedraw;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
|
||||
if (Platform.isClient()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if( !this.getProxy().isActive() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!this.getProxy().isActive()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !Platform.hasPermissions( this.getLocation(), player ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!Platform.hasPermissions(this.getLocation(), player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !this.isLocked )
|
||||
{
|
||||
final ItemStack eq = player.getHeldItem( hand );
|
||||
FluidStack fluidInTank = null;
|
||||
if (!this.isLocked) {
|
||||
final ItemStack eq = player.getHeldItem(hand);
|
||||
FluidStack fluidInTank = null;
|
||||
|
||||
if( eq.hasCapability( CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null ) )
|
||||
{
|
||||
IFluidHandlerItem fluidHandlerItem = ( eq.getCapability( CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null ) );
|
||||
fluidInTank = fluidHandlerItem.drain( Integer.MAX_VALUE, false );
|
||||
}
|
||||
if (eq.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) {
|
||||
IFluidHandlerItem fluidHandlerItem = (eq.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null));
|
||||
fluidInTank = fluidHandlerItem.drain(Integer.MAX_VALUE, false);
|
||||
}
|
||||
|
||||
if( fluidInTank == null )
|
||||
{
|
||||
this.configuredFluid = null;
|
||||
if( !eq.isEmpty() )
|
||||
{
|
||||
this.configuredItem = AEItemStack.fromItemStack( eq ).setStackSize( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.configuredItem = null;
|
||||
}
|
||||
}
|
||||
else if( fluidInTank.amount > 0 )
|
||||
{
|
||||
this.configuredFluid = AEFluidStack.fromFluidStack( fluidInTank ).setStackSize( 0 );
|
||||
this.configuredItem = null;
|
||||
}
|
||||
if (fluidInTank == null) {
|
||||
this.configuredFluid = null;
|
||||
if (!eq.isEmpty()) {
|
||||
this.configuredItem = AEItemStack.fromItemStack(eq).setStackSize(0);
|
||||
} else {
|
||||
this.configuredItem = null;
|
||||
}
|
||||
} else if (fluidInTank.amount > 0) {
|
||||
this.configuredFluid = AEFluidStack.fromFluidStack(fluidInTank).setStackSize(0);
|
||||
this.configuredItem = null;
|
||||
}
|
||||
|
||||
this.configureWatchers();
|
||||
this.getHost().markForSave();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.onPartActivate( player, hand, pos );
|
||||
}
|
||||
this.configureWatchers();
|
||||
this.getHost().markForSave();
|
||||
this.getHost().markForUpdate();
|
||||
} else {
|
||||
return super.onPartActivate(player, hand, pos);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartShiftActivate( EntityPlayer player, EnumHand hand, Vec3d pos )
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onPartShiftActivate(EntityPlayer player, EnumHand hand, Vec3d pos) {
|
||||
if (Platform.isClient()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if( !this.getProxy().isActive() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!this.getProxy().isActive()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !Platform.hasPermissions( this.getLocation(), player ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!Platform.hasPermissions(this.getLocation(), player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( player.getHeldItem( hand ).isEmpty() )
|
||||
{
|
||||
this.isLocked = !this.isLocked;
|
||||
player.sendMessage( ( this.isLocked ? PlayerMessages.isNowLocked : PlayerMessages.isNowUnlocked ).get() );
|
||||
this.getHost().markForSave();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
if (player.getHeldItem(hand).isEmpty()) {
|
||||
this.isLocked = !this.isLocked;
|
||||
player.sendMessage((this.isLocked ? PlayerMessages.isNowLocked : PlayerMessages.isNowUnlocked).get());
|
||||
this.getHost().markForSave();
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// update the system...
|
||||
private void configureWatchers()
|
||||
{
|
||||
if( this.myWatcher != null )
|
||||
{
|
||||
this.myWatcher.reset();
|
||||
}
|
||||
// update the system...
|
||||
private void configureWatchers() {
|
||||
if (this.myWatcher != null) {
|
||||
this.myWatcher.reset();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if( this.configuredItem != null )
|
||||
{
|
||||
if( this.myWatcher != null )
|
||||
{
|
||||
this.myWatcher.add( this.configuredItem );
|
||||
}
|
||||
try {
|
||||
if (this.configuredItem != null) {
|
||||
if (this.myWatcher != null) {
|
||||
this.myWatcher.add(this.configuredItem);
|
||||
}
|
||||
|
||||
this.updateReportingValue(
|
||||
this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) );
|
||||
}
|
||||
else if ( this.configuredFluid != null )
|
||||
{
|
||||
if( this.myWatcher != null )
|
||||
{
|
||||
this.myWatcher.add( this.configuredFluid );
|
||||
}
|
||||
this.updateReportingValue(
|
||||
this.getProxy().getStorage().getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class)));
|
||||
} else if (this.configuredFluid != null) {
|
||||
if (this.myWatcher != null) {
|
||||
this.myWatcher.add(this.configuredFluid);
|
||||
}
|
||||
|
||||
this.updateReportingValue(
|
||||
this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) ) );
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// >.>
|
||||
}
|
||||
}
|
||||
this.updateReportingValue(
|
||||
this.getProxy().getStorage().getInventory(AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class)));
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// >.>
|
||||
}
|
||||
}
|
||||
|
||||
private <T extends IAEStack<T>> void updateReportingValue ( final IMEMonitor<T> monitor )
|
||||
{
|
||||
if( this.configuredItem != null)
|
||||
{
|
||||
final IAEItemStack result = (IAEItemStack) monitor.getStorageList().findPrecise( (T) this.configuredItem );
|
||||
if( result == null )
|
||||
{
|
||||
this.configuredAmount = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.configuredAmount = result.getStackSize();
|
||||
}
|
||||
this.configuredItem.setStackSize( this.configuredAmount );
|
||||
}
|
||||
else if( this.configuredFluid != null)
|
||||
{
|
||||
final IAEFluidStack result = (IAEFluidStack) monitor.getStorageList().findPrecise( (T) this.configuredFluid );
|
||||
if( result == null )
|
||||
{
|
||||
this.configuredAmount = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.configuredAmount = result.getStackSize();
|
||||
}
|
||||
this.configuredFluid.setStackSize( this.configuredAmount );
|
||||
}
|
||||
}
|
||||
private <T extends IAEStack<T>> void updateReportingValue(final IMEMonitor<T> monitor) {
|
||||
if (this.configuredItem != null) {
|
||||
final IAEItemStack result = (IAEItemStack) monitor.getStorageList().findPrecise((T) this.configuredItem);
|
||||
if (result == null) {
|
||||
this.configuredAmount = 0;
|
||||
} else {
|
||||
this.configuredAmount = result.getStackSize();
|
||||
}
|
||||
this.configuredItem.setStackSize(this.configuredAmount);
|
||||
} else if (this.configuredFluid != null) {
|
||||
final IAEFluidStack result = (IAEFluidStack) monitor.getStorageList().findPrecise((T) this.configuredFluid);
|
||||
if (result == null) {
|
||||
this.configuredAmount = 0;
|
||||
} else {
|
||||
this.configuredAmount = result.getStackSize();
|
||||
}
|
||||
this.configuredFluid.setStackSize(this.configuredAmount);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly( Side.CLIENT )
|
||||
public void renderDynamic( double x, double y, double z, float partialTicks, int destroyStage )
|
||||
{
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderDynamic(double x, double y, double z, float partialTicks, int destroyStage) {
|
||||
|
||||
if( ( this.getClientFlags() & ( PartPanel.POWERED_FLAG | PartPanel.CHANNEL_FLAG ) ) != ( PartPanel.POWERED_FLAG | PartPanel.CHANNEL_FLAG ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ((this.getClientFlags() & (PartPanel.POWERED_FLAG | PartPanel.CHANNEL_FLAG)) != (PartPanel.POWERED_FLAG | PartPanel.CHANNEL_FLAG)) {
|
||||
return;
|
||||
}
|
||||
|
||||
IAEStack<?> ais = this.getDisplayed();
|
||||
IAEStack<?> ais = this.getDisplayed();
|
||||
|
||||
if( ais == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (ais == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate( x + 0.5, y + 0.5, z + 0.5 );
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(x + 0.5, y + 0.5, z + 0.5);
|
||||
|
||||
EnumFacing facing = this.getSide().getFacing();
|
||||
EnumFacing facing = this.getSide().getFacing();
|
||||
|
||||
TesrRenderHelper.moveToFace( facing );
|
||||
TesrRenderHelper.rotateToFace( facing, this.getSpin() );
|
||||
if (ais instanceof IAEItemStack)
|
||||
TesrRenderHelper.renderItem2dWithAmount( (IAEItemStack) ais, 0.8f, 0.17f );
|
||||
if (ais instanceof IAEFluidStack)
|
||||
TesrRenderHelper.renderFluid2dWithAmount( (IAEFluidStack) ais, 0.8f, 0.17f );
|
||||
GlStateManager.popMatrix();
|
||||
TesrRenderHelper.moveToFace(facing);
|
||||
TesrRenderHelper.rotateToFace(facing, this.getSpin());
|
||||
if (ais instanceof IAEItemStack)
|
||||
TesrRenderHelper.renderItem2dWithAmount((IAEItemStack) ais, 0.8f, 0.17f);
|
||||
if (ais instanceof IAEFluidStack)
|
||||
TesrRenderHelper.renderFluid2dWithAmount((IAEFluidStack) ais, 0.8f, 0.17f);
|
||||
GlStateManager.popMatrix();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requireDynamicRender()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean requireDynamicRender() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEStack<?> getDisplayed()
|
||||
{
|
||||
if (this.configuredItem != null)
|
||||
return this.configuredItem;
|
||||
else if (this.configuredFluid != null)
|
||||
return this.configuredFluid;
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public IAEStack<?> getDisplayed() {
|
||||
if (this.configuredItem != null)
|
||||
return this.configuredItem;
|
||||
else if (this.configuredFluid != null)
|
||||
return this.configuredFluid;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLocked()
|
||||
{
|
||||
return this.isLocked;
|
||||
}
|
||||
@Override
|
||||
public boolean isLocked() {
|
||||
return this.isLocked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWatcher( final IStackWatcher newWatcher )
|
||||
{
|
||||
this.myWatcher = newWatcher;
|
||||
this.configureWatchers();
|
||||
}
|
||||
@Override
|
||||
public void updateWatcher(final IStackWatcher newWatcher) {
|
||||
this.myWatcher = newWatcher;
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerStatusChange( final MENetworkPowerStatusChange ev )
|
||||
{
|
||||
if( this.getProxy().isPowered() )
|
||||
{
|
||||
this.configureWatchers();
|
||||
}
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void powerStatusChange(final MENetworkPowerStatusChange ev) {
|
||||
if (this.getProxy().isPowered()) {
|
||||
this.configureWatchers();
|
||||
}
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void channelChanged( final MENetworkChannelsChanged c )
|
||||
{
|
||||
if( this.getProxy().isPowered() )
|
||||
{
|
||||
this.configureWatchers();
|
||||
}
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public void channelChanged(final MENetworkChannelsChanged c) {
|
||||
if (this.getProxy().isPowered()) {
|
||||
this.configureWatchers();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStackChange( IItemList<?> o, IAEStack<?> fullStack, IAEStack<?> diffStack, IActionSource src, IStorageChannel<?> chan )
|
||||
{
|
||||
this.configuredAmount = fullStack.getStackSize();
|
||||
@Override
|
||||
public void onStackChange(IItemList<?> o, IAEStack<?> fullStack, IAEStack<?> diffStack, IActionSource src, IStorageChannel<?> chan) {
|
||||
this.configuredAmount = fullStack.getStackSize();
|
||||
|
||||
if( this.configuredItem != null )
|
||||
{
|
||||
this.configuredItem.setStackSize( this.configuredAmount );
|
||||
}
|
||||
else if( this.configuredFluid != null )
|
||||
{
|
||||
this.configuredFluid.setStackSize( this.configuredAmount );
|
||||
}
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
if (this.configuredItem != null) {
|
||||
this.configuredItem.setStackSize(this.configuredAmount);
|
||||
} else if (this.configuredFluid != null) {
|
||||
this.configuredFluid.setStackSize(this.configuredAmount);
|
||||
}
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showNetworkInfo( final RayTraceResult where )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean showNetworkInfo(final RayTraceResult where) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected IPartModel selectModel( IPartModel off, IPartModel on, IPartModel hasChannel, IPartModel lockedOff, IPartModel lockedOn, IPartModel lockedHasChannel )
|
||||
{
|
||||
if( this.isActive() )
|
||||
{
|
||||
if( this.isLocked() )
|
||||
{
|
||||
return lockedHasChannel;
|
||||
}
|
||||
else
|
||||
{
|
||||
return hasChannel;
|
||||
}
|
||||
}
|
||||
else if( this.isPowered() )
|
||||
{
|
||||
if( this.isLocked() )
|
||||
{
|
||||
return lockedOn;
|
||||
}
|
||||
else
|
||||
{
|
||||
return on;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( this.isLocked() )
|
||||
{
|
||||
return lockedOff;
|
||||
}
|
||||
else
|
||||
{
|
||||
return off;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected IPartModel selectModel(IPartModel off, IPartModel on, IPartModel hasChannel, IPartModel lockedOff, IPartModel lockedOn, IPartModel lockedHasChannel) {
|
||||
if (this.isActive()) {
|
||||
if (this.isLocked()) {
|
||||
return lockedHasChannel;
|
||||
} else {
|
||||
return hasChannel;
|
||||
}
|
||||
} else if (this.isPowered()) {
|
||||
if (this.isLocked()) {
|
||||
return lockedOn;
|
||||
} else {
|
||||
return on;
|
||||
}
|
||||
} else {
|
||||
if (this.isLocked()) {
|
||||
return lockedOff;
|
||||
} else {
|
||||
return off;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,17 +19,16 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.items.parts.PartModels;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
|
||||
/**
|
||||
* A very simple part for emitting light.
|
||||
*
|
||||
* <p>
|
||||
* Opposed to the other subclass of {@link AbstractPartReporting}, it will only use the bright front texture.
|
||||
*
|
||||
* @author AlgorithmX2
|
||||
@@ -37,29 +36,26 @@ import appeng.items.parts.PartModels;
|
||||
* @version rv3
|
||||
* @since rv3
|
||||
*/
|
||||
public abstract class AbstractPartPanel extends AbstractPartReporting
|
||||
{
|
||||
public abstract class AbstractPartPanel extends AbstractPartReporting {
|
||||
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/monitor_base" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation(AppEng.MOD_ID, "part/monitor_base");
|
||||
|
||||
public AbstractPartPanel( final ItemStack is )
|
||||
{
|
||||
super( is, false );
|
||||
}
|
||||
public AbstractPartPanel(final ItemStack is) {
|
||||
super(is, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLightSource()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isLightSource() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* How bright the color the panel should appear. Usually it depends on a {@link AEColor} variant.
|
||||
* This does not affect the actual light level of the part.
|
||||
*
|
||||
* @return the brightness to be used.
|
||||
*/
|
||||
protected abstract int getBrightnessColor();
|
||||
/**
|
||||
* How bright the color the panel should appear. Usually it depends on a {@link AEColor} variant.
|
||||
* This does not affect the actual light level of the part.
|
||||
*
|
||||
* @return the brightness to be used.
|
||||
*/
|
||||
protected abstract int getBrightnessColor();
|
||||
|
||||
}
|
||||
|
||||
@@ -19,20 +19,6 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
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.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import appeng.api.implementations.IPowerChannelState;
|
||||
import appeng.api.implementations.parts.IPartMonitor;
|
||||
import appeng.api.networking.GridFlags;
|
||||
@@ -45,14 +31,26 @@ import appeng.api.util.AEPartLocation;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.AEBasePart;
|
||||
import appeng.util.Platform;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
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.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* The most basic class for any part reporting information, like terminals or monitors. This can also include basic
|
||||
* panels which just provide light.
|
||||
*
|
||||
* <p>
|
||||
* It deals with the most basic functionalities like network data, grid registration or the rotation of the actual part.
|
||||
*
|
||||
* <p>
|
||||
* The direct abstract subclasses are usually a better entry point for adding new concrete ones.
|
||||
* But this might be an ideal starting point to completely new type, which does not resemble any existing one.
|
||||
*
|
||||
@@ -61,270 +59,211 @@ import appeng.util.Platform;
|
||||
* @version rv3
|
||||
* @since rv3
|
||||
*/
|
||||
public abstract class AbstractPartReporting extends AEBasePart implements IPartMonitor, IPowerChannelState
|
||||
{
|
||||
public abstract class AbstractPartReporting extends AEBasePart implements IPartMonitor, IPowerChannelState {
|
||||
|
||||
protected static final int POWERED_FLAG = 4;
|
||||
protected static final int CHANNEL_FLAG = 16;
|
||||
private static final int BOOTING_FLAG = 8;
|
||||
protected static final int POWERED_FLAG = 4;
|
||||
protected static final int CHANNEL_FLAG = 16;
|
||||
private static final int BOOTING_FLAG = 8;
|
||||
|
||||
private byte spin = 0; // 0-3
|
||||
private int clientFlags = 0; // sent as byte.
|
||||
private int opacity = -1;
|
||||
private byte spin = 0; // 0-3
|
||||
private int clientFlags = 0; // sent as byte.
|
||||
private int opacity = -1;
|
||||
|
||||
public AbstractPartReporting( final ItemStack is )
|
||||
{
|
||||
this( is, false );
|
||||
}
|
||||
public AbstractPartReporting(final ItemStack is) {
|
||||
this(is, false);
|
||||
}
|
||||
|
||||
protected AbstractPartReporting( final ItemStack is, final boolean requireChannel )
|
||||
{
|
||||
super( is );
|
||||
protected AbstractPartReporting(final ItemStack is, final boolean requireChannel) {
|
||||
super(is);
|
||||
|
||||
if( requireChannel )
|
||||
{
|
||||
this.getProxy().setFlags( GridFlags.REQUIRE_CHANNEL );
|
||||
this.getProxy().setIdlePowerUsage( 1.0 / 2.0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getProxy().setIdlePowerUsage( 1.0 / 16.0 ); // lights drain a little bit.
|
||||
}
|
||||
}
|
||||
if (requireChannel) {
|
||||
this.getProxy().setFlags(GridFlags.REQUIRE_CHANNEL);
|
||||
this.getProxy().setIdlePowerUsage(1.0 / 2.0);
|
||||
} else {
|
||||
this.getProxy().setIdlePowerUsage(1.0 / 16.0); // lights drain a little bit.
|
||||
}
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public final void bootingRender( final MENetworkBootingStatusChange c )
|
||||
{
|
||||
if( !this.isLightSource() )
|
||||
{
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public final void bootingRender(final MENetworkBootingStatusChange c) {
|
||||
if (!this.isLightSource()) {
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public final void powerRender( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
@MENetworkEventSubscribe
|
||||
public final void powerRender(final MENetworkPowerStatusChange c) {
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void getBoxes( final IPartCollisionHelper bch )
|
||||
{
|
||||
bch.addBox( 2, 2, 14, 14, 14, 16 );
|
||||
bch.addBox( 4, 4, 13, 12, 12, 14 );
|
||||
}
|
||||
@Override
|
||||
public final void getBoxes(final IPartCollisionHelper bch) {
|
||||
bch.addBox(2, 2, 14, 14, 14, 16);
|
||||
bch.addBox(4, 4, 13, 12, 12, 14);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged( IBlockAccess w, BlockPos pos, BlockPos neighbor )
|
||||
{
|
||||
if( pos.offset( this.getSide().getFacing() ).equals( neighbor ) )
|
||||
{
|
||||
this.opacity = -1;
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onNeighborChanged(IBlockAccess w, BlockPos pos, BlockPos neighbor) {
|
||||
if (pos.offset(this.getSide().getFacing()).equals(neighbor)) {
|
||||
this.opacity = -1;
|
||||
this.getHost().markForUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.spin = data.getByte( "spin" );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
this.spin = data.getByte("spin");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
data.setByte( "spin", this.getSpin() );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
data.setByte("spin", this.getSpin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream( final ByteBuf data ) throws IOException
|
||||
{
|
||||
super.writeToStream( data );
|
||||
this.clientFlags = this.getSpin() & 3;
|
||||
@Override
|
||||
public void writeToStream(final ByteBuf data) throws IOException {
|
||||
super.writeToStream(data);
|
||||
this.clientFlags = this.getSpin() & 3;
|
||||
|
||||
try
|
||||
{
|
||||
if( this.getProxy().getEnergy().isNetworkPowered() )
|
||||
{
|
||||
this.clientFlags = this.getClientFlags() | AbstractPartReporting.POWERED_FLAG;
|
||||
}
|
||||
try {
|
||||
if (this.getProxy().getEnergy().isNetworkPowered()) {
|
||||
this.clientFlags = this.getClientFlags() | AbstractPartReporting.POWERED_FLAG;
|
||||
}
|
||||
|
||||
if( this.getProxy().getPath().isNetworkBooting() )
|
||||
{
|
||||
this.clientFlags = this.getClientFlags() | AbstractPartReporting.BOOTING_FLAG;
|
||||
}
|
||||
if (this.getProxy().getPath().isNetworkBooting()) {
|
||||
this.clientFlags = this.getClientFlags() | AbstractPartReporting.BOOTING_FLAG;
|
||||
}
|
||||
|
||||
if( this.getProxy().getNode().meetsChannelRequirements() )
|
||||
{
|
||||
this.clientFlags = this.getClientFlags() | AbstractPartReporting.CHANNEL_FLAG;
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// um.. nothing.
|
||||
}
|
||||
if (this.getProxy().getNode().meetsChannelRequirements()) {
|
||||
this.clientFlags = this.getClientFlags() | AbstractPartReporting.CHANNEL_FLAG;
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// um.. nothing.
|
||||
}
|
||||
|
||||
data.writeByte( (byte) this.getClientFlags() );
|
||||
data.writeInt( this.opacity );
|
||||
}
|
||||
data.writeByte((byte) this.getClientFlags());
|
||||
data.writeInt(this.opacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream( final ByteBuf data ) throws IOException
|
||||
{
|
||||
super.readFromStream( data );
|
||||
final int oldFlags = this.getClientFlags();
|
||||
final int oldOpacity = this.opacity;
|
||||
@Override
|
||||
public boolean readFromStream(final ByteBuf data) throws IOException {
|
||||
super.readFromStream(data);
|
||||
final int oldFlags = this.getClientFlags();
|
||||
final int oldOpacity = this.opacity;
|
||||
|
||||
this.clientFlags = data.readByte();
|
||||
this.opacity = data.readInt();
|
||||
this.clientFlags = data.readByte();
|
||||
this.opacity = data.readInt();
|
||||
|
||||
this.spin = (byte) ( this.getClientFlags() & 3 );
|
||||
if( this.getClientFlags() == oldFlags && this.opacity == oldOpacity )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
this.spin = (byte) (this.getClientFlags() & 3);
|
||||
return this.getClientFlags() != oldFlags || this.opacity != oldOpacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getLightLevel()
|
||||
{
|
||||
return this.blockLight( this.isPowered() ? ( this.isLightSource() ? 15 : 9 ) : 0 );
|
||||
}
|
||||
@Override
|
||||
public final int getLightLevel() {
|
||||
return this.blockLight(this.isPowered() ? (this.isLightSource() ? 15 : 9) : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
|
||||
{
|
||||
final TileEntity te = this.getTile();
|
||||
@Override
|
||||
public boolean onPartActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
|
||||
final TileEntity te = this.getTile();
|
||||
|
||||
if( Platform.isWrench( player, player.inventory.getCurrentItem(), te.getPos() ) )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
if( this.getSpin() > 3 )
|
||||
{
|
||||
this.spin = 0;
|
||||
}
|
||||
if (Platform.isWrench(player, player.inventory.getCurrentItem(), te.getPos())) {
|
||||
if (Platform.isServer()) {
|
||||
if (this.getSpin() > 3) {
|
||||
this.spin = 0;
|
||||
}
|
||||
|
||||
switch( this.getSpin() )
|
||||
{
|
||||
case 0:
|
||||
this.spin = 1;
|
||||
break;
|
||||
case 1:
|
||||
this.spin = 3;
|
||||
break;
|
||||
case 2:
|
||||
this.spin = 0;
|
||||
break;
|
||||
case 3:
|
||||
this.spin = 2;
|
||||
break;
|
||||
}
|
||||
switch (this.getSpin()) {
|
||||
case 0:
|
||||
this.spin = 1;
|
||||
break;
|
||||
case 1:
|
||||
this.spin = 3;
|
||||
break;
|
||||
case 2:
|
||||
this.spin = 0;
|
||||
break;
|
||||
case 3:
|
||||
this.spin = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
this.getHost().markForUpdate();
|
||||
this.saveChanges();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.onPartActivate( player, hand, pos );
|
||||
}
|
||||
}
|
||||
this.getHost().markForUpdate();
|
||||
this.saveChanges();
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return super.onPartActivate(player, hand, pos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onPlacement( final EntityPlayer player, final EnumHand hand, final ItemStack held, final AEPartLocation side )
|
||||
{
|
||||
super.onPlacement( player, hand, held, side );
|
||||
@Override
|
||||
public final void onPlacement(final EntityPlayer player, final EnumHand hand, final ItemStack held, final AEPartLocation side) {
|
||||
super.onPlacement(player, hand, held, side);
|
||||
|
||||
final byte rotation = (byte) ( MathHelper.floor( ( player.rotationYaw * 4F ) / 360F + 2.5D ) & 3 );
|
||||
if( side == AEPartLocation.UP )
|
||||
{
|
||||
this.spin = rotation;
|
||||
}
|
||||
else if( side == AEPartLocation.DOWN )
|
||||
{
|
||||
this.spin = rotation;
|
||||
}
|
||||
}
|
||||
final byte rotation = (byte) (MathHelper.floor((player.rotationYaw * 4F) / 360F + 2.5D) & 3);
|
||||
if (side == AEPartLocation.UP) {
|
||||
this.spin = rotation;
|
||||
} else if (side == AEPartLocation.DOWN) {
|
||||
this.spin = rotation;
|
||||
}
|
||||
}
|
||||
|
||||
private final int blockLight( final int emit )
|
||||
{
|
||||
if( this.opacity < 0 )
|
||||
{
|
||||
final TileEntity te = this.getTile();
|
||||
this.opacity = 255 - te.getWorld().getBlockLightOpacity( te.getPos().offset( this.getSide().getFacing() ) );
|
||||
}
|
||||
private final int blockLight(final int emit) {
|
||||
if (this.opacity < 0) {
|
||||
final TileEntity te = this.getTile();
|
||||
this.opacity = 255 - te.getWorld().getBlockLightOpacity(te.getPos().offset(this.getSide().getFacing()));
|
||||
}
|
||||
|
||||
return (int) ( emit * ( this.opacity / 255.0f ) );
|
||||
}
|
||||
return (int) (emit * (this.opacity / 255.0f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isPowered()
|
||||
{
|
||||
try
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
return this.getProxy().getEnergy().isNetworkPowered();
|
||||
}
|
||||
else
|
||||
{
|
||||
return( ( this.getClientFlags() & PartPanel.POWERED_FLAG ) == PartPanel.POWERED_FLAG );
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public final boolean isPowered() {
|
||||
try {
|
||||
if (Platform.isServer()) {
|
||||
return this.getProxy().getEnergy().isNetworkPowered();
|
||||
} else {
|
||||
return ((this.getClientFlags() & PartPanel.POWERED_FLAG) == PartPanel.POWERED_FLAG);
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isActive()
|
||||
{
|
||||
if( !this.isLightSource() )
|
||||
{
|
||||
return( ( this.getClientFlags() & ( PartPanel.CHANNEL_FLAG | PartPanel.POWERED_FLAG ) ) == ( PartPanel.CHANNEL_FLAG | PartPanel.POWERED_FLAG ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.isPowered();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public final boolean isActive() {
|
||||
if (!this.isLightSource()) {
|
||||
return ((this.getClientFlags() & (PartPanel.CHANNEL_FLAG | PartPanel.POWERED_FLAG)) == (PartPanel.CHANNEL_FLAG | PartPanel.POWERED_FLAG));
|
||||
} else {
|
||||
return this.isPowered();
|
||||
}
|
||||
}
|
||||
|
||||
protected IPartModel selectModel( IPartModel offModels, IPartModel onModels, IPartModel hasChannelModels )
|
||||
{
|
||||
if( this.isActive() )
|
||||
{
|
||||
return hasChannelModels;
|
||||
}
|
||||
else if( this.isPowered() )
|
||||
{
|
||||
return onModels;
|
||||
}
|
||||
else
|
||||
{
|
||||
return offModels;
|
||||
}
|
||||
}
|
||||
protected IPartModel selectModel(IPartModel offModels, IPartModel onModels, IPartModel hasChannelModels) {
|
||||
if (this.isActive()) {
|
||||
return hasChannelModels;
|
||||
} else if (this.isPowered()) {
|
||||
return onModels;
|
||||
} else {
|
||||
return offModels;
|
||||
}
|
||||
}
|
||||
|
||||
public final int getClientFlags()
|
||||
{
|
||||
return this.clientFlags;
|
||||
}
|
||||
public final int getClientFlags() {
|
||||
return this.clientFlags;
|
||||
}
|
||||
|
||||
public final byte getSpin()
|
||||
{
|
||||
return this.spin;
|
||||
}
|
||||
public final byte getSpin() {
|
||||
return this.spin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the part emit light. This actually only affects the light level, light source use a level of 15 and non
|
||||
* light source 9.
|
||||
*/
|
||||
public abstract boolean isLightSource();
|
||||
/**
|
||||
* Should the part emit light. This actually only affects the light level, light source use a level of 15 and non
|
||||
* light source 9.
|
||||
*/
|
||||
public abstract boolean isLightSource();
|
||||
|
||||
}
|
||||
|
||||
@@ -19,15 +19,6 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.SortDir;
|
||||
import appeng.api.config.SortOrder;
|
||||
@@ -46,11 +37,19 @@ import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Anything resembling an network terminal with view cells can reuse this.
|
||||
*
|
||||
* <p>
|
||||
* Note this applies only to terminals like the ME Terminal. It does not apply for more specialized terminals like the
|
||||
* Interface Terminal.
|
||||
*
|
||||
@@ -59,104 +58,85 @@ import appeng.util.inv.InvOperation;
|
||||
* @version rv3
|
||||
* @since rv3
|
||||
*/
|
||||
public abstract class AbstractPartTerminal extends AbstractPartDisplay implements ITerminalHost, IConfigManagerHost, IViewCellStorage, IAEAppEngInventory
|
||||
{
|
||||
public abstract class AbstractPartTerminal extends AbstractPartDisplay implements ITerminalHost, IConfigManagerHost, IViewCellStorage, IAEAppEngInventory {
|
||||
|
||||
private final IConfigManager cm = new ConfigManager( this );
|
||||
private final AppEngInternalInventory viewCell = new AppEngInternalInventory( this, 5 );
|
||||
private final IConfigManager cm = new ConfigManager(this);
|
||||
private final AppEngInternalInventory viewCell = new AppEngInternalInventory(this, 5);
|
||||
|
||||
public AbstractPartTerminal( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
public AbstractPartTerminal(final ItemStack is) {
|
||||
super(is);
|
||||
|
||||
this.cm.registerSetting( Settings.SORT_BY, SortOrder.NAME );
|
||||
this.cm.registerSetting( Settings.VIEW_MODE, ViewItems.ALL );
|
||||
this.cm.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING );
|
||||
}
|
||||
this.cm.registerSetting(Settings.SORT_BY, SortOrder.NAME);
|
||||
this.cm.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
|
||||
this.cm.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops( final List<ItemStack> drops, final boolean wrenched )
|
||||
{
|
||||
super.getDrops( drops, wrenched );
|
||||
@Override
|
||||
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
|
||||
super.getDrops(drops, wrenched);
|
||||
|
||||
for( final ItemStack is : this.viewCell )
|
||||
{
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
drops.add( is );
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final ItemStack is : this.viewCell) {
|
||||
if (!is.isEmpty()) {
|
||||
drops.add(is);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
return this.cm;
|
||||
}
|
||||
@Override
|
||||
public IConfigManager getConfigManager() {
|
||||
return this.cm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.cm.readFromNBT( data );
|
||||
this.viewCell.readFromNBT( data, "viewCell" );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
this.cm.readFromNBT(data);
|
||||
this.viewCell.readFromNBT(data, "viewCell");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
this.cm.writeToNBT( data );
|
||||
this.viewCell.writeToNBT( data, "viewCell" );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
this.cm.writeToNBT(data);
|
||||
this.viewCell.writeToNBT(data, "viewCell");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
|
||||
{
|
||||
if( !super.onPartActivate( player, hand, pos ) )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
Platform.openGUI( player, this.getHost().getTile(), this.getSide(), this.getGui( player ) );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
|
||||
if (!super.onPartActivate(player, hand, pos)) {
|
||||
if (Platform.isServer()) {
|
||||
Platform.openGUI(player, this.getHost().getTile(), this.getSide(), this.getGui(player));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public GuiBridge getGui( final EntityPlayer player )
|
||||
{
|
||||
return GuiBridge.GUI_ME;
|
||||
}
|
||||
public GuiBridge getGui(final EntityPlayer player) {
|
||||
return GuiBridge.GUI_ME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends IAEStack<T>> IMEMonitor<T> getInventory( IStorageChannel<T> channel )
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.getProxy().getStorage().getInventory( channel );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// err nope?
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public <T extends IAEStack<T>> IMEMonitor<T> getInventory(IStorageChannel<T> channel) {
|
||||
try {
|
||||
return this.getProxy().getStorage().getInventory(channel);
|
||||
} catch (final GridAccessException e) {
|
||||
// err nope?
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
|
||||
{
|
||||
@Override
|
||||
public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getViewCellStorage()
|
||||
{
|
||||
return this.viewCell;
|
||||
}
|
||||
@Override
|
||||
public IItemHandler getViewCellStorage() {
|
||||
return this.viewCell;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
|
||||
{
|
||||
this.getHost().markForSave();
|
||||
}
|
||||
@Override
|
||||
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
|
||||
this.getHost().markForSave();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,22 +19,27 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.energy.IEnergySource;
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.channels.IFluidStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketInventoryAction;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.fluids.util.AEFluidStack;
|
||||
import appeng.helpers.InventoryAction;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.helpers.PlayerSource;
|
||||
import appeng.parts.PartModel;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumHand;
|
||||
@@ -47,413 +52,323 @@ import net.minecraftforge.fluids.capability.IFluidHandlerItem;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.PlayerMainInvWrapper;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.networking.energy.IEnergySource;
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.helpers.PlayerSource;
|
||||
import appeng.parts.PartModel;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class PartConversionMonitor extends AbstractPartMonitor
|
||||
{
|
||||
public class PartConversionMonitor extends AbstractPartMonitor {
|
||||
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/conversion_monitor_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/conversion_monitor_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_LOCKED_OFF = new ResourceLocation( AppEng.MOD_ID, "part/conversion_monitor_locked_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_LOCKED_ON = new ResourceLocation( AppEng.MOD_ID, "part/conversion_monitor_locked_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation(AppEng.MOD_ID, "part/conversion_monitor_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation(AppEng.MOD_ID, "part/conversion_monitor_on");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_LOCKED_OFF = new ResourceLocation(AppEng.MOD_ID, "part/conversion_monitor_locked_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_LOCKED_ON = new ResourceLocation(AppEng.MOD_ID, "part/conversion_monitor_locked_on");
|
||||
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF );
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, MODEL_ON, MODEL_STATUS_ON );
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL );
|
||||
public static final IPartModel MODELS_LOCKED_OFF = new PartModel( MODEL_BASE, MODEL_LOCKED_OFF, MODEL_STATUS_OFF );
|
||||
public static final IPartModel MODELS_LOCKED_ON = new PartModel( MODEL_BASE, MODEL_LOCKED_ON, MODEL_STATUS_ON );
|
||||
public static final IPartModel MODELS_LOCKED_HAS_CHANNEL = new PartModel( MODEL_BASE, MODEL_LOCKED_ON, MODEL_STATUS_HAS_CHANNEL );
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF);
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_ON);
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL);
|
||||
public static final IPartModel MODELS_LOCKED_OFF = new PartModel(MODEL_BASE, MODEL_LOCKED_OFF, MODEL_STATUS_OFF);
|
||||
public static final IPartModel MODELS_LOCKED_ON = new PartModel(MODEL_BASE, MODEL_LOCKED_ON, MODEL_STATUS_ON);
|
||||
public static final IPartModel MODELS_LOCKED_HAS_CHANNEL = new PartModel(MODEL_BASE, MODEL_LOCKED_ON, MODEL_STATUS_HAS_CHANNEL);
|
||||
|
||||
@Reflected
|
||||
public PartConversionMonitor( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
@Reflected
|
||||
public PartConversionMonitor(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( EntityPlayer player, EnumHand hand, Vec3d pos )
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(EntityPlayer player, EnumHand hand, Vec3d pos) {
|
||||
if (Platform.isClient()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if( !this.getProxy().isActive() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!this.getProxy().isActive()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !Platform.hasPermissions( this.getLocation(), player ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!Platform.hasPermissions(this.getLocation(), player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final ItemStack eq = player.getHeldItem( hand );
|
||||
FluidStack fluidInTank = null;
|
||||
if( eq.hasCapability( CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null ) )
|
||||
{
|
||||
IFluidHandlerItem fluidHandlerItem = ( eq.getCapability( CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null ) );
|
||||
fluidInTank = fluidHandlerItem.drain( Integer.MAX_VALUE, false );
|
||||
}
|
||||
final ItemStack eq = player.getHeldItem(hand);
|
||||
FluidStack fluidInTank = null;
|
||||
if (eq.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) {
|
||||
IFluidHandlerItem fluidHandlerItem = (eq.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null));
|
||||
fluidInTank = fluidHandlerItem.drain(Integer.MAX_VALUE, false);
|
||||
}
|
||||
|
||||
if( this.isLocked() )
|
||||
{
|
||||
if( eq.isEmpty() )
|
||||
{
|
||||
this.insertItem( player, hand, true );
|
||||
}
|
||||
else if( Platform.isWrench( player, eq, this.getLocation().getPos() ) && ( this.getDisplayed() == null || !this.getDisplayed().equals( eq ) ) )
|
||||
{
|
||||
// wrench it
|
||||
return super.onPartActivate( player, hand, pos );
|
||||
}
|
||||
else if( fluidInTank != null && fluidInTank.amount > 0 )
|
||||
{
|
||||
if( this.getDisplayed() != null && getDisplayed().equals( AEFluidStack.fromFluidStack( fluidInTank ) ) )
|
||||
{
|
||||
this.drainFluidContainer( player, hand );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.insertItem( player, hand, false );
|
||||
}
|
||||
}
|
||||
if (this.isLocked()) {
|
||||
if (eq.isEmpty()) {
|
||||
this.insertItem(player, hand, true);
|
||||
} else if (Platform.isWrench(player, eq, this.getLocation().getPos()) && (this.getDisplayed() == null || !this.getDisplayed().equals(eq))) {
|
||||
// wrench it
|
||||
return super.onPartActivate(player, hand, pos);
|
||||
} else if (fluidInTank != null && fluidInTank.amount > 0) {
|
||||
if (this.getDisplayed() != null && getDisplayed().equals(AEFluidStack.fromFluidStack(fluidInTank))) {
|
||||
this.drainFluidContainer(player, hand);
|
||||
}
|
||||
} else {
|
||||
this.insertItem(player, hand, false);
|
||||
}
|
||||
}
|
||||
|
||||
//If its a fluid container, grab its fluidstack. if its empty pass its itemstack;
|
||||
//If its a fluid container, grab its fluidstack. if its empty pass its itemstack;
|
||||
|
||||
if( fluidInTank != null && fluidInTank.amount > 0 )
|
||||
{
|
||||
if( getDisplayed() instanceof IAEItemStack || getDisplayed() == null )
|
||||
{
|
||||
return super.onPartActivate( player, hand, pos );
|
||||
}
|
||||
if( ( (IAEFluidStack) this.getDisplayed() ).equals( AEFluidStack.fromFluidStack( fluidInTank ) ) )
|
||||
{
|
||||
this.drainFluidContainer( player, hand );
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.onPartActivate( player, hand, pos );
|
||||
}
|
||||
}
|
||||
else if( this.getDisplayed() != null && this.getDisplayed().equals( player.getHeldItem( hand ) ) )
|
||||
{
|
||||
this.insertItem( player, hand, false );
|
||||
}
|
||||
return super.onPartActivate( player, hand, pos );
|
||||
}
|
||||
if (fluidInTank != null && fluidInTank.amount > 0) {
|
||||
if (getDisplayed() instanceof IAEItemStack || getDisplayed() == null) {
|
||||
return super.onPartActivate(player, hand, pos);
|
||||
}
|
||||
if (((IAEFluidStack) this.getDisplayed()).equals(AEFluidStack.fromFluidStack(fluidInTank))) {
|
||||
this.drainFluidContainer(player, hand);
|
||||
} else {
|
||||
return super.onPartActivate(player, hand, pos);
|
||||
}
|
||||
} else if (this.getDisplayed() != null && this.getDisplayed().equals(player.getHeldItem(hand))) {
|
||||
this.insertItem(player, hand, false);
|
||||
}
|
||||
return super.onPartActivate(player, hand, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClicked( EntityPlayer player, EnumHand hand, Vec3d pos )
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onClicked(EntityPlayer player, EnumHand hand, Vec3d pos) {
|
||||
if (Platform.isClient()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if( !this.getProxy().isActive() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!this.getProxy().isActive()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !Platform.hasPermissions( this.getLocation(), player ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!Platform.hasPermissions(this.getLocation(), player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( this.getDisplayed() != null && this.getDisplayed() instanceof IAEItemStack )
|
||||
{
|
||||
this.extractItem( player, ( (IAEItemStack) this.getDisplayed() ).getDefinition().getMaxStackSize() );
|
||||
}
|
||||
else if( this.getDisplayed() != null && this.getDisplayed() instanceof IAEFluidStack )
|
||||
{
|
||||
this.fillFluidContainer( player,hand );
|
||||
}
|
||||
if (this.getDisplayed() != null && this.getDisplayed() instanceof IAEItemStack) {
|
||||
this.extractItem(player, ((IAEItemStack) this.getDisplayed()).getDefinition().getMaxStackSize());
|
||||
} else if (this.getDisplayed() != null && this.getDisplayed() instanceof IAEFluidStack) {
|
||||
this.fillFluidContainer(player, hand);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onShiftClicked( EntityPlayer player, EnumHand hand, Vec3d pos )
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onShiftClicked(EntityPlayer player, EnumHand hand, Vec3d pos) {
|
||||
if (Platform.isClient()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if( !this.getProxy().isActive() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!this.getProxy().isActive()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !Platform.hasPermissions( this.getLocation(), player ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!Platform.hasPermissions(this.getLocation(), player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( this.getDisplayed() != null )
|
||||
{
|
||||
this.extractItem( player, 1 );
|
||||
}
|
||||
if (this.getDisplayed() != null) {
|
||||
this.extractItem(player, 1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void insertItem( final EntityPlayer player, final EnumHand hand, final boolean allItems )
|
||||
{
|
||||
try
|
||||
{
|
||||
final IEnergySource energy = this.getProxy().getEnergy();
|
||||
final IMEMonitor<IAEItemStack> cell = this.getProxy()
|
||||
.getStorage()
|
||||
.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
|
||||
private void insertItem(final EntityPlayer player, final EnumHand hand, final boolean allItems) {
|
||||
try {
|
||||
final IEnergySource energy = this.getProxy().getEnergy();
|
||||
final IMEMonitor<IAEItemStack> cell = this.getProxy()
|
||||
.getStorage()
|
||||
.getInventory(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
|
||||
if( allItems )
|
||||
{
|
||||
if( this.getDisplayed() != null && this.getDisplayed() instanceof IAEItemStack)
|
||||
{
|
||||
final IAEItemStack input = (IAEItemStack) this.getDisplayed().copy();
|
||||
IItemHandler inv = new PlayerMainInvWrapper( player.inventory );
|
||||
if (allItems) {
|
||||
if (this.getDisplayed() != null && this.getDisplayed() instanceof IAEItemStack) {
|
||||
final IAEItemStack input = (IAEItemStack) this.getDisplayed().copy();
|
||||
IItemHandler inv = new PlayerMainInvWrapper(player.inventory);
|
||||
|
||||
for( int x = 0; x < inv.getSlots(); x++ )
|
||||
{
|
||||
final ItemStack targetStack = inv.getStackInSlot( x );
|
||||
if( input.equals( targetStack ) )
|
||||
{
|
||||
final ItemStack canExtract = inv.extractItem( x, targetStack.getCount(), true );
|
||||
if( !canExtract.isEmpty() )
|
||||
{
|
||||
input.setStackSize( canExtract.getCount() );
|
||||
final IAEItemStack failedToInsert = Platform.poweredInsert( energy, cell, input, new PlayerSource( player, this ) );
|
||||
inv.extractItem( x,
|
||||
failedToInsert == null ? canExtract.getCount() : canExtract.getCount() - (int) failedToInsert.getStackSize(),
|
||||
false );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
final IAEItemStack input = AEItemStack.fromItemStack( player.getHeldItem( hand ) );
|
||||
final IAEItemStack failedToInsert = Platform.poweredInsert( energy, cell, input, new PlayerSource( player, this ) );
|
||||
player.setHeldItem( hand, failedToInsert == null ? ItemStack.EMPTY : failedToInsert.createItemStack() );
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
for (int x = 0; x < inv.getSlots(); x++) {
|
||||
final ItemStack targetStack = inv.getStackInSlot(x);
|
||||
if (input.equals(targetStack)) {
|
||||
final ItemStack canExtract = inv.extractItem(x, targetStack.getCount(), true);
|
||||
if (!canExtract.isEmpty()) {
|
||||
input.setStackSize(canExtract.getCount());
|
||||
final IAEItemStack failedToInsert = Platform.poweredInsert(energy, cell, input, new PlayerSource(player, this));
|
||||
inv.extractItem(x,
|
||||
failedToInsert == null ? canExtract.getCount() : canExtract.getCount() - (int) failedToInsert.getStackSize(),
|
||||
false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final IAEItemStack input = AEItemStack.fromItemStack(player.getHeldItem(hand));
|
||||
final IAEItemStack failedToInsert = Platform.poweredInsert(energy, cell, input, new PlayerSource(player, this));
|
||||
player.setHeldItem(hand, failedToInsert == null ? ItemStack.EMPTY : failedToInsert.createItemStack());
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
private void extractItem( final EntityPlayer player, int count )
|
||||
{
|
||||
if (!(this.getDisplayed() instanceof IAEItemStack))
|
||||
return;
|
||||
final IAEItemStack input = (IAEItemStack) this.getDisplayed().copy();
|
||||
if( input != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
if( !this.getProxy().isActive() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
private void extractItem(final EntityPlayer player, int count) {
|
||||
if (!(this.getDisplayed() instanceof IAEItemStack))
|
||||
return;
|
||||
final IAEItemStack input = (IAEItemStack) this.getDisplayed().copy();
|
||||
if (input != null) {
|
||||
try {
|
||||
if (!this.getProxy().isActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final IEnergySource energy = this.getProxy().getEnergy();
|
||||
final IMEMonitor<IAEItemStack> cell = this.getProxy()
|
||||
.getStorage()
|
||||
.getInventory(
|
||||
AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
|
||||
final IEnergySource energy = this.getProxy().getEnergy();
|
||||
final IMEMonitor<IAEItemStack> cell = this.getProxy()
|
||||
.getStorage()
|
||||
.getInventory(
|
||||
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
|
||||
|
||||
input.setStackSize( count );
|
||||
input.setStackSize(count);
|
||||
|
||||
final IAEItemStack retrieved = Platform.poweredExtraction( energy, cell, input, new PlayerSource( player, this ) );
|
||||
if( retrieved != null )
|
||||
{
|
||||
ItemStack newItems = retrieved.createItemStack();
|
||||
final InventoryAdaptor adaptor = InventoryAdaptor.getAdaptor( player );
|
||||
newItems = adaptor.addItems( newItems );
|
||||
if( !newItems.isEmpty() )
|
||||
{
|
||||
final TileEntity te = this.getTile();
|
||||
final List<ItemStack> list = Collections.singletonList( newItems );
|
||||
Platform.spawnDrops( player.world, te.getPos().offset( this.getSide().getFacing() ), list );
|
||||
}
|
||||
final IAEItemStack retrieved = Platform.poweredExtraction(energy, cell, input, new PlayerSource(player, this));
|
||||
if (retrieved != null) {
|
||||
ItemStack newItems = retrieved.createItemStack();
|
||||
final InventoryAdaptor adaptor = InventoryAdaptor.getAdaptor(player);
|
||||
newItems = adaptor.addItems(newItems);
|
||||
if (!newItems.isEmpty()) {
|
||||
final TileEntity te = this.getTile();
|
||||
final List<ItemStack> list = Collections.singletonList(newItems);
|
||||
Platform.spawnDrops(player.world, te.getPos().offset(this.getSide().getFacing()), list);
|
||||
}
|
||||
|
||||
if( player.openContainer != null )
|
||||
{
|
||||
player.openContainer.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
}
|
||||
if (player.openContainer != null) {
|
||||
player.openContainer.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
} catch (final GridAccessException e) {
|
||||
// :P
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drainFluidContainer( final EntityPlayer player, final EnumHand hand ) {
|
||||
try
|
||||
{
|
||||
final ItemStack held = player.getHeldItem( hand );
|
||||
if( held.getCount() != 1 )
|
||||
{
|
||||
// only support stacksize 1 for now
|
||||
return;
|
||||
}
|
||||
private void drainFluidContainer(final EntityPlayer player, final EnumHand hand) {
|
||||
try {
|
||||
final ItemStack held = player.getHeldItem(hand);
|
||||
if (held.getCount() != 1) {
|
||||
// only support stacksize 1 for now
|
||||
return;
|
||||
}
|
||||
|
||||
final IFluidHandlerItem fh = FluidUtil.getFluidHandler( held );
|
||||
if( fh == null )
|
||||
{
|
||||
// only fluid handlers items
|
||||
return;
|
||||
}
|
||||
final IFluidHandlerItem fh = FluidUtil.getFluidHandler(held);
|
||||
if (fh == null) {
|
||||
// only fluid handlers items
|
||||
return;
|
||||
}
|
||||
|
||||
// See how much we can drain from the item
|
||||
final FluidStack extract = fh.drain( Integer.MAX_VALUE, false );
|
||||
if( extract == null || extract.amount < 1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
// See how much we can drain from the item
|
||||
final FluidStack extract = fh.drain(Integer.MAX_VALUE, false);
|
||||
if (extract == null || extract.amount < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if we can push into the system
|
||||
final IEnergySource energy = this.getProxy().getEnergy();
|
||||
final IMEMonitor<IAEFluidStack> cell = this.getProxy()
|
||||
.getStorage()
|
||||
.getInventory(
|
||||
AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) );
|
||||
final IAEFluidStack notStorable = Platform.poweredInsert( energy, cell, AEFluidStack.fromFluidStack( extract ), new PlayerSource( player, this ), Actionable.SIMULATE );
|
||||
// Check if we can push into the system
|
||||
final IEnergySource energy = this.getProxy().getEnergy();
|
||||
final IMEMonitor<IAEFluidStack> cell = this.getProxy()
|
||||
.getStorage()
|
||||
.getInventory(
|
||||
AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class));
|
||||
final IAEFluidStack notStorable = Platform.poweredInsert(energy, cell, AEFluidStack.fromFluidStack(extract), new PlayerSource(player, this), Actionable.SIMULATE);
|
||||
|
||||
if( notStorable != null && notStorable.getStackSize() > 0 )
|
||||
{
|
||||
final int toStore = (int) ( extract.amount - notStorable.getStackSize() );
|
||||
final FluidStack storable = fh.drain( toStore, false );
|
||||
if (notStorable != null && notStorable.getStackSize() > 0) {
|
||||
final int toStore = (int) (extract.amount - notStorable.getStackSize());
|
||||
final FluidStack storable = fh.drain(toStore, false);
|
||||
|
||||
if( storable == null || storable.amount == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
extract.amount = storable.amount;
|
||||
}
|
||||
}
|
||||
if (storable == null || storable.amount == 0) {
|
||||
return;
|
||||
} else {
|
||||
extract.amount = storable.amount;
|
||||
}
|
||||
}
|
||||
|
||||
// Actually drain
|
||||
final FluidStack drained = fh.drain( extract, true );
|
||||
extract.amount = drained.amount;
|
||||
// Actually drain
|
||||
final FluidStack drained = fh.drain(extract, true);
|
||||
extract.amount = drained.amount;
|
||||
|
||||
final IAEFluidStack notInserted = Platform.poweredInsert( energy, cell, AEFluidStack.fromFluidStack( extract ), new PlayerSource( player, this ) );
|
||||
final IAEFluidStack notInserted = Platform.poweredInsert(energy, cell, AEFluidStack.fromFluidStack(extract), new PlayerSource(player, this));
|
||||
|
||||
if( notInserted != null && notInserted.getStackSize() > 0 )
|
||||
{
|
||||
AELog.error( "Fluid item [%s] reported a different possible amount to drain than it actually provided.", held.getDisplayName() );
|
||||
}
|
||||
if (notInserted != null && notInserted.getStackSize() > 0) {
|
||||
AELog.error("Fluid item [%s] reported a different possible amount to drain than it actually provided.", held.getDisplayName());
|
||||
}
|
||||
|
||||
player.setHeldItem( hand, fh.getContainer() );
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
player.setHeldItem(hand, fh.getContainer());
|
||||
} catch (GridAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void fillFluidContainer( final EntityPlayer player, final EnumHand hand )
|
||||
{
|
||||
try
|
||||
{
|
||||
final ItemStack held = player.getHeldItem( hand );
|
||||
if( held.getCount() != 1 )
|
||||
{
|
||||
// only support stacksize 1 for now
|
||||
return;
|
||||
}
|
||||
private void fillFluidContainer(final EntityPlayer player, final EnumHand hand) {
|
||||
try {
|
||||
final ItemStack held = player.getHeldItem(hand);
|
||||
if (held.getCount() != 1) {
|
||||
// only support stacksize 1 for now
|
||||
return;
|
||||
}
|
||||
|
||||
final IFluidHandlerItem fh = FluidUtil.getFluidHandler( held );
|
||||
if( fh == null )
|
||||
{
|
||||
// only fluid handlers items
|
||||
return;
|
||||
}
|
||||
final IFluidHandlerItem fh = FluidUtil.getFluidHandler(held);
|
||||
if (fh == null) {
|
||||
// only fluid handlers items
|
||||
return;
|
||||
}
|
||||
|
||||
final IAEFluidStack stack = (IAEFluidStack) this.getDisplayed().copy();
|
||||
final IAEFluidStack stack = (IAEFluidStack) this.getDisplayed().copy();
|
||||
|
||||
// Check how much we can store in the item
|
||||
stack.setStackSize( Integer.MAX_VALUE );
|
||||
int amountAllowed = fh.fill( stack.getFluidStack(), false );
|
||||
stack.setStackSize( amountAllowed );
|
||||
// Check how much we can store in the item
|
||||
stack.setStackSize(Integer.MAX_VALUE);
|
||||
int amountAllowed = fh.fill(stack.getFluidStack(), false);
|
||||
stack.setStackSize(amountAllowed);
|
||||
|
||||
// Check if we can pull out of the system
|
||||
final IEnergySource energy = this.getProxy().getEnergy();
|
||||
final IMEMonitor<IAEFluidStack> cell = this.getProxy()
|
||||
.getStorage()
|
||||
.getInventory(
|
||||
AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) );
|
||||
final IAEFluidStack canPull = Platform.poweredExtraction( energy, cell, stack, new PlayerSource( player, this ), Actionable.SIMULATE );
|
||||
if( canPull == null || canPull.getStackSize() < 1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Check if we can pull out of the system
|
||||
final IEnergySource energy = this.getProxy().getEnergy();
|
||||
final IMEMonitor<IAEFluidStack> cell = this.getProxy()
|
||||
.getStorage()
|
||||
.getInventory(
|
||||
AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class));
|
||||
final IAEFluidStack canPull = Platform.poweredExtraction(energy, cell, stack, new PlayerSource(player, this), Actionable.SIMULATE);
|
||||
if (canPull == null || canPull.getStackSize() < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// How much could fit into the container
|
||||
final int canFill = fh.fill( canPull.getFluidStack(), false );
|
||||
if( canFill == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
// How much could fit into the container
|
||||
final int canFill = fh.fill(canPull.getFluidStack(), false);
|
||||
if (canFill == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Now actually pull out of the system
|
||||
stack.setStackSize( canFill );
|
||||
final IAEFluidStack pulled = Platform.poweredExtraction( energy, cell, stack, new PlayerSource( player, this ) );
|
||||
if( pulled == null || pulled.getStackSize() < 1 )
|
||||
{
|
||||
// Something went wrong
|
||||
AELog.error( "Unable to pull fluid out of the ME system even though the simulation said yes " );
|
||||
return;
|
||||
}
|
||||
// Now actually pull out of the system
|
||||
stack.setStackSize(canFill);
|
||||
final IAEFluidStack pulled = Platform.poweredExtraction(energy, cell, stack, new PlayerSource(player, this));
|
||||
if (pulled == null || pulled.getStackSize() < 1) {
|
||||
// Something went wrong
|
||||
AELog.error("Unable to pull fluid out of the ME system even though the simulation said yes ");
|
||||
return;
|
||||
}
|
||||
|
||||
// Actually fill
|
||||
final int used = fh.fill( pulled.getFluidStack(), true );
|
||||
// Actually fill
|
||||
final int used = fh.fill(pulled.getFluidStack(), true);
|
||||
|
||||
if( used != canFill )
|
||||
{
|
||||
AELog.error( "Fluid item [%s] reported a different possible amount than it actually accepted.", held.getDisplayName() );
|
||||
}
|
||||
player.setHeldItem( hand, fh.getContainer() );
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (used != canFill) {
|
||||
AELog.error("Fluid item [%s] reported a different possible amount than it actually accepted.", held.getDisplayName());
|
||||
}
|
||||
player.setHeldItem(hand, fh.getContainer());
|
||||
} catch (GridAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return this.selectModel( MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL,
|
||||
MODELS_LOCKED_OFF, MODELS_LOCKED_ON, MODELS_LOCKED_HAS_CHANNEL );
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return this.selectModel(MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL,
|
||||
MODELS_LOCKED_OFF, MODELS_LOCKED_ON, MODELS_LOCKED_HAS_CHANNEL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,14 +19,6 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
@@ -34,90 +26,84 @@ import appeng.helpers.Reflected;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.parts.PartModel;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class PartCraftingTerminal extends AbstractPartTerminal
|
||||
{
|
||||
public class PartCraftingTerminal extends AbstractPartTerminal {
|
||||
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/crafting_terminal_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/crafting_terminal_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation(AppEng.MOD_ID, "part/crafting_terminal_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation(AppEng.MOD_ID, "part/crafting_terminal_on");
|
||||
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF );
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, MODEL_ON, MODEL_STATUS_ON );
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL );
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF);
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_ON);
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL);
|
||||
|
||||
private final AppEngInternalInventory craftingGrid = new AppEngInternalInventory( this, 9 );
|
||||
private final AppEngInternalInventory craftingGrid = new AppEngInternalInventory(this, 9);
|
||||
|
||||
@Reflected
|
||||
public PartCraftingTerminal( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
@Reflected
|
||||
public PartCraftingTerminal(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops( final List<ItemStack> drops, final boolean wrenched )
|
||||
{
|
||||
super.getDrops( drops, wrenched );
|
||||
@Override
|
||||
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
|
||||
super.getDrops(drops, wrenched);
|
||||
|
||||
for( final ItemStack is : this.craftingGrid )
|
||||
{
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
drops.add( is );
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final ItemStack is : this.craftingGrid) {
|
||||
if (!is.isEmpty()) {
|
||||
drops.add(is);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.craftingGrid.readFromNBT( data, "craftingGrid" );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
this.craftingGrid.readFromNBT(data, "craftingGrid");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
this.craftingGrid.writeToNBT( data, "craftingGrid" );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
this.craftingGrid.writeToNBT(data, "craftingGrid");
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiBridge getGui( final EntityPlayer p )
|
||||
{
|
||||
int x = (int) p.posX;
|
||||
int y = (int) p.posY;
|
||||
int z = (int) p.posZ;
|
||||
if( this.getHost().getTile() != null )
|
||||
{
|
||||
x = this.getTile().getPos().getX();
|
||||
y = this.getTile().getPos().getY();
|
||||
z = this.getTile().getPos().getZ();
|
||||
}
|
||||
@Override
|
||||
public GuiBridge getGui(final EntityPlayer p) {
|
||||
int x = (int) p.posX;
|
||||
int y = (int) p.posY;
|
||||
int z = (int) p.posZ;
|
||||
if (this.getHost().getTile() != null) {
|
||||
x = this.getTile().getPos().getX();
|
||||
y = this.getTile().getPos().getY();
|
||||
z = this.getTile().getPos().getZ();
|
||||
}
|
||||
|
||||
if( GuiBridge.GUI_CRAFTING_TERMINAL.hasPermissions( this.getHost().getTile(), x, y, z, this.getSide(), p ) )
|
||||
{
|
||||
return GuiBridge.GUI_CRAFTING_TERMINAL;
|
||||
}
|
||||
return GuiBridge.GUI_ME;
|
||||
}
|
||||
if (GuiBridge.GUI_CRAFTING_TERMINAL.hasPermissions(this.getHost().getTile(), x, y, z, this.getSide(), p)) {
|
||||
return GuiBridge.GUI_CRAFTING_TERMINAL;
|
||||
}
|
||||
return GuiBridge.GUI_ME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventoryByName( final String name )
|
||||
{
|
||||
if( name.equals( "crafting" ) )
|
||||
{
|
||||
return this.craftingGrid;
|
||||
}
|
||||
return super.getInventoryByName( name );
|
||||
}
|
||||
@Override
|
||||
public IItemHandler getInventoryByName(final String name) {
|
||||
if (name.equals("crafting")) {
|
||||
return this.craftingGrid;
|
||||
}
|
||||
return super.getInventoryByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return this.selectModel( MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL );
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return this.selectModel(MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,43 +19,38 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.parts.PartModel;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
|
||||
public class PartDarkPanel extends AbstractPartPanel
|
||||
{
|
||||
public class PartDarkPanel extends AbstractPartPanel {
|
||||
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/monitor_dark_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/monitor_dark_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation(AppEng.MOD_ID, "part/monitor_dark_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation(AppEng.MOD_ID, "part/monitor_dark_on");
|
||||
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, MODEL_OFF );
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, MODEL_ON );
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, MODEL_OFF);
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_ON);
|
||||
|
||||
@Reflected
|
||||
public PartDarkPanel( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
@Reflected
|
||||
public PartDarkPanel(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getBrightnessColor()
|
||||
{
|
||||
return this.getColor().mediumVariant;
|
||||
}
|
||||
@Override
|
||||
protected int getBrightnessColor() {
|
||||
return this.getColor().mediumVariant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return this.isPowered() ? MODELS_ON : MODELS_OFF;
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return this.isPowered() ? MODELS_ON : MODELS_OFF;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,100 +23,84 @@ import static appeng.helpers.PatternHelper.PROCESSING_INPUT_LIMIT;
|
||||
import static appeng.helpers.PatternHelper.PROCESSING_OUTPUT_LIMIT;
|
||||
|
||||
|
||||
public class PartExpandedProcessingPatternTerminal extends AbstractPartTerminal
|
||||
{
|
||||
public class PartExpandedProcessingPatternTerminal extends AbstractPartTerminal {
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/expanded_processing_pattern_terminal_off" );
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation(AppEng.MOD_ID, "part/expanded_processing_pattern_terminal_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/expanded_processing_pattern_terminal_on" );
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation(AppEng.MOD_ID, "part/expanded_processing_pattern_terminal_on");
|
||||
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF );
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, MODEL_ON, MODEL_STATUS_ON );
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL );
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF);
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_ON);
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL);
|
||||
|
||||
private final AppEngInternalInventory crafting = new AppEngInternalInventory( this, PROCESSING_INPUT_LIMIT );
|
||||
private final AppEngInternalInventory crafting = new AppEngInternalInventory(this, PROCESSING_INPUT_LIMIT);
|
||||
|
||||
private final AppEngInternalInventory output = new AppEngInternalInventory( this, PROCESSING_OUTPUT_LIMIT );
|
||||
private final AppEngInternalInventory pattern = new AppEngInternalInventory( this, 2 );
|
||||
private final AppEngInternalInventory output = new AppEngInternalInventory(this, PROCESSING_OUTPUT_LIMIT);
|
||||
private final AppEngInternalInventory pattern = new AppEngInternalInventory(this, 2);
|
||||
|
||||
@Reflected
|
||||
public PartExpandedProcessingPatternTerminal( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
public PartExpandedProcessingPatternTerminal(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops( final List<ItemStack> drops, final boolean wrenched )
|
||||
{
|
||||
for( final ItemStack is : this.pattern )
|
||||
{
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
drops.add( is );
|
||||
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
|
||||
for (final ItemStack is : this.pattern) {
|
||||
if (!is.isEmpty()) {
|
||||
drops.add(is);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( NBTTagCompound data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.crafting.readFromNBT( data, "processingGrid" );
|
||||
this.pattern.readFromNBT( data, "pattern" );
|
||||
this.output.readFromNBT( data, "outputList" );
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
this.crafting.readFromNBT(data, "processingGrid");
|
||||
this.pattern.readFromNBT(data, "pattern");
|
||||
this.output.readFromNBT(data, "outputList");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( NBTTagCompound data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
this.crafting.writeToNBT( data, "processingGrid" );
|
||||
this.pattern.writeToNBT( data, "pattern" );
|
||||
this.output.writeToNBT( data, "outputList" );
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
this.crafting.writeToNBT(data, "processingGrid");
|
||||
this.pattern.writeToNBT(data, "pattern");
|
||||
this.output.writeToNBT(data, "outputList");
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiBridge getGui( final EntityPlayer p )
|
||||
{
|
||||
public GuiBridge getGui(final EntityPlayer p) {
|
||||
int x = (int) p.posX;
|
||||
int y = (int) p.posY;
|
||||
int z = (int) p.posZ;
|
||||
if( this.getHost().getTile() != null )
|
||||
{
|
||||
if (this.getHost().getTile() != null) {
|
||||
x = this.getTile().getPos().getX();
|
||||
y = this.getTile().getPos().getY();
|
||||
z = this.getTile().getPos().getZ();
|
||||
}
|
||||
|
||||
if( GuiBridge.GUI_EXPANDED_PROCESSING_PATTERN_TERMINAL.hasPermissions( this.getHost().getTile(), x, y, z, this.getSide(), p ) )
|
||||
{
|
||||
if (GuiBridge.GUI_EXPANDED_PROCESSING_PATTERN_TERMINAL.hasPermissions(this.getHost().getTile(), x, y, z, this.getSide(), p)) {
|
||||
return GuiBridge.GUI_EXPANDED_PROCESSING_PATTERN_TERMINAL;
|
||||
}
|
||||
return GuiBridge.GUI_ME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
|
||||
{
|
||||
if( inv == this.pattern && slot == 1 )
|
||||
{
|
||||
final ItemStack is = this.pattern.getStackInSlot( 1 );
|
||||
if( !is.isEmpty() && is.getItem() instanceof ICraftingPatternItem )
|
||||
{
|
||||
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
|
||||
if (inv == this.pattern && slot == 1) {
|
||||
final ItemStack is = this.pattern.getStackInSlot(1);
|
||||
if (!is.isEmpty() && is.getItem() instanceof ICraftingPatternItem) {
|
||||
final ICraftingPatternItem pattern = (ICraftingPatternItem) is.getItem();
|
||||
final ICraftingPatternDetails details = pattern.getPatternForItem( is, this.getHost().getTile().getWorld() );
|
||||
if( details != null )
|
||||
{
|
||||
for( int x = 0; x < this.crafting.getSlots() && x < details.getInputs().length; x++ )
|
||||
{
|
||||
final ICraftingPatternDetails details = pattern.getPatternForItem(is, this.getHost().getTile().getWorld());
|
||||
if (details != null) {
|
||||
for (int x = 0; x < this.crafting.getSlots() && x < details.getInputs().length; x++) {
|
||||
final IAEItemStack item = details.getInputs()[x];
|
||||
this.crafting.setStackInSlot( x, item == null ? ItemStack.EMPTY : item.createItemStack() );
|
||||
this.crafting.setStackInSlot(x, item == null ? ItemStack.EMPTY : item.createItemStack());
|
||||
}
|
||||
|
||||
for( int x = 0; x < this.output.getSlots() && x < details.getOutputs().length; x++ )
|
||||
{
|
||||
for (int x = 0; x < this.output.getSlots() && x < details.getOutputs().length; x++) {
|
||||
final IAEItemStack item = details.getOutputs()[x];
|
||||
this.output.setStackInSlot( x, item == null ? ItemStack.EMPTY : item.createItemStack() );
|
||||
this.output.setStackInSlot(x, item == null ? ItemStack.EMPTY : item.createItemStack());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,27 +110,22 @@ public class PartExpandedProcessingPatternTerminal extends AbstractPartTerminal
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventoryByName( final String name )
|
||||
{
|
||||
if( name.equals( "crafting" ) )
|
||||
{
|
||||
public IItemHandler getInventoryByName(final String name) {
|
||||
if (name.equals("crafting")) {
|
||||
return this.crafting;
|
||||
}
|
||||
if( name.equals( "output" ) )
|
||||
{
|
||||
if (name.equals("output")) {
|
||||
return this.output;
|
||||
}
|
||||
if( name.equals( "pattern" ) )
|
||||
{
|
||||
if (name.equals("pattern")) {
|
||||
return this.pattern;
|
||||
}
|
||||
return super.getInventoryByName( name );
|
||||
return super.getInventoryByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return this.selectModel( MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL );
|
||||
public IPartModel getStaticModels() {
|
||||
return this.selectModel(MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,59 +19,51 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.parts.PartModel;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
|
||||
public class PartInterfaceConfigurationTerminal extends AbstractPartDisplay
|
||||
{
|
||||
public class PartInterfaceConfigurationTerminal extends AbstractPartDisplay {
|
||||
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/interface_configuration_terminal_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/interface_configuration_terminal_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation(AppEng.MOD_ID, "part/interface_configuration_terminal_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation(AppEng.MOD_ID, "part/interface_configuration_terminal_on");
|
||||
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF );
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, MODEL_ON, MODEL_STATUS_ON );
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL );
|
||||
public String in = "";
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF);
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_ON);
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL);
|
||||
public String in = "";
|
||||
|
||||
public PartInterfaceConfigurationTerminal( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
public PartInterfaceConfigurationTerminal(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
|
||||
{
|
||||
if( !super.onPartActivate( player, hand, pos ) )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_INTERFACE_CONFIGURATION_TERMINAL );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
|
||||
if (!super.onPartActivate(player, hand, pos)) {
|
||||
if (Platform.isServer()) {
|
||||
Platform.openGUI(player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_INTERFACE_CONFIGURATION_TERMINAL);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return this.selectModel( MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL );
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return this.selectModel(MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL);
|
||||
}
|
||||
|
||||
public void saveSearchStrings( String in )
|
||||
{
|
||||
this.in = in;
|
||||
}
|
||||
public void saveSearchStrings(String in) {
|
||||
this.in = in;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,61 +19,54 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.parts.PartModel;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
|
||||
public class PartInterfaceTerminal extends AbstractPartDisplay
|
||||
{
|
||||
public class PartInterfaceTerminal extends AbstractPartDisplay {
|
||||
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/interface_terminal_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/interface_terminal_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation(AppEng.MOD_ID, "part/interface_terminal_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation(AppEng.MOD_ID, "part/interface_terminal_on");
|
||||
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF );
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, MODEL_ON, MODEL_STATUS_ON );
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL );
|
||||
public String in = "";
|
||||
public String out = "";
|
||||
public boolean onlyInterfacesWithFreeSlots = false;
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF);
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_ON);
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL);
|
||||
public String in = "";
|
||||
public String out = "";
|
||||
public boolean onlyInterfacesWithFreeSlots = false;
|
||||
|
||||
public PartInterfaceTerminal( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
public PartInterfaceTerminal(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
|
||||
{
|
||||
if( !super.onPartActivate( player, hand, pos ) )
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
Platform.openGUI( player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_INTERFACE_TERMINAL );
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean onPartActivate(final EntityPlayer player, final EnumHand hand, final Vec3d pos) {
|
||||
if (!super.onPartActivate(player, hand, pos)) {
|
||||
if (Platform.isServer()) {
|
||||
Platform.openGUI(player, this.getHost().getTile(), this.getSide(), GuiBridge.GUI_INTERFACE_TERMINAL);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return this.selectModel( MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL );
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return this.selectModel(MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL);
|
||||
}
|
||||
|
||||
public void saveSearchStrings(String in, String out){
|
||||
this.in = in;
|
||||
this.out = out;
|
||||
}
|
||||
public void saveSearchStrings(String in, String out) {
|
||||
this.in = in;
|
||||
this.out = out;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,43 +19,38 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.parts.PartModel;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
|
||||
public class PartPanel extends AbstractPartPanel
|
||||
{
|
||||
public class PartPanel extends AbstractPartPanel {
|
||||
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/monitor_bright_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/monitor_bright_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation(AppEng.MOD_ID, "part/monitor_bright_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation(AppEng.MOD_ID, "part/monitor_bright_on");
|
||||
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, MODEL_OFF );
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, MODEL_ON );
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, MODEL_OFF);
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_ON);
|
||||
|
||||
@Reflected
|
||||
public PartPanel( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
@Reflected
|
||||
public PartPanel(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getBrightnessColor()
|
||||
{
|
||||
return this.getColor().whiteVariant;
|
||||
}
|
||||
@Override
|
||||
protected int getBrightnessColor() {
|
||||
return this.getColor().whiteVariant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return this.isPowered() ? MODELS_ON : MODELS_OFF;
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return this.isPowered() ? MODELS_ON : MODELS_OFF;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,14 +19,6 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.implementations.ICraftingPatternItem;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.parts.IPartModel;
|
||||
@@ -38,184 +30,160 @@ import appeng.items.parts.PartModels;
|
||||
import appeng.parts.PartModel;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class PartPatternTerminal extends AbstractPartTerminal
|
||||
{
|
||||
public class PartPatternTerminal extends AbstractPartTerminal {
|
||||
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/pattern_terminal_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/pattern_terminal_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation(AppEng.MOD_ID, "part/pattern_terminal_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation(AppEng.MOD_ID, "part/pattern_terminal_on");
|
||||
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF );
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, MODEL_ON, MODEL_STATUS_ON );
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL );
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF);
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_ON);
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL);
|
||||
|
||||
private final AppEngInternalInventory crafting = new AppEngInternalInventory( this, 9 );
|
||||
private final AppEngInternalInventory output = new AppEngInternalInventory( this, 3 );
|
||||
private final AppEngInternalInventory pattern = new AppEngInternalInventory( this, 2 );
|
||||
private final AppEngInternalInventory crafting = new AppEngInternalInventory(this, 9);
|
||||
private final AppEngInternalInventory output = new AppEngInternalInventory(this, 3);
|
||||
private final AppEngInternalInventory pattern = new AppEngInternalInventory(this, 2);
|
||||
|
||||
private boolean craftingMode = true;
|
||||
private boolean substitute = false;
|
||||
private boolean craftingMode = true;
|
||||
private boolean substitute = false;
|
||||
|
||||
@Reflected
|
||||
public PartPatternTerminal( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
@Reflected
|
||||
public PartPatternTerminal(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops( final List<ItemStack> drops, final boolean wrenched )
|
||||
{
|
||||
for( final ItemStack is : this.pattern )
|
||||
{
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
drops.add( is );
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void getDrops(final List<ItemStack> drops, final boolean wrenched) {
|
||||
for (final ItemStack is : this.pattern) {
|
||||
if (!is.isEmpty()) {
|
||||
drops.add(is);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.setCraftingRecipe( data.getBoolean( "craftingMode" ) );
|
||||
this.setSubstitution( data.getBoolean( "substitute" ) );
|
||||
this.pattern.readFromNBT( data, "pattern" );
|
||||
this.output.readFromNBT( data, "outputList" );
|
||||
this.crafting.readFromNBT( data, "craftingGrid" );
|
||||
}
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
this.setCraftingRecipe(data.getBoolean("craftingMode"));
|
||||
this.setSubstitution(data.getBoolean("substitute"));
|
||||
this.pattern.readFromNBT(data, "pattern");
|
||||
this.output.readFromNBT(data, "outputList");
|
||||
this.crafting.readFromNBT(data, "craftingGrid");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound data )
|
||||
{
|
||||
super.writeToNBT( data );
|
||||
data.setBoolean( "craftingMode", this.craftingMode );
|
||||
data.setBoolean( "substitute", this.substitute );
|
||||
this.pattern.writeToNBT( data, "pattern" );
|
||||
this.output.writeToNBT( data, "outputList" );
|
||||
this.crafting.writeToNBT( data, "craftingGrid" );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
data.setBoolean("craftingMode", this.craftingMode);
|
||||
data.setBoolean("substitute", this.substitute);
|
||||
this.pattern.writeToNBT(data, "pattern");
|
||||
this.output.writeToNBT(data, "outputList");
|
||||
this.crafting.writeToNBT(data, "craftingGrid");
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiBridge getGui( final EntityPlayer p )
|
||||
{
|
||||
int x = (int) p.posX;
|
||||
int y = (int) p.posY;
|
||||
int z = (int) p.posZ;
|
||||
if( this.getHost().getTile() != null )
|
||||
{
|
||||
x = this.getTile().getPos().getX();
|
||||
y = this.getTile().getPos().getY();
|
||||
z = this.getTile().getPos().getZ();
|
||||
}
|
||||
@Override
|
||||
public GuiBridge getGui(final EntityPlayer p) {
|
||||
int x = (int) p.posX;
|
||||
int y = (int) p.posY;
|
||||
int z = (int) p.posZ;
|
||||
if (this.getHost().getTile() != null) {
|
||||
x = this.getTile().getPos().getX();
|
||||
y = this.getTile().getPos().getY();
|
||||
z = this.getTile().getPos().getZ();
|
||||
}
|
||||
|
||||
if( GuiBridge.GUI_PATTERN_TERMINAL.hasPermissions( this.getHost().getTile(), x, y, z, this.getSide(), p ) )
|
||||
{
|
||||
return GuiBridge.GUI_PATTERN_TERMINAL;
|
||||
}
|
||||
return GuiBridge.GUI_ME;
|
||||
}
|
||||
if (GuiBridge.GUI_PATTERN_TERMINAL.hasPermissions(this.getHost().getTile(), x, y, z, this.getSide(), p)) {
|
||||
return GuiBridge.GUI_PATTERN_TERMINAL;
|
||||
}
|
||||
return GuiBridge.GUI_ME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
|
||||
{
|
||||
if( inv == this.pattern && slot == 1 )
|
||||
{
|
||||
final ItemStack is = this.pattern.getStackInSlot( 1 );
|
||||
if( !is.isEmpty() && is.getItem() instanceof ICraftingPatternItem )
|
||||
{
|
||||
final ICraftingPatternItem pattern = (ICraftingPatternItem) is.getItem();
|
||||
final ICraftingPatternDetails details = pattern.getPatternForItem( is, this.getHost().getTile().getWorld() );
|
||||
if( details != null )
|
||||
{
|
||||
this.setCraftingRecipe( details.isCraftable() );
|
||||
this.setSubstitution( details.canSubstitute() );
|
||||
@Override
|
||||
public void onChangeInventory(final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack) {
|
||||
if (inv == this.pattern && slot == 1) {
|
||||
final ItemStack is = this.pattern.getStackInSlot(1);
|
||||
if (!is.isEmpty() && is.getItem() instanceof ICraftingPatternItem) {
|
||||
final ICraftingPatternItem pattern = (ICraftingPatternItem) is.getItem();
|
||||
final ICraftingPatternDetails details = pattern.getPatternForItem(is, this.getHost().getTile().getWorld());
|
||||
if (details != null) {
|
||||
this.setCraftingRecipe(details.isCraftable());
|
||||
this.setSubstitution(details.canSubstitute());
|
||||
|
||||
for( int x = 0; x < this.crafting.getSlots() && x < details.getInputs().length; x++ )
|
||||
{
|
||||
final IAEItemStack item = details.getInputs()[x];
|
||||
this.crafting.setStackInSlot( x, item == null ? ItemStack.EMPTY : item.createItemStack() );
|
||||
}
|
||||
for (int x = 0; x < this.crafting.getSlots() && x < details.getInputs().length; x++) {
|
||||
final IAEItemStack item = details.getInputs()[x];
|
||||
this.crafting.setStackInSlot(x, item == null ? ItemStack.EMPTY : item.createItemStack());
|
||||
}
|
||||
|
||||
for( int x = 0; x < this.output.getSlots() && x < details.getOutputs().length; x++ )
|
||||
{
|
||||
final IAEItemStack item = details.getOutputs()[x];
|
||||
this.output.setStackInSlot( x, item == null ? ItemStack.EMPTY : item.createItemStack() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( inv == this.crafting )
|
||||
{
|
||||
this.fixCraftingRecipes();
|
||||
}
|
||||
for (int x = 0; x < this.output.getSlots() && x < details.getOutputs().length; x++) {
|
||||
final IAEItemStack item = details.getOutputs()[x];
|
||||
this.output.setStackInSlot(x, item == null ? ItemStack.EMPTY : item.createItemStack());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (inv == this.crafting) {
|
||||
this.fixCraftingRecipes();
|
||||
}
|
||||
|
||||
this.getHost().markForSave();
|
||||
}
|
||||
this.getHost().markForSave();
|
||||
}
|
||||
|
||||
private void fixCraftingRecipes()
|
||||
{
|
||||
if( this.craftingMode )
|
||||
{
|
||||
for( int x = 0; x < this.crafting.getSlots(); x++ )
|
||||
{
|
||||
final ItemStack is = this.crafting.getStackInSlot( x );
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
is.setCount( 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void fixCraftingRecipes() {
|
||||
if (this.craftingMode) {
|
||||
for (int x = 0; x < this.crafting.getSlots(); x++) {
|
||||
final ItemStack is = this.crafting.getStackInSlot(x);
|
||||
if (!is.isEmpty()) {
|
||||
is.setCount(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCraftingRecipe()
|
||||
{
|
||||
return this.craftingMode;
|
||||
}
|
||||
public boolean isCraftingRecipe() {
|
||||
return this.craftingMode;
|
||||
}
|
||||
|
||||
public void setCraftingRecipe( final boolean craftingMode )
|
||||
{
|
||||
this.craftingMode = craftingMode;
|
||||
this.fixCraftingRecipes();
|
||||
}
|
||||
public void setCraftingRecipe(final boolean craftingMode) {
|
||||
this.craftingMode = craftingMode;
|
||||
this.fixCraftingRecipes();
|
||||
}
|
||||
|
||||
public boolean isSubstitution()
|
||||
{
|
||||
return this.substitute;
|
||||
}
|
||||
public boolean isSubstitution() {
|
||||
return this.substitute;
|
||||
}
|
||||
|
||||
public void setSubstitution( final boolean canSubstitute )
|
||||
{
|
||||
this.substitute = canSubstitute;
|
||||
}
|
||||
public void setSubstitution(final boolean canSubstitute) {
|
||||
this.substitute = canSubstitute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemHandler getInventoryByName( final String name )
|
||||
{
|
||||
if( name.equals( "crafting" ) )
|
||||
{
|
||||
return this.crafting;
|
||||
}
|
||||
@Override
|
||||
public IItemHandler getInventoryByName(final String name) {
|
||||
if (name.equals("crafting")) {
|
||||
return this.crafting;
|
||||
}
|
||||
|
||||
if( name.equals( "output" ) )
|
||||
{
|
||||
return this.output;
|
||||
}
|
||||
if (name.equals("output")) {
|
||||
return this.output;
|
||||
}
|
||||
|
||||
if( name.equals( "pattern" ) )
|
||||
{
|
||||
return this.pattern;
|
||||
}
|
||||
if (name.equals("pattern")) {
|
||||
return this.pattern;
|
||||
}
|
||||
|
||||
return super.getInventoryByName( name );
|
||||
}
|
||||
return super.getInventoryByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return this.selectModel( MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL );
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return this.selectModel(MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,44 +19,39 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.parts.PartModel;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
|
||||
public class PartSemiDarkPanel extends AbstractPartPanel
|
||||
{
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/monitor_medium_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/monitor_medium_on" );
|
||||
public class PartSemiDarkPanel extends AbstractPartPanel {
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation(AppEng.MOD_ID, "part/monitor_medium_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation(AppEng.MOD_ID, "part/monitor_medium_on");
|
||||
|
||||
public static final PartModel MODELS_OFF = new PartModel( MODEL_BASE, MODEL_OFF );
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, MODEL_ON );
|
||||
public static final PartModel MODELS_OFF = new PartModel(MODEL_BASE, MODEL_OFF);
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_ON);
|
||||
|
||||
@Reflected
|
||||
public PartSemiDarkPanel( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
@Reflected
|
||||
public PartSemiDarkPanel(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getBrightnessColor()
|
||||
{
|
||||
final int light = this.getColor().whiteVariant;
|
||||
final int dark = this.getColor().mediumVariant;
|
||||
return ( ( ( ( ( light >> 16 ) & 0xff ) + ( ( dark >> 16 ) & 0xff ) ) / 2 ) << 16 ) | ( ( ( ( ( light >> 8 ) & 0xff ) + ( ( dark >> 8 ) & 0xff ) ) / 2 ) << 8 ) | ( ( ( ( light ) & 0xff ) + ( ( dark ) & 0xff ) ) / 2 );
|
||||
}
|
||||
@Override
|
||||
protected int getBrightnessColor() {
|
||||
final int light = this.getColor().whiteVariant;
|
||||
final int dark = this.getColor().mediumVariant;
|
||||
return (((((light >> 16) & 0xff) + ((dark >> 16) & 0xff)) / 2) << 16) | (((((light >> 8) & 0xff) + ((dark >> 8) & 0xff)) / 2) << 8) | ((((light) & 0xff) + ((dark) & 0xff)) / 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return this.isPowered() ? MODELS_ON : MODELS_OFF;
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return this.isPowered() ? MODELS_ON : MODELS_OFF;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,14 +19,13 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.parts.PartModel;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
|
||||
/**
|
||||
@@ -35,36 +34,33 @@ import appeng.parts.PartModel;
|
||||
* @version rv2
|
||||
* @since rv0
|
||||
*/
|
||||
public class PartStorageMonitor extends AbstractPartMonitor
|
||||
{
|
||||
public class PartStorageMonitor extends AbstractPartMonitor {
|
||||
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/storage_monitor_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/storage_monitor_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_LOCKED_OFF = new ResourceLocation( AppEng.MOD_ID, "part/storage_monitor_locked_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_LOCKED_ON = new ResourceLocation( AppEng.MOD_ID, "part/storage_monitor_locked_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation(AppEng.MOD_ID, "part/storage_monitor_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation(AppEng.MOD_ID, "part/storage_monitor_on");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_LOCKED_OFF = new ResourceLocation(AppEng.MOD_ID, "part/storage_monitor_locked_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_LOCKED_ON = new ResourceLocation(AppEng.MOD_ID, "part/storage_monitor_locked_on");
|
||||
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF );
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, MODEL_ON, MODEL_STATUS_ON );
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL );
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF);
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_ON);
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL);
|
||||
|
||||
public static final IPartModel MODELS_LOCKED_OFF = new PartModel( MODEL_BASE, MODEL_LOCKED_OFF, MODEL_STATUS_OFF );
|
||||
public static final IPartModel MODELS_LOCKED_ON = new PartModel( MODEL_BASE, MODEL_LOCKED_ON, MODEL_STATUS_ON );
|
||||
public static final IPartModel MODELS_LOCKED_HAS_CHANNEL = new PartModel( MODEL_BASE, MODEL_LOCKED_ON, MODEL_STATUS_HAS_CHANNEL );
|
||||
public static final IPartModel MODELS_LOCKED_OFF = new PartModel(MODEL_BASE, MODEL_LOCKED_OFF, MODEL_STATUS_OFF);
|
||||
public static final IPartModel MODELS_LOCKED_ON = new PartModel(MODEL_BASE, MODEL_LOCKED_ON, MODEL_STATUS_ON);
|
||||
public static final IPartModel MODELS_LOCKED_HAS_CHANNEL = new PartModel(MODEL_BASE, MODEL_LOCKED_ON, MODEL_STATUS_HAS_CHANNEL);
|
||||
|
||||
@Reflected
|
||||
public PartStorageMonitor( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
@Reflected
|
||||
public PartStorageMonitor(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return this.selectModel( MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL,
|
||||
MODELS_LOCKED_OFF, MODELS_LOCKED_ON, MODELS_LOCKED_HAS_CHANNEL );
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return this.selectModel(MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL,
|
||||
MODELS_LOCKED_OFF, MODELS_LOCKED_ON, MODELS_LOCKED_HAS_CHANNEL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,35 +19,31 @@
|
||||
package appeng.parts.reporting;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import appeng.api.parts.IPartModel;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.parts.PartModel;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
|
||||
public class PartTerminal extends AbstractPartTerminal
|
||||
{
|
||||
public class PartTerminal extends AbstractPartTerminal {
|
||||
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation( AppEng.MOD_ID, "part/terminal_off" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation( AppEng.MOD_ID, "part/terminal_on" );
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_OFF = new ResourceLocation(AppEng.MOD_ID, "part/terminal_off");
|
||||
@PartModels
|
||||
public static final ResourceLocation MODEL_ON = new ResourceLocation(AppEng.MOD_ID, "part/terminal_on");
|
||||
|
||||
public static final IPartModel MODELS_OFF = new PartModel( MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF );
|
||||
public static final IPartModel MODELS_ON = new PartModel( MODEL_BASE, MODEL_ON, MODEL_STATUS_ON );
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel( MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL );
|
||||
public static final IPartModel MODELS_OFF = new PartModel(MODEL_BASE, MODEL_OFF, MODEL_STATUS_OFF);
|
||||
public static final IPartModel MODELS_ON = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_ON);
|
||||
public static final IPartModel MODELS_HAS_CHANNEL = new PartModel(MODEL_BASE, MODEL_ON, MODEL_STATUS_HAS_CHANNEL);
|
||||
|
||||
public PartTerminal( final ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
}
|
||||
public PartTerminal(final ItemStack is) {
|
||||
super(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPartModel getStaticModels()
|
||||
{
|
||||
return this.selectModel( MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL );
|
||||
}
|
||||
@Override
|
||||
public IPartModel getStaticModels() {
|
||||
return this.selectModel(MODELS_OFF, MODELS_ON, MODELS_HAS_CHANNEL);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user