Skip to content

Commit 8214de1

Browse files
authored
Show multiblock shapes in guidebook (#1040)
1 parent 781940e commit 8214de1

File tree

24 files changed

+289
-11
lines changed

24 files changed

+289
-11
lines changed

src/generated/resources/assets/modern_industrialization/lang/en_us.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,7 @@
14931493
"text.modern_industrialization.AcceptLowOrHighPressure": "Only accepts %s and %s",
14941494
"text.modern_industrialization.AcceptSingleFluid": "Consumes %s and produces %s per mb",
14951495
"text.modern_industrialization.AcceptSingleItem": "Consumes %s and produces %s per item",
1496+
"text.modern_industrialization.AcceptsHatches": "Accepts hatches:",
14961497
"text.modern_industrialization.AcceptsMachineHull": "Change machine hull to connect higher tier cables.",
14971498
"text.modern_industrialization.AcceptsOverdriveModule": "Accepts an overdrive module.",
14981499
"text.modern_industrialization.AcceptsRedstoneControlModule": "Accepts a redstone control module.",
@@ -1564,6 +1565,8 @@
15641565
"text.modern_industrialization.EmptyWhitelistWarning": "⚠ Empty Filter",
15651566
"text.modern_industrialization.Enabled": "Enabled",
15661567
"text.modern_industrialization.EnergyFill": "Energy: %s %%",
1568+
"text.modern_industrialization.EnergyInputHatch": "Energy Input Hatch",
1569+
"text.modern_industrialization.EnergyOutputHatch": "Energy Output Hatch",
15671570
"text.modern_industrialization.EnergyStored": "Energy Stored: %s",
15681571
"text.modern_industrialization.Eu": "%s%s EU",
15691572
"text.modern_industrialization.EuCable": "%s - Max network transfer: %s",
@@ -1580,6 +1583,8 @@
15801583
"text.modern_industrialization.FluidAutoInsertOff": "Fluid auto-pull disabled",
15811584
"text.modern_industrialization.FluidAutoInsertOn": "Fluid auto-pull enabled",
15821585
"text.modern_industrialization.FluidFuels": "Fluid Fuels",
1586+
"text.modern_industrialization.FluidInputHatch": "Fluid Input Hatch",
1587+
"text.modern_industrialization.FluidOutputHatch": "Fluid Output Hatch",
15831588
"text.modern_industrialization.FluidSlotIO": "Fluid IO, Left Click to Insert or Extract",
15841589
"text.modern_industrialization.FluidSlotInput": "Fluid Input, Left Click to Insert or Extract",
15851590
"text.modern_industrialization.FluidSlotOutput": "Fluid Output, Left Click to Extract",
@@ -1595,6 +1600,8 @@
15951600
"text.modern_industrialization.ItemAutoExtractOn": "Item auto-eject enabled",
15961601
"text.modern_industrialization.ItemAutoInsertOff": "Item auto-pull disabled",
15971602
"text.modern_industrialization.ItemAutoInsertOn": "Item auto-pull enabled",
1603+
"text.modern_industrialization.ItemInputHatch": "Item Input Hatch",
1604+
"text.modern_industrialization.ItemOutputHatch": "Item Output Hatch",
15981605
"text.modern_industrialization.JetpackDisabled": "Jetpack disabled!",
15991606
"text.modern_industrialization.JetpackEnabled": "Jetpack enabled!",
16001607
"text.modern_industrialization.JetpackFill": "Fuel: %d %%",

src/main/java/aztech/modern_industrialization/MIText.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public enum MIText {
3939
AcceptLowOrHighPressure("Only accepts %s and %s"),
4040
AcceptSingleFluid("Consumes %s and produces %s per mb"),
4141
AcceptSingleItem("Consumes %s and produces %s per item"),
42+
AcceptsHatches("Accepts hatches:"),
4243
AcceptsMachineHull("Change machine hull to connect higher tier cables."),
4344
AcceptsOverdriveModule("Accepts an overdrive module."),
4445
AcceptsRedstoneControlModule("Accepts a redstone control module."),
@@ -110,6 +111,8 @@ public enum MIText {
110111
EmptyWhitelistWarning("⚠ Empty Filter"),
111112
Enabled("Enabled"),
112113
EnergyFill("Energy: %s %%"),
114+
EnergyInputHatch("Energy Input Hatch"),
115+
EnergyOutputHatch("Energy Output Hatch"),
113116
EnergyStored("Energy Stored: %s"),
114117
Eu("%s%s EU"),
115118
EuCable("%s - Max network transfer: %s"),
@@ -126,6 +129,8 @@ public enum MIText {
126129
FluidAutoInsertOff("Fluid auto-pull disabled"),
127130
FluidAutoInsertOn("Fluid auto-pull enabled"),
128131
FluidFuels("Fluid Fuels"),
132+
FluidInputHatch("Fluid Input Hatch"),
133+
FluidOutputHatch("Fluid Output Hatch"),
129134
FluidSlotIO("Fluid IO, Left Click to Insert or Extract"),
130135
FluidSlotInput("Fluid Input, Left Click to Insert or Extract"),
131136
FluidSlotOutput("Fluid Output, Left Click to Extract"),
@@ -141,6 +146,8 @@ public enum MIText {
141146
ItemAutoExtractOn("Item auto-eject enabled"),
142147
ItemAutoInsertOff("Item auto-pull disabled"),
143148
ItemAutoInsertOn("Item auto-pull enabled"),
149+
ItemInputHatch("Item Input Hatch"),
150+
ItemOutputHatch("Item Output Hatch"),
144151
JetpackDisabled("Jetpack disabled!"),
145152
JetpackEnabled("Jetpack enabled!"),
146153
JetpackFill("Fuel: %d %%"),

src/main/java/aztech/modern_industrialization/guidebook/MIGuide.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import aztech.modern_industrialization.MI;
2727
import guideme.Guide;
28+
import guideme.scene.element.SceneElementTagCompiler;
2829
import net.minecraft.resources.ResourceLocation;
2930

3031
public class MIGuide {
@@ -34,6 +35,7 @@ public class MIGuide {
3435
public static void init() {
3536
guide = Guide.builder(ID)
3637
.folder("mi_guidebook")
38+
.extension(SceneElementTagCompiler.EXTENSION_POINT, new MultiblockShapeCompiler())
3739
.build();
3840
}
3941

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2020 Azercoco & Technici4n
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package aztech.modern_industrialization.guidebook;
25+
26+
import aztech.modern_industrialization.MIText;
27+
import aztech.modern_industrialization.machines.MachineBlock;
28+
import aztech.modern_industrialization.machines.multiblocks.HatchType;
29+
import aztech.modern_industrialization.machines.multiblocks.MultiblockMachineBlockEntity;
30+
import guideme.color.SymbolicColor;
31+
import guideme.compiler.PageCompiler;
32+
import guideme.compiler.tags.MdxAttrs;
33+
import guideme.document.LytErrorSink;
34+
import guideme.document.interaction.TextTooltip;
35+
import guideme.libs.mdast.mdx.model.MdxJsxElementFields;
36+
import guideme.scene.GuidebookScene;
37+
import guideme.scene.annotation.InWorldBoxAnnotation;
38+
import guideme.scene.element.SceneElementTagCompiler;
39+
import java.util.ArrayList;
40+
import java.util.List;
41+
import java.util.Set;
42+
import net.minecraft.network.chat.Component;
43+
import net.minecraft.world.phys.Vec3;
44+
45+
public class MultiblockShapeCompiler implements SceneElementTagCompiler {
46+
@Override
47+
public Set<String> getTagNames() {
48+
return Set.of("MultiblockShape");
49+
}
50+
51+
@Override
52+
public void compile(GuidebookScene scene, PageCompiler compiler, LytErrorSink errorSink, MdxJsxElementFields el) {
53+
var controller = MdxAttrs.getRequiredBlockAndId(compiler, errorSink, el, "controller");
54+
if (controller == null) {
55+
// Parsing error
56+
return;
57+
}
58+
if (!(controller.getRight() instanceof MachineBlock machineBlock)
59+
|| !(machineBlock.getBlockEntityInstance() instanceof MultiblockMachineBlockEntity multi)) {
60+
errorSink.appendError(compiler, "Block is not a multiblock controller: " + controller.getLeft(), el);
61+
return;
62+
}
63+
var useBigShape = MdxAttrs.getBoolean(compiler, errorSink, el, "useBigShape", false);
64+
65+
var shape = useBigShape ? multi.getBigShape() : multi.getActiveShape();
66+
var controllerPos = MdxAttrs.getPos(compiler, errorSink, el);
67+
68+
// Controller
69+
scene.getLevel().setBlockAndUpdate(controllerPos, controller.getRight().defaultBlockState());
70+
// Shape blocks
71+
for (var entry : shape.simpleMembers.entrySet()) {
72+
scene.getLevel().setBlockAndUpdate(entry.getKey().offset(controllerPos), entry.getValue().getPreviewState());
73+
}
74+
// Annotations for allowed hatches
75+
for (var entry : shape.hatchFlags.entrySet()) {
76+
var minCorner = Vec3.atLowerCornerOf(entry.getKey().offset(controllerPos));
77+
var annotation = new InWorldBoxAnnotation(minCorner.toVector3f(), minCorner.add(1, 1, 1).toVector3f(), SymbolicColor.GREEN);
78+
79+
List<Component> tooltipLines = new ArrayList<>();
80+
// Add name of the block because the annotation overrides the usual tooltip
81+
var member = shape.simpleMembers.get(entry.getKey());
82+
tooltipLines.add(member.getPreviewState().getBlock().getName());
83+
84+
tooltipLines.add(MIText.AcceptsHatches.text());
85+
var flags = entry.getValue();
86+
for (var type : HatchType.values()) {
87+
if (flags.allows(type)) {
88+
tooltipLines.add(Component.literal("- ").append(type.description()));
89+
}
90+
}
91+
annotation.setTooltip(new TextTooltip(tooltipLines));
92+
scene.addAnnotation(annotation);
93+
}
94+
}
95+
}

src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/DistillationTowerBlockEntity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ public int getMaxFluidOutputs() {
9898
return activeShape.getActiveShapeIndex() + 1;
9999
}
100100

101+
@Override
102+
public ShapeTemplate getBigShape() {
103+
return shapeTemplates[shapeTemplates.length - 1];
104+
}
105+
101106
public static void registerReiShapes() {
102107
for (int i = 0; i < shapeTemplates.length; ++i) {
103108
ReiMachineRecipes.registerMultiblockShape("distillation_tower", shapeTemplates[i], "" + i);

src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/ElectricBlastFurnaceBlockEntity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ public boolean isOverdriving() {
160160
return overdrive.shouldOverdrive();
161161
}
162162

163+
@Override
164+
public ShapeTemplate getBigShape() {
165+
return shapeTemplates[shapeTemplates.length - 1];
166+
}
167+
163168
public static void registerReiShapes() {
164169
for (int i = 0; i < shapeTemplates.length; ++i) {
165170
ReiMachineRecipes.registerMultiblockShape("electric_blast_furnace", shapeTemplates[i], tiers.get(i).coilBlockId.getPath());

src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/LargeTankMultiblockBlockEntity.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ public ShapeTemplate getActiveShape() {
206206
return activeShape.getActiveShape();
207207
}
208208

209+
@Override
210+
public ShapeTemplate getBigShape() {
211+
// Largest tank
212+
return shapeTemplates[shapeTemplates.length - 1];
213+
}
214+
209215
@Override
210216
public FluidStorageComponent getFluidStorageComponent() {
211217
return fluidStorage;

src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/NuclearReactorMultiblockBlockEntity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ public ShapeTemplate getActiveShape() {
129129
return activeShape.getActiveShape();
130130
}
131131

132+
@Override
133+
public ShapeTemplate getBigShape() {
134+
return shapeTemplates[shapeTemplates.length - 1];
135+
}
136+
132137
@Override
133138
protected void onRematch(ShapeMatcher shapeMatcher) {
134139
nuclearGrid = null;

src/main/java/aztech/modern_industrialization/machines/multiblocks/HatchType.java

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,42 @@
2323
*/
2424
package aztech.modern_industrialization.machines.multiblocks;
2525

26+
import aztech.modern_industrialization.MI;
27+
import aztech.modern_industrialization.MIText;
28+
import com.mojang.datafixers.util.Either;
29+
import net.minecraft.core.registries.BuiltInRegistries;
30+
import net.minecraft.network.chat.MutableComponent;
31+
import net.minecraft.resources.ResourceLocation;
32+
2633
public enum HatchType {
27-
ITEM_INPUT(0),
28-
ITEM_OUTPUT(1),
29-
FLUID_INPUT(2),
30-
FLUID_OUTPUT(3),
31-
ENERGY_INPUT(4),
32-
ENERGY_OUTPUT(5),
33-
NUCLEAR_ITEM(6),
34-
NUCLEAR_FLUID(7),
35-
LARGE_TANK(8);
34+
ITEM_INPUT(0, MIText.ItemInputHatch),
35+
ITEM_OUTPUT(1, MIText.ItemOutputHatch),
36+
FLUID_INPUT(2, MIText.FluidInputHatch),
37+
FLUID_OUTPUT(3, MIText.FluidOutputHatch),
38+
ENERGY_INPUT(4, MIText.EnergyInputHatch),
39+
ENERGY_OUTPUT(5, MIText.EnergyOutputHatch),
40+
NUCLEAR_ITEM(6, "nuclear_item_hatch"),
41+
NUCLEAR_FLUID(7, "nuclear_fluid_hatch"),
42+
LARGE_TANK(8, "large_tank_hatch");
3643

3744
private final int id;
45+
private final Either<MIText, ResourceLocation> descriptionOrBlockId;
46+
47+
HatchType(int id, MIText description) {
48+
this.id = id;
49+
this.descriptionOrBlockId = Either.left(description);
50+
}
3851

39-
HatchType(int id) {
52+
HatchType(int id, String blockId) {
4053
this.id = id;
54+
this.descriptionOrBlockId = Either.right(MI.id(blockId));
4155
}
4256

4357
public int getId() {
4458
return id;
4559
}
60+
61+
public MutableComponent description() {
62+
return descriptionOrBlockId.map(MIText::text, id -> BuiltInRegistries.BLOCK.get(id).getName());
63+
}
4664
}

src/main/java/aztech/modern_industrialization/machines/multiblocks/MultiblockMachineBlockEntity.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ public void setRemoved() {
105105

106106
public abstract ShapeTemplate getActiveShape();
107107

108+
/**
109+
* Can be used in the guide book to show an example of a big shape.
110+
*/
111+
public ShapeTemplate getBigShape() {
112+
return getActiveShape();
113+
}
114+
108115
public OrientationComponent getOrientation() {
109116
return orientation;
110117
}

0 commit comments

Comments
 (0)