diff --git a/README.md b/README.md index 7342594..fcd4607 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,8 @@ excluded from the release JAR. ## Content and operation -MMDLib standalone definitions register all 17 legacy block IDs and four legacy item IDs under +MMDLib XML machine definitions (the twelve machines) and standalone definitions (the other +blocks and items) register all 17 legacy block IDs and four legacy item IDs under `steamadvantage`. The art and translations originate in SA2; texture paths, blockstates, models, enchantments, recipes, mining tags, and loot use 1.21.1 formats. There is a SteamAdvantage creative tab. @@ -40,8 +41,8 @@ There is a SteamAdvantage creative tab. | Geothermal boiler | Gains heat beside lava or magma, boils water after reaching operating temperature | | Oil boiler | Burns 100 mB aliquots of tagged liquid fuel, consumes water, outputs steam | | Steam tank | Stores 1,000,000 mB steam; comparator reports fill level | -| Steam furnace | Three independent vanilla smelting lanes; fuel heats the furnace, steam increases heating | -| Rock crusher | Uses MMDLib `mmdlib:crushing` recipes; 125 processing ticks at 150 mB steam/tick | +| Steam furnace | Three independent smelting lanes on steam alone; each smelts at the recipe's cooking time, 2000 mB steam per 200 ticks | +| Rock crusher | Runs every MMDLib `mmdlib:crushing` recipe; 125 ticks and 18,750 mB steam per item | | Steam drill | Mines in its facing direction, extends a damaging drill shaft, retains drops, follows adjacent steam track at range/obstruction | | Steam elevator | Redstone raises the platform and passengers; removing power retracts it; 16-block search range | | Steam still | Runs PA3 distilling recipes with persisted progress and output | @@ -125,7 +126,8 @@ The integration suite checks all machine registrations, capabilities, NBT persistence, steam filtering, boiler fuel/energy/water use, redstone behavior, PA3 pipe delivery, pumping conservation, crushing and blocked-output behavior, three furnace lanes, drill movement/inventory preservation, elevator movement, -valve operation, distillation ratios, and musket loading/firing. +valve operation, distillation ratios, imports of saves from before the XML machine +port, and musket loading/firing. The development client completed resource reload and atlas creation without SteamAdvantage missing-model or missing-texture warnings. Actual in-world diff --git a/TODO.md b/TODO.md index 3a0a4f9..e64ce44 100644 --- a/TODO.md +++ b/TODO.md @@ -30,6 +30,9 @@ implementation and its relevant gameplay checks are complete. - Looks up the mined block's item in MMDLib's live crushing recipes, matching the steam crusher's recipe type. Uses the recipe's complete output when present; otherwise uses normal unenchanted diamond-pickaxe drops. + - Removed in 3.2.0: with Mineralogy's runtime c:cobblestones tag every rock + crushed to gravel, so the drill now always returns normal block drops, + like Electric Advantage's laser drill. - Checks all output slots together before mining spends steam or advances progress. Insufficient space preserves the block and pauses mining until the entire result fits; recipe output replaces rather than adds to loot. diff --git a/build.gradle b/build.gradle index 4975978..5a30bb0 100644 --- a/build.gradle +++ b/build.gradle @@ -132,7 +132,7 @@ if (project.hasProperty('gameTests')) { } } } - tasks.named('jar') { exclude '**/SteamGameTests*', 'data/steamadvantage/structure/empty.nbt', 'data/steamadvantage/recipe/test_slow_distillation.json', 'data/c/tags/fluid/oil.json', 'mmdlib/standalone/block/test_large_steam_tank.json', 'mmdlib/screen/test_large_steam_tank.xml' } + tasks.named('jar') { exclude '**/SteamGameTests*', 'data/steamadvantage/structure/empty.nbt', 'data/steamadvantage/recipe/test_slow_distillation.json', 'data/c/tags/fluid/oil.json', 'mmdlib/machine/test_large_steam_tank.xml', 'data/steamadvantage/legacy_saves/**' } tasks.named('sourcesJar') { exclude '**/SteamGameTests*' } tasks.named('javadoc') { exclude '**/SteamGameTests*' } } diff --git a/docs/mmdlib-integration.md b/docs/mmdlib-integration.md index aad374f..8abd1b1 100644 --- a/docs/mmdlib-integration.md +++ b/docs/mmdlib-integration.md @@ -1,84 +1,99 @@ # MMDLib integration -SteamAdvantage is a consumer and showcase of MMDLib's public standalone APIs. -It does not declare a synthetic material to register machines or crafting parts. - -## Content path +SteamAdvantage is a consumer and showcase of MMDLib's public APIs. Its twelve machines are +MMDLib XML machine definitions (MMDLib 2.0.3 or later); its other blocks and items are MMDLib +standalone plans. It declares no synthetic material. + +## Machines + +Each machine is `src/main/resources/mmdlib/machine/.xml`. MMDLib registers its block, +item, block-entity type, capabilities, screen, recipe type and JEI catalyst, and generates its +blockstate, item model and loot table from the XML. All of them extend the abstract +`steamadvantage:steam_base` (hardness, pickaxe, required tool), which extends +`mmdlib:base_machine` (redstone and side-configuration drawers, recovery capsule, base screen). + +MMDLib's generated resource pack sits below mod resources, so SteamAdvantage must not ship its +own blockstate, item model or loot table for a machine. A machine's `appearance` names a model +that is not `block/`, so SteamAdvantage's models are `block/_model`. + +| Machine | Work | Tanks (index order) | Items | +| --- | --- | --- | --- | +| Coal / oil / electric / geothermal boiler | `*BoilerProcessor` | steam, water, (oil: fuel) | coal: fuel | +| Steam tank | `SteamTankProcessor` | steam | | +| Steam switch | `SteamValveProcessor` | steam | | +| Steam pump | `PumpProcessor` | steam, product | | +| Steam-powered still | `StillProcessor` | steam, product, input | | +| Steam elevator | `ElevatorProcessor` | steam | | +| Steam drill | `DrillProcessor` (six-way facing) | steam | 5 outputs | +| Steam crusher | MMDLib recipe lane + `RecipeMachineSensor` | steam | input, 5 outputs | +| Steam furnace | three MMDLib recipe lanes + `RecipeMachineSensor` | steam | 3 inputs, 3 outputs | + +Custom processors extend `SteamProcessor` (a `StoredProcessor`). It provides the steam helpers, +SA2's rule that a machine stops while it receives any redstone signal (the elevator uses the +signal instead), and the comparator reading every machine XML selects with +``. Machine state (burn timers, +temperature, drill depth, elevator position, distillation batches) is processor state. +Admission rules that tags cannot express (furnace fuel, the config-selected oil fuel tag, still +inputs from Power Advantage's distilling recipes) are `filter-processor` bindings on processors +that implement `StorageAdmission`. + +The crusher and furnace use MMDLib recipe processors with recipe types declared in their XML: + +- `steamadvantage:steam_crushing`, from `recipes.SteamCrushingRecipes`: every MMDLib crushing + recipe, 125 ticks and 18,750 mB of steam per item by default. +- `steamadvantage:steam_smelting`, from `recipes.SteamSmeltingRecipes`: every smelting recipe at + its own cooking time, with MMDLib's FE price converted to steam (a 200-tick recipe costs + 2000 mB). The furnace's three lanes bind `input`/`output` to their own slots and share the + steam tank. + +Authored recipe JSON with a generated recipe's ID replaces it. `RecipeMachineSensor` supplies +their comparator reading (input fullness) and lets a working furnace melt snow above it. + +### Block entity + +`machines.SteamMachineEntity` extends `DefinedMachineEntity` and is registered for every machine +with `MachineContent.registerEntityFactory` in the mod constructor. It: + +- imports saves from before the XML port (`migrateMachineData`): each processor's + `importLegacy` copies the top-level keys it used (`Burn`, `Temperature`, `Depth`...) into its + state, the pre-2.0.2 `Energy` key becomes `energy`, and `legacySlots` maps the old shared + nine-slot inventory onto each machine's declared slots (unplaced contents, such as the + retired furnace fuel slot, go to recovery). Storage keeps the `Items` and `Fluids` keys and + the old tank order; +- holds recipe machines while they are powered (`processingAllowed`); +- clears the drill pipe when a drill is removed (`dropContents`, which MMDLib never calls on chunk + unload) or turned (`setBlockState`), and skips dropping contents while a drill moves itself + along a track. + +### Screens + +Machine XML screens extend MMDLib's base machine screen: generated, interactive tank gauges, +generated slot groups and recipe progress, a pause button, and the redstone and +side-configuration drawers. XML machine screens bind to `DefinedMachineEntity`, so the extra +displays SteamAdvantage adds in a machine's `machine` region (burn meter, heat gauge, drill +depth, distillation progress, help text) read processor state through static helpers, +`value="zone.moddev.mc.SteamAdvantage.machines.SteamScreens#burnTime"` and so on. + +## Other content 1. `mmdlib/block/*.json` and `mmdlib/item/*.json` select public implementation factories. -2. `mmdlib/standalone/block/*.json` and `mmdlib/standalone/item/*.json` declare instances. -3. MMDLib's startup loader discovers and validates those files. -4. `init.ContentFactories` registers public `BlockImplementation`, `ItemImplementation`, - and `BlockEntityFactory` contracts. -5. `init.ModContent` queues only this namespace's standalone plans on - `RuntimeContentRegistrar`, then passes its own block-entity `DeferredRegister` to every - `BlockEntityHandle` the registrar prepared. It has no block or item registers. -6. MMDLib creates the blocks and paired items, and gives each machine block a prepared - `BlockEntityBinding`. `MachineBlock` delegates construction and ticking to - `MaterialEntityBlock`. -7. `MachineSettings.CODEC` validates behavior selection and storage capacities. Each machine - type has its own ID matching its block and XML screen. - -The library registrar also provides the creative tab. Capability storage/roles, transfer -operations, `MachineCapabilities` registration and crushing recipes use MMDLib. - -A test-only standalone tank changes capacity to 2,345,678 mB and inventory size to 12. -It registers, persists and exposes its fluid through XML-bound getters without adding a -Java registration or material definition. Its data and screen are excluded from releases. - -## GUI - -Twelve machine-specific XML files live under `mmdlib/screen/`. Each declares its slots, -gauges, progress indicators, labels and tooltips, and its file name matches the machine's -block-entity type, which is how MMDLib finds it. SteamAdvantage contains no menu, screen, -renderer, layout or synchronization code: - -| Concern | Provided by MMDLib | -| --- | --- | -| Schema, reading, getter binding, layout | `gui.load`, `gui.model`, `gui.layout` | -| Menu, slots, shift-click, opening | `gui.runtime.MachineMenu`, `ScreenRuntime`, `BlockEvents.openMenu` | -| Value synchronization | `gui.runtime.ScreenNetwork`, `ScreenValues`, `ScreenSnapshots` | -| Screen and gauge rendering | `gui.client.MachineScreen`, `GaugeRenderer` | - -The block-entity class `SteamMachine` extends MMDLib's `machine.neoforge.BaseMachine`, which -implements `gui.runtime.ScreenHost` and owns persistence through a `MachineInventoryLifecycle` -(items under `Items`, fluids under `Fluids`, the electric boiler's buffer under `energy`; older -saves' `Energy` is still read). Machine state such as burn time and drill depth stays top-level -through `saveMachineData`/`loadMachineData`, and broken machines drop their items through -`BaseMachine.dropContents`. `screenItems()` exposes its `ItemStorage` (so roles and filters -apply to clicks and shift-click) and -`screenRecipeSlots()` names the crusher and furnace recipe inputs for optional JEI transfer. -Right-click goes through the `steamadvantage:use_machine` handler declared in -`mmdlib/extension/machines.json`: fluid containers act on the machine's tanks first, otherwise -`BlockEvents.openMenu` opens the XML screen. - -Remaining SteamAdvantage-side code that MMDLib has no equivalent for: the comparator reading in -`MachineBlock` (MMDLib's comparator support does not yet read block-entity getters) and the -fluid-container interaction above. Moving the machines to MMDLib's XML machine definitions, as -Power Advantage 3.2 has, waits on MMDLib support for six-way facing (the drill) and for -processor-supplied slot and tank filters. - -Each machine also declares MMDLib automation groups (`SteamMachine.automationGroups`): item -fuel/input/output groups where a machine has them, and steam, water or input, fuel and product -tanks. Every face of a group starts at the group's role, which matches the access SA3 always -exposed. The item, fluid and energy capabilities registered in `ModContent` read each face's mode -from these groups, so side settings gate pipes and hoppers and are saved under `automation`. -Because `BaseMachine.screenAutomation()` returns these groups, every machine screen gets MMDLib's -built-in side-configuration drawer, coloured group outlines on its slots, and add-on and filter -slots per group (Power Advantage's fluid intake and output pumps work there). Fluid and energy -groups name their screen gauge, which is highlighted while the group is selected. Installed -add-ons drop as items when a machine is broken. +2. `mmdlib/standalone/block/*.json` and `mmdlib/standalone/item/*.json` declare the pipes, track, + drill bit, platform, pump shaft, components and musket. +3. `init.ContentFactories` registers their `BlockImplementation`, `ItemImplementation` and + `BlockEntityFactory` contracts; `init.ModContent` queues this namespace's standalone plans on + `RuntimeContentRegistrar` and registers the pipes' capabilities. ## Verification -The GameTest suite checks the XML-declared versus hidden slots, output-role protection, -shift-click routing, host removal, rejection of mismatched screen definitions, codec validation, -payload round trips for numbers exceeding `long`, decimals and fluid amounts, and layout of every -screen through MMDLib. +The GameTest suite covers each machine's behavior, comparator readings (real comparators +included), automation sides and their persistence, Power Advantage pump add-ons, menu slot +roles and shift-click, rejection of mismatched screen definitions, an XML-only variant machine +(a GameTest-only tank that extends `steam_tank`), and imports of saves written by the pre-XML +entity, kept as SNBT fixtures in `src/gameTest/resources/data/steamadvantage/legacy_saves`. -An opt-in client fixture copies the disposable GameTest world and opens each of the twelve -screens through the actual block interaction. It checks synchronized getters, verifies that -each translated layout fits, captures each rendered screen, and shuts down automatically: +An opt-in client fixture copies the disposable GameTest world, opens each of the twelve screens +through the actual block interaction, checks that each layout fits and has its gauges, captures +each rendered screen, and shuts down automatically: ```sh ./gradlew -PgameTests runGameTestServer --offline diff --git a/gradle.properties b/gradle.properties index 8162505..ba7911b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ # Example: 1.0.0. 1 21 01 2 notice the minecraft version hidden there at the end? # and the 2 means it's for NeoForge while 1 is Forge and I suspect if we did Fabric mods 3 would be for that. # (This also helps for bug reports as the version number gives us a clue as to what version of Minecraft the bug happened on) -mod_version = 3.1.0.121012 +mod_version = 3.2.0.121012 mod_name = SteamAdvantage mod_id = steamadvantage mod_archive_name = SteamAdvantage @@ -24,8 +24,8 @@ minecraft_version_range = [1.21.1,1.21.2) neoforge_version = 21.1.265 neoforge_version_range = [21.1.265,21.2) loader_version_range = [4,) -mmdlib_version = 2.0.2.121012+Neo -mmdlib_version_range = [2.0.2,3) +mmdlib_version = 2.0.3.121012+Neo +mmdlib_version_range = [2.0.3,3) poweradvantage_version = 3.2.0.121012+Neo poweradvantage_version_range = [3.2.0,4) diff --git a/src/gameTest/java/zone/moddev/mc/SteamAdvantage/machines/SteamGameTests.java b/src/gameTest/java/zone/moddev/mc/SteamAdvantage/machines/SteamGameTests.java index e7742e9..96214b9 100644 --- a/src/gameTest/java/zone/moddev/mc/SteamAdvantage/machines/SteamGameTests.java +++ b/src/gameTest/java/zone/moddev/mc/SteamAdvantage/machines/SteamGameTests.java @@ -16,12 +16,55 @@ @GameTestHolder(SteamAdvantage.MODID) @PrefixGameTestTemplate(false) public final class SteamGameTests { - private static SteamMachine place(GameTestHelper h, String name, int x, int y, int z) { + /** The machine's processor of the given type. */ + private static T processor(zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity m, Class type) { + return m.features.allProcessors().stream().filter(type::isInstance).map(type::cast) + .findFirst().orElseThrow(); + } + private static zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity place( + GameTestHelper h, String name, int x, int y, int z) { var p = new BlockPos(x, y, z); h.setBlock(p, ModContent.block(name)); var be = h.getLevel().getBlockEntity(h.absolutePos(p)); - h.assertTrue(be instanceof SteamMachine, "Machine entity: " + name); - return (SteamMachine) be; + h.assertTrue(be instanceof zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity, + "XML machine entity: " + name); + return (zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity) be; + } + /** Sets an XML machine's comparator source to empty, half or full. */ + private static void setXmlComparatorSource(zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity m, int fraction) { + switch (m.definition.id().getPath()) { + case "steam_elevator" -> processor(m, ElevatorProcessor.class).setRaised(fraction > 0); + case "steam_boiler_geothermal" -> + processor(m, GeothermalBoilerProcessor.class).setTemperature(1000 * fraction); + case "steam_boiler_electric" -> m.energy.setStored(m.energy.capacity() * fraction / 2); + case "steam_boiler_coal" -> m.items.setStackInSlot(0, fraction == 0 ? ItemStack.EMPTY + : new ItemStack(Items.COAL, fraction * 32)); + case "steam_crusher" -> m.items.setStackInSlot(0, fraction == 0 ? ItemStack.EMPTY + : new ItemStack(Items.COBBLESTONE, fraction * 32)); + case "steam_furnace" -> { + for (int slot = 0; slot < 3; slot++) + m.items.setStackInSlot(slot, fraction == 0 ? ItemStack.EMPTY + : new ItemStack(Items.RAW_IRON, fraction * 32)); + } + case "steam_drill" -> { + for (int slot = 0; slot < 5; slot++) + m.items.setStackInSlot(slot, fraction == 0 ? ItemStack.EMPTY + : new ItemStack(Items.COAL, fraction * 32)); + } + default -> { + String kind = m.definition.id().getPath(); + int index = kind.equals("steam_boiler_oil") || kind.equals("steam_still") ? 2 + : kind.equals("steam_pump") ? 1 : 0; + var fluid = kind.equals("steam_boiler_oil") ? Fluids.LAVA + : index > 0 ? Fluids.WATER + : zone.moddev.mc.poweradvantage.init.Fluids.STEAM.get(); + var tank = m.fluids.tank(index); + tank.drain(Integer.MAX_VALUE, FluidAction.EXECUTE); + if (fraction > 0) + tank.fill(new FluidStack(fluid, tank.getCapacity() * fraction / 2), + FluidAction.EXECUTE); + } + } } @GameTest(template = "empty") public static void drillBitLineCleanup(GameTestHelper h) { @@ -32,14 +75,14 @@ public static void drillBitLineCleanup(GameTestHelper h) { BlockPos origin = new BlockPos(2, 2, 2); h.setBlock(origin, ModContent.block("steam_drill").defaultBlockState() .setValue(facing, direction)); - var drill = (SteamMachine) h.getLevel().getBlockEntity(h.absolutePos(origin)); + var drill = (zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity) h.getLevel().getBlockEntity(h.absolutePos(origin)); + var dp = processor(drill, DrillProcessor.class); var bit = ModContent.block("drillbit").defaultBlockState().setValue(facing, direction); BlockPos isolated = new BlockPos(6, 2, 6); for (int scenario = 0; scenario < 3; scenario++) { for (int n = 1; n <= 3; n++) h.setBlock(origin.relative(direction, n), bit); h.setBlock(isolated, bit); - drill.depth = 3; - drill.progress[0] = 12; + dp.set(3, DrillProcessor.DRILLING, 12); if (scenario == 0) h.getLevel().destroyBlock(h.absolutePos(origin.relative(direction, 2)), true); else if (scenario == 1) @@ -51,7 +94,7 @@ else if (scenario == 1) "Connected bit removed: " + direction + " scenario " + scenario); h.assertTrue(h.getBlockState(isolated).is(ModContent.block("drillbit")), "Disconnected bit preserved"); - h.assertTrue(drill.depth == 0 && drill.progress[0] == 0, "Drill progress reset"); + h.assertTrue(dp.depth() == 0 && dp.progress() == 0, "Drill progress reset"); if (scenario == 1) h.setBlock(origin, drill.getBlockState().setValue(facing, direction)); } @@ -63,42 +106,45 @@ else if (scenario == 1) @GameTest(template = "empty") public static void drillRetractsGraduallyAndWaitsForReset(GameTestHelper h) { var drill = place(h, "steam_drill", 2, 2, 2); + var dp = processor(drill, DrillProcessor.class); var facing = net.minecraft.world.level.block.state.properties.BlockStateProperties.FACING; h.setBlock(new BlockPos(2, 2, 2), drill.getBlockState().setValue(facing, Direction.UP)); var bit = ModContent.block("drillbit").defaultBlockState().setValue(facing, Direction.UP); for (int n = 1; n <= 3; n++) h.setBlock(new BlockPos(2, 2 + n, 2), bit); h.setBlock(new BlockPos(2, 6, 2), Blocks.BEDROCK); - drill.depth = 3; - DrillOperation.drill(drill); - h.assertTrue(drill.drillPhase == 1, "Bedrock starts retraction without steam"); - for (int n = 0; n < 4; n++) DrillOperation.drill(drill); - h.assertTrue(drill.depth == 2 && h.getBlockState(new BlockPos(2, 5, 2)).isAir(), + dp.set(3, DrillProcessor.DRILLING, 0); + dp.step(); + h.assertTrue(dp.phase() == DrillProcessor.RETRACTING, "Bedrock starts retraction without steam"); + for (int n = 0; n < 4; n++) dp.step(); + h.assertTrue(dp.depth() == 2 && h.getBlockState(new BlockPos(2, 5, 2)).isAir(), "Only the outermost segment retracts first"); h.assertTrue(h.getBlockState(new BlockPos(2, 3, 2)).is(ModContent.block("drillbit")), "Inner line survives controlled retraction"); var saved = drill.saveWithoutMetadata(h.getLevel().registryAccess()); drill.loadWithComponents(saved, h.getLevel().registryAccess()); - h.assertTrue(drill.drillPhase == 1 && drill.depth == 2, "Retraction survives save/load"); - for (int n = 0; n < 20; n++) DrillOperation.drill(drill); - h.assertTrue(drill.depth == 0 && drill.drillPhase == 2, "Drill stays retracted"); + h.assertTrue(dp.phase() == DrillProcessor.RETRACTING && dp.depth() == 2, + "Retraction survives save/load"); + for (int n = 0; n < 20; n++) dp.step(); + h.assertTrue(dp.depth() == 0 && dp.phase() == DrillProcessor.RETRACTED, "Drill stays retracted"); drill.fluids.fill(steam(10000), FluidAction.EXECUTE); - for (int n = 0; n < 10; n++) DrillOperation.drill(drill); - h.assertTrue(drill.depth == 0, "Steam does not restart completed drill"); + for (int n = 0; n < 10; n++) dp.step(); + h.assertTrue(dp.depth() == 0, "Steam does not restart completed drill"); h.setBlock(new BlockPos(3, 2, 2), Blocks.REDSTONE_BLOCK); - SteamMachine.tick(h.getLevel(), drill.getBlockPos(), drill.getBlockState(), drill); - h.assertTrue(drill.drillPhase == 0, "Redstone resets completion"); - h.setBlock(new BlockPos(3, 2, 2), Blocks.AIR); - DrillOperation.drill(drill); - h.assertTrue(drill.depth == 1, "Drilling resumes after reset"); - drill.clearDrill(); - drill.depth = DrillOperation.MAX_RANGE; - DrillOperation.drill(drill); - h.assertTrue(drill.drillPhase == 1, "Maximum range also starts retraction"); - drill.clearDrill(); - drill.drillPhase = 2; - h.setBlock(new BlockPos(2, 2, 2), drill.getBlockState().setValue(facing, Direction.DOWN)); - h.assertTrue(drill.drillPhase == 0, "Rotation resets completion"); - h.succeed(); + h.runAfterDelay(2, () -> { + h.assertTrue(dp.phase() == DrillProcessor.DRILLING, "Redstone resets completion"); + h.setBlock(new BlockPos(3, 2, 2), Blocks.AIR); + dp.step(); + h.assertTrue(dp.depth() == 1, "Drilling resumes after reset"); + dp.clear(); + dp.set(DrillProcessor.MAX_RANGE, DrillProcessor.DRILLING, 0); + dp.step(); + h.assertTrue(dp.phase() == DrillProcessor.RETRACTING, "Maximum range also starts retraction"); + dp.clear(); + dp.set(0, DrillProcessor.RETRACTED, 0); + h.setBlock(new BlockPos(2, 2, 2), drill.getBlockState().setValue(facing, Direction.DOWN)); + h.assertTrue(dp.phase() == DrillProcessor.DRILLING, "Rotation resets completion"); + h.succeed(); + }); } @GameTest(template = "empty") @@ -187,126 +233,108 @@ public static void villagerOffersIncludeBothSmithsAndEnchantedCleric(GameTestHel } @GameTest(template = "empty") - public static void drillUsesCrushingRecipesAndFallsBackToNormalDrops(GameTestHelper h) { + public static void drillReturnsNormalBlockDropsWithoutCrushing(GameTestHelper h) { var drill = place(h, "steam_drill", 3, 2, 3); + var dp = processor(drill, DrillProcessor.class); var target = new BlockPos(3, 2, 2); - drill.fluids.fill(steam(5000), FluidAction.EXECUTE); + // Cobblestone and bricks have crushing recipes; the drill must not apply them. for (var block : new net.minecraft.world.level.block.Block[] { - Blocks.COBBLESTONE, Blocks.BRICKS, Blocks.DIRT}) { + Blocks.STONE, Blocks.COBBLESTONE, Blocks.BRICKS, Blocks.DIRT}) { h.setBlock(target, block); - drill.depth = 0; - drill.progress[0] = 0; - for (int slot = 4; slot < 9; slot++) drill.items.setStackInSlot(slot, ItemStack.EMPTY); - if (block == Blocks.DIRT) - h.assertTrue(h.getLevel().getRecipeManager().getRecipeFor( - zone.moddev.mc.lib.common.recipes.CrushingRecipe.TYPE.get(), - new net.minecraft.world.item.crafting.SingleRecipeInput(new ItemStack(block)), - h.getLevel()).isEmpty(), "Fallback block has no crushing recipe"); - int ticks = DrillOperation.breakTicks(block.defaultBlockState(), h.getLevel(), h.absolutePos(target)); - for (int tick = 0; tick < ticks; tick++) DrillOperation.drill(drill); - var expected = block == Blocks.COBBLESTONE ? Items.GRAVEL - : block == Blocks.BRICKS ? Items.BRICK : Items.DIRT; - int count = block == Blocks.BRICKS ? 4 : 1; - h.assertTrue(drill.items.getStackInSlot(4).is(expected) - && drill.items.getStackInSlot(4).getCount() == count, - "Correct crushing/fallback output for " + block); - h.assertTrue(drill.depth == 1 && h.getBlockState(target).is(ModContent.block("drillbit")), + dp.set(0, DrillProcessor.DRILLING, 0); + drill.fluids.fill(steam(5000), FluidAction.EXECUTE); + for (int slot = 0; slot < 5; slot++) drill.items.setStackInSlot(slot, ItemStack.EMPTY); + int ticks = DrillProcessor.breakTicks(block.defaultBlockState(), h.getLevel(), h.absolutePos(target)); + for (int tick = 0; tick < ticks; tick++) dp.step(); + var expected = block == Blocks.STONE ? Items.COBBLESTONE : block.asItem(); + h.assertTrue(drill.items.getStackInSlot(0).is(expected) + && drill.items.getStackInSlot(0).getCount() == 1, + "Normal block drop for " + block); + h.assertTrue(dp.depth() == 1 && h.getBlockState(target).is(ModContent.block("drillbit")), "Mining replaces the block with one drill segment"); - for (int slot = 5; slot < 9; slot++) - h.assertTrue(drill.items.getStackInSlot(slot).isEmpty(), "No extra normal drops"); + for (int slot = 1; slot < 5; slot++) + h.assertTrue(drill.items.getStackInSlot(slot).isEmpty(), "No extra drops"); } h.succeed(); } @GameTest(template = "empty") - public static void drillWaitsForCompleteCrushingOutputCapacity(GameTestHelper h) { + public static void drillWaitsForOutputCapacity(GameTestHelper h) { var drill = place(h, "steam_drill", 3, 2, 3); + var dp = processor(drill, DrillProcessor.class); var target = new BlockPos(3, 2, 2); - h.setBlock(target, Blocks.BRICKS); + h.setBlock(target, Blocks.COBBLESTONE); h.setBlock(new BlockPos(3, 2, 1), Blocks.BEDROCK); drill.fluids.fill(steam(5000), FluidAction.EXECUTE); - for (int slot = 4; slot < 9; slot++) + for (int slot = 0; slot < 5; slot++) drill.items.setStackInSlot(slot, new ItemStack(Items.DIAMOND, 64)); - drill.items.setStackInSlot(4, new ItemStack(Items.BRICK, 63)); - for (int tick = 0; tick < 20; tick++) DrillOperation.drill(drill); - h.assertTrue(h.getBlockState(target).is(Blocks.BRICKS) && drill.depth == 0 - && drill.progress[0] == 0 && drill.fluids.tank(0).getFluidAmount() == 5000, + for (int tick = 0; tick < 30; tick++) dp.step(); + h.assertTrue(h.getBlockState(target).is(Blocks.COBBLESTONE) && dp.depth() == 0 + && dp.progress() == 0 && drill.fluids.tank(0).getFluidAmount() == 5000, "Full output preserves target, depth, progress and steam"); - drill.items.setStackInSlot(5, new ItemStack(Items.BRICK, 62)); - DrillOperation.drill(drill); - h.assertTrue(drill.items.getStackInSlot(4).getCount() == 63 - && drill.items.getStackInSlot(5).getCount() == 62 - && drill.fluids.tank(0).getFluidAmount() == 5000, - "Three spaces cannot partially accept a four-brick recipe"); - drill.items.setStackInSlot(5, new ItemStack(Items.BRICK, 61)); - int ticks = DrillOperation.breakTicks(Blocks.BRICKS.defaultBlockState(), h.getLevel(), h.absolutePos(target)); - for (int tick = 0; tick < ticks; tick++) DrillOperation.drill(drill); - h.assertTrue(drill.items.getStackInSlot(4).getCount() == 64 - && drill.items.getStackInSlot(5).getCount() == 64 && drill.depth == 1, - "Mining resumes and distributes the complete recipe across output slots"); - for (int tick = 0; tick < 8; tick++) DrillOperation.drill(drill); - h.assertTrue(drill.items.getStackInSlot(4).getCount() == 64 - && drill.items.getStackInSlot(5).getCount() == 64, - "Subsequent ticks do not duplicate crushing output"); + drill.items.setStackInSlot(2, new ItemStack(Items.COBBLESTONE, 63)); + int ticks = DrillProcessor.breakTicks(Blocks.COBBLESTONE.defaultBlockState(), h.getLevel(), h.absolutePos(target)); + for (int tick = 0; tick < ticks; tick++) dp.step(); + h.assertTrue(drill.items.getStackInSlot(2).getCount() == 64 && dp.depth() == 1, + "Mining resumes once there is room"); + for (int tick = 0; tick < 8; tick++) dp.step(); + h.assertTrue(drill.items.getStackInSlot(2).getCount() == 64, + "Subsequent ticks do not duplicate output"); h.succeed(); } - private static void setComparatorSource(SteamMachine m, int fraction) { - switch (m.kind) { - case "steam_elevator" -> m.raised = fraction > 0; - case "steam_boiler_geothermal" -> m.temperature = 1000 * fraction; - case "steam_boiler_electric" -> m.energy.setStored(m.energy.capacity() * fraction / 2); - case "steam_drill", "steam_furnace", "steam_crusher", "steam_boiler_coal" -> { - int first = m.kind.equals("steam_drill") ? 4 : m.kind.equals("steam_furnace") ? 1 : 0; - int end = m.kind.equals("steam_drill") ? 9 : m.kind.equals("steam_furnace") ? 4 : 1; - for (int slot = first; slot < end; slot++) - m.items.setStackInSlot(slot, fraction == 0 ? ItemStack.EMPTY - : new ItemStack(Items.COAL, fraction * 32)); - } - default -> { - int tank = m.kind.equals("steam_boiler_oil") ? m.fuel - : m.kind.equals("steam_pump") ? m.product - : m.kind.equals("steam_still") ? m.water : m.steam; - var fluid = m.kind.equals("steam_boiler_oil") ? Fluids.LAVA - : m.kind.equals("steam_pump") || m.kind.equals("steam_still") ? Fluids.WATER - : zone.moddev.mc.poweradvantage.init.Fluids.STEAM.get(); - m.fluids.tank(tank).drain(Integer.MAX_VALUE, FluidAction.EXECUTE); - if (fraction > 0) m.fluids.tank(tank).fill( - new FluidStack(fluid, m.fluids.tank(tank).getCapacity() * fraction / 2), - FluidAction.EXECUTE); - } - } - } @GameTest(template = "empty") - public static void machineComparatorSourcesAndScaling(GameTestHelper h) { - var pos = new BlockPos(2, 2, 2); + public static void comparatorReadingsIgnoreUnrelatedStorage(GameTestHelper h) { + // Machines whose reading is not their steam tank ignore steam fullness. for (String kind : ModContent.MACHINES) { - h.setBlock(pos, Blocks.AIR); + if (kind.equals("steam_tank") || kind.equals("steam_switch")) + continue; + h.setBlock(new BlockPos(2, 2, 2), Blocks.AIR); var m = place(h, kind, 2, 2, 2); - for (int fraction = 0; fraction <= 2; fraction++) { - setComparatorSource(m, fraction); - int expected = kind.equals("steam_elevator") ? (fraction == 0 ? 0 : 15) - : fraction == 0 ? 0 : fraction == 1 ? 7 : 15; - h.assertTrue(m.getBlockState().getAnalogOutputSignal(h.getLevel(), m.getBlockPos()) == expected, - kind + " comparator fraction " + fraction + " expected " + expected); - } - setComparatorSource(m, 0); - if (!kind.equals("steam_tank") && !kind.equals("steam_switch")) { - m.fluids.tank(m.steam).fill(steam(m.getSteamCapacity()), FluidAction.EXECUTE); - h.assertTrue(m.comparatorSignal() == 0, kind + " ignores unrelated steam fullness"); - } + m.fluids.tank(0).fill(steam(m.fluids.tank(0).getCapacity()), FluidAction.EXECUTE); + var reading = processor(m, SteamProcessor.class).redstoneOutputs().getFirst().signal(); + h.assertTrue(reading.getAsInt() == 0, kind + " ignores unrelated steam fullness"); } + h.setBlock(new BlockPos(2, 2, 2), Blocks.AIR); var drill = place(h, "steam_drill", 2, 2, 2); - drill.items.setStackInSlot(4, new ItemStack(Items.WATER_BUCKET)); - h.assertTrue(drill.comparatorSignal() == 3, "Nonstackable item fills one of five drill slots"); - drill.items.setStackInSlot(4, new ItemStack(Items.ENDER_PEARL, 8)); - h.assertTrue(drill.comparatorSignal() == 1, "Sixteen-stack item fullness is normalized"); - drill.items.setStackInSlot(4, new ItemStack(Items.COAL)); - h.assertTrue(drill.comparatorSignal() == 1, "Nonempty inventory has a minimum signal of one"); + var reading = processor(drill, DrillProcessor.class).redstoneOutputs().getFirst().signal(); + drill.items.setStackInSlot(0, new ItemStack(Items.WATER_BUCKET)); + h.assertTrue(reading.getAsInt() == 3, "Nonstackable item fills one of five drill slots"); + drill.items.setStackInSlot(0, new ItemStack(Items.ENDER_PEARL, 8)); + h.assertTrue(reading.getAsInt() == 1, "Sixteen-stack item fullness is normalized"); + drill.items.setStackInSlot(0, new ItemStack(Items.COAL)); + h.assertTrue(reading.getAsInt() == 1, "Nonempty inventory has a minimum signal of one"); h.succeed(); } + /** MMDLib samples an XML machine's comparator source once per tick, so step a tick apart. */ + @GameTest(template = "empty", timeoutTicks = 200) + public static void xmlComparatorScaling(GameTestHelper h) { + verifyXmlScaling(h, ModContent.MACHINES.stream().sorted().toList(), 0, 0); + } + private static void verifyXmlScaling( + GameTestHelper h, java.util.List kinds, int index, int fraction) { + if (index == kinds.size()) { h.succeed(); return; } + String kind = kinds.get(index); + if (fraction == 0) h.setBlock(new BlockPos(2, 2, 2), Blocks.AIR); + var x = fraction == 0 ? place(h, kind, 2, 2, 2) + : (zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity) + h.getLevel().getBlockEntity(h.absolutePos(new BlockPos(2, 2, 2))); + // Hold processing so a tank does not empty itself into the test structure. + h.setBlock(new BlockPos(2, 3, 2), Blocks.REDSTONE_BLOCK); + setXmlComparatorSource(x, fraction); + h.runAfterDelay(2, () -> { + int expected = kind.equals("steam_elevator") ? (fraction == 0 ? 0 : 15) + : fraction == 0 ? 0 : fraction == 1 ? 7 : 15; + h.assertTrue(x.getBlockState().getAnalogOutputSignal(h.getLevel(), x.getBlockPos()) + == expected, + kind + " comparator fraction " + fraction + " expected " + expected); + if (fraction < 2) verifyXmlScaling(h, kinds, index, fraction + 1); + else verifyXmlScaling(h, kinds, index + 1, 0); + }); + } + @GameTest(template = "empty", timeoutTicks = 200) public static void realComparatorsRefreshWhenMachineSourcesChange(GameTestHelper h) { verifyComparatorUpdate(h, 0); @@ -318,26 +346,26 @@ private static void verifyComparatorUpdate(GameTestHelper h, int index) { var comparatorPos = new BlockPos(3, 2, 2); h.setBlock(comparatorPos, Blocks.AIR); h.setBlock(machinePos, Blocks.AIR); - var m = place(h, ModContent.MACHINES.get(index), 2, 2, 2); - h.setBlock(machinePos.above(), Blocks.REDSTONE_BLOCK); // Pause processing without powering the comparator. - h.setBlock(comparatorPos.below(), Blocks.STONE); - h.setBlock(comparatorPos, Blocks.COMPARATOR.defaultBlockState().setValue( - net.minecraft.world.level.block.state.properties.BlockStateProperties.HORIZONTAL_FACING, - Direction.WEST)); - setComparatorSource(m, 2); - h.runAfterDelay(4, () -> { - var comparator = (net.minecraft.world.level.block.entity.ComparatorBlockEntity) - h.getLevel().getBlockEntity(h.absolutePos(comparatorPos)); - h.assertTrue(comparator.getOutputSignal() == 15, m.kind + " comparator rises to 15"); - // A raw stack mutation bypasses onChange, as some machine operations do. - if (m.kind.equals("steam_boiler_coal") || m.kind.equals("steam_crusher")) - m.items.getStackInSlot(0).shrink(64); - else setComparatorSource(m, 0); + String kind = ModContent.MACHINES.get(index); + var x = place(h, kind, 2, 2, 2); + { + h.setBlock(machinePos.above(), Blocks.REDSTONE_BLOCK); + h.setBlock(comparatorPos.below(), Blocks.STONE); + h.setBlock(comparatorPos, Blocks.COMPARATOR.defaultBlockState().setValue( + net.minecraft.world.level.block.state.properties.BlockStateProperties.HORIZONTAL_FACING, + Direction.WEST)); + setXmlComparatorSource(x, 2); h.runAfterDelay(4, () -> { - h.assertTrue(comparator.getOutputSignal() == 0, m.kind + " comparator falls to zero"); - verifyComparatorUpdate(h, index + 1); + var comparator = (net.minecraft.world.level.block.entity.ComparatorBlockEntity) + h.getLevel().getBlockEntity(h.absolutePos(comparatorPos)); + h.assertTrue(comparator.getOutputSignal() == 15, kind + " comparator rises to 15"); + setXmlComparatorSource(x, 0); + h.runAfterDelay(4, () -> { + h.assertTrue(comparator.getOutputSignal() == 0, kind + " comparator falls to zero"); + verifyComparatorUpdate(h, index + 1); + }); }); - }); + } } /** Temporary tag membership exercises datapack integration without shipping test tag entries. */ @@ -595,18 +623,20 @@ public static void registrationCapabilitiesPersistence(GameTestHelper h) { h.assertTrue(tank.fluids.fill(new FluidStack(Fluids.WATER, 1000), FluidAction.EXECUTE) == 0, "Steam-only filter"); tank.fluids.fill(steam(123456), FluidAction.EXECUTE); - var saved = tank.saveWithoutMetadata(h.getLevel().registryAccess()); - var restored = new SteamMachine(tank.getBlockPos(), tank.getBlockState()); - restored.loadWithComponents(saved, h.getLevel().registryAccess()); + var registries = h.getLevel().registryAccess(); + var saved = tank.saveWithFullMetadata(registries); + var restored = (zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity) + net.minecraft.world.level.block.entity.BlockEntity.loadStatic( + tank.getBlockPos(), tank.getBlockState(), saved, registries); h.assertTrue(restored.fluids.tank(0).getFluidAmount() == 123456, "Fluid persistence"); h.succeed(); } private static net.neoforged.neoforge.items.IItemHandler itemsAt( - GameTestHelper h, SteamMachine m, Direction side) { + GameTestHelper h, net.minecraft.world.level.block.entity.BlockEntity m, Direction side) { return h.getLevel().getCapability(Capabilities.ItemHandler.BLOCK, m.getBlockPos(), side); } private static net.neoforged.neoforge.fluids.capability.IFluidHandler fluidsAt( - GameTestHelper h, SteamMachine m, Direction side) { + GameTestHelper h, net.minecraft.world.level.block.entity.BlockEntity m, Direction side) { return h.getLevel().getCapability(Capabilities.FluidHandler.BLOCK, m.getBlockPos(), side); } @GameTest(template = "empty") @@ -614,16 +644,16 @@ public static void defaultAutomationSidesMatchRoles(GameTestHelper h) { var furnace = place(h, "steam_furnace", 1, 2, 1); var boiler = place(h, "steam_boiler_electric", 4, 2, 1); var tank = place(h, "steam_tank", 1, 2, 4); - furnace.items.setStackInSlot(4, new ItemStack(Items.IRON_INGOT, 6)); + furnace.items.setStackInSlot(3, new ItemStack(Items.IRON_INGOT, 6)); for (var side : Direction.values()) { var items = itemsAt(h, furnace, side); - h.assertTrue(items.insertItem(0, new ItemStack(Items.COAL), true).isEmpty(), - "Fuel accepted from " + side); - h.assertTrue(items.insertItem(1, new ItemStack(Items.RAW_IRON), true).isEmpty(), + h.assertTrue(items.insertItem(0, new ItemStack(Items.RAW_IRON), true).isEmpty(), "Smeltable input accepted from " + side); - h.assertTrue(!items.insertItem(4, new ItemStack(Items.IRON_INGOT), true).isEmpty(), + h.assertTrue(!items.insertItem(0, new ItemStack(Items.STICK), true).isEmpty(), + "Unsmeltable input refused from " + side); + h.assertTrue(!items.insertItem(3, new ItemStack(Items.IRON_INGOT), true).isEmpty(), "Output refuses insertion from " + side); - h.assertTrue(items.extractItem(4, 1, true).getCount() == 1, + h.assertTrue(items.extractItem(3, 1, true).getCount() == 1, "Output extractable from " + side); var water = fluidsAt(h, boiler, side); h.assertTrue(water.fill(new FluidStack(Fluids.WATER, 100), FluidAction.SIMULATE) == 100, @@ -645,9 +675,10 @@ public static void defaultAutomationSidesMatchRoles(GameTestHelper h) { @GameTest(template = "empty") public static void automationSideConfigGatesAndPersists(GameTestHelper h) { var boiler = place(h, "steam_boiler_coal", 2, 2, 2); - var automation = boiler.automation(); + var automation = boiler.screenAutomation(); var water = automation.group(automation.index("water")); - var facing = boiler.facing(); + var facing = boiler.getBlockState().getValue( + net.minecraft.world.level.block.state.properties.BlockStateProperties.HORIZONTAL_FACING); water.sides().set( zone.moddev.mc.lib.api.capabilities.RelativeFace.of(facing, Direction.UP), zone.moddev.mc.lib.api.capabilities.IoMode.DISABLED); @@ -657,10 +688,12 @@ public static void automationSideConfigGatesAndPersists(GameTestHelper h) { h.assertTrue(fluidsAt(h, boiler, Direction.DOWN) .fill(new FluidStack(Fluids.WATER, 100), FluidAction.SIMULATE) == 100, "Other faces still accept water"); - var saved = boiler.saveWithoutMetadata(h.getLevel().registryAccess()); - var restored = new SteamMachine(boiler.getBlockPos(), boiler.getBlockState()); - restored.loadWithComponents(saved, h.getLevel().registryAccess()); - var restoredWater = restored.automation().group(restored.automation().index("water")); + var registries = h.getLevel().registryAccess(); + var restored = (zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity) net.minecraft.world.level.block.entity.BlockEntity + .loadStatic(boiler.getBlockPos(), boiler.getBlockState(), + boiler.saveWithFullMetadata(registries), registries); + var restoredWater = restored.screenAutomation().group( + restored.screenAutomation().index("water")); h.assertTrue(restoredWater.mode(Direction.UP) == zone.moddev.mc.lib.api.capabilities.IoMode.DISABLED && restoredWater.mode(Direction.DOWN) @@ -673,7 +706,7 @@ public static void powerAdvantagePumpAddonWorksAndDrops(GameTestHelper h) { var boiler = place(h, "steam_boiler_coal", 2, 2, 2); var still = place(h, "steam_still", 3, 2, 2); still.fluids.tank(1).fill(new FluidStack(Fluids.WATER, 2000), FluidAction.EXECUTE); - var automation = boiler.automation(); + var automation = boiler.screenAutomation(); int water = automation.index("water"); var slot = zone.moddev.mc.lib.api.automation.AutomationInventory.addonSlot(water, 0); var pump = new ItemStack(zone.moddev.mc.poweradvantage.init.ModItems.FLUID_INTAKE_PUMP.get()); @@ -693,32 +726,100 @@ public static void powerAdvantagePumpAddonWorksAndDrops(GameTestHelper h) { h.succeed(); }); } + /** + * Loads a save written by the shared pre-XML SteamMachine entity, captured as SNBT in + * data/steamadvantage/legacy_saves (see that folder's README), into the machine's XML entity. + */ + private static zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity importLegacy( + GameTestHelper h, String kind) { + var registries = h.getLevel().registryAccess(); + var placed = place(h, kind, 2, 2, 2); + net.minecraft.nbt.CompoundTag saved; + try (var in = SteamGameTests.class.getResourceAsStream( + "/data/steamadvantage/legacy_saves/" + kind + ".snbt")) { + saved = net.minecraft.nbt.NbtUtils.snbtToStructure( + new String(in.readAllBytes(), java.nio.charset.StandardCharsets.UTF_8)); + } catch (Exception failure) { + throw new IllegalStateException("Missing legacy fixture " + kind, failure); + } + h.assertTrue(saved.contains("TotalBurn"), kind + " fixture is a pre-XML save"); + var imported = (zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity) + net.minecraft.world.level.block.entity.BlockEntity.loadStatic( + placed.getBlockPos(), placed.getBlockState(), saved, registries); + h.assertTrue(imported != null, kind + " imports a pre-XML save"); + var resaved = imported.saveWithFullMetadata(registries); + h.assertTrue(!resaved.contains("TotalBurn") && !resaved.contains("Burn") + && !resaved.contains("Energy"), + kind + " saves in the current format"); + h.setBlock(new BlockPos(2, 2, 2), Blocks.AIR); + return imported; + } @GameTest(template = "empty") - public static void legacySaveLayoutLoads(GameTestHelper h) { - // SA3 before the BaseMachine move saved every storage at the top level, energy as "Energy". - var boiler = place(h, "steam_boiler_electric", 2, 2, 2); - boiler.fluids.fill(new FluidStack(Fluids.WATER, 777), FluidAction.EXECUTE); - boiler.energy.setStored(1234); - boiler.burn = 17; - var saved = boiler.saveWithoutMetadata(h.getLevel().registryAccess()); - h.assertTrue(saved.contains("energy") && saved.contains("Items") && saved.contains("Fluids"), - "Current layout keeps Items/Fluids and uses MMDLib's energy key"); - saved.put("Energy", saved.get("energy")); - saved.remove("energy"); - saved.remove("automation"); - saved.remove("features"); - var restored = new SteamMachine(boiler.getBlockPos(), boiler.getBlockState()); - restored.loadWithComponents(saved, h.getLevel().registryAccess()); - h.assertTrue(restored.energy.stored() == 1234, "Legacy Energy key is migrated"); - h.assertTrue(restored.fluids.tank(1).getFluidAmount() == 777, "Legacy fluids load"); - h.assertTrue(restored.burn == 17, "Top-level machine state loads"); + public static void preXmlMachineSavesLoad(GameTestHelper h) { + var coal = importLegacy(h, "steam_boiler_coal"); + var burner = processor(coal, CoalBoilerProcessor.class); + h.assertTrue(coal.items.getStackInSlot(0).getCount() == 5, "Coal stays in the fuel slot"); + h.assertTrue(coal.fluids.tank(1).getFluidAmount() == 777, "Water stays in tank 1"); + h.assertTrue(burner.burnTime() == 17 && burner.totalBurnTime() == 1600, "Burn timer imported"); + + var electric = importLegacy(h, "steam_boiler_electric"); + h.assertTrue(electric.energy.stored() == 1234, "Legacy Energy key is imported"); + + var oil = importLegacy(h, "steam_boiler_oil"); + h.assertTrue(oil.fluids.tank(2).getFluidAmount() == 900 + && processor(oil, OilBoilerProcessor.class).burnTime() == 40, + "Oil fuel tank and burn timer imported"); + + var geo = importLegacy(h, "steam_boiler_geothermal"); + h.assertTrue(processor(geo, GeothermalBoilerProcessor.class).temperature() == 640, + "Geothermal temperature imported"); + + var elevator = importLegacy(h, "steam_elevator"); + h.assertTrue(processor(elevator, ElevatorProcessor.class).raised(), "Raised state imported"); + + var still = importLegacy(h, "steam_still"); + var batch = processor(still, StillProcessor.class); + h.assertTrue(still.fluids.tank(2).getFluidAmount() == 300, "Still input stays in tank 2"); + h.assertTrue(batch.pending().getFluid() == Fluids.LAVA && batch.pending().getAmount() == 100 + && batch.progress() == 7 && batch.duration() == 20, + "Pending distillation batch imported"); + + var pump = importLegacy(h, "steam_pump"); + h.assertTrue(pump.fluids.tank(1).getFluidAmount() == 2000, "Pumped fluid stays in tank 1"); + + var crusher = importLegacy(h, "steam_crusher"); + h.assertTrue(crusher.items.getStackInSlot(0).getCount() == 3 + && crusher.items.getStackInSlot(1).is(Items.GRAVEL) + && crusher.items.getStackInSlot(1).getCount() == 4 + && crusher.fluids.tank(0).getFluidAmount() == 5000, + "Crusher input, output (slot 4 to 1) and steam imported"); + + var furnace = importLegacy(h, "steam_furnace"); + h.assertTrue(furnace.items.getStackInSlot(0).is(Items.RAW_IRON) + && furnace.items.getStackInSlot(1).getCount() == 2 + && furnace.items.getStackInSlot(3).getCount() == 3 + && furnace.fluids.tank(0).getFluidAmount() == 6000, + "Furnace lanes (inputs 1-3 to 0-2, outputs 4-6 to 3-5) and steam imported"); + h.assertTrue(furnace.items.recoveryContents().stream().anyMatch( + entry -> ((net.minecraft.nbt.CompoundTag) entry).getString("id") + .equals("minecraft:coal")), + "The retired fuel slot's coal is kept for recovery"); + + var drill = importLegacy(h, "steam_drill"); + var bore = processor(drill, DrillProcessor.class); + h.assertTrue(drill.items.getStackInSlot(0).getCount() == 12 + && drill.items.getStackInSlot(4).is(Items.FLINT), + "Drill output slots 4-8 move to 0-4"); + h.assertTrue(bore.depth() == 9 && bore.phase() == DrillProcessor.RETRACTING + && bore.progress() == 5, + "Drill depth, phase and progress imported"); h.succeed(); } @GameTest(template = "empty") public static void brokenMachineDropsItemsOnce(GameTestHelper h) { var crusher = place(h, "steam_crusher", 2, 2, 2); crusher.items.setStackInSlot(0, new ItemStack(Items.COBBLESTONE, 5)); - crusher.items.setStackInSlot(4, new ItemStack(Items.GRAVEL, 3)); + crusher.items.setStackInSlot(1, new ItemStack(Items.GRAVEL, 3)); h.setBlock(new BlockPos(2, 2, 2), Blocks.AIR); var area = new net.minecraft.world.phys.AABB(h.absolutePos(new BlockPos(2, 2, 2))).inflate(2); var drops = h.getLevel().getEntitiesOfClass(net.minecraft.world.entity.item.ItemEntity.class, area); @@ -796,7 +897,7 @@ public static void crushingUsesLibraryRecipes(GameTestHelper h) { crusher.items.setStackInSlot(0, new ItemStack(Items.COBBLESTONE)); h.runAfterDelay(130, () -> { h.assertTrue(crusher.items.getStackInSlot(0).isEmpty(), "Crushing consumes input"); - h.assertTrue(crusher.items.getStackInSlot(4).is(Items.GRAVEL), + h.assertTrue(crusher.items.getStackInSlot(1).is(Items.GRAVEL), "Library recipe produced gravel"); h.assertTrue(crusher.fluids.tank(0).getFluidAmount() == 1250, "Crushing spends 125 x 150 mB"); @@ -807,14 +908,17 @@ public static void crushingUsesLibraryRecipes(GameTestHelper h) { public static void drillMovesAlongTrackWithoutLosingInventory(GameTestHelper h) { var drill = place(h, "steam_drill", 3, 2, 3); drill.fluids.fill(steam(5000), FluidAction.EXECUTE); - drill.items.setStackInSlot(4, new ItemStack(Items.DIAMOND, 3)); + drill.items.setStackInSlot(0, new ItemStack(Items.DIAMOND, 3)); h.setBlock(new BlockPos(3, 2, 2), Blocks.BEDROCK); h.setBlock(new BlockPos(4, 2, 3), ModContent.block("steam_track")); h.runAfterDelay(5, () -> { var moved = h.getLevel().getBlockEntity(h.absolutePos(new BlockPos(4, 2, 3))); - h.assertTrue(moved instanceof SteamMachine, "Drill follows track"); - h.assertTrue(((SteamMachine) moved).items.getStackInSlot(4).getCount() == 3, + h.assertTrue(moved instanceof SteamMachineEntity, "Drill follows track"); + h.assertTrue(((SteamMachineEntity) moved).items.getStackInSlot(0).getCount() == 3, "Drill preserves inventory"); + h.assertTrue(h.getLevel().getEntitiesOfClass(net.minecraft.world.entity.item.ItemEntity.class, + new net.minecraft.world.phys.AABB(h.absolutePos(new BlockPos(3, 2, 3))).inflate(2)) + .isEmpty(), "Moving drops nothing"); h.assertTrue(h.getBlockState(new BlockPos(3, 2, 3)).is(ModContent.block("steam_pipe")), "Drill leaves steam pipe"); h.succeed(); @@ -824,13 +928,15 @@ public static void drillMovesAlongTrackWithoutLosingInventory(GameTestHelper h) public static void drillBreaksBlocksAtDiamondPickaxeSpeed(GameTestHelper h) { var level = h.getLevel(); var p = h.absolutePos(BlockPos.ZERO); - // Vanilla diamond pickaxe ticks: stone 1.5*30/8, dirt (wrong tool) 0.5*30/1, obsidian 50*30/8. - h.assertTrue(DrillOperation.breakTicks(Blocks.STONE.defaultBlockState(), level, p) == 6, - "Stone breaks in 6 ticks"); - h.assertTrue(DrillOperation.breakTicks(Blocks.DIRT.defaultBlockState(), level, p) == 15, - "Dirt breaks in 15 ticks"); - h.assertTrue(DrillOperation.breakTicks(Blocks.OBSIDIAN.defaultBlockState(), level, p) == 188, - "Obsidian breaks in 188 ticks"); + // SA2 timing at the default 12 ticks per hardness, minimum 6. + h.assertTrue(DrillProcessor.breakTicks(Blocks.STONE.defaultBlockState(), level, p) == 18, + "Stone breaks in 18 ticks"); + h.assertTrue(DrillProcessor.breakTicks(Blocks.DIRT.defaultBlockState(), level, p) == 6, + "Dirt breaks in 6 ticks"); + h.assertTrue(DrillProcessor.breakTicks(Blocks.IRON_ORE.defaultBlockState(), level, p) == 36, + "Iron ore breaks in 36 ticks"); + h.assertTrue(DrillProcessor.breakTicks(Blocks.OBSIDIAN.defaultBlockState(), level, p) == 600, + "Obsidian breaks in 600 ticks"); h.succeed(); } @GameTest(template = "empty", timeoutTicks = 80) @@ -841,7 +947,7 @@ public static void starvedDrillPausesInsteadOfRetracting(GameTestHelper h) { h.runAfterDelay(5, () -> { h.assertTrue(h.getBlockState(new BlockPos(3, 2, 2)).is(ModContent.block("drillbit")), "Starved drill keeps its pipe extended"); - h.assertTrue(drill.getDrillDepth() == 1, "Starved drill keeps its depth"); + h.assertTrue(SteamScreens.drillDepth(drill) == 1, "Starved drill keeps its depth"); h.succeed(); }); } @@ -861,6 +967,19 @@ public static void elevatorExtendsAndRetracts(GameTestHelper h) { }); }); } + /** Pre-XML tanks and switches keep their steam. */ + @GameTest(template = "empty") + public static void preXmlTankAndSwitchSavesLoad(GameTestHelper h) { + for (String kind : java.util.List.of("steam_tank", "steam_switch")) { + var imported = importLegacy(h, kind); + h.assertTrue(imported.fluids.tank(0).getFluidAmount() == 4321 + && imported.fluids.tank(0).getFluid().getFluid() + == zone.moddev.mc.poweradvantage.init.Fluids.STEAM.get(), + kind + " keeps its pre-XML steam"); + } + h.succeed(); + } + @GameTest(template = "empty", timeoutTicks = 80) public static void valveStopsOutputWhenPowered(GameTestHelper h) { var valve = place(h, "steam_switch", 3, 2, 3); @@ -909,14 +1028,15 @@ public static void distillationUsesPowerAdvantageDefaultRecipe(GameTestHelper h) "Running still melts snow above it"); h.assertTrue(still.fluids.tank(2).isEmpty(), "Input is consumed when operation starts"); h.assertTrue(still.fluids.tank(1).isEmpty(), "Output waits for recipe duration"); - h.assertTrue(still.getProgress() == 1 && still.getProgressMax() == 100, + h.assertTrue(zone.moddev.mc.SteamAdvantage.machines.SteamScreens.distillProgress(still) == 1 + && zone.moddev.mc.SteamAdvantage.machines.SteamScreens.distillDuration(still) == 100, "PA3 recipe duration drives progress"); h.runAfterDelay(99, () -> { h.assertTrue(still.fluids.tank(1).getFluidAmount() == 50 && still.fluids.tank(1).getFluid().getFluid() == refinedOil, "PA3's built-in recipe converts crude oil to refined oil"); h.assertTrue(still.fluids.tank(0).isEmpty(), "Steam is charged once per operation"); - h.assertTrue(still.getProgress() == 0, "Completed operation clears progress"); + h.assertTrue(SteamScreens.distillProgress(still) == 0, "Completed operation clears progress"); h.succeed(); }); }); @@ -928,10 +1048,11 @@ public static void distillationProgressPersistsUntilOutput(GameTestHelper h) { still.fluids.tank(0).fill(steam(150), FluidAction.EXECUTE); still.fluids.tank(2).fill(new FluidStack(Fluids.WATER, 1000), FluidAction.EXECUTE); h.runAfterDelay(10, () -> { - h.assertTrue(still.getProgress() == 10 && still.getProgressMax() == 20, + h.assertTrue(SteamScreens.distillProgress(still) == 10 + && SteamScreens.distillDuration(still) == 20, "Timed recipe accumulates progress"); h.assertTrue(still.fluids.tank(2).isEmpty() - && still.pendingDistillation.getAmount() == 100, + && processor(still, StillProcessor.class).pending().getAmount() == 100, "Input and pending output persist during processing"); var saved = still.saveWithoutMetadata(h.getLevel().registryAccess()); still.loadWithComponents(saved, h.getLevel().registryAccess()); @@ -939,7 +1060,7 @@ public static void distillationProgressPersistsUntilOutput(GameTestHelper h) { h.assertTrue(still.fluids.tank(1).getFluidAmount() == 100 && still.fluids.tank(1).getFluid().getFluid() == Fluids.LAVA, "Saved operation completes after the remaining duration"); - h.assertTrue(still.pendingDistillation.isEmpty(), "Completed output is cleared"); + h.assertTrue(processor(still, StillProcessor.class).pending().isEmpty(), "Completed output is cleared"); h.succeed(); }); }); @@ -956,7 +1077,7 @@ public static void distillationBlockedOutputDoesNotConsumeResources(GameTestHelp "Blocked output preserves steam"); h.assertTrue(still.fluids.tank(2).getFluidAmount() == 1000, "Blocked output preserves input"); - h.assertTrue(still.pendingDistillation.isEmpty(), + h.assertTrue(processor(still, StillProcessor.class).pending().isEmpty(), "Blocked output does not start an operation"); h.succeed(); }); @@ -981,44 +1102,27 @@ public static void musketLoadsConsumesAmmoAndUnloads(GameTestHelper h) { public static void furnaceProcessesThreeLanes(GameTestHelper h) { var furnace = place(h, "steam_furnace", 2, 2, 2); furnace.fluids.fill(steam(20000), FluidAction.EXECUTE); - furnace.items.setStackInSlot(0, new ItemStack(Items.COAL)); - furnace.items.setStackInSlot(1, new ItemStack(Items.RAW_IRON)); - furnace.items.setStackInSlot(2, new ItemStack(Items.RAW_GOLD)); - furnace.items.setStackInSlot(3, new ItemStack(Items.RAW_COPPER)); + furnace.items.setStackInSlot(0, new ItemStack(Items.RAW_IRON)); + furnace.items.setStackInSlot(1, new ItemStack(Items.RAW_GOLD)); + furnace.items.setStackInSlot(2, new ItemStack(Items.RAW_COPPER)); h.setBlock(new BlockPos(2, 3, 2), Blocks.SNOW); - h.runAfterDelay(500, () -> { - h.assertTrue(furnace.items.getStackInSlot(4).is(Items.IRON_INGOT), "Furnace iron lane"); - h.assertTrue(furnace.items.getStackInSlot(5).is(Items.GOLD_INGOT), "Furnace gold lane"); + h.runAfterDelay(20, () -> h.assertTrue(h.getBlockState(new BlockPos(2, 3, 2)).isAir(), + "Running furnace melts snow above it")); + h.runAfterDelay(260, () -> { + h.assertTrue(furnace.items.getStackInSlot(3).is(Items.IRON_INGOT), "Furnace iron lane"); + h.assertTrue(furnace.items.getStackInSlot(4).is(Items.GOLD_INGOT), "Furnace gold lane"); h.assertTrue( - furnace.items.getStackInSlot(6).is(Items.COPPER_INGOT), "Furnace copper lane"); - h.assertTrue(h.getBlockState(new BlockPos(2, 3, 2)).isAir(), - "Running furnace melts snow above it"); + furnace.items.getStackInSlot(5).is(Items.COPPER_INGOT), "Furnace copper lane"); + h.assertTrue(furnace.fluids.tank(0).getFluidAmount() == 20000 - 3 * 2000, + "Each 200-tick smelt costs 2000 mB of steam"); h.succeed(); }); } @GameTest(template = "empty", timeoutTicks = 40) - public static void hotIdleFurnaceStillMeltsSnow(GameTestHelper h) { - var furnace = place(h, "steam_furnace", 2, 2, 2); - furnace.temperature = 1500; - h.setBlock(new BlockPos(2, 3, 2), Blocks.SNOW); - h.runAfterDelay(1, () -> { - h.assertTrue(h.getBlockState(new BlockPos(2, 3, 2)).isAir(), - "Furnace without fuel melts snow while it is still hot"); - furnace.temperature = 50; - h.setBlock(new BlockPos(2, 3, 2), Blocks.SNOW); - h.runAfterDelay(1, () -> { - h.assertTrue(h.getBlockState(new BlockPos(2, 3, 2)).is(Blocks.SNOW), - "Cool furnace does not melt snow"); - h.succeed(); - }); - }); - } - @GameTest(template = "empty", timeoutTicks = 40) public static void fullGeothermalBoilerStillMeltsSnow(GameTestHelper h) { var geo = place(h, "steam_boiler_geothermal", 2, 2, 2); - geo.fluids.tank(geo.steam).fill(steam(geo.fluids.tank(geo.steam).getCapacity()), - FluidAction.EXECUTE); - geo.temperature = 500; + geo.fluids.tank(0).fill(steam(geo.fluids.tank(0).getCapacity()), FluidAction.EXECUTE); + processor(geo, GeothermalBoilerProcessor.class).setTemperature(500); h.setBlock(new BlockPos(2, 3, 2), Blocks.SNOW); h.runAfterDelay(1, () -> { h.assertTrue(h.getBlockState(new BlockPos(2, 3, 2)).isAir(), @@ -1026,25 +1130,30 @@ public static void fullGeothermalBoilerStillMeltsSnow(GameTestHelper h) { h.succeed(); }); } - @GameTest(template = "empty", timeoutTicks = 40) - public static void furnaceCoolingClearsResidualTemperature(GameTestHelper h) { - var furnace = place(h, "steam_furnace", 2, 2, 2); - furnace.temperature = 0.005f; - FurnaceOperation.smelt(furnace); - h.assertTrue(furnace.getTemperature() == 0, - "Cooling snaps negligible residual temperature to zero"); - h.assertTrue(Float.isFinite(furnace.getTemperature()), - "Furnace temperature remains finite"); - h.succeed(); + /** Recipe-driven machines hold their work while powered, like every SteamAdvantage machine. */ + @GameTest(template = "empty", timeoutTicks = 60) + public static void poweredCrusherHoldsItsRecipe(GameTestHelper h) { + var crusher = place(h, "steam_crusher", 2, 2, 2); + h.setBlock(new BlockPos(3, 2, 2), Blocks.REDSTONE_BLOCK); + crusher.fluids.fill(steam(20000), FluidAction.EXECUTE); + crusher.items.setStackInSlot(0, new ItemStack(Items.COBBLESTONE)); + h.runAfterDelay(20, () -> { + h.assertTrue(crusher.fluids.tank(0).getFluidAmount() == 20000 + && crusher.items.getStackInSlot(0).getCount() == 1 + && crusher.items.getStackInSlot(1).isEmpty(), + "Powered crusher does not work"); + h.succeed(); + }); } @GameTest(template = "empty", timeoutTicks = 40) public static void fullCrusherOutputDoesNotConsumeResources(GameTestHelper h) { var crusher = place(h, "steam_crusher", 2, 2, 2); - crusher.fluids.fill(steam(1000), FluidAction.EXECUTE); + crusher.fluids.fill(steam(20000), FluidAction.EXECUTE); crusher.items.setStackInSlot(0, new ItemStack(Items.COBBLESTONE)); - crusher.items.setStackInSlot(4, new ItemStack(Items.GRAVEL, 64)); + for (int slot = 1; slot <= 5; slot++) + crusher.items.setStackInSlot(slot, new ItemStack(Items.DIAMOND, 64)); h.runAfterDelay(10, () -> { - h.assertTrue(crusher.fluids.tank(0).getFluidAmount() == 1000, + h.assertTrue(crusher.fluids.tank(0).getFluidAmount() == 20000, "Blocked output preserves steam"); h.assertTrue(crusher.items.getStackInSlot(0).getCount() == 1, "Blocked output preserves input"); @@ -1052,35 +1161,21 @@ public static void fullCrusherOutputDoesNotConsumeResources(GameTestHelper h) { }); } + /** + * A test-only machine (gameTest resources, excluded from releases) extends the steam tank in + * XML alone, changing its capacity, and gets its own block, entity and processor. + */ @GameTest(template = "empty") - public static void standaloneVariantNeedsNoJavaRegistration(GameTestHelper h) { + public static void xmlVariantNeedsNoJavaRegistration(GameTestHelper h) { var variant = place(h, "test_large_steam_tank", 2, 2, 2); - h.assertTrue(variant.getSteamCapacity() == 2345678, "MMDLib decoded variant capacity"); - h.assertTrue(variant.items().getSlots() == 12, "MMDLib decoded variant inventory size"); + h.assertTrue(variant.fluids.tank(0).getCapacity() == 2345678, "Inherited tank resized"); h.assertTrue(net.minecraft.core.registries.BuiltInRegistries.BLOCK_ENTITY_TYPE .getKey(variant.getType()) .equals(ModContent.id("test_large_steam_tank")), - "Standalone block entity has its own ID"); - h.assertTrue(zone.moddev.mc.lib.MMDLib.standaloneBlocks().containsKey( - ModContent.id("test_large_steam_tank")), - "Variant came through MMDLib's standalone loader"); - h.assertTrue(!zone.moddev.mc.lib.MMDLib.loadedMaterials().keySet().stream().anyMatch( - id -> id.getNamespace().equals(SteamAdvantage.MODID)), - "No synthetic SteamAdvantage materials"); - variant.fluids().fill(steam(1234567), FluidAction.EXECUTE); - var bound = zone.moddev.mc.lib.gui.Screens - .get(net.minecraft.core.registries.BuiltInRegistries.BLOCK_ENTITY_TYPE - .getKey(variant.getType())) - .orElseThrow(); - var element = bound.screen().find("steam").orElseThrow(); - try { - var fluid = (FluidStack) bound.values().get(element).read(variant); - var capacity = (Number) bound.maxima().get(element).read(variant); - h.assertTrue(fluid.getAmount() == 1234567 && capacity.intValue() == 2345678, - "XML getters bind to variant storage"); - } catch (Throwable failure) { - throw new IllegalStateException("Bound XML getter failed", failure); - } + "Variant block entity has its own ID"); + h.assertTrue(variant.features.allProcessors().stream() + .anyMatch(SteamTankProcessor.class::isInstance), + "Variant inherits the tank processor"); h.succeed(); } @GameTest(template = "empty") @@ -1107,33 +1202,28 @@ public static void standaloneItemsAndScreenCatalog(GameTestHelper h) { } @GameTest(template = "empty") - public static void declarativeMenuRespectsHiddenSlotsAndRoles(GameTestHelper h) { + public static void declarativeMenuRespectsSlotRoles(GameTestHelper h) { var crusher = place(h, "steam_crusher", 2, 2, 2); var player = h.makeMockPlayer(net.minecraft.world.level.GameType.SURVIVAL); player.setPos(crusher.getBlockPos().getX() + .5, crusher.getBlockPos().getY() + .5, crusher.getBlockPos().getZ() + .5); var menu = new zone.moddev.mc.lib.gui.runtime.MachineMenu(1, player.getInventory(), crusher); - h.assertTrue(menu.slots.get(0).isActive() && menu.slots.get(4).isActive(), + h.assertTrue(menu.slots.get(0).isActive() && menu.slots.get(1).isActive(), "XML declares input/output slots"); - h.assertTrue(!menu.slots.get(1).isActive() - && !menu.slots.get(1).mayPlace(new ItemStack(Items.COBBLESTONE)), - "Undeclared slot refuses clicks"); - h.assertTrue(!menu.slots.get(4).mayPlace(new ItemStack(Items.GRAVEL)), + h.assertTrue(!menu.slots.get(1).mayPlace(new ItemStack(Items.GRAVEL)), "Output role refuses insertion"); player.getInventory().setItem(0, new ItemStack(Items.COBBLESTONE, 3)); - // MMDLib 2.0.2 also adds armor and offhand slots, so locate hotbar slot 0 directly. int hotbar = menu.slots.stream() .filter(slot -> slot.container == player.getInventory() && slot.getContainerSlot() == 0) .findFirst().orElseThrow().index; menu.quickMoveStack(player, hotbar); - h.assertTrue(crusher.items().getStackInSlot(0).getCount() == 3, + h.assertTrue(crusher.items.getStackInSlot(0).getCount() == 3, "Shift-click follows declared input"); - crusher.items().setStackInSlot(4, new ItemStack(Items.GRAVEL, 2)); - menu.quickMoveStack(player, 4); + crusher.items.setStackInSlot(1, new ItemStack(Items.GRAVEL, 2)); + menu.quickMoveStack(player, 1); h.assertTrue( player.getInventory().countItem(Items.GRAVEL) == 2, "Shift-click extracts output"); - h.assertTrue(menu.slots.get(4).index == 4, "MMDLib preserves XML slot indices"); h.assertTrue(menu.stillValid(player), "Nearby original host is valid"); h.setBlock(new BlockPos(2, 2, 2), Blocks.AIR); h.assertTrue(!menu.stillValid(player), "Removed host invalidates menu"); @@ -1162,7 +1252,7 @@ public static void screenSnapshotsPreserveLargeAndFluidValues(GameTestHelper h) h.succeed(); } @GameTest(template = "empty") - public static void mismatchedScreenAndInvalidSettingsAreRejected(GameTestHelper h) { + public static void mismatchedScreenIsRejected(GameTestHelper h) { var tank = place(h, "steam_tank", 2, 2, 2); var player = h.makeMockPlayer(net.minecraft.world.level.GameType.SURVIVAL); var buffer = new net.minecraft.network.RegistryFriendlyByteBuf( @@ -1178,17 +1268,6 @@ public static void mismatchedScreenAndInvalidSettingsAreRejected(GameTestHelper buffer.release(); } h.assertTrue(rejected, "MMDLib rejects mismatched XML definitions"); - var invalid = com.google.gson.JsonParser.parseString( - "{\"kind\":\"steam_boiler_coal\",\"steam_capacity\":1000,\"water_capacity\":0}"); - boolean bad = false; - try { - bad = MachineSettings.CODEC.parse(com.mojang.serialization.JsonOps.INSTANCE, invalid) - .error() - .isPresent(); - } catch (IllegalArgumentException expected) { - bad = true; - } - h.assertTrue(bad, "DFU settings reject missing mandatory storage"); h.succeed(); } @GameTest(template = "empty") diff --git a/src/gameTest/resources/data/steamadvantage/legacy_saves/README.md b/src/gameTest/resources/data/steamadvantage/legacy_saves/README.md new file mode 100644 index 0000000..c6cfb1b --- /dev/null +++ b/src/gameTest/resources/data/steamadvantage/legacy_saves/README.md @@ -0,0 +1,8 @@ +# Pre-XML save fixtures + +Each file is a block entity saved by SteamAdvantage 3.1's shared `SteamMachine` entity, before +the machines became MMDLib XML definitions. They were captured from commit 74ffdb0 by building +the old entity with known contents and writing `NbtUtils.structureToSnbt` of +`saveWithFullMetadata` (position removed; the electric boiler's buffer renamed to the pre-2.0.2 +`Energy` key). `SteamGameTests.preXmlMachineSavesLoad` and `preXmlTankAndSwitchSavesLoad` load +them into the XML machines. Do not regenerate them from current code: the old entity is gone. diff --git a/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_boiler_coal.snbt b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_boiler_coal.snbt new file mode 100644 index 0000000..6cfaf7d --- /dev/null +++ b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_boiler_coal.snbt @@ -0,0 +1,107 @@ +{ + data: [], + palette: [], + Burn: 17, + Depth: 0, + DistillationDuration: 0, + DrillPhase: 0, + DrillRetractionTicks: 0, + ElevatorHeight: 0, + Fluids: { + Recovery: [], + Tanks: [ + {}, + { + Fluid: { + amount: 777, + id: "minecraft:water" + } + } + ] + }, + Items: { + Items: [ + { + Slot: 0, + count: 5, + id: "minecraft:coal" + } + ], + Recovery: [], + Size: 9 + }, + Progress: [I; 0, 0, 0], + Raised: 0b, + Temperature: 0.0f, + TotalBurn: 1600, + automation: { + groups: { + fuel: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "input", + bottom: "input", + front: "input", + left: "input", + right: "input", + top: "input" + } + }, + steam: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "output", + bottom: "output", + front: "output", + left: "output", + right: "output", + top: "output" + } + }, + water: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "input", + bottom: "input", + front: "input", + left: "input", + right: "input", + top: "input" + } + } + }, + recovery: [], + refund: 0L, + transfers: {}, + version: 1 + }, + features: {}, + id: "steamadvantage:steam_boiler_coal" +} \ No newline at end of file diff --git a/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_boiler_electric.snbt b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_boiler_electric.snbt new file mode 100644 index 0000000..f9cb34f --- /dev/null +++ b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_boiler_electric.snbt @@ -0,0 +1,97 @@ +{ + data: [], + palette: [], + Burn: 0, + Depth: 0, + DistillationDuration: 0, + DrillPhase: 0, + DrillRetractionTicks: 0, + ElevatorHeight: 0, + Energy: 1234L, + Fluids: { + Recovery: [], + Tanks: [ + {}, + {} + ] + }, + Items: { + Items: [], + Recovery: [], + Size: 9 + }, + Progress: [I; 0, 0, 0], + Raised: 0b, + Temperature: 0.0f, + TotalBurn: 0, + automation: { + groups: { + energy: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "input", + bottom: "input", + front: "input", + left: "input", + right: "input", + top: "input" + } + }, + steam: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "output", + bottom: "output", + front: "output", + left: "output", + right: "output", + top: "output" + } + }, + water: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "input", + bottom: "input", + front: "input", + left: "input", + right: "input", + top: "input" + } + } + }, + recovery: [], + refund: 0L, + transfers: {}, + version: 1 + }, + features: {}, + id: "steamadvantage:steam_boiler_electric" +} \ No newline at end of file diff --git a/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_boiler_geothermal.snbt b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_boiler_geothermal.snbt new file mode 100644 index 0000000..f7cec49 --- /dev/null +++ b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_boiler_geothermal.snbt @@ -0,0 +1,76 @@ +{ + data: [], + palette: [], + Burn: 0, + Depth: 0, + DistillationDuration: 0, + DrillPhase: 0, + DrillRetractionTicks: 0, + ElevatorHeight: 0, + Fluids: { + Recovery: [], + Tanks: [ + {}, + {} + ] + }, + Items: { + Items: [], + Recovery: [], + Size: 9 + }, + Progress: [I; 0, 0, 0], + Raised: 0b, + Temperature: 640.0f, + TotalBurn: 0, + automation: { + groups: { + steam: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "output", + bottom: "output", + front: "output", + left: "output", + right: "output", + top: "output" + } + }, + water: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "input", + bottom: "input", + front: "input", + left: "input", + right: "input", + top: "input" + } + } + }, + recovery: [], + refund: 0L, + transfers: {}, + version: 1 + }, + features: {}, + id: "steamadvantage:steam_boiler_geothermal" +} \ No newline at end of file diff --git a/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_boiler_oil.snbt b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_boiler_oil.snbt new file mode 100644 index 0000000..be5993f --- /dev/null +++ b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_boiler_oil.snbt @@ -0,0 +1,102 @@ +{ + data: [], + palette: [], + Burn: 40, + Depth: 0, + DistillationDuration: 0, + DrillPhase: 0, + DrillRetractionTicks: 0, + ElevatorHeight: 0, + Fluids: { + Recovery: [], + Tanks: [ + {}, + {}, + { + Fluid: { + amount: 900, + id: "minecraft:lava" + } + } + ] + }, + Items: { + Items: [], + Recovery: [], + Size: 9 + }, + Progress: [I; 0, 0, 0], + Raised: 0b, + Temperature: 0.0f, + TotalBurn: 100, + automation: { + groups: { + fuel: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "input", + bottom: "input", + front: "input", + left: "input", + right: "input", + top: "input" + } + }, + steam: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "output", + bottom: "output", + front: "output", + left: "output", + right: "output", + top: "output" + } + }, + water: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "input", + bottom: "input", + front: "input", + left: "input", + right: "input", + top: "input" + } + } + }, + recovery: [], + refund: 0L, + transfers: {}, + version: 1 + }, + features: {}, + id: "steamadvantage:steam_boiler_oil" +} \ No newline at end of file diff --git a/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_crusher.snbt b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_crusher.snbt new file mode 100644 index 0000000..d19d0d8 --- /dev/null +++ b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_crusher.snbt @@ -0,0 +1,111 @@ +{ + data: [], + palette: [], + Burn: 0, + Depth: 0, + DistillationDuration: 0, + DrillPhase: 0, + DrillRetractionTicks: 0, + ElevatorHeight: 0, + Fluids: { + Recovery: [], + Tanks: [ + { + Fluid: { + amount: 5000, + id: "poweradvantage:steam" + } + } + ] + }, + Items: { + Items: [ + { + Slot: 0, + count: 3, + id: "minecraft:cobblestone" + }, + { + Slot: 4, + count: 4, + id: "minecraft:gravel" + } + ], + Recovery: [], + Size: 9 + }, + Progress: [I; 40, 0, 0], + Raised: 0b, + Temperature: 0.0f, + TotalBurn: 0, + automation: { + groups: { + input: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "input", + bottom: "input", + front: "input", + left: "input", + right: "input", + top: "input" + } + }, + output: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "output", + bottom: "output", + front: "output", + left: "output", + right: "output", + top: "output" + } + }, + steam: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "input", + bottom: "input", + front: "input", + left: "input", + right: "input", + top: "input" + } + } + }, + recovery: [], + refund: 0L, + transfers: {}, + version: 1 + }, + features: {}, + id: "steamadvantage:steam_crusher" +} \ No newline at end of file diff --git a/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_drill.snbt b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_drill.snbt new file mode 100644 index 0000000..aaf470c --- /dev/null +++ b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_drill.snbt @@ -0,0 +1,86 @@ +{ + data: [], + palette: [], + Burn: 0, + Depth: 9, + DistillationDuration: 0, + DrillPhase: 1, + DrillRetractionTicks: 2, + ElevatorHeight: 0, + Fluids: { + Recovery: [], + Tanks: [ + {} + ] + }, + Items: { + Items: [ + { + Slot: 4, + count: 12, + id: "minecraft:cobblestone" + }, + { + Slot: 8, + count: 2, + id: "minecraft:flint" + } + ], + Recovery: [], + Size: 9 + }, + Progress: [I; 5, 0, 0], + Raised: 0b, + Temperature: 0.0f, + TotalBurn: 0, + automation: { + groups: { + output: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "output", + bottom: "output", + front: "output", + left: "output", + right: "output", + top: "output" + } + }, + steam: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "input", + bottom: "input", + front: "input", + left: "input", + right: "input", + top: "input" + } + } + }, + recovery: [], + refund: 0L, + transfers: {}, + version: 1 + }, + features: {}, + id: "steamadvantage:steam_drill" +} \ No newline at end of file diff --git a/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_elevator.snbt b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_elevator.snbt new file mode 100644 index 0000000..db83d84 --- /dev/null +++ b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_elevator.snbt @@ -0,0 +1,55 @@ +{ + data: [], + palette: [], + Burn: 0, + Depth: 0, + DistillationDuration: 0, + DrillPhase: 0, + DrillRetractionTicks: 0, + ElevatorHeight: 5, + Fluids: { + Recovery: [], + Tanks: [ + {} + ] + }, + Items: { + Items: [], + Recovery: [], + Size: 9 + }, + Progress: [I; 0, 0, 0], + Raised: 1b, + Temperature: 0.0f, + TotalBurn: 0, + automation: { + groups: { + steam: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "input", + bottom: "input", + front: "input", + left: "input", + right: "input", + top: "input" + } + } + }, + recovery: [], + refund: 0L, + transfers: {}, + version: 1 + }, + features: {}, + id: "steamadvantage:steam_elevator" +} \ No newline at end of file diff --git a/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_furnace.snbt b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_furnace.snbt new file mode 100644 index 0000000..3cdd904 --- /dev/null +++ b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_furnace.snbt @@ -0,0 +1,141 @@ +{ + data: [], + palette: [], + Burn: 100, + Depth: 0, + DistillationDuration: 0, + DrillPhase: 0, + DrillRetractionTicks: 0, + ElevatorHeight: 0, + Fluids: { + Recovery: [], + Tanks: [ + { + Fluid: { + amount: 6000, + id: "poweradvantage:steam" + } + } + ] + }, + Items: { + Items: [ + { + Slot: 0, + count: 2, + id: "minecraft:coal" + }, + { + Slot: 1, + count: 1, + id: "minecraft:raw_iron" + }, + { + Slot: 2, + count: 2, + id: "minecraft:raw_gold" + }, + { + Slot: 4, + count: 3, + id: "minecraft:iron_ingot" + } + ], + Recovery: [], + Size: 9 + }, + Progress: [I; 0, 500, 0], + Raised: 0b, + Temperature: 900.0f, + TotalBurn: 1600, + automation: { + groups: { + fuel: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "input", + bottom: "input", + front: "input", + left: "input", + right: "input", + top: "input" + } + }, + input: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "input", + bottom: "input", + front: "input", + left: "input", + right: "input", + top: "input" + } + }, + output: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "output", + bottom: "output", + front: "output", + left: "output", + right: "output", + top: "output" + } + }, + steam: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "input", + bottom: "input", + front: "input", + left: "input", + right: "input", + top: "input" + } + } + }, + recovery: [], + refund: 0L, + transfers: {}, + version: 1 + }, + features: {}, + id: "steamadvantage:steam_furnace" +} \ No newline at end of file diff --git a/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_pump.snbt b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_pump.snbt new file mode 100644 index 0000000..b827654 --- /dev/null +++ b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_pump.snbt @@ -0,0 +1,81 @@ +{ + data: [], + palette: [], + Burn: 0, + Depth: 0, + DistillationDuration: 0, + DrillPhase: 0, + DrillRetractionTicks: 0, + ElevatorHeight: 0, + Fluids: { + Recovery: [], + Tanks: [ + {}, + { + Fluid: { + amount: 2000, + id: "minecraft:water" + } + } + ] + }, + Items: { + Items: [], + Recovery: [], + Size: 9 + }, + Progress: [I; 0, 0, 0], + Raised: 0b, + Temperature: 0.0f, + TotalBurn: 0, + automation: { + groups: { + product: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "output", + bottom: "output", + front: "output", + left: "output", + right: "output", + top: "output" + } + }, + steam: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "input", + bottom: "input", + front: "input", + left: "input", + right: "input", + top: "input" + } + } + }, + recovery: [], + refund: 0L, + transfers: {}, + version: 1 + }, + features: {}, + id: "steamadvantage:steam_pump" +} \ No newline at end of file diff --git a/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_still.snbt b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_still.snbt new file mode 100644 index 0000000..898484e --- /dev/null +++ b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_still.snbt @@ -0,0 +1,106 @@ +{ + data: [], + palette: [], + Burn: 0, + Depth: 0, + DistillationDuration: 20, + DrillPhase: 0, + DrillRetractionTicks: 0, + ElevatorHeight: 0, + Fluids: { + Recovery: [], + Tanks: [ + {}, + {}, + { + Fluid: { + amount: 300, + id: "minecraft:water" + } + } + ] + }, + Items: { + Items: [], + Recovery: [], + Size: 9 + }, + PendingDistillation: { + amount: 100, + id: "minecraft:lava" + }, + Progress: [I; 7, 0, 0], + Raised: 0b, + Temperature: 0.0f, + TotalBurn: 0, + automation: { + groups: { + input: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "input", + bottom: "input", + front: "input", + left: "input", + right: "input", + top: "input" + } + }, + product: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "output", + bottom: "output", + front: "output", + left: "output", + right: "output", + top: "output" + } + }, + steam: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "input", + bottom: "input", + front: "input", + left: "input", + right: "input", + top: "input" + } + } + }, + recovery: [], + refund: 0L, + transfers: {}, + version: 1 + }, + features: {}, + id: "steamadvantage:steam_still" +} \ No newline at end of file diff --git a/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_switch.snbt b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_switch.snbt new file mode 100644 index 0000000..d659309 --- /dev/null +++ b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_switch.snbt @@ -0,0 +1,60 @@ +{ + data: [], + palette: [], + Burn: 0, + Depth: 0, + DistillationDuration: 0, + DrillPhase: 0, + DrillRetractionTicks: 0, + ElevatorHeight: 0, + Fluids: { + Recovery: [], + Tanks: [ + { + Fluid: { + amount: 4321, + id: "poweradvantage:steam" + } + } + ] + }, + Items: { + Items: [], + Recovery: [], + Size: 9 + }, + Progress: [I; 0, 0, 0], + Raised: 0b, + Temperature: 0.0f, + TotalBurn: 0, + automation: { + groups: { + steam: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "input", + bottom: "input", + front: "input", + left: "input", + right: "input", + top: "input" + } + } + }, + recovery: [], + refund: 0L, + transfers: {}, + version: 1 + }, + features: {}, + id: "steamadvantage:steam_switch" +} \ No newline at end of file diff --git a/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_tank.snbt b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_tank.snbt new file mode 100644 index 0000000..050ff33 --- /dev/null +++ b/src/gameTest/resources/data/steamadvantage/legacy_saves/steam_tank.snbt @@ -0,0 +1,60 @@ +{ + data: [], + palette: [], + Burn: 0, + Depth: 0, + DistillationDuration: 0, + DrillPhase: 0, + DrillRetractionTicks: 0, + ElevatorHeight: 0, + Fluids: { + Recovery: [], + Tanks: [ + { + Fluid: { + amount: 4321, + id: "poweradvantage:steam" + } + } + ] + }, + Items: { + Items: [], + Recovery: [], + Size: 9 + }, + Progress: [I; 0, 0, 0], + Raised: 0b, + Temperature: 0.0f, + TotalBurn: 0, + automation: { + groups: { + steam: { + contents: [ + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + ], + sides: { + back: "both", + bottom: "both", + front: "both", + left: "both", + right: "both", + top: "both" + } + } + }, + recovery: [], + refund: 0L, + transfers: {}, + version: 1 + }, + features: {}, + id: "steamadvantage:steam_tank" +} \ No newline at end of file diff --git a/src/gameTest/resources/mmdlib/machine/test_large_steam_tank.xml b/src/gameTest/resources/mmdlib/machine/test_large_steam_tank.xml new file mode 100644 index 0000000..7a80a66 --- /dev/null +++ b/src/gameTest/resources/mmdlib/machine/test_large_steam_tank.xml @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/src/gameTest/resources/mmdlib/screen/test_large_steam_tank.xml b/src/gameTest/resources/mmdlib/screen/test_large_steam_tank.xml deleted file mode 100644 index b212253..0000000 --- a/src/gameTest/resources/mmdlib/screen/test_large_steam_tank.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - diff --git a/src/gameTest/resources/mmdlib/standalone/block/test_large_steam_tank.json b/src/gameTest/resources/mmdlib/standalone/block/test_large_steam_tank.json deleted file mode 100644 index 74621f5..0000000 --- a/src/gameTest/resources/mmdlib/standalone/block/test_large_steam_tank.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "module": "steamadvantage:machine", - "block_entity_data": { - "kind": "steam_tank", - "steam_capacity": 2345678, - "inventory_size": 12, - "energy_capacity": 0, - "energy_transfer": 0 - } -} diff --git a/src/guiSmoke/java/zone/moddev/mc/SteamAdvantage/smoke/GuiSmokeClient.java b/src/guiSmoke/java/zone/moddev/mc/SteamAdvantage/smoke/GuiSmokeClient.java index e3622b6..76b23ef 100644 --- a/src/guiSmoke/java/zone/moddev/mc/SteamAdvantage/smoke/GuiSmokeClient.java +++ b/src/guiSmoke/java/zone/moddev/mc/SteamAdvantage/smoke/GuiSmokeClient.java @@ -43,12 +43,25 @@ static void tick(ClientTickEvent.Post event) { } if (++settled < 10 || captured.contains(name)) return; - var steam = menu.bound.screen().find("steam").orElseThrow(); - if (((Number) menu.value(steam, true)).doubleValue() <= 0 - || !(menu.value(steam, false) - instanceof net.neoforged.neoforge.fluids.FluidStack fluid) - || fluid.getAmount() <= 0) - throw new IllegalStateException("XML getter synchronization failed for " + name); + var steam = menu.bound.screen().find("steam"); + if (steam.isPresent()) { + // Hand-written screens bind their steam gauge through XML getters. + if (((Number) menu.value(steam.get(), true)).doubleValue() <= 0 + || !(menu.value(steam.get(), false) + instanceof net.neoforged.neoforge.fluids.FluidStack fluid) + || fluid.getAmount() <= 0) + throw new IllegalStateException("XML getter synchronization failed for " + name); + } else { + // MMDLib's generated tank gauges on XML machines sync their own element state. + var tanks = new ArrayList(); + menu.bound.screen().forEach(element -> { + if (element instanceof zone.moddev.mc.lib.gui.model.elements.FluidTankElement) + tanks.add(element); + }); + // Their fill is checked in the captured screenshot. + if (tanks.isEmpty()) + throw new IllegalStateException("No tank gauge for " + name); + } var layout = screen.layout; if (layout.panel().width() > screen.width || layout.panel().height() > screen.height) throw new IllegalStateException("Screen does not fit: " + name + " " + layout.panel() @@ -62,7 +75,8 @@ static void tick(ClientTickEvent.Post event) { captured.add(name); org.slf4j.LoggerFactory.getLogger(GuiSmokeClient.class) .info("GUI_SMOKE_CAPTURE {} steam={} capacity={}", name, - menu.value(steam, false), menu.value(steam, true)); + steam.map(e -> menu.value(e, false)).orElse("generated"), + steam.map(e -> menu.value(e, true)).orElse("generated")); if (captured.size() == ModContent.MACHINES.size()) { Files.writeString(minecraft.gameDirectory.toPath().resolve("GUI_SMOKE_PASS.txt"), String.join("\n", captured) + "\n"); diff --git a/src/guiSmoke/java/zone/moddev/mc/SteamAdvantage/smoke/GuiSmokeServer.java b/src/guiSmoke/java/zone/moddev/mc/SteamAdvantage/smoke/GuiSmokeServer.java index 67a0e79..da7bea7 100644 --- a/src/guiSmoke/java/zone/moddev/mc/SteamAdvantage/smoke/GuiSmokeServer.java +++ b/src/guiSmoke/java/zone/moddev/mc/SteamAdvantage/smoke/GuiSmokeServer.java @@ -12,7 +12,6 @@ import net.neoforged.neoforge.fluids.capability.IFluidHandler.FluidAction; import zone.moddev.mc.SteamAdvantage.SteamAdvantage; import zone.moddev.mc.SteamAdvantage.init.ModContent; -import zone.moddev.mc.SteamAdvantage.machines.SteamMachine; /** Opt-in disposable-world fixture. Never included in released mods. */ @EventBusSubscriber(modid = SteamAdvantage.MODID) @@ -33,28 +32,15 @@ static void tick(ServerTickEvent.Post event) { var pos = pending; pending = null; var name = ModContent.MACHINES.get(index - 1); - var machine = (SteamMachine) level.getBlockEntity(pos); - machine.fluids().tank(0).fill( + var xml = (zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity) + level.getBlockEntity(pos); + xml.fluids.tank(0).fill( new FluidStack(zone.moddev.mc.poweradvantage.init.Fluids.STEAM.get(), - machine.getSteamCapacity() * 3 / 4), + xml.fluids.tank(0).getCapacity() * 3 / 4), FluidAction.EXECUTE); - for (int tank = 1; tank < machine.fluids().getTanks(); tank++) { - machine.fluids().tank(tank).fill( - new FluidStack(net.minecraft.world.level.material.Fluids.WATER, 2000), - FluidAction.EXECUTE); - } - machine.energy().setStored(1200); - machine.items().setStackInSlot(0, new ItemStack(Items.COAL, 8)); - if (name.equals("steam_furnace")) - for (int i = 1; i <= 3; i++) - machine.items().setStackInSlot(i, new ItemStack(Items.RAW_IRON, 8)); - if (name.equals("steam_crusher")) - machine.items().setStackInSlot(0, new ItemStack(Items.COBBLESTONE, 8)); - player.setItemInHand(net.minecraft.world.InteractionHand.MAIN_HAND, ItemStack.EMPTY); - player.gameMode.useItemOn(player, level, ItemStack.EMPTY, - net.minecraft.world.InteractionHand.MAIN_HAND, - new BlockHitResult( - Vec3.atCenterOf(pos), net.minecraft.core.Direction.UP, pos, false)); + // Hold processing so the machine does not empty itself before the capture. + level.setBlockAndUpdate(pos.above(), Blocks.REDSTONE_BLOCK.defaultBlockState()); + openMenu(player, level, pos); return; } if (++ticks % 60 != 0) @@ -66,4 +52,12 @@ static void tick(ServerTickEvent.Post event) { level.setBlockAndUpdate(pos, ModContent.block(name).defaultBlockState()); pending = pos; } + private static void openMenu(net.minecraft.server.level.ServerPlayer player, + net.minecraft.server.level.ServerLevel level, BlockPos pos) { + player.setItemInHand(net.minecraft.world.InteractionHand.MAIN_HAND, ItemStack.EMPTY); + player.gameMode.useItemOn(player, level, ItemStack.EMPTY, + net.minecraft.world.InteractionHand.MAIN_HAND, + new BlockHitResult( + Vec3.atCenterOf(pos), net.minecraft.core.Direction.UP, pos, false)); + } } diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/SteamAdvantage.java b/src/main/java/zone/moddev/mc/SteamAdvantage/SteamAdvantage.java index 1ded233..296f133 100644 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/SteamAdvantage.java +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/SteamAdvantage.java @@ -15,5 +15,10 @@ public final class SteamAdvantage { public SteamAdvantage(IEventBus bus, ModContainer container) { container.registerConfig(ModConfig.Type.COMMON, SteamConfig.SPEC); ModContent.register(bus); + // XML machines use SteamMachineEntity, which imports saves from before the XML port. + for (String machine : ModContent.MACHINES) + zone.moddev.mc.lib.machine.neoforge.MachineContent.registerEntityFactory( + ModContent.id(machine), + zone.moddev.mc.SteamAdvantage.machines.SteamMachineEntity::new); } } diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/blocks/DrillBitBlock.java b/src/main/java/zone/moddev/mc/SteamAdvantage/blocks/DrillBitBlock.java index db2bbf2..b90c0b0 100644 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/blocks/DrillBitBlock.java +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/blocks/DrillBitBlock.java @@ -12,7 +12,6 @@ import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import zone.moddev.mc.SteamAdvantage.init.ModContent; -import zone.moddev.mc.SteamAdvantage.machines.SteamMachine; public final class DrillBitBlock extends zone.moddev.mc.lib.common.runtime.MaterialEntityBlock { // Removing a segment invokes onRemove again; keep long lines off the call stack. @@ -48,8 +47,11 @@ protected void onRemove(BlockState state, Level level, BlockPos pos, ModContent.block("steam_drill")) && level.getBlockState(cursor).getValue(BlockStateProperties.FACING) == direction.getOpposite() - && level.getBlockEntity(cursor) instanceof SteamMachine drill) { - drill.clearDrill(); + && level.getBlockEntity(cursor) + instanceof zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity drill) { + drill.features.allProcessors().stream() + .filter(zone.moddev.mc.SteamAdvantage.machines.DrillProcessor.class::isInstance) + .forEach(p -> ((zone.moddev.mc.SteamAdvantage.machines.DrillProcessor) p).clear()); drill.setChanged(); } } diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/config/SteamConfig.java b/src/main/java/zone/moddev/mc/SteamAdvantage/config/SteamConfig.java index 47f56fc..c27559d 100644 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/config/SteamConfig.java +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/config/SteamConfig.java @@ -11,7 +11,7 @@ public enum RecipeMode { NORMAL, TECH_PROGRESSION, APOCALYPTIC } public static final ModConfigSpec.EnumValue RECIPE_MODE; public static final ModConfigSpec SPEC; public static final ModConfigSpec.IntValue OIL_BURN_TICKS, RELOAD; - public static final ModConfigSpec.DoubleValue DAMAGE; + public static final ModConfigSpec.DoubleValue DAMAGE, DRILL_TICKS_PER_HARDNESS; public static final ModConfigSpec.BooleanValue MUSKETS; static { var builder = new ModConfigSpec.Builder(); @@ -20,6 +20,10 @@ public enum RecipeMode { NORMAL, TECH_PROGRESSION, APOCALYPTIC } RELOAD = builder.defineInRange("musketReloadTicks", 100, 20, 300); DAMAGE = builder.defineInRange("musketDamage", 20.0, 0, 100); MUSKETS = builder.define("musketsEnabled", true); + DRILL_TICKS_PER_HARDNESS = builder + .comment("Steam drill mining time: ticks per point of block hardness (stone 1.5,", + "obsidian 50), with a minimum of half this value. 12 matches Steam Advantage 2.") + .defineInRange("drillTicksPerHardness", 12.0, 0.1, 1000.0); SPEC = builder.build(); } public static TagKey fuelTag() { diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/init/ContentFactories.java b/src/main/java/zone/moddev/mc/SteamAdvantage/init/ContentFactories.java index ae9395d..580db6e 100644 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/init/ContentFactories.java +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/init/ContentFactories.java @@ -4,18 +4,13 @@ import com.mojang.datafixers.util.Unit; import java.util.function.Function; import net.minecraft.core.BlockPos; -import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.entity.BlockEntityTicker; import net.minecraft.world.level.block.entity.BlockEntityType; import zone.moddev.mc.SteamAdvantage.blocks.DrillBitBlock; import zone.moddev.mc.SteamAdvantage.blocks.DrillBitBlockEntity; import zone.moddev.mc.SteamAdvantage.blocks.PlatformBlock; import zone.moddev.mc.SteamAdvantage.blocks.PumpShaftBlock; import zone.moddev.mc.SteamAdvantage.items.MusketItem; -import zone.moddev.mc.SteamAdvantage.machines.MachineBlock; -import zone.moddev.mc.SteamAdvantage.machines.MachineSettings; -import zone.moddev.mc.SteamAdvantage.machines.SteamMachine; import zone.moddev.mc.lib.api.BlockContext; import zone.moddev.mc.lib.api.BlockImplementation; import zone.moddev.mc.lib.api.ItemContext; @@ -31,19 +26,6 @@ final class ContentFactories { private ContentFactories() {} static void register(MaterialExtensions api) { - api.registerBlockImplementation( - ModContent.id("machine"), new BlockImplementation() { - public Class blockClass() { - return MachineBlock.class; - } - public MachineBlock create(MMDMaterial material, MMDBlock definition) { - throw new IllegalStateException("Machine requires BlockContext"); - } - public MachineBlock create(BlockContext context) { - return new MachineBlock(context.properties(), - context.blockEntity().orElseThrow().as(SteamMachine.class)); - } - }); block(api, "platform", PlatformBlock.class, PlatformBlock::new); api.registerBlockImplementation(ModContent.id("drillbit"), new BlockImplementation() { public Class blockClass() { return DrillBitBlock.class; } @@ -80,24 +62,6 @@ public MusketItem create(ItemContext context) { return new MusketItem(context.properties()); } }); - zone.moddev.mc.lib.util.Registries.BLOCK_ENTITY_FACTORIES.register( - ModContent.id("machine"), new BlockEntityFactory() { - public Class blockEntityClass() { - return SteamMachine.class; - } - public Codec settingsCodec() { - return MachineSettings.CODEC; - } - public SteamMachine create(BlockEntityType type, BlockPos pos, - net.minecraft.world.level.block.state.BlockState state, - MMDBlockEntity definition, MachineSettings settings) { - return new SteamMachine(type, pos, state, settings); - } - public BlockEntityTicker ticker( - Level level, MMDBlockEntity definition, MachineSettings settings) { - return level.isClientSide ? null : SteamMachine::tick; - } - }); } private static void block(MaterialExtensions api, String name, Class type, Function diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/init/ModContent.java b/src/main/java/zone/moddev/mc/SteamAdvantage/init/ModContent.java index ae2acda..c1773b0 100644 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/init/ModContent.java +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/init/ModContent.java @@ -18,8 +18,6 @@ import net.neoforged.neoforge.registries.NeoForgeRegistries; import zone.moddev.mc.SteamAdvantage.SteamAdvantage; import zone.moddev.mc.SteamAdvantage.blocks.DrillBitBlockEntity; -import zone.moddev.mc.SteamAdvantage.machines.MachineBlock; -import zone.moddev.mc.SteamAdvantage.machines.SteamMachine; import zone.moddev.mc.SteamAdvantage.recipes.RecipeModeCondition; import zone.moddev.mc.lib.MMDLib; import zone.moddev.mc.lib.api.MaterialExtensions; @@ -38,7 +36,7 @@ public final class ModContent { private static final DeferredRegister> BLOCK_ENTITY_TYPES = DeferredRegister.create(Registries.BLOCK_ENTITY_TYPE, SteamAdvantage.MODID); private static RuntimeContentRegistrar runtime; - // Acceptance-test catalog, not an alternative registration list. Definitions own registration. + // Every machine is an MMDLib XML machine (mmdlib/machine/) whose entity is SteamMachineEntity. public static final List MACHINES = List.of("steam_boiler_coal", "steam_boiler_electric", "steam_boiler_geothermal", "steam_boiler_oil", "steam_tank", "steam_furnace", "steam_crusher", @@ -57,13 +55,6 @@ public static RuntimeContentRegistrar runtime() { return java.util.Objects.requireNonNull(runtime, "Content has not been initialized"); } @SuppressWarnings("unchecked") - public static BlockEntityType machineType(BlockState state) { - return (BlockEntityType) runtime() - .blockEntityTypes() - .get(BuiltInRegistries.BLOCK.getKey(state.getBlock())) - .get(); - } - @SuppressWarnings("unchecked") public static BlockEntityType drillBitType() { return (BlockEntityType) runtime().blockEntityTypes().get(id("drillbit")).get(); @@ -89,29 +80,8 @@ public static void register(IEventBus bus) { })); bus.addListener(ModContent::capabilities); } - @SuppressWarnings("unchecked") + /** Machine capabilities come from their XML definitions; pipes are Power Advantage's. */ private static void capabilities(RegisterCapabilitiesEvent event) { - runtime.blockEntityTypes().forEach((id, holder) -> { - if (!(block(id.getPath()) instanceof MachineBlock)) return; - var type = (BlockEntityType) holder.get(); - // Each face follows the machine's MMDLib automation groups; a null side keeps full - // role-based access, as before. - event.registerBlockEntity(Capabilities.ItemHandler.BLOCK, type, - (be, side) -> side == null - ? be.items().view(IoMode.BOTH) - : be.items().view(slot -> be.automation().mode( - ResourceType.ITEMS, slot, side))); - event.registerBlockEntity(Capabilities.FluidHandler.BLOCK, type, - (be, side) -> side == null - ? be.fluids().view(IoMode.BOTH) - : be.fluids().view(tank -> be.automation().mode( - ResourceType.FLUIDS, tank, side))); - event.registerBlockEntity(Capabilities.EnergyStorage.BLOCK, type, - (be, side) -> !be.kind().equals("steam_boiler_electric") ? null - : side == null ? be.energy().view(IoMode.INPUT) - : be.energy().view(() -> be.automation().mode( - ResourceType.ENERGY, 0, side))); - }); FluidPipeBlock.registerCapabilities( event, (FluidPipeBlock) block("steam_pipe"), (FluidPipeBlock) block("steam_track")); } diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/BoilerOperation.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/BoilerOperation.java deleted file mode 100644 index 39ea510..0000000 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/BoilerOperation.java +++ /dev/null @@ -1,59 +0,0 @@ -package zone.moddev.mc.SteamAdvantage.machines; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.material.Fluids; -import net.neoforged.neoforge.fluids.FluidStack; -import net.neoforged.neoforge.fluids.capability.IFluidHandler.FluidAction; -import zone.moddev.mc.SteamAdvantage.config.SteamConfig; - -/** Shared boiler conversion and heat logic. */ -final class BoilerOperation { - private BoilerOperation() {} - - static boolean boil(SteamMachine machine) { - // Geothermal heat comes from the surroundings, so it stays hot even when it can't boil. - boolean geothermalHot = - machine.kind.equals("steam_boiler_geothermal") && geothermalHeat(machine); - if (machine.fluids.tank(machine.water).isEmpty() - || machine.fluids.tank(machine.steam).getSpace() < 100) - return geothermalHot; - boolean heat = switch (machine.kind) { - case "steam_boiler_electric" -> machine.energy.consume(16); - case "steam_boiler_geothermal" -> geothermalHot; - case "steam_boiler_oil" -> { - if (machine.burn <= 0 - && machine.fluids.tank(machine.fuel).getFluidAmount() >= 100) { - machine.fluids.tank(machine.fuel).drain(100, FluidAction.EXECUTE); - machine.burn = machine.totalBurn = SteamConfig.OIL_BURN_TICKS.get(); - } - yield machine.burn-- > 0; - } - default -> machine.burnFuel(); - }; - if (heat) { - machine.fluids.tank(machine.water).drain(1, FluidAction.EXECUTE); - machine.fluids.tank(machine.steam) - .fill(new FluidStack(zone.moddev.mc.poweradvantage.init.Fluids.STEAM.get(), - machine.kind.equals("steam_boiler_electric") ? 50 : 100), - FluidAction.EXECUTE); - } - return heat; - } - - private static boolean geothermalHeat(SteamMachine machine) { - var level = machine.getLevel(); - var pos = machine.getBlockPos(); - int hot = 0; - for (Direction d : Direction.values()) { - BlockPos p = pos.relative(d); - if (level.hasChunkAt(p) - && (level.getFluidState(p).is(net.minecraft.tags.FluidTags.LAVA) - || level.getBlockState(p).is(Blocks.MAGMA_BLOCK))) - hot++; - } - machine.temperature = Math.min(2000, Math.max(0, machine.temperature + hot * 4 - 1)); - return machine.temperature >= 100; - } -} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/BoilerProcessor.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/BoilerProcessor.java new file mode 100644 index 0000000..b5b896a --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/BoilerProcessor.java @@ -0,0 +1,60 @@ +package zone.moddev.mc.SteamAdvantage.machines; + +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.capability.IFluidHandler.FluidAction; +import zone.moddev.mc.lib.machine.feature.ProcessorMachine; +import zone.moddev.mc.lib.machine.feature.ProcessorState; + +/** + * Shared boiler behavior: while unpowered, each tick a heated boiler turns 1 mB of water into + * steam and pushes up to 100 mB of steam out of every face. Tanks: steam (0), water (1). + */ +public abstract class BoilerProcessor extends SteamProcessor { + protected static final int WATER = 1; + + @Override + public boolean canStart(ProcessorState state, ProcessorMachine host) { + return !powered(); + } + + @Override + public ProcessState process(ProcessorState state, ProcessorMachine host, int ticks) { + boolean running = false; + for (int step = 0; step < ticks; step++) { + if (powered()) + return ProcessState.IDLE; + running |= boil(); + pushAllSides(STEAM, 100); + } + if (running) + meltSnow(); + return running ? ProcessState.RUNNING : ProcessState.IDLE; + } + + private boolean boil() { + // Surrounding heat (geothermal) is measured even when the boiler cannot boil. + boolean ambient = ambientHeat(); + if (tank(WATER).isEmpty() || tank(STEAM).getSpace() < 100) + return ambient; + boolean heat = heat(ambient); + if (heat) { + tank(WATER).drain(1, FluidAction.EXECUTE); + tank(STEAM).fill(new FluidStack( + zone.moddev.mc.poweradvantage.init.Fluids.STEAM.get(), steamPerTick()), + FluidAction.EXECUTE); + } + return heat; + } + + /** Heat from the surroundings, updated every unpowered tick. */ + protected boolean ambientHeat() { + return false; + } + + /** Spends this tick's fuel or energy; true when the boiler is heated. */ + protected abstract boolean heat(boolean ambient); + + protected int steamPerTick() { + return 100; + } +} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/Burner.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/Burner.java new file mode 100644 index 0000000..1e60b32 --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/Burner.java @@ -0,0 +1,8 @@ +package zone.moddev.mc.SteamAdvantage.machines; + +/** A processor with a fuel burn timer, shown by its screen's burn meter. */ +public interface Burner { + int burnTime(); + + int totalBurnTime(); +} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/CoalBoilerProcessor.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/CoalBoilerProcessor.java new file mode 100644 index 0000000..6832a6d --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/CoalBoilerProcessor.java @@ -0,0 +1,64 @@ +package zone.moddev.mc.SteamAdvantage.machines; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeType; +import zone.moddev.mc.lib.machine.feature.ProcessorMachine; +import zone.moddev.mc.lib.machine.feature.StorageAdmission; + +/** Coal boiler: burns any furnace fuel from its fuel slot (item slot 0). */ +public final class CoalBoilerProcessor extends BoilerProcessor implements StorageAdmission, Burner { + private final zone.moddev.mc.lib.machine.feature.ProcessorState.Key burn = + intVariable("burn"), totalBurn = intVariable("totalBurn"); + + @Override + protected boolean heat(boolean ambient) { + return burnFuel(entity(), variables, burn, totalBurn); + } + + /** Spends one tick of burn time, lighting the next fuel item from slot 0 when out. */ + static boolean burnFuel(zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity machine, + zone.moddev.mc.lib.machine.feature.ProcessorState variables, + zone.moddev.mc.lib.machine.feature.ProcessorState.Key burn, + zone.moddev.mc.lib.machine.feature.ProcessorState.Key totalBurn) { + if (variables.get(burn) > 0) { + variables.set(burn, variables.get(burn) - 1); + return true; + } + var items = machine.items; + ItemStack stack = items.getStackInSlot(0); + int ticks = stack.getBurnTime(RecipeType.SMELTING); + if (ticks <= 0) + return false; + ItemStack remainder = stack.getCraftingRemainingItem(); + ItemStack rest = stack.copyWithCount(stack.getCount() - 1); + items.setStackInSlot(0, rest.isEmpty() ? remainder : rest); + variables.set(burn, ticks); + variables.set(totalBurn, ticks); + return true; + } + + @Override + public boolean acceptsItem(ProcessorMachine host, String member, ItemStack stack) { + return stack.getBurnTime(RecipeType.SMELTING) > 0; + } + + @Override + void importLegacy(CompoundTag old, CompoundTag state) { + state.putInt("burn", old.getInt("Burn")); + state.putInt("totalBurn", old.getInt("TotalBurn")); + } + + @Override + protected int comparatorSignal() { + return inventorySignal(0, 1); + } + + public int burnTime() { + return variables.get(burn); + } + + public int totalBurnTime() { + return variables.get(totalBurn); + } +} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/CrusherOperation.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/CrusherOperation.java deleted file mode 100644 index 975a1ea..0000000 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/CrusherOperation.java +++ /dev/null @@ -1,29 +0,0 @@ -package zone.moddev.mc.SteamAdvantage.machines; - -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.SingleRecipeInput; -import zone.moddev.mc.lib.common.recipes.CrushingRecipe; - -/** MMDLib crushing recipe processing. */ -final class CrusherOperation { - private CrusherOperation() {} - - static void crush(SteamMachine machine) { - var level = machine.getLevel(); - var input = new SingleRecipeInput(machine.items.getStackInSlot(0)); - var recipe = level.getRecipeManager().getRecipeFor(CrushingRecipe.TYPE.get(), input, level); - if (recipe.isEmpty()) { - machine.progress[0] = 0; - return; - } - ItemStack output = recipe.get().value().assemble(input, level.registryAccess()); - if (!machine.items.fits(4, output) || !machine.hasSteam(150)) - return; - machine.spendSteam(150); - if (++machine.progress[0] >= 125) { - machine.progress[0] = 0; - machine.items.getStackInSlot(0).shrink(1); - machine.items.insertResult(4, output, false); - } - } -} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/DrillOperation.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/DrillOperation.java deleted file mode 100644 index 34ff13a..0000000 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/DrillOperation.java +++ /dev/null @@ -1,211 +0,0 @@ -package zone.moddev.mc.SteamAdvantage.machines; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.item.crafting.SingleRecipeInput; -import zone.moddev.mc.lib.common.recipes.CrushingRecipe; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.properties.BlockStateProperties; -import zone.moddev.mc.SteamAdvantage.init.ModContent; -import zone.moddev.mc.lib.api.capabilities.IoMode; -import zone.moddev.mc.lib.api.capabilities.Transfer; - -/** Drill extension, mining and track movement. */ -final class DrillOperation { - private DrillOperation() {} - - /** - * Maximum pipe length. SA2 used 64, which reached bedrock from sea level when the world - * bottom was y=0; with the floor now at -64, 128 covers sea level down to bedrock. - */ - static final int MAX_RANGE = 128; - - static void drill(SteamMachine machine) { - var level = machine.getLevel(); - var pos = machine.getBlockPos(); - Direction direction = machine.getBlockState().getValue(BlockStateProperties.FACING); - // Empty the output every tick, so a full inventory can drain and mining resume. - Transfer.pushItems( - level, pos, direction.getOpposite(), machine.items.view(IoMode.OUTPUT), 64); - if (machine.drillPhase == 1) { - retract(machine, direction); - return; - } - if (machine.drillPhase == 2) { - followTrack(machine); - return; - } - if (machine.depth >= MAX_RANGE) { - beginRetraction(machine); - return; - } - BlockPos target = pos.relative(direction, machine.depth + 1); - if (!level.isInWorldBounds(target)) { - // Reached the top or bottom of the world: treat it like bedrock. - beginRetraction(machine); - return; - } - if (!level.hasChunkAt(target)) - return; - BlockState state = level.getBlockState(target); - if (state.is(ModContent.block("drillbit"))) { - machine.depth++; - return; - } - if (state.getDestroySpeed(level, target) < 0 || state.hasBlockEntity()) { - beginRetraction(machine); - return; - } - // Air, fluids, plants etc. are simply displaced by the pipe rather than mined. - boolean replace = state.canBeReplaced(); - // Steam starvation pauses the drill rather than retracting its existing line. - if (!machine.hasSteam(replace ? 250 : 100)) - return; - if (!replace) { - var drops = miningDrops(state, (net.minecraft.server.level.ServerLevel) level, target); - // Simulate all drops together before altering the world. - var test = new net.neoforged.neoforge.items.ItemStackHandler(5); - for (int i = 0; i < 5; i++) - test.setStackInSlot(i, machine.items.getStackInSlot(i + 4).copy()); - for (ItemStack drop : drops) { - ItemStack remaining = drop.copy(); - for (int i = 0; i < 5; i++) remaining = test.insertItem(i, remaining, false); - if (!remaining.isEmpty()) - return; - } - // A blocked output must pause before mining consumes steam or progress. - int ticks = breakTicks(state, level, target); - if (machine.progress[0] < ticks) { - machine.spendSteam(100); - if (++machine.progress[0] < ticks) - return; - } - if (!level.destroyBlock(target, false)) - return; - machine.progress[0] = 0; - for (int i = 0; i < 5; i++) machine.items.setStackInSlot(i + 4, test.getStackInSlot(i)); - } else - machine.spendSteam(250); - level.setBlockAndUpdate(target, - ModContent.block("drillbit") - .defaultBlockState() - .setValue(BlockStateProperties.FACING, direction)); - machine.depth++; - } - - private static java.util.List miningDrops(BlockState state, - net.minecraft.server.level.ServerLevel level, BlockPos target) { - // SA2 crushed the block itself, rather than each item in its loot table. - var input = new SingleRecipeInput(new ItemStack(state.getBlock())); - if (!input.item().isEmpty()) { - var recipe = level.getRecipeManager().getRecipeFor(CrushingRecipe.TYPE.get(), input, level); - if (recipe.isPresent()) - return java.util.List.of(recipe.get().value().assemble(input, level.registryAccess())); - } - return Block.getDrops(state, level, target, null, null, tool()); - } - - private static void beginRetraction(SteamMachine machine) { - machine.drillPhase = 1; - machine.drillRetractionTicks = 0; - machine.progress[0] = 0; - machine.getLevel().playSound(null, machine.getBlockPos(), - net.minecraft.sounds.SoundEvents.IRON_DOOR_CLOSE, - net.minecraft.sounds.SoundSource.BLOCKS, .8f, .7f); - machine.setChanged(); - } - - private static void retract(SteamMachine machine, Direction direction) { - var level = machine.getLevel(); - if (machine.depth > 0) { - BlockPos tip = machine.getBlockPos().relative(direction, machine.depth); - // Never load chunks or lose our place while a tip is unavailable. - if (!level.hasChunkAt(tip)) return; - if (++machine.drillRetractionTicks < 4) return; - machine.drillRetractionTicks = 0; - if (level.getBlockState(tip).is(ModContent.block("drillbit"))) - zone.moddev.mc.SteamAdvantage.blocks.DrillBitBlock.retractSegment(level, tip); - machine.depth--; - var pos = machine.getBlockPos(); - level.playSound(null, pos, net.minecraft.sounds.SoundEvents.PISTON_CONTRACT, - net.minecraft.sounds.SoundSource.BLOCKS, .5f, 1.2f); - ((net.minecraft.server.level.ServerLevel) level).sendParticles( - net.minecraft.core.particles.ParticleTypes.CLOUD, - pos.getX() + .5, pos.getY() + 1, pos.getZ() + .5, 3, .2, .1, .2, .01); - } - if (machine.depth == 0) { - machine.drillPhase = 2; - level.playSound(null, machine.getBlockPos(), - net.minecraft.sounds.SoundEvents.IRON_TRAPDOOR_CLOSE, - net.minecraft.sounds.SoundSource.BLOCKS, .8f, 1); - followTrack(machine); - } - machine.setChanged(); - } - - /** The drill mines as an unenchanted diamond pickaxe. */ - private static ItemStack tool() { - return new ItemStack(Items.DIAMOND_PICKAXE); - } - - /** - * Ticks to break a block, using vanilla's player formula for the drill's tool: tool speed - * over hardness, divided by 30 when the tool can harvest the block or 100 when it cannot. - */ - static int breakTicks(BlockState state, net.minecraft.world.level.Level level, BlockPos pos) { - float hardness = state.getDestroySpeed(level, pos); - if (hardness <= 0) - return 1; - ItemStack tool = tool(); - boolean harvestable = - !state.requiresCorrectToolForDrops() || tool.isCorrectToolForDrops(state); - float perTick = tool.getDestroySpeed(state) / hardness / (harvestable ? 30f : 100f); - return Math.max(1, net.minecraft.util.Mth.ceil(1f / perTick)); - } - - static void clearDrill(SteamMachine machine) { - var level = machine.getLevel(); - var pos = machine.getBlockPos(); - Direction direction = machine.getBlockState().getValue(BlockStateProperties.FACING); - for (int i = 1; i <= MAX_RANGE; i++) { - BlockPos p = pos.relative(direction, i); - if (!level.hasChunkAt(p) || !level.getBlockState(p).is(ModContent.block("drillbit"))) - break; - level.removeBlock(p, false); - } - machine.depth = 0; - machine.progress[0] = 0; - machine.drillPhase = 0; - machine.drillRetractionTicks = 0; - } - - static void followTrack(SteamMachine machine) { - var level = machine.getLevel(); - var pos = machine.getBlockPos(); - if (!machine.hasSteam(1000)) - return; - for (Direction d : Direction.values()) { - BlockPos target = pos.relative(d); - if (!level.hasChunkAt(target) - || !level.getBlockState(target).is(ModContent.block("steam_track"))) - continue; - machine.spendSteam(1000); - clearDrill(machine); - CompoundTag saved = machine.saveWithoutMetadata(level.registryAccess()); - BlockState state = machine.getBlockState(); - for (int i = 0; i < machine.items.getSlots(); i++) - machine.items.setStackInSlot(i, ItemStack.EMPTY); - level.setBlockAndUpdate(target, state); - if (level.getBlockEntity(target) instanceof SteamMachine moved) { - moved.loadWithComponents(saved, level.registryAccess()); - moved.setChanged(); - } - level.setBlockAndUpdate(pos, ModContent.block("steam_pipe").defaultBlockState()); - return; - } - } -} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/DrillProcessor.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/DrillProcessor.java new file mode 100644 index 0000000..d629815 --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/DrillProcessor.java @@ -0,0 +1,272 @@ +package zone.moddev.mc.SteamAdvantage.machines; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import zone.moddev.mc.SteamAdvantage.config.SteamConfig; +import zone.moddev.mc.SteamAdvantage.init.ModContent; +import zone.moddev.mc.lib.api.capabilities.IoMode; +import zone.moddev.mc.lib.api.capabilities.Transfer; +import zone.moddev.mc.lib.machine.feature.ProcessorMachine; +import zone.moddev.mc.lib.machine.feature.ProcessorState; + +/** + * Steam drill: extends a drill pipe from its front, mining each block as an unenchanted diamond + * pickaxe into its five output slots. At bedrock, the world edge or its range it retracts the + * pipe one segment at a time, then follows an adjacent steam track if there is one. A redstone + * signal resets it. It pushes its output out of its back every tick. + */ +public final class DrillProcessor extends SteamProcessor { + /** + * Maximum pipe length. SA2 used 64, which reached bedrock from sea level when the world + * bottom was y=0; with the floor now at -64, 128 covers sea level down to bedrock. + */ + public static final int MAX_RANGE = 128; + private static final int OUTPUTS = 5; + /** 0: drilling, 1: retracting, 2: fully retracted and waiting for reset or track. */ + static final int DRILLING = 0, RETRACTING = 1, RETRACTED = 2; + private final ProcessorState.Key depth = intVariable("depth"), + phase = intVariable("phase"), retractTicks = intVariable("retractTicks"), + progress = intVariable("progress"); + + @Override + public boolean canStart(ProcessorState state, ProcessorMachine host) { + return true; + } + + @Override + public ProcessState process(ProcessorState state, ProcessorMachine host, int ticks) { + if (powered()) { + clear(); + return ProcessState.IDLE; + } + for (int step = 0; step < ticks && !machine.removed(); step++) + drill(); + return ProcessState.IDLE; + } + + private void drill() { + var level = machine.level(); + var pos = machine.position(); + Direction direction = front(); + // Empty the output every tick, so a full inventory can drain and mining resume. + Transfer.pushItems(level, pos, direction.getOpposite(), + entity().items.view(slot -> IoMode.OUTPUT), 64); + int phase = variables.get(this.phase); + if (phase == RETRACTING) { + retract(direction); + return; + } + if (phase == RETRACTED) { + followTrack(); + return; + } + int depth = variables.get(this.depth); + if (depth >= MAX_RANGE) { + beginRetraction(); + return; + } + BlockPos target = pos.relative(direction, depth + 1); + if (!level.isInWorldBounds(target)) { + // Reached the top or bottom of the world: treat it like bedrock. + beginRetraction(); + return; + } + if (!level.hasChunkAt(target)) + return; + BlockState state = level.getBlockState(target); + if (state.is(ModContent.block("drillbit"))) { + variables.set(this.depth, depth + 1); + return; + } + if (state.getDestroySpeed(level, target) < 0 || state.hasBlockEntity()) { + beginRetraction(); + return; + } + // Air, fluids, plants etc. are simply displaced by the pipe rather than mined. + boolean replace = state.canBeReplaced(); + // Steam starvation pauses the drill rather than retracting its existing line. + if (!hasSteam(replace ? 250 : 100)) + return; + if (!replace) { + var items = entity().items; + var drops = Block.getDrops(state, (ServerLevel) level, target, null, null, tool()); + // Simulate all drops together before altering the world. + var test = new net.neoforged.neoforge.items.ItemStackHandler(OUTPUTS); + for (int i = 0; i < OUTPUTS; i++) + test.setStackInSlot(i, items.getStackInSlot(i).copy()); + for (ItemStack drop : drops) { + ItemStack remaining = drop.copy(); + for (int i = 0; i < OUTPUTS; i++) remaining = test.insertItem(i, remaining, false); + if (!remaining.isEmpty()) + return; + } + // A blocked output must pause before mining consumes steam or progress. + int ticks = breakTicks(state, level, target); + int done = variables.get(progress); + if (done < ticks) { + spendSteam(100); + variables.set(progress, ++done); + if (done < ticks) + return; + } + if (!level.destroyBlock(target, false)) + return; + variables.set(progress, 0); + for (int i = 0; i < OUTPUTS; i++) + items.setStackInSlot(i, test.getStackInSlot(i)); + } else + spendSteam(250); + level.setBlockAndUpdate(target, ModContent.block("drillbit").defaultBlockState() + .setValue(BlockStateProperties.FACING, direction)); + variables.set(this.depth, depth + 1); + } + + private void beginRetraction() { + variables.set(phase, RETRACTING); + variables.set(retractTicks, 0); + variables.set(progress, 0); + machine.level().playSound(null, machine.position(), SoundEvents.IRON_DOOR_CLOSE, + SoundSource.BLOCKS, .8f, .7f); + } + + private void retract(Direction direction) { + var level = machine.level(); + var pos = machine.position(); + int depth = variables.get(this.depth); + if (depth > 0) { + BlockPos tip = pos.relative(direction, depth); + // Never load chunks or lose our place while a tip is unavailable. + if (!level.hasChunkAt(tip)) + return; + int waited = variables.get(retractTicks) + 1; + variables.set(retractTicks, waited < 4 ? waited : 0); + if (waited < 4) + return; + if (level.getBlockState(tip).is(ModContent.block("drillbit"))) + zone.moddev.mc.SteamAdvantage.blocks.DrillBitBlock.retractSegment(level, tip); + variables.set(this.depth, --depth); + level.playSound(null, pos, SoundEvents.PISTON_CONTRACT, SoundSource.BLOCKS, .5f, 1.2f); + ((ServerLevel) level).sendParticles(net.minecraft.core.particles.ParticleTypes.CLOUD, + pos.getX() + .5, pos.getY() + 1, pos.getZ() + .5, 3, .2, .1, .2, .01); + } + if (depth == 0) { + variables.set(phase, RETRACTED); + level.playSound(null, pos, SoundEvents.IRON_TRAPDOOR_CLOSE, SoundSource.BLOCKS, .8f, 1); + followTrack(); + } + } + + /** The drill mines as an unenchanted diamond pickaxe. */ + private static ItemStack tool() { + return new ItemStack(Items.DIAMOND_PICKAXE); + } + + /** + * Ticks to break a block, as in SA2: a configurable number of ticks per point of hardness + * (12 by default), never less than half that. + */ + static int breakTicks(BlockState state, Level level, BlockPos pos) { + double factor = SteamConfig.DRILL_TICKS_PER_HARDNESS.get(); + float hardness = state.getDestroySpeed(level, pos); + return Math.max(1, (int) Math.ceil(Math.max(factor * hardness, factor * .5))); + } + + /** Removes the drill pipe and resets the drill to its starting state. */ + public void clear() { + variables.update(this::clearPipe); + } + + private void clearPipe() { + var level = machine.level(); + var pos = machine.position(); + Direction direction = front(); + for (int i = 1; i <= MAX_RANGE; i++) { + BlockPos p = pos.relative(direction, i); + if (!level.hasChunkAt(p) || !level.getBlockState(p).is(ModContent.block("drillbit"))) + break; + level.removeBlock(p, false); + } + variables.set(depth, 0); + variables.set(progress, 0); + variables.set(phase, DRILLING); + variables.set(retractTicks, 0); + } + + /** Moves the whole machine one block onto an adjacent steam track, leaving a pipe behind. */ + private void followTrack() { + var level = machine.level(); + var pos = machine.position(); + if (!hasSteam(1000)) + return; + for (Direction d : Direction.values()) { + BlockPos target = pos.relative(d); + if (!level.hasChunkAt(target) + || !level.getBlockState(target).is(ModContent.block("steam_track"))) + continue; + spendSteam(1000); + clearPipe(); + var self = (SteamMachineEntity) entity(); + CompoundTag saved = self.saveWithoutMetadata(level.registryAccess()); + BlockState state = machine.blockState(); + level.setBlockAndUpdate(target, state); + if (level.getBlockEntity(target) instanceof SteamMachineEntity moved) { + moved.loadWithComponents(saved, level.registryAccess()); + moved.setChanged(); + } + // The contents went with the moved drill; replacing this block must not drop them. + self.relocating = true; + level.setBlockAndUpdate(pos, ModContent.block("steam_pipe").defaultBlockState()); + return; + } + } + + @Override + void importLegacy(CompoundTag old, CompoundTag state) { + int[] progress = old.getIntArray("Progress"); + state.putInt("depth", old.getInt("Depth")); + state.putInt("phase", Math.clamp(old.getInt("DrillPhase"), DRILLING, RETRACTED)); + state.putInt("retractTicks", Math.clamp(old.getInt("DrillRetractionTicks"), 0, 3)); + state.putInt("progress", progress.length > 0 ? progress[0] : 0); + } + + @Override + protected int comparatorSignal() { + return inventorySignal(0, OUTPUTS); + } + + public int depth() { + return variables.get(depth); + } + + public int phase() { + return variables.get(phase); + } + + public int progress() { + return variables.get(progress); + } + + /** Runs one unpowered drill tick immediately; for tests. */ + public void step() { + variables.update(this::drill); + } + + /** Test and tooling access; outside a processor tick. */ + public void set(int depth, int phase, int progress) { + variables.update(() -> { + variables.set(this.depth, depth); + variables.set(this.phase, phase); + variables.set(this.progress, progress); + }); + } +} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/ElectricBoilerProcessor.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/ElectricBoilerProcessor.java new file mode 100644 index 0000000..7de7d38 --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/ElectricBoilerProcessor.java @@ -0,0 +1,20 @@ +package zone.moddev.mc.SteamAdvantage.machines; + +/** Electric boiler: 16 FE makes 50 mB of steam. */ +public final class ElectricBoilerProcessor extends BoilerProcessor { + @Override + protected boolean heat(boolean ambient) { + return entity().energy.consume(16); + } + + @Override + protected int steamPerTick() { + return 50; + } + + @Override + protected int comparatorSignal() { + var energy = entity().energy; + return proportionalSignal(energy.stored(), energy.capacity()); + } +} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/ElevatorOperation.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/ElevatorOperation.java deleted file mode 100644 index 0c01827..0000000 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/ElevatorOperation.java +++ /dev/null @@ -1,57 +0,0 @@ -package zone.moddev.mc.SteamAdvantage.machines; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.phys.AABB; -import zone.moddev.mc.SteamAdvantage.blocks.PlatformBlock; -import zone.moddev.mc.SteamAdvantage.init.ModContent; - -/** Platform and passenger movement. */ -final class ElevatorOperation { - private ElevatorOperation() {} - - static void elevator(SteamMachine machine, boolean signal) { - var level = machine.getLevel(); - var pos = machine.getBlockPos(); - if (signal == machine.raised || !machine.hasSteam(3200)) - return; - Block platform = ModContent.block("platform"); - if (signal) { - int height = 0; - for (int i = 1; i <= 16; i++) { - BlockPos p = pos.above(i); - if (!level.hasChunkAt(p) || !level.isEmptyBlock(p)) - break; - height = i; - } - height -= 2; - if (height < 1) - return; - machine.elevatorHeight = height; - for (int i = 1; i <= height; i++) - level.setBlockAndUpdate(pos.above(i), - platform.defaultBlockState().setValue( - PlatformBlock.HEIGHT, i == height ? 4 : 0)); - for (var entity : - level.getEntities(null, new AABB(pos.above()).expandTowards(0, height, 0))) { - entity.teleportTo(entity.getX(), pos.getY() + height + 1.01, entity.getZ()); - entity.fallDistance = 0; - } - } else { - for (int i = 1; i <= machine.elevatorHeight; i++) { - BlockPos p = pos.above(i); - if (!level.hasChunkAt(p) || !level.getBlockState(p).is(platform)) - return; - } - for (int i = 1; i <= machine.elevatorHeight; i++) - level.removeBlock(pos.above(i), false); - for (var entity : level.getEntities(null, - new AABB(pos.above(machine.elevatorHeight + 1)).expandTowards(0, 2, 0))) { - entity.teleportTo(entity.getX(), pos.getY() + 1.01, entity.getZ()); - entity.fallDistance = 0; - } - } - machine.spendSteam(3200); - machine.raised = signal; - } -} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/ElevatorProcessor.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/ElevatorProcessor.java new file mode 100644 index 0000000..4eb3f6b --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/ElevatorProcessor.java @@ -0,0 +1,98 @@ +package zone.moddev.mc.SteamAdvantage.machines; + +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.phys.AABB; +import zone.moddev.mc.SteamAdvantage.blocks.PlatformBlock; +import zone.moddev.mc.SteamAdvantage.init.ModContent; +import zone.moddev.mc.lib.machine.feature.ProcessorMachine; +import zone.moddev.mc.lib.machine.feature.ProcessorState; + +/** + * Steam elevator: a redstone signal raises a platform column (up to 16 blocks, stopping two + * short of an obstruction) and lifts what stands on it; losing the signal lowers it. Each move + * costs 3200 mB of steam. Unlike other machines, redstone drives it rather than pausing it. + */ +public final class ElevatorProcessor extends SteamProcessor { + private final ProcessorState.Key raised = + variables.define("raised", com.mojang.serialization.Codec.BOOL, false); + private final ProcessorState.Key height = intVariable("height"); + + @Override + public boolean canStart(ProcessorState state, ProcessorMachine host) { + return true; + } + + @Override + public ProcessState process(ProcessorState state, ProcessorMachine host, int ticks) { + move(powered()); + return ProcessState.IDLE; + } + + private void move(boolean signal) { + var level = machine.level(); + var pos = machine.position(); + if (signal == variables.get(raised) || !hasSteam(3200)) + return; + Block platform = ModContent.block("platform"); + int columns = variables.get(height); + if (signal) { + int top = 0; + for (int i = 1; i <= 16; i++) { + BlockPos p = pos.above(i); + if (!level.hasChunkAt(p) || !level.isEmptyBlock(p)) + break; + top = i; + } + top -= 2; + if (top < 1) + return; + columns = top; + for (int i = 1; i <= columns; i++) + level.setBlockAndUpdate(pos.above(i), platform.defaultBlockState() + .setValue(PlatformBlock.HEIGHT, i == columns ? 4 : 0)); + for (var entity : + level.getEntities(null, new AABB(pos.above()).expandTowards(0, columns, 0))) { + entity.teleportTo(entity.getX(), pos.getY() + columns + 1.01, entity.getZ()); + entity.fallDistance = 0; + } + } else { + for (int i = 1; i <= columns; i++) { + BlockPos p = pos.above(i); + if (!level.hasChunkAt(p) || !level.getBlockState(p).is(platform)) + return; + } + for (int i = 1; i <= columns; i++) + level.removeBlock(pos.above(i), false); + for (var entity : level.getEntities(null, + new AABB(pos.above(columns + 1)).expandTowards(0, 2, 0))) { + entity.teleportTo(entity.getX(), pos.getY() + 1.01, entity.getZ()); + entity.fallDistance = 0; + } + } + variables.set(height, columns); + spendSteam(3200); + variables.set(raised, signal); + } + + @Override + void importLegacy(CompoundTag old, CompoundTag state) { + state.putBoolean("raised", old.getBoolean("Raised")); + state.putInt("height", old.getInt("ElevatorHeight")); + } + + @Override + protected int comparatorSignal() { + return variables.get(raised) ? 15 : 0; + } + + public boolean raised() { + return variables.get(raised); + } + + /** Test and tooling access; outside a processor tick. */ + public void setRaised(boolean value) { + variables.update(() -> variables.set(raised, value)); + } +} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/FurnaceOperation.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/FurnaceOperation.java deleted file mode 100644 index e853377..0000000 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/FurnaceOperation.java +++ /dev/null @@ -1,55 +0,0 @@ -package zone.moddev.mc.SteamAdvantage.machines; - -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.world.item.crafting.SingleRecipeInput; - -/** Three-lane smelting and temperature calculation. */ -final class FurnaceOperation { - private static final float MIN_TEMPERATURE = 0.01f; - - private FurnaceOperation() {} - - static boolean smelt(SteamMachine machine) { - var level = machine.getLevel(); - boolean canProcess = false; - for (int i = 1; i <= 3; i++) - if (level.getRecipeManager() - .getRecipeFor(RecipeType.SMELTING, - new SingleRecipeInput(machine.items.getStackInSlot(i)), level) - .isPresent()) - canProcess = true; - boolean burning = (machine.burn > 0 || canProcess) && machine.burnFuel(); - float input = burning ? 2.5f : 0; - if (burning && machine.hasSteam(50)) { - input = 15; - machine.spendSteam(50); - } - machine.temperature = Math.clamp(machine.temperature - + .3f - * (10 * input - .00003f * machine.temperature * machine.temperature - - .03f * machine.temperature), - 0, 2000); - if (machine.temperature < MIN_TEMPERATURE) - machine.temperature = 0; - for (int i = 0; i < 3; i++) { - var inputStack = new SingleRecipeInput(machine.items.getStackInSlot(i + 1)); - var recipe = - level.getRecipeManager().getRecipeFor(RecipeType.SMELTING, inputStack, level); - if (recipe.isEmpty() || machine.temperature < 100) { - machine.progress[i] = 0; - continue; - } - ItemStack output = recipe.get().value().assemble(inputStack, level.registryAccess()); - if (!machine.items.fits(i + 4, output)) - continue; - machine.progress[i] += Math.max(1, (int) (machine.temperature * .035)); - if (machine.progress[i] >= 10000) { - machine.progress[i] = 0; - machine.items.getStackInSlot(i + 1).shrink(1); - machine.items.insertResult(i + 4, output, false); - } - } - return machine.temperature >= 100; - } -} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/GeothermalBoilerProcessor.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/GeothermalBoilerProcessor.java new file mode 100644 index 0000000..7deda47 --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/GeothermalBoilerProcessor.java @@ -0,0 +1,57 @@ +package zone.moddev.mc.SteamAdvantage.machines; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.block.Blocks; + +/** + * Geothermal boiler: each adjacent lava or magma block adds heat (up to 2000); it boils at 100 + * or more and cools by one each tick. + */ +public final class GeothermalBoilerProcessor extends BoilerProcessor { + public static final int MAX_TEMPERATURE = 2000; + private final zone.moddev.mc.lib.machine.feature.ProcessorState.Key temperature = + variables.define("temperature", com.mojang.serialization.Codec.FLOAT, 0f); + + @Override + protected boolean ambientHeat() { + var level = machine.level(); + var pos = machine.position(); + int hot = 0; + for (Direction d : Direction.values()) { + BlockPos p = pos.relative(d); + if (level.hasChunkAt(p) + && (level.getFluidState(p).is(net.minecraft.tags.FluidTags.LAVA) + || level.getBlockState(p).is(Blocks.MAGMA_BLOCK))) + hot++; + } + float next = Math.min(MAX_TEMPERATURE, Math.max(0, variables.get(temperature) + hot * 4 - 1)); + variables.set(temperature, next); + return next >= 100; + } + + @Override + protected boolean heat(boolean ambient) { + return ambient; + } + + @Override + void importLegacy(CompoundTag old, CompoundTag state) { + state.putFloat("temperature", old.getFloat("Temperature")); + } + + @Override + protected int comparatorSignal() { + return proportionalSignal(variables.get(temperature), MAX_TEMPERATURE); + } + + public float temperature() { + return variables.get(temperature); + } + + /** Test and tooling access; outside a processor tick. */ + public void setTemperature(float value) { + variables.update(() -> variables.set(temperature, value)); + } +} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/MachineBlock.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/MachineBlock.java deleted file mode 100644 index f0968d1..0000000 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/MachineBlock.java +++ /dev/null @@ -1,65 +0,0 @@ -package zone.moddev.mc.SteamAdvantage.machines; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.item.context.BlockPlaceContext; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.RenderShape; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateDefinition; -import net.minecraft.world.level.block.state.properties.BlockStateProperties; - -public class MachineBlock - extends zone.moddev.mc.lib.common.runtime.MaterialEntityBlock { - private final MachineSettings settings; - public MachineBlock(Properties properties, - zone.moddev.mc.lib.api.BlockEntityBinding binding) { - super(properties, binding.prepared(), binding.type()); - settings = binding.prepared() - .definition() - .factoryData() - .decode(MachineSettings.CODEC) - .getOrThrow(); - registerDefaultState( - stateDefinition.any().setValue(BlockStateProperties.FACING, Direction.NORTH)); - } - public MachineSettings settings() { - return settings; - } - @Override - protected void createBlockStateDefinition(StateDefinition.Builder b) { - b.add(BlockStateProperties.FACING); - } - @Override - public BlockState getStateForPlacement(BlockPlaceContext c) { - return defaultBlockState().setValue(BlockStateProperties.FACING, - settings.kind().equals("steam_drill") ? c.getNearestLookingDirection().getOpposite() - : c.getHorizontalDirection().getOpposite()); - } - @Override - protected RenderShape getRenderShape(BlockState state) { - return RenderShape.MODEL; - } - @Override - protected void onRemove(BlockState s, Level l, BlockPos p, BlockState next, boolean moving) { - if (l.getBlockEntity(p) instanceof SteamMachine machine - && machine.kind.equals("steam_drill") - && (!s.is(next.getBlock()) - || s.getValue(BlockStateProperties.FACING) - != next.getValue(BlockStateProperties.FACING))) - machine.clearDrill(); - // MaterialEntityBlock drops the contents through MMDLib's BaseMachine lifecycle. - super.onRemove(s, l, p, next, moving); - } - @Override - protected boolean hasAnalogOutputSignal(BlockState s) { - return true; - } - @Override - protected int getAnalogOutputSignal(BlockState s, Level l, BlockPos p) { - return l.getBlockEntity(p) instanceof SteamMachine m - ? m.comparatorSignal() - : 0; - } -} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/MachineInteractions.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/MachineInteractions.java deleted file mode 100644 index 29d3187..0000000 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/MachineInteractions.java +++ /dev/null @@ -1,21 +0,0 @@ -package zone.moddev.mc.SteamAdvantage.machines; - -import net.minecraft.world.entity.player.Player; -import net.neoforged.neoforge.fluids.FluidUtil; -import zone.moddev.mc.lib.api.MaterialEventContexts.BlockUse; -import zone.moddev.mc.lib.common.runtime.BlockEvents; - -/** Declared block callback: fluid containers take priority, MMDLib owns XML menu opening. */ -public final class MachineInteractions { - private MachineInteractions() {} - public static void use(Player player, BlockUse use) { - if (FluidUtil.getFluidHandler(use.stack()).isPresent()) { - if (!use.level().isClientSide - && use.level().getBlockEntity(use.position()) instanceof SteamMachine machine) - FluidUtil.interactWithFluidHandler(player, use.hand(), machine.fluids()); - use.consume(); - return; - } - BlockEvents.openMenu(player, use); - } -} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/MachineInventory.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/MachineInventory.java deleted file mode 100644 index b75a10d..0000000 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/MachineInventory.java +++ /dev/null @@ -1,33 +0,0 @@ -package zone.moddev.mc.SteamAdvantage.machines; - -import java.util.function.Supplier; -import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.world.item.crafting.SingleRecipeInput; -import net.minecraft.world.level.Level; -import zone.moddev.mc.lib.api.capabilities.ItemStorage; -import zone.moddev.mc.lib.api.capabilities.Role; - -/** Shared inventory policy for server storage and client menu prediction. */ -public final class MachineInventory { - private MachineInventory() {} - public static ItemStorage create( - MachineSettings settings, Supplier level, Runnable changed) { - String kind = settings.kind(); - var items = new ItemStorage(settings.inventorySize()).onChange(changed); - items.role(Role.INPUT, 0, 1, 2, 3).role(Role.OUTPUT, 4, 5, 6, 7, 8); - items.filter(stack - -> kind.equals("steam_crusher") - || ((kind.equals("steam_furnace") || kind.equals("steam_boiler_coal")) - && stack.getBurnTime(RecipeType.SMELTING) > 0), - 0); - items.filter(stack - -> kind.equals("steam_furnace") && level.get() != null - && level.get() - .getRecipeManager() - .getRecipeFor(RecipeType.SMELTING, new SingleRecipeInput(stack), - level.get()) - .isPresent(), - 1, 2, 3); - return items; - } -} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/MachineSettings.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/MachineSettings.java deleted file mode 100644 index 344e808..0000000 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/MachineSettings.java +++ /dev/null @@ -1,65 +0,0 @@ -package zone.moddev.mc.SteamAdvantage.machines; - -import com.mojang.serialization.Codec; -import com.mojang.serialization.codecs.RecordCodecBuilder; - -/** Validated settings decoded by MMDLib for every standalone machine definition. */ -public record MachineSettings(String kind, int steamCapacity, int waterCapacity, int fuelCapacity, - int productCapacity, int inventorySize, long energyCapacity, long energyTransfer) { - public static final Codec CODEC = RecordCodecBuilder.create(instance - -> instance - .group(Codec.STRING.fieldOf("kind").forGetter(MachineSettings::kind), - Codec.intRange(1, 10000000) - .fieldOf("steam_capacity") - .forGetter(MachineSettings::steamCapacity), - Codec.intRange(0, 1000000) - .optionalFieldOf("water_capacity", 0) - .forGetter(MachineSettings::waterCapacity), - Codec.intRange(0, 1000000) - .optionalFieldOf("fuel_capacity", 0) - .forGetter(MachineSettings::fuelCapacity), - Codec.intRange(0, 1000000) - .optionalFieldOf("product_capacity", 0) - .forGetter(MachineSettings::productCapacity), - Codec.intRange(9, 64) - .optionalFieldOf("inventory_size", 9) - .forGetter(MachineSettings::inventorySize), - Codec.LONG - .validate(value - -> value >= 0 - ? com.mojang.serialization.DataResult.success( - value) - : com.mojang.serialization.DataResult.error( - () - -> "Expected nonnegative " - + "energy value")) - .optionalFieldOf("energy_capacity", 1600L) - .forGetter(MachineSettings::energyCapacity), - Codec.LONG - .validate(value - -> value >= 0 - ? com.mojang.serialization.DataResult.success( - value) - : com.mojang.serialization.DataResult.error( - () - -> "Expected nonnegative " - + "energy value")) - .optionalFieldOf("energy_transfer", 160L) - .forGetter(MachineSettings::energyTransfer)) - .apply(instance, MachineSettings::new)); - public MachineSettings { - if (!java.util.Set - .of("steam_boiler_coal", "steam_boiler_electric", "steam_boiler_geothermal", - "steam_boiler_oil", "steam_tank", "steam_furnace", "steam_crusher", - "steam_drill", "steam_elevator", "steam_still", "steam_pump", - "steam_switch") - .contains(kind)) - throw new IllegalArgumentException("Unknown SteamAdvantage machine behavior: " + kind); - if ((kind.startsWith("steam_boiler") || kind.equals("steam_still")) && waterCapacity == 0) - throw new IllegalArgumentException("Machine requires water/input storage: " + kind); - if (kind.equals("steam_boiler_oil") && fuelCapacity == 0) - throw new IllegalArgumentException("Oil boiler requires fuel storage"); - if ((kind.equals("steam_still") || kind.equals("steam_pump")) && productCapacity == 0) - throw new IllegalArgumentException("Machine requires output storage: " + kind); - } -} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/OilBoilerProcessor.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/OilBoilerProcessor.java new file mode 100644 index 0000000..cbeabae --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/OilBoilerProcessor.java @@ -0,0 +1,55 @@ +package zone.moddev.mc.SteamAdvantage.machines; + +import net.minecraft.nbt.CompoundTag; +import net.neoforged.neoforge.fluids.capability.IFluidHandler.FluidAction; +import zone.moddev.mc.SteamAdvantage.config.SteamConfig; +import zone.moddev.mc.lib.machine.feature.ProcessorMachine; +import zone.moddev.mc.lib.machine.feature.StorageAdmission; +import zone.moddev.mc.lib.machine.ingredient.FluidAmount; + +/** + * Oil boiler: burns 100 mB of fuel for {@code oilBurnTicks} ticks. Its fuel tank (2) accepts + * the fluid tag named in the common config. + */ +public final class OilBoilerProcessor extends BoilerProcessor implements StorageAdmission, Burner { + private static final int FUEL = 2; + private final zone.moddev.mc.lib.machine.feature.ProcessorState.Key burn = + intVariable("burn"), totalBurn = intVariable("totalBurn"); + + @Override + protected boolean heat(boolean ambient) { + if (variables.get(burn) <= 0 && tank(FUEL).getFluidAmount() >= 100) { + tank(FUEL).drain(100, FluidAction.EXECUTE); + int ticks = SteamConfig.OIL_BURN_TICKS.get(); + variables.set(burn, ticks); + variables.set(totalBurn, ticks); + } + int left = variables.get(burn); + variables.set(burn, left - 1); + return left > 0; + } + + @Override + public boolean acceptsFluid(ProcessorMachine host, String member, FluidAmount fluid) { + return fluid.fluid().is(SteamConfig.fuelTag()); + } + + @Override + void importLegacy(CompoundTag old, CompoundTag state) { + state.putInt("burn", old.getInt("Burn")); + state.putInt("totalBurn", old.getInt("TotalBurn")); + } + + @Override + protected int comparatorSignal() { + return tankSignal(FUEL); + } + + public int burnTime() { + return variables.get(burn); + } + + public int totalBurnTime() { + return variables.get(totalBurn); + } +} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/PumpOperation.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/PumpProcessor.java similarity index 63% rename from src/main/java/zone/moddev/mc/SteamAdvantage/machines/PumpOperation.java rename to src/main/java/zone/moddev/mc/SteamAdvantage/machines/PumpProcessor.java index 539a779..a86e06b 100644 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/PumpOperation.java +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/PumpProcessor.java @@ -9,15 +9,36 @@ import net.neoforged.neoforge.fluids.FluidStack; import net.neoforged.neoforge.fluids.capability.IFluidHandler.FluidAction; import zone.moddev.mc.SteamAdvantage.init.ModContent; +import zone.moddev.mc.lib.machine.feature.ProcessorMachine; +import zone.moddev.mc.lib.machine.feature.ProcessorState; -/** Intake-shaft extension and bounded world-fluid collection. */ -final class PumpOperation { - private PumpOperation() {} +/** + * Steam pump: extends an intake shaft down to the nearest fluid, then collects source blocks + * within reach into its product tank (1), which it empties out of every face. + */ +public final class PumpProcessor extends SteamProcessor { + private static final int PRODUCT = 1; - static void pump(SteamMachine machine) { - var level = machine.getLevel(); - var pos = machine.getBlockPos(); - if (!machine.hasSteam(500)) + @Override + public boolean canStart(ProcessorState state, ProcessorMachine host) { + return true; + } + + @Override + public ProcessState process(ProcessorState state, ProcessorMachine host, int ticks) { + for (int step = 0; step < ticks; step++) { + if (!powered()) + pump(); + // Pumped fluid leaves the machine even while it is held by redstone. + pushAllSides(PRODUCT, 100); + } + return ProcessState.IDLE; + } + + private void pump() { + var level = machine.level(); + var pos = machine.position(); + if (!hasSteam(500)) return; Block pipe = ModContent.block("pump_pipe_steam"); BlockPos end = pos.below(); @@ -37,14 +58,13 @@ static void pump(SteamMachine machine) { break; if (level.getGameTime() % 11 == 0) { level.setBlockAndUpdate(end, pipe.defaultBlockState()); - machine.spendSteam(500); + spendSteam(500); } return; } break; } - if (level.getGameTime() % 32 != 0 || !machine.hasSteam(3200) - || machine.fluids.tank(machine.product).getSpace() < 1000) + if (level.getGameTime() % 32 != 0 || !hasSteam(3200) || tank(PRODUCT).getSpace() < 1000) return; var queue = new java.util.ArrayDeque(); var seen = new java.util.HashSet(); @@ -60,12 +80,11 @@ static void pump(SteamMachine machine) { continue; if (state.getBlock() instanceof BucketPickup pickup) { FluidStack candidate = new FluidStack(state.getFluidState().getType(), 1000); - if (machine.fluids.tank(machine.product).fill(candidate, FluidAction.SIMULATE) - == 1000) { + if (tank(PRODUCT).fill(candidate, FluidAction.SIMULATE) == 1000) { ItemStack bucket = pickup.pickupBlock(null, level, p, state); if (!bucket.isEmpty()) { - machine.fluids.tank(machine.product).fill(candidate, FluidAction.EXECUTE); - machine.spendSteam(3200); + tank(PRODUCT).fill(candidate, FluidAction.EXECUTE); + spendSteam(3200); return; } } @@ -73,4 +92,9 @@ static void pump(SteamMachine machine) { for (Direction d : Direction.values()) queue.addLast(p.relative(d)); } } + + @Override + protected int comparatorSignal() { + return tankSignal(PRODUCT); + } } diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/RecipeMachineSensor.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/RecipeMachineSensor.java new file mode 100644 index 0000000..4cd9140 --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/RecipeMachineSensor.java @@ -0,0 +1,33 @@ +package zone.moddev.mc.SteamAdvantage.machines; + +import zone.moddev.mc.lib.machine.feature.ProcessorMachine; +import zone.moddev.mc.lib.machine.feature.ProcessorState; + +/** + * Companion processor for the recipe-driven crusher and furnace. MMDLib's recipe lanes do the + * work; this supplies SA2's comparator reading (input fullness) and lets a working furnace melt + * snow above it. It does no processing of its own. + */ +public final class RecipeMachineSensor extends SteamProcessor { + @Override + public boolean canStart(ProcessorState state, ProcessorMachine host) { + return true; + } + + @Override + public ProcessState process(ProcessorState state, ProcessorMachine host, int ticks) { + if (melts() && entity().features.processors().stream().anyMatch(lane -> lane.processing())) + meltSnow(); + return ProcessState.IDLE; + } + + private boolean melts() { + return entity().definition.id().getPath().equals("steam_furnace"); + } + + @Override + protected int comparatorSignal() { + // Crusher: its input slot. Furnace: its three lane inputs. + return inventorySignal(0, melts() ? 3 : 1); + } +} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamMachine.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamMachine.java deleted file mode 100644 index 0690f43..0000000 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamMachine.java +++ /dev/null @@ -1,443 +0,0 @@ -package zone.moddev.mc.SteamAdvantage.machines; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.core.HolderLookup; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.RecipeType; -import net.minecraft.world.level.Level; -import java.util.List; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.properties.BlockStateProperties; -import net.minecraft.world.level.material.Fluids; -import net.neoforged.neoforge.fluids.capability.IFluidHandler.FluidAction; -import zone.moddev.mc.SteamAdvantage.config.SteamConfig; -import zone.moddev.mc.SteamAdvantage.init.ModContent; -import net.minecraft.network.chat.Component; -import zone.moddev.mc.lib.api.automation.AutomationInventory; -import zone.moddev.mc.lib.api.automation.ResourceGroup; -import zone.moddev.mc.lib.api.automation.ResourceType; -import zone.moddev.mc.lib.api.capabilities.SideConfig; -import zone.moddev.mc.lib.api.capabilities.EnergyBuffer; -import zone.moddev.mc.lib.api.capabilities.FluidStorage; -import zone.moddev.mc.lib.api.capabilities.IoMode; -import zone.moddev.mc.lib.api.capabilities.ItemStorage; -import zone.moddev.mc.lib.api.capabilities.Role; -import zone.moddev.mc.lib.api.capabilities.Transfer; -import zone.moddev.mc.lib.machine.neoforge.BaseMachine; -import zone.moddev.mc.lib.machine.neoforge.MachineInventoryLifecycle; -import zone.moddev.mc.lib.machine.neoforge.MachineResources; -import zone.moddev.mc.poweradvantage.api.distillation.DistillingRecipe; - -/** - * Shared persisted machine storage. One steam unit is represented by 100 mB. - * - *

Built on MMDLib's {@link BaseMachine}, which owns storage persistence, the feature host, - * screen stats and warnings, while SteamAdvantage keeps its own block (comparator output, - * six-way facing, slot and tank filters) and its hand-written machine behaviour. - * - *

Save layout: items and fluids stay under the {@code Items} and {@code Fluids} keys SA3 - * always used. The electric boiler's buffer moves to MMDLib's {@code energy} key; older saves' - * {@code Energy} is still read. Machine state ({@code Burn}, {@code Depth} and so on) remains - * top-level, through {@link #saveMachineData} and {@link #loadMachineData}. - */ -public final class SteamMachine extends BaseMachine { - final String kind; - final ItemStorage items; - final FluidStorage fluids = new FluidStorage().onChange(this::setChanged); - final EnergyBuffer energy; - private final MachineSettings settings; - int burn, totalBurn, depth, elevatorHeight; - // 0: drilling, 1: retracting, 2: fully retracted and waiting for reset/track. - int drillPhase, drillRetractionTicks; - float temperature; - final int[] progress = new int[3]; - net.neoforged.neoforge.fluids.FluidStack pendingDistillation = - net.neoforged.neoforge.fluids.FluidStack.EMPTY; - int distillationDuration; - int steam, water = -1, fuel = -1, product = -1; - boolean raised; - private int lastComparatorSignal = -1; - private final MachineInventoryLifecycle inventory; - private final MachineResources resources; - public SteamMachine(BlockPos pos, BlockState state) { - this(ModContent.machineType(state), pos, state, - ((MachineBlock) state.getBlock()).settings()); - } - public SteamMachine(net.minecraft.world.level.block.entity.BlockEntityType type, - BlockPos pos, BlockState state, MachineSettings settings) { - super(type, pos, state); - this.settings = settings; - items = MachineInventory.create(settings, this::getLevel, this::setChanged); - energy = new EnergyBuffer(settings.energyCapacity(), settings.energyTransfer(), 0) - .onChange(this::setChanged); - kind = settings.kind(); - boolean boiler = kind.startsWith("steam_boiler"); - int capacity = settings.steamCapacity(); - steam = fluids.addTank(capacity, - kind.equals("steam_tank") ? Role.STORAGE - : boiler ? Role.OUTPUT - : Role.INPUT, - f -> f.getFluid() == zone.moddev.mc.poweradvantage.init.Fluids.STEAM.get()); - if (boiler) - water = fluids.addTank( - settings.waterCapacity(), Role.INPUT, f -> f.getFluid() == Fluids.WATER); - if (kind.equals("steam_boiler_oil")) - fuel = fluids.addTank( - settings.fuelCapacity(), Role.INPUT, f -> f.is(SteamConfig.fuelTag())); - if (kind.equals("steam_pump") || kind.equals("steam_still")) - product = fluids.addTank(settings.productCapacity(), Role.OUTPUT); - if (kind.equals("steam_still")) - water = fluids.addTank(settings.waterCapacity(), Role.INPUT, - f -> getLevel() != null && DistillingRecipe.accepts(getLevel(), f)); - resources = automationGroups(); - inventory = genericInventory(resources.automation()) - .items("Items", items) - .fluids("Fluids", fluids); - } - - /** - * MMDLib automation groups for this machine's storage. Every face of a group starts at the - * group's role, which is exactly the access SA3 machines always exposed on every side; the - * capabilities registered in ModContent read each face's mode from these groups. - */ - private MachineResources automationGroups() { - var groups = new MachineResources(this, this::facing); - switch (kind) { - case "steam_furnace" -> { - items(groups, "fuel", "screen.steamadvantage.fuel", 0xE88D24, IoMode.INPUT, 0); - items(groups, "input", "screen.steamadvantage.input", 0x5080D0, IoMode.INPUT, 1, 2, 3); - items(groups, "output", "screen.steamadvantage.output", 0xD08050, IoMode.OUTPUT, - 4, 5, 6, 7, 8); - } - case "steam_boiler_coal" -> - items(groups, "fuel", "screen.steamadvantage.fuel", 0xE88D24, IoMode.INPUT, 0); - case "steam_crusher" -> { - items(groups, "input", "screen.steamadvantage.input", 0x5080D0, IoMode.INPUT, 0); - items(groups, "output", "screen.steamadvantage.output", 0xD08050, IoMode.OUTPUT, - 4, 5, 6, 7, 8); - } - case "steam_drill" -> - items(groups, "output", "screen.steamadvantage.output", 0xD08050, IoMode.OUTPUT, - 4, 5, 6, 7, 8); - default -> { - } - } - // The last argument names the screen gauge highlighted while the group is selected. - fluid(groups, "steam", "screen.steamadvantage.steam", 0xC8C8C8, steam, "steam"); - fluid(groups, kind.equals("steam_still") ? "input" : "water", - kind.equals("steam_still") ? "screen.steamadvantage.input" - : "screen.steamadvantage.water", - 0x3F76E4, water, "water"); - fluid(groups, "fuel", "screen.steamadvantage.fuel", 0x4A3A2A, fuel, "fuel"); - fluid(groups, "product", "screen.steamadvantage.product", 0x70A050, product, "product"); - if (powerStorage() != null) - groups.energy(new ResourceGroup<>("energy", - Component.translatable("screen.steamadvantage.energy"), - 0xD03030, ResourceType.ENERGY, IoMode.INPUT, List.of(0), - List.of("energy"), new SideConfig(IoMode.INPUT)), - energy); - return groups.build(); - } - - private void items(MachineResources groups, String id, String name, int colour, IoMode mode, - Integer... slots) { - groups.items(new ResourceGroup<>(id, Component.translatable(name), colour, - ResourceType.ITEMS, mode, List.of(slots), List.of(), - new SideConfig(mode)), - items); - } - - private void fluid(MachineResources groups, String id, String name, int colour, int tank, - String gauge) { - if (tank < 0) - return; - IoMode mode = switch (fluids.role(tank)) { - case INPUT -> IoMode.INPUT; - case OUTPUT -> IoMode.OUTPUT; - case STORAGE -> IoMode.BOTH; - case MANUAL -> IoMode.DISABLED; - }; - groups.fluids(new ResourceGroup<>(id, Component.translatable(name), colour, - ResourceType.FLUIDS, mode, List.of(tank), List.of(gauge), - new SideConfig(mode)), - fluids); - } - - /** Per-face automation settings; capabilities and MMDLib transfers both follow them. */ - public AutomationInventory automation() { - return resources.automation(); - } - - @Override - protected EnergyBuffer powerStorage() { - return settings.energyCapacity() > 0 ? energy : null; - } - - @Override - protected MachineInventoryLifecycle machineInventory() { - return inventory; - } - - /** - * Fluids left in a broken machine are discarded, as they always were; its items are - * dropped by MMDLib's lifecycle. - */ - @Override - protected void recoverResources(Level level, BlockPos pos, CompoundTag payload) {} - public String kind() { - return kind; - } - public ItemStorage items() { - return items; - } - public FluidStorage fluids() { - return fluids; - } - public EnergyBuffer energy() { - return energy; - } - - /** Signal sources follow SA2; fullness calculations use SA3's active slot layout. */ - public int comparatorSignal() { - return switch (kind) { - case "steam_elevator" -> raised ? 15 : 0; - case "steam_drill" -> inventorySignal(4, 9); - case "steam_furnace" -> inventorySignal(1, 4); - case "steam_crusher", "steam_boiler_coal" -> inventorySignal(0, 1); - case "steam_boiler_geothermal" -> proportionalSignal(temperature, getMaxTemperature()); - case "steam_boiler_electric" -> proportionalSignal(energy.stored(), energy.capacity()); - case "steam_boiler_oil" -> tankSignal(fuel); - case "steam_pump" -> tankSignal(product); - case "steam_still" -> tankSignal(water); - default -> tankSignal(steam); - }; - } - - private int tankSignal(int tank) { - return tank < 0 ? 0 : proportionalSignal( - fluids.tank(tank).getFluidAmount(), fluids.tank(tank).getCapacity()); - } - - private int inventorySignal(int first, int end) { - double fullness = 0; - for (int slot = first; slot < end; slot++) { - var stack = items.getStackInSlot(slot); - if (!stack.isEmpty()) - fullness += (double) stack.getCount() - / Math.min(stack.getMaxStackSize(), items.getSlotLimit(slot)); - } - // Inventory signals retain a minimum of 1 for a nonempty measured inventory. - return fullness <= 0 ? 0 : Math.max(1, proportionalSignal(fullness, end - first)); - } - - private static int proportionalSignal(double amount, double capacity) { - return capacity <= 0 || amount <= 0 ? 0 : (int) Math.clamp(15 * amount / capacity, 0, 15); - } - - public void clearDrill() { - DrillOperation.clearDrill(this); - } - - public static void tick(Level level, BlockPos pos, BlockState state, SteamMachine m) { - m.serverTick(); - } - - @Override - protected void afterMachineTick() { - tickMachine(level, worldPosition, getBlockState(), this); - } - - private static void tickMachine(Level level, BlockPos pos, BlockState state, SteamMachine m) { - boolean powered = level.hasNeighborSignal(pos); - boolean running = false; - if (powered && m.kind.equals("steam_drill")) - DrillOperation.clearDrill(m); - if (m.kind.equals("steam_elevator")) - ElevatorOperation.elevator(m, powered); - else if (!powered) { - switch (m.kind) { - case "steam_boiler_coal", "steam_boiler_oil", "steam_boiler_electric", - "steam_boiler_geothermal" -> - running = BoilerOperation.boil(m); - case "steam_furnace" -> running = FurnaceOperation.smelt(m); - case "steam_crusher" -> CrusherOperation.crush(m); - case "steam_drill" -> DrillOperation.drill(m); - case "steam_pump" -> PumpOperation.pump(m); - case "steam_still" -> running = StillOperation.distill(m); - case "steam_switch" -> m.exportSteam(); - default -> { - } - } - } - if (running) { - BlockPos snowPos = pos.above(); - if (level.getBlockState(snowPos).is(Blocks.SNOW)) - level.removeBlock(snowPos, false); - } - if (!powered && (m.kind.startsWith("steam_boiler") || m.kind.equals("steam_tank"))) { - for (Direction side : Direction.values()) - Transfer.pushFluids(level, pos, side, m.fluids.tank(m.steam), 100); - } - if (m.product >= 0) - for (Direction side : Direction.values()) - Transfer.pushFluids(level, pos, side, m.fluids.view(IoMode.OUTPUT), 100); - // Storage callbacks already notify comparators through setChanged. Also catch - // direct stack mutations, temperature and elevator-position changes each tick. - if (!m.isRemoved()) { - int signal = state.getAnalogOutputSignal(level, pos); - if (signal != m.lastComparatorSignal) { - m.lastComparatorSignal = signal; - m.setChanged(); - } - } - if (level.getGameTime() % 20 == 0) - m.setChanged(); - } - private void exportSteam() { - Direction output = getBlockState().getValue(BlockStateProperties.FACING); - Transfer.pushFluids(level, worldPosition, output, fluids.tank(steam), 1000); - } - boolean hasSteam(int amount) { - return fluids.tank(steam).getFluidAmount() >= amount; - } - void spendSteam(int amount) { - fluids.tank(steam).drain(amount, FluidAction.EXECUTE); - } - boolean burnFuel() { - if (burn > 0) { - burn--; - return true; - } - ItemStack stack = items.getStackInSlot(0); - int ticks = stack.getBurnTime(RecipeType.SMELTING); - if (ticks <= 0) - return false; - ItemStack remainder = stack.getCraftingRemainingItem(); - stack.shrink(1); - if (stack.isEmpty()) - items.setStackInSlot(0, remainder); - burn = totalBurn = ticks; - return true; - } - - @Override - protected void saveMachineData(CompoundTag tag, HolderLookup.Provider registries) { - tag.putInt("Burn", burn); - tag.putInt("TotalBurn", totalBurn); - tag.putFloat("Temperature", temperature); - tag.putIntArray("Progress", progress); - if (!pendingDistillation.isEmpty()) - tag.put("PendingDistillation", pendingDistillation.save(registries)); - tag.putInt("DistillationDuration", distillationDuration); - tag.putInt("Depth", depth); - tag.putInt("DrillPhase", drillPhase); - tag.putInt("DrillRetractionTicks", drillRetractionTicks); - tag.putBoolean("Raised", raised); - tag.putInt("ElevatorHeight", elevatorHeight); - } - @Override - protected void loadMachineData(CompoundTag tag, HolderLookup.Provider registries) { - // SA3 before MMDLib 2.0.2 saved every machine's buffer under "Energy". - if (powerStorage() != null && !tag.contains("energy") && tag.contains("Energy")) - energy.deserializeNBT(registries, tag.get("Energy")); - burn = tag.getInt("Burn"); - totalBurn = tag.getInt("TotalBurn"); - temperature = tag.getFloat("Temperature"); - int[] p = tag.getIntArray("Progress"); - System.arraycopy(p, 0, progress, 0, Math.min(p.length, 3)); - pendingDistillation = tag.contains("PendingDistillation") - ? net.neoforged.neoforge.fluids.FluidStack.parseOptional( - registries, tag.getCompound("PendingDistillation")) - : net.neoforged.neoforge.fluids.FluidStack.EMPTY; - distillationDuration = pendingDistillation.isEmpty() - ? 0 : Math.max(1, tag.getInt("DistillationDuration")); - depth = tag.getInt("Depth"); - drillPhase = Math.clamp(tag.getInt("DrillPhase"), 0, 2); - drillRetractionTicks = Math.clamp(tag.getInt("DrillRetractionTicks"), 0, 3); - raised = tag.getBoolean("Raised"); - elevatorHeight = tag.getInt("ElevatorHeight"); - } - public MachineSettings settings() { - return settings; - } - public net.neoforged.neoforge.fluids.FluidStack getSteamTank() { - return fluids.tank(steam).getFluid().copy(); - } - public int getSteamCapacity() { - return fluids.tank(steam).getCapacity(); - } - public net.neoforged.neoforge.fluids.FluidStack getWaterTank() { - return water < 0 ? net.neoforged.neoforge.fluids.FluidStack.EMPTY - : fluids.tank(water).getFluid().copy(); - } - public int getWaterCapacity() { - return water < 0 ? 0 : fluids.tank(water).getCapacity(); - } - public net.neoforged.neoforge.fluids.FluidStack getFuelTank() { - return fuel < 0 ? net.neoforged.neoforge.fluids.FluidStack.EMPTY - : fluids.tank(fuel).getFluid().copy(); - } - public int getFuelCapacity() { - return fuel < 0 ? 0 : fluids.tank(fuel).getCapacity(); - } - public net.neoforged.neoforge.fluids.FluidStack getProductTank() { - return product < 0 ? net.neoforged.neoforge.fluids.FluidStack.EMPTY - : fluids.tank(product).getFluid().copy(); - } - public int getProductCapacity() { - return product < 0 ? 0 : fluids.tank(product).getCapacity(); - } - public long getEnergy() { - return energy.stored(); - } - public long getEnergyCapacity() { - return energy.capacity(); - } - public float getTemperature() { - return temperature; - } - public int getMaxTemperature() { - return 2000; - } - public int getBurnTime() { - return burn; - } - public int getTotalBurnTime() { - return totalBurn; - } - public int getProgress() { - return progress[0]; - } - public int getSecondProgress() { - return progress[1]; - } - public int getThirdProgress() { - return progress[2]; - } - public int getProgressMax() { - return kind.equals("steam_crusher") ? 125 - : kind.equals("steam_still") ? Math.max(1, distillationDuration) - : 10000; - } - public int getDrillDepth() { - return depth; - } - public int getDrillRange() { - return DrillOperation.MAX_RANGE; - } - @Override - public net.neoforged.neoforge.items.IItemHandlerModifiable screenItems() { - return items; - } - @Override - public int[] screenRecipeSlots(net.minecraft.resources.ResourceLocation category) { - if (kind.equals("steam_crusher") && category.toString().equals("mmdlib:crushing")) - return new int[] {0}; - if (kind.equals("steam_furnace") && category.toString().equals("minecraft:smelting")) - return new int[] {1}; - return new int[0]; - } -} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamMachineEntity.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamMachineEntity.java new file mode 100644 index 0000000..0c04f79 --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamMachineEntity.java @@ -0,0 +1,123 @@ +package zone.moddev.mc.SteamAdvantage.machines; + +import java.util.List; +import java.util.function.IntUnaryOperator; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.HolderLookup; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; +import zone.moddev.mc.lib.machine.definition.MachineDefinition; +import zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity; +import zone.moddev.mc.lib.machine.recipe.MachineRecipeType; + +/** + * Block entity for SteamAdvantage's XML machines. The XML definition supplies storage, + * processors, capabilities and screen; this subclass only imports saves written before the + * XML port, when every machine shared one entity class. + * + *

Those saves kept machine state in top-level keys ({@code Burn}, {@code Temperature}, + * {@code Raised} and so on), every machine's items in one nine-slot {@code Items} inventory, and + * the electric boiler's energy under {@code Energy} before MMDLib 2.0.2. Each processor copies + * the keys it uses into its own state ({@link SteamProcessor#importLegacy}); the next save is + * in the current format. + */ +public class SteamMachineEntity extends DefinedMachineEntity { + /** Every pre-XML save wrote this key, whatever the machine; XML saves never do. */ + private static final String LEGACY_MARKER = "TotalBurn"; + private static final List LEGACY_KEYS = List.of("Burn", "TotalBurn", "Temperature", + "Progress", "PendingDistillation", "DistillationDuration", "Depth", "DrillPhase", + "DrillRetractionTicks", "Raised", "ElevatorHeight", "Energy"); + + /** Set while a drill moves itself along a track; its contents went with it. */ + boolean relocating; + + public SteamMachineEntity(BlockEntityType type, BlockPos pos, BlockState state, + MachineDefinition definition, @Nullable MachineRecipeType recipes) { + super(type, pos, state, definition, recipes); + } + + /** True for a save written before the XML port. */ + static boolean isLegacy(CompoundTag tag) { + return tag.contains(LEGACY_MARKER, Tag.TAG_ANY_NUMERIC); + } + + @Override + protected CompoundTag migrateMachineData(CompoundTag tag, HolderLookup.Provider registries) { + if (!isLegacy(tag)) + return tag; + var converted = tag.copy(); + if (!converted.contains("energy") && converted.contains("Energy")) + converted.put("energy", converted.get("Energy").copy()); + var saved = converted.getCompound("features"); + for (var config : definition.processors()) + features.findProcessor(config.id(), SteamProcessor.class).ifPresent(processor -> { + var state = saved.getCompound(config.id()); + processor.importLegacy(tag, state); + saved.put(config.id(), state); + }); + converted.put("features", saved); + LEGACY_KEYS.forEach(converted::remove); + return converted; + } + + /** + * Removing a drill also removes its pipe. MMDLib calls this only when the machine block is + * really replaced, never on chunk unload. + */ + @Override + public void dropContents(net.minecraft.world.level.Level level, BlockPos pos) { + if (relocating) + return; + features.allProcessors().stream() + .filter(DrillProcessor.class::isInstance) + .forEach(drill -> ((DrillProcessor) drill).clear()); + super.dropContents(level, pos); + } + + /** + * Like SA2, a recipe-driven machine (crusher, furnace) holds its work while it receives a + * redstone signal. Custom processors check the signal themselves. + */ + @Override + protected boolean processingAllowed() { + return super.processingAllowed() && !(level != null + && definition.processors().stream().anyMatch(lane -> lane.recipeType() != null) + && level.hasNeighborSignal(worldPosition)); + } + + /** Turning a drill to face elsewhere removes the pipe it had extended. */ + @Override + @SuppressWarnings("deprecation") + public void setBlockState(BlockState state) { + var level = getLevel(); + if (level != null && !level.isClientSide && state.is(getBlockState().getBlock()) + && state.hasProperty(net.minecraft.world.level.block.state.properties.BlockStateProperties.FACING) + && state.getValue(net.minecraft.world.level.block.state.properties.BlockStateProperties.FACING) + != getBlockState().getValue(net.minecraft.world.level.block.state.properties.BlockStateProperties.FACING)) + features.allProcessors().stream() + .filter(DrillProcessor.class::isInstance) + .forEach(drill -> ((DrillProcessor) drill).clear()); + super.setBlockState(state); + } + + /** + * Pre-XML item slots: 0 fuel or input, 1-3 furnace inputs, 4-8 outputs. Each XML machine + * declares only the slots it uses, so outputs move down. + */ + @Override + protected IntUnaryOperator legacySlots(String key, CompoundTag tag) { + if (!"Items".equals(key)) + return IntUnaryOperator.identity(); + return switch (definition.id().getPath()) { + case "steam_crusher" -> slot -> slot == 0 ? 0 : slot >= 4 ? slot - 3 : -1; + case "steam_drill" -> slot -> slot >= 4 ? slot - 4 : -1; + // Fuel (0) and the unused outputs (7, 8) have no place; they go to recovery. + case "steam_furnace" -> slot -> slot >= 1 && slot <= 6 ? slot - 1 : -1; + default -> IntUnaryOperator.identity(); + }; + } +} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamProcessor.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamProcessor.java new file mode 100644 index 0000000..eed4b01 --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamProcessor.java @@ -0,0 +1,127 @@ +package zone.moddev.mc.SteamAdvantage.machines; + +import java.util.List; +import java.util.Optional; + +import net.minecraft.core.Direction; +import net.minecraft.network.chat.Component; +import net.neoforged.neoforge.fluids.capability.IFluidHandler.FluidAction; +import net.neoforged.neoforge.fluids.capability.templates.FluidTank; +import zone.moddev.mc.lib.api.redstone.IRedstoneOutput; +import zone.moddev.mc.lib.api.redstone.RedstoneOutput; +import zone.moddev.mc.lib.machine.feature.StoredProcessor; +import zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity; + +/** + * Shared base for SteamAdvantage's XML machine processors. + * + *

Every SteamAdvantage machine keeps its steam tank first, so tank 0 is always steam; the + * remaining tank indexes follow each machine's XML declaration order, which matches the order + * SA3 used before the XML port so existing saves load into the same tanks. + * + *

Like SA2, a machine stops working while it receives any redstone signal. That check lives + * here, rather than in MMDLib's per-face redstone control, so the default is unchanged. + * + *

Each processor also supplies the machine's comparator reading, selected in the machine XML + * with {@code }. + */ +public abstract class SteamProcessor extends StoredProcessor implements IRedstoneOutput { + /** The comparator descriptor ID every SteamAdvantage machine XML selects. */ + public static final String COMPARATOR = "steamadvantage/comparator"; + protected static final int STEAM = 0; + + /** The machine block entity; only valid on a live host, never on the schema prototype. */ + protected final DefinedMachineEntity entity() { + return (DefinedMachineEntity) machine; + } + + protected final FluidTank tank(int index) { + return entity().fluids.tank(index); + } + + protected final boolean powered() { + return machine.level().hasNeighborSignal(machine.position()); + } + + protected final boolean hasSteam(int amount) { + return tank(STEAM).getFluidAmount() >= amount; + } + + protected final void spendSteam(int amount) { + tank(STEAM).drain(amount, FluidAction.EXECUTE); + } + + /** The machine's front, for horizontal and six-way machines alike. */ + protected final Direction front() { + var state = machine.blockState(); + for (var property : state.getProperties()) + if (property.getName().equals("facing") && property.getValueClass() == Direction.class) + return (Direction) state.getValue(property); + return Direction.NORTH; + } + + /** Pushes up to {@code amount} mB from a tank out of every face. */ + protected final void pushAllSides(int tank, int amount) { + for (Direction side : Direction.values()) + zone.moddev.mc.lib.api.capabilities.Transfer.pushFluids( + machine.level(), machine.position(), side, tank(tank), amount); + } + + /** A running heat source melts snow resting on top of the machine, as in SA2. */ + protected final void meltSnow() { + var above = machine.position().above(); + if (machine.level().getBlockState(above).is(net.minecraft.world.level.block.Blocks.SNOW)) + machine.level().removeBlock(above, false); + } + + /** An integer variable that is saved, synchronized and usable in appearance conditions. */ + protected final zone.moddev.mc.lib.machine.feature.ProcessorState.Key intVariable( + String name) { + return variables.define(name, com.mojang.serialization.Codec.INT, 0); + } + + /** + * Copies this machine's pre-XML top-level save keys (Burn, Temperature and so on) into + * the processor's saved state. Called once, on a save written before the XML port; see + * {@link SteamMachineEntity}. + */ + void importLegacy(net.minecraft.nbt.CompoundTag old, net.minecraft.nbt.CompoundTag state) {} + + /** Current comparator reading, 0..15. Called only on a live host. */ + protected abstract int comparatorSignal(); + + @Override + public final List redstoneOutputs() { + return List.of(new RedstoneOutput(COMPARATOR, + Component.translatable("redstone.steamadvantage.comparator"), + Component.translatable("redstone.steamadvantage.comparator.desc"), 0xC8C8C8, + Optional.empty(), () -> machine == null || machine.removed() + ? 0 : comparatorSignal())); + } + + /** SA2's proportional reading: floor(15 * fraction), zero when empty. */ + protected static int proportionalSignal(double amount, double capacity) { + return capacity <= 0 || amount <= 0 ? 0 : (int) Math.clamp(15 * amount / capacity, 0, 15); + } + + protected final int tankSignal(int index) { + var tank = tank(index); + return proportionalSignal(tank.getFluidAmount(), tank.getCapacity()); + } + + /** + * Fullness of item slots {@code first..end-1}, normalizing each stack to its own limit. + * A nonempty measured inventory reads at least 1. + */ + protected final int inventorySignal(int first, int end) { + var items = entity().items; + double fullness = 0; + for (int slot = first; slot < end; slot++) { + var stack = items.getStackInSlot(slot); + if (!stack.isEmpty()) + fullness += (double) stack.getCount() + / Math.min(stack.getMaxStackSize(), items.getSlotLimit(slot)); + } + return fullness <= 0 ? 0 : Math.max(1, proportionalSignal(fullness, end - first)); + } +} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamScreens.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamScreens.java new file mode 100644 index 0000000..e9a742b --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamScreens.java @@ -0,0 +1,51 @@ +package zone.moddev.mc.SteamAdvantage.machines; + +import zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity; + +/** + * Screen values for SteamAdvantage's XML machines. MMDLib binds an XML machine's screen to + * {@link DefinedMachineEntity}, so machine XML names these as + * {@code zone.moddev.mc.SteamAdvantage.machines.SteamScreens#burnTime} and so on; each reads + * the machine's processor. + */ +public final class SteamScreens { + private SteamScreens() {} + + private static java.util.Optional processor(DefinedMachineEntity machine, Class type) { + return machine.features.allProcessors().stream() + .filter(type::isInstance).map(type::cast).findFirst(); + } + + public static int burnTime(DefinedMachineEntity machine) { + return processor(machine, Burner.class).map(Burner::burnTime).orElse(0); + } + + public static int totalBurnTime(DefinedMachineEntity machine) { + return processor(machine, Burner.class).map(Burner::totalBurnTime).orElse(0); + } + + public static float temperature(DefinedMachineEntity machine) { + return processor(machine, GeothermalBoilerProcessor.class) + .map(GeothermalBoilerProcessor::temperature).orElse(0f); + } + + public static int maxTemperature(DefinedMachineEntity machine) { + return GeothermalBoilerProcessor.MAX_TEMPERATURE; + } + + public static int drillDepth(DefinedMachineEntity machine) { + return processor(machine, DrillProcessor.class).map(DrillProcessor::depth).orElse(0); + } + + public static int drillRange(DefinedMachineEntity machine) { + return DrillProcessor.MAX_RANGE; + } + + public static int distillProgress(DefinedMachineEntity machine) { + return processor(machine, StillProcessor.class).map(StillProcessor::progress).orElse(0); + } + + public static int distillDuration(DefinedMachineEntity machine) { + return processor(machine, StillProcessor.class).map(StillProcessor::duration).orElse(1); + } +} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamTankProcessor.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamTankProcessor.java new file mode 100644 index 0000000..f110d8b --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamTankProcessor.java @@ -0,0 +1,30 @@ +package zone.moddev.mc.SteamAdvantage.machines; + +import net.minecraft.core.Direction; +import zone.moddev.mc.lib.api.capabilities.Transfer; +import zone.moddev.mc.lib.machine.feature.ProcessorMachine; +import zone.moddev.mc.lib.machine.feature.ProcessorState; + +/** Steam tank: pushes up to 100 mB of steam out of every face each tick while unpowered. */ +public final class SteamTankProcessor extends SteamProcessor { + @Override + public boolean canStart(ProcessorState state, ProcessorMachine host) { + return !tank(STEAM).isEmpty() && !powered(); + } + + @Override + public ProcessState process(ProcessorState state, ProcessorMachine host, int ticks) { + if (tank(STEAM).isEmpty() || powered()) + return ProcessState.IDLE; + int moved = 0; + for (int step = 0; step < ticks; step++) + for (Direction side : Direction.values()) + moved += Transfer.pushFluids(host.level(), host.position(), side, tank(STEAM), 100); + return moved > 0 ? ProcessState.RUNNING : ProcessState.IDLE; + } + + @Override + protected int comparatorSignal() { + return tankSignal(STEAM); + } +} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamValveProcessor.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamValveProcessor.java new file mode 100644 index 0000000..6a9aa66 --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamValveProcessor.java @@ -0,0 +1,28 @@ +package zone.moddev.mc.SteamAdvantage.machines; + +import zone.moddev.mc.lib.api.capabilities.Transfer; +import zone.moddev.mc.lib.machine.feature.ProcessorMachine; +import zone.moddev.mc.lib.machine.feature.ProcessorState; + +/** Steam switch (valve): passes up to 1000 mB of steam out of its front each tick unless powered. */ +public final class SteamValveProcessor extends SteamProcessor { + @Override + public boolean canStart(ProcessorState state, ProcessorMachine host) { + return !tank(STEAM).isEmpty() && !powered(); + } + + @Override + public ProcessState process(ProcessorState state, ProcessorMachine host, int ticks) { + if (tank(STEAM).isEmpty() || powered()) + return ProcessState.IDLE; + int moved = 0; + for (int step = 0; step < ticks; step++) + moved += Transfer.pushFluids(host.level(), host.position(), front(), tank(STEAM), 1000); + return moved > 0 ? ProcessState.RUNNING : ProcessState.IDLE; + } + + @Override + protected int comparatorSignal() { + return tankSignal(STEAM); + } +} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/StillOperation.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/StillOperation.java deleted file mode 100644 index da45742..0000000 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/StillOperation.java +++ /dev/null @@ -1,51 +0,0 @@ -package zone.moddev.mc.SteamAdvantage.machines; - -import net.neoforged.neoforge.fluids.FluidStack; -import net.neoforged.neoforge.fluids.capability.IFluidHandler.FluidAction; -import zone.moddev.mc.poweradvantage.api.distillation.DistillingRecipe; - -/** PA3 recipe processing with persisted operation progress and output. */ -final class StillOperation { - private StillOperation() {} - - static boolean distill(SteamMachine machine) { - boolean running = !machine.pendingDistillation.isEmpty(); - if (machine.pendingDistillation.isEmpty()) { - if (!machine.hasSteam(150)) - return false; - var inputTank = machine.fluids.tank(machine.water); - var recipeHolder = DistillingRecipe.find(machine.getLevel(), inputTank.getFluid()); - if (recipeHolder.isEmpty()) - return false; - var recipe = recipeHolder.get().value(); - FluidStack result = recipe.output().copy(); - if (machine.fluids.tank(machine.product).fill(result, FluidAction.SIMULATE) - != result.getAmount()) - return false; - int amount = recipe.input().amount(); - if (inputTank.drain(amount, FluidAction.SIMULATE).getAmount() != amount) - return false; - inputTank.drain(amount, FluidAction.EXECUTE); - machine.spendSteam(150); - machine.pendingDistillation = result; - machine.distillationDuration = Math.max(1, recipe.duration()); - machine.progress[0] = 0; - running = true; - } - - if (machine.progress[0] < machine.distillationDuration) - machine.progress[0]++; - if (machine.progress[0] < machine.distillationDuration) - return running; - - var outputTank = machine.fluids.tank(machine.product); - if (outputTank.fill(machine.pendingDistillation, FluidAction.SIMULATE) - != machine.pendingDistillation.getAmount()) - return running; - outputTank.fill(machine.pendingDistillation, FluidAction.EXECUTE); - machine.pendingDistillation = FluidStack.EMPTY; - machine.progress[0] = 0; - machine.distillationDuration = 0; - return running; - } -} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/StillProcessor.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/StillProcessor.java new file mode 100644 index 0000000..e74e308 --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/StillProcessor.java @@ -0,0 +1,113 @@ +package zone.moddev.mc.SteamAdvantage.machines; + +import net.minecraft.nbt.CompoundTag; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.capability.IFluidHandler.FluidAction; +import zone.moddev.mc.lib.machine.feature.ProcessorMachine; +import zone.moddev.mc.lib.machine.feature.ProcessorState; +import zone.moddev.mc.lib.machine.feature.StorageAdmission; +import zone.moddev.mc.lib.machine.ingredient.FluidAmount; +import zone.moddev.mc.poweradvantage.api.distillation.DistillingRecipe; + +/** + * Steam-powered still: runs Power Advantage distilling recipes. Spends 150 mB of steam and the + * recipe's input when a batch starts, holds the result until the batch time has passed and the + * product tank (1) can take it all. Tanks: steam (0), product (1), input (2). + */ +public final class StillProcessor extends SteamProcessor implements StorageAdmission { + private static final int PRODUCT = 1, INPUT = 2; + private final ProcessorState.Key pending = variables.define("pending", + FluidStack.OPTIONAL_CODEC, FluidStack.EMPTY, FluidStack::copy, false, false); + private final ProcessorState.Key duration = intVariable("duration"), + progress = intVariable("progress"); + + @Override + public boolean canStart(ProcessorState state, ProcessorMachine host) { + return true; + } + + @Override + public ProcessState process(ProcessorState state, ProcessorMachine host, int ticks) { + boolean running = false; + for (int step = 0; step < ticks; step++) { + if (!powered()) + running |= distill(); + pushAllSides(PRODUCT, 100); + } + if (running) + meltSnow(); + return running ? ProcessState.RUNNING : ProcessState.IDLE; + } + + private boolean distill() { + boolean running = !variables.get(pending).isEmpty(); + if (!running) { + if (!hasSteam(150)) + return false; + var input = tank(INPUT); + var holder = DistillingRecipe.find(machine.level(), input.getFluid()); + if (holder.isEmpty()) + return false; + var recipe = holder.get().value(); + FluidStack result = recipe.output().copy(); + if (tank(PRODUCT).fill(result, FluidAction.SIMULATE) != result.getAmount()) + return false; + int amount = recipe.input().amount(); + if (input.drain(amount, FluidAction.SIMULATE).getAmount() != amount) + return false; + input.drain(amount, FluidAction.EXECUTE); + spendSteam(150); + variables.set(pending, result); + variables.set(duration, Math.max(1, recipe.duration())); + variables.set(progress, 0); + running = true; + } + int time = variables.get(duration); + if (variables.get(progress) < time) + variables.set(progress, variables.get(progress) + 1); + if (variables.get(progress) < time) + return running; + var result = variables.get(pending); + if (tank(PRODUCT).fill(result, FluidAction.SIMULATE) != result.getAmount()) + return running; + tank(PRODUCT).fill(result, FluidAction.EXECUTE); + variables.set(pending, FluidStack.EMPTY); + variables.set(progress, 0); + variables.set(duration, 0); + return running; + } + + @Override + public boolean acceptsFluid(ProcessorMachine host, String member, FluidAmount fluid) { + return host.level() != null && DistillingRecipe.accepts(host.level(), + new FluidStack(fluid.fluid(), Math.max(1, fluid.amount()), fluid.components())); + } + + @Override + void importLegacy(CompoundTag old, CompoundTag state) { + int[] progress = old.getIntArray("Progress"); + if (old.contains("PendingDistillation")) { + state.put("pending", old.getCompound("PendingDistillation")); + state.putInt("duration", Math.max(1, old.getInt("DistillationDuration"))); + state.putInt("progress", progress.length > 0 ? progress[0] : 0); + } + } + + @Override + protected int comparatorSignal() { + return tankSignal(INPUT); + } + + public int progress() { + return variables.get(progress); + } + + public int duration() { + return Math.max(1, variables.get(duration)); + } + + /** The batch result waiting to be delivered, or empty. */ + public FluidStack pending() { + return variables.get(pending).copy(); + } +} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/recipes/SteamCrushingRecipes.java b/src/main/java/zone/moddev/mc/SteamAdvantage/recipes/SteamCrushingRecipes.java new file mode 100644 index 0000000..8af5a27 --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/recipes/SteamCrushingRecipes.java @@ -0,0 +1,50 @@ +package zone.moddev.mc.SteamAdvantage.recipes; + +import net.minecraft.core.HolderSet; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import zone.moddev.mc.lib.common.recipes.CrushingRecipe; +import zone.moddev.mc.lib.machine.recipe.MachineRecipeBuilder; +import zone.moddev.mc.lib.machine.recipe.generation.MachineRecipeGenerator; +import zone.moddev.mc.lib.machine.recipe.generation.MachineRecipeOutput; +import zone.moddev.mc.lib.machine.recipe.generation.RecipeGenerationContext; + +/** + * Steam crusher recipes: every MMDLib crushing recipe (including other mods' and datapacks'), + * taking {@code time} ticks and {@code steam} mB of steam per item. The defaults match the + * crusher before the XML port, 125 ticks at 150 mB per tick. + */ +public final class SteamCrushingRecipes implements MachineRecipeGenerator { + static final ResourceKey STEAM = + ResourceKey.create(Registries.FLUID, ResourceLocation.parse("poweradvantage:steam")); + + @Override + public void generate(RecipeGenerationContext ctx, MachineRecipeOutput output) { + var p = ctx.properties(); + p.requireOnly("input-group", "output-group", "steam-group", "steam", "time"); + String input = p.string("input-group", "input"); + String result = p.string("output-group", "output"); + String steamGroup = p.string("steam-group", "steam"); + int steam = p.integer("steam", 18750, 1, Integer.MAX_VALUE); + int time = p.integer("time", 125, 1, Integer.MAX_VALUE); + var steamFluid = HolderSet.direct( + ctx.registries().lookupOrThrow(Registries.FLUID).getOrThrow(STEAM)); + for (var holder : ctx.recipes()) { + if (!(holder.value() instanceof CrushingRecipe recipe)) + continue; + var product = recipe.getResultItem(ctx.registries()); + if (product.isEmpty() || recipe.getIngredients().size() != 1) + continue; + var id = ResourceLocation.fromNamespaceAndPath(ctx.recipeType().id().getNamespace(), + "generated/" + ctx.recipeType().id().getPath() + "/crushing/" + + holder.id().getNamespace() + "/" + holder.id().getPath()); + output.accept(id, MachineRecipeBuilder.recipe(ctx.recipeType()) + .inputItems(input, recipe.getIngredients().getFirst(), 1) + .inputFluids(steamGroup, steamFluid, steam) + .outputItem(result, product.copy()) + .time(time) + .build()); + } + } +} diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/recipes/SteamSmeltingRecipes.java b/src/main/java/zone/moddev/mc/SteamAdvantage/recipes/SteamSmeltingRecipes.java new file mode 100644 index 0000000..4c72ed9 --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/recipes/SteamSmeltingRecipes.java @@ -0,0 +1,28 @@ +package zone.moddev.mc.SteamAdvantage.recipes; + +import net.minecraft.core.HolderSet; +import net.minecraft.core.registries.Registries; +import zone.moddev.mc.lib.machine.recipe.generation.MachineRecipeOutput; +import zone.moddev.mc.lib.machine.recipe.generation.RecipeGenerationContext; +import zone.moddev.mc.lib.machine.recipe.generation.RecipeTransforms; +import zone.moddev.mc.lib.machine.recipe.generation.SmeltingRecipeGenerator; + +/** + * Steam furnace recipes: every smelting recipe, at its own cooking time, paid in steam. MMDLib's + * smelting adapter prices a recipe at {@code energy-per-tick} FE per cooking tick (20); this + * converts that to steam at {@code energy-per-mb} FE per mB (2), so a 200-tick recipe costs + * 2000 mB. + */ +public final class SteamSmeltingRecipes extends SmeltingRecipeGenerator { + @Override + public void generate(RecipeGenerationContext ctx, MachineRecipeOutput output) { + var p = ctx.properties(); + String group = p.string("steam-group", "steam"); + long rate = p.longValue("energy-per-mb", 2, 1, Long.MAX_VALUE); + var steam = HolderSet.direct(ctx.registries().lookupOrThrow(Registries.FLUID) + .getOrThrow(SteamCrushingRecipes.STEAM)); + super.generate(ctx.withProperties(p.without("steam-group", "energy-per-mb")), + (id, recipe) -> output.accept(id, + RecipeTransforms.energyToFluid(recipe, group, steam, rate))); + } +} diff --git a/src/main/resources/assets/steamadvantage/blockstates/steam_boiler_coal.json b/src/main/resources/assets/steamadvantage/blockstates/steam_boiler_coal.json deleted file mode 100644 index 4dbb577..0000000 --- a/src/main/resources/assets/steamadvantage/blockstates/steam_boiler_coal.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "variants": { - "facing=north": { - "model": "steamadvantage:block/steam_boiler_coal", - "y": 0 - }, - "facing=east": { - "model": "steamadvantage:block/steam_boiler_coal", - "y": 90 - }, - "facing=south": { - "model": "steamadvantage:block/steam_boiler_coal", - "y": 180 - }, - "facing=west": { - "model": "steamadvantage:block/steam_boiler_coal", - "y": 270 - }, - "facing=up": { - "model": "steamadvantage:block/steam_boiler_coal", - "x": 270 - }, - "facing=down": { - "model": "steamadvantage:block/steam_boiler_coal", - "x": 90 - } - } -} diff --git a/src/main/resources/assets/steamadvantage/blockstates/steam_boiler_electric.json b/src/main/resources/assets/steamadvantage/blockstates/steam_boiler_electric.json deleted file mode 100644 index c60208a..0000000 --- a/src/main/resources/assets/steamadvantage/blockstates/steam_boiler_electric.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "variants": { - "facing=north": { - "model": "steamadvantage:block/steam_boiler_electric", - "y": 0 - }, - "facing=east": { - "model": "steamadvantage:block/steam_boiler_electric", - "y": 90 - }, - "facing=south": { - "model": "steamadvantage:block/steam_boiler_electric", - "y": 180 - }, - "facing=west": { - "model": "steamadvantage:block/steam_boiler_electric", - "y": 270 - }, - "facing=up": { - "model": "steamadvantage:block/steam_boiler_electric", - "x": 270 - }, - "facing=down": { - "model": "steamadvantage:block/steam_boiler_electric", - "x": 90 - } - } -} diff --git a/src/main/resources/assets/steamadvantage/blockstates/steam_boiler_geothermal.json b/src/main/resources/assets/steamadvantage/blockstates/steam_boiler_geothermal.json deleted file mode 100644 index 1291126..0000000 --- a/src/main/resources/assets/steamadvantage/blockstates/steam_boiler_geothermal.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "variants": { - "facing=north": { - "model": "steamadvantage:block/steam_boiler_geothermal", - "y": 0 - }, - "facing=east": { - "model": "steamadvantage:block/steam_boiler_geothermal", - "y": 90 - }, - "facing=south": { - "model": "steamadvantage:block/steam_boiler_geothermal", - "y": 180 - }, - "facing=west": { - "model": "steamadvantage:block/steam_boiler_geothermal", - "y": 270 - }, - "facing=up": { - "model": "steamadvantage:block/steam_boiler_geothermal", - "x": 270 - }, - "facing=down": { - "model": "steamadvantage:block/steam_boiler_geothermal", - "x": 90 - } - } -} diff --git a/src/main/resources/assets/steamadvantage/blockstates/steam_boiler_oil.json b/src/main/resources/assets/steamadvantage/blockstates/steam_boiler_oil.json deleted file mode 100644 index 01882da..0000000 --- a/src/main/resources/assets/steamadvantage/blockstates/steam_boiler_oil.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "variants": { - "facing=north": { - "model": "steamadvantage:block/steam_boiler_oil", - "y": 0 - }, - "facing=east": { - "model": "steamadvantage:block/steam_boiler_oil", - "y": 90 - }, - "facing=south": { - "model": "steamadvantage:block/steam_boiler_oil", - "y": 180 - }, - "facing=west": { - "model": "steamadvantage:block/steam_boiler_oil", - "y": 270 - }, - "facing=up": { - "model": "steamadvantage:block/steam_boiler_oil", - "x": 270 - }, - "facing=down": { - "model": "steamadvantage:block/steam_boiler_oil", - "x": 90 - } - } -} diff --git a/src/main/resources/assets/steamadvantage/blockstates/steam_crusher.json b/src/main/resources/assets/steamadvantage/blockstates/steam_crusher.json deleted file mode 100644 index 3b0e4e7..0000000 --- a/src/main/resources/assets/steamadvantage/blockstates/steam_crusher.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "variants": { - "facing=north": { - "model": "steamadvantage:block/steam_crusher", - "y": 0 - }, - "facing=east": { - "model": "steamadvantage:block/steam_crusher", - "y": 90 - }, - "facing=south": { - "model": "steamadvantage:block/steam_crusher", - "y": 180 - }, - "facing=west": { - "model": "steamadvantage:block/steam_crusher", - "y": 270 - }, - "facing=up": { - "model": "steamadvantage:block/steam_crusher", - "x": 270 - }, - "facing=down": { - "model": "steamadvantage:block/steam_crusher", - "x": 90 - } - } -} diff --git a/src/main/resources/assets/steamadvantage/blockstates/steam_drill.json b/src/main/resources/assets/steamadvantage/blockstates/steam_drill.json deleted file mode 100644 index 52dec2e..0000000 --- a/src/main/resources/assets/steamadvantage/blockstates/steam_drill.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "variants": { - "facing=north": { - "model": "steamadvantage:block/steam_drill", - "y": 0 - }, - "facing=east": { - "model": "steamadvantage:block/steam_drill", - "y": 90 - }, - "facing=south": { - "model": "steamadvantage:block/steam_drill", - "y": 180 - }, - "facing=west": { - "model": "steamadvantage:block/steam_drill", - "y": 270 - }, - "facing=up": { - "model": "steamadvantage:block/steam_drill", - "x": 270 - }, - "facing=down": { - "model": "steamadvantage:block/steam_drill", - "x": 90 - } - } -} diff --git a/src/main/resources/assets/steamadvantage/blockstates/steam_elevator.json b/src/main/resources/assets/steamadvantage/blockstates/steam_elevator.json deleted file mode 100644 index a98dd00..0000000 --- a/src/main/resources/assets/steamadvantage/blockstates/steam_elevator.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "variants": { - "facing=north": { - "model": "steamadvantage:block/steam_elevator", - "y": 0 - }, - "facing=east": { - "model": "steamadvantage:block/steam_elevator", - "y": 90 - }, - "facing=south": { - "model": "steamadvantage:block/steam_elevator", - "y": 180 - }, - "facing=west": { - "model": "steamadvantage:block/steam_elevator", - "y": 270 - }, - "facing=up": { - "model": "steamadvantage:block/steam_elevator", - "x": 270 - }, - "facing=down": { - "model": "steamadvantage:block/steam_elevator", - "x": 90 - } - } -} diff --git a/src/main/resources/assets/steamadvantage/blockstates/steam_furnace.json b/src/main/resources/assets/steamadvantage/blockstates/steam_furnace.json deleted file mode 100644 index 6a2c81d..0000000 --- a/src/main/resources/assets/steamadvantage/blockstates/steam_furnace.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "variants": { - "facing=north": { - "model": "steamadvantage:block/steam_furnace", - "y": 0 - }, - "facing=east": { - "model": "steamadvantage:block/steam_furnace", - "y": 90 - }, - "facing=south": { - "model": "steamadvantage:block/steam_furnace", - "y": 180 - }, - "facing=west": { - "model": "steamadvantage:block/steam_furnace", - "y": 270 - }, - "facing=up": { - "model": "steamadvantage:block/steam_furnace", - "x": 270 - }, - "facing=down": { - "model": "steamadvantage:block/steam_furnace", - "x": 90 - } - } -} diff --git a/src/main/resources/assets/steamadvantage/blockstates/steam_pump.json b/src/main/resources/assets/steamadvantage/blockstates/steam_pump.json deleted file mode 100644 index 56826ce..0000000 --- a/src/main/resources/assets/steamadvantage/blockstates/steam_pump.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "variants": { - "facing=north": { - "model": "steamadvantage:block/steam_pump", - "y": 0 - }, - "facing=east": { - "model": "steamadvantage:block/steam_pump", - "y": 90 - }, - "facing=south": { - "model": "steamadvantage:block/steam_pump", - "y": 180 - }, - "facing=west": { - "model": "steamadvantage:block/steam_pump", - "y": 270 - }, - "facing=up": { - "model": "steamadvantage:block/steam_pump", - "x": 270 - }, - "facing=down": { - "model": "steamadvantage:block/steam_pump", - "x": 90 - } - } -} diff --git a/src/main/resources/assets/steamadvantage/blockstates/steam_still.json b/src/main/resources/assets/steamadvantage/blockstates/steam_still.json deleted file mode 100644 index 723b64a..0000000 --- a/src/main/resources/assets/steamadvantage/blockstates/steam_still.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "variants": { - "facing=north": { - "model": "steamadvantage:block/steam_still", - "y": 0 - }, - "facing=east": { - "model": "steamadvantage:block/steam_still", - "y": 90 - }, - "facing=south": { - "model": "steamadvantage:block/steam_still", - "y": 180 - }, - "facing=west": { - "model": "steamadvantage:block/steam_still", - "y": 270 - }, - "facing=up": { - "model": "steamadvantage:block/steam_still", - "x": 270 - }, - "facing=down": { - "model": "steamadvantage:block/steam_still", - "x": 90 - } - } -} diff --git a/src/main/resources/assets/steamadvantage/blockstates/steam_switch.json b/src/main/resources/assets/steamadvantage/blockstates/steam_switch.json deleted file mode 100644 index e6066c7..0000000 --- a/src/main/resources/assets/steamadvantage/blockstates/steam_switch.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "variants": { - "facing=north": { - "model": "steamadvantage:block/steam_switch_off", - "y": 0 - }, - "facing=east": { - "model": "steamadvantage:block/steam_switch_off", - "y": 90 - }, - "facing=south": { - "model": "steamadvantage:block/steam_switch_off", - "y": 180 - }, - "facing=west": { - "model": "steamadvantage:block/steam_switch_off", - "y": 270 - }, - "facing=up": { - "model": "steamadvantage:block/steam_switch_off", - "x": 270 - }, - "facing=down": { - "model": "steamadvantage:block/steam_switch_off", - "x": 90 - } - } -} diff --git a/src/main/resources/assets/steamadvantage/blockstates/steam_tank.json b/src/main/resources/assets/steamadvantage/blockstates/steam_tank.json deleted file mode 100644 index 5064a91..0000000 --- a/src/main/resources/assets/steamadvantage/blockstates/steam_tank.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "variants": { - "facing=north": { - "model": "steamadvantage:block/steam_tank", - "y": 0 - }, - "facing=east": { - "model": "steamadvantage:block/steam_tank", - "y": 90 - }, - "facing=south": { - "model": "steamadvantage:block/steam_tank", - "y": 180 - }, - "facing=west": { - "model": "steamadvantage:block/steam_tank", - "y": 270 - }, - "facing=up": { - "model": "steamadvantage:block/steam_tank", - "x": 270 - }, - "facing=down": { - "model": "steamadvantage:block/steam_tank", - "x": 90 - } - } -} diff --git a/src/main/resources/assets/steamadvantage/lang/en_us.json b/src/main/resources/assets/steamadvantage/lang/en_us.json index 62299c1..d437ed7 100644 --- a/src/main/resources/assets/steamadvantage/lang/en_us.json +++ b/src/main/resources/assets/steamadvantage/lang/en_us.json @@ -55,5 +55,7 @@ "screen.steamadvantage.progress_amount": "Processing: {value} / {max}", "screen.steamadvantage.depth_amount": "Extension: {value} / {max} blocks", "screen.steamadvantage.elevator_help": "Redstone raises; no signal retracts.", - "screen.steamadvantage.valve_help": "Redstone closes the facing outlet." + "screen.steamadvantage.valve_help": "Redstone closes the facing outlet.", + "redstone.steamadvantage.comparator": "Machine reading", + "redstone.steamadvantage.comparator.desc": "What a comparator reads from this machine" } diff --git a/src/main/resources/assets/steamadvantage/models/block/steam_boiler_coal.json b/src/main/resources/assets/steamadvantage/models/block/steam_boiler_coal_model.json similarity index 100% rename from src/main/resources/assets/steamadvantage/models/block/steam_boiler_coal.json rename to src/main/resources/assets/steamadvantage/models/block/steam_boiler_coal_model.json diff --git a/src/main/resources/assets/steamadvantage/models/block/steam_boiler_electric.json b/src/main/resources/assets/steamadvantage/models/block/steam_boiler_electric_model.json similarity index 100% rename from src/main/resources/assets/steamadvantage/models/block/steam_boiler_electric.json rename to src/main/resources/assets/steamadvantage/models/block/steam_boiler_electric_model.json diff --git a/src/main/resources/assets/steamadvantage/models/block/steam_boiler_geothermal.json b/src/main/resources/assets/steamadvantage/models/block/steam_boiler_geothermal_model.json similarity index 100% rename from src/main/resources/assets/steamadvantage/models/block/steam_boiler_geothermal.json rename to src/main/resources/assets/steamadvantage/models/block/steam_boiler_geothermal_model.json diff --git a/src/main/resources/assets/steamadvantage/models/block/steam_boiler_oil.json b/src/main/resources/assets/steamadvantage/models/block/steam_boiler_oil_model.json similarity index 100% rename from src/main/resources/assets/steamadvantage/models/block/steam_boiler_oil.json rename to src/main/resources/assets/steamadvantage/models/block/steam_boiler_oil_model.json diff --git a/src/main/resources/assets/steamadvantage/models/block/steam_crusher.json b/src/main/resources/assets/steamadvantage/models/block/steam_crusher_model.json similarity index 100% rename from src/main/resources/assets/steamadvantage/models/block/steam_crusher.json rename to src/main/resources/assets/steamadvantage/models/block/steam_crusher_model.json diff --git a/src/main/resources/assets/steamadvantage/models/block/steam_drill.json b/src/main/resources/assets/steamadvantage/models/block/steam_drill_model.json similarity index 100% rename from src/main/resources/assets/steamadvantage/models/block/steam_drill.json rename to src/main/resources/assets/steamadvantage/models/block/steam_drill_model.json diff --git a/src/main/resources/assets/steamadvantage/models/block/steam_elevator.json b/src/main/resources/assets/steamadvantage/models/block/steam_elevator_model.json similarity index 100% rename from src/main/resources/assets/steamadvantage/models/block/steam_elevator.json rename to src/main/resources/assets/steamadvantage/models/block/steam_elevator_model.json diff --git a/src/main/resources/assets/steamadvantage/models/block/steam_furnace.json b/src/main/resources/assets/steamadvantage/models/block/steam_furnace_model.json similarity index 100% rename from src/main/resources/assets/steamadvantage/models/block/steam_furnace.json rename to src/main/resources/assets/steamadvantage/models/block/steam_furnace_model.json diff --git a/src/main/resources/assets/steamadvantage/models/block/steam_pump.json b/src/main/resources/assets/steamadvantage/models/block/steam_pump_model.json similarity index 100% rename from src/main/resources/assets/steamadvantage/models/block/steam_pump.json rename to src/main/resources/assets/steamadvantage/models/block/steam_pump_model.json diff --git a/src/main/resources/assets/steamadvantage/models/block/steam_still.json b/src/main/resources/assets/steamadvantage/models/block/steam_still_model.json similarity index 100% rename from src/main/resources/assets/steamadvantage/models/block/steam_still.json rename to src/main/resources/assets/steamadvantage/models/block/steam_still_model.json diff --git a/src/main/resources/assets/steamadvantage/models/block/steam_tank.json b/src/main/resources/assets/steamadvantage/models/block/steam_tank_model.json similarity index 100% rename from src/main/resources/assets/steamadvantage/models/block/steam_tank.json rename to src/main/resources/assets/steamadvantage/models/block/steam_tank_model.json diff --git a/src/main/resources/assets/steamadvantage/models/item/steam_boiler_coal.json b/src/main/resources/assets/steamadvantage/models/item/steam_boiler_coal.json deleted file mode 100644 index 8305a21..0000000 --- a/src/main/resources/assets/steamadvantage/models/item/steam_boiler_coal.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "parent": "steamadvantage:block/steam_boiler_coal" -} diff --git a/src/main/resources/assets/steamadvantage/models/item/steam_boiler_electric.json b/src/main/resources/assets/steamadvantage/models/item/steam_boiler_electric.json deleted file mode 100644 index 76a4dfe..0000000 --- a/src/main/resources/assets/steamadvantage/models/item/steam_boiler_electric.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "parent": "steamadvantage:block/steam_boiler_electric" -} diff --git a/src/main/resources/assets/steamadvantage/models/item/steam_boiler_geothermal.json b/src/main/resources/assets/steamadvantage/models/item/steam_boiler_geothermal.json deleted file mode 100644 index 44d1971..0000000 --- a/src/main/resources/assets/steamadvantage/models/item/steam_boiler_geothermal.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "parent": "steamadvantage:block/steam_boiler_geothermal" -} diff --git a/src/main/resources/assets/steamadvantage/models/item/steam_boiler_oil.json b/src/main/resources/assets/steamadvantage/models/item/steam_boiler_oil.json deleted file mode 100644 index 6174975..0000000 --- a/src/main/resources/assets/steamadvantage/models/item/steam_boiler_oil.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "parent": "steamadvantage:block/steam_boiler_oil" -} diff --git a/src/main/resources/assets/steamadvantage/models/item/steam_crusher.json b/src/main/resources/assets/steamadvantage/models/item/steam_crusher.json deleted file mode 100644 index 008a065..0000000 --- a/src/main/resources/assets/steamadvantage/models/item/steam_crusher.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "parent": "steamadvantage:block/steam_crusher" -} diff --git a/src/main/resources/assets/steamadvantage/models/item/steam_drill.json b/src/main/resources/assets/steamadvantage/models/item/steam_drill.json deleted file mode 100644 index 51b4440..0000000 --- a/src/main/resources/assets/steamadvantage/models/item/steam_drill.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "parent": "steamadvantage:block/steam_drill" -} diff --git a/src/main/resources/assets/steamadvantage/models/item/steam_elevator.json b/src/main/resources/assets/steamadvantage/models/item/steam_elevator.json deleted file mode 100644 index a43dbaa..0000000 --- a/src/main/resources/assets/steamadvantage/models/item/steam_elevator.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "parent": "steamadvantage:block/steam_elevator" -} diff --git a/src/main/resources/assets/steamadvantage/models/item/steam_furnace.json b/src/main/resources/assets/steamadvantage/models/item/steam_furnace.json deleted file mode 100644 index 424dd6f..0000000 --- a/src/main/resources/assets/steamadvantage/models/item/steam_furnace.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "parent": "steamadvantage:block/steam_furnace" -} diff --git a/src/main/resources/assets/steamadvantage/models/item/steam_pump.json b/src/main/resources/assets/steamadvantage/models/item/steam_pump.json deleted file mode 100644 index d562095..0000000 --- a/src/main/resources/assets/steamadvantage/models/item/steam_pump.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "parent": "steamadvantage:block/steam_pump" -} diff --git a/src/main/resources/assets/steamadvantage/models/item/steam_still.json b/src/main/resources/assets/steamadvantage/models/item/steam_still.json deleted file mode 100644 index 922076a..0000000 --- a/src/main/resources/assets/steamadvantage/models/item/steam_still.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "parent": "steamadvantage:block/steam_still" -} diff --git a/src/main/resources/assets/steamadvantage/models/item/steam_switch.json b/src/main/resources/assets/steamadvantage/models/item/steam_switch.json deleted file mode 100644 index cd82d28..0000000 --- a/src/main/resources/assets/steamadvantage/models/item/steam_switch.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "parent": "steamadvantage:block/steam_switch_off" -} diff --git a/src/main/resources/assets/steamadvantage/models/item/steam_tank.json b/src/main/resources/assets/steamadvantage/models/item/steam_tank.json deleted file mode 100644 index ce433e7..0000000 --- a/src/main/resources/assets/steamadvantage/models/item/steam_tank.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "parent": "steamadvantage:block/steam_tank" -} diff --git a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_boiler_coal.json b/src/main/resources/data/steamadvantage/loot_table/blocks/steam_boiler_coal.json deleted file mode 100644 index 0801b32..0000000 --- a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_boiler_coal.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "type": "minecraft:block", - "pools": [ - { - "rolls": 1, - "entries": [ - { - "type": "minecraft:item", - "name": "steamadvantage:steam_boiler_coal" - } - ], - "conditions": [ - { - "condition": "minecraft:survives_explosion" - } - ] - } - ] -} diff --git a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_boiler_electric.json b/src/main/resources/data/steamadvantage/loot_table/blocks/steam_boiler_electric.json deleted file mode 100644 index 1f82a7d..0000000 --- a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_boiler_electric.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "type": "minecraft:block", - "pools": [ - { - "rolls": 1, - "entries": [ - { - "type": "minecraft:item", - "name": "steamadvantage:steam_boiler_electric" - } - ], - "conditions": [ - { - "condition": "minecraft:survives_explosion" - } - ] - } - ] -} diff --git a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_boiler_geothermal.json b/src/main/resources/data/steamadvantage/loot_table/blocks/steam_boiler_geothermal.json deleted file mode 100644 index 410debc..0000000 --- a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_boiler_geothermal.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "type": "minecraft:block", - "pools": [ - { - "rolls": 1, - "entries": [ - { - "type": "minecraft:item", - "name": "steamadvantage:steam_boiler_geothermal" - } - ], - "conditions": [ - { - "condition": "minecraft:survives_explosion" - } - ] - } - ] -} diff --git a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_boiler_oil.json b/src/main/resources/data/steamadvantage/loot_table/blocks/steam_boiler_oil.json deleted file mode 100644 index 95dc00b..0000000 --- a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_boiler_oil.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "type": "minecraft:block", - "pools": [ - { - "rolls": 1, - "entries": [ - { - "type": "minecraft:item", - "name": "steamadvantage:steam_boiler_oil" - } - ], - "conditions": [ - { - "condition": "minecraft:survives_explosion" - } - ] - } - ] -} diff --git a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_crusher.json b/src/main/resources/data/steamadvantage/loot_table/blocks/steam_crusher.json deleted file mode 100644 index 73ebe89..0000000 --- a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_crusher.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "type": "minecraft:block", - "pools": [ - { - "rolls": 1, - "entries": [ - { - "type": "minecraft:item", - "name": "steamadvantage:steam_crusher" - } - ], - "conditions": [ - { - "condition": "minecraft:survives_explosion" - } - ] - } - ] -} diff --git a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_drill.json b/src/main/resources/data/steamadvantage/loot_table/blocks/steam_drill.json deleted file mode 100644 index 706dc6d..0000000 --- a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_drill.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "type": "minecraft:block", - "pools": [ - { - "rolls": 1, - "entries": [ - { - "type": "minecraft:item", - "name": "steamadvantage:steam_drill" - } - ], - "conditions": [ - { - "condition": "minecraft:survives_explosion" - } - ] - } - ] -} diff --git a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_elevator.json b/src/main/resources/data/steamadvantage/loot_table/blocks/steam_elevator.json deleted file mode 100644 index 09589d2..0000000 --- a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_elevator.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "type": "minecraft:block", - "pools": [ - { - "rolls": 1, - "entries": [ - { - "type": "minecraft:item", - "name": "steamadvantage:steam_elevator" - } - ], - "conditions": [ - { - "condition": "minecraft:survives_explosion" - } - ] - } - ] -} diff --git a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_furnace.json b/src/main/resources/data/steamadvantage/loot_table/blocks/steam_furnace.json deleted file mode 100644 index 782aef5..0000000 --- a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_furnace.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "type": "minecraft:block", - "pools": [ - { - "rolls": 1, - "entries": [ - { - "type": "minecraft:item", - "name": "steamadvantage:steam_furnace" - } - ], - "conditions": [ - { - "condition": "minecraft:survives_explosion" - } - ] - } - ] -} diff --git a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_pump.json b/src/main/resources/data/steamadvantage/loot_table/blocks/steam_pump.json deleted file mode 100644 index 2466029..0000000 --- a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_pump.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "type": "minecraft:block", - "pools": [ - { - "rolls": 1, - "entries": [ - { - "type": "minecraft:item", - "name": "steamadvantage:steam_pump" - } - ], - "conditions": [ - { - "condition": "minecraft:survives_explosion" - } - ] - } - ] -} diff --git a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_still.json b/src/main/resources/data/steamadvantage/loot_table/blocks/steam_still.json deleted file mode 100644 index 423f51e..0000000 --- a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_still.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "type": "minecraft:block", - "pools": [ - { - "rolls": 1, - "entries": [ - { - "type": "minecraft:item", - "name": "steamadvantage:steam_still" - } - ], - "conditions": [ - { - "condition": "minecraft:survives_explosion" - } - ] - } - ] -} diff --git a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_switch.json b/src/main/resources/data/steamadvantage/loot_table/blocks/steam_switch.json deleted file mode 100644 index 6c43980..0000000 --- a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_switch.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "type": "minecraft:block", - "pools": [ - { - "rolls": 1, - "entries": [ - { - "type": "minecraft:item", - "name": "steamadvantage:steam_switch" - } - ], - "conditions": [ - { - "condition": "minecraft:survives_explosion" - } - ] - } - ] -} diff --git a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_tank.json b/src/main/resources/data/steamadvantage/loot_table/blocks/steam_tank.json deleted file mode 100644 index d66e74e..0000000 --- a/src/main/resources/data/steamadvantage/loot_table/blocks/steam_tank.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "type": "minecraft:block", - "pools": [ - { - "rolls": 1, - "entries": [ - { - "type": "minecraft:item", - "name": "steamadvantage:steam_tank" - } - ], - "conditions": [ - { - "condition": "minecraft:survives_explosion" - } - ] - } - ] -} diff --git a/src/main/resources/mmdlib/block/machine.json b/src/main/resources/mmdlib/block/machine.json deleted file mode 100644 index 4f666e6..0000000 --- a/src/main/resources/mmdlib/block/machine.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "factory": "steamadvantage:machine", - "template": { - "has_item": true, - "properties": { - "hardness": 3.5, - "blast_resistance": 6, - "requires_correct_tool": true - }, - "tags": [ - "minecraft:mineable/pickaxe", - "minecraft:needs_iron_tool" - ], - "events": { - "block-right-click": "steamadvantage:use_machine" - } - }, - "part": { - "block_entity": { - "factory": "steamadvantage:machine", - "factory_data": { - "kind": "steam_tank", - "steam_capacity": 1000000 - } - } - } -} diff --git a/src/main/resources/mmdlib/block/machine_open.json b/src/main/resources/mmdlib/block/machine_open.json deleted file mode 100644 index e00812d..0000000 --- a/src/main/resources/mmdlib/block/machine_open.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "factory": "steamadvantage:machine", - "template": { - "has_item": true, - "properties": { - "hardness": 3.5, - "blast_resistance": 6, - "requires_correct_tool": true, - "occlusion": false - }, - "tags": [ - "minecraft:mineable/pickaxe", - "minecraft:needs_iron_tool" - ], - "events": { - "block-right-click": "steamadvantage:use_machine" - } - }, - "part": { - "block_entity": { - "factory": "steamadvantage:machine", - "factory_data": { - "kind": "steam_tank", - "steam_capacity": 1000000 - } - } - } -} diff --git a/src/main/resources/mmdlib/extension/machines.json b/src/main/resources/mmdlib/extension/machines.json deleted file mode 100644 index 22f1857..0000000 --- a/src/main/resources/mmdlib/extension/machines.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "events": [ - { - "type": "block-right-click", - "id": "steamadvantage:use_machine", - "handler": "zone.moddev.mc.SteamAdvantage.machines.MachineInteractions#use", - "name": "Use steam machine" - } - ] -} diff --git a/src/main/resources/mmdlib/machine/steam_base.xml b/src/main/resources/mmdlib/machine/steam_base.xml new file mode 100644 index 0000000..0867458 --- /dev/null +++ b/src/main/resources/mmdlib/machine/steam_base.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/src/main/resources/mmdlib/machine/steam_boiler_coal.xml b/src/main/resources/mmdlib/machine/steam_boiler_coal.xml new file mode 100644 index 0000000..c26bd7c --- /dev/null +++ b/src/main/resources/mmdlib/machine/steam_boiler_coal.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/mmdlib/machine/steam_boiler_electric.xml b/src/main/resources/mmdlib/machine/steam_boiler_electric.xml new file mode 100644 index 0000000..e62e5af --- /dev/null +++ b/src/main/resources/mmdlib/machine/steam_boiler_electric.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + diff --git a/src/main/resources/mmdlib/machine/steam_boiler_geothermal.xml b/src/main/resources/mmdlib/machine/steam_boiler_geothermal.xml new file mode 100644 index 0000000..1fe4168 --- /dev/null +++ b/src/main/resources/mmdlib/machine/steam_boiler_geothermal.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/mmdlib/machine/steam_boiler_oil.xml b/src/main/resources/mmdlib/machine/steam_boiler_oil.xml new file mode 100644 index 0000000..8aaeda4 --- /dev/null +++ b/src/main/resources/mmdlib/machine/steam_boiler_oil.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/mmdlib/machine/steam_crusher.xml b/src/main/resources/mmdlib/machine/steam_crusher.xml new file mode 100644 index 0000000..9a9ffef --- /dev/null +++ b/src/main/resources/mmdlib/machine/steam_crusher.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/mmdlib/machine/steam_drill.xml b/src/main/resources/mmdlib/machine/steam_drill.xml new file mode 100644 index 0000000..793dcfe --- /dev/null +++ b/src/main/resources/mmdlib/machine/steam_drill.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/mmdlib/machine/steam_elevator.xml b/src/main/resources/mmdlib/machine/steam_elevator.xml new file mode 100644 index 0000000..4c1debd --- /dev/null +++ b/src/main/resources/mmdlib/machine/steam_elevator.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + diff --git a/src/main/resources/mmdlib/machine/steam_furnace.xml b/src/main/resources/mmdlib/machine/steam_furnace.xml new file mode 100644 index 0000000..37b2b57 --- /dev/null +++ b/src/main/resources/mmdlib/machine/steam_furnace.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/mmdlib/machine/steam_pump.xml b/src/main/resources/mmdlib/machine/steam_pump.xml new file mode 100644 index 0000000..61f0d4e --- /dev/null +++ b/src/main/resources/mmdlib/machine/steam_pump.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + diff --git a/src/main/resources/mmdlib/machine/steam_still.xml b/src/main/resources/mmdlib/machine/steam_still.xml new file mode 100644 index 0000000..68718bc --- /dev/null +++ b/src/main/resources/mmdlib/machine/steam_still.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/mmdlib/machine/steam_switch.xml b/src/main/resources/mmdlib/machine/steam_switch.xml new file mode 100644 index 0000000..030c28a --- /dev/null +++ b/src/main/resources/mmdlib/machine/steam_switch.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + diff --git a/src/main/resources/mmdlib/machine/steam_tank.xml b/src/main/resources/mmdlib/machine/steam_tank.xml new file mode 100644 index 0000000..11a85bf --- /dev/null +++ b/src/main/resources/mmdlib/machine/steam_tank.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + diff --git a/src/main/resources/mmdlib/screen/steam_boiler_coal.xml b/src/main/resources/mmdlib/screen/steam_boiler_coal.xml deleted file mode 100644 index 2f32a6b..0000000 --- a/src/main/resources/mmdlib/screen/steam_boiler_coal.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/src/main/resources/mmdlib/screen/steam_boiler_electric.xml b/src/main/resources/mmdlib/screen/steam_boiler_electric.xml deleted file mode 100644 index cb4627c..0000000 --- a/src/main/resources/mmdlib/screen/steam_boiler_electric.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/src/main/resources/mmdlib/screen/steam_boiler_geothermal.xml b/src/main/resources/mmdlib/screen/steam_boiler_geothermal.xml deleted file mode 100644 index f271048..0000000 --- a/src/main/resources/mmdlib/screen/steam_boiler_geothermal.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/src/main/resources/mmdlib/screen/steam_boiler_oil.xml b/src/main/resources/mmdlib/screen/steam_boiler_oil.xml deleted file mode 100644 index 7a94d9a..0000000 --- a/src/main/resources/mmdlib/screen/steam_boiler_oil.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/src/main/resources/mmdlib/screen/steam_crusher.xml b/src/main/resources/mmdlib/screen/steam_crusher.xml deleted file mode 100644 index 69c571c..0000000 --- a/src/main/resources/mmdlib/screen/steam_crusher.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/mmdlib/screen/steam_drill.xml b/src/main/resources/mmdlib/screen/steam_drill.xml deleted file mode 100644 index 823d573..0000000 --- a/src/main/resources/mmdlib/screen/steam_drill.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/resources/mmdlib/screen/steam_elevator.xml b/src/main/resources/mmdlib/screen/steam_elevator.xml deleted file mode 100644 index e3c5764..0000000 --- a/src/main/resources/mmdlib/screen/steam_elevator.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - diff --git a/src/main/resources/mmdlib/screen/steam_furnace.xml b/src/main/resources/mmdlib/screen/steam_furnace.xml deleted file mode 100644 index e6ce54f..0000000 --- a/src/main/resources/mmdlib/screen/steam_furnace.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/resources/mmdlib/screen/steam_pump.xml b/src/main/resources/mmdlib/screen/steam_pump.xml deleted file mode 100644 index 535d4eb..0000000 --- a/src/main/resources/mmdlib/screen/steam_pump.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/src/main/resources/mmdlib/screen/steam_still.xml b/src/main/resources/mmdlib/screen/steam_still.xml deleted file mode 100644 index 268448c..0000000 --- a/src/main/resources/mmdlib/screen/steam_still.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/src/main/resources/mmdlib/screen/steam_switch.xml b/src/main/resources/mmdlib/screen/steam_switch.xml deleted file mode 100644 index 72b377e..0000000 --- a/src/main/resources/mmdlib/screen/steam_switch.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - diff --git a/src/main/resources/mmdlib/screen/steam_tank.xml b/src/main/resources/mmdlib/screen/steam_tank.xml deleted file mode 100644 index 3c9d95e..0000000 --- a/src/main/resources/mmdlib/screen/steam_tank.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/src/main/resources/mmdlib/standalone/block/steam_boiler_coal.json b/src/main/resources/mmdlib/standalone/block/steam_boiler_coal.json deleted file mode 100644 index 381c020..0000000 --- a/src/main/resources/mmdlib/standalone/block/steam_boiler_coal.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "module": "steamadvantage:machine", - "block_entity_data": { - "kind": "steam_boiler_coal", - "steam_capacity": 100000, - "water_capacity": 4000, - "fuel_capacity": 0, - "product_capacity": 0, - "inventory_size": 9, - "energy_capacity": 0, - "energy_transfer": 0 - } -} diff --git a/src/main/resources/mmdlib/standalone/block/steam_boiler_electric.json b/src/main/resources/mmdlib/standalone/block/steam_boiler_electric.json deleted file mode 100644 index 36a9130..0000000 --- a/src/main/resources/mmdlib/standalone/block/steam_boiler_electric.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "module": "steamadvantage:machine", - "block_entity_data": { - "kind": "steam_boiler_electric", - "steam_capacity": 20000, - "water_capacity": 4000, - "fuel_capacity": 0, - "product_capacity": 0, - "inventory_size": 9, - "energy_capacity": 1600, - "energy_transfer": 160 - } -} diff --git a/src/main/resources/mmdlib/standalone/block/steam_boiler_geothermal.json b/src/main/resources/mmdlib/standalone/block/steam_boiler_geothermal.json deleted file mode 100644 index 2cb6755..0000000 --- a/src/main/resources/mmdlib/standalone/block/steam_boiler_geothermal.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "module": "steamadvantage:machine", - "block_entity_data": { - "kind": "steam_boiler_geothermal", - "steam_capacity": 10000, - "water_capacity": 4000, - "fuel_capacity": 0, - "product_capacity": 0, - "inventory_size": 9, - "energy_capacity": 0, - "energy_transfer": 0 - } -} diff --git a/src/main/resources/mmdlib/standalone/block/steam_boiler_oil.json b/src/main/resources/mmdlib/standalone/block/steam_boiler_oil.json deleted file mode 100644 index 2691e57..0000000 --- a/src/main/resources/mmdlib/standalone/block/steam_boiler_oil.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "module": "steamadvantage:machine_open", - "block_entity_data": { - "kind": "steam_boiler_oil", - "steam_capacity": 100000, - "water_capacity": 4000, - "fuel_capacity": 4000, - "product_capacity": 0, - "inventory_size": 9, - "energy_capacity": 0, - "energy_transfer": 0 - } -} diff --git a/src/main/resources/mmdlib/standalone/block/steam_crusher.json b/src/main/resources/mmdlib/standalone/block/steam_crusher.json deleted file mode 100644 index 737deb3..0000000 --- a/src/main/resources/mmdlib/standalone/block/steam_crusher.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "module": "steamadvantage:machine", - "block_entity_data": { - "kind": "steam_crusher", - "steam_capacity": 20000, - "water_capacity": 0, - "fuel_capacity": 0, - "product_capacity": 0, - "inventory_size": 9, - "energy_capacity": 0, - "energy_transfer": 0 - } -} diff --git a/src/main/resources/mmdlib/standalone/block/steam_drill.json b/src/main/resources/mmdlib/standalone/block/steam_drill.json deleted file mode 100644 index b703c63..0000000 --- a/src/main/resources/mmdlib/standalone/block/steam_drill.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "module": "steamadvantage:machine_open", - "block_entity_data": { - "kind": "steam_drill", - "steam_capacity": 5000, - "water_capacity": 0, - "fuel_capacity": 0, - "product_capacity": 0, - "inventory_size": 9, - "energy_capacity": 0, - "energy_transfer": 0 - } -} diff --git a/src/main/resources/mmdlib/standalone/block/steam_elevator.json b/src/main/resources/mmdlib/standalone/block/steam_elevator.json deleted file mode 100644 index 848d0f0..0000000 --- a/src/main/resources/mmdlib/standalone/block/steam_elevator.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "module": "steamadvantage:machine", - "block_entity_data": { - "kind": "steam_elevator", - "steam_capacity": 6400, - "water_capacity": 0, - "fuel_capacity": 0, - "product_capacity": 0, - "inventory_size": 9, - "energy_capacity": 0, - "energy_transfer": 0 - } -} diff --git a/src/main/resources/mmdlib/standalone/block/steam_furnace.json b/src/main/resources/mmdlib/standalone/block/steam_furnace.json deleted file mode 100644 index 9809732..0000000 --- a/src/main/resources/mmdlib/standalone/block/steam_furnace.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "module": "steamadvantage:machine", - "block_entity_data": { - "kind": "steam_furnace", - "steam_capacity": 20000, - "water_capacity": 0, - "fuel_capacity": 0, - "product_capacity": 0, - "inventory_size": 9, - "energy_capacity": 0, - "energy_transfer": 0 - } -} diff --git a/src/main/resources/mmdlib/standalone/block/steam_pump.json b/src/main/resources/mmdlib/standalone/block/steam_pump.json deleted file mode 100644 index d9874d6..0000000 --- a/src/main/resources/mmdlib/standalone/block/steam_pump.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "module": "steamadvantage:machine", - "block_entity_data": { - "kind": "steam_pump", - "steam_capacity": 20000, - "water_capacity": 0, - "fuel_capacity": 0, - "product_capacity": 4000, - "inventory_size": 9, - "energy_capacity": 0, - "energy_transfer": 0 - } -} diff --git a/src/main/resources/mmdlib/standalone/block/steam_still.json b/src/main/resources/mmdlib/standalone/block/steam_still.json deleted file mode 100644 index eaa97ae..0000000 --- a/src/main/resources/mmdlib/standalone/block/steam_still.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "module": "steamadvantage:machine_open", - "block_entity_data": { - "kind": "steam_still", - "steam_capacity": 10000, - "water_capacity": 4000, - "fuel_capacity": 0, - "product_capacity": 4000, - "inventory_size": 9, - "energy_capacity": 0, - "energy_transfer": 0 - } -} diff --git a/src/main/resources/mmdlib/standalone/block/steam_switch.json b/src/main/resources/mmdlib/standalone/block/steam_switch.json deleted file mode 100644 index 25fde92..0000000 --- a/src/main/resources/mmdlib/standalone/block/steam_switch.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "module": "steamadvantage:machine", - "block_entity_data": { - "kind": "steam_switch", - "steam_capacity": 20000, - "water_capacity": 0, - "fuel_capacity": 0, - "product_capacity": 0, - "inventory_size": 9, - "energy_capacity": 0, - "energy_transfer": 0 - } -} diff --git a/src/main/resources/mmdlib/standalone/block/steam_tank.json b/src/main/resources/mmdlib/standalone/block/steam_tank.json deleted file mode 100644 index f4fc818..0000000 --- a/src/main/resources/mmdlib/standalone/block/steam_tank.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "module": "steamadvantage:machine_open", - "block_entity_data": { - "kind": "steam_tank", - "steam_capacity": 1000000, - "water_capacity": 0, - "fuel_capacity": 0, - "product_capacity": 0, - "inventory_size": 9, - "energy_capacity": 0, - "energy_transfer": 0 - } -} diff --git a/update.json b/update.json index a542a97..02b8ddf 100644 --- a/update.json +++ b/update.json @@ -5,6 +5,7 @@ "1.21.1-recommended": "3.0.3.121012" }, "1.21.1": { + "3.2.0.121012": "Requires MMDLib 2.0.3. Every machine is now an MMDLib XML machine definition; existing worlds load unchanged. Machines use MMDLib's standard machine screen, with interactive tank gauges (pour or fill buckets on them), a pause button, and the side-configuration and redstone drawers. The steam crusher and steam furnace now run MMDLib machine recipes, which JEI shows: the crusher takes every crushing recipe as before (125 ticks, 18,750 mB of steam per item). The furnace runs on steam alone: no fuel slot or warm-up, three independent lanes that each smelt at the recipe's own cooking time, 2000 mB of steam per 200 ticks. Coal left in an old furnace's fuel slot is kept and comes out in the recovery capsule when the furnace is broken; work in progress in a crusher or furnace restarts after updating. Pack makers can override the generated recipes with recipe JSON. The steam drill mines at Steam Advantage 2's pace again (12 ticks per point of block hardness, adjustable with drillTicksPerHardness in the common config). It now returns blocks' normal drops instead of running them through crusher recipes, so stone types (including Mineralogy rocks) are no longer turned into gravel. Broken machines now keep their fluids in a recovery capsule instead of losing them. Machines' blast resistance matches their hardness (3.5, down from 6).", "3.1.0.121012": "Requires MMDLib 2.0.2 and Power Advantage 3.2. Machines now build on MMDLib's shared machine base for saving, syncing and dropping contents; existing worlds load unchanged. Every machine now has MMDLib's side-configuration drawer: choose per face which slots, tanks and energy pipes and hoppers may use, and install Power Advantage's fluid intake and output pumps. Defaults match the old behavior. Steam-Powered Still screen fits small windows again, and the update checker points at the correct repository.", "3.0.3.121012": "Restore villager offers, machine-specific comparator signals, drill crushing and rotating drill bits, connected drill-bit cleanup, gradual end-of-line retraction, and musket repair, tooltips, ammunition compatibility, block interactions, particles and camera kick.", "3.0.2.121012": "Steam drill: visible drill pipe, diamond-pickaxe mining speeds, 128-block range to reach modern bedrock, no longer retracts or flickers when short on steam, and no longer stalls with a full inventory.",