Search in sources :

Example 21 with TrainPacket

use of club.nsdn.nyasamarailway.network.TrainPacket in project NyaSamaRailway by NSDN.

the class ItemNTP32Bit method onCreated.

@Override
public void onCreated(ItemStack itemStack, World world, EntityPlayer player) {
    int[] array = new int[] { -1 };
    power.set(itemStack, 0);
    brake.set(itemStack, 5);
    dir.set(itemStack, 0);
    carts.set(itemStack, array);
    if (player instanceof EntityPlayerMP) {
        TrainPacket packet = new TrainPacket();
        packet.fromStack(itemStack);
        NetworkWrapper.instance.sendTo(packet, (EntityPlayerMP) player);
    }
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) TrainPacket(club.nsdn.nyasamarailway.network.TrainPacket)

Example 22 with TrainPacket

use of club.nsdn.nyasamarailway.network.TrainPacket in project NyaSamaRailway by NSDN.

the class ItemNTP32Bit 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.dimensionID = player.dimension;
            int[] carts = this.carts.get(itemStack);
            if (carts.length == 1 && carts[0] == -1)
                return;
            EntityMinecart cart;
            for (int i : carts) {
                cart = packet.getCartInServer(i);
                if (cart != null) {
                    if (cart instanceof LocoBase)
                        continue;
                    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) TrainPacket(club.nsdn.nyasamarailway.network.TrainPacket)

Example 23 with TrainPacket

use of club.nsdn.nyasamarailway.network.TrainPacket in project NyaSamaRailway by NSDN.

the class ItemNTP8Bit method addCart.

public void addCart(ItemStack itemStack, EntityPlayer player, Entity entity) {
    int id = entity.getEntityId();
    power.set(itemStack, 0);
    brake.set(itemStack, 5);
    dir.set(itemStack, 0);
    cart.set(itemStack, id);
    if (player instanceof EntityPlayerMP) {
        TrainPacket packet = new TrainPacket();
        packet.fromStack(itemStack);
        NetworkWrapper.instance.sendTo(packet, (EntityPlayerMP) player);
    }
    player.addChatComponentMessage(new ChatComponentTranslation("info.ntp.controlled"));
}
Also used : ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) TrainPacket(club.nsdn.nyasamarailway.network.TrainPacket)

Aggregations

TrainPacket (club.nsdn.nyasamarailway.network.TrainPacket)23 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 LocoBase (club.nsdn.nyasamarailway.entity.LocoBase)3 EntityMinecart (net.minecraft.entity.item.EntityMinecart)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 ChatComponentTranslation (net.minecraft.util.ChatComponentTranslation)3 ItemNTP32Bit (club.nsdn.nyasamarailway.item.tool.ItemNTP32Bit)1 ItemNTP8Bit (club.nsdn.nyasamarailway.item.tool.ItemNTP8Bit)1 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 GuiChat (net.minecraft.client.gui.GuiChat)1 ItemStack (net.minecraft.item.ItemStack)1