Skip to content

Commit c2b9576

Browse files
committed
Make structure member use blockstates to store mode and add variable mode
1 parent 24615a7 commit c2b9576

27 files changed

+339
-81
lines changed

src/client/java/aztech/modern_industrialization/gui/structure/StructureMultiblockControllerEditScreen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public boolean charTyped(char codePoint, int modifiers) {
224224
idBox.setResponder(text -> this.updateId());
225225
this.addRenderableWidget(idBox);
226226

227-
casingBox = new EditBox(font, width / 2 - 152, 90, 304, 20, MIText.StructureMultiblockHatchCasing.text()) {
227+
casingBox = new EditBox(font, width / 2 - 152, 90, 304, 20, MIText.StructureMultiblockCasing.text()) {
228228
@Override
229229
public boolean charTyped(char codePoint, int modifiers) {
230230
return ResourceLocation.isAllowedInResourceLocation(codePoint) && super.charTyped(codePoint, modifiers);
@@ -285,7 +285,7 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTi
285285
graphics.drawString(font, MIText.StructureMultiblockStructureName.text(), width / 2 - 152, 40, 0xA0A0A0);
286286

287287
if (casingBox.visible)
288-
graphics.drawString(font, MIText.StructureMultiblockHatchCasing.text(), width / 2 - 152, 80, 0xA0A0A0);
288+
graphics.drawString(font, MIText.StructureMultiblockCasing.text(), width / 2 - 152, 80, 0xA0A0A0);
289289

290290
if (posXBox.visible || posYBox.visible || posZBox.visible)
291291
graphics.drawString(font, Component.translatable("structure_block.position"), width / 2 - 152, 120, 0xA0A0A0);

src/client/java/aztech/modern_industrialization/gui/structure/StructureMultiblockMemberEditScreen.java

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public class StructureMultiblockMemberEditScreen extends Screen {
5959
private Button cancelButton;
6060
private CycleButton<StructureMemberMode> modeButton;
6161

62+
private EditBox nameBox;
63+
6264
private EditBox previewBox;
6365
private EditBox membersBox;
6466

@@ -89,19 +91,34 @@ private Optional<HatchFlags> getHatchFlags() {
8991
private void updateMode(StructureMemberMode mode) {
9092
this.sendToServer();
9193

94+
nameBox.visible = false;
95+
previewBox.visible = false;
96+
membersBox.visible = false;
9297
casingBox.visible = false;
9398
flagsBox.visible = false;
9499

95100
switch (mode) {
96101
case HATCH -> {
102+
previewBox.visible = true;
103+
membersBox.visible = true;
97104
casingBox.visible = true;
98105
flagsBox.visible = true;
99106
}
100107
case SIMPLE -> {
108+
previewBox.visible = true;
109+
membersBox.visible = true;
110+
}
111+
case VARIABLE -> {
112+
nameBox.visible = true;
101113
}
102114
}
103115
}
104116

117+
private void updateName() {
118+
boolean validName = !nameBox.getValue().isEmpty();
119+
nameBox.setTextColor(validName ? VALID_TEXT_COLOR : INVALID_TEXT_COLOR);
120+
}
121+
105122
private void updatePreview() {
106123
boolean validPreview = previewBox.getValue().isEmpty() || this.getPreview().isPresent();
107124
previewBox.setTextColor(validPreview ? VALID_TEXT_COLOR : INVALID_TEXT_COLOR);
@@ -124,6 +141,7 @@ private void updateFlags() {
124141

125142
private void updateAll() {
126143
this.updateMode(member.getMode());
144+
this.updateName();
127145
this.updatePreview();
128146
this.updateMembers();
129147
this.updateCasing();
@@ -139,6 +157,7 @@ private void sendToServer() {
139157
new StructureUpdateMemberPacket(
140158
member.getBlockPos(),
141159
modeButton.getValue(),
160+
nameBox.getValue(),
142161
previewBox.getValue(),
143162
membersBox.getValue(),
144163
casingBox.getValue(),
@@ -161,6 +180,12 @@ protected void init() {
161180
.withInitialValue(member.getMode())
162181
.create(width / 2 - 4 - 150, 185, 50, 20, Component.literal("MODE"), (button, mode) -> this.updateMode(mode)));
163182

183+
nameBox = new EditBox(font, width / 2 - 152, 20, 304, 20, MIText.StructureMultiblockMemberName.text());
184+
nameBox.setMaxLength(Short.MAX_VALUE);
185+
nameBox.setValue(member.getInputName());
186+
nameBox.setResponder(text -> this.updateName());
187+
this.addRenderableWidget(nameBox);
188+
164189
previewBox = new EditBox(font, width / 2 - 152, 20, 304, 20, MIText.StructureMultiblockMemberPreview.text());
165190
previewBox.setMaxLength(Short.MAX_VALUE);
166191
previewBox.setValue(member.getInputPreview());
@@ -173,7 +198,7 @@ protected void init() {
173198
membersBox.setResponder(text -> this.updateMembers());
174199
this.addRenderableWidget(membersBox);
175200

176-
casingBox = new EditBox(font, width / 2 - 152, 100, 304, 20, MIText.StructureMultiblockHatchCasing.text()) {
201+
casingBox = new EditBox(font, width / 2 - 152, 100, 304, 20, MIText.StructureMultiblockCasing.text()) {
177202
@Override
178203
public boolean charTyped(char codePoint, int modifiers) {
179204
return ResourceLocation.isAllowedInResourceLocation(codePoint) && super.charTyped(codePoint, modifiers);
@@ -184,7 +209,7 @@ public boolean charTyped(char codePoint, int modifiers) {
184209
casingBox.setResponder(text -> this.updateCasing());
185210
this.addRenderableWidget(casingBox);
186211

187-
flagsBox = new EditBox(font, width / 2 - 152, 140, 304, 20, MIText.StructureMultiblockHatchFlags.text()) {
212+
flagsBox = new EditBox(font, width / 2 - 152, 140, 304, 20, MIText.StructureMultiblockMemberHatchFlags.text()) {
188213
@Override
189214
public boolean charTyped(char codePoint, int modifiers) {
190215
return (Character.isDigit(codePoint) || Character.isAlphabetic(codePoint) || codePoint == ';' || codePoint == '_')
@@ -203,15 +228,20 @@ public boolean charTyped(char codePoint, int modifiers) {
203228
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
204229
super.render(graphics, mouseX, mouseY, partialTick);
205230

206-
graphics.drawString(font, MIText.StructureMultiblockMemberPreview.text(), width / 2 - 152, 10, 0xA0A0A0);
231+
if (nameBox.visible)
232+
graphics.drawString(font, MIText.StructureMultiblockMemberName.text(), width / 2 - 152, 10, 0xA0A0A0);
233+
234+
if (previewBox.visible)
235+
graphics.drawString(font, MIText.StructureMultiblockMemberPreview.text(), width / 2 - 152, 10, 0xA0A0A0);
207236

208-
graphics.drawString(font, MIText.StructureMultiblockMemberMembers.text(), width / 2 - 152, 50, 0xA0A0A0);
237+
if (membersBox.visible)
238+
graphics.drawString(font, MIText.StructureMultiblockMemberMembers.text(), width / 2 - 152, 50, 0xA0A0A0);
209239

210240
if (casingBox.visible)
211-
graphics.drawString(font, MIText.StructureMultiblockHatchCasing.text(), width / 2 - 152, 90, 0xA0A0A0);
241+
graphics.drawString(font, MIText.StructureMultiblockCasing.text(), width / 2 - 152, 90, 0xA0A0A0);
212242

213243
if (flagsBox.visible)
214-
graphics.drawString(font, MIText.StructureMultiblockHatchFlags.text(), width / 2 - 152, 130, 0xA0A0A0);
244+
graphics.drawString(font, MIText.StructureMultiblockMemberHatchFlags.text(), width / 2 - 152, 130, 0xA0A0A0);
215245

216246
graphics.drawString(font, modeButton.getValue().textInfo(), width / 2 - 4 - 150, 175, 0xA0A0A0);
217247
}
@@ -228,13 +258,15 @@ protected void setInitialFocus() {
228258

229259
@Override
230260
public void resize(Minecraft minecraft, int width, int height) {
261+
String nameBoxValue = nameBox.getValue();
231262
String previewBoxValue = previewBox.getValue();
232263
String membersBoxValue = membersBox.getValue();
233264
String casingBoxValue = casingBox.getValue();
234265
String flagsBoxValue = flagsBox.getValue();
235266

236267
this.init(minecraft, width, height);
237268

269+
nameBox.setValue(nameBoxValue);
238270
previewBox.setValue(previewBoxValue);
239271
membersBox.setValue(membersBoxValue);
240272
casingBox.setValue(casingBoxValue);

src/generated/resources/assets/modern_industrialization/blockstates/structure_multiblock_controller.json

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
{
22
"variants": {
3-
"facing=east": {
3+
"facing=east,mode=load": {
44
"model": "modern_industrialization:block/structure_multiblock_controller",
55
"y": 90
66
},
7-
"facing=north": {
7+
"facing=east,mode=save": {
8+
"model": "modern_industrialization:block/structure_multiblock_controller",
9+
"y": 90
10+
},
11+
"facing=north,mode=load": {
812
"model": "modern_industrialization:block/structure_multiblock_controller"
913
},
10-
"facing=south": {
14+
"facing=north,mode=save": {
15+
"model": "modern_industrialization:block/structure_multiblock_controller"
16+
},
17+
"facing=south,mode=load": {
1118
"model": "modern_industrialization:block/structure_multiblock_controller",
1219
"y": 180
1320
},
14-
"facing=west": {
21+
"facing=south,mode=save": {
22+
"model": "modern_industrialization:block/structure_multiblock_controller",
23+
"y": 180
24+
},
25+
"facing=west,mode=load": {
26+
"model": "modern_industrialization:block/structure_multiblock_controller",
27+
"y": 270
28+
},
29+
"facing=west,mode=save": {
1530
"model": "modern_industrialization:block/structure_multiblock_controller",
1631
"y": 270
1732
}
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
{
22
"variants": {
3-
"": {
4-
"model": "modern_industrialization:block/structure_multiblock_member"
3+
"mode=hatch": {
4+
"model": "modern_industrialization:block/structure_multiblock_member_hatch"
5+
},
6+
"mode=simple": {
7+
"model": "modern_industrialization:block/structure_multiblock_member_simple"
8+
},
9+
"mode=variable": {
10+
"model": "modern_industrialization:block/structure_multiblock_member_variable"
511
}
612
}
713
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,17 +1693,20 @@
16931693
"text.modern_industrialization.SteamDrillProfit": "- Press %s to toggle 3x3 mining.",
16941694
"text.modern_industrialization.SteamDrillToggle": "- Toggle Silk Touch with %s + %s.",
16951695
"text.modern_industrialization.SteamDrillWaterHelp": "- Press %s on still or flowing water to fill.",
1696-
"text.modern_industrialization.StructureMultiblockHatchCasing": "Machine Casing",
1697-
"text.modern_industrialization.StructureMultiblockHatchFlags": "Hatch Flags",
1696+
"text.modern_industrialization.StructureMultiblockCasing": "Machine Casing",
16981697
"text.modern_industrialization.StructureMultiblockLoadFailDoesntExist": "Failed to place the structure. No structure exists as %s.",
16991698
"text.modern_industrialization.StructureMultiblockLoadFailInvalidId": "Failed to place the structure. No id was provided.",
17001699
"text.modern_industrialization.StructureMultiblockLoadSuccess": "Successfully placed the structure %s.",
17011700
"text.modern_industrialization.StructureMultiblockLoadTooltip": "Hold SHIFT to place actual blocks instead of structure blocks.",
1701+
"text.modern_industrialization.StructureMultiblockMemberHatchFlags": "Hatch Flags",
17021702
"text.modern_industrialization.StructureMultiblockMemberMembers": "Members",
17031703
"text.modern_industrialization.StructureMultiblockMemberModeHatch": "Hatch",
17041704
"text.modern_industrialization.StructureMultiblockMemberModeInfoHatch": "Hatch Mode - Include hatches",
17051705
"text.modern_industrialization.StructureMultiblockMemberModeInfoSimple": "Simple Mode - Just a block",
1706+
"text.modern_industrialization.StructureMultiblockMemberModeInfoVariable": "Variable Mode - Filled in at runtime",
17061707
"text.modern_industrialization.StructureMultiblockMemberModeSimple": "Simple",
1708+
"text.modern_industrialization.StructureMultiblockMemberModeVariable": "Variable",
1709+
"text.modern_industrialization.StructureMultiblockMemberName": "Member Name",
17071710
"text.modern_industrialization.StructureMultiblockMemberPreview": "Preview",
17081711
"text.modern_industrialization.StructureMultiblockSaveFailInvalidBounds": "Failed to save structure. The bounds provided are not valid.",
17091712
"text.modern_industrialization.StructureMultiblockSaveFailMisconfiguredBlock": "Failed to save structure. Some blocks are not properly configured.",
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"parent": "minecraft:block/cube_all",
33
"textures": {
4-
"all": "modern_industrialization:block/structure_multiblock_member"
4+
"all": "modern_industrialization:block/structure_multiblock_member_hatch"
55
}
66
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"parent": "minecraft:block/cube_all",
3+
"textures": {
4+
"all": "modern_industrialization:block/structure_multiblock_member_simple"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"parent": "minecraft:block/cube_all",
3+
"textures": {
4+
"all": "modern_industrialization:block/structure_multiblock_member_variable"
5+
}
6+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"parent": "modern_industrialization:block/structure_multiblock_member"
2+
"parent": "modern_industrialization:block/structure_multiblock_member_simple"
33
}

src/main/java/aztech/modern_industrialization/MIBlock.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import net.minecraft.world.level.material.MapColor;
6464
import net.neoforged.bus.api.IEventBus;
6565
import net.neoforged.neoforge.capabilities.Capabilities;
66+
import net.neoforged.neoforge.client.model.generators.ConfiguredModel;
6667
import net.neoforged.neoforge.client.model.generators.ItemModelProvider;
6768
import net.neoforged.neoforge.client.model.generators.ModelFile;
6869
import net.neoforged.neoforge.registries.DeferredRegister;
@@ -152,8 +153,15 @@ public static void init(IEventBus modBus) {
152153
.withBlockConstructor(StructureMultiblockMemberBlock::new)
153154
.withBlockItemConstructor((block, p) -> new BlockItem(block, p.rarity(Rarity.EPIC)))
154155
.withModel((block, gen) -> {
155-
String name = gen.name(block);
156-
gen.simpleBlockWithItem(block, gen.models().cubeAll(name, gen.blockTexture("structure_multiblock_member")));
156+
gen.getVariantBuilder(block).forAllStates(state -> {
157+
var mode = state.getValue(StructureMultiblockMemberBlock.MODE);
158+
String texture = "structure_multiblock_member_" + mode.getSerializedName();
159+
return ConfiguredModel.builder()
160+
.modelFile(gen.models().cubeAll(texture, gen.blockTexture(texture)))
161+
.build();
162+
});
163+
String simpleTexture = "structure_multiblock_member_simple";
164+
gen.simpleBlockItem(block, gen.models().cubeAll(simpleTexture, gen.blockTexture(simpleTexture)));
157165
}));
158166

159167
// Materials

0 commit comments

Comments
 (0)