Search in sources :

Example 1 with LocoBase

use of club.nsdn.nyasamarailway.entity.LocoBase in project NyaSamaRailway by NSDN.

the class TileEntityRailReception method tick.

public static void tick(boolean isAnti, List bBox, TileEntityRailReception rail, boolean playerDetectable) {
    if (rail == null)
        return;
    World world = rail.worldObj;
    int x = rail.xCoord, y = rail.yCoord, z = rail.zCoord;
    boolean hasCart = !bBox.isEmpty();
    if (!playerDetectable) {
        if (rail.getSender() != null && rail.getBlockType() instanceof IRailReception) {
            IRailReception blockRail = (IRailReception) rail.getBlockType();
            if (!isRailPowered(world, x, y, z) && rail.senderIsPowered()) {
                blockRail.setRailState(world, x, y, z, true);
            } else if (isRailPowered(world, x, y, z) && !rail.senderIsPowered()) {
                blockRail.setRailState(world, x, y, z, false);
            }
        }
    } else {
        if (rail.cartType.equals("loco")) {
            if (!hasCart) {
                rail.reset();
            } else {
                if (rail.getTarget() != null) {
                    rail.controlTarget(rail.doorCtrl);
                }
                for (Object obj : bBox) {
                    if (obj instanceof LocoBase) {
                        loco(isAnti, (LocoBase) obj, rail);
                        break;
                    }
                }
            }
        } else {
            if (hasCart) {
                if (rail.getTarget() != null) {
                    rail.controlTarget(rail.doorCtrl);
                }
                for (Object obj : bBox) {
                    if (obj instanceof EntityMinecart) {
                        if (((EntityMinecart) obj).riddenByEntity == null) {
                            EntityMinecart cart = (EntityMinecart) obj;
                            cart.motionX = 0.0D;
                            cart.motionZ = 0.0D;
                            cart.setPosition(x + 0.5, y + 0.5, z + 0.5);
                            rail.reset();
                            rail.prev = true;
                        } else if (rail.prev) {
                            rail.prev = false;
                        // rail.delay = DELAY_TIME * 15 - 1;
                        }
                        break;
                    }
                }
            } else {
                rail.count += 1;
                if (rail.count >= TileEntityRailReception.SPAWN_DELAY * 20) {
                    rail.reset();
                    rail.spawn(rail.worldObj, x, y, z);
                }
            }
        }
    }
}
Also used : IRailReception(club.nsdn.nyasamarailway.block.rail.IRailReception) LocoBase(club.nsdn.nyasamarailway.entity.LocoBase) World(net.minecraft.world.World) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Example 2 with LocoBase

use of club.nsdn.nyasamarailway.entity.LocoBase in project NyaSamaRailway by NSDN.

the class TileEntityTrackSideReception method core.

protected static void core(EntityMinecart cart, TileEntityTrackSideReception reception) {
    if (reception == null)
        return;
    boolean hasCart = (cart != null);
    ForgeDirection railPos = reception.direction.getRotation(ITrackSide.getAxis());
    int x = reception.xCoord + railPos.offsetX, y = reception.yCoord, z = reception.zCoord + railPos.offsetZ;
    if (reception.cartType.equals("loco")) {
        if (!hasCart) {
            reception.reset();
        } else {
            if (reception.getTarget() != null) {
                reception.controlTarget(reception.doorCtrl);
            }
            if (cart instanceof LocoBase)
                loco((LocoBase) cart, reception);
        }
    } else {
        if (!hasCart) {
            reception.count += 1;
            if (reception.count >= SPAWN_DELAY * 20) {
                reception.reset();
                reception.spawn();
            }
        } else {
            if (reception.getTarget() != null) {
                reception.controlTarget(reception.doorCtrl);
            }
            if (cart.riddenByEntity == null) {
                cart.motionX = 0.0D;
                cart.motionZ = 0.0D;
                cart.setPosition(x + 0.5, y + 0.5, z + 0.5);
                reception.reset();
                if (ITrackSide.hasMultiMinecart(reception, reception.direction)) {
                    LinkedList<EntityMinecart> carts = ITrackSide.getMinecarts(reception, reception.direction);
                    for (int i = 1; i < carts.size(); i++) carts.get(i).killMinecart(new DamageSource("nsr"));
                }
                reception.prev = true;
            } else if (reception.prev) {
                reception.prev = false;
            // reception.delay = DELAY_TIME * 15 - 1;
            }
            EntityPlayer player = null;
            if (cart.riddenByEntity instanceof EntityPlayer)
                player = (EntityPlayer) cart.riddenByEntity;
            cart(cart, reception, player);
        }
        tri(cart, reception);
    }
}
Also used : DamageSource(net.minecraft.util.DamageSource) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) LocoBase(club.nsdn.nyasamarailway.entity.LocoBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Example 3 with LocoBase

use of club.nsdn.nyasamarailway.entity.LocoBase in project NyaSamaRailway by NSDN.

the class ItemNTP8Bit method onUpdate.

@Override
public void onUpdate(ItemStack itemStack, World world, Entity entity, int index, boolean inHand) {
    if (!world.isRemote && inHand) {
        if (entity instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) entity;
            TrainPacket packet = new TrainPacket();
            packet.P = this.power.get(itemStack);
            packet.R = this.brake.get(itemStack);
            packet.Dir = this.dir.get(itemStack);
            packet.Mode = this.mode.get(itemStack);
            packet.dimensionID = player.dimension;
            EntityMinecart cart = packet.getCartInServer(this.cart.get(itemStack));
            if (cart != null) {
                if (cart instanceof IHighSpeedCart) {
                    ((IHighSpeedCart) cart).setHighSpeedMode(packet.Mode);
                }
                if (cart instanceof LocoBase) {
                    ((LocoBase) cart).setTrainPacket(packet);
                    return;
                }
                if (Traincraft.getInstance() != null) {
                    if (Traincraft.instance.isLocomotive(cart)) {
                        Traincraft.instance.Locomotive_setIsLocoTurnedOn(cart, true);
                    }
                }
                packet.Velocity = Dynamics.vel(cart.motionX, cart.motionZ);
                TrainController.doMotion(packet, cart);
            }
        }
    }
}
Also used : LocoBase(club.nsdn.nyasamarailway.entity.LocoBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityMinecart(net.minecraft.entity.item.EntityMinecart) IHighSpeedCart(club.nsdn.nyasamarailway.entity.IHighSpeedCart) TrainPacket(club.nsdn.nyasamarailway.network.TrainPacket)

Example 4 with LocoBase

use of club.nsdn.nyasamarailway.entity.LocoBase in project NyaSamaRailway by NSDN.

the class NSPCT8C method doSpawn.

public static void doSpawn(World world, int x, int y, int z, String name) {
    LocoBase head = new NSPCT8C(world, (double) x + 0.5, (double) y + 0.5, (double) z + 0.5);
    if (!name.isEmpty())
        head.setMinecartName(name);
    world.spawnEntityInWorld(head);
    MinecartBase container = new NSPCT8C.Container(world, (double) x + 0.5, (double) y + 0.5 - 3.0, (double) z + 0.5);
    world.spawnEntityInWorld(container);
    container.mountEntity(head);
}
Also used : MinecartBase(club.nsdn.nyasamarailway.entity.MinecartBase) LocoBase(club.nsdn.nyasamarailway.entity.LocoBase)

Example 5 with LocoBase

use of club.nsdn.nyasamarailway.entity.LocoBase in project NyaSamaRailway by NSDN.

the class ItemNSPCT7 method onItemUse.

@Override
public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float px, float py, float pz) {
    if (BlockRailBase.func_150051_a(world.getBlock(x, y, z))) {
        if (!world.isRemote) {
            LocoBase entityminecart = new NSPCT7(world, (double) x + 0.5, (double) y + 0.5, (double) z + 0.5);
            if (itemStack.hasDisplayName()) {
                entityminecart.setMinecartName(itemStack.getDisplayName());
            }
            world.spawnEntityInWorld(entityminecart);
        }
        --itemStack.stackSize;
        return true;
    } else {
        return false;
    }
}
Also used : LocoBase(club.nsdn.nyasamarailway.entity.LocoBase) NSPCT7(club.nsdn.nyasamarailway.entity.loco.NSPCT7)

Aggregations

LocoBase (club.nsdn.nyasamarailway.entity.LocoBase)24 EntityMinecart (net.minecraft.entity.item.EntityMinecart)5 RailMonoMagnetBase (club.nsdn.nyasamarailway.tileblock.rail.mono.RailMonoMagnetBase)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 TrainPacket (club.nsdn.nyasamarailway.network.TrainPacket)3 IExtendedInfoCart (club.nsdn.nyasamarailway.entity.IExtendedInfoCart)2 ILimitVelCart (club.nsdn.nyasamarailway.entity.ILimitVelCart)2 IMotorCart (club.nsdn.nyasamarailway.entity.IMotorCart)2 MinecartBase (club.nsdn.nyasamarailway.entity.MinecartBase)2 Entity (net.minecraft.entity.Entity)2 ForgeChunkManager (net.minecraftforge.common.ForgeChunkManager)2 IRailReception (club.nsdn.nyasamarailway.block.rail.IRailReception)1 IHighSpeedCart (club.nsdn.nyasamarailway.entity.IHighSpeedCart)1 NSET1 (club.nsdn.nyasamarailway.entity.loco.NSET1)1 NSET2 (club.nsdn.nyasamarailway.entity.loco.NSET2)1 NSPCT10J (club.nsdn.nyasamarailway.entity.loco.NSPCT10J)1 NSPCT10M (club.nsdn.nyasamarailway.entity.loco.NSPCT10M)1 NSPCT4M (club.nsdn.nyasamarailway.entity.loco.NSPCT4M)1 NSPCT6L (club.nsdn.nyasamarailway.entity.loco.NSPCT6L)1 NSPCT7 (club.nsdn.nyasamarailway.entity.loco.NSPCT7)1