use of mods.railcraft.api.core.WorldCoordinate in project Trains-In-Motion-1.7.10 by EternalBlueFlame.
the class SignalBlock method isSignalBlockValid.
private TrackValidationStatus isSignalBlockValid(WorldCoordinate other) {
if (other == null)
return new TrackValidationStatus(true, "UNVERIFIABLE_COORD_NULL");
SignalBlock otherSignalBlock = getSignalAt(other);
if (otherSignalBlock == null)
return new TrackValidationStatus(true, "UNVERIFIABLE_OTHER_SIGNAL_NULL");
Status trackStatus = getTrackStatus();
if (trackStatus == Status.INVALID)
return new TrackValidationStatus(false, "INVALID_MY_TRACK_NULL");
Status otherTrackStatus = otherSignalBlock.getTrackStatus();
if (otherTrackStatus == Status.INVALID)
return new TrackValidationStatus(false, "INVALID_OTHER_TRACK_INVALID");
WorldCoordinate otherTrack = trackCache.get(other);
if (otherTrackStatus == Status.UNKNOWN) {
if (otherTrack == null)
return new TrackValidationStatus(true, "UNVERIFIABLE_OTHER_TRACK_UNKNOWN");
} else {
otherTrack = otherSignalBlock.getTrackLocation();
if (otherTrack != null)
trackCache.put(other, otherTrack);
}
if (otherTrack == null)
return new TrackValidationStatus(true, "UNVERIFIABLE_OTHER_TRACK_NULL");
WorldCoordinate myTrack = getTrackLocation();
TrackScanner.ScanResult scan = TrackScanner.scanStraightTrackSection(tile.getWorldObj(), myTrack.x, myTrack.y, myTrack.z, otherTrack.x, otherTrack.y, otherTrack.z);
trackScans.put(otherTrack, scan);
if (scan.verdict == TrackScanner.ScanResult.Verdict.VALID)
return new TrackValidationStatus(true, "VALID");
if (scan.verdict == TrackScanner.ScanResult.Verdict.UNKNOWN)
return new TrackValidationStatus(true, "UNVERIFIABLE_UNLOADED_CHUNK");
return new TrackValidationStatus(false, "INVALID_SCAN_FAIL: " + scan.verdict.name());
}
use of mods.railcraft.api.core.WorldCoordinate in project Trains-In-Motion-1.7.10 by EternalBlueFlame.
the class SignalBlock method determineMyAspect.
private SignalAspect determineMyAspect(WorldCoordinate otherCoord) {
WorldCoordinate myTrack = getTrackLocation();
if (myTrack == null)
return SignalAspect.RED;
WorldCoordinate otherTrack = getOtherTrackLocation(otherCoord);
if (otherTrack == null)
return SignalAspect.YELLOW;
TrackScanner.ScanResult scan = getOrCreateTrackScan(otherTrack);
int y1 = scan.minY;
int y2 = scan.maxY + 1;
int x1 = Math.min(myTrack.x, otherTrack.x);
int z1 = Math.min(myTrack.z, otherTrack.z);
int x2 = Math.max(myTrack.x, otherTrack.x) + 1;
int z2 = Math.max(myTrack.z, otherTrack.z) + 1;
boolean zAxis = Math.abs(myTrack.x - otherTrack.x) < Math.abs(myTrack.z - otherTrack.z);
int xOffset = otherTrack.x > myTrack.x ? -3 : 3;
int zOffset = otherTrack.z > myTrack.z ? -3 : 3;
List<EntityMinecart> carts = CartTools.getMinecartsIn(tile.getWorldObj(), x1, y1, z1, x2, y2, z2);
// System.out.printf("%d, %d, %d, %d, %d, %d\n", i1, j1, k1, i2, j2, k2);
// System.out.println("carts = " + carts.size());
SignalAspect newAspect = SignalAspect.GREEN;
for (EntityMinecart cart : carts) {
int cartX = MathHelper.floor_double(cart.posX);
int cartZ = MathHelper.floor_double(cart.posZ);
if (Math.abs(cart.motionX) < 0.08 && Math.abs(cart.motionZ) < 0.08)
return SignalAspect.RED;
else if (zAxis)
if (cartZ > myTrack.z + zOffset && cart.motionZ < 0)
return SignalAspect.RED;
else if (cartZ < myTrack.z + zOffset && cart.motionZ > 0)
return SignalAspect.RED;
else
newAspect = SignalAspect.YELLOW;
else if (cartX > myTrack.x + xOffset && cart.motionX < 0)
return SignalAspect.RED;
else if (cartX < myTrack.x + xOffset && cart.motionX > 0)
return SignalAspect.RED;
else
newAspect = SignalAspect.YELLOW;
}
return newAspect;
}
use of mods.railcraft.api.core.WorldCoordinate in project Trains-In-Motion-1.7.10 by EternalBlueFlame.
the class SignalBlockRelay method loadNBT.
@Override
protected void loadNBT(NBTTagCompound data) {
super.loadNBT(data);
NBTTagList tagList = new NBTTagList();
for (Map.Entry<WorldCoordinate, SignalAspect> entry : aspects.entrySet()) {
NBTTagCompound nbt = new NBTTagCompound();
if (entry.getKey() != null && entry.getValue() != null) {
entry.getKey().writeToNBT(nbt, "coord");
entry.getValue().writeToNBT(nbt, "aspect");
tagList.appendTag(nbt);
}
}
data.setTag("aspects", tagList);
}
use of mods.railcraft.api.core.WorldCoordinate in project Trains-In-Motion-1.7.10 by EternalBlueFlame.
the class SignalController method registerReceiver.
public void registerReceiver(SignalReceiver receiver) {
WorldCoordinate coords = receiver.getCoords();
addPairing(coords);
receiver.registerController(this);
receiver.onControllerAspectChange(this, getAspectFor(coords));
}
use of mods.railcraft.api.core.WorldCoordinate in project Trains-In-Motion-1.7.10 by EternalBlueFlame.
the class SignalBlock method addPairing.
@Override
protected void addPairing(WorldCoordinate other) {
pairings.remove(other);
pairings.add(other);
while (pairings.size() > getMaxPairings()) {
WorldCoordinate pair = pairings.remove();
printDebugPair("Signal Block dropped because too many pairs.", pair);
}
SignalTools.packetBuilder.sendPairPacketUpdate(this);
}
Aggregations