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);
}
}
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;
}
}
}
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);
}
}
}
}
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;
}
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;
}
Aggregations