diff --git a/src/main/java/cr0s/warpdrive/block/atomic/TileEntityAcceleratorControlPoint.java b/src/main/java/cr0s/warpdrive/block/atomic/TileEntityAcceleratorControlPoint.java index 35b8d041..e5f3da15 100644 --- a/src/main/java/cr0s/warpdrive/block/atomic/TileEntityAcceleratorControlPoint.java +++ b/src/main/java/cr0s/warpdrive/block/atomic/TileEntityAcceleratorControlPoint.java @@ -22,7 +22,7 @@ import cpw.mods.fml.common.Optional; public class TileEntityAcceleratorControlPoint extends TileEntityAbstractInterfaced implements IControlChannel { // persistent properties - public boolean isEnabled = true; + private boolean isEnabled = true; private int controlChannel = -1; // computed properties @@ -56,14 +56,13 @@ public class TileEntityAcceleratorControlPoint extends TileEntityAbstractInterfa updateTicks--; if (updateTicks <= 0) { updateTicks = UPDATE_INTERVAL_TICKS; - updateMetadata((controlChannel == -1) ? 0 : 1); + updateMetadata((controlChannel == -1) || !isEnabled ? 0 : 1); } } @Override public void invalidate() { super.invalidate(); - // @TODO } @Override @@ -72,9 +71,9 @@ public class TileEntityAcceleratorControlPoint extends TileEntityAbstractInterfa } @Override - public void setControlChannel(int parVideoChannel) { - if (controlChannel != parVideoChannel) { - controlChannel = parVideoChannel; + public void setControlChannel(final int controlChannel) { + if (this.controlChannel != controlChannel) { + this.controlChannel = controlChannel; if (WarpDriveConfig.LOGGING_VIDEO_CHANNEL) { WarpDrive.logger.info(this + " Accelerator control point controlChannel channel set to " + controlChannel); } @@ -126,6 +125,15 @@ public class TileEntityAcceleratorControlPoint extends TileEntityAbstractInterfa readFromNBT(tagCompound); } + public boolean getIsEnabled() { + return isEnabled; + } + + public void setIsEnabled(final boolean isEnabled) { + this.isEnabled = isEnabled; + WarpDrive.starMap.onBlockUpdated(worldObj, xCoord, yCoord, zCoord, getBlockType(), getBlockMetadata()); + } + // OpenComputer callback methods @Callback @Optional.Method(modid = "OpenComputers") @@ -160,7 +168,7 @@ public class TileEntityAcceleratorControlPoint extends TileEntityAbstractInterfa } return new Object[] { isEnabled }; } - isEnabled = enable; + setIsEnabled(enable); } return new Object[] { isEnabled }; } diff --git a/src/main/java/cr0s/warpdrive/data/AcceleratorControlParameter.java b/src/main/java/cr0s/warpdrive/data/AcceleratorControlParameter.java new file mode 100644 index 00000000..095e8ffb --- /dev/null +++ b/src/main/java/cr0s/warpdrive/data/AcceleratorControlParameter.java @@ -0,0 +1,68 @@ +package cr0s.warpdrive.data; + +import cr0s.warpdrive.api.IControlChannel; +import cr0s.warpdrive.block.atomic.TileEntityAcceleratorController; + +import net.minecraft.nbt.NBTTagCompound; + +public class AcceleratorControlParameter { + + // persistent properties + public int controlChannel; // final + public boolean isEnabled = true; + public double threshold = TileEntityAcceleratorController.ACCELERATOR_THRESHOLD_DEFAULT; + public String description = "-"; + + public AcceleratorControlParameter(final int controlChannel) { + this.controlChannel = controlChannel; + } + + public AcceleratorControlParameter(final NBTTagCompound nbtTagCompound) { + readFromNBT(nbtTagCompound); + } + + private void readFromNBT(final NBTTagCompound nbtTagCompound) { + controlChannel = nbtTagCompound.getInteger(IControlChannel.CONTROL_CHANNEL_TAG); + isEnabled = nbtTagCompound.getBoolean("isEnabled"); + threshold = nbtTagCompound.getDouble("threshold"); + description = nbtTagCompound.getString("description"); + } + + public NBTTagCompound writeToNBT(final NBTTagCompound nbtTagCompound) { + nbtTagCompound.setInteger(IControlChannel.CONTROL_CHANNEL_TAG, controlChannel); + nbtTagCompound.setBoolean("isEnabled", isEnabled); + nbtTagCompound.setDouble("threshold", threshold); + nbtTagCompound.setString("description", description); + return nbtTagCompound; + } + + // Hash based collections need a stable hashcode, so we use a unique id instead + @Override + public int hashCode() { + return controlChannel; + } + + @Override + public boolean equals(Object object) { + if (object instanceof AcceleratorControlParameter) { + AcceleratorControlParameter acceleratorControlParameter = (AcceleratorControlParameter) object; + return controlChannel == acceleratorControlParameter.controlChannel + && isEnabled == acceleratorControlParameter.isEnabled + && threshold == acceleratorControlParameter.threshold + && description.equals(acceleratorControlParameter.description); + } + + return false; + } + + + @Override + public String toString() { + return String.format("%s/%d isEnabled %s threshold %.3f '%s'", + getClass().getSimpleName(), + controlChannel, + isEnabled, + threshold, + description); + } +} diff --git a/src/main/java/cr0s/warpdrive/data/AcceleratorSetup.java b/src/main/java/cr0s/warpdrive/data/AcceleratorSetup.java index 5818703c..89d54207 100644 --- a/src/main/java/cr0s/warpdrive/data/AcceleratorSetup.java +++ b/src/main/java/cr0s/warpdrive/data/AcceleratorSetup.java @@ -12,6 +12,7 @@ import cr0s.warpdrive.block.atomic.BlockParticlesCollider; import cr0s.warpdrive.block.atomic.BlockParticlesInjector; import cr0s.warpdrive.block.atomic.BlockVoidShellPlain; import cr0s.warpdrive.block.atomic.TileEntityAcceleratorControlPoint; +import cr0s.warpdrive.block.atomic.TileEntityAcceleratorController; import cr0s.warpdrive.block.atomic.TileEntityParticlesInjector; import cr0s.warpdrive.block.energy.BlockEnergyBank; import cr0s.warpdrive.block.energy.TileEntityEnergyBank; @@ -66,6 +67,7 @@ public class AcceleratorSetup extends GlobalPosition { // increase with tier (0.25 > 1.0 > 4.0) // increase with number of cooling vents + public double temperatureTarget_K; public double[] temperatures_cooling_K_perTick = new double[3]; public double temperature_coolingEnergyCost_perTick; public double[] temperatures_sustainEnergyCost_perTick = new double[3]; @@ -112,13 +114,13 @@ public class AcceleratorSetup extends GlobalPosition { } // add the vector with it's surrounding block so we can catch 'added' blocks - private void addToBoundingBox(final VectorI vector) { - vMin.x = Math.min(vMin.x, vector.x - 1); - vMin.y = Math.min(vMin.y, vector.y - 1); - vMin.z = Math.min(vMin.z, vector.z - 1); - vMax.x = Math.max(vMax.x, vector.x + 1); - vMax.y = Math.max(vMax.y, vector.y + 1); - vMax.z = Math.max(vMax.z, vector.z + 1); + private void addToBoundingBox(final VectorI vector, final int range) { + vMin.x = Math.min(vMin.x, vector.x - range); + vMin.y = Math.min(vMin.y, vector.y - range); + vMin.z = Math.min(vMin.z, vector.z - range); + vMax.x = Math.max(vMax.x, vector.x + range); + vMax.y = Math.max(vMax.y, vector.y + range); + vMax.z = Math.max(vMax.z, vector.z + range); } private void refresh() { @@ -145,7 +147,10 @@ public class AcceleratorSetup extends GlobalPosition { computeVectorArrays(world); // compute values - double coolingFactor = 10.0 / (countMagnets[0] + countMagnets[1] + countMagnets[2]); + final int indexHighest = countMagnets[2] > 0 ? 2 : countMagnets[1] > 0 ? 1 : 0; + temperatureTarget_K = TileEntityAcceleratorController.ACCELERATOR_TEMPERATURES_K[indexHighest]; + + final double coolingFactor = 10.0 / (countMagnets[0] + countMagnets[1] + countMagnets[2]); temperatures_cooling_K_perTick[0] = (countChillers[0] * 1.00 + countChillers[1] * 0.75 + countChillers[2] * 0.5) * coolingFactor; temperatures_cooling_K_perTick[1] = (countChillers[1] * 1.00 + countChillers[2] * 0.75) * coolingFactor; temperatures_cooling_K_perTick[2] = (countChillers[2] * 1.00) * coolingFactor; @@ -278,7 +283,7 @@ public class AcceleratorSetup extends GlobalPosition { vMax = trajectoryPoint.getVectorI(); isFirst = false; } - addToBoundingBox(trajectoryPoint); + addToBoundingBox(trajectoryPoint, 2); // count main magnets int indexTier = trajectoryPoint.type & TrajectoryPoint.MASK_TIERS - 1; @@ -309,21 +314,21 @@ public class AcceleratorSetup extends GlobalPosition { if (blockForward instanceof BlockParticlesInjector) { final int controlChannel = ((TileEntityParticlesInjector) vectorToAdd.getTileEntity(world)).getControlChannel(); mapInjectors.put(controlChannel, vectorToAdd); - addToBoundingBox(vectorToAdd); + addToBoundingBox(vectorToAdd, 1); } else { vectorToAdd = trajectoryPoint.clone(trajectoryPoint.directionBackward.getOpposite()); Block blockBackward = vectorToAdd.getBlock(world); if (blockBackward instanceof BlockParticlesInjector) { final int controlChannel = ((TileEntityParticlesInjector) vectorToAdd.getTileEntity(world)).getControlChannel(); mapInjectors.put(controlChannel, vectorToAdd); - addToBoundingBox(vectorToAdd); + addToBoundingBox(vectorToAdd, 1); } } // collect control points and colliders if (trajectoryPoint.vControlPoint != null) { controlPoints.put(trajectoryPoint.vControlPoint, trajectoryPoint.type); - addToBoundingBox(trajectoryPoint.vControlPoint); + addToBoundingBox(trajectoryPoint.vControlPoint, 1); if (trajectoryPoint.isCollider()) { listColliders.add(trajectoryPoint); } @@ -539,31 +544,6 @@ public class AcceleratorSetup extends GlobalPosition { } // Pseudo-API for computers - public int enableControlPoints(final IBlockAccess world, final int controlChannel, final boolean isEnabled) { - int count = 0; - for (final Entry entryControlPoint : controlPoints.entrySet()) { - final TileEntity tileEntity = entryControlPoint.getKey().getTileEntity(world); - if ( tileEntity instanceof TileEntityAcceleratorControlPoint - && ((TileEntityAcceleratorControlPoint) tileEntity).getControlChannel() == controlChannel ) { - if (isEnabled != ((TileEntityAcceleratorControlPoint) tileEntity).isEnabled) { - count++; - ((TileEntityAcceleratorControlPoint) tileEntity).isEnabled = isEnabled; - } - } - } - for (final Entry entryControlPoint : mapInjectors.entrySet()) { - final TileEntity tileEntity = entryControlPoint.getValue().getTileEntity(world); - if ( tileEntity instanceof TileEntityParticlesInjector - && ((TileEntityParticlesInjector) tileEntity).getControlChannel() == controlChannel ) { - if (isEnabled != ((TileEntityParticlesInjector) tileEntity).isEnabled) { - count++; - ((TileEntityParticlesInjector) tileEntity).isEnabled = isEnabled; - } - } - } - return count; - } - public Object[][] getControlPoints(final IBlockAccess world) { final Object[][] objectResults = new Object[controlPoints.size() + keyInjectors.length][]; int index = 0; @@ -573,7 +553,7 @@ public class AcceleratorSetup extends GlobalPosition { TrajectoryPoint.isOutput(entryControlPoint.getValue()) ? "Output" : TrajectoryPoint.isInput(entryControlPoint.getValue()) ? "Input" : "?"; final TileEntity tileEntity = entryControlPoint.getKey().getTileEntity(world); - final Boolean isEnabled = (tileEntity instanceof TileEntityAcceleratorControlPoint) && ((TileEntityAcceleratorControlPoint) tileEntity).isEnabled; + final Boolean isEnabled = (tileEntity instanceof TileEntityAcceleratorControlPoint) && ((TileEntityAcceleratorControlPoint) tileEntity).getIsEnabled(); final Integer controlChannel = (tileEntity instanceof IControlChannel) ? ((IControlChannel) tileEntity).getControlChannel() : -1; objectResults[index++] = new Object[] { @@ -584,7 +564,7 @@ public class AcceleratorSetup extends GlobalPosition { final Integer tier = 1; final String type = "Injector"; final TileEntity tileEntity = entryControlPoint.getValue().getTileEntity(world); - final Boolean isEnabled = (tileEntity instanceof TileEntityParticlesInjector) && ((TileEntityParticlesInjector) tileEntity).isEnabled; + final Boolean isEnabled = (tileEntity instanceof TileEntityParticlesInjector) && ((TileEntityParticlesInjector) tileEntity).getIsEnabled(); final Integer controlChannel = (tileEntity instanceof IControlChannel) ? ((IControlChannel) tileEntity).getControlChannel() : -1; objectResults[index++] = new Object[] { diff --git a/src/main/java/cr0s/warpdrive/data/StarMapRegistry.java b/src/main/java/cr0s/warpdrive/data/StarMapRegistry.java index 48347c81..9020cbfb 100644 --- a/src/main/java/cr0s/warpdrive/data/StarMapRegistry.java +++ b/src/main/java/cr0s/warpdrive/data/StarMapRegistry.java @@ -238,9 +238,10 @@ public class StarMapRegistry { double dZ = entry.z - tileEntity.zCoord; double distance2 = dX * dX + dY * dY + dZ * dZ; - if (distance2 <= radius2 - && (entry.isolationRate == 0.0D || tileEntity.getWorldObj().rand.nextDouble() >= entry.isolationRate) - && (entry.getSpaceCoordinates() != null)) { + if ( distance2 <= radius2 + && (entry.isolationRate == 0.0D || tileEntity.getWorldObj().rand.nextDouble() >= entry.isolationRate) + && (entry.getSpaceCoordinates() != null) + && (entry.type != EnumStarMapEntryType.ACCELERATOR) ) { starMapRegistryItems.add(entry); } } diff --git a/src/main/java/cr0s/warpdrive/data/TrajectoryPoint.java b/src/main/java/cr0s/warpdrive/data/TrajectoryPoint.java index 2f52a0d2..56ddc68e 100644 --- a/src/main/java/cr0s/warpdrive/data/TrajectoryPoint.java +++ b/src/main/java/cr0s/warpdrive/data/TrajectoryPoint.java @@ -8,6 +8,7 @@ import cr0s.warpdrive.block.atomic.BlockVoidShellPlain; import cr0s.warpdrive.block.atomic.TileEntityAcceleratorControlPoint; import net.minecraft.block.Block; +import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; @@ -49,8 +50,8 @@ public class TrajectoryPoint extends VectorI { public static final int ERROR_MISSING_MAIN_MAGNET = 0x00080000; // missing main magnets at control point public static final int ERROR_MISSING_CORNER_MAGNET = 0x00100000; // missing corner magnets at control point public static final int ERROR_MISSING_COLLIDER = 0x00200000; - public static final int ERROR_MISSING_VOID_SHELL = 0x00400000; // too many void shells - public static final int ERROR_TOO_MANY_VOID_SHELLS = 0x00800000; // not enough void shells + public static final int ERROR_MISSING_VOID_SHELL = 0x00400000; + public static final int ERROR_TOO_MANY_VOID_SHELLS = 0x00800000; // public static final int ERROR_OUT_OF_RANGE = 0x01000000; // public static final int ERROR_TBD2 = 0x02000000; // public static final int ERROR_TBD4 = 0x04000000; @@ -149,19 +150,29 @@ public class TrajectoryPoint extends VectorI { int new_controlChannel = -1; if (isShellValid) { for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { - Block block = world.getBlock( - x + 2 * direction.offsetX, - y + 2 * direction.offsetY, - z + 2 * direction.offsetZ); - if (block instanceof BlockAcceleratorControlPoint && !(block instanceof BlockParticlesInjector)) { - if ((typeNew & MASK_MAGNETS_BOTH) == 0) { - typeNew |= ERROR_MISSING_MAIN_MAGNET; - } else { - new_vControlPoint = new VectorI( + final Block block = world.getBlock( + x + 2 * direction.offsetX, + y + 2 * direction.offsetY, + z + 2 * direction.offsetZ); + + if ( block instanceof BlockAcceleratorControlPoint + && !(block instanceof BlockParticlesInjector) ) { + final TileEntity tileEntity = world.getTileEntity( x + 2 * direction.offsetX, y + 2 * direction.offsetY, z + 2 * direction.offsetZ); - new_controlChannel = ((TileEntityAcceleratorControlPoint) new_vControlPoint.getTileEntity(world)).getControlChannel(); + + if ( tileEntity instanceof TileEntityAcceleratorControlPoint + && ((TileEntityAcceleratorControlPoint) tileEntity).getIsEnabled()) { + if ((typeNew & MASK_MAGNETS_BOTH) == 0) { + typeNew |= ERROR_MISSING_MAIN_MAGNET; + } else { + new_vControlPoint = new VectorI( + x + 2 * direction.offsetX, + y + 2 * direction.offsetY, + z + 2 * direction.offsetZ); + new_controlChannel = ((TileEntityAcceleratorControlPoint) new_vControlPoint.getTileEntity(world)).getControlChannel(); + } } break; }