Search in sources :

Example 11 with WorldCoordinate

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

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<WorldCoordinate, EnumSet<ConnectType>> position : gridObject.getChargeHandler().getPossibleConnectionLocations().entrySet()) {
        IElectricGrid otherObj = getGridObjectAt(gridObject.getTile().getWorldObj(), position.getKey());
        if (otherObj != null && position.getValue().contains(otherObj.getChargeHandler().getType())) {
            EnumSet<ConnectType> otherType = otherObj.getChargeHandler().getPossibleConnectionLocations().get(myPos);
            if (otherType != null && otherType.contains(gridObject.getChargeHandler().getType()))
                connectedObjects.add(otherObj);
        }
    }
    return connectedObjects;
}
Also used : WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) EnumSet(java.util.EnumSet) Map(java.util.Map) HashSet(java.util.HashSet) ConnectType(mods.railcraft.api.electricity.IElectricGrid.ChargeHandler.ConnectType)

Example 12 with WorldCoordinate

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

the class AbstractPair method validatePairings.

protected void validatePairings() {
    if (!pairingsToTestNext.isEmpty()) {
        pairingsToTestNext.retainAll(pairings);
        for (WorldCoordinate coord : pairingsToTestNext) {
            int x = coord.x;
            int y = coord.y;
            int z = coord.z;
            World world = tile.getWorldObj();
            if (!world.blockExists(x, y, z))
                continue;
            Block block = world.getBlock(x, y, z);
            int meta = world.getBlockMetadata(x, y, z);
            if (!block.hasTileEntity(meta)) {
                clearPairing(coord);
                continue;
            }
            TileEntity target = world.getTileEntity(x, y, z);
            if (target != null && !isValidPair(coord, target))
                clearPairing(coord);
        }
        pairingsToTestNext.clear();
    }
    cleanPairings();
    for (WorldCoordinate coord : pairings) {
        getPairAt(coord);
    }
    pairingsToTestNext.addAll(pairingsToTest);
    pairingsToTest.clear();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) Block(net.minecraft.block.Block) World(net.minecraft.world.World)

Example 13 with WorldCoordinate

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

the class SignalBlock method createSignalBlock.

//    @Override
//    public void startPairing() {
//        clearSignalBlockPairing("Signal Block pairing cleared in preparation to start a new pairing.  [{0}, {1}, {2}]", tile.xCoord, tile.yCoord, tile.zCoord);
//        super.startPairing();
//    }
public boolean createSignalBlock(SignalBlock other) {
    if (other == this) {
        printDebugPair("Signal Block creation was aborted, cannot pair with self.", other.tile);
        return false;
    }
    printDebugPair("Signal Block creation being attempted.", other.tile);
    Status myTrackStatus = getTrackStatus();
    Status otherTrackStatus = other.getTrackStatus();
    if (myTrackStatus == Status.INVALID || otherTrackStatus == Status.INVALID) {
        printDebugPair("Signal Block creation failed, could not find Track.", other.tile);
        return false;
    }
    WorldCoordinate myTrack = getTrackLocation();
    WorldCoordinate otherTrack = other.getTrackLocation();
    TrackScanner.ScanResult scan = TrackScanner.scanStraightTrackSection(tile.getWorldObj(), myTrack.x, myTrack.y, myTrack.z, otherTrack.x, otherTrack.y, otherTrack.z);
    if (!scan.areConnected) {
        printDebugPair("Signal Block creation failed, could not find Path.", other.tile);
        return false;
    }
    addPairing(other.getCoords());
    other.addPairing(getCoords());
    endPairing();
    other.endPairing();
    trackScans.put(otherTrack, scan);
    printDebugPair("Signal Block created successfully.", other.tile);
    return true;
}
Also used : WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) TrackScanner(mods.railcraft.api.tracks.TrackScanner)

Example 14 with WorldCoordinate

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

the class SignalBlockRelay method saveNBT.

@Override
protected void saveNBT(NBTTagCompound data) {
    super.saveNBT(data);
    NBTTagList tagList = data.getTagList("aspects", 10);
    for (int i = 0; i < tagList.tagCount(); i++) {
        NBTTagCompound nbt = tagList.getCompoundTagAt(i);
        WorldCoordinate coord = WorldCoordinate.readFromNBT(nbt, "coord");
        SignalAspect aspect = SignalAspect.readFromNBT(nbt, "aspect");
        aspects.put(coord, aspect);
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) WorldCoordinate(mods.railcraft.api.core.WorldCoordinate) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 15 with WorldCoordinate

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

the class DualSignalReceiver method onControllerAspectChange.

@Override
public void onControllerAspectChange(SignalController con, @Nonnull SignalAspect aspect) {
    WorldCoordinate coord = pairings.peekFirst();
    if (coord == null) {
        return;
    }
    if (coord.equals(con.getCoords())) {
        if (aspect != topAspect) {
            topAspect = aspect;
            super.onControllerAspectChange(con, aspect);
        }
    } else {
        if (aspect != bottomAspect) {
            bottomAspect = aspect;
            super.onControllerAspectChange(con, aspect);
        }
    }
}
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