Search in sources :

Example 1 with WorldCoordinate

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());
}
Also used : WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) TrackScanner(mods.railcraft.api.tracks.TrackScanner)

Example 2 with WorldCoordinate

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;
}
Also used : WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) TrackScanner(mods.railcraft.api.tracks.TrackScanner) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Example 3 with WorldCoordinate

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);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with WorldCoordinate

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));
}
Also used : WorldCoordinate(mods.railcraft.api.core.WorldCoordinate)

Example 5 with WorldCoordinate

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);
}
Also used : WorldCoordinate(mods.railcraft.api.core.WorldCoordinate)

Aggregations

WorldCoordinate (mods.railcraft.api.core.WorldCoordinate)23 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)8 NBTTagList (net.minecraft.nbt.NBTTagList)6 TrackScanner (mods.railcraft.api.tracks.TrackScanner)4 TileEntity (net.minecraft.tileentity.TileEntity)4 Map (java.util.Map)3 EnumSet (java.util.EnumSet)2 HashSet (java.util.HashSet)2 IToolCrowbar (mods.railcraft.api.core.items.IToolCrowbar)2 HashMap (java.util.HashMap)1 Nullable (javax.annotation.Nullable)1 ConnectType (mods.railcraft.api.charge.IElectricGrid.ChargeHandler.ConnectType)1 ConnectType (mods.railcraft.api.electricity.IElectricGrid.ChargeHandler.ConnectType)1 IControllerTile (mods.railcraft.api.signals.IControllerTile)1 IReceiverTile (mods.railcraft.api.signals.IReceiverTile)1 ISignalBlockTile (mods.railcraft.api.signals.ISignalBlockTile)1 SignalBlock (mods.railcraft.api.signals.SignalBlock)1 SignalController (mods.railcraft.api.signals.SignalController)1 SignalReceiver (mods.railcraft.api.signals.SignalReceiver)1 Block (net.minecraft.block.Block)1