Search in sources :

Example 11 with EnumRailDirection

use of net.minecraft.block.BlockRailBase.EnumRailDirection in project Railcraft by Railcraft.

the class TrackKitDisembark method onMinecartPass.

@Override
public void onMinecartPass(EntityMinecart cart) {
    if (isPowered() && cart.isBeingRidden()) {
        double x = getPos().getX();
        double z = getPos().getZ();
        double offset = 1.5;
        IBlockState state = theWorldAsserted().getBlockState(getPos());
        EnumRailDirection dir = TrackTools.getTrackDirectionRaw(state);
        if (dir == EnumRailDirection.NORTH_SOUTH)
            if (mirrored)
                x += offset;
            else
                x -= offset;
        else if (mirrored)
            z += offset;
        else
            z -= offset;
        CartTools.removePassengers(cart, new Vec3d(x + 0.5, getPos().getY() + 1, z + 0.5));
        cart.getEntityData().setInteger("MountPrevention", TIME_TILL_NEXT_MOUNT);
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumRailDirection(net.minecraft.block.BlockRailBase.EnumRailDirection) Vec3d(net.minecraft.util.math.Vec3d)

Example 12 with EnumRailDirection

use of net.minecraft.block.BlockRailBase.EnumRailDirection in project Railcraft by Railcraft.

the class TrackKitBooster method onMinecartPassStandard.

private void onMinecartPassStandard(EntityMinecart cart, double boostFactor) {
    EnumRailDirection dir = getRailDirectionRaw();
    double speed = Math.sqrt(cart.motionX * cart.motionX + cart.motionZ * cart.motionZ);
    if (isPowered()) {
        if (speed > BOOST_THRESHOLD) {
            cart.motionX += (cart.motionX / speed) * boostFactor;
            cart.motionZ += (cart.motionZ / speed) * boostFactor;
        } else {
            CartTools.startBoost(cart, getPos(), dir, START_BOOST);
        }
    } else {
        if (speed < STALL_THRESHOLD) {
            cart.motionX = 0.0D;
            cart.motionY = 0.0D;
            cart.motionZ = 0.0D;
        } else {
            cart.motionX *= SLOW_FACTOR;
            cart.motionY = 0.0D;
            cart.motionZ *= SLOW_FACTOR;
        }
    }
}
Also used : EnumRailDirection(net.minecraft.block.BlockRailBase.EnumRailDirection)

Example 13 with EnumRailDirection

use of net.minecraft.block.BlockRailBase.EnumRailDirection in project Railcraft by Railcraft.

the class TrackKitBooster method onMinecartPassHighSpeed.

private void onMinecartPassHighSpeed(EntityMinecart cart) {
    if (isPowered()) {
        double speed = Math.sqrt(cart.motionX * cart.motionX + cart.motionZ * cart.motionZ);
        EnumRailDirection dir = getRailDirectionRaw();
        if (speed > BOOST_THRESHOLD) {
            cart.motionX += (cart.motionX / speed) * BOOST_FACTOR_HS;
            cart.motionZ += (cart.motionZ / speed) * BOOST_FACTOR_HS;
        } else {
            CartTools.startBoost(cart, getPos(), dir, START_BOOST);
        }
    } else {
        boolean highSpeed = CartTools.isTravellingHighSpeed(cart);
        if (highSpeed) {
            if (cart instanceof EntityLocomotive) {
                ((EntityLocomotive) cart).forceIdle(20);
            }
            cart.motionX *= SLOW_FACTOR_HS;
            cart.motionY = 0.0D;
            cart.motionZ *= SLOW_FACTOR_HS;
        } else {
            if (Math.abs(cart.motionX) > 0) {
                cart.motionX = Math.copySign(0.38f, cart.motionX);
            }
            if (Math.abs(cart.motionZ) > 0) {
                cart.motionZ = Math.copySign(0.38f, cart.motionZ);
            }
        }
    }
}
Also used : EnumRailDirection(net.minecraft.block.BlockRailBase.EnumRailDirection) EntityLocomotive(mods.railcraft.common.carts.EntityLocomotive)

Example 14 with EnumRailDirection

use of net.minecraft.block.BlockRailBase.EnumRailDirection in project Railcraft by Railcraft.

the class TrackTools method setTrackDirection.

public static boolean setTrackDirection(World world, BlockPos pos, EnumRailDirection wanted) {
    IBlockState state = world.getBlockState(pos);
    IProperty<EnumRailDirection> prop = getRailDirectionProperty(state.getBlock());
    if (prop.getAllowedValues().contains(wanted)) {
        state = state.withProperty(prop, wanted);
        return world.setBlockState(pos, state);
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumRailDirection(net.minecraft.block.BlockRailBase.EnumRailDirection)

Example 15 with EnumRailDirection

use of net.minecraft.block.BlockRailBase.EnumRailDirection in project Railcraft by Railcraft.

the class TrackTools method getConnectedTracks.

public static Set<BlockPos> getConnectedTracks(IBlockAccess world, BlockPos pos) {
    Set<BlockPos> connectedTracks = new HashSet<>();
    EnumRailDirection shape;
    if (isRailBlockAt(world, pos))
        shape = getTrackDirectionRaw(world, pos);
    else
        shape = EnumRailDirection.NORTH_SOUTH;
    for (EnumFacing side : EnumFacing.HORIZONTALS) {
        BlockPos trackPos = getTrackConnectedTrackAt(world, pos.offset(side), shape);
        if (trackPos != null)
            connectedTracks.add(trackPos);
    }
    return connectedTracks;
}
Also used : EnumRailDirection(net.minecraft.block.BlockRailBase.EnumRailDirection) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) HashSet(java.util.HashSet)

Aggregations

EnumRailDirection (net.minecraft.block.BlockRailBase.EnumRailDirection)15 BlockPos (net.minecraft.util.math.BlockPos)8 IBlockState (net.minecraft.block.state.IBlockState)2 EnumFacing (net.minecraft.util.EnumFacing)2 World (net.minecraft.world.World)2 HashSet (java.util.HashSet)1 EntityLocomotive (mods.railcraft.common.carts.EntityLocomotive)1 Vec3d (net.minecraft.util.math.Vec3d)1