pick 97420a31d The big reformat of 2020

This commit is contained in:
yueh
2020-06-16 21:41:28 +02:00
parent 5304b3febe
commit 5225ea426b
2252 changed files with 95466 additions and 118582 deletions
@@ -18,6 +18,14 @@
package appeng.parts.networking;
import java.io.IOException;
import java.util.EnumSet;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.Direction;
import appeng.api.AEApi;
import appeng.api.config.SecurityPermissions;
@@ -39,394 +47,309 @@ import appeng.items.parts.ColoredPartItem;
import appeng.me.GridAccessException;
import appeng.parts.AEBasePart;
import appeng.util.Platform;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.Direction;
import java.io.IOException;
import java.util.EnumSet;
public class PartCable extends AEBasePart implements IPartCable {
private final int[] channelsOnSide = { 0, 0, 0, 0, 0, 0 };
public class PartCable extends AEBasePart implements IPartCable
{
private EnumSet<AEPartLocation> connections = EnumSet.noneOf(AEPartLocation.class);
private boolean powered = false;
private final int[] channelsOnSide = { 0, 0, 0, 0, 0, 0 };
public PartCable(final ItemStack is) {
super(is);
this.getProxy().setFlags(GridFlags.PREFERRED);
this.getProxy().setIdlePowerUsage(0.0);
if (is.getItem() instanceof ColoredPartItem) {
ColoredPartItem<?> coloredPartItem = (ColoredPartItem<?>) is.getItem();
this.getProxy().setColor(coloredPartItem.getColor());
}
}
private EnumSet<AEPartLocation> connections = EnumSet.noneOf( AEPartLocation.class );
private boolean powered = false;
@Override
public BusSupport supportsBuses() {
return BusSupport.CABLE;
}
public PartCable( final ItemStack is )
{
super( is );
this.getProxy().setFlags( GridFlags.PREFERRED );
this.getProxy().setIdlePowerUsage( 0.0 );
if (is.getItem() instanceof ColoredPartItem) {
ColoredPartItem<?> coloredPartItem = (ColoredPartItem<?>) is.getItem();
this.getProxy().setColor(coloredPartItem.getColor());
}
}
@Override
public AEColor getCableColor() {
return this.getProxy().getColor();
}
@Override
public BusSupport supportsBuses()
{
return BusSupport.CABLE;
}
@Override
public AECableType getCableConnectionType() {
return AECableType.GLASS;
}
@Override
public AEColor getCableColor()
{
return this.getProxy().getColor();
}
@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 AECableType getCableConnectionType()
{
return AECableType.GLASS;
}
@Override
public boolean changeColor(final AEColor newColor, final PlayerEntity who) {
if (this.getCableColor() != newColor) {
ItemStack newPart = null;
@Override
public float getCableConnectionLength( AECableType cable )
{
if( cable == this.getCableConnectionType() )
{
return 4;
}
else if( cable.ordinal() >= this.getCableConnectionType().ordinal() )
{
return -1;
}
else
{
return 8;
}
}
final IParts parts = AEApi.instance().definitions().parts();
@Override
public boolean changeColor( final AEColor newColor, final PlayerEntity who )
{
if( this.getCableColor() != newColor )
{
ItemStack newPart = null;
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);
}
final IParts parts = AEApi.instance().definitions().parts();
boolean hasPermission = true;
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 );
}
try {
hasPermission = this.getProxy().getSecurity().hasPermission(who, SecurityPermissions.BUILD);
} catch (final GridAccessException e) {
// :P
}
boolean hasPermission = true;
if (newPart != null && hasPermission) {
if (Platform.isClient()) {
return true;
}
try
{
hasPermission = this.getProxy().getSecurity().hasPermission( who, SecurityPermissions.BUILD );
}
catch( final GridAccessException e )
{
// :P
}
this.getHost().removePart(AEPartLocation.INTERNAL, true);
this.getHost().addPart(newPart, AEPartLocation.INTERNAL, who, null);
return true;
}
}
return false;
}
if( newPart != null && hasPermission )
{
if( Platform.isClient() )
{
return true;
}
@Override
public void setValidSides(final EnumSet<Direction> sides) {
this.getProxy().setValidSides(sides);
}
this.getHost().removePart( AEPartLocation.INTERNAL, true );
this.getHost().addPart( newPart, AEPartLocation.INTERNAL, who, null );
return true;
}
}
return false;
}
@Override
public boolean isConnected(final Direction side) {
return this.getConnections().contains(AEPartLocation.fromFacing(side));
}
@Override
public void setValidSides( final EnumSet<Direction> sides )
{
this.getProxy().setValidSides( sides );
}
public void markForUpdate() {
this.getHost().markForUpdate();
}
@Override
public boolean isConnected( final Direction side )
{
return this.getConnections().contains( AEPartLocation.fromFacing( side ) );
}
@Override
public void getBoxes(final IPartCollisionHelper bch) {
bch.addBox(6.0, 6.0, 6.0, 10.0, 10.0, 10.0);
public void markForUpdate()
{
this.getHost().markForUpdate();
}
if (Platform.isServer()) {
final IGridNode n = this.getGridNode();
if (n != null) {
this.setConnections(n.getConnectedSides());
} else {
this.getConnections().clear();
}
}
@Override
public void getBoxes( final IPartCollisionHelper bch )
{
bch.addBox( 6.0, 6.0, 6.0, 10.0, 10.0, 10.0 );
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( Platform.isServer() )
{
final IGridNode n = this.getGridNode();
if( n != null )
{
this.setConnections( n.getConnectedSides() );
}
else
{
this.getConnections().clear();
}
}
if (dist > 8) {
continue;
}
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() );
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:
}
}
}
}
if( dist > 8 )
{
continue;
}
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:
}
}
}
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:
}
}
}
}
@Override
public void writeToNBT(final CompoundNBT data) {
super.writeToNBT(data);
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:
}
}
}
if (Platform.isServer()) {
final IGridNode node = this.getGridNode();
@Override
public void writeToNBT( final CompoundNBT data )
{
super.writeToNBT( data );
if (node != null) {
int howMany = 0;
for (final IGridConnection gc : node.getConnections()) {
howMany = Math.max(gc.getUsedChannels(), howMany);
}
if( Platform.isServer() )
{
final IGridNode node = this.getGridNode();
data.putByte("usedChannels", (byte) howMany);
}
}
}
if( node != null )
{
int howMany = 0;
for( final IGridConnection gc : node.getConnections() )
{
howMany = Math.max( gc.getUsedChannels(), howMany );
}
@Override
public void writeToStream(final PacketBuffer data) throws IOException {
int flags = 0;
boolean[] writeSide = new boolean[Direction.values().length];
int[] channelsPerSide = new int[Direction.values().length];
data.putByte( "usedChannels", (byte) howMany );
}
}
}
for (Direction thisSide : Direction.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;
}
}
@Override
public void writeToStream( final PacketBuffer data ) throws IOException
{
int flags = 0;
boolean[] writeSide = new boolean[Direction.values().length];
int[] channelsPerSide = new int[Direction.values().length];
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());
}
}
}
for( Direction thisSide : Direction.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;
}
}
try {
if (this.getProxy().getEnergy().isNetworkPowered()) {
flags |= (1 << AEPartLocation.INTERNAL.ordinal());
}
} catch (final GridAccessException e) {
// aww...
}
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() );
}
}
}
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]);
}
}
}
try
{
if( this.getProxy().getEnergy().isNetworkPowered() )
{
flags |= ( 1 << AEPartLocation.INTERNAL.ordinal() );
}
}
catch( final GridAccessException e )
{
// aww...
}
@Override
public boolean readFromStream(final PacketBuffer 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;
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] );
}
}
}
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);
}
@Override
public boolean readFromStream( final PacketBuffer 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;
int ch = 0;
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 );
}
// 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;
}
int ch = 0;
if (ch != this.getChannelsOnSide(d.ordinal())) {
channelsChanged = true;
this.setChannelsOnSide(d.ordinal(), ch);
}
}
}
// 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;
}
return !myC.equals(this.getConnections()) || wasPowered != this.powered || channelsChanged;
}
if( ch != this.getChannelsOnSide( d.ordinal() ) )
{
channelsChanged = true;
this.setChannelsOnSide( d.ordinal(), ch );
}
}
}
int getChannelsOnSide(final int i) {
return this.channelsOnSide[i];
}
return !myC.equals( this.getConnections() ) || wasPowered != this.powered || channelsChanged;
}
public int getChannelsOnSide(Direction side) {
if (!this.powered) {
return 0;
}
return this.channelsOnSide[side.ordinal()];
}
int getChannelsOnSide( final int i )
{
return this.channelsOnSide[i];
}
void setChannelsOnSide(final int i, final int channels) {
this.channelsOnSide[i] = channels;
}
public int getChannelsOnSide( Direction side )
{
if( !this.powered )
{
return 0;
}
return this.channelsOnSide[side.ordinal()];
}
EnumSet<AEPartLocation> getConnections() {
return this.connections;
}
void setChannelsOnSide( final int i, final int channels )
{
this.channelsOnSide[i] = channels;
}
EnumSet<AEPartLocation> getConnections()
{
return this.connections;
}
void setConnections( final EnumSet<AEPartLocation> connections )
{
this.connections = connections;
}
void setConnections(final EnumSet<AEPartLocation> connections) {
this.connections = connections;
}
}
@@ -18,7 +18,6 @@
package appeng.parts.networking;
import net.minecraft.item.ItemStack;
import appeng.api.networking.IGridNode;
@@ -31,75 +30,62 @@ import appeng.api.util.AEPartLocation;
import appeng.helpers.Reflected;
import appeng.util.Platform;
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:
}
}
}
}
@@ -18,17 +18,13 @@
package appeng.parts.networking;
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);
}
}
@@ -18,7 +18,6 @@
package appeng.parts.networking;
import net.minecraft.item.ItemStack;
import appeng.api.networking.IGridNode;
@@ -31,75 +30,62 @@ import appeng.api.util.AEPartLocation;
import appeng.helpers.Reflected;
import appeng.util.Platform;
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:
}
}
}
}
@@ -18,7 +18,6 @@
package appeng.parts.networking;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@@ -35,122 +34,103 @@ import appeng.api.util.AEPartLocation;
import appeng.helpers.Reflected;
import appeng.util.Platform;
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();
}
}
@@ -18,24 +18,19 @@
package appeng.parts.networking;
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;
}
}
@@ -18,23 +18,18 @@
package appeng.parts.networking;
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;
}
}
@@ -18,7 +18,6 @@
package appeng.parts.networking;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
@@ -47,153 +46,129 @@ import appeng.me.helpers.AENetworkProxy;
import appeng.parts.AEBasePart;
import appeng.parts.PartModel;
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 CompoundNBT extra) {
super.readFromNBT(extra);
this.outerProxy.readFromNBT(extra);
}
@Override
public void readFromNBT( final CompoundNBT extra )
{
super.readFromNBT( extra );
this.outerProxy.readFromNBT( extra );
}
@Override
public void writeToNBT(final CompoundNBT extra) {
super.writeToNBT(extra);
this.outerProxy.writeToNBT(extra);
}
@Override
public void writeToNBT( final CompoundNBT extra )
{
super.writeToNBT( extra );
this.outerProxy.writeToNBT( extra );
}
@Override
public void removeFromWorld() {
super.removeFromWorld();
this.outerProxy.remove();
}
@Override
public void removeFromWorld()
{
super.removeFromWorld();
this.outerProxy.remove();
}
@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 PlayerEntity player, final Hand hand, final ItemStack held,
final AEPartLocation side) {
super.onPlacement(player, hand, held, side);
this.outerProxy.setOwner(player);
}
@Override
public void onPlacement( final PlayerEntity player, final Hand 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;
}
}