Search in sources :

Example 6 with WorldCoordinate

use of mods.railcraft.api.core.WorldCoordinate in project Trains-In-Motion-1.7.10 by EternalBlueFlame.

the class SignalBlock method tickServer.

@Override
public void tickServer() {
    super.tickServer();
    update++;
    try {
        if (!isLoaded())
            return;
    } catch (Throwable ex) {
    //            Game.logErrorAPI("Railcraft", ex, AbstractPair.class);
    }
    if (update % SignalTools.signalUpdateInterval == 0) {
        SignalAspect prev = getSignalAspect();
        if (prev != SignalAspect.BLINK_RED)
            changedAspect = true;
        updateSignalAspect();
        if (getSignalAspect() == SignalAspect.BLINK_RED && prev != SignalAspect.BLINK_RED)
            printDebug("Signal Block changed aspect to BLINK_RED: source:[{0}, {1}, {2}] pairs: {3}", tile.xCoord, tile.yCoord, tile.zCoord, pairings);
    }
    if (update % VALIDATION_CHECK_INTERVAL == 0) {
        Status trackStatus = getTrackStatus();
        switch(trackStatus) {
            case INVALID:
                clearSignalBlockPairing(null, "Signal Block dropped because no track was found near Signal. [{0}, {1}, {2}]", tile.xCoord, tile.yCoord, tile.zCoord);
                break;
            case VALID:
                for (WorldCoordinate otherCoord : waitingForRetest) {
                    TrackValidationStatus status = isSignalBlockValid(otherCoord);
                    if (!status.isValid)
                        clearSignalBlockPairing(otherCoord, "Signal Block dropped because track between Signals was invalid. source:[{0}, {1}, {2}] target:[{3}, {4}, {5}] reason:{6}", tile.xCoord, tile.yCoord, tile.zCoord, otherCoord.x, otherCoord.y, otherCoord.z, status.message);
                }
                waitingForRetest.clear();
                for (WorldCoordinate otherCoord : getPairs()) {
                    if (!isSignalBlockValid(otherCoord).isValid)
                        waitingForRetest.add(otherCoord);
                }
                break;
        }
    }
}
Also used : WorldCoordinate(mods.railcraft.api.core.WorldCoordinate)

Example 7 with WorldCoordinate

use of mods.railcraft.api.core.WorldCoordinate in project Trains-In-Motion-1.7.10 by EternalBlueFlame.

the class SignalBlock method getOrCreateTrackScan.

private TrackScanner.ScanResult getOrCreateTrackScan(WorldCoordinate otherTrack) {
    TrackScanner.ScanResult scan = trackScans.get(otherTrack);
    if (scan == null) {
        WorldCoordinate myTrack = getTrackLocation();
        scan = TrackScanner.scanStraightTrackSection(tile.getWorldObj(), myTrack.x, myTrack.y, myTrack.z, otherTrack.x, otherTrack.y, otherTrack.z);
        trackScans.put(otherTrack, scan);
    }
    return scan;
}
Also used : WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) TrackScanner(mods.railcraft.api.tracks.TrackScanner)

Example 8 with WorldCoordinate

use of mods.railcraft.api.core.WorldCoordinate in project Trains-In-Motion-1.7.10 by EternalBlueFlame.

the class AbstractPair method loadNBT.

protected void loadNBT(NBTTagCompound data) {
    NBTTagList list = data.getTagList("pairings", 10);
    for (byte entry = 0; entry < list.tagCount(); entry++) {
        NBTTagCompound tag = list.getCompoundTagAt(entry);
        int[] c = tag.getIntArray("coords");
        pairings.add(new WorldCoordinate(c[0], c[1], c[2], c[3]));
    }
    this.name = data.getString("name");
    if (this.name.isEmpty()) {
        this.name = null;
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 9 with WorldCoordinate

use of mods.railcraft.api.core.WorldCoordinate in project Trains-In-Motion-1.7.10 by EternalBlueFlame.

the class AbstractPair method saveNBT.

protected void saveNBT(NBTTagCompound data) {
    NBTTagList list = new NBTTagList();
    for (WorldCoordinate c : pairings) {
        NBTTagCompound tag = new NBTTagCompound();
        tag.setIntArray("coords", new int[] { c.dimension, c.x, c.y, c.z });
        list.appendTag(tag);
    }
    data.setTag("pairings", list);
    if (this.name != null) {
        data.setString("name", this.name);
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 10 with WorldCoordinate

use of mods.railcraft.api.core.WorldCoordinate in project Railcraft by Railcraft.

the class GridTools method getMutuallyConnectedObjects.

public static Set<IElectricGrid> getMutuallyConnectedObjects(IElectricGrid gridObject) {
    Set<IElectricGrid> connectedObjects = new HashSet<IElectricGrid>();
    WorldCoordinate myPos = new WorldCoordinate(gridObject.getTile());
    for (Map.Entry<BlockPos, EnumSet<ConnectType>> position : gridObject.getChargeHandler().getPossibleConnectionLocations().entrySet()) {
        Optional<IElectricGrid> otherObj = getGridObjectAt(gridObject.getTile().getWorld(), position.getKey());
        if (otherObj.isPresent() && position.getValue().contains(otherObj.get().getChargeHandler().getType())) {
            EnumSet<ConnectType> otherType = otherObj.get().getChargeHandler().getPossibleConnectionLocations().get(myPos);
            if (otherType != null && otherType.contains(gridObject.getChargeHandler().getType()))
                connectedObjects.add(otherObj.get());
        }
    }
    return connectedObjects;
}
Also used : WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) EnumSet(java.util.EnumSet) BlockPos(net.minecraft.util.math.BlockPos) Map(java.util.Map) HashSet(java.util.HashSet) ConnectType(mods.railcraft.api.charge.IElectricGrid.ChargeHandler.ConnectType)

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