|
30 | 30 | import zmaster587.advancedRocketry.item.IDataItem; |
31 | 31 | import zmaster587.advancedRocketry.item.ItemAsteroidChip; |
32 | 32 | import zmaster587.advancedRocketry.item.ItemMemoryCrystal; |
| 33 | +import zmaster587.advancedRocketry.navigation.CrystalEntry; |
33 | 34 | import zmaster587.advancedRocketry.space.GalacticCoord; |
34 | 35 | import zmaster587.advancedRocketry.tile.hatch.TileDataBus; |
35 | 36 | import zmaster587.advancedRocketry.universe.RegionScan; |
@@ -117,6 +118,7 @@ public class TileObservatory extends TileMultiPowerConsumer implements IModularI |
117 | 118 | private static final byte ABORT_SCAN = 20; |
118 | 119 | private static final byte PASSIVE_SWEEP = 21; |
119 | 120 | private static final byte TOGGLE_WHOLE_SYSTEM = 22; |
| 121 | + private static final byte UPLOAD_CRYSTAL = 23; |
120 | 122 | /** Progress id of the region-scan bar; the machine's own bar keeps id 0. */ |
121 | 123 | private static final int PROGRESS_SCAN = 1; |
122 | 124 | /** |
@@ -748,6 +750,12 @@ public List<ModuleBase> getModules(int ID, EntityPlayer player) { |
748 | 750 | zmaster587.libVulpes.inventory.TextureResources.buttonBuild, |
749 | 751 | LibVulpes.proxy.getLocalizedString("msg.observetory.scan.abort.tooltip"), 40, 18)); |
750 | 752 | } |
| 753 | + // Reading a crystal INTO this world, the reverse of the survey that fills one. It costs |
| 754 | + // no power and no data: the knowledge already exists, it is being put down here. |
| 755 | + modules.add(new ModuleButton(100, 142, 10, |
| 756 | + LibVulpes.proxy.getLocalizedString("msg.observetory.upload.button"), this, |
| 757 | + zmaster587.libVulpes.inventory.TextureResources.buttonBuild, |
| 758 | + LibVulpes.proxy.getLocalizedString("msg.observetory.upload.tooltip"), 64, 18)); |
751 | 759 | modules.add(new ModuleButton(166, 42, 8, |
752 | 760 | LibVulpes.proxy.getLocalizedString(passive |
753 | 761 | ? "msg.observetory.scan.mode.passive" : "msg.observetory.scan.mode.active"), |
@@ -1186,6 +1194,41 @@ public void onInventoryButtonPressed(int buttonId) { |
1186 | 1194 | if (buttonId == 9) { |
1187 | 1195 | PacketHandler.sendToServer(new PacketMachine(this, TOGGLE_WHOLE_SYSTEM)); |
1188 | 1196 | } |
| 1197 | + if (buttonId == 10) { |
| 1198 | + PacketHandler.sendToServer(new PacketMachine(this, UPLOAD_CRYSTAL)); |
| 1199 | + } |
| 1200 | + } |
| 1201 | + |
| 1202 | + /** |
| 1203 | + * Read the crystal in the machine into the KNOWLEDGE OF THIS BODY: what somebody carried here |
| 1204 | + * becomes what a launch pad standing here may be aimed at. |
| 1205 | + * |
| 1206 | + * <p>This is the one sanctioned crossing between the two discovery systems, and it goes one way. |
| 1207 | + * A crystal deposits into a body's set; a body's set never feeds a crystal, a console, or a jump |
| 1208 | + * target.</p> |
| 1209 | + * |
| 1210 | + * <p><b>An address without a world is skipped, and the count says so.</b> A procedural body |
| 1211 | + * carries no dimension until somebody descends to it, so a survey of unvisited space writes |
| 1212 | + * addresses that tier-1 has nothing to fly to yet - and an upload that silently did nothing |
| 1213 | + * would be indistinguishable from a broken button. Re-surveying such a system after somebody has |
| 1214 | + * landed there records the world it now has.</p> |
| 1215 | + * |
| 1216 | + * @return {@code {landed, total}} |
| 1217 | + */ |
| 1218 | + private int[] uploadCrystalHere() { |
| 1219 | + ItemStack crystal = getStackInSlot(SLOT_CRYSTAL); |
| 1220 | + if (!ItemMemoryCrystal.isCrystal(crystal)) { |
| 1221 | + return new int[] {0, 0}; |
| 1222 | + } |
| 1223 | + List<CrystalEntry> entries = ItemMemoryCrystal.memoryOf(crystal).list(); |
| 1224 | + Set<Integer> landed = new HashSet<>(); |
| 1225 | + for (CrystalEntry entry : entries) { |
| 1226 | + if (entry.namesBody()) { |
| 1227 | + landed.add(entry.dimId()); |
| 1228 | + } |
| 1229 | + } |
| 1230 | + teachThisBody(landed); |
| 1231 | + return new int[] {landed.size(), entries.size()}; |
1189 | 1232 | } |
1190 | 1233 |
|
1191 | 1234 |
|
@@ -1259,6 +1302,11 @@ else if (id == TOGGLE_WHOLE_SYSTEM) { |
1259 | 1302 | player.openGui(LibVulpes.instance, GuiHandler.guiId.MODULARNOINV.ordinal(), |
1260 | 1303 | getWorld(), pos.getX(), pos.getY(), pos.getZ()); |
1261 | 1304 | } |
| 1305 | + else if (id == UPLOAD_CRYSTAL) { |
| 1306 | + int[] result = uploadCrystalHere(); |
| 1307 | + player.sendMessage(new net.minecraft.util.text.TextComponentTranslation( |
| 1308 | + "msg.observetory.upload.result", result[0], result[1])); |
| 1309 | + } |
1262 | 1310 | else if (id == START_SCAN || id == ABORT_SCAN || id == PASSIVE_SWEEP) { |
1263 | 1311 | if (id == ABORT_SCAN) { |
1264 | 1312 | abortRegionScan(); |
|
0 commit comments