From 949a0ef630167f2f5f81c96235ec81297d7c1494 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 27 Feb 2019 22:42:02 +0100 Subject: [PATCH] Fixed stabilize LUA return values inconsistency Added reactor protection for frozen chunks --- .../energy/TileEntityEnanReactorCore.java | 6 ++- .../energy/TileEntityEnanReactorLaser.java | 37 ++++++++++--------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorCore.java b/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorCore.java index e5a11e4b..41ab13f9 100644 --- a/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorCore.java +++ b/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorCore.java @@ -222,7 +222,11 @@ public class TileEntityEnanReactorCore extends TileEntityEnanReactorController { if (instabilityValues[reactorFace.indexStability] > instabilityTarget) { final TileEntityEnanReactorLaser tileEntityEnanReactorLaser = getLaser(reactorFace); if (tileEntityEnanReactorLaser != null) { - tileEntityEnanReactorLaser.stabilize(stabilizerEnergy); + if (tileEntityEnanReactorLaser.stabilize(stabilizerEnergy) == -stabilizerEnergy) { + // chunk isn't updating properly => protect the reactor + instabilityValues[reactorFace.indexStability] = instabilityTarget; + hold = true; + } } } } diff --git a/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorLaser.java b/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorLaser.java index f7223bf3..36a33142 100644 --- a/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorLaser.java +++ b/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorLaser.java @@ -154,17 +154,21 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen } } - boolean stabilize(final int energy) { + protected int stabilize(final int energy) { if (energy <= 0) { - return false; + return 0; } if (laserMedium_direction == null) { - return false; + return 0; + } + if (energyStabilizationRequest > 0) { + WarpDrive.logger.warn("%s Stabilization already requested for %s", + this, energy); + return -energy; } - energyStabilizationRequest = energy; - return true; + return energy; } private void doStabilize(final int energy) { @@ -229,20 +233,19 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen @Override public Object[] stabilize(final Object[] arguments) { - if (arguments.length != 1) { - return new Object[] { false, "Invalid number of arguments" }; - } - final int energy; - try { - energy = Commons.toInt(arguments[0]); - } catch (final Exception exception) { - if (WarpDriveConfig.LOGGING_LUA) { - WarpDrive.logger.error(String.format("%s LUA error on stabilize(): Integer expected for 1st argument %s", - this, arguments[0])); + if (arguments.length == 1) { + final int energy; + try { + energy = Commons.toInt(arguments[0]); + return new Object[] { stabilize(energy) }; + } catch (final Exception exception) { + if (WarpDriveConfig.LOGGING_LUA) { + WarpDrive.logger.error(String.format("%s LUA error on stabilize(): Integer expected for 1st argument %s", + this, arguments[0])); + } } - return new Object[] { false, "Invalid integer" }; } - return new Object[] { stabilize(energy) }; + return new Object[] { energyStabilizationRequest }; } @Override