diff --git a/src/main/java/cr0s/warpdrive/block/energy/BlockEnanReactorCore.java b/src/main/java/cr0s/warpdrive/block/energy/BlockEnanReactorCore.java index 6971d6a5..d4c45709 100644 --- a/src/main/java/cr0s/warpdrive/block/energy/BlockEnanReactorCore.java +++ b/src/main/java/cr0s/warpdrive/block/energy/BlockEnanReactorCore.java @@ -1,7 +1,7 @@ package cr0s.warpdrive.block.energy; import cr0s.warpdrive.block.BlockAbstractContainer; -import cr0s.warpdrive.data.EnumReactorFace; +import cr0s.warpdrive.data.ReactorFace; import cr0s.warpdrive.data.EnumTier; import net.minecraft.block.material.Material; @@ -60,7 +60,7 @@ public class BlockEnanReactorCore extends BlockAbstractContainer { public void breakBlock(final World world, @Nonnull final BlockPos blockPos, @Nonnull final IBlockState blockState) { super.breakBlock(world, blockPos, blockState); - for (final EnumReactorFace reactorFace : EnumReactorFace.getLasers(enumTier)) { + for (final ReactorFace reactorFace : ReactorFace.getLasers(enumTier)) { if (reactorFace.indexStability < 0) { continue; } @@ -68,7 +68,7 @@ public class BlockEnanReactorCore extends BlockAbstractContainer { final TileEntity tileEntity = world.getTileEntity(blockPos.add(reactorFace.x, reactorFace.y, reactorFace.z)); if (tileEntity instanceof TileEntityEnanReactorLaser) { if (((TileEntityEnanReactorLaser) tileEntity).getReactorFace() == reactorFace) { - ((TileEntityEnanReactorLaser) tileEntity).setReactorFace(EnumReactorFace.UNKNOWN, null); + ((TileEntityEnanReactorLaser) tileEntity).setReactorFace(ReactorFace.UNKNOWN, null); } } } diff --git a/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorCore.java b/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorCore.java index 41ab13f9..04a9db81 100644 --- a/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorCore.java +++ b/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorCore.java @@ -4,7 +4,7 @@ import cr0s.warpdrive.Commons; import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.config.WarpDriveConfig; import cr0s.warpdrive.data.EnergyWrapper; -import cr0s.warpdrive.data.EnumReactorFace; +import cr0s.warpdrive.data.ReactorFace; import cr0s.warpdrive.data.EnumReactorOutputMode; import cr0s.warpdrive.data.Vector3; import cr0s.warpdrive.network.PacketHandler; @@ -12,7 +12,6 @@ import cr0s.warpdrive.network.PacketHandler; import javax.annotation.Nonnull; import java.lang.ref.WeakReference; import java.lang.reflect.Array; -import java.util.ArrayList; import java.util.Arrays; import net.minecraft.block.state.IBlockState; @@ -46,7 +45,7 @@ public class TileEntityEnanReactorCore extends TileEntityEnanReactorController { private int stabilizerEnergy = 10000; private int containedEnergy = 0; - private final double[] instabilityValues = new double[EnumReactorFace.maxInstabilities]; // no instability = 0, explosion = 100 + private final double[] instabilityValues = new double[ReactorFace.maxInstabilities]; // no instability = 0, explosion = 100 // computed properties private boolean isFirstException = true; @@ -64,7 +63,7 @@ public class TileEntityEnanReactorCore extends TileEntityEnanReactorController { private long energyReleasedLastCycle = 0; @SuppressWarnings("unchecked") - private final WeakReference[] weakTileEntityLasers = (WeakReference[]) Array.newInstance(WeakReference.class, EnumReactorFace.maxInstabilities); + private final WeakReference[] weakTileEntityLasers = (WeakReference[]) Array.newInstance(WeakReference.class, ReactorFace.maxInstabilities); public TileEntityEnanReactorCore() { super(); @@ -135,7 +134,7 @@ public class TileEntityEnanReactorCore extends TileEntityEnanReactorController { } private void increaseInstability() { - for (final EnumReactorFace reactorFace : EnumReactorFace.getLasers(enumTier)) { + for (final ReactorFace reactorFace : ReactorFace.getLasers(enumTier)) { // increase instability final int indexStability = reactorFace.indexStability; if (containedEnergy > 2000) { @@ -154,7 +153,7 @@ public class TileEntityEnanReactorCore extends TileEntityEnanReactorController { } } - void decreaseInstability(final EnumReactorFace reactorFace, final int energy) { + void decreaseInstability(final ReactorFace reactorFace, final int energy) { if (reactorFace.indexStability < 0) { return; } @@ -164,7 +163,7 @@ public class TileEntityEnanReactorCore extends TileEntityEnanReactorController { return; } - lasersReceived = Math.min(10.0F, lasersReceived + 1.0F / WarpDriveConfig.ENAN_REACTOR_MAX_LASERS_PER_SECOND); + lasersReceived = Math.min(10.0F, lasersReceived + 1.0F / WarpDriveConfig.ENAN_REACTOR_MAX_LASERS_PER_SECOND[enumTier.getIndex()]); double nospamFactor = 1.0D; if (lasersReceived > 1.0F) { nospamFactor = 0.5; @@ -194,7 +193,7 @@ public class TileEntityEnanReactorCore extends TileEntityEnanReactorController { private void generateEnergy() { double stabilityOffset = 0.5; - for (final EnumReactorFace reactorFace : EnumReactorFace.getLasers(enumTier)) { + for (final ReactorFace reactorFace : ReactorFace.getLasers(enumTier)) { stabilityOffset *= Math.max(0.01D, instabilityValues[reactorFace.indexStability] / 100.0D); } @@ -218,7 +217,7 @@ public class TileEntityEnanReactorCore extends TileEntityEnanReactorController { } private void runControlLoop() { - for (final EnumReactorFace reactorFace : EnumReactorFace.getLasers(enumTier)) { + for (final ReactorFace reactorFace : ReactorFace.getLasers(enumTier)) { if (instabilityValues[reactorFace.indexStability] > instabilityTarget) { final TileEntityEnanReactorLaser tileEntityEnanReactorLaser = getLaser(reactorFace); if (tileEntityEnanReactorLaser != null) { @@ -232,7 +231,7 @@ public class TileEntityEnanReactorCore extends TileEntityEnanReactorController { } } - private TileEntityEnanReactorLaser getLaser(final EnumReactorFace reactorFace) { + private TileEntityEnanReactorLaser getLaser(final ReactorFace reactorFace) { final WeakReference weakTileEntityLaser = weakTileEntityLasers[reactorFace.indexStability]; TileEntityEnanReactorLaser tileEntityEnanReactorLaser; if (weakTileEntityLaser != null) { @@ -270,7 +269,7 @@ public class TileEntityEnanReactorCore extends TileEntityEnanReactorController { private boolean shouldExplode() { boolean exploding = false; - for (final EnumReactorFace reactorFace : EnumReactorFace.getLasers(enumTier)) { + for (final ReactorFace reactorFace : ReactorFace.getLasers(enumTier)) { exploding = exploding || (instabilityValues[reactorFace.indexStability] >= 100); } exploding &= (world.rand.nextInt(4) == 2); @@ -278,7 +277,7 @@ public class TileEntityEnanReactorCore extends TileEntityEnanReactorController { if (exploding) { final StringBuilder statusLasers = new StringBuilder(); final MutableBlockPos mutableBlockPos = new MutableBlockPos(); - for (final EnumReactorFace reactorFace : EnumReactorFace.getLasers(enumTier)) { + for (final ReactorFace reactorFace : ReactorFace.getLasers(enumTier)) { long energyStored = -1L; int countLaserMediums = 0; mutableBlockPos.setPos( @@ -396,7 +395,7 @@ public class TileEntityEnanReactorCore extends TileEntityEnanReactorController { // first check if we have the required 'air' blocks boolean isValid = true; - for (final EnumReactorFace reactorFace : EnumReactorFace.get(enumTier)) { + for (final ReactorFace reactorFace : ReactorFace.get(enumTier)) { assert reactorFace.enumTier == enumTier; if (reactorFace.indexStability < 0) { mutableBlockPos.setPos(pos.getX() + reactorFace.x, @@ -417,7 +416,7 @@ public class TileEntityEnanReactorCore extends TileEntityEnanReactorController { } // then update the stabilization lasers accordingly - for (final EnumReactorFace reactorFace : EnumReactorFace.getLasers(enumTier)) { + for (final ReactorFace reactorFace : ReactorFace.getLasers(enumTier)) { mutableBlockPos.setPos(pos.getX() + reactorFace.x, pos.getY() + reactorFace.y, pos.getZ() + reactorFace.z); @@ -426,7 +425,7 @@ public class TileEntityEnanReactorCore extends TileEntityEnanReactorController { if (isValid) { ((TileEntityEnanReactorLaser) tileEntity).setReactorFace(reactorFace, this); } else { - ((TileEntityEnanReactorLaser) tileEntity).setReactorFace(EnumReactorFace.UNKNOWN, null); + ((TileEntityEnanReactorLaser) tileEntity).setReactorFace(ReactorFace.UNKNOWN, null); } } else { final Vector3 vPosition = new Vector3(mutableBlockPos).translate(0.5D); @@ -461,11 +460,13 @@ public class TileEntityEnanReactorCore extends TileEntityEnanReactorController { // computer is alive => start updating reactor hold = false; - final ArrayList result = new ArrayList<>(16); - for (final EnumReactorFace reactorFace : EnumReactorFace.getLasers(enumTier)) { - result.add(reactorFace.indexStability, instabilityValues[reactorFace.indexStability]); + final ReactorFace[] lasers = ReactorFace.getLasers(enumTier); + final Double[] result = new Double[lasers.length]; + for (final ReactorFace reactorFace : lasers) { + final double value = instabilityValues[reactorFace.indexStability]; + result[reactorFace.indexStability] = value; } - return result.toArray(new Double[0]); + return result; } @Override @@ -622,7 +623,7 @@ public class TileEntityEnanReactorCore extends TileEntityEnanReactorController { tagCompound.setInteger("energy", containedEnergy); final NBTTagCompound tagCompoundInstability = new NBTTagCompound(); - for (final EnumReactorFace reactorFace : EnumReactorFace.getLasers(enumTier)) { + for (final ReactorFace reactorFace : ReactorFace.getLasers(enumTier)) { tagCompoundInstability.setDouble(reactorFace.name, instabilityValues[reactorFace.indexStability]); } tagCompound.setTag("instability", tagCompoundInstability); @@ -649,7 +650,7 @@ public class TileEntityEnanReactorCore extends TileEntityEnanReactorController { containedEnergy = tagCompound.getInteger("energy"); final NBTTagCompound tagCompoundInstability = tagCompound.getCompoundTag("instability"); // tier isn't defined yet, so we check all candidates - for (final EnumReactorFace reactorFace : EnumReactorFace.values()) { + for (final ReactorFace reactorFace : ReactorFace.getLasers()) { if (reactorFace.indexStability < 0) { continue; } diff --git a/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorLaser.java b/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorLaser.java index 36a33142..7f6a552e 100644 --- a/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorLaser.java +++ b/src/main/java/cr0s/warpdrive/block/energy/TileEntityEnanReactorLaser.java @@ -6,7 +6,7 @@ import cr0s.warpdrive.api.computer.IEnanReactorLaser; import cr0s.warpdrive.block.TileEntityAbstractLaser; import cr0s.warpdrive.config.WarpDriveConfig; import cr0s.warpdrive.data.BlockProperties; -import cr0s.warpdrive.data.EnumReactorFace; +import cr0s.warpdrive.data.ReactorFace; import cr0s.warpdrive.data.Vector3; import cr0s.warpdrive.network.PacketHandler; @@ -30,7 +30,7 @@ import net.minecraftforge.fml.common.Optional; public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implements IEnanReactorLaser { // persistent properties - private EnumReactorFace reactorFace = EnumReactorFace.UNKNOWN; + private ReactorFace reactorFace = ReactorFace.UNKNOWN; private int energyStabilizationRequest = 0; // computed properties @@ -56,10 +56,10 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen protected void onFirstUpdateTick() { super.onFirstUpdateTick(); - if (reactorFace == EnumReactorFace.UNKNOWN) { + if (reactorFace == ReactorFace.UNKNOWN) { final MutableBlockPos mutableBlockPos = new MutableBlockPos(pos); // laser isn't linked yet, let's try to update nearby reactors - for (final EnumReactorFace reactorFace : EnumReactorFace.values()) { + for (final ReactorFace reactorFace : ReactorFace.getLasers()) { if (reactorFace.indexStability < 0) { continue; } @@ -90,11 +90,11 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen } @Nonnull - public EnumReactorFace getReactorFace() { - return reactorFace != null ? reactorFace : EnumReactorFace.UNKNOWN; + public ReactorFace getReactorFace() { + return reactorFace != null ? reactorFace : ReactorFace.UNKNOWN; } - public void setReactorFace(@Nonnull final EnumReactorFace reactorFace, final TileEntityEnanReactorCore reactorCore) { + public void setReactorFace(@Nonnull final ReactorFace reactorFace, final TileEntityEnanReactorCore reactorCore) { // skip if it's already set to save resources if (this.reactorFace == reactorFace) { return; @@ -102,7 +102,7 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen // update properties this.reactorFace = reactorFace; - this.weakReactorCore = reactorCore != null && reactorFace != EnumReactorFace.UNKNOWN ? new WeakReference<>(reactorCore) : null; + this.weakReactorCore = reactorCore != null && reactorFace != ReactorFace.UNKNOWN ? new WeakReference<>(reactorCore) : null; // refresh blockstate final IBlockState blockState_old = world.getBlockState(pos); @@ -123,7 +123,7 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen } private TileEntityEnanReactorCore getReactorCore() { - if (reactorFace == EnumReactorFace.UNKNOWN) { + if (reactorFace == ReactorFace.UNKNOWN) { return null; } TileEntityEnanReactorCore reactorCore = weakReactorCore != null ? weakReactorCore.get() : null; @@ -208,7 +208,7 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen @Override public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) { tagCompound = super.writeToNBT(tagCompound); - tagCompound.setInteger("reactorFace", reactorFace.ordinal()); + tagCompound.setString("reactorFace", reactorFace.getName()); tagCompound.setInteger("energyStabilizationRequest", energyStabilizationRequest); return tagCompound; } @@ -217,7 +217,7 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen public void readFromNBT(final NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); - reactorFace = EnumReactorFace.get(tagCompound.getInteger("reactorFace")); + reactorFace = ReactorFace.get(tagCompound.getString("reactorFace")); energyStabilizationRequest = tagCompound.getInteger("energyStabilizationRequest"); } @@ -225,7 +225,7 @@ public class TileEntityEnanReactorLaser extends TileEntityAbstractLaser implemen // Common OC/CC methods @Override public Object[] isAssemblyValid() { - if (reactorFace == EnumReactorFace.UNKNOWN) { + if (reactorFace == ReactorFace.UNKNOWN) { return new Object[] { false, "No reactor detected" }; } return super.isAssemblyValid(); diff --git a/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java b/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java index a7463a78..f4b313c8 100644 --- a/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java +++ b/src/main/java/cr0s/warpdrive/config/WarpDriveConfig.java @@ -483,7 +483,7 @@ public class WarpDriveConfig { // Enantiomorphic power reactor public static int[] ENAN_REACTOR_MAX_ENERGY_STORED_BY_TIER = { 100000000, 100000000, 500000000, 2000000000 }; public static final int ENAN_REACTOR_UPDATE_INTERVAL_TICKS = 5; // hardcoded in the equations, - public static int ENAN_REACTOR_MAX_LASERS_PER_SECOND = 6; + public static int[] ENAN_REACTOR_MAX_LASERS_PER_SECOND = { 64, 6, 12, 24 }; public static int[] ENAN_REACTOR_GENERATION_MIN_RF_BY_TIER = { 4, 4, 4, 4 }; public static int[] ENAN_REACTOR_GENERATION_MAX_RF_BY_TIER = { 64000, 64000, 192000, 576000 }; public static int[] ENAN_REACTOR_EXPLOSION_MAX_RADIUS_BY_TIER = { 6, 6, 8, 10 }; @@ -1199,8 +1199,9 @@ public class WarpDriveConfig { ENAN_REACTOR_MAX_ENERGY_STORED_BY_TIER = config.get("enantiomorphic_reactor", "max_energy_stored_by_tier", ENAN_REACTOR_MAX_ENERGY_STORED_BY_TIER, "Maximum energy stored in the core for a given tier").getIntList(); clampByTier(1, Integer.MAX_VALUE, ENAN_REACTOR_MAX_ENERGY_STORED_BY_TIER); - ENAN_REACTOR_MAX_LASERS_PER_SECOND = Commons.clamp(4, 80, - config.get("enantiomorphic_reactor", "max_lasers", ENAN_REACTOR_MAX_LASERS_PER_SECOND, "Maximum number of stabilisation laser shots per seconds before loosing efficiency").getInt()); + ENAN_REACTOR_MAX_LASERS_PER_SECOND = + config.get("enantiomorphic_reactor", "max_lasers", ENAN_REACTOR_MAX_LASERS_PER_SECOND, "Maximum number of stabilisation laser shots per seconds before loosing efficiency").getIntList(); + clampByTier(1, Integer.MAX_VALUE, ENAN_REACTOR_MAX_LASERS_PER_SECOND); ENAN_REACTOR_GENERATION_MIN_RF_BY_TIER = config.get("enantiomorphic_reactor", "min_generation_RF_by_tier", ENAN_REACTOR_GENERATION_MIN_RF_BY_TIER, "Minimum energy added to the core when enabled, measured in RF/t, for a given tier").getIntList(); clampByTier(1, Integer.MAX_VALUE, ENAN_REACTOR_GENERATION_MIN_RF_BY_TIER); diff --git a/src/main/java/cr0s/warpdrive/data/EnumReactorFace.java b/src/main/java/cr0s/warpdrive/data/EnumReactorFace.java deleted file mode 100644 index 75a334d3..00000000 --- a/src/main/java/cr0s/warpdrive/data/EnumReactorFace.java +++ /dev/null @@ -1,153 +0,0 @@ -package cr0s.warpdrive.data; - -import javax.annotation.Nonnull; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map.Entry; - -import net.minecraft.util.EnumFacing; -import net.minecraft.util.IStringSerializable; - -public enum EnumReactorFace implements IStringSerializable { - - // tier inst name x y z facingLaserProperty - UNKNOWN (null , -1, "unknown" , 0, 0, 0, null ), - - BASIC_LASER_SOUTH (EnumTier.BASIC , 0, "laser_south" , 0, 0, -2, EnumFacing.NORTH), - BASIC_LASER_NORTH (EnumTier.BASIC , 1, "laser_north" , 0, 0, 2, EnumFacing.SOUTH), - BASIC_LASER_EAST (EnumTier.BASIC , 2, "laser_east" , -2, 0, 0, EnumFacing.WEST ), - BASIC_LASER_WEST (EnumTier.BASIC , 3, "laser_west" , 2, 0, 0, EnumFacing.EAST ), - BASIC_LENS_NORTH (EnumTier.BASIC , -1, "lens_north" , 0, 0, -1, null ), - BASIC_LENS_SOUTH (EnumTier.BASIC , -1, "lens_south" , 0, 0, 1, null ), - BASIC_LENS_EAST (EnumTier.BASIC , -1, "lens_east" , -1, 0, 0, null ), - BASIC_LENS_WEST (EnumTier.BASIC , -1, "lens_west" , 1, 0, 0, null ), - - ADVANCED_LASER_SOUTH_BOTTOM (EnumTier.ADVANCED, 0, "laser_south" , 1, 2, -3, EnumFacing.NORTH), - ADVANCED_LASER_SOUTH_TOP (EnumTier.ADVANCED, 1, "laser_south" , -1, 4, -3, EnumFacing.NORTH), - ADVANCED_LASER_NORTH_BOTTOM (EnumTier.ADVANCED, 2, "laser_north" , -1, 2, 3, EnumFacing.SOUTH), - ADVANCED_LASER_NORTH_TOP (EnumTier.ADVANCED, 3, "laser_north" , 1, 4, 3, EnumFacing.SOUTH), - ADVANCED_LASER_EAST_BOTTOM (EnumTier.ADVANCED, 4, "laser_east" , -3, 2, -1, EnumFacing.WEST ), - ADVANCED_LASER_EAST_TOP (EnumTier.ADVANCED, 5, "laser_east" , -3, 4, 1, EnumFacing.WEST ), - ADVANCED_LASER_WEST_BOTTOM (EnumTier.ADVANCED, 6, "laser_west" , 3, 2, 1, EnumFacing.EAST ), - ADVANCED_LASER_WEST_TOP (EnumTier.ADVANCED, 7, "laser_west" , 3, 4, -1, EnumFacing.EAST ), - ADVANCED_LENS_SOUTH_BOTTOM (EnumTier.ADVANCED, -1, "lens_south" , 1, 2, -2, null ), - ADVANCED_LENS_SOUTH_TOP (EnumTier.ADVANCED, -1, "lens_south" , -1, 4, -2, null ), - ADVANCED_LENS_NORTH_BOTTOM (EnumTier.ADVANCED, -1, "lens_north" , -1, 2, 2, null ), - ADVANCED_LENS_NORTH_TOP (EnumTier.ADVANCED, -1, "lens_north" , 1, 4, 2, null ), - ADVANCED_LENS_EAST_BOTTOM (EnumTier.ADVANCED, -1, "lens_east" , -2, 2, -1, null ), - ADVANCED_LENS_EAST_TOP (EnumTier.ADVANCED, -1, "lens_east" , -2, 4, 1, null ), - ADVANCED_LENS_WEST_BOTTOM (EnumTier.ADVANCED, -1, "lens_west" , 2, 2, 1, null ), - ADVANCED_LENS_WEST_TOP (EnumTier.ADVANCED, -1, "lens_west" , 2, 4, -1, null ), - ADVANCED_CORE_CENTER (EnumTier.ADVANCED, -1, "core_center" , 0, 3, -1, null ), - ADVANCED_CORE_BOTTOM (EnumTier.ADVANCED, -1, "core_bottom" , 0, 2, 0, null ), - ADVANCED_CORE_TOP (EnumTier.ADVANCED, -1, "core_top" , 0, 4, 0, null ), - ADVANCED_CORE_NORTH (EnumTier.ADVANCED, -1, "core_north" , 0, 3, -1, null ), - ADVANCED_CORE_SOUTH (EnumTier.ADVANCED, -1, "core_south" , 0, 3, 1, null ), - ADVANCED_CORE_EAST (EnumTier.ADVANCED, -1, "core_east" , -1, 3, 0, null ), - ADVANCED_CORE_WEST (EnumTier.ADVANCED, -1, "core_west" , 1, 3, 0, null ), - ADVANCED_SHELL1_BOTTOM_NORTH (EnumTier.ADVANCED, -1, "shell_inner" , 0, 2, -1, null ), - ADVANCED_SHELL1_BOTTOM_SOUTH (EnumTier.ADVANCED, -1, "shell_inner" , 0, 2, 1, null ), - ADVANCED_SHELL1_BOTTOM_EAST (EnumTier.ADVANCED, -1, "shell_inner" , -1, 2, 0, null ), - ADVANCED_SHELL1_BOTTOM_WEST (EnumTier.ADVANCED, -1, "shell_inner" , 1, 2, 0, null ), - ADVANCED_SHELL1_TOP_NORTH (EnumTier.ADVANCED, -1, "shell_inner" , 0, 4, -1, null ), - ADVANCED_SHELL1_TOP_SOUTH (EnumTier.ADVANCED, -1, "shell_inner" , 0, 4, 1, null ), - ADVANCED_SHELL1_TOP_EAST (EnumTier.ADVANCED, -1, "shell_inner" , -1, 4, 0, null ), - ADVANCED_SHELL1_TOP_WEST (EnumTier.ADVANCED, -1, "shell_inner" , 1, 4, 0, null ), - ADVANCED_SHELL1_NORTH_EAST (EnumTier.ADVANCED, -1, "shell_inner" , -1, 3, -1, null ), - ADVANCED_SHELL1_NORTH_WEST (EnumTier.ADVANCED, -1, "shell_inner" , 1, 3, -1, null ), - ADVANCED_SHELL1_SOUTH_EAST (EnumTier.ADVANCED, -1, "shell_inner" , -1, 3, 1, null ), - ADVANCED_SHELL1_SOUTH_WEST (EnumTier.ADVANCED, -1, "shell_inner" , 1, 3, 1, null ), - ADVANCED_SHELL2_BOTTOM (EnumTier.ADVANCED, -1, "shell_outer" , 0, 1, 0, null ), - ADVANCED_SHELL2_TOP (EnumTier.ADVANCED, -1, "shell_outer" , 0, 5, 0, null ), - ADVANCED_SHELL2_NORTH (EnumTier.ADVANCED, -1, "shell_outer" , 0, 3, -2, null ), - ADVANCED_SHELL2_SOUTH (EnumTier.ADVANCED, -1, "shell_outer" , 0, 3, 2, null ), - ADVANCED_SHELL2_EAST (EnumTier.ADVANCED, -1, "shell_outer" , -2, 3, 0, null ), - ADVANCED_SHELL2_WEST (EnumTier.ADVANCED, -1, "shell_outer" , 2, 3, 0, null ), - ADVANCED_SHELL2_BOTTOM_NORTH_EAST (EnumTier.ADVANCED, -1, "shell_outer" , -1, 2, -1, null ), - ADVANCED_SHELL2_BOTTOM_NORTH_WEST (EnumTier.ADVANCED, -1, "shell_outer" , 1, 2, -1, null ), - ADVANCED_SHELL2_BOTTOM_SOUTH_EAST (EnumTier.ADVANCED, -1, "shell_outer" , -1, 2, 1, null ), - ADVANCED_SHELL2_BOTTOM_SOUTH_WEST (EnumTier.ADVANCED, -1, "shell_outer" , 1, 2, 1, null ), - ADVANCED_SHELL2_TOP_NORTH_EAST (EnumTier.ADVANCED, -1, "shell_outer" , -1, 4, -1, null ), - ADVANCED_SHELL2_TOP_NORTH_WEST (EnumTier.ADVANCED, -1, "shell_outer" , 1, 4, -1, null ), - ADVANCED_SHELL2_TOP_SOUTH_EAST (EnumTier.ADVANCED, -1, "shell_outer" , -1, 4, 1, null ), - ADVANCED_SHELL2_TOP_SOUTH_WEST (EnumTier.ADVANCED, -1, "shell_outer" , 1, 4, 1, null ), - ; - - public final EnumTier enumTier; - public final int indexStability; - public final String name; - public final int x; - public final int y; - public final int z; - public final EnumFacing facingLaserProperty; - - // cached values - public static final int length; - public static final int maxInstabilities; - private static final HashMap ID_MAP = new HashMap<>(); - private static final HashMap TIER_ALL = new HashMap<>(EnumTier.length); - private static final HashMap TIER_LASERS = new HashMap<>(EnumTier.length); - - static { - length = EnumReactorFace.values().length; - for (final EnumReactorFace reactorFace : values()) { - ID_MAP.put(reactorFace.ordinal(), reactorFace); - } - - // pre-build the list of lasers in the structure - final HashMap> tierAll = new HashMap<>(EnumTier.length); - final HashMap> tierLasers = new HashMap<>(EnumTier.length); - for (final EnumTier tierLoop : EnumTier.values()) { - tierAll.put(tierLoop, new ArrayList<>(16)); - tierLasers.put(tierLoop, new ArrayList<>(16)); - } - for (final EnumReactorFace reactorFace : values()) { - if (reactorFace.enumTier == null) { - continue; - } - tierAll.get(reactorFace.enumTier).add(reactorFace); - if (reactorFace.indexStability >= 0) { - tierLasers.get(reactorFace.enumTier).add(reactorFace); - } - } - for (final Entry> entry : tierAll.entrySet()) { - TIER_ALL.put(entry.getKey(), entry.getValue().toArray(new EnumReactorFace[0])); - } - int max = 0; - for (final Entry> entry : tierLasers.entrySet()) { - TIER_LASERS.put(entry.getKey(), entry.getValue().toArray(new EnumReactorFace[0])); - max = Math.max(max, entry.getValue().size()); - } - maxInstabilities = max; - } - - EnumReactorFace(final EnumTier enumTier, final int indexStability, final String name, - final int x, final int y, final int z, - final EnumFacing facingLaserProperty) { - this.enumTier = enumTier; - this.indexStability = indexStability; - this.name = name; - this.x = x; - this.y = y; - this.z = z; - this.facingLaserProperty = facingLaserProperty; - } - - public static EnumReactorFace[] get(final EnumTier tier) { - return TIER_ALL.get(tier); - } - - public static EnumReactorFace[] getLasers(final EnumTier tier) { - return TIER_LASERS.get(tier); - } - - @Nonnull - @Override - public String getName() { - return name; - } - - public static EnumReactorFace get(final int ordinal) { - return ID_MAP.get(ordinal); - } -} diff --git a/src/main/java/cr0s/warpdrive/data/ReactorFace.java b/src/main/java/cr0s/warpdrive/data/ReactorFace.java new file mode 100644 index 00000000..72e4fbff --- /dev/null +++ b/src/main/java/cr0s/warpdrive/data/ReactorFace.java @@ -0,0 +1,179 @@ +package cr0s.warpdrive.data; + +import javax.annotation.Nonnull; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map.Entry; + +import net.minecraft.util.EnumFacing; +import net.minecraft.util.IStringSerializable; + +public class ReactorFace implements IStringSerializable { + + public static final ReactorFace UNKNOWN; + + public final EnumTier enumTier; + public final int indexStability; // >= 0 for lasers, -1 otherwise + public final String name; // non null + public final int x; + public final int y; + public final int z; + public final EnumFacing facingLaserProperty; // defined for laser, null otherwise + + // cached values + public static final int maxInstabilities; + private static final HashMap NAME_MAP = new HashMap<>(); + private static final HashMap FACES_BY_TIER; + private static final HashMap LASERS_BY_TIER; + private static final ReactorFace[] LASERS; + + static { + UNKNOWN = new ReactorFace(null, -1, "unknown", 0, 0, 0, null); + + // basic reactor has core for core + new ReactorFace(EnumTier.BASIC , 0, "laser.basic.south" , 0, 0, -2, EnumFacing.NORTH); + new ReactorFace(EnumTier.BASIC , 1, "laser.basic.north" , 0, 0, 2, EnumFacing.SOUTH); + new ReactorFace(EnumTier.BASIC , 2, "laser.basic.east" , -2, 0, 0, EnumFacing.WEST ); + new ReactorFace(EnumTier.BASIC , 3, "laser.basic.west" , 2, 0, 0, EnumFacing.EAST ); + + // advanced reactor has core offset with small radius + new ReactorFace(EnumTier.ADVANCED, 0, "laser.advanced.south+" , 1, 2, -3, EnumFacing.NORTH); + new ReactorFace(EnumTier.ADVANCED, 1, "laser.advanced.south-" , -1, 4, -3, EnumFacing.NORTH); + new ReactorFace(EnumTier.ADVANCED, 2, "laser.advanced.north-" , -1, 2, 3, EnumFacing.SOUTH); + new ReactorFace(EnumTier.ADVANCED, 3, "laser.advanced.north+" , 1, 4, 3, EnumFacing.SOUTH); + new ReactorFace(EnumTier.ADVANCED, 4, "laser.advanced.east-" , -3, 2, -1, EnumFacing.WEST ); + new ReactorFace(EnumTier.ADVANCED, 5, "laser.advanced.east+" , -3, 4, 1, EnumFacing.WEST ); + new ReactorFace(EnumTier.ADVANCED, 6, "laser.advanced.west+" , 3, 2, 1, EnumFacing.EAST ); + new ReactorFace(EnumTier.ADVANCED, 7, "laser.advanced.west-" , 3, 4, -1, EnumFacing.EAST ); + addCoreBlocks(EnumTier.ADVANCED, 1, 0, 3, 0); + + // superior reactor has core offset with larger radius + new ReactorFace(EnumTier.SUPERIOR, 0, "laser.superior.south+" , 1, 3, -4, EnumFacing.NORTH); + new ReactorFace(EnumTier.SUPERIOR, 1, "laser.superior.south-" , -1, 5, -4, EnumFacing.NORTH); + new ReactorFace(EnumTier.SUPERIOR, 2, "laser.superior.north-" , -1, 3, 4, EnumFacing.SOUTH); + new ReactorFace(EnumTier.SUPERIOR, 3, "laser.superior.north+" , 1, 5, 4, EnumFacing.SOUTH); + new ReactorFace(EnumTier.SUPERIOR, 4, "laser.superior.east-" , -4, 3, -1, EnumFacing.WEST ); + new ReactorFace(EnumTier.SUPERIOR, 5, "laser.superior.east+" , -4, 5, 1, EnumFacing.WEST ); + new ReactorFace(EnumTier.SUPERIOR, 6, "laser.superior.west+" , 4, 3, 1, EnumFacing.EAST ); + new ReactorFace(EnumTier.SUPERIOR, 7, "laser.superior.west-" , 4, 5, -1, EnumFacing.EAST ); + + new ReactorFace(EnumTier.SUPERIOR, 8, "laser.superior.south--" , -2, 2, -4, EnumFacing.NORTH); + new ReactorFace(EnumTier.SUPERIOR, 9, "laser.superior.south++" , 2, 6, -4, EnumFacing.NORTH); + new ReactorFace(EnumTier.SUPERIOR, 10, "laser.superior.north++" , 2, 2, 4, EnumFacing.SOUTH); + new ReactorFace(EnumTier.SUPERIOR, 11, "laser.superior.north--" , -2, 6, 4, EnumFacing.SOUTH); + new ReactorFace(EnumTier.SUPERIOR, 12, "laser.superior.east++" , -4, 2, 2, EnumFacing.WEST ); + new ReactorFace(EnumTier.SUPERIOR, 13, "laser.superior.east--" , -4, 6, -2, EnumFacing.WEST ); + new ReactorFace(EnumTier.SUPERIOR, 14, "laser.superior.west--" , 4, 2, -2, EnumFacing.EAST ); + new ReactorFace(EnumTier.SUPERIOR, 15, "laser.superior.west++" , 4, 6, 2, EnumFacing.EAST ); + addCoreBlocks(EnumTier.SUPERIOR, 2, 0, 4, 0); + + // pre-build the list of lasers in the structure + final HashMap> facesByTiers = new HashMap<>(EnumTier.length); + final HashMap> lasersByTiers = new HashMap<>(EnumTier.length); + for (final EnumTier tierLoop : EnumTier.values()) { + facesByTiers.put(tierLoop, new ArrayList<>(16)); + lasersByTiers.put(tierLoop, new ArrayList<>(16)); + } + for (final ReactorFace reactorFace : NAME_MAP.values()) { + if (reactorFace.enumTier == null) { + continue; + } + facesByTiers.get(reactorFace.enumTier).add(reactorFace); + if (reactorFace.indexStability >= 0) { + lasersByTiers.get(reactorFace.enumTier).add(reactorFace); + } + } + FACES_BY_TIER = new HashMap<>(EnumTier.length); + for (final Entry> entry : facesByTiers.entrySet()) { + FACES_BY_TIER.put(entry.getKey(), entry.getValue().toArray(new ReactorFace[0])); + } + int max = 0; + LASERS_BY_TIER = new HashMap<>(EnumTier.length); + final ArrayList lasers = new ArrayList<>(32); + for (final Entry> entry : lasersByTiers.entrySet()) { + LASERS_BY_TIER.put(entry.getKey(), entry.getValue().toArray(new ReactorFace[0])); + lasers.addAll(entry.getValue()); + max = Math.max(max, entry.getValue().size()); + } + LASERS = lasers.toArray(new ReactorFace[0]); + maxInstabilities = max; + } + + private static void addCoreBlocks(final EnumTier enumTier, final int radius, final int xOffset, final int yOffset, final int zOffset) { + // square radius from center of block + final double sqRadiusHigh = (radius + 0.5D) * (radius + 0.5D); + + // sphere + final int radiusCeil = radius + 1; + + // Pass the cube and check points for sphere equation x^2 + y^2 + z^2 = r^2 + for (int x = -radiusCeil; x <= radiusCeil; x++) { + final double x2 = (x + 0.5D) * (x + 0.5D); + for (int y = -radiusCeil; y <= radiusCeil; y++) { + final double x2y2 = x2 + (y + 0.5D) * (y + 0.5D); + for (int z = -radiusCeil; z <= radiusCeil; z++) { + final double sqRange = x2y2 + (z + 0.5D) * (z + 0.5D); // Square distance from current position to center + + // Skip too far blocks + if (sqRange > sqRadiusHigh) { + continue; + } + new ReactorFace(enumTier, + -1, + String.format("core.%s.[%d,%d,%d]", enumTier.getName(), x, y, z), + xOffset + x, yOffset + y, zOffset + z, + null); + } + } + } + } + + ReactorFace(final EnumTier enumTier, final int indexStability, final String name, + final int x, final int y, final int z, + final EnumFacing facingLaserProperty) { + this.enumTier = enumTier; + this.indexStability = indexStability; + this.name = name; + this.x = x; + this.y = y; + this.z = z; + this.facingLaserProperty = facingLaserProperty; + + // register + NAME_MAP.put(name, this); + + // add lens + if (facingLaserProperty != null) { + new ReactorFace(enumTier, -1, name + ".lens", + x - facingLaserProperty.getXOffset(), + y - facingLaserProperty.getYOffset(), + z - facingLaserProperty.getZOffset(), + null); + } + } + + @Nonnull + public static ReactorFace[] get(@Nonnull final EnumTier tier) { + return FACES_BY_TIER.get(tier); + } + + @Nonnull + public static ReactorFace[] getLasers() { + return LASERS; + } + + @Nonnull + public static ReactorFace[] getLasers(@Nonnull final EnumTier tier) { + return LASERS_BY_TIER.get(tier); + } + + @Nonnull + @Override + public String getName() { + return name; + } + + public static ReactorFace get(final String name) { + return NAME_MAP.get(name); + } +} diff --git a/src/main/resources/assets/warpdrive/lua.ComputerCraft/warpdriveEnanReactorCore/startup b/src/main/resources/assets/warpdrive/lua.ComputerCraft/warpdriveEnanReactorCore/startup index 5f318372..ad429101 100644 --- a/src/main/resources/assets/warpdrive/lua.ComputerCraft/warpdriveEnanReactorCore/startup +++ b/src/main/resources/assets/warpdrive/lua.ComputerCraft/warpdriveEnanReactorCore/startup @@ -108,7 +108,7 @@ function reactor_page() local instabilities = { reactor.getInstabilities() } for key, instability in pairs(instabilities) do local y = (key - 1) % 4 - local x = (key - y - 1) / 4 + local x = (key - 1 - y) / 4 w.setCursorPos(2 + 6 * x, 3 + y) local stability = math.floor((100.0 - instability) * 10) / 10.0 if stability >= reactor_targetStability then @@ -136,7 +136,7 @@ function reactor_page() w.write(w.format_boolean(isEnabled, "YES", "no")) end - w.setCursorPos(26, 2) + w.setCursorPos(28, 2) if #reactorlasers == 0 then w.setColorDisabled() w.write("Lasers not detected") @@ -144,11 +144,11 @@ function reactor_page() w.setColorNormal() w.write("Lasers charge (k)") - for key, reactorlaser in pairs(reactorlasers) do + for _, reactorlaser in pairs(reactorlasers) do if reactorlaser.wrap ~= nil then - local y = (key - 1) % 4 - local x = (key - y - 1) / 4 - w.setCursorPos(26 + 7 * x, 3 + y) + local y = reactorlaser.side % 4 + local x = (reactorlaser.side - y) / 4 + w.setCursorPos(28 + 6 * x, 3 + y) local energyStored, _, _ = reactorlaser.wrap.getEnergyStatus() if energyStored == nil then energyStored = -1 @@ -259,7 +259,7 @@ function reactor_pulse(output) if w.page_getCallbackDisplay() == reactor_page and (not reactor_configPageLoaded) then for key, instability in pairs(instabilities) do local y = (key - 1) % 4 - local x = (key - y - 1) / 4 + local x = (key - 1 - y) / 4 w.setCursorPos(2 + 6 * x, 3 + y) local stability = math.floor((100.0 - instability) * 10) / 10 if stability >= reactor_targetStability then @@ -270,7 +270,7 @@ function reactor_pulse(output) w.write(w.format_float(stability, 5)) end - local energyStored, energyMax, energyUnits, _, energyOutputRate = reactor.getEnergyStatus() + local energyStored, _, _, _, energyOutputRate = reactor.getEnergyStatus() w.setCursorPos(12, 7) w.setColorNormal() w.write(w.format_integer(energyStored, 10)) @@ -280,11 +280,11 @@ function reactor_pulse(output) w.write(w.format_integer(energyOutputRate, 6)) if #reactorlasers ~= 0 then - for key, reactorlaser in pairs(reactorlasers) do - if key ~= nil and reactorlaser.wrap ~= nil then - local y = (key - 1) % 4 - local x = (key - y - 1) / 4 - w.setCursorPos(26 + 7 * x, 3 + y) + for _, reactorlaser in pairs(reactorlasers) do + if reactorlaser.wrap ~= nil then + local y = reactorlaser.side % 4 + local x = (reactorlaser.side - y) / 4 + w.setCursorPos(28 + 6 * x, 3 + y) local energyStored, _, _ = reactorlaser.wrap.getEnergyStatus() if energyStored == nil then energyStored = -1 diff --git a/src/main/resources/assets/warpdrive/lua.OpenComputers/warpdriveEnanReactorCore/startup b/src/main/resources/assets/warpdrive/lua.OpenComputers/warpdriveEnanReactorCore/startup index cff1ab54..b58eade2 100644 --- a/src/main/resources/assets/warpdrive/lua.OpenComputers/warpdriveEnanReactorCore/startup +++ b/src/main/resources/assets/warpdrive/lua.OpenComputers/warpdriveEnanReactorCore/startup @@ -107,7 +107,7 @@ function reactor_page() local instabilities = { reactor.getInstabilities() } for key, instability in pairs(instabilities) do local y = (key - 1) % 4 - local x = (key - y - 1) / 4 + local x = (key - 1 - y) / 4 w.setCursorPos(2 + 6 * x, 3 + y) local stability = math.floor((100.0 - instability) * 10) / 10.0 if stability >= reactor_targetStability then @@ -135,7 +135,7 @@ function reactor_page() w.write(w.format_boolean(isEnabled, "YES", "no")) end - w.setCursorPos(26, 2) + w.setCursorPos(28, 2) if #reactorlasers == 0 then w.setColorDisabled() w.write("Lasers not detected") @@ -143,11 +143,11 @@ function reactor_page() w.setColorNormal() w.write("Lasers charge (k)") - for key, reactorlaser in pairs(reactorlasers) do + for _, reactorlaser in pairs(reactorlasers) do if reactorlaser.wrap ~= nil then - local y = (key - 1) % 4 - local x = (key - y - 1) / 4 - w.setCursorPos(26 + 7 * x, 3 + y) + local y = reactorlaser.side % 4 + local x = (reactorlaser.side - y) / 4 + w.setCursorPos(28 + 6 * x, 3 + y) local energyStored, _, _ = reactorlaser.wrap.getEnergyStatus() if energyStored == nil then energyStored = -1 @@ -260,7 +260,7 @@ function reactor_pulse(output) if w.page_getCallbackDisplay() == reactor_page and (not reactor_configPageLoaded) then for key, instability in pairs(instabilities) do local y = (key - 1) % 4 - local x = (key - y - 1) / 4 + local x = (key - 1 - y) / 4 w.setCursorPos(2 + 6 * x, 3 + y) local stability = math.floor((100.0 - instability) * 10) / 10 if stability >= reactor_targetStability then @@ -283,11 +283,11 @@ function reactor_pulse(output) end if #reactorlasers ~= 0 then - for key, reactorlaser in pairs(reactorlasers) do - if reactor_pulseStep == key and reactorlaser.wrap ~= nil then - local y = (key - 1) % 4 - local x = (key - y - 1) / 4 - w.setCursorPos(26 + 7 * x, 3 + y) + for _, reactorlaser in pairs(reactorlasers) do + if reactorlaser.wrap ~= nil and reactor_pulseStep == key then + local y = reactorlaser.side % 4 + local x = (reactorlaser.side - y) / 4 + w.setCursorPos(28 + 6 * x, 3 + y) local energyStored, _, _ = reactorlaser.wrap.getEnergyStatus() if energyStored == nil then energyStored = -1