From 6d20ccebfbab3706ba76a3bab4c8d35e2dfeafe2 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Thu, 19 Nov 2026 08:52:09 -0500 Subject: [PATCH 1/7] Restore SA2's drill pace and stop crushing mined blocks The steam drill again mines at Steam Advantage 2's rate: a configurable number of ticks per point of block hardness (drillTicksPerHardness, 12 by default, minimum half that). It now returns blocks' normal drops instead of running them through crusher recipes, which turned every Mineralogy rock in c:cobblestones into gravel. Co-Authored-By: Claude Opus 5.5 --- TODO.md | 3 + .../machines/SteamGameTests.java | 67 ++++++++----------- .../mc/SteamAdvantage/config/SteamConfig.java | 6 +- .../machines/DrillOperation.java | 27 +++----- update.json | 2 +- 5 files changed, 45 insertions(+), 60 deletions(-) diff --git a/TODO.md b/TODO.md index 3a0a4f9..e9a4546 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.1.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/src/gameTest/java/zone/moddev/mc/SteamAdvantage/machines/SteamGameTests.java b/src/gameTest/java/zone/moddev/mc/SteamAdvantage/machines/SteamGameTests.java index e7742e9..6d0f08f 100644 --- a/src/gameTest/java/zone/moddev/mc/SteamAdvantage/machines/SteamGameTests.java +++ b/src/gameTest/java/zone/moddev/mc/SteamAdvantage/machines/SteamGameTests.java @@ -187,67 +187,52 @@ 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 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; + drill.fluids.fill(steam(5000), FluidAction.EXECUTE); 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; + var expected = block == Blocks.STONE ? Items.COBBLESTONE : block.asItem(); h.assertTrue(drill.items.getStackInSlot(4).is(expected) - && drill.items.getStackInSlot(4).getCount() == count, - "Correct crushing/fallback output for " + block); + && drill.items.getStackInSlot(4).getCount() == 1, + "Normal block drop for " + block); h.assertTrue(drill.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"); + 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 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++) 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 + for (int tick = 0; tick < 30; tick++) DrillOperation.drill(drill); + h.assertTrue(h.getBlockState(target).is(Blocks.COBBLESTONE) && drill.depth == 0 && drill.progress[0] == 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)); + drill.items.setStackInSlot(6, new ItemStack(Items.COBBLESTONE, 63)); + int ticks = DrillOperation.breakTicks(Blocks.COBBLESTONE.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"); + h.assertTrue(drill.items.getStackInSlot(6).getCount() == 64 && drill.depth == 1, + "Mining resumes once there is room"); 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"); + h.assertTrue(drill.items.getStackInSlot(6).getCount() == 64, + "Subsequent ticks do not duplicate output"); h.succeed(); } @@ -824,13 +809,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(DrillOperation.breakTicks(Blocks.STONE.defaultBlockState(), level, p) == 18, + "Stone breaks in 18 ticks"); + h.assertTrue(DrillOperation.breakTicks(Blocks.DIRT.defaultBlockState(), level, p) == 6, + "Dirt breaks in 6 ticks"); + h.assertTrue(DrillOperation.breakTicks(Blocks.IRON_ORE.defaultBlockState(), level, p) == 36, + "Iron ore breaks in 36 ticks"); + h.assertTrue(DrillOperation.breakTicks(Blocks.OBSIDIAN.defaultBlockState(), level, p) == 600, + "Obsidian breaks in 600 ticks"); h.succeed(); } @GameTest(template = "empty", timeoutTicks = 80) 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/machines/DrillOperation.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/DrillOperation.java index 34ff13a..6ddb012 100644 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/DrillOperation.java +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/DrillOperation.java @@ -5,8 +5,6 @@ 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; @@ -97,15 +95,13 @@ static void drill(SteamMachine machine) { machine.depth++; } + /** + * Normal block drops, as if mined with the drill's pickaxe. SA2 also ran the block through + * the crusher, but with tags such as Mineralogy's (every rock in c:cobblestones) that turned + * most of the stone it mined into gravel. + */ 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()); } @@ -153,18 +149,13 @@ private static ItemStack tool() { } /** - * 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. + * 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, net.minecraft.world.level.Level level, BlockPos pos) { + double factor = zone.moddev.mc.SteamAdvantage.config.SteamConfig.DRILL_TICKS_PER_HARDNESS.get(); 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)); + return Math.max(1, (int) Math.ceil(Math.max(factor * hardness, factor * .5))); } static void clearDrill(SteamMachine machine) { diff --git a/update.json b/update.json index a542a97..504911f 100644 --- a/update.json +++ b/update.json @@ -5,7 +5,7 @@ "1.21.1-recommended": "3.0.3.121012" }, "1.21.1": { - "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.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. 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. 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.", "3.0.0.121012": "Initial NeoForge 1.21.1 release." From 5a4cd63a6840547d63bbd6b4c065e7f4d4cf44bc Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Thu, 19 Nov 2026 08:52:13 -0500 Subject: [PATCH 2/7] Require MMDLib 2.0.3 2.0.3 adds what the XML machine port needs: six-way facing, tag and Java-rule storage admission, several processors per machine, comparator sources, and entity subclasses that can import legacy save data. The existing machines pass all GameTests on it unchanged. Co-Authored-By: Claude Opus 5.5 --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 8162505..e00e3d1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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) From e8fc742cffbd85b1cd738160d17c0e315d805fd3 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Thu, 19 Nov 2026 08:52:28 -0500 Subject: [PATCH 3/7] Port the steam tank and steam switch to MMDLib XML machines The first two machines move from the shared SteamMachine entity to MMDLib 2.0.3 XML definitions (mmdlib/machine/), on a new abstract steam_base with the shared block settings. - SteamProcessor: base for SteamAdvantage's custom processors, with the steam helpers, SA2's "stop while powered" rule and the comparator reading each machine XML selects as steamadvantage/comparator. - SteamTankProcessor and SteamValveProcessor keep the old push rates (100 mB per face; 1000 mB out of the front). - Storage keeps the "Fluids" key and steam as tank 0, so pre-XML saves load unchanged; a new GameTest imports saves written by the old entity. - The machines' old blockstates, item models, loot tables, standalone JSON and screens are removed: MMDLib generates them, and SA3's own copies would take priority. The tank model becomes block/steam_tank_model. - An XML machine's comparator is sampled once per tick, so its scaling test steps a tick apart. The GUI smoke test opens XML machines too and accepts MMDLib's generated tank gauges. Version 3.2.0, with a changelog entry for the port so far. Co-Authored-By: Claude Opus 5.5 --- gradle.properties | 2 +- .../machines/SteamGameTests.java | 125 ++++++++++++++++-- .../SteamAdvantage/smoke/GuiSmokeClient.java | 28 +++- .../SteamAdvantage/smoke/GuiSmokeServer.java | 25 +++- .../machines/SteamProcessor.java | 84 ++++++++++++ .../machines/SteamTankProcessor.java | 30 +++++ .../machines/SteamValveProcessor.java | 28 ++++ .../blockstates/steam_switch.json | 28 ---- .../blockstates/steam_tank.json | 28 ---- .../assets/steamadvantage/lang/en_us.json | 4 +- ...{steam_tank.json => steam_tank_model.json} | 0 .../models/item/steam_switch.json | 3 - .../models/item/steam_tank.json | 3 - .../loot_table/blocks/steam_switch.json | 19 --- .../loot_table/blocks/steam_tank.json | 19 --- .../resources/mmdlib/machine/steam_base.xml | 6 + .../resources/mmdlib/machine/steam_switch.xml | 13 ++ .../resources/mmdlib/machine/steam_tank.xml | 15 +++ .../resources/mmdlib/screen/steam_switch.xml | 11 -- .../resources/mmdlib/screen/steam_tank.xml | 10 -- .../mmdlib/standalone/block/steam_switch.json | 13 -- .../mmdlib/standalone/block/steam_tank.json | 13 -- update.json | 1 + 23 files changed, 335 insertions(+), 173 deletions(-) create mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamProcessor.java create mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamTankProcessor.java create mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamValveProcessor.java delete mode 100644 src/main/resources/assets/steamadvantage/blockstates/steam_switch.json delete mode 100644 src/main/resources/assets/steamadvantage/blockstates/steam_tank.json rename src/main/resources/assets/steamadvantage/models/block/{steam_tank.json => steam_tank_model.json} (100%) delete mode 100644 src/main/resources/assets/steamadvantage/models/item/steam_switch.json delete mode 100644 src/main/resources/assets/steamadvantage/models/item/steam_tank.json delete mode 100644 src/main/resources/data/steamadvantage/loot_table/blocks/steam_switch.json delete mode 100644 src/main/resources/data/steamadvantage/loot_table/blocks/steam_tank.json create mode 100644 src/main/resources/mmdlib/machine/steam_base.xml create mode 100644 src/main/resources/mmdlib/machine/steam_switch.xml create mode 100644 src/main/resources/mmdlib/machine/steam_tank.xml delete mode 100644 src/main/resources/mmdlib/screen/steam_switch.xml delete mode 100644 src/main/resources/mmdlib/screen/steam_tank.xml delete mode 100644 src/main/resources/mmdlib/standalone/block/steam_switch.json delete mode 100644 src/main/resources/mmdlib/standalone/block/steam_tank.json diff --git a/gradle.properties b/gradle.properties index e00e3d1..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 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 6d0f08f..701c68b 100644 --- a/src/gameTest/java/zone/moddev/mc/SteamAdvantage/machines/SteamGameTests.java +++ b/src/gameTest/java/zone/moddev/mc/SteamAdvantage/machines/SteamGameTests.java @@ -23,6 +23,26 @@ private static SteamMachine place(GameTestHelper h, String name, int x, int y, i h.assertTrue(be instanceof SteamMachine, "Machine entity: " + name); return (SteamMachine) be; } + /** Machines already ported to MMDLib XML definitions. */ + private static final java.util.Set XML_MACHINES = + java.util.Set.of("steam_tank", "steam_switch"); + private static zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity placeXml( + 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 zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity, + "XML machine entity: " + name); + return (zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity) be; + } + /** Comparator source for XML machines: tank 0 (steam) at 0, half or full. */ + private static void setXmlComparatorSource( + zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity m, int fraction) { + var tank = m.fluids.tank(0); + tank.drain(Integer.MAX_VALUE, FluidAction.EXECUTE); + if (fraction > 0) + tank.fill(steam(tank.getCapacity() * fraction / 2), FluidAction.EXECUTE); + } @GameTest(template = "empty") public static void drillBitLineCleanup(GameTestHelper h) { var facing = net.minecraft.world.level.block.state.properties.BlockStateProperties.FACING; @@ -268,6 +288,8 @@ public static void machineComparatorSourcesAndScaling(GameTestHelper h) { var pos = new BlockPos(2, 2, 2); for (String kind : ModContent.MACHINES) { h.setBlock(pos, Blocks.AIR); + if (XML_MACHINES.contains(kind)) + continue; // Sampled once per tick; see xmlComparatorScaling. var m = place(h, kind, 2, 2, 2); for (int fraction = 0; fraction <= 2; fraction++) { setComparatorSource(m, fraction); @@ -292,6 +314,32 @@ public static void machineComparatorSourcesAndScaling(GameTestHelper h) { 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, XML_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 ? placeXml(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 = 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); @@ -303,7 +351,28 @@ 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); + String kind = ModContent.MACHINES.get(index); + if (XML_MACHINES.contains(kind)) { + var x = placeXml(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, () -> { + 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); + }); + }); + return; + } + var m = place(h, kind, 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( @@ -569,36 +638,39 @@ private static FluidStack steam(int amount) { @GameTest(template = "empty") public static void registrationCapabilitiesPersistence(GameTestHelper h) { for (String name : ModContent.MACHINES) { - var m = place(h, name, 2, 2, 2); + var m = XML_MACHINES.contains(name) ? placeXml(h, name, 2, 2, 2) + : place(h, name, 2, 2, 2); for (var side : Direction.values()) h.assertTrue(h.getLevel().getCapability( Capabilities.FluidHandler.BLOCK, m.getBlockPos(), side) != null, "Missing fluid capability " + name); } - var tank = place(h, "steam_tank", 2, 2, 2); + var tank = placeXml(h, "steam_tank", 2, 2, 2); 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") 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); + var tank = placeXml(h, "steam_tank", 1, 2, 4); furnace.items.setStackInSlot(4, new ItemStack(Items.IRON_INGOT, 6)); for (var side : Direction.values()) { var items = itemsAt(h, furnace, side); @@ -848,10 +920,39 @@ public static void elevatorExtendsAndRetracts(GameTestHelper h) { }); }); } + /** + * A tank or switch saved by SA3 before the XML port (the shared SteamMachine entity, with a + * nine-slot "Items" inventory and an unnamed steam tank under "Fluids") loads into the XML + * machine with its steam intact. + */ + @GameTest(template = "empty") + public static void preXmlTankAndSwitchSavesLoad(GameTestHelper h) { + var registries = h.getLevel().registryAccess(); + var crusher = ModContent.block("steam_crusher").defaultBlockState(); + for (String kind : java.util.List.of("steam_tank", "steam_switch")) { + var placed = placeXml(h, kind, 2, 2, 2); + var legacy = new SteamMachine(ModContent.machineType(crusher), placed.getBlockPos(), + crusher, new MachineSettings(kind, kind.equals("steam_tank") ? 1000000 : 20000, + 0, 0, 0, 9, 0, 0)); + legacy.fluids().tank(0).fill(steam(4321), FluidAction.EXECUTE); + var saved = legacy.saveWithFullMetadata(registries); + saved.putString("id", ModContent.id(kind).toString()); + 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 && 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.setBlock(new BlockPos(2, 2, 2), Blocks.AIR); + } + h.succeed(); + } + @GameTest(template = "empty", timeoutTicks = 80) public static void valveStopsOutputWhenPowered(GameTestHelper h) { - var valve = place(h, "steam_switch", 3, 2, 3); - var tank = place(h, "steam_tank", 3, 2, 2); + var valve = placeXml(h, "steam_switch", 3, 2, 3); + var tank = placeXml(h, "steam_tank", 3, 2, 2); valve.fluids.fill(steam(10000), FluidAction.EXECUTE); h.setBlock(new BlockPos(4, 2, 3), Blocks.REDSTONE_BLOCK); h.runAfterDelay(5, () -> { @@ -1150,7 +1251,7 @@ public static void screenSnapshotsPreserveLargeAndFluidValues(GameTestHelper h) } @GameTest(template = "empty") public static void mismatchedScreenAndInvalidSettingsAreRejected(GameTestHelper h) { - var tank = place(h, "steam_tank", 2, 2, 2); + var tank = placeXml(h, "steam_tank", 2, 2, 2); var player = h.makeMockPlayer(net.minecraft.world.level.GameType.SURVIVAL); var buffer = new net.minecraft.network.RegistryFriendlyByteBuf( io.netty.buffer.Unpooled.buffer(), h.getLevel().registryAccess()); 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..1aabcc7 100644 --- a/src/guiSmoke/java/zone/moddev/mc/SteamAdvantage/smoke/GuiSmokeServer.java +++ b/src/guiSmoke/java/zone/moddev/mc/SteamAdvantage/smoke/GuiSmokeServer.java @@ -33,6 +33,17 @@ static void tick(ServerTickEvent.Post event) { var pos = pending; pending = null; var name = ModContent.MACHINES.get(index - 1); + if (level.getBlockEntity(pos) + instanceof zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity xml) { + xml.fluids.tank(0).fill( + new FluidStack(zone.moddev.mc.poweradvantage.init.Fluids.STEAM.get(), + xml.fluids.tank(0).getCapacity() * 3 / 4), + FluidAction.EXECUTE); + // 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; + } var machine = (SteamMachine) level.getBlockEntity(pos); machine.fluids().tank(0).fill( new FluidStack(zone.moddev.mc.poweradvantage.init.Fluids.STEAM.get(), @@ -50,11 +61,7 @@ static void tick(ServerTickEvent.Post event) { 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)); + openMenu(player, level, pos); return; } if (++ticks % 60 != 0) @@ -66,4 +73,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/machines/SteamProcessor.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamProcessor.java new file mode 100644 index 0000000..e18ede0 --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamProcessor.java @@ -0,0 +1,84 @@ +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; + } + + /** 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()); + } +} 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/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_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_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_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/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_switch.xml b/src/main/resources/mmdlib/machine/steam_switch.xml new file mode 100644 index 0000000..1615de4 --- /dev/null +++ b/src/main/resources/mmdlib/machine/steam_switch.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + 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_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_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 504911f..6e6663a 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. Machines are moving to MMDLib's XML machine definitions; existing worlds load unchanged. Ported so far: the steam tank and steam switch, which now use MMDLib's standard machine screen with a pause button and the side-configuration and redstone drawers. Broken machines now keep their fluids in a recovery capsule instead of losing them. Ported 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. 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. 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.", From c2ab71e94ba985cdce03c1db37362ff1a9c6d5c8 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Thu, 19 Nov 2026 09:01:32 -0500 Subject: [PATCH 4/7] Port the boilers, pump, still and elevator to XML machines Seven more machines move to MMDLib XML definitions, each with a custom processor that keeps its SA3 behavior: - BoilerProcessor, with coal, oil, electric and geothermal variants (fuel slot and oil tank admission rules, burn timers, temperature). - PumpProcessor, StillProcessor (Power Advantage distilling recipes, with a recipe-based input filter) and ElevatorProcessor, which redstone drives rather than pauses. SteamMachineEntity imports saves from before the XML port: each processor copies the top-level keys it used (Burn, TotalBurn, Temperature, Raised, ElevatorHeight, PendingDistillation...) into its own state, the electric boiler's pre-2.0.2 "Energy" becomes "energy", and old nine-slot item positions map onto each machine's declared slots. It is registered as the entity for every XML machine. Screens use MMDLib's generated tank gauges, with SA3's burn meter, heat gauge, distillation progress and help text placed in the machine region through SteamScreens' static value helpers (XML machine screens bind to DefinedMachineEntity). The switch gets its help text back. Tests: the ported machines' tests use the XML entity and processors, and preXmlMachineSavesLoad imports saves written by the old entity for all seven machines. Co-Authored-By: Claude Opus 5.5 --- .../machines/SteamGameTests.java | 216 +++++++++++++----- .../mc/SteamAdvantage/SteamAdvantage.java | 5 + .../mc/SteamAdvantage/init/ModContent.java | 5 + .../machines/BoilerProcessor.java | 60 +++++ .../mc/SteamAdvantage/machines/Burner.java | 8 + .../machines/CoalBoilerProcessor.java | 64 ++++++ .../machines/ElectricBoilerProcessor.java | 20 ++ .../machines/ElevatorProcessor.java | 98 ++++++++ .../machines/GeothermalBoilerProcessor.java | 57 +++++ .../machines/OilBoilerProcessor.java | 55 +++++ .../machines/PumpProcessor.java | 100 ++++++++ .../machines/SteamMachineEntity.java | 78 +++++++ .../machines/SteamProcessor.java | 43 ++++ .../SteamAdvantage/machines/SteamScreens.java | 43 ++++ .../machines/StillProcessor.java | 113 +++++++++ .../blockstates/steam_boiler_coal.json | 28 --- .../blockstates/steam_boiler_electric.json | 28 --- .../blockstates/steam_boiler_geothermal.json | 28 --- .../blockstates/steam_boiler_oil.json | 28 --- .../blockstates/steam_elevator.json | 28 --- .../blockstates/steam_pump.json | 28 --- .../blockstates/steam_still.json | 28 --- ...coal.json => steam_boiler_coal_model.json} | 0 ....json => steam_boiler_electric_model.json} | 0 ...son => steam_boiler_geothermal_model.json} | 0 ...r_oil.json => steam_boiler_oil_model.json} | 0 ...levator.json => steam_elevator_model.json} | 0 ...{steam_pump.json => steam_pump_model.json} | 0 ...team_still.json => steam_still_model.json} | 0 .../models/item/steam_boiler_coal.json | 3 - .../models/item/steam_boiler_electric.json | 3 - .../models/item/steam_boiler_geothermal.json | 3 - .../models/item/steam_boiler_oil.json | 3 - .../models/item/steam_elevator.json | 3 - .../models/item/steam_pump.json | 3 - .../models/item/steam_still.json | 3 - .../loot_table/blocks/steam_boiler_coal.json | 19 -- .../blocks/steam_boiler_electric.json | 19 -- .../blocks/steam_boiler_geothermal.json | 19 -- .../loot_table/blocks/steam_boiler_oil.json | 19 -- .../loot_table/blocks/steam_elevator.json | 19 -- .../loot_table/blocks/steam_pump.json | 19 -- .../loot_table/blocks/steam_still.json | 19 -- .../mmdlib/machine/steam_boiler_coal.xml | 27 +++ .../mmdlib/machine/steam_boiler_electric.xml | 15 ++ .../machine/steam_boiler_geothermal.xml | 22 ++ .../mmdlib/machine/steam_boiler_oil.xml | 23 ++ .../mmdlib/machine/steam_elevator.xml | 17 ++ .../resources/mmdlib/machine/steam_pump.xml | 13 ++ .../resources/mmdlib/machine/steam_still.xml | 22 ++ .../resources/mmdlib/machine/steam_switch.xml | 5 + .../mmdlib/screen/steam_boiler_coal.xml | 19 -- .../mmdlib/screen/steam_boiler_electric.xml | 16 -- .../mmdlib/screen/steam_boiler_geothermal.xml | 16 -- .../mmdlib/screen/steam_boiler_oil.xml | 16 -- .../mmdlib/screen/steam_elevator.xml | 11 - .../resources/mmdlib/screen/steam_pump.xml | 13 -- .../resources/mmdlib/screen/steam_still.xml | 17 -- .../standalone/block/steam_boiler_coal.json | 13 -- .../block/steam_boiler_electric.json | 13 -- .../block/steam_boiler_geothermal.json | 13 -- .../standalone/block/steam_boiler_oil.json | 13 -- .../standalone/block/steam_elevator.json | 13 -- .../mmdlib/standalone/block/steam_pump.json | 13 -- .../mmdlib/standalone/block/steam_still.json | 13 -- update.json | 2 +- 66 files changed, 1052 insertions(+), 608 deletions(-) create mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/BoilerProcessor.java create mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/Burner.java create mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/CoalBoilerProcessor.java create mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/ElectricBoilerProcessor.java create mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/ElevatorProcessor.java create mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/GeothermalBoilerProcessor.java create mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/OilBoilerProcessor.java create mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/PumpProcessor.java create mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamMachineEntity.java create mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamScreens.java create mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/StillProcessor.java delete mode 100644 src/main/resources/assets/steamadvantage/blockstates/steam_boiler_coal.json delete mode 100644 src/main/resources/assets/steamadvantage/blockstates/steam_boiler_electric.json delete mode 100644 src/main/resources/assets/steamadvantage/blockstates/steam_boiler_geothermal.json delete mode 100644 src/main/resources/assets/steamadvantage/blockstates/steam_boiler_oil.json delete mode 100644 src/main/resources/assets/steamadvantage/blockstates/steam_elevator.json delete mode 100644 src/main/resources/assets/steamadvantage/blockstates/steam_pump.json delete mode 100644 src/main/resources/assets/steamadvantage/blockstates/steam_still.json rename src/main/resources/assets/steamadvantage/models/block/{steam_boiler_coal.json => steam_boiler_coal_model.json} (100%) rename src/main/resources/assets/steamadvantage/models/block/{steam_boiler_electric.json => steam_boiler_electric_model.json} (100%) rename src/main/resources/assets/steamadvantage/models/block/{steam_boiler_geothermal.json => steam_boiler_geothermal_model.json} (100%) rename src/main/resources/assets/steamadvantage/models/block/{steam_boiler_oil.json => steam_boiler_oil_model.json} (100%) rename src/main/resources/assets/steamadvantage/models/block/{steam_elevator.json => steam_elevator_model.json} (100%) rename src/main/resources/assets/steamadvantage/models/block/{steam_pump.json => steam_pump_model.json} (100%) rename src/main/resources/assets/steamadvantage/models/block/{steam_still.json => steam_still_model.json} (100%) delete mode 100644 src/main/resources/assets/steamadvantage/models/item/steam_boiler_coal.json delete mode 100644 src/main/resources/assets/steamadvantage/models/item/steam_boiler_electric.json delete mode 100644 src/main/resources/assets/steamadvantage/models/item/steam_boiler_geothermal.json delete mode 100644 src/main/resources/assets/steamadvantage/models/item/steam_boiler_oil.json delete mode 100644 src/main/resources/assets/steamadvantage/models/item/steam_elevator.json delete mode 100644 src/main/resources/assets/steamadvantage/models/item/steam_pump.json delete mode 100644 src/main/resources/assets/steamadvantage/models/item/steam_still.json delete mode 100644 src/main/resources/data/steamadvantage/loot_table/blocks/steam_boiler_coal.json delete mode 100644 src/main/resources/data/steamadvantage/loot_table/blocks/steam_boiler_electric.json delete mode 100644 src/main/resources/data/steamadvantage/loot_table/blocks/steam_boiler_geothermal.json delete mode 100644 src/main/resources/data/steamadvantage/loot_table/blocks/steam_boiler_oil.json delete mode 100644 src/main/resources/data/steamadvantage/loot_table/blocks/steam_elevator.json delete mode 100644 src/main/resources/data/steamadvantage/loot_table/blocks/steam_pump.json delete mode 100644 src/main/resources/data/steamadvantage/loot_table/blocks/steam_still.json create mode 100644 src/main/resources/mmdlib/machine/steam_boiler_coal.xml create mode 100644 src/main/resources/mmdlib/machine/steam_boiler_electric.xml create mode 100644 src/main/resources/mmdlib/machine/steam_boiler_geothermal.xml create mode 100644 src/main/resources/mmdlib/machine/steam_boiler_oil.xml create mode 100644 src/main/resources/mmdlib/machine/steam_elevator.xml create mode 100644 src/main/resources/mmdlib/machine/steam_pump.xml create mode 100644 src/main/resources/mmdlib/machine/steam_still.xml delete mode 100644 src/main/resources/mmdlib/screen/steam_boiler_coal.xml delete mode 100644 src/main/resources/mmdlib/screen/steam_boiler_electric.xml delete mode 100644 src/main/resources/mmdlib/screen/steam_boiler_geothermal.xml delete mode 100644 src/main/resources/mmdlib/screen/steam_boiler_oil.xml delete mode 100644 src/main/resources/mmdlib/screen/steam_elevator.xml delete mode 100644 src/main/resources/mmdlib/screen/steam_pump.xml delete mode 100644 src/main/resources/mmdlib/screen/steam_still.xml delete mode 100644 src/main/resources/mmdlib/standalone/block/steam_boiler_coal.json delete mode 100644 src/main/resources/mmdlib/standalone/block/steam_boiler_electric.json delete mode 100644 src/main/resources/mmdlib/standalone/block/steam_boiler_geothermal.json delete mode 100644 src/main/resources/mmdlib/standalone/block/steam_boiler_oil.json delete mode 100644 src/main/resources/mmdlib/standalone/block/steam_elevator.json delete mode 100644 src/main/resources/mmdlib/standalone/block/steam_pump.json delete mode 100644 src/main/resources/mmdlib/standalone/block/steam_still.json 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 701c68b..da03df6 100644 --- a/src/gameTest/java/zone/moddev/mc/SteamAdvantage/machines/SteamGameTests.java +++ b/src/gameTest/java/zone/moddev/mc/SteamAdvantage/machines/SteamGameTests.java @@ -25,7 +25,12 @@ private static SteamMachine place(GameTestHelper h, String name, int x, int y, i } /** Machines already ported to MMDLib XML definitions. */ private static final java.util.Set XML_MACHINES = - java.util.Set.of("steam_tank", "steam_switch"); + java.util.Set.copyOf(ModContent.XML_MACHINES); + /** 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 placeXml( GameTestHelper h, String name, int x, int y, int z) { var p = new BlockPos(x, y, z); @@ -35,13 +40,29 @@ private static zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity placeXml "XML machine entity: " + name); return (zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity) be; } - /** Comparator source for XML machines: tank 0 (steam) at 0, half or full. */ - private static void setXmlComparatorSource( - zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity m, int fraction) { - var tank = m.fluids.tank(0); - tank.drain(Integer.MAX_VALUE, FluidAction.EXECUTE); - if (fraction > 0) - tank.fill(steam(tank.getCapacity() * fraction / 2), FluidAction.EXECUTE); + /** 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)); + 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) { @@ -331,7 +352,8 @@ private static void verifyXmlScaling( h.setBlock(new BlockPos(2, 3, 2), Blocks.REDSTONE_BLOCK); setXmlComparatorSource(x, fraction); h.runAfterDelay(2, () -> { - int expected = fraction == 0 ? 0 : fraction == 1 ? 7 : 15; + 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); @@ -669,7 +691,7 @@ private static net.neoforged.neoforge.fluids.capability.IFluidHandler fluidsAt( @GameTest(template = "empty") 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 boiler = placeXml(h, "steam_boiler_electric", 4, 2, 1); var tank = placeXml(h, "steam_tank", 1, 2, 4); furnace.items.setStackInSlot(4, new ItemStack(Items.IRON_INGOT, 6)); for (var side : Direction.values()) { @@ -701,10 +723,11 @@ 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 boiler = placeXml(h, "steam_boiler_coal", 2, 2, 2); + 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); @@ -714,10 +737,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) @@ -727,10 +752,10 @@ public static void automationSideConfigGatesAndPersists(GameTestHelper h) { } @GameTest(template = "empty", timeoutTicks = 60) 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); + var boiler = placeXml(h, "steam_boiler_coal", 2, 2, 2); + var still = placeXml(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()); @@ -750,25 +775,99 @@ public static void powerAdvantagePumpAddonWorksAndDrops(GameTestHelper h) { h.succeed(); }); } + /** + * A save written by the shared pre-XML SteamMachine entity, with its machine state in + * top-level keys and the electric boiler's pre-2.0.2 "Energy" key. + */ + private static zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity importLegacy( + GameTestHelper h, String kind, java.util.function.Consumer setup, + java.util.function.Consumer edit) { + var registries = h.getLevel().registryAccess(); + var placed = placeXml(h, kind, 2, 2, 2); + var crusher = ModContent.block("steam_crusher").defaultBlockState(); + var settings = switch (kind) { + case "steam_boiler_electric" -> new MachineSettings(kind, 20000, 4000, 0, 0, 9, 1600, 160); + case "steam_boiler_coal" -> new MachineSettings(kind, 100000, 4000, 0, 0, 9, 0, 0); + case "steam_boiler_oil" -> new MachineSettings(kind, 100000, 4000, 4000, 0, 9, 0, 0); + case "steam_boiler_geothermal" -> new MachineSettings(kind, 10000, 4000, 0, 0, 9, 0, 0); + case "steam_still" -> new MachineSettings(kind, 10000, 4000, 0, 4000, 9, 0, 0); + case "steam_pump" -> new MachineSettings(kind, 20000, 0, 0, 4000, 9, 0, 0); + default -> new MachineSettings(kind, 6400, 0, 0, 0, 9, 0, 0); + }; + var legacy = new SteamMachine(ModContent.machineType(crusher), placed.getBlockPos(), crusher, + settings); + legacy.setLevel(h.getLevel()); // The still's input filter consults the level's recipes. + setup.accept(legacy); + var saved = legacy.saveWithFullMetadata(registries); + saved.putString("id", ModContent.id(kind).toString()); + edit.accept(saved); + h.setBlock(new BlockPos(2, 2, 2), Blocks.AIR); + h.setBlock(new BlockPos(2, 2, 2), placed.getBlockState()); + var imported = (zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity) + net.minecraft.world.level.block.entity.BlockEntity.loadStatic( + h.absolutePos(new BlockPos(2, 2, 2)), 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"); + 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", m -> { + m.items().setStackInSlot(0, new ItemStack(Items.COAL, 5)); + m.fluids().tank(1).fill(new FluidStack(Fluids.WATER, 777), FluidAction.EXECUTE); + m.burn = 17; + m.totalBurn = 1600; + }, tag -> {}); + 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", m -> m.energy().setStored(1234), + tag -> { + // SA3 before MMDLib 2.0.2 saved the buffer as "Energy". + tag.put("Energy", tag.get("energy")); + tag.remove("energy"); + }); + h.assertTrue(electric.energy.stored() == 1234, "Legacy Energy key is imported"); + + var oil = importLegacy(h, "steam_boiler_oil", m -> { + m.fluids().tank(2).fill(new FluidStack(Fluids.LAVA, 900), FluidAction.EXECUTE); + m.burn = 40; + }, tag -> {}); + 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", m -> m.temperature = 640, tag -> {}); + h.assertTrue(processor(geo, GeothermalBoilerProcessor.class).temperature() == 640, + "Geothermal temperature imported"); + + var elevator = importLegacy(h, "steam_elevator", m -> { + m.raised = true; + m.elevatorHeight = 5; + }, tag -> {}); + h.assertTrue(processor(elevator, ElevatorProcessor.class).raised(), "Raised state imported"); + + var still = importLegacy(h, "steam_still", m -> { + m.fluids().tank(2).fill(new FluidStack(Fluids.WATER, 300), FluidAction.EXECUTE); + m.pendingDistillation = new FluidStack(Fluids.LAVA, 100); + m.distillationDuration = 20; + m.progress[0] = 7; + }, tag -> {}); + 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", m -> + m.fluids().tank(1).fill(new FluidStack(Fluids.WATER, 2000), FluidAction.EXECUTE), + tag -> {}); + h.assertTrue(pump.fluids.tank(1).getFluidAmount() == 2000, "Pumped fluid stays in tank 1"); h.succeed(); } @GameTest(template = "empty") @@ -788,7 +887,7 @@ public static void brokenMachineDropsItemsOnce(GameTestHelper h) { } @GameTest(template = "empty", timeoutTicks = 100) public static void coalBoilerAndRedstone(GameTestHelper h) { - var boiler = place(h, "steam_boiler_coal", 2, 2, 2); + var boiler = placeXml(h, "steam_boiler_coal", 2, 2, 2); boiler.fluids.fill(new FluidStack(Fluids.WATER, 1000), FluidAction.EXECUTE); boiler.items.setStackInSlot(0, new ItemStack(Items.COAL)); h.setBlock(new BlockPos(2, 3, 2), Blocks.SNOW); @@ -811,7 +910,7 @@ public static void coalBoilerAndRedstone(GameTestHelper h) { } @GameTest(template = "empty", timeoutTicks = 100) public static void electricBoilerSpendsEnergy(GameTestHelper h) { - var boiler = place(h, "steam_boiler_electric", 2, 2, 2); + var boiler = placeXml(h, "steam_boiler_electric", 2, 2, 2); boiler.fluids.fill(new FluidStack(Fluids.WATER, 1000), FluidAction.EXECUTE); boiler.energy.setStored(160); h.runAfterDelay(20, () -> { @@ -822,7 +921,7 @@ public static void electricBoilerSpendsEnergy(GameTestHelper h) { } @GameTest(template = "empty", timeoutTicks = 100) public static void pumpConservesWorldFluid(GameTestHelper h) { - var pump = place(h, "steam_pump", 2, 4, 2); + var pump = placeXml(h, "steam_pump", 2, 4, 2); pump.fluids.fill(steam(6400), FluidAction.EXECUTE); h.setBlock(new BlockPos(2, 3, 2), Blocks.WATER); h.runAfterDelay(40, () -> { @@ -834,7 +933,7 @@ public static void pumpConservesWorldFluid(GameTestHelper h) { } @GameTest(template = "empty", timeoutTicks = 120) public static void boilerPipeConsumer(GameTestHelper h) { - var boiler = place(h, "steam_boiler_coal", 2, 2, 2); + var boiler = placeXml(h, "steam_boiler_coal", 2, 2, 2); h.setBlock(new BlockPos(3, 2, 2), ModContent.block("steam_pipe")); var furnace = place(h, "steam_furnace", 4, 2, 2); boiler.fluids.fill(new FluidStack(Fluids.WATER, 1000), FluidAction.EXECUTE); @@ -906,7 +1005,7 @@ public static void starvedDrillPausesInsteadOfRetracting(GameTestHelper h) { } @GameTest(template = "empty", timeoutTicks = 80) public static void elevatorExtendsAndRetracts(GameTestHelper h) { - var elevator = place(h, "steam_elevator", 3, 2, 3); + var elevator = placeXml(h, "steam_elevator", 3, 2, 3); elevator.fluids.fill(steam(10000), FluidAction.EXECUTE); h.setBlock(new BlockPos(3, 8, 3), Blocks.STONE); h.setBlock(new BlockPos(4, 2, 3), Blocks.REDSTONE_BLOCK); @@ -967,10 +1066,10 @@ public static void valveStopsOutputWhenPowered(GameTestHelper h) { @GameTest(template = "empty", timeoutTicks = 100) public static void oilAndGeothermalBoilers(GameTestHelper h) { - var oil = place(h, "steam_boiler_oil", 2, 2, 2); + var oil = placeXml(h, "steam_boiler_oil", 2, 2, 2); oil.fluids.fill(new FluidStack(Fluids.WATER, 1000), FluidAction.EXECUTE); oil.fluids.fill(new FluidStack(Fluids.LAVA, 1000), FluidAction.EXECUTE); - var geo = place(h, "steam_boiler_geothermal", 6, 2, 2); + var geo = placeXml(h, "steam_boiler_geothermal", 6, 2, 2); geo.fluids.fill(new FluidStack(Fluids.WATER, 1000), FluidAction.EXECUTE); h.setBlock(new BlockPos(6, 1, 2), Blocks.MAGMA_BLOCK); h.runAfterDelay(60, () -> { @@ -984,7 +1083,7 @@ public static void oilAndGeothermalBoilers(GameTestHelper h) { @GameTest(template = "empty", timeoutTicks = 140) public static void distillationUsesPowerAdvantageDefaultRecipe(GameTestHelper h) { // PA 3.2's built-in poweradvantage:distilling_refined_oil: 100 mB crude -> 50 mB refined in 100 ticks. - var still = place(h, "steam_still", 2, 2, 2); + var still = placeXml(h, "steam_still", 2, 2, 2); var crudeOil = zone.moddev.mc.poweradvantage.init.Fluids.CRUDE_OIL.get(); var refinedOil = zone.moddev.mc.poweradvantage.init.Fluids.REFINED_OIL.get(); h.setBlock(new BlockPos(2, 3, 2), Blocks.SNOW); @@ -997,14 +1096,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(); }); }); @@ -1012,14 +1112,15 @@ public static void distillationUsesPowerAdvantageDefaultRecipe(GameTestHelper h) @GameTest(template = "empty", timeoutTicks = 60) public static void distillationProgressPersistsUntilOutput(GameTestHelper h) { - var still = place(h, "steam_still", 2, 2, 2); + var still = placeXml(h, "steam_still", 2, 2, 2); 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()); @@ -1027,7 +1128,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(); }); }); @@ -1035,7 +1136,7 @@ public static void distillationProgressPersistsUntilOutput(GameTestHelper h) { @GameTest(template = "empty", timeoutTicks = 40) public static void distillationBlockedOutputDoesNotConsumeResources(GameTestHelper h) { - var still = place(h, "steam_still", 2, 2, 2); + var still = placeXml(h, "steam_still", 2, 2, 2); still.fluids.tank(0).fill(steam(150), FluidAction.EXECUTE); still.fluids.tank(1).fill(new FluidStack(Fluids.LAVA, 4000), FluidAction.EXECUTE); still.fluids.tank(2).fill(new FluidStack(Fluids.WATER, 1000), FluidAction.EXECUTE); @@ -1044,7 +1145,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(); }); @@ -1103,10 +1204,9 @@ public static void hotIdleFurnaceStillMeltsSnow(GameTestHelper h) { } @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; + var geo = placeXml(h, "steam_boiler_geothermal", 2, 2, 2); + 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(), diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/SteamAdvantage.java b/src/main/java/zone/moddev/mc/SteamAdvantage/SteamAdvantage.java index 1ded233..1e3e4a8 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.XML_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/init/ModContent.java b/src/main/java/zone/moddev/mc/SteamAdvantage/init/ModContent.java index ae2acda..ab64a73 100644 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/init/ModContent.java +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/init/ModContent.java @@ -43,6 +43,11 @@ public final class ModContent { List.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"); + /** Machines defined by MMDLib XML (mmdlib/machine/); the rest still use MachineBlock. */ + public static final List XML_MACHINES = + List.of("steam_boiler_coal", "steam_boiler_electric", "steam_boiler_geothermal", + "steam_boiler_oil", "steam_tank", "steam_elevator", "steam_still", + "steam_pump", "steam_switch"); private ModContent() {} public static ResourceLocation id(String path) { return ResourceLocation.fromNamespaceAndPath(SteamAdvantage.MODID, path); 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/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/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/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/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/PumpProcessor.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/PumpProcessor.java new file mode 100644 index 0000000..a86e06b --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/PumpProcessor.java @@ -0,0 +1,100 @@ +package zone.moddev.mc.SteamAdvantage.machines; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.BucketPickup; +import net.minecraft.world.level.block.state.BlockState; +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; + +/** + * 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; + + @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(); + for (int i = 0; i < 64; i++, end = end.below()) { + if (!level.hasChunkAt(end) || !level.isInWorldBounds(end)) + return; + BlockState s = level.getBlockState(end); + if (s.is(pipe)) + continue; + if (s.isAir()) { + boolean fluidNearby = false; + for (Direction d : Direction.values()) + if (level.hasChunkAt(end.relative(d)) + && !level.getFluidState(end.relative(d)).isEmpty()) + fluidNearby = true; + if (fluidNearby) + break; + if (level.getGameTime() % 11 == 0) { + level.setBlockAndUpdate(end, pipe.defaultBlockState()); + spendSteam(500); + } + return; + } + break; + } + if (level.getGameTime() % 32 != 0 || !hasSteam(3200) || tank(PRODUCT).getSpace() < 1000) + return; + var queue = new java.util.ArrayDeque(); + var seen = new java.util.HashSet(); + queue.add(end); + for (Direction d : Direction.values()) queue.add(end.relative(d)); + int visited = 0; + while (!queue.isEmpty() && visited++ < 125) { + BlockPos p = queue.removeFirst(); + if (!seen.add(p) || !level.hasChunkAt(p) || p.distManhattan(end) > 32) + continue; + BlockState state = level.getBlockState(p); + if (state.getFluidState().isEmpty()) + continue; + if (state.getBlock() instanceof BucketPickup pickup) { + FluidStack candidate = new FluidStack(state.getFluidState().getType(), 1000); + if (tank(PRODUCT).fill(candidate, FluidAction.SIMULATE) == 1000) { + ItemStack bucket = pickup.pickupBlock(null, level, p, state); + if (!bucket.isEmpty()) { + tank(PRODUCT).fill(candidate, FluidAction.EXECUTE); + spendSteam(3200); + return; + } + } + } + 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/SteamMachineEntity.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamMachineEntity.java new file mode 100644 index 0000000..e7e2f42 --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamMachineEntity.java @@ -0,0 +1,78 @@ +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"); + + 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; + } + + /** + * 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; + 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 index e18ede0..eed4b01 100644 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamProcessor.java +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamProcessor.java @@ -60,6 +60,33 @@ protected final Direction front() { 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(); @@ -81,4 +108,20 @@ 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..82e8095 --- /dev/null +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamScreens.java @@ -0,0 +1,43 @@ +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 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/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/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_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_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/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_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_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/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_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_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/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_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_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/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_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_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 index 1615de4..030c28a 100644 --- a/src/main/resources/mmdlib/machine/steam_switch.xml +++ b/src/main/resources/mmdlib/machine/steam_switch.xml @@ -10,4 +10,9 @@ + + + + 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_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_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/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_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_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/update.json b/update.json index 6e6663a..e59df46 100644 --- a/update.json +++ b/update.json @@ -5,7 +5,7 @@ "1.21.1-recommended": "3.0.3.121012" }, "1.21.1": { - "3.2.0.121012": "Requires MMDLib 2.0.3. Machines are moving to MMDLib's XML machine definitions; existing worlds load unchanged. Ported so far: the steam tank and steam switch, which now use MMDLib's standard machine screen with a pause button and the side-configuration and redstone drawers. Broken machines now keep their fluids in a recovery capsule instead of losing them. Ported machines' blast resistance matches their hardness (3.5, down from 6).", + "3.2.0.121012": "Requires MMDLib 2.0.3. Machines are moving to MMDLib's XML machine definitions; existing worlds load unchanged. Ported so far: the steam tank, steam switch, all four steam boilers, steam pump, steam-powered still and steam elevator. They now 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. Broken machines now keep their fluids in a recovery capsule instead of losing them. Ported 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. 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. 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.", From 74ffdb04c0a1f7f2d8e253cb78cef26d52c7a8bb Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Thu, 19 Nov 2026 09:07:09 -0500 Subject: [PATCH 5/7] Port the steam drill to an XML machine DrillProcessor carries DrillOperation's behavior, including the restored SA2 pace and plain block drops: drilling, segment-by-segment retraction at bedrock, the world edge or its range, track following, and output pushed out of its back. The XML block uses six-way facing, placed toward the player as before. SteamMachineEntity keeps the drill pipe tidy without a machine-specific block: removing the drill (MMDLib's dropContents, which never runs on chunk unload) or turning it to face elsewhere (setBlockState) clears the pipe. A drill moving along a track carries its contents with it and no longer drops a recovery capsule where it was. Pre-XML drills import their depth, phase, retraction and progress, and output slots 4-8 become 0-4. The drill bit's cleanup reaches the drill through its processor. Drill tests step DrillProcessor directly; the redstone reset is checked on real ticks. Co-Authored-By: Claude Opus 5.5 --- .../machines/SteamGameTests.java | 163 ++++++----- .../SteamAdvantage/blocks/DrillBitBlock.java | 8 +- .../mc/SteamAdvantage/init/ModContent.java | 2 +- .../machines/DrillProcessor.java | 272 ++++++++++++++++++ .../machines/SteamMachineEntity.java | 32 +++ .../SteamAdvantage/machines/SteamScreens.java | 8 + .../blockstates/steam_drill.json | 28 -- ...team_drill.json => steam_drill_model.json} | 0 .../models/item/steam_drill.json | 3 - .../loot_table/blocks/steam_drill.json | 19 -- .../resources/mmdlib/machine/steam_drill.xml | 35 +++ .../resources/mmdlib/screen/steam_drill.xml | 22 -- .../mmdlib/standalone/block/steam_drill.json | 13 - update.json | 2 +- 14 files changed, 450 insertions(+), 157 deletions(-) create mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/DrillProcessor.java delete mode 100644 src/main/resources/assets/steamadvantage/blockstates/steam_drill.json rename src/main/resources/assets/steamadvantage/models/block/{steam_drill.json => steam_drill_model.json} (100%) delete mode 100644 src/main/resources/assets/steamadvantage/models/item/steam_drill.json delete mode 100644 src/main/resources/data/steamadvantage/loot_table/blocks/steam_drill.json create mode 100644 src/main/resources/mmdlib/machine/steam_drill.xml delete mode 100644 src/main/resources/mmdlib/screen/steam_drill.xml delete mode 100644 src/main/resources/mmdlib/standalone/block/steam_drill.json 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 da03df6..913353a 100644 --- a/src/gameTest/java/zone/moddev/mc/SteamAdvantage/machines/SteamGameTests.java +++ b/src/gameTest/java/zone/moddev/mc/SteamAdvantage/machines/SteamGameTests.java @@ -49,6 +49,11 @@ private static void setXmlComparatorSource(zone.moddev.mc.lib.machine.neoforge.D 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_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 @@ -73,14 +78,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) @@ -92,7 +97,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)); } @@ -103,43 +108,46 @@ else if (scenario == 1) @GameTest(template = "empty") public static void drillRetractsGraduallyAndWaitsForReset(GameTestHelper h) { - var drill = place(h, "steam_drill", 2, 2, 2); + var drill = placeXml(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") @@ -229,25 +237,25 @@ public static void villagerOffersIncludeBothSmithsAndEnchantedCleric(GameTestHel @GameTest(template = "empty") public static void drillReturnsNormalBlockDropsWithoutCrushing(GameTestHelper h) { - var drill = place(h, "steam_drill", 3, 2, 3); + var drill = placeXml(h, "steam_drill", 3, 2, 3); + var dp = processor(drill, DrillProcessor.class); var target = new BlockPos(3, 2, 2); // Cobblestone and bricks have crushing recipes; the drill must not apply them. for (var block : new net.minecraft.world.level.block.Block[] { Blocks.STONE, Blocks.COBBLESTONE, Blocks.BRICKS, Blocks.DIRT}) { h.setBlock(target, block); - drill.depth = 0; - drill.progress[0] = 0; + dp.set(0, DrillProcessor.DRILLING, 0); drill.fluids.fill(steam(5000), FluidAction.EXECUTE); - for (int slot = 4; slot < 9; slot++) drill.items.setStackInSlot(slot, ItemStack.EMPTY); - int ticks = DrillOperation.breakTicks(block.defaultBlockState(), h.getLevel(), h.absolutePos(target)); - for (int tick = 0; tick < ticks; tick++) DrillOperation.drill(drill); + 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(4).is(expected) - && drill.items.getStackInSlot(4).getCount() == 1, + h.assertTrue(drill.items.getStackInSlot(0).is(expected) + && drill.items.getStackInSlot(0).getCount() == 1, "Normal block drop for " + block); - h.assertTrue(drill.depth == 1 && h.getBlockState(target).is(ModContent.block("drillbit")), + 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++) + for (int slot = 1; slot < 5; slot++) h.assertTrue(drill.items.getStackInSlot(slot).isEmpty(), "No extra drops"); } h.succeed(); @@ -255,24 +263,25 @@ public static void drillReturnsNormalBlockDropsWithoutCrushing(GameTestHelper h) @GameTest(template = "empty") public static void drillWaitsForOutputCapacity(GameTestHelper h) { - var drill = place(h, "steam_drill", 3, 2, 3); + var drill = placeXml(h, "steam_drill", 3, 2, 3); + var dp = processor(drill, DrillProcessor.class); var target = new BlockPos(3, 2, 2); 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)); - for (int tick = 0; tick < 30; tick++) DrillOperation.drill(drill); - h.assertTrue(h.getBlockState(target).is(Blocks.COBBLESTONE) && 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(6, new ItemStack(Items.COBBLESTONE, 63)); - int ticks = DrillOperation.breakTicks(Blocks.COBBLESTONE.defaultBlockState(), h.getLevel(), h.absolutePos(target)); - for (int tick = 0; tick < ticks; tick++) DrillOperation.drill(drill); - h.assertTrue(drill.items.getStackInSlot(6).getCount() == 64 && drill.depth == 1, + 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++) DrillOperation.drill(drill); - h.assertTrue(drill.items.getStackInSlot(6).getCount() == 64, + 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(); } @@ -325,13 +334,14 @@ public static void machineComparatorSourcesAndScaling(GameTestHelper h) { h.assertTrue(m.comparatorSignal() == 0, kind + " ignores unrelated steam fullness"); } } - 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 drill = placeXml(h, "steam_drill", 2, 2, 2); + 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(); } @@ -868,6 +878,22 @@ && processor(oil, OilBoilerProcessor.class).burnTime() == 40, m.fluids().tank(1).fill(new FluidStack(Fluids.WATER, 2000), FluidAction.EXECUTE), tag -> {}); h.assertTrue(pump.fluids.tank(1).getFluidAmount() == 2000, "Pumped fluid stays in tank 1"); + + var drill = importLegacy(h, "steam_drill", m -> { + m.items().setStackInSlot(4, new ItemStack(Items.COBBLESTONE, 12)); + m.items().setStackInSlot(8, new ItemStack(Items.FLINT, 2)); + m.depth = 9; + m.drillPhase = 1; + m.drillRetractionTicks = 2; + m.progress[0] = 5; + }, tag -> {}); + 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") @@ -961,16 +987,19 @@ public static void crushingUsesLibraryRecipes(GameTestHelper h) { } @GameTest(template = "empty", timeoutTicks = 80) public static void drillMovesAlongTrackWithoutLosingInventory(GameTestHelper h) { - var drill = place(h, "steam_drill", 3, 2, 3); + var drill = placeXml(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(); @@ -981,25 +1010,25 @@ public static void drillBreaksBlocksAtDiamondPickaxeSpeed(GameTestHelper h) { var level = h.getLevel(); var p = h.absolutePos(BlockPos.ZERO); // SA2 timing at the default 12 ticks per hardness, minimum 6. - h.assertTrue(DrillOperation.breakTicks(Blocks.STONE.defaultBlockState(), level, p) == 18, + h.assertTrue(DrillProcessor.breakTicks(Blocks.STONE.defaultBlockState(), level, p) == 18, "Stone breaks in 18 ticks"); - h.assertTrue(DrillOperation.breakTicks(Blocks.DIRT.defaultBlockState(), level, p) == 6, + h.assertTrue(DrillProcessor.breakTicks(Blocks.DIRT.defaultBlockState(), level, p) == 6, "Dirt breaks in 6 ticks"); - h.assertTrue(DrillOperation.breakTicks(Blocks.IRON_ORE.defaultBlockState(), level, p) == 36, + h.assertTrue(DrillProcessor.breakTicks(Blocks.IRON_ORE.defaultBlockState(), level, p) == 36, "Iron ore breaks in 36 ticks"); - h.assertTrue(DrillOperation.breakTicks(Blocks.OBSIDIAN.defaultBlockState(), level, p) == 600, + h.assertTrue(DrillProcessor.breakTicks(Blocks.OBSIDIAN.defaultBlockState(), level, p) == 600, "Obsidian breaks in 600 ticks"); h.succeed(); } @GameTest(template = "empty", timeoutTicks = 80) public static void starvedDrillPausesInsteadOfRetracting(GameTestHelper h) { - var drill = place(h, "steam_drill", 3, 2, 3); + var drill = placeXml(h, "steam_drill", 3, 2, 3); // Enough steam for one pipe segment through air, then starved. drill.fluids.fill(steam(300), FluidAction.EXECUTE); 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(); }); } 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/init/ModContent.java b/src/main/java/zone/moddev/mc/SteamAdvantage/init/ModContent.java index ab64a73..e504eb6 100644 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/init/ModContent.java +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/init/ModContent.java @@ -47,7 +47,7 @@ public final class ModContent { public static final List XML_MACHINES = List.of("steam_boiler_coal", "steam_boiler_electric", "steam_boiler_geothermal", "steam_boiler_oil", "steam_tank", "steam_elevator", "steam_still", - "steam_pump", "steam_switch"); + "steam_pump", "steam_switch", "steam_drill"); private ModContent() {} public static ResourceLocation id(String path) { return ResourceLocation.fromNamespaceAndPath(SteamAdvantage.MODID, path); 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/SteamMachineEntity.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamMachineEntity.java index e7e2f42..4dccc07 100644 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamMachineEntity.java +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamMachineEntity.java @@ -32,6 +32,9 @@ public class SteamMachineEntity extends DefinedMachineEntity { "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); @@ -61,6 +64,35 @@ protected CompoundTag migrateMachineData(CompoundTag tag, HolderLookup.Provider 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); + } + + /** 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. diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamScreens.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamScreens.java index 82e8095..e9a742b 100644 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamScreens.java +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamScreens.java @@ -33,6 +33,14 @@ 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); } 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/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/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/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/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/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/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/update.json b/update.json index e59df46..1ad5177 100644 --- a/update.json +++ b/update.json @@ -5,7 +5,7 @@ "1.21.1-recommended": "3.0.3.121012" }, "1.21.1": { - "3.2.0.121012": "Requires MMDLib 2.0.3. Machines are moving to MMDLib's XML machine definitions; existing worlds load unchanged. Ported so far: the steam tank, steam switch, all four steam boilers, steam pump, steam-powered still and steam elevator. They now 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. Broken machines now keep their fluids in a recovery capsule instead of losing them. Ported machines' blast resistance matches their hardness (3.5, down from 6).", + "3.2.0.121012": "Requires MMDLib 2.0.3. Machines are moving to MMDLib's XML machine definitions; existing worlds load unchanged. Ported so far: the steam tank, steam switch, all four steam boilers, steam pump, steam-powered still, steam elevator and steam drill. They now 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. Broken machines now keep their fluids in a recovery capsule instead of losing them. Ported 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. 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. 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.", From c7abb51eb8930c74f4da279d83e97488a14122a8 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Thu, 19 Nov 2026 09:17:27 -0500 Subject: [PATCH 6/7] Finish the XML machine port: crusher, furnace and cleanup The crusher and furnace become XML machines driven by MMDLib recipe processors, so every SteamAdvantage machine is now an MMDLib XML machine. - steamadvantage:steam_crushing (SteamCrushingRecipes) adapts every MMDLib crushing recipe at the old cost: 125 ticks, 18,750 mB of steam per item. - steamadvantage:steam_smelting (SteamSmeltingRecipes) adapts smelting at each recipe's cooking time, converting MMDLib's FE price to steam (2000 mB per 200 ticks). The furnace runs three lanes bound to their own slots, sharing the steam tank; its fuel slot and heat model are gone. - RecipeMachineSensor gives both machines their comparator reading and lets a working furnace melt snow. SteamMachineEntity holds recipe machines while powered, keeping SA2's redstone rule. - Pre-XML crushers and furnaces import their items and steam; the old furnace fuel slot's contents go to recovery. The shared SteamMachine entity, MachineBlock, MachineSettings, the old *Operation classes, the machine factories and the use_machine handler are removed. Old-save tests now load SNBT fixtures written by that entity (captured from 74ffdb0, data/steamadvantage/legacy_saves), the GameTest- only tank variant is an XML machine extending steam_tank, and the furnace temperature tests are dropped with the model they tested. docs/mmdlib-integration.md, the README and the 3.2.0 changelog entry describe the XML machines. Co-Authored-By: Claude Opus 5.5 --- README.md | 10 +- build.gradle | 2 +- docs/mmdlib-integration.md | 161 ++++--- .../machines/SteamGameTests.java | 430 ++++++----------- .../steamadvantage/legacy_saves/README.md | 8 + .../legacy_saves/steam_boiler_coal.snbt | 107 +++++ .../legacy_saves/steam_boiler_electric.snbt | 97 ++++ .../legacy_saves/steam_boiler_geothermal.snbt | 76 +++ .../legacy_saves/steam_boiler_oil.snbt | 102 ++++ .../legacy_saves/steam_crusher.snbt | 111 +++++ .../legacy_saves/steam_drill.snbt | 86 ++++ .../legacy_saves/steam_elevator.snbt | 55 +++ .../legacy_saves/steam_furnace.snbt | 141 ++++++ .../legacy_saves/steam_pump.snbt | 81 ++++ .../legacy_saves/steam_still.snbt | 106 +++++ .../legacy_saves/steam_switch.snbt | 60 +++ .../legacy_saves/steam_tank.snbt | 60 +++ .../mmdlib/machine/test_large_steam_tank.xml | 10 + .../mmdlib/screen/test_large_steam_tank.xml | 11 - .../block/test_large_steam_tank.json | 10 - .../SteamAdvantage/smoke/GuiSmokeServer.java | 33 +- .../mc/SteamAdvantage/SteamAdvantage.java | 2 +- .../SteamAdvantage/init/ContentFactories.java | 36 -- .../mc/SteamAdvantage/init/ModContent.java | 39 +- .../machines/BoilerOperation.java | 59 --- .../machines/CrusherOperation.java | 29 -- .../machines/DrillOperation.java | 202 -------- .../machines/ElevatorOperation.java | 57 --- .../machines/FurnaceOperation.java | 55 --- .../SteamAdvantage/machines/MachineBlock.java | 65 --- .../machines/MachineInteractions.java | 21 - .../machines/MachineInventory.java | 33 -- .../machines/MachineSettings.java | 65 --- .../machines/PumpOperation.java | 76 --- .../machines/RecipeMachineSensor.java | 33 ++ .../SteamAdvantage/machines/SteamMachine.java | 443 ------------------ .../machines/SteamMachineEntity.java | 13 + .../machines/StillOperation.java | 51 -- .../recipes/SteamCrushingRecipes.java | 50 ++ .../recipes/SteamSmeltingRecipes.java | 28 ++ .../blockstates/steam_crusher.json | 28 -- .../blockstates/steam_furnace.json | 28 -- ..._crusher.json => steam_crusher_model.json} | 0 ..._furnace.json => steam_furnace_model.json} | 0 .../models/item/steam_crusher.json | 3 - .../models/item/steam_furnace.json | 3 - .../loot_table/blocks/steam_crusher.json | 19 - .../loot_table/blocks/steam_furnace.json | 19 - src/main/resources/mmdlib/block/machine.json | 27 -- .../resources/mmdlib/block/machine_open.json | 28 -- .../resources/mmdlib/extension/machines.json | 10 - .../mmdlib/machine/steam_crusher.xml | 22 + .../mmdlib/machine/steam_furnace.xml | 32 ++ .../resources/mmdlib/screen/steam_crusher.xml | 17 - .../resources/mmdlib/screen/steam_furnace.xml | 38 -- .../standalone/block/steam_crusher.json | 13 - .../standalone/block/steam_furnace.json | 13 - update.json | 2 +- 58 files changed, 1529 insertions(+), 1887 deletions(-) create mode 100644 src/gameTest/resources/data/steamadvantage/legacy_saves/README.md create mode 100644 src/gameTest/resources/data/steamadvantage/legacy_saves/steam_boiler_coal.snbt create mode 100644 src/gameTest/resources/data/steamadvantage/legacy_saves/steam_boiler_electric.snbt create mode 100644 src/gameTest/resources/data/steamadvantage/legacy_saves/steam_boiler_geothermal.snbt create mode 100644 src/gameTest/resources/data/steamadvantage/legacy_saves/steam_boiler_oil.snbt create mode 100644 src/gameTest/resources/data/steamadvantage/legacy_saves/steam_crusher.snbt create mode 100644 src/gameTest/resources/data/steamadvantage/legacy_saves/steam_drill.snbt create mode 100644 src/gameTest/resources/data/steamadvantage/legacy_saves/steam_elevator.snbt create mode 100644 src/gameTest/resources/data/steamadvantage/legacy_saves/steam_furnace.snbt create mode 100644 src/gameTest/resources/data/steamadvantage/legacy_saves/steam_pump.snbt create mode 100644 src/gameTest/resources/data/steamadvantage/legacy_saves/steam_still.snbt create mode 100644 src/gameTest/resources/data/steamadvantage/legacy_saves/steam_switch.snbt create mode 100644 src/gameTest/resources/data/steamadvantage/legacy_saves/steam_tank.snbt create mode 100644 src/gameTest/resources/mmdlib/machine/test_large_steam_tank.xml delete mode 100644 src/gameTest/resources/mmdlib/screen/test_large_steam_tank.xml delete mode 100644 src/gameTest/resources/mmdlib/standalone/block/test_large_steam_tank.json delete mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/BoilerOperation.java delete mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/CrusherOperation.java delete mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/DrillOperation.java delete mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/ElevatorOperation.java delete mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/FurnaceOperation.java delete mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/MachineBlock.java delete mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/MachineInteractions.java delete mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/MachineInventory.java delete mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/MachineSettings.java delete mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/PumpOperation.java create mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/RecipeMachineSensor.java delete mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamMachine.java delete mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/machines/StillOperation.java create mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/recipes/SteamCrushingRecipes.java create mode 100644 src/main/java/zone/moddev/mc/SteamAdvantage/recipes/SteamSmeltingRecipes.java delete mode 100644 src/main/resources/assets/steamadvantage/blockstates/steam_crusher.json delete mode 100644 src/main/resources/assets/steamadvantage/blockstates/steam_furnace.json rename src/main/resources/assets/steamadvantage/models/block/{steam_crusher.json => steam_crusher_model.json} (100%) rename src/main/resources/assets/steamadvantage/models/block/{steam_furnace.json => steam_furnace_model.json} (100%) delete mode 100644 src/main/resources/assets/steamadvantage/models/item/steam_crusher.json delete mode 100644 src/main/resources/assets/steamadvantage/models/item/steam_furnace.json delete mode 100644 src/main/resources/data/steamadvantage/loot_table/blocks/steam_crusher.json delete mode 100644 src/main/resources/data/steamadvantage/loot_table/blocks/steam_furnace.json delete mode 100644 src/main/resources/mmdlib/block/machine.json delete mode 100644 src/main/resources/mmdlib/block/machine_open.json delete mode 100644 src/main/resources/mmdlib/extension/machines.json create mode 100644 src/main/resources/mmdlib/machine/steam_crusher.xml create mode 100644 src/main/resources/mmdlib/machine/steam_furnace.xml delete mode 100644 src/main/resources/mmdlib/screen/steam_crusher.xml delete mode 100644 src/main/resources/mmdlib/screen/steam_furnace.xml delete mode 100644 src/main/resources/mmdlib/standalone/block/steam_crusher.json delete mode 100644 src/main/resources/mmdlib/standalone/block/steam_furnace.json 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/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/src/gameTest/java/zone/moddev/mc/SteamAdvantage/machines/SteamGameTests.java b/src/gameTest/java/zone/moddev/mc/SteamAdvantage/machines/SteamGameTests.java index 913353a..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,22 +16,12 @@ @GameTestHolder(SteamAdvantage.MODID) @PrefixGameTestTemplate(false) public final class SteamGameTests { - private static SteamMachine 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; - } - /** Machines already ported to MMDLib XML definitions. */ - private static final java.util.Set XML_MACHINES = - java.util.Set.copyOf(ModContent.XML_MACHINES); /** 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 placeXml( + 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)); @@ -49,6 +39,13 @@ private static void setXmlComparatorSource(zone.moddev.mc.lib.machine.neoforge.D 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 @@ -108,7 +105,7 @@ else if (scenario == 1) @GameTest(template = "empty") public static void drillRetractsGraduallyAndWaitsForReset(GameTestHelper h) { - var drill = placeXml(h, "steam_drill", 2, 2, 2); + 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)); @@ -237,7 +234,7 @@ public static void villagerOffersIncludeBothSmithsAndEnchantedCleric(GameTestHel @GameTest(template = "empty") public static void drillReturnsNormalBlockDropsWithoutCrushing(GameTestHelper h) { - var drill = placeXml(h, "steam_drill", 3, 2, 3); + var drill = place(h, "steam_drill", 3, 2, 3); var dp = processor(drill, DrillProcessor.class); var target = new BlockPos(3, 2, 2); // Cobblestone and bricks have crushing recipes; the drill must not apply them. @@ -263,7 +260,7 @@ public static void drillReturnsNormalBlockDropsWithoutCrushing(GameTestHelper h) @GameTest(template = "empty") public static void drillWaitsForOutputCapacity(GameTestHelper h) { - var drill = placeXml(h, "steam_drill", 3, 2, 3); + 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.COBBLESTONE); @@ -286,55 +283,21 @@ public static void drillWaitsForOutputCapacity(GameTestHelper h) { 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 (XML_MACHINES.contains(kind)) - continue; // Sampled once per tick; see xmlComparatorScaling. + 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"); } - var drill = placeXml(h, "steam_drill", 2, 2, 2); + h.setBlock(new BlockPos(2, 2, 2), Blocks.AIR); + var drill = place(h, "steam_drill", 2, 2, 2); 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"); @@ -348,14 +311,14 @@ public static void machineComparatorSourcesAndScaling(GameTestHelper h) { /** 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, XML_MACHINES.stream().sorted().toList(), 0, 0); + 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 ? placeXml(h, kind, 2, 2, 2) + 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. @@ -384,8 +347,8 @@ private static void verifyComparatorUpdate(GameTestHelper h, int index) { h.setBlock(comparatorPos, Blocks.AIR); h.setBlock(machinePos, Blocks.AIR); String kind = ModContent.MACHINES.get(index); - if (XML_MACHINES.contains(kind)) { - var x = placeXml(h, kind, 2, 2, 2); + 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( @@ -402,28 +365,7 @@ private static void verifyComparatorUpdate(GameTestHelper h, int index) { verifyComparatorUpdate(h, index + 1); }); }); - return; } - var m = place(h, kind, 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); - h.runAfterDelay(4, () -> { - h.assertTrue(comparator.getOutputSignal() == 0, m.kind + " comparator falls to zero"); - verifyComparatorUpdate(h, index + 1); - }); - }); } /** Temporary tag membership exercises datapack integration without shipping test tag entries. */ @@ -670,15 +612,14 @@ private static FluidStack steam(int amount) { @GameTest(template = "empty") public static void registrationCapabilitiesPersistence(GameTestHelper h) { for (String name : ModContent.MACHINES) { - var m = XML_MACHINES.contains(name) ? placeXml(h, name, 2, 2, 2) - : place(h, name, 2, 2, 2); + var m = place(h, name, 2, 2, 2); for (var side : Direction.values()) h.assertTrue(h.getLevel().getCapability( Capabilities.FluidHandler.BLOCK, m.getBlockPos(), side) != null, "Missing fluid capability " + name); } - var tank = placeXml(h, "steam_tank", 2, 2, 2); + var tank = place(h, "steam_tank", 2, 2, 2); h.assertTrue(tank.fluids.fill(new FluidStack(Fluids.WATER, 1000), FluidAction.EXECUTE) == 0, "Steam-only filter"); tank.fluids.fill(steam(123456), FluidAction.EXECUTE); @@ -701,18 +642,18 @@ private static net.neoforged.neoforge.fluids.capability.IFluidHandler fluidsAt( @GameTest(template = "empty") public static void defaultAutomationSidesMatchRoles(GameTestHelper h) { var furnace = place(h, "steam_furnace", 1, 2, 1); - var boiler = placeXml(h, "steam_boiler_electric", 4, 2, 1); - var tank = placeXml(h, "steam_tank", 1, 2, 4); - furnace.items.setStackInSlot(4, new ItemStack(Items.IRON_INGOT, 6)); + var boiler = place(h, "steam_boiler_electric", 4, 2, 1); + var tank = place(h, "steam_tank", 1, 2, 4); + 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, @@ -733,7 +674,7 @@ public static void defaultAutomationSidesMatchRoles(GameTestHelper h) { } @GameTest(template = "empty") public static void automationSideConfigGatesAndPersists(GameTestHelper h) { - var boiler = placeXml(h, "steam_boiler_coal", 2, 2, 2); + var boiler = place(h, "steam_boiler_coal", 2, 2, 2); var automation = boiler.screenAutomation(); var water = automation.group(automation.index("water")); var facing = boiler.getBlockState().getValue( @@ -762,8 +703,8 @@ public static void automationSideConfigGatesAndPersists(GameTestHelper h) { } @GameTest(template = "empty", timeoutTicks = 60) public static void powerAdvantagePumpAddonWorksAndDrops(GameTestHelper h) { - var boiler = placeXml(h, "steam_boiler_coal", 2, 2, 2); - var still = placeXml(h, "steam_still", 3, 2, 2); + 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.screenAutomation(); int water = automation.index("water"); @@ -786,107 +727,85 @@ public static void powerAdvantagePumpAddonWorksAndDrops(GameTestHelper h) { }); } /** - * A save written by the shared pre-XML SteamMachine entity, with its machine state in - * top-level keys and the electric boiler's pre-2.0.2 "Energy" key. + * 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, java.util.function.Consumer setup, - java.util.function.Consumer edit) { + GameTestHelper h, String kind) { var registries = h.getLevel().registryAccess(); - var placed = placeXml(h, kind, 2, 2, 2); - var crusher = ModContent.block("steam_crusher").defaultBlockState(); - var settings = switch (kind) { - case "steam_boiler_electric" -> new MachineSettings(kind, 20000, 4000, 0, 0, 9, 1600, 160); - case "steam_boiler_coal" -> new MachineSettings(kind, 100000, 4000, 0, 0, 9, 0, 0); - case "steam_boiler_oil" -> new MachineSettings(kind, 100000, 4000, 4000, 0, 9, 0, 0); - case "steam_boiler_geothermal" -> new MachineSettings(kind, 10000, 4000, 0, 0, 9, 0, 0); - case "steam_still" -> new MachineSettings(kind, 10000, 4000, 0, 4000, 9, 0, 0); - case "steam_pump" -> new MachineSettings(kind, 20000, 0, 0, 4000, 9, 0, 0); - default -> new MachineSettings(kind, 6400, 0, 0, 0, 9, 0, 0); - }; - var legacy = new SteamMachine(ModContent.machineType(crusher), placed.getBlockPos(), crusher, - settings); - legacy.setLevel(h.getLevel()); // The still's input filter consults the level's recipes. - setup.accept(legacy); - var saved = legacy.saveWithFullMetadata(registries); - saved.putString("id", ModContent.id(kind).toString()); - edit.accept(saved); - h.setBlock(new BlockPos(2, 2, 2), Blocks.AIR); - h.setBlock(new BlockPos(2, 2, 2), placed.getBlockState()); + 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( - h.absolutePos(new BlockPos(2, 2, 2)), placed.getBlockState(), saved, registries); + 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 preXmlMachineSavesLoad(GameTestHelper h) { - var coal = importLegacy(h, "steam_boiler_coal", m -> { - m.items().setStackInSlot(0, new ItemStack(Items.COAL, 5)); - m.fluids().tank(1).fill(new FluidStack(Fluids.WATER, 777), FluidAction.EXECUTE); - m.burn = 17; - m.totalBurn = 1600; - }, tag -> {}); + 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", m -> m.energy().setStored(1234), - tag -> { - // SA3 before MMDLib 2.0.2 saved the buffer as "Energy". - tag.put("Energy", tag.get("energy")); - tag.remove("energy"); - }); + 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", m -> { - m.fluids().tank(2).fill(new FluidStack(Fluids.LAVA, 900), FluidAction.EXECUTE); - m.burn = 40; - }, tag -> {}); + 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", m -> m.temperature = 640, tag -> {}); + var geo = importLegacy(h, "steam_boiler_geothermal"); h.assertTrue(processor(geo, GeothermalBoilerProcessor.class).temperature() == 640, "Geothermal temperature imported"); - var elevator = importLegacy(h, "steam_elevator", m -> { - m.raised = true; - m.elevatorHeight = 5; - }, tag -> {}); + var elevator = importLegacy(h, "steam_elevator"); h.assertTrue(processor(elevator, ElevatorProcessor.class).raised(), "Raised state imported"); - var still = importLegacy(h, "steam_still", m -> { - m.fluids().tank(2).fill(new FluidStack(Fluids.WATER, 300), FluidAction.EXECUTE); - m.pendingDistillation = new FluidStack(Fluids.LAVA, 100); - m.distillationDuration = 20; - m.progress[0] = 7; - }, tag -> {}); + 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", m -> - m.fluids().tank(1).fill(new FluidStack(Fluids.WATER, 2000), FluidAction.EXECUTE), - tag -> {}); + var pump = importLegacy(h, "steam_pump"); h.assertTrue(pump.fluids.tank(1).getFluidAmount() == 2000, "Pumped fluid stays in tank 1"); - var drill = importLegacy(h, "steam_drill", m -> { - m.items().setStackInSlot(4, new ItemStack(Items.COBBLESTONE, 12)); - m.items().setStackInSlot(8, new ItemStack(Items.FLINT, 2)); - m.depth = 9; - m.drillPhase = 1; - m.drillRetractionTicks = 2; - m.progress[0] = 5; - }, tag -> {}); + 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), @@ -900,7 +819,7 @@ && processor(oil, OilBoilerProcessor.class).burnTime() == 40, 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); @@ -913,7 +832,7 @@ public static void brokenMachineDropsItemsOnce(GameTestHelper h) { } @GameTest(template = "empty", timeoutTicks = 100) public static void coalBoilerAndRedstone(GameTestHelper h) { - var boiler = placeXml(h, "steam_boiler_coal", 2, 2, 2); + var boiler = place(h, "steam_boiler_coal", 2, 2, 2); boiler.fluids.fill(new FluidStack(Fluids.WATER, 1000), FluidAction.EXECUTE); boiler.items.setStackInSlot(0, new ItemStack(Items.COAL)); h.setBlock(new BlockPos(2, 3, 2), Blocks.SNOW); @@ -936,7 +855,7 @@ public static void coalBoilerAndRedstone(GameTestHelper h) { } @GameTest(template = "empty", timeoutTicks = 100) public static void electricBoilerSpendsEnergy(GameTestHelper h) { - var boiler = placeXml(h, "steam_boiler_electric", 2, 2, 2); + var boiler = place(h, "steam_boiler_electric", 2, 2, 2); boiler.fluids.fill(new FluidStack(Fluids.WATER, 1000), FluidAction.EXECUTE); boiler.energy.setStored(160); h.runAfterDelay(20, () -> { @@ -947,7 +866,7 @@ public static void electricBoilerSpendsEnergy(GameTestHelper h) { } @GameTest(template = "empty", timeoutTicks = 100) public static void pumpConservesWorldFluid(GameTestHelper h) { - var pump = placeXml(h, "steam_pump", 2, 4, 2); + var pump = place(h, "steam_pump", 2, 4, 2); pump.fluids.fill(steam(6400), FluidAction.EXECUTE); h.setBlock(new BlockPos(2, 3, 2), Blocks.WATER); h.runAfterDelay(40, () -> { @@ -959,7 +878,7 @@ public static void pumpConservesWorldFluid(GameTestHelper h) { } @GameTest(template = "empty", timeoutTicks = 120) public static void boilerPipeConsumer(GameTestHelper h) { - var boiler = placeXml(h, "steam_boiler_coal", 2, 2, 2); + var boiler = place(h, "steam_boiler_coal", 2, 2, 2); h.setBlock(new BlockPos(3, 2, 2), ModContent.block("steam_pipe")); var furnace = place(h, "steam_furnace", 4, 2, 2); boiler.fluids.fill(new FluidStack(Fluids.WATER, 1000), FluidAction.EXECUTE); @@ -978,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"); @@ -987,7 +906,7 @@ public static void crushingUsesLibraryRecipes(GameTestHelper h) { } @GameTest(template = "empty", timeoutTicks = 80) public static void drillMovesAlongTrackWithoutLosingInventory(GameTestHelper h) { - var drill = placeXml(h, "steam_drill", 3, 2, 3); + var drill = place(h, "steam_drill", 3, 2, 3); drill.fluids.fill(steam(5000), FluidAction.EXECUTE); drill.items.setStackInSlot(0, new ItemStack(Items.DIAMOND, 3)); h.setBlock(new BlockPos(3, 2, 2), Blocks.BEDROCK); @@ -1022,7 +941,7 @@ public static void drillBreaksBlocksAtDiamondPickaxeSpeed(GameTestHelper h) { } @GameTest(template = "empty", timeoutTicks = 80) public static void starvedDrillPausesInsteadOfRetracting(GameTestHelper h) { - var drill = placeXml(h, "steam_drill", 3, 2, 3); + var drill = place(h, "steam_drill", 3, 2, 3); // Enough steam for one pipe segment through air, then starved. drill.fluids.fill(steam(300), FluidAction.EXECUTE); h.runAfterDelay(5, () -> { @@ -1034,7 +953,7 @@ public static void starvedDrillPausesInsteadOfRetracting(GameTestHelper h) { } @GameTest(template = "empty", timeoutTicks = 80) public static void elevatorExtendsAndRetracts(GameTestHelper h) { - var elevator = placeXml(h, "steam_elevator", 3, 2, 3); + var elevator = place(h, "steam_elevator", 3, 2, 3); elevator.fluids.fill(steam(10000), FluidAction.EXECUTE); h.setBlock(new BlockPos(3, 8, 3), Blocks.STONE); h.setBlock(new BlockPos(4, 2, 3), Blocks.REDSTONE_BLOCK); @@ -1048,39 +967,23 @@ public static void elevatorExtendsAndRetracts(GameTestHelper h) { }); }); } - /** - * A tank or switch saved by SA3 before the XML port (the shared SteamMachine entity, with a - * nine-slot "Items" inventory and an unnamed steam tank under "Fluids") loads into the XML - * machine with its steam intact. - */ + /** Pre-XML tanks and switches keep their steam. */ @GameTest(template = "empty") public static void preXmlTankAndSwitchSavesLoad(GameTestHelper h) { - var registries = h.getLevel().registryAccess(); - var crusher = ModContent.block("steam_crusher").defaultBlockState(); for (String kind : java.util.List.of("steam_tank", "steam_switch")) { - var placed = placeXml(h, kind, 2, 2, 2); - var legacy = new SteamMachine(ModContent.machineType(crusher), placed.getBlockPos(), - crusher, new MachineSettings(kind, kind.equals("steam_tank") ? 1000000 : 20000, - 0, 0, 0, 9, 0, 0)); - legacy.fluids().tank(0).fill(steam(4321), FluidAction.EXECUTE); - var saved = legacy.saveWithFullMetadata(registries); - saved.putString("id", ModContent.id(kind).toString()); - 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 && imported.fluids.tank(0).getFluidAmount() == 4321 + 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.setBlock(new BlockPos(2, 2, 2), Blocks.AIR); } h.succeed(); } @GameTest(template = "empty", timeoutTicks = 80) public static void valveStopsOutputWhenPowered(GameTestHelper h) { - var valve = placeXml(h, "steam_switch", 3, 2, 3); - var tank = placeXml(h, "steam_tank", 3, 2, 2); + var valve = place(h, "steam_switch", 3, 2, 3); + var tank = place(h, "steam_tank", 3, 2, 2); valve.fluids.fill(steam(10000), FluidAction.EXECUTE); h.setBlock(new BlockPos(4, 2, 3), Blocks.REDSTONE_BLOCK); h.runAfterDelay(5, () -> { @@ -1095,10 +998,10 @@ public static void valveStopsOutputWhenPowered(GameTestHelper h) { @GameTest(template = "empty", timeoutTicks = 100) public static void oilAndGeothermalBoilers(GameTestHelper h) { - var oil = placeXml(h, "steam_boiler_oil", 2, 2, 2); + var oil = place(h, "steam_boiler_oil", 2, 2, 2); oil.fluids.fill(new FluidStack(Fluids.WATER, 1000), FluidAction.EXECUTE); oil.fluids.fill(new FluidStack(Fluids.LAVA, 1000), FluidAction.EXECUTE); - var geo = placeXml(h, "steam_boiler_geothermal", 6, 2, 2); + var geo = place(h, "steam_boiler_geothermal", 6, 2, 2); geo.fluids.fill(new FluidStack(Fluids.WATER, 1000), FluidAction.EXECUTE); h.setBlock(new BlockPos(6, 1, 2), Blocks.MAGMA_BLOCK); h.runAfterDelay(60, () -> { @@ -1112,7 +1015,7 @@ public static void oilAndGeothermalBoilers(GameTestHelper h) { @GameTest(template = "empty", timeoutTicks = 140) public static void distillationUsesPowerAdvantageDefaultRecipe(GameTestHelper h) { // PA 3.2's built-in poweradvantage:distilling_refined_oil: 100 mB crude -> 50 mB refined in 100 ticks. - var still = placeXml(h, "steam_still", 2, 2, 2); + var still = place(h, "steam_still", 2, 2, 2); var crudeOil = zone.moddev.mc.poweradvantage.init.Fluids.CRUDE_OIL.get(); var refinedOil = zone.moddev.mc.poweradvantage.init.Fluids.REFINED_OIL.get(); h.setBlock(new BlockPos(2, 3, 2), Blocks.SNOW); @@ -1141,7 +1044,7 @@ public static void distillationUsesPowerAdvantageDefaultRecipe(GameTestHelper h) @GameTest(template = "empty", timeoutTicks = 60) public static void distillationProgressPersistsUntilOutput(GameTestHelper h) { - var still = placeXml(h, "steam_still", 2, 2, 2); + var still = place(h, "steam_still", 2, 2, 2); still.fluids.tank(0).fill(steam(150), FluidAction.EXECUTE); still.fluids.tank(2).fill(new FluidStack(Fluids.WATER, 1000), FluidAction.EXECUTE); h.runAfterDelay(10, () -> { @@ -1165,7 +1068,7 @@ && processor(still, StillProcessor.class).pending().getAmount() == 100, @GameTest(template = "empty", timeoutTicks = 40) public static void distillationBlockedOutputDoesNotConsumeResources(GameTestHelper h) { - var still = placeXml(h, "steam_still", 2, 2, 2); + var still = place(h, "steam_still", 2, 2, 2); still.fluids.tank(0).fill(steam(150), FluidAction.EXECUTE); still.fluids.tank(1).fill(new FluidStack(Fluids.LAVA, 4000), FluidAction.EXECUTE); still.fluids.tank(2).fill(new FluidStack(Fluids.WATER, 1000), FluidAction.EXECUTE); @@ -1199,41 +1102,25 @@ 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 = placeXml(h, "steam_boiler_geothermal", 2, 2, 2); + var geo = place(h, "steam_boiler_geothermal", 2, 2, 2); 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); @@ -1243,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"); @@ -1269,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") @@ -1324,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"); @@ -1379,8 +1252,8 @@ public static void screenSnapshotsPreserveLargeAndFluidValues(GameTestHelper h) h.succeed(); } @GameTest(template = "empty") - public static void mismatchedScreenAndInvalidSettingsAreRejected(GameTestHelper h) { - var tank = placeXml(h, "steam_tank", 2, 2, 2); + 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( io.netty.buffer.Unpooled.buffer(), h.getLevel().registryAccess()); @@ -1395,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/GuiSmokeServer.java b/src/guiSmoke/java/zone/moddev/mc/SteamAdvantage/smoke/GuiSmokeServer.java index 1aabcc7..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,34 +32,14 @@ static void tick(ServerTickEvent.Post event) { var pos = pending; pending = null; var name = ModContent.MACHINES.get(index - 1); - if (level.getBlockEntity(pos) - instanceof zone.moddev.mc.lib.machine.neoforge.DefinedMachineEntity xml) { - xml.fluids.tank(0).fill( - new FluidStack(zone.moddev.mc.poweradvantage.init.Fluids.STEAM.get(), - xml.fluids.tank(0).getCapacity() * 3 / 4), - FluidAction.EXECUTE); - // 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; - } - 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)); + // 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; } diff --git a/src/main/java/zone/moddev/mc/SteamAdvantage/SteamAdvantage.java b/src/main/java/zone/moddev/mc/SteamAdvantage/SteamAdvantage.java index 1e3e4a8..296f133 100644 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/SteamAdvantage.java +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/SteamAdvantage.java @@ -16,7 +16,7 @@ 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.XML_MACHINES) + 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/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 e504eb6..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,16 +36,11 @@ 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", "steam_drill", "steam_elevator", "steam_still", "steam_pump", "steam_switch"); - /** Machines defined by MMDLib XML (mmdlib/machine/); the rest still use MachineBlock. */ - public static final List XML_MACHINES = - List.of("steam_boiler_coal", "steam_boiler_electric", "steam_boiler_geothermal", - "steam_boiler_oil", "steam_tank", "steam_elevator", "steam_still", - "steam_pump", "steam_switch", "steam_drill"); private ModContent() {} public static ResourceLocation id(String path) { return ResourceLocation.fromNamespaceAndPath(SteamAdvantage.MODID, path); @@ -62,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(); @@ -94,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/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 6ddb012..0000000 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/DrillOperation.java +++ /dev/null @@ -1,202 +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.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++; - } - - /** - * Normal block drops, as if mined with the drill's pickaxe. SA2 also ran the block through - * the crusher, but with tags such as Mineralogy's (every rock in c:cobblestones) that turned - * most of the stone it mined into gravel. - */ - private static java.util.List miningDrops(BlockState state, - net.minecraft.server.level.ServerLevel level, BlockPos target) { - 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, 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, net.minecraft.world.level.Level level, BlockPos pos) { - double factor = zone.moddev.mc.SteamAdvantage.config.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))); - } - - 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/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/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/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/PumpOperation.java b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/PumpOperation.java deleted file mode 100644 index 539a779..0000000 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/PumpOperation.java +++ /dev/null @@ -1,76 +0,0 @@ -package zone.moddev.mc.SteamAdvantage.machines; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.BucketPickup; -import net.minecraft.world.level.block.state.BlockState; -import net.neoforged.neoforge.fluids.FluidStack; -import net.neoforged.neoforge.fluids.capability.IFluidHandler.FluidAction; -import zone.moddev.mc.SteamAdvantage.init.ModContent; - -/** Intake-shaft extension and bounded world-fluid collection. */ -final class PumpOperation { - private PumpOperation() {} - - static void pump(SteamMachine machine) { - var level = machine.getLevel(); - var pos = machine.getBlockPos(); - if (!machine.hasSteam(500)) - return; - Block pipe = ModContent.block("pump_pipe_steam"); - BlockPos end = pos.below(); - for (int i = 0; i < 64; i++, end = end.below()) { - if (!level.hasChunkAt(end) || !level.isInWorldBounds(end)) - return; - BlockState s = level.getBlockState(end); - if (s.is(pipe)) - continue; - if (s.isAir()) { - boolean fluidNearby = false; - for (Direction d : Direction.values()) - if (level.hasChunkAt(end.relative(d)) - && !level.getFluidState(end.relative(d)).isEmpty()) - fluidNearby = true; - if (fluidNearby) - break; - if (level.getGameTime() % 11 == 0) { - level.setBlockAndUpdate(end, pipe.defaultBlockState()); - machine.spendSteam(500); - } - return; - } - break; - } - if (level.getGameTime() % 32 != 0 || !machine.hasSteam(3200) - || machine.fluids.tank(machine.product).getSpace() < 1000) - return; - var queue = new java.util.ArrayDeque(); - var seen = new java.util.HashSet(); - queue.add(end); - for (Direction d : Direction.values()) queue.add(end.relative(d)); - int visited = 0; - while (!queue.isEmpty() && visited++ < 125) { - BlockPos p = queue.removeFirst(); - if (!seen.add(p) || !level.hasChunkAt(p) || p.distManhattan(end) > 32) - continue; - BlockState state = level.getBlockState(p); - if (state.getFluidState().isEmpty()) - 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) { - ItemStack bucket = pickup.pickupBlock(null, level, p, state); - if (!bucket.isEmpty()) { - machine.fluids.tank(machine.product).fill(candidate, FluidAction.EXECUTE); - machine.spendSteam(3200); - return; - } - } - } - for (Direction d : Direction.values()) queue.addLast(p.relative(d)); - } - } -} 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 index 4dccc07..0c04f79 100644 --- a/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamMachineEntity.java +++ b/src/main/java/zone/moddev/mc/SteamAdvantage/machines/SteamMachineEntity.java @@ -78,6 +78,17 @@ public void dropContents(net.minecraft.world.level.Level level, BlockPos pos) { 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") @@ -104,6 +115,8 @@ protected IntUnaryOperator legacySlots(String key, CompoundTag tag) { 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/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/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_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_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/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_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/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_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/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_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/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_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_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/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_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/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_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/update.json b/update.json index 1ad5177..25a9453 100644 --- a/update.json +++ b/update.json @@ -5,7 +5,7 @@ "1.21.1-recommended": "3.0.3.121012" }, "1.21.1": { - "3.2.0.121012": "Requires MMDLib 2.0.3. Machines are moving to MMDLib's XML machine definitions; existing worlds load unchanged. Ported so far: the steam tank, steam switch, all four steam boilers, steam pump, steam-powered still, steam elevator and steam drill. They now 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. Broken machines now keep their fluids in a recovery capsule instead of losing them. Ported machines' blast resistance matches their hardness (3.5, down from 6).", + "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. 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. 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. 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.", From 5dc24b12ba94c34ac6329d2cc4094e2e6f6854a4 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Thu, 19 Nov 2026 09:39:24 -0500 Subject: [PATCH 7/7] Move the drill changes to the 3.2.0 changelog The SA2 drill pace and plain block drops landed after 3.1.0 was tagged, so their notes belong to 3.2.0, as does the TODO's "removed in" version. Co-Authored-By: Claude Opus 5.5 --- TODO.md | 2 +- update.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index e9a4546..e64ce44 100644 --- a/TODO.md +++ b/TODO.md @@ -30,7 +30,7 @@ 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.1.0: with Mineralogy's runtime c:cobblestones tag every rock + - 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 diff --git a/update.json b/update.json index 25a9453..02b8ddf 100644 --- a/update.json +++ b/update.json @@ -5,8 +5,8 @@ "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. 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. 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. Steam-Powered Still screen fits small windows again, and the update checker points at the correct repository.", + "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.", "3.0.0.121012": "Initial NeoForge 1.21.1 release."