mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +01:00
For some reason, with this done, random disconnections don't occur anymore!?
This commit is contained in:
parent
ff70e6d53d
commit
9ad6dfcd0f
4 changed files with 20 additions and 18 deletions
|
@ -65,7 +65,7 @@ public class LaserRelayConnectionHandler{
|
||||||
WorldData.getDataForWorld(world).laserRelayNetworks.remove(network);
|
WorldData.getDataForWorld(world).laserRelayNetworks.remove(network);
|
||||||
for(ConnectionPair pair : network.connections){
|
for(ConnectionPair pair : network.connections){
|
||||||
if(!pair.contains(relay)){
|
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!");
|
//System.out.println("Removing a Relay from the Network!");
|
||||||
|
@ -142,12 +142,11 @@ public class LaserRelayConnectionHandler{
|
||||||
|
|
||||||
public static class ConnectionPair{
|
public static class ConnectionPair{
|
||||||
|
|
||||||
public final BlockPos firstRelay;
|
public final BlockPos[] positions = new BlockPos[2];
|
||||||
public final BlockPos secondRelay;
|
|
||||||
|
|
||||||
public ConnectionPair(BlockPos firstRelay, BlockPos secondRelay){
|
public ConnectionPair(BlockPos firstRelay, BlockPos secondRelay){
|
||||||
this.firstRelay = firstRelay;
|
this.positions[0] = firstRelay;
|
||||||
this.secondRelay = secondRelay;
|
this.positions[1] = secondRelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConnectionPair readFromNBT(NBTTagCompound compound){
|
public static ConnectionPair readFromNBT(NBTTagCompound compound){
|
||||||
|
@ -165,18 +164,23 @@ public class LaserRelayConnectionHandler{
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(BlockPos relay){
|
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
|
@Override
|
||||||
public String toString(){
|
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(){
|
public NBTTagCompound writeToNBT(){
|
||||||
NBTTagCompound compound = new NBTTagCompound();
|
NBTTagCompound compound = new NBTTagCompound();
|
||||||
for(int i = 0; i < 2; i++){
|
for(int i = 0; i < this.positions.length; i++){
|
||||||
BlockPos relay = i == 0 ? this.firstRelay : this.secondRelay;
|
BlockPos relay = this.positions[i];
|
||||||
compound.setInteger("x"+i, relay.getX());
|
compound.setInteger("x"+i, relay.getX());
|
||||||
compound.setInteger("y"+i, relay.getY());
|
compound.setInteger("y"+i, relay.getY());
|
||||||
compound.setInteger("z"+i, relay.getZ());
|
compound.setInteger("z"+i, relay.getZ());
|
||||||
|
@ -188,8 +192,8 @@ public class LaserRelayConnectionHandler{
|
||||||
public boolean equals(Object obj){
|
public boolean equals(Object obj){
|
||||||
if(obj instanceof ConnectionPair){
|
if(obj instanceof ConnectionPair){
|
||||||
ConnectionPair pair = (ConnectionPair)obj;
|
ConnectionPair pair = (ConnectionPair)obj;
|
||||||
if(this.firstRelay == pair.firstRelay || (this.firstRelay != null && this.firstRelay.equals(pair.firstRelay))){
|
for(int i = 0; i < this.positions.length; i++){
|
||||||
if(this.secondRelay == pair.secondRelay && (this.secondRelay != null && this.secondRelay.equals(pair.secondRelay))){
|
if(this.positions[i] == pair.positions[i] || (this.positions[i] != null && this.positions[i].equals(pair.positions[i]))){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
||||||
if(!list.hasNoTags()){
|
if(!list.hasNoTags()){
|
||||||
for(int i = 0; i < list.tagCount(); i++){
|
for(int i = 0; i < list.tagCount(); i++){
|
||||||
LaserRelayConnectionHandler.ConnectionPair pair = LaserRelayConnectionHandler.ConnectionPair.readFromNBT(list.getCompoundTagAt(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);
|
LaserRelayConnectionHandler.Network network = LaserRelayConnectionHandler.getNetworkFor(thisPos, this.worldObj);
|
||||||
if(network != null){
|
if(network != null){
|
||||||
for(LaserRelayConnectionHandler.ConnectionPair aPair : network.connections){
|
for(LaserRelayConnectionHandler.ConnectionPair aPair : network.connections){
|
||||||
if(aPair.contains(thisPos) && PosUtil.areSamePos(thisPos, aPair.firstRelay)){
|
if(aPair.contains(thisPos) && PosUtil.areSamePos(thisPos, aPair.positions[0])){
|
||||||
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);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,9 +64,8 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
|
||||||
List<BlockPos> alreadyChecked = new ArrayList<BlockPos>();
|
List<BlockPos> alreadyChecked = new ArrayList<BlockPos>();
|
||||||
//Go through all of the connections in the network
|
//Go through all of the connections in the network
|
||||||
for(LaserRelayConnectionHandler.ConnectionPair pair : network.connections){
|
for(LaserRelayConnectionHandler.ConnectionPair pair : network.connections){
|
||||||
BlockPos[] relays = new BlockPos[]{pair.firstRelay, pair.secondRelay};
|
|
||||||
//Go through both relays in the connection
|
//Go through both relays in the connection
|
||||||
for(BlockPos relay : relays){
|
for(BlockPos relay : pair.positions){
|
||||||
if(relay != null && !alreadyChecked.contains(relay)){
|
if(relay != null && !alreadyChecked.contains(relay)){
|
||||||
alreadyChecked.add(relay);
|
alreadyChecked.add(relay);
|
||||||
//Get every side of the relay
|
//Get every side of the relay
|
||||||
|
|
|
@ -55,8 +55,7 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay{
|
||||||
public List<TileEntityItemViewer.GenericItemHandlerInfo> getItemHandlersInNetwork(LaserRelayConnectionHandler.Network network){
|
public List<TileEntityItemViewer.GenericItemHandlerInfo> getItemHandlersInNetwork(LaserRelayConnectionHandler.Network network){
|
||||||
List<TileEntityItemViewer.GenericItemHandlerInfo> handlers = new ArrayList<TileEntityItemViewer.GenericItemHandlerInfo>();
|
List<TileEntityItemViewer.GenericItemHandlerInfo> handlers = new ArrayList<TileEntityItemViewer.GenericItemHandlerInfo>();
|
||||||
for(LaserRelayConnectionHandler.ConnectionPair pair : network.connections){
|
for(LaserRelayConnectionHandler.ConnectionPair pair : network.connections){
|
||||||
BlockPos[] relays = new BlockPos[]{pair.firstRelay, pair.secondRelay};
|
for(BlockPos relay : pair.positions){
|
||||||
for(BlockPos relay : relays){
|
|
||||||
if(relay != null){
|
if(relay != null){
|
||||||
TileEntity aRelayTile = this.worldObj.getTileEntity(relay);
|
TileEntity aRelayTile = this.worldObj.getTileEntity(relay);
|
||||||
if(aRelayTile instanceof de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItem){
|
if(aRelayTile instanceof de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItem){
|
||||||
|
|
Loading…
Reference in a new issue