Search in sources :

Example 66 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart in project NyaSamaRailway by NSDN.

the class LocoBase method update.

public void update() {
    if (this.worldObj.isRemote) {
        super.onUpdate();
        return;
    }
    if (this.getRollingAmplitude() > 0) {
        this.setRollingAmplitude(this.getRollingAmplitude() - 1);
    }
    if (this.getDamage() > 0.0F) {
        this.setDamage(this.getDamage() - 1.0F);
    }
    if (this.posY < -64.0D) {
        this.kill();
    }
    if (!this.worldObj.isRemote && this.worldObj instanceof WorldServer) {
        this.worldObj.theProfiler.startSection("portal");
        MinecraftServer minecraftserver = ((WorldServer) this.worldObj).func_73046_m();
        int i = this.getMaxInPortalTime();
        if (this.inPortal) {
            if (minecraftserver.getAllowNether()) {
                if (this.ridingEntity == null && this.portalCounter++ >= i) {
                    this.portalCounter = i;
                    this.timeUntilPortal = this.getPortalCooldown();
                    byte b0;
                    if (this.worldObj.provider.dimensionId == -1) {
                        b0 = 0;
                    } else {
                        b0 = -1;
                    }
                    this.travelToDimension(b0);
                }
                this.inPortal = false;
            }
        } else {
            if (this.portalCounter > 0) {
                this.portalCounter -= 4;
            }
            if (this.portalCounter < 0) {
                this.portalCounter = 0;
            }
        }
        if (this.timeUntilPortal > 0) {
            --this.timeUntilPortal;
        }
        this.worldObj.theProfiler.endSection();
        this.prevPosX = this.posX;
        this.prevPosY = this.posY;
        this.prevPosZ = this.posZ;
        this.motionY -= 0.03999999910593033D;
        int x = MathHelper.floor_double(this.posX);
        int y = MathHelper.floor_double(this.posY);
        int z = MathHelper.floor_double(this.posZ);
        if (!BlockRailBase.func_150049_b_(this.worldObj, x, y, z) && BlockRailBase.func_150049_b_(this.worldObj, x, y - 1, z)) {
            --y;
        }
        double d0 = 0.4D;
        double d2 = 0.0078125D;
        Block block = this.worldObj.getBlock(x, y, z);
        if (canUseRail() && BlockRailBase.func_150051_a(block)) {
            float railMaxSpeed = ((BlockRailBase) block).getRailMaxSpeed(worldObj, this, x, y, z);
            double maxSpeed = Math.min(railMaxSpeed, getMaxCartSpeedOnRail());
            this.func_145821_a(x, y, z, maxSpeed, getSlopeAdjustment(), block, ((BlockRailBase) block).getBasicRailMetadata(worldObj, this, x, y, z));
            if (block == Blocks.activator_rail) {
                this.onActivatorRailPass(x, y, z, (worldObj.getBlockMetadata(x, y, z) & 8) != 0);
            }
        } else {
            this.func_94088_b(onGround ? d0 : getMaxSpeedAirLateral());
        }
        this.func_145775_I();
        this.rotationPitch = 0.0F;
        double d8 = this.prevPosX - this.posX;
        double d4 = this.prevPosZ - this.posZ;
        if (d8 * d8 + d4 * d4 > 0.001D) {
            this.rotationYaw = (float) (Math.atan2(d4, d8) * 180.0D / Math.PI);
            if (this.isInReverse) {
                this.rotationYaw += 180.0F;
            }
        }
        double detlaYaw = (double) MathHelper.wrapAngleTo180_float(this.rotationYaw - this.prevRotationYaw);
        if (detlaYaw < -170.0D || detlaYaw >= 170.0D) {
            this.rotationYaw += 180.0F;
            this.isInReverse = !this.isInReverse;
        }
        this.setRotation(this.rotationYaw, this.rotationPitch);
        AxisAlignedBB box = getBoundingBox();
        if (box == null) {
            box = AxisAlignedBB.getBoundingBox(chunkCoordX, chunkCoordY, chunkCoordZ, chunkCoordX + 1, chunkCoordY + 1, chunkCoordZ + 1);
        }
        List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, box);
        if (list != null && !list.isEmpty()) {
            for (int k = 0; k < list.size(); ++k) {
                Entity entity = (Entity) list.get(k);
                if (entity != this.riddenByEntity && entity.canBePushed() && entity instanceof EntityMinecart) {
                    entity.applyEntityCollision(this);
                }
            }
        }
        if (this.riddenByEntity != null && this.riddenByEntity.isDead) {
            if (this.riddenByEntity.ridingEntity == this) {
                this.riddenByEntity.ridingEntity = null;
            }
            this.riddenByEntity = null;
        }
        MinecraftForge.EVENT_BUS.post(new MinecartUpdateEvent(this, x, y, z));
    }
}
Also used : Entity(net.minecraft.entity.Entity) WorldServer(net.minecraft.world.WorldServer) EntityMinecart(net.minecraft.entity.item.EntityMinecart) MinecraftServer(net.minecraft.server.MinecraftServer) BlockRailBase(net.minecraft.block.BlockRailBase) MinecartUpdateEvent(net.minecraftforge.event.entity.minecart.MinecartUpdateEvent) Block(net.minecraft.block.Block) List(java.util.List)

Example 67 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart in project NyaSamaRailway by NSDN.

the class MinecartBase method onUpdate.

/**
 ****************************************************************************************************************
 */
@Override
public void onUpdate() {
    if (this.worldObj.isRemote) {
        super.onUpdate();
        double detlaYaw = (double) MathHelper.wrapAngleTo180_float(this.rotationYaw - this.prevRotationYaw);
        /* Driver Heading */
        if (this.riddenByEntity != null && !this.riddenByEntity.isDead) {
            if (this.riddenByEntity.ridingEntity == this) {
                if (this.riddenByEntity instanceof EntityPlayer) {
                    if (canMakePlayerTurn())
                        ((EntityPlayer) this.riddenByEntity).rotationYaw += detlaYaw;
                }
            }
        }
        return;
    }
    if (this.getRollingAmplitude() > 0) {
        this.setRollingAmplitude(this.getRollingAmplitude() - 1);
    }
    if (this.getDamage() > 0.0F) {
        this.setDamage(this.getDamage() - 1.0F);
    }
    if (this.posY < -64.0D) {
        this.kill();
    }
    if (!this.worldObj.isRemote && this.worldObj instanceof WorldServer) {
        this.worldObj.theProfiler.startSection("portal");
        MinecraftServer minecraftserver = ((WorldServer) this.worldObj).func_73046_m();
        int i = this.getMaxInPortalTime();
        if (this.inPortal) {
            if (minecraftserver.getAllowNether()) {
                if (this.ridingEntity == null && this.portalCounter++ >= i) {
                    this.portalCounter = i;
                    this.timeUntilPortal = this.getPortalCooldown();
                    byte b0;
                    if (this.worldObj.provider.dimensionId == -1) {
                        b0 = 0;
                    } else {
                        b0 = -1;
                    }
                    this.travelToDimension(b0);
                }
                this.inPortal = false;
            }
        } else {
            if (this.portalCounter > 0) {
                this.portalCounter -= 4;
            }
            if (this.portalCounter < 0) {
                this.portalCounter = 0;
            }
        }
        if (this.timeUntilPortal > 0) {
            --this.timeUntilPortal;
        }
        this.worldObj.theProfiler.endSection();
        this.prevPosX = this.posX;
        this.prevPosY = this.posY;
        this.prevPosZ = this.posZ;
        this.motionY -= 0.03999999910593033D;
        int x = MathHelper.floor_double(this.posX);
        int y = MathHelper.floor_double(this.posY);
        int z = MathHelper.floor_double(this.posZ);
        if (!BlockRailBase.func_150049_b_(this.worldObj, x, y, z) && BlockRailBase.func_150049_b_(this.worldObj, x, y - 1, z)) {
            --y;
        }
        double d0 = 0.4D;
        double d2 = 0.0078125D;
        Block block = this.worldObj.getBlock(x, y, z);
        if (canUseRail() && BlockRailBase.func_150051_a(block)) {
            float railMaxSpeed = ((BlockRailBase) block).getRailMaxSpeed(worldObj, this, x, y, z);
            double maxSpeed = Math.min(railMaxSpeed, getMaxCartSpeedOnRail());
            this.func_145821_a(x, y, z, maxSpeed, getSlopeAdjustment(), block, ((BlockRailBase) block).getBasicRailMetadata(worldObj, this, x, y, z));
            if (block == Blocks.activator_rail) {
                this.onActivatorRailPass(x, y, z, (worldObj.getBlockMetadata(x, y, z) & 8) != 0);
            }
        } else {
            this.func_94088_b(onGround ? d0 : getMaxSpeedAirLateral());
        }
        this.func_145775_I();
        this.rotationPitch = 0.0F;
        double d8 = this.prevPosX - this.posX;
        double d4 = this.prevPosZ - this.posZ;
        if (d8 * d8 + d4 * d4 > 0.001D) {
            this.rotationYaw = (float) (Math.atan2(d4, d8) * 180.0D / Math.PI);
            if (this.isInReverse) {
                this.rotationYaw += 180.0F;
            }
        }
        double detlaYaw = (double) MathHelper.wrapAngleTo180_float(this.rotationYaw - this.prevRotationYaw);
        if (detlaYaw < -170.0D || detlaYaw >= 170.0D) {
            this.rotationYaw += 180.0F;
            this.isInReverse = !this.isInReverse;
        }
        this.setRotation(this.rotationYaw, this.rotationPitch);
        AxisAlignedBB box = getBoundingBox();
        if (box == null) {
            box = AxisAlignedBB.getBoundingBox(chunkCoordX, chunkCoordY, chunkCoordZ, chunkCoordX + 1, chunkCoordY + 1, chunkCoordZ + 1);
        }
        List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, box);
        if (list != null && !list.isEmpty()) {
            for (int k = 0; k < list.size(); ++k) {
                Entity entity = (Entity) list.get(k);
                if (entity != this.riddenByEntity && entity.canBePushed() && entity instanceof EntityMinecart) {
                    entity.applyEntityCollision(this);
                }
            }
        }
        /* Driver Heading */
        if (this.riddenByEntity != null && !this.riddenByEntity.isDead) {
            if (this.riddenByEntity.ridingEntity == this) {
                if (this.riddenByEntity instanceof EntityPlayer) {
                    if (canMakePlayerTurn())
                        ((EntityPlayer) this.riddenByEntity).rotationYaw += detlaYaw;
                }
            }
        }
        if (this.riddenByEntity != null && this.riddenByEntity.isDead) {
            if (this.riddenByEntity.ridingEntity == this) {
                this.riddenByEntity.ridingEntity = null;
            }
            this.riddenByEntity = null;
        }
        MinecraftForge.EVENT_BUS.post(new MinecartUpdateEvent(this, x, y, z));
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) WorldServer(net.minecraft.world.WorldServer) EntityMinecart(net.minecraft.entity.item.EntityMinecart) MinecraftServer(net.minecraft.server.MinecraftServer) BlockRailBase(net.minecraft.block.BlockRailBase) MinecartUpdateEvent(net.minecraftforge.event.entity.minecart.MinecartUpdateEvent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) List(java.util.List)

Example 68 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart in project NyaSamaRailway by NSDN.

the class TrainBase method onUpdate.

@Override
public void onUpdate() {
    if (this.getRollingAmplitude() > 0) {
        this.setRollingAmplitude(this.getRollingAmplitude() - 1);
    }
    if (this.getDamage() > 0.0F) {
        this.setDamage(this.getDamage() - 1.0F);
    }
    if (this.posY < -64.0D) {
        this.kill();
    }
    int Y;
    if (!this.worldObj.isRemote && this.worldObj instanceof WorldServer) {
        this.worldObj.theProfiler.startSection("portal");
        MinecraftServer l = ((WorldServer) this.worldObj).func_73046_m();
        Y = this.getMaxInPortalTime();
        if (this.inPortal) {
            if (l.getAllowNether()) {
                if (this.ridingEntity == null && this.portalCounter++ >= Y) {
                    this.portalCounter = Y;
                    this.timeUntilPortal = this.getPortalCooldown();
                    byte i1;
                    if (this.worldObj.provider.dimensionId == -1) {
                        i1 = 0;
                    } else {
                        i1 = -1;
                    }
                    this.travelToDimension(i1);
                }
                this.inPortal = false;
            }
        } else {
            if (this.portalCounter > 0) {
                this.portalCounter -= 4;
            }
            if (this.portalCounter < 0) {
                this.portalCounter = 0;
            }
        }
        if (this.timeUntilPortal > 0) {
            --this.timeUntilPortal;
        }
        this.worldObj.theProfiler.endSection();
    }
    // if(false) {
    if (this.worldObj.isRemote) {
        this.setPosition(this.posX, this.posY, this.posZ);
        this.setRotation(this.rotationYaw, this.rotationPitch);
    } else {
        this.prevPosX = this.posX;
        this.prevPosY = this.posY;
        this.prevPosZ = this.posZ;
        if (!bogies.isEmpty()) {
            EntityMinecart bogieFront = (EntityMinecart) this.worldObj.getEntityByID(bogies.get(0));
            EntityMinecart bogieBack = (EntityMinecart) this.worldObj.getEntityByID(bogies.get(1));
            /*some code*/
            double Ks = 500.0;
            double Kd = 500.0;
            double m = 1.0;
            double length = 2.0;
            double dt = 0.001;
            double dist = calcDist(bogieFront, bogieBack);
            double dv = Ks * (dist - length) / m * dt;
            double DdvX = Kd * (bogieFront.motionX - bogieBack.motionX) / m * dt;
            double DdvZ = Kd * (bogieFront.motionZ - bogieBack.motionZ) / m * dt;
            bogieBack.motionX += dv * (bogieFront.posX - bogieBack.posX) / dist + DdvX;
            bogieBack.motionZ += dv * (bogieFront.posZ - bogieBack.posZ) / dist + DdvZ;
            bogieFront.motionX += -dv * (bogieFront.posX - bogieBack.posX) / dist - DdvX;
            bogieFront.motionZ += -dv * (bogieFront.posZ - bogieBack.posZ) / dist - DdvZ;
            this.posX = (bogieFront.posX + bogieBack.posX) / 2.0;
            this.posY = (bogieFront.posY + bogieBack.posY) / 2.0;
            this.posZ = (bogieFront.posZ + bogieBack.posZ) / 2.0;
            this.motionX = this.posX - this.prevPosX;
            this.motionY = this.posY - this.prevPosY;
            this.motionZ = this.posZ - this.prevPosZ;
            this.rotationYaw = 180.0F - (float) Math.acos((bogieFront.posX - bogieBack.posX) / calcDist(bogieFront.posX - bogieBack.posX, bogieFront.posZ - bogieBack.posZ));
            this.rotationPitch = (float) Math.atan((bogieFront.posY - bogieBack.posY) / calcDist(bogieFront.posX - bogieBack.posX, bogieFront.posZ - bogieBack.posZ));
            this.moveEntity(this.motionX, this.motionY, this.motionZ);
        }
        if (this.riddenByEntity != null && this.riddenByEntity.isDead) {
            if (this.riddenByEntity.ridingEntity == this) {
                this.riddenByEntity.ridingEntity = null;
            }
            this.riddenByEntity = null;
        }
        int X = MathHelper.floor_double(this.posX);
        Y = MathHelper.floor_double(this.posY);
        int Z = MathHelper.floor_double(this.posZ);
        MinecraftForge.EVENT_BUS.post(new MinecartUpdateEvent(this, (float) X, (float) Y, (float) Z));
    }
}
Also used : MinecartUpdateEvent(net.minecraftforge.event.entity.minecart.MinecartUpdateEvent) WorldServer(net.minecraft.world.WorldServer) EntityMinecart(net.minecraft.entity.item.EntityMinecart) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 69 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart in project NyaSamaRailway by NSDN.

the class EntityInteractHandler method onEntityInteract.

@SubscribeEvent
public void onEntityInteract(EntityInteractEvent event) {
    if (event.entityLiving instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.entityLiving;
        if (player.worldObj.isRemote)
            return;
        Entity entity = event.target;
        ItemStack stack = player.getCurrentEquippedItem();
        if (stack != null) {
            if (stack.getItem() instanceof ItemNTP8Bit) {
                if (player.isSneaking()) {
                    ((ItemNTP8Bit) stack.getItem()).clearCart(stack, player);
                    return;
                }
                if (entity instanceof EntityMinecart) {
                    ((ItemNTP8Bit) stack.getItem()).addCart(stack, player, entity);
                }
            } else if (stack.getItem() instanceof ItemNTP32Bit) {
                if (player.isSneaking()) {
                    ((ItemNTP32Bit) stack.getItem()).clearCart(stack, player);
                    return;
                }
                if (entity instanceof EntityMinecart) {
                    ((ItemNTP32Bit) stack.getItem()).addCart(stack, player, entity);
                } else {
                    if (ExRollerCoaster.getInstance() != null) {
                        if (ExRollerCoaster.getInstance().verifyEntity(entity)) {
                            ((ItemNTP32Bit) stack.getItem()).addCart(stack, player, entity);
                        }
                    }
                    if (RailsOfWar.getInstance() != null) {
                        if (RailsOfWar.getInstance().verifyEntity(entity)) {
                            ((ItemNTP32Bit) stack.getItem()).addCart(stack, player, entity);
                        }
                    }
                }
            } else if (stack.getItem() instanceof Item1N4148) {
                if (entity instanceof NSPCT8J) {
                    NSPCT8J loco = (NSPCT8J) entity;
                    loco.modifyHighSpeedMode(player);
                }
            } else if (stack.getItem() instanceof ItemNSPCT5) {
                if (entity instanceof NSPCT5) {
                    ((NSPCT5) entity).modifyLength();
                }
            } else if (stack.getItem() instanceof ItemNSPCT5L) {
                if (entity instanceof NSPCT5L) {
                    ((NSPCT5L) entity).modifyLength();
                }
            }
        }
    }
}
Also used : ItemNTP32Bit(club.nsdn.nyasamarailway.item.tool.ItemNTP32Bit) Entity(net.minecraft.entity.Entity) ItemNTP8Bit(club.nsdn.nyasamarailway.item.tool.ItemNTP8Bit) NSPCT8J(club.nsdn.nyasamarailway.entity.loco.NSPCT8J) Item1N4148(club.nsdn.nyasamarailway.item.tool.Item1N4148) NSPCT5(club.nsdn.nyasamarailway.entity.cart.NSPCT5) ItemNSPCT5(club.nsdn.nyasamarailway.item.cart.ItemNSPCT5) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) NSPCT5L(club.nsdn.nyasamarailway.entity.cart.NSPCT5L) ItemNSPCT5L(club.nsdn.nyasamarailway.item.cart.ItemNSPCT5L) EntityMinecart(net.minecraft.entity.item.EntityMinecart) ItemNSPCT5L(club.nsdn.nyasamarailway.item.cart.ItemNSPCT5L) ItemNSPCT5(club.nsdn.nyasamarailway.item.cart.ItemNSPCT5) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 70 with EntityMinecart

use of net.minecraft.entity.item.EntityMinecart 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)

Aggregations

EntityMinecart (net.minecraft.entity.item.EntityMinecart)75 EntityPlayer (net.minecraft.entity.player.EntityPlayer)21 ItemStack (net.minecraft.item.ItemStack)17 List (java.util.List)16 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)11 Entity (net.minecraft.entity.Entity)9 DamageSource (net.minecraft.util.DamageSource)8 World (net.minecraft.world.World)8 ItemNTP32Bit (club.nsdn.nyasamarailway.item.tool.ItemNTP32Bit)6 ItemNTP8Bit (club.nsdn.nyasamarailway.item.tool.ItemNTP8Bit)6 ILinkageManager (mods.railcraft.api.carts.ILinkageManager)6 LocoBase (club.nsdn.nyasamarailway.entity.LocoBase)5 Nullable (javax.annotation.Nullable)5 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 TileEntityReceiver (club.nsdn.nyasamatelecom.api.tileentity.TileEntityReceiver)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)4 MinecartUpdateEvent (net.minecraftforge.event.entity.minecart.MinecartUpdateEvent)4 TrainPacket (club.nsdn.nyasamarailway.network.TrainPacket)3 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)3 ArrayList (java.util.ArrayList)3