Fixed #236 hardcoded max jump distance

This commit is contained in:
LemADEC 2017-05-02 19:31:44 +02:00
parent 4f094b11ca
commit abb3864095
5 changed files with 30 additions and 22 deletions

View file

@ -24,6 +24,7 @@ import net.minecraft.util.StatCollector;
import cpw.mods.fml.common.Optional;
public class TileEntityShipController extends TileEntityAbstractInterfaced {
// Variables
private int distance = 0;
private int direction = 0;
@ -39,7 +40,7 @@ public class TileEntityShipController extends TileEntityAbstractInterfaced {
private String targetJumpgateName = "";
// Gabarits
// Dimensions
private int front, right, up;
private int back, left, down;
@ -80,7 +81,8 @@ public class TileEntityShipController extends TileEntityAbstractInterfaced {
"isAttached",
"getEnergyRequired",
"movement",
"rotationSteps"
"rotationSteps",
"getMaxJumpDistance"
});
CC_scripts = Arrays.asList("startup");
}
@ -360,8 +362,16 @@ public class TileEntityShipController extends TileEntityAbstractInterfaced {
this.down = down;
}
private void setDistance(int distance) {
this.distance = Math.max(1, Math.min(WarpDriveConfig.SHIP_MAX_JUMP_DISTANCE, distance));
public int getMaxJumpDistance() {
int maxDistance = WarpDriveConfig.SHIP_MAX_JUMP_DISTANCE;
if (worldObj == null || WarpDrive.starMap.isInHyperspace(worldObj, xCoord, zCoord)) {
maxDistance *= WarpDriveConfig.SHIP_HYPERSPACE_ACCELERATION;
}
return maxDistance;
}
private void setDistance(final int distance) {
this.distance = Math.max(1, Math.min(getMaxJumpDistance(), distance));
if (WarpDriveConfig.LOGGING_JUMP && worldObj != null) {
WarpDrive.logger.info(this + " Jump distance set to " + distance);
}
@ -519,6 +529,12 @@ public class TileEntityShipController extends TileEntityAbstractInterfaced {
return core.energy();
}
@Callback
@Optional.Method(modid = "OpenComputers")
public Object[] getMaxJumpDistance(Context context, Arguments arguments) {
return new Object[] { getMaxJumpDistance() };
}
@Callback
@Optional.Method(modid = "OpenComputers")
public Object[] getEnergyRequired(Context context, Arguments arguments) {
@ -590,6 +606,7 @@ public class TileEntityShipController extends TileEntityAbstractInterfaced {
return null;
}
// Common OC/CC methods
private Object[] dim_positive(Object[] arguments) {
try {
if (arguments.length == 3) {
@ -870,6 +887,8 @@ public class TileEntityShipController extends TileEntityAbstractInterfaced {
case "rotationSteps":
return rotationSteps(arguments);
case "getMaxJumpDistance":
return new Object[] { getMaxJumpDistance() };
}
return super.callMethod(computer, context, method, arguments);

View file

@ -865,10 +865,7 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy implements ISta
VectorI shipSize = new VectorI(controller.getFront() + 1 + controller.getBack(),
controller.getUp() + 1 + controller.getDown(),
controller.getRight() + 1 + controller.getLeft());
int maxDistance = WarpDriveConfig.SHIP_MAX_JUMP_DISTANCE;
if (WarpDrive.starMap.isInHyperspace(worldObj, xCoord, zCoord)) {
maxDistance *= 100;
}
final int maxDistance = controller.getMaxJumpDistance();
if (Math.abs(movement.x) - shipSize.x > maxDistance) {
movement.x = (int) Math.signum(movement.x) * (shipSize.x + maxDistance);
}
@ -881,12 +878,7 @@ public class TileEntityShipCore extends TileEntityAbstractEnergy implements ISta
moveX = dx * movement.x - dz * movement.z;
moveY = movement.y;
moveZ = dz * movement.x + dx * movement.z;
if (currentMode == EnumShipCoreMode.BASIC_JUMP) {
// VectorI sizes = new VectorI(controller.getBack() + controller.getFront(), controller.getDown() + controller.getUp(), controller.getLeft() + controller.getRight());
// moveX += Math.signum((double)moveX) * Math.abs(dx * sizes.x - dz * sizes.z);
// moveY += Math.signum((double)moveY) * (sizes.y);
// moveZ += Math.signum((double)moveZ) * Math.abs(dz * sizes.x + dx * sizes.z);
} else if (currentMode == EnumShipCoreMode.LONG_JUMP) {
if (currentMode == EnumShipCoreMode.LONG_JUMP) {
moveX *= 100;
moveZ *= 100;
}

View file

@ -170,6 +170,7 @@ public class WarpDriveConfig {
public static int SHIP_HYPERJUMP_ENERGY_PER_DISTANCE = 1000;
public static int SHIP_TELEPORT_ENERGY_PER_ENTITY = 1000000;
public static int SHIP_MAX_JUMP_DISTANCE = 128;
public static int SHIP_HYPERSPACE_ACCELERATION = 100;
public static int SHIP_VOLUME_MAX_ON_PLANET_SURFACE = 3000;
public static int SHIP_VOLUME_MIN_FOR_HYPERSPACE = 1200;
public static int SHIP_MAX_SIDE_SIZE = 127;
@ -491,6 +492,8 @@ public class WarpDriveConfig {
SHIP_MAX_JUMP_DISTANCE = Commons.clamp(0, 30000000,
config.get("ship", "max_jump_distance", SHIP_MAX_JUMP_DISTANCE, "Maximum jump length value in blocks").getInt());
SHIP_HYPERSPACE_ACCELERATION = Commons.clamp(1, 10000,
config.get("ship", "hyperspace_acceleration", SHIP_HYPERSPACE_ACCELERATION, "Acceleration gain from moving while in hyperspace").getInt());
SHIP_VOLUME_MAX_ON_PLANET_SURFACE = Commons.clamp(0, 10000000,
config.get("ship", "volume_max_on_planet_surface", SHIP_VOLUME_MAX_ON_PLANET_SURFACE, "Maximum ship mass (in blocks) to jump on a planet").getInt());

View file

@ -618,10 +618,7 @@ function core_page_setMovement()
end
function core_page_setDistanceAxis(line, axis, positive, negative, userEntry, shipLength)
local maximumDistance = shipLength + 127
if core_isInHyper and line ~= 3 then
maximumDistance = shipLength + 127 * 100
end
local maximumDistance = shipLength + ship.getMaxJumpDistance()
SetColorDisabled()
SetCursorPos(3, line + 1)
Write(positive .. " is " .. ( shipLength + 1) .. ", maximum is " .. maximumDistance .. " ")

View file

@ -570,10 +570,7 @@ function core_page_setMovement()
end
function core_page_setDistanceAxis(line, axis, positive, negative, userEntry, shipLength)
local maximumDistance = shipLength + 127
if core_isInHyper and line ~= 3 then
maximumDistance = shipLength + 127 * 100
end
local maximumDistance = shipLength + ship.getMaxJumpDistance()
SetColorDisabled()
SetCursorPos(3, line + 1)
Write(positive .. " is " .. ( shipLength + 1) .. ", maximum is " .. maximumDistance .. " ")