Search in sources :

Example 1 with TileEntityRailSniffer

use of club.nsdn.nyasamarailway.tileblock.signal.TileEntityRailSniffer in project NyaSamaRailway by NSDN.

the class RailMonoMagnetSniffer method setRailOutput.

@Override
public void setRailOutput(World world, int x, int y, int z, int meta) {
    RailSniffer sniffer = null;
    if (world.getTileEntity(x, y, z) instanceof RailSniffer)
        sniffer = (RailSniffer) world.getTileEntity(x, y, z);
    if (sniffer != null) {
        if (railHasCart(world, x, y, z) && sniffer.nsasmState == RailSniffer.NSASM_IDLE) {
            sniffer.nsasmState = RailSniffer.NSASM_DONE;
            EntityMinecart cart = getCart(world, x, y, z);
            EntityPlayer player;
            if (!(cart.riddenByEntity instanceof EntityPlayer))
                player = null;
            else
                player = (EntityPlayer) cart.riddenByEntity;
            RailSniffer rail = sniffer;
            new RailSnifferCore(rail.nsasmCode) {

                @Override
                public World getWorld() {
                    return world;
                }

                @Override
                public double getX() {
                    return x;
                }

                @Override
                public double getY() {
                    return y;
                }

                @Override
                public double getZ() {
                    return z;
                }

                @Override
                public EntityPlayer getPlayer() {
                    return player;
                }

                @Override
                public TileEntityRailSniffer getRail() {
                    return rail;
                }

                @Override
                public EntityMinecart getCart() {
                    return cart;
                }
            }.run();
        }
        if (!railHasCart(world, x, y, z) && sniffer.nsasmState == RailSniffer.NSASM_DONE) {
            sniffer.nsasmState = RailSniffer.NSASM_IDLE;
            sniffer.enable = false;
        }
        if (railHasCart(world, x, y, z) && !railHasPowered(world, x, y, z) && !sniffer.enable) {
            setOutputSignal(sniffer, true);
            if (sniffer.getTransceiver() != null)
                setOutputSignal(sniffer.getTransceiver(), true);
        }
        if (!railHasCart(world, x, y, z) && railHasPowered(world, x, y, z)) {
            setOutputSignal(sniffer, false);
            if (sniffer.getTransceiver() != null)
                setOutputSignal(sniffer.getTransceiver(), false);
        }
        if (railHasCart(world, x, y, z)) {
            world.scheduleBlockUpdate(x, y, z, this, sniffer.keep);
        }
    }
}
Also used : TileEntityRailSniffer(club.nsdn.nyasamarailway.tileblock.signal.TileEntityRailSniffer) RailSnifferCore(club.nsdn.nyasamarailway.util.RailSnifferCore) EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(net.minecraft.world.World) EntityMinecart(net.minecraft.entity.item.EntityMinecart) TileEntityRailSniffer(club.nsdn.nyasamarailway.tileblock.signal.TileEntityRailSniffer)

Example 2 with TileEntityRailSniffer

use of club.nsdn.nyasamarailway.tileblock.signal.TileEntityRailSniffer in project NyaSamaRailway by NSDN.

the class BlockRailSniffer method setRailOutput.

@Override
public void setRailOutput(World world, int x, int y, int z, int meta) {
    RailSniffer sniffer = null;
    if (world.getTileEntity(x, y, z) instanceof RailSniffer)
        sniffer = (RailSniffer) world.getTileEntity(x, y, z);
    if (sniffer != null) {
        if (railHasCart(world, x, y, z) && sniffer.nsasmState == RailSniffer.NSASM_IDLE) {
            sniffer.nsasmState = RailSniffer.NSASM_DONE;
            EntityMinecart cart = getCart(world, x, y, z);
            EntityPlayer player;
            if (!(cart.riddenByEntity instanceof EntityPlayer))
                player = null;
            else
                player = (EntityPlayer) cart.riddenByEntity;
            RailSniffer rail = sniffer;
            new RailSnifferCore(rail.nsasmCode) {

                @Override
                public World getWorld() {
                    return world;
                }

                @Override
                public double getX() {
                    return x;
                }

                @Override
                public double getY() {
                    return y;
                }

                @Override
                public double getZ() {
                    return z;
                }

                @Override
                public EntityPlayer getPlayer() {
                    return player;
                }

                @Override
                public TileEntityRailSniffer getRail() {
                    return rail;
                }

                @Override
                public EntityMinecart getCart() {
                    return cart;
                }
            }.run();
        }
        if (!railHasCart(world, x, y, z) && sniffer.nsasmState == RailSniffer.NSASM_DONE) {
            sniffer.nsasmState = RailSniffer.NSASM_IDLE;
            sniffer.enable = false;
        }
        if (railHasCart(world, x, y, z) && !railHasPowered(world, x, y, z) && !sniffer.enable) {
            setOutputSignal(sniffer, true);
            if (sniffer.getTransceiver() != null)
                setOutputSignal(sniffer.getTransceiver(), true);
        }
        if (!railHasCart(world, x, y, z) && railHasPowered(world, x, y, z)) {
            setOutputSignal(sniffer, false);
            if (sniffer.getTransceiver() != null)
                setOutputSignal(sniffer.getTransceiver(), false);
        }
        if (railHasCart(world, x, y, z)) {
            world.scheduleBlockUpdate(x, y, z, this, sniffer.keep);
        }
    }
}
Also used : TileEntityRailSniffer(club.nsdn.nyasamarailway.tileblock.signal.TileEntityRailSniffer) RailSnifferCore(club.nsdn.nyasamarailway.util.RailSnifferCore) EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(net.minecraft.world.World) EntityMinecart(net.minecraft.entity.item.EntityMinecart) TileEntityRailSniffer(club.nsdn.nyasamarailway.tileblock.signal.TileEntityRailSniffer)

Aggregations

TileEntityRailSniffer (club.nsdn.nyasamarailway.tileblock.signal.TileEntityRailSniffer)2 RailSnifferCore (club.nsdn.nyasamarailway.util.RailSnifferCore)2 EntityMinecart (net.minecraft.entity.item.EntityMinecart)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 World (net.minecraft.world.World)2