For some reason, with this done, random disconnections don't occur anymore!?

This commit is contained in:
Ellpeck 2016-06-05 14:33:53 +02:00
parent ff70e6d53d
commit 9ad6dfcd0f
4 changed files with 20 additions and 18 deletions

View file

@ -65,7 +65,7 @@ public class LaserRelayConnectionHandler{
WorldData.getDataForWorld(world).laserRelayNetworks.remove(network);
for(ConnectionPair pair : network.connections){
if(!pair.contains(relay)){
addConnection(pair.firstRelay, pair.secondRelay, world);
addConnection(pair.positions[0], pair.positions[1], world);
}
}
//System.out.println("Removing a Relay from the Network!");
@ -142,12 +142,11 @@ public class LaserRelayConnectionHandler{
public static class ConnectionPair{
public final BlockPos firstRelay;
public final BlockPos secondRelay;
public final BlockPos[] positions = new BlockPos[2];
public ConnectionPair(BlockPos firstRelay, BlockPos secondRelay){
this.firstRelay = firstRelay;
this.secondRelay = secondRelay;
this.positions[0] = firstRelay;
this.positions[1] = secondRelay;
}
public static ConnectionPair readFromNBT(NBTTagCompound compound){
@ -165,18 +164,23 @@ public class LaserRelayConnectionHandler{
}
public boolean contains(BlockPos relay){
return (this.firstRelay != null && PosUtil.areSamePos(this.firstRelay, relay)) || (this.secondRelay != null && PosUtil.areSamePos(this.secondRelay, relay));
for(BlockPos position : this.positions){
if(position != null && PosUtil.areSamePos(position, relay)){
return true;
}
}
return false;
}
@Override
public String toString(){
return (this.firstRelay == null ? "-" : this.firstRelay.toString())+" | "+(this.secondRelay == null ? "-" : this.secondRelay.toString());
return (this.positions[0] == null ? "-" : this.positions[0].toString())+" | "+(this.positions[1] == null ? "-" : this.positions[1].toString());
}
public NBTTagCompound writeToNBT(){
NBTTagCompound compound = new NBTTagCompound();
for(int i = 0; i < 2; i++){
BlockPos relay = i == 0 ? this.firstRelay : this.secondRelay;
for(int i = 0; i < this.positions.length; i++){
BlockPos relay = this.positions[i];
compound.setInteger("x"+i, relay.getX());
compound.setInteger("y"+i, relay.getY());
compound.setInteger("z"+i, relay.getZ());
@ -188,8 +192,8 @@ public class LaserRelayConnectionHandler{
public boolean equals(Object obj){
if(obj instanceof ConnectionPair){
ConnectionPair pair = (ConnectionPair)obj;
if(this.firstRelay == pair.firstRelay || (this.firstRelay != null && this.firstRelay.equals(pair.firstRelay))){
if(this.secondRelay == pair.secondRelay && (this.secondRelay != null && this.secondRelay.equals(pair.secondRelay))){
for(int i = 0; i < this.positions.length; i++){
if(this.positions[i] == pair.positions[i] || (this.positions[i] != null && this.positions[i].equals(pair.positions[i]))){
return true;
}
}

View file

@ -43,7 +43,7 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
if(!list.hasNoTags()){
for(int i = 0; i < list.tagCount(); i++){
LaserRelayConnectionHandler.ConnectionPair pair = LaserRelayConnectionHandler.ConnectionPair.readFromNBT(list.getCompoundTagAt(i));
LaserRelayConnectionHandler.addConnection(pair.firstRelay, pair.secondRelay, this.worldObj);
LaserRelayConnectionHandler.addConnection(pair.positions[0], pair.positions[1], this.worldObj);
}
}
@ -82,8 +82,8 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getNetworkFor(thisPos, this.worldObj);
if(network != null){
for(LaserRelayConnectionHandler.ConnectionPair aPair : network.connections){
if(aPair.contains(thisPos) && PosUtil.areSamePos(thisPos, aPair.firstRelay)){
PacketParticle.renderParticlesFromAToB(aPair.firstRelay.getX(), aPair.firstRelay.getY(), aPair.firstRelay.getZ(), aPair.secondRelay.getX(), aPair.secondRelay.getY(), aPair.secondRelay.getZ(), ConfigBoolValues.LESS_PARTICLES.isEnabled() ? 1 : Util.RANDOM.nextInt(3)+1, 0.8F, this.isItem ? COLOR_ITEM : COLOR, 1F);
if(aPair.contains(thisPos) && PosUtil.areSamePos(thisPos, aPair.positions[0])){
PacketParticle.renderParticlesFromAToB(aPair.positions[0].getX(), aPair.positions[0].getY(), aPair.positions[0].getZ(), aPair.positions[1].getX(), aPair.positions[1].getY(), aPair.positions[1].getZ(), ConfigBoolValues.LESS_PARTICLES.isEnabled() ? 1 : Util.RANDOM.nextInt(3)+1, 0.8F, this.isItem ? COLOR_ITEM : COLOR, 1F);
}
}
}

View file

@ -64,9 +64,8 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
List<BlockPos> alreadyChecked = new ArrayList<BlockPos>();
//Go through all of the connections in the network
for(LaserRelayConnectionHandler.ConnectionPair pair : network.connections){
BlockPos[] relays = new BlockPos[]{pair.firstRelay, pair.secondRelay};
//Go through both relays in the connection
for(BlockPos relay : relays){
for(BlockPos relay : pair.positions){
if(relay != null && !alreadyChecked.contains(relay)){
alreadyChecked.add(relay);
//Get every side of the relay

View file

@ -55,8 +55,7 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
public List<TileEntityItemViewer.GenericItemHandlerInfo> getItemHandlersInNetwork(LaserRelayConnectionHandler.Network network){
List<TileEntityItemViewer.GenericItemHandlerInfo> handlers = new ArrayList<TileEntityItemViewer.GenericItemHandlerInfo>();
for(LaserRelayConnectionHandler.ConnectionPair pair : network.connections){
BlockPos[] relays = new BlockPos[]{pair.firstRelay, pair.secondRelay};
for(BlockPos relay : relays){
for(BlockPos relay : pair.positions){
if(relay != null){
TileEntity aRelayTile = this.worldObj.getTileEntity(relay);
if(aRelayTile instanceof de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItem){