Search in sources :

Example 1 with RailMonoMagnetReception

use of club.nsdn.nyasamarailway.tileblock.rail.mono.RailMonoMagnetReception in project NyaSamaRailway by NSDN.

the class MinecartBase method func_145821_a.

// applyPush()
@Override
protected void func_145821_a(int x, int y, int z, double maxVel, double slopeAdj, Block block, int meta) {
    // applyPush
    if (block instanceof BlockRailReception) {
        BlockRailReception.TileEntityRailReception tile = (BlockRailReception.TileEntityRailReception) worldObj.getTileEntity(x, y, z);
        if (!((BlockRailReception) block).checkNearbySameRail(worldObj, x, y, z))
            if (riddenByEntity == null && !tile.cartType.isEmpty()) {
                if (!tile.cartType.equals("loco"))
                    return;
            }
    }
    if (block instanceof BlockRailReceptionAnti) {
        BlockRailReceptionAnti.TileEntityRailReceptionAnti tile = (BlockRailReceptionAnti.TileEntityRailReceptionAnti) worldObj.getTileEntity(x, y, z);
        if (!((BlockRailReceptionAnti) block).checkNearbySameRail(worldObj, x, y, z))
            if (riddenByEntity == null && !tile.cartType.isEmpty()) {
                if (!tile.cartType.equals("loco"))
                    return;
            }
    }
    if (block instanceof RailMonoMagnetReception) {
        RailMonoMagnetReception.TileEntityRail tile = (RailMonoMagnetReception.TileEntityRail) worldObj.getTileEntity(x, y, z);
        if (!((RailMonoMagnetReception) block).checkNearbySameRail(worldObj, x, y, z))
            if (riddenByEntity == null && !tile.cartType.isEmpty())
                return;
    }
    if (block instanceof RailMonoMagnetReceptionAnti) {
        RailMonoMagnetReceptionAnti.TileEntityRail tile = (RailMonoMagnetReceptionAnti.TileEntityRail) worldObj.getTileEntity(x, y, z);
        if (!((RailMonoMagnetReceptionAnti) block).checkNearbySameRail(worldObj, x, y, z))
            if (riddenByEntity == null && !tile.cartType.isEmpty())
                return;
    }
    /* ******************************** MAIN FUNC ******************************** */
    this.fallDistance = 0.0F;
    Vec3 vec3 = this.func_70489_a(this.posX, this.posY, this.posZ);
    this.posY = (double) y;
    boolean isRailPowered = false;
    boolean slowDown = false;
    if (block == Blocks.golden_rail) {
        // Stock Powered Rail, Push-Brake
        isRailPowered = (this.worldObj.getBlockMetadata(x, y, z) & 8) != 0;
        slowDown = !isRailPowered;
    }
    if (((BlockRailBase) block).isPowered()) {
        meta &= 7;
    }
    if (meta >= 2 && meta <= 5) {
        this.posY = (double) (y + 1);
    }
    if (meta == 2) {
        this.motionX -= slopeAdj;
    }
    if (meta == 3) {
        this.motionX += slopeAdj;
    }
    if (meta == 4) {
        this.motionZ += slopeAdj;
    }
    if (meta == 5) {
        this.motionZ -= slopeAdj;
    }
    int[][] aint = matrix[meta];
    double d2 = (double) (aint[1][0] - aint[0][0]);
    double d3 = (double) (aint[1][2] - aint[0][2]);
    double d4 = Math.sqrt(d2 * d2 + d3 * d3);
    double d5 = this.motionX * d2 + this.motionZ * d3;
    if (d5 < 0.0D) {
        d2 = -d2;
        d3 = -d3;
    }
    double vel = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
    if (vel > getMaxCartSpeedOnRail()) {
        vel = getMaxCartSpeedOnRail();
    }
    this.motionX = vel * d2 / d4;
    this.motionZ = vel * d3 / d4;
    double d7;
    double d8;
    double d9;
    double d10;
    if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityLivingBase) {
        d7 = (double) ((EntityLivingBase) this.riddenByEntity).moveForward;
        if (d7 > 0.0D) {
            d8 = -Math.sin((double) (this.riddenByEntity.rotationYaw * 3.1415927F / 180.0F));
            d9 = Math.cos((double) (this.riddenByEntity.rotationYaw * 3.1415927F / 180.0F));
            d10 = this.motionX * this.motionX + this.motionZ * this.motionZ;
            if (d10 < 0.01D) {
                this.motionX += d8 * 0.1D;
                this.motionZ += d9 * 0.1D;
                slowDown = false;
            }
        }
    }
    if (slowDown && this.shouldDoRailFunctions()) {
        d7 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
        if (d7 < 0.03D) {
            this.motionX *= 0.0D;
            this.motionY *= 0.0D;
            this.motionZ *= 0.0D;
        } else {
            this.motionX *= 0.5D;
            this.motionY *= 0.0D;
            this.motionZ *= 0.5D;
        }
    }
    d7 = 0.0D;
    d8 = (double) x + 0.5D + (double) aint[0][0] * 0.5D;
    d9 = (double) z + 0.5D + (double) aint[0][2] * 0.5D;
    d10 = (double) x + 0.5D + (double) aint[1][0] * 0.5D;
    double d11 = (double) z + 0.5D + (double) aint[1][2] * 0.5D;
    d2 = d10 - d8;
    d3 = d11 - d9;
    if (d2 == 0.0D) {
        this.posX = (double) x + 0.5D;
        d7 = this.posZ - (double) z;
    } else if (d3 == 0.0D) {
        this.posZ = (double) z + 0.5D;
        d7 = this.posX - (double) x;
    } else {
        double d12 = this.posX - d8;
        double d13 = this.posZ - d9;
        d7 = (d12 * d2 + d13 * d3) * 2.0D;
    }
    this.posX = d8 + d2 * d7;
    this.posZ = d9 + d3 * d7;
    this.setPosition(this.posX, this.posY + (double) this.yOffset, this.posZ);
    this.moveMinecartOnRail(x, y, z, maxVel);
    if (aint[0][1] != 0 && MathHelper.floor_double(this.posX) - x == aint[0][0] && MathHelper.floor_double(this.posZ) - z == aint[0][2]) {
        this.setPosition(this.posX, this.posY + (double) aint[0][1], this.posZ);
    } else if (aint[1][1] != 0 && MathHelper.floor_double(this.posX) - x == aint[1][0] && MathHelper.floor_double(this.posZ) - z == aint[1][2]) {
        this.setPosition(this.posX, this.posY + (double) aint[1][1], this.posZ);
    }
    this.applyDrag();
    Vec3 vec31 = this.func_70489_a(this.posX, this.posY, this.posZ);
    if (vec31 != null && vec3 != null) {
        double d14 = (vec3.yCoord - vec31.yCoord) * 0.05D;
        vel = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
        if (vel > 0.0D) {
            this.motionX = this.motionX / vel * (vel + d14);
            this.motionZ = this.motionZ / vel * (vel + d14);
        }
        this.setPosition(this.posX, vec31.yCoord, this.posZ);
    }
    /**
     * HOLY SHIT! THE CODE CAUSES BUG!
     *        int pX = MathHelper.floor_double(this.posX);
     *        int pZ = MathHelper.floor_double(this.posZ);
     *        if (pX != x || pZ != z) {
     *            vel = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
     *            this.motionX = vel * (double)(pX - x);
     *            this.motionZ = vel * (double)(pZ - z);
     *        }
     */
    if (this.shouldDoRailFunctions()) {
        ((BlockRailBase) block).onMinecartPass(this.worldObj, this, x, y, z);
    }
    if (isRailPowered && this.shouldDoRailFunctions()) {
        double d15 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
        if (d15 > 0.01D) {
            double d16 = 0.06D;
            this.motionX += this.motionX / d15 * d16;
            this.motionZ += this.motionZ / d15 * d16;
        } else if (meta == 1) {
            if (this.worldObj.getBlock(x - 1, y, z).isNormalCube()) {
                this.motionX = 0.02D;
            } else if (this.worldObj.getBlock(x + 1, y, z).isNormalCube()) {
                this.motionX = -0.02D;
            }
        } else if (meta == 0) {
            if (this.worldObj.getBlock(x, y, z - 1).isNormalCube()) {
                this.motionZ = 0.02D;
            } else if (this.worldObj.getBlock(x, y, z + 1).isNormalCube()) {
                this.motionZ = -0.02D;
            }
        }
    }
}
Also used : BlockRailBase(net.minecraft.block.BlockRailBase) BlockRailReceptionAnti(club.nsdn.nyasamarailway.block.rail.special.BlockRailReceptionAnti) RailMonoMagnetReceptionAnti(club.nsdn.nyasamarailway.tileblock.rail.mono.RailMonoMagnetReceptionAnti) Vec3(net.minecraft.util.Vec3) BlockRailReception(club.nsdn.nyasamarailway.block.rail.special.BlockRailReception) EntityLivingBase(net.minecraft.entity.EntityLivingBase) RailMonoMagnetReception(club.nsdn.nyasamarailway.tileblock.rail.mono.RailMonoMagnetReception)

Aggregations

BlockRailReception (club.nsdn.nyasamarailway.block.rail.special.BlockRailReception)1 BlockRailReceptionAnti (club.nsdn.nyasamarailway.block.rail.special.BlockRailReceptionAnti)1 RailMonoMagnetReception (club.nsdn.nyasamarailway.tileblock.rail.mono.RailMonoMagnetReception)1 RailMonoMagnetReceptionAnti (club.nsdn.nyasamarailway.tileblock.rail.mono.RailMonoMagnetReceptionAnti)1 BlockRailBase (net.minecraft.block.BlockRailBase)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 Vec3 (net.minecraft.util.Vec3)1