Skip to content

Commit ff4580c

Browse files
committed
Rework multiblock shape internals in preparation for future changes
1 parent 6f9bcd3 commit ff4580c

33 files changed

+625
-261
lines changed

src/client/java/aztech/modern_industrialization/compat/viewer/usage/MultiblockCategory.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
import aztech.modern_industrialization.MIText;
2929
import aztech.modern_industrialization.compat.rei.machines.ReiMachineRecipes;
3030
import aztech.modern_industrialization.compat.viewer.abstraction.ViewerCategory;
31-
import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate;
31+
import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate;
32+
import aztech.modern_industrialization.machines.multiblocks.shape.member.MultiblockMemberState;
3233
import java.util.ArrayList;
3334
import java.util.Comparator;
3435
import java.util.List;
@@ -42,7 +43,6 @@
4243
import net.minecraft.world.item.ItemStack;
4344
import net.minecraft.world.item.Items;
4445
import net.minecraft.world.item.crafting.RecipeManager;
45-
import net.minecraft.world.level.block.state.BlockState;
4646
import org.jetbrains.annotations.Nullable;
4747

4848
public class MultiblockCategory extends ViewerCategory<MultiblockCategory.Recipe> {
@@ -92,9 +92,10 @@ public Recipe(ResourceLocation controller, ShapeTemplate shapeTemplate, @Nullabl
9292
this.controller = BuiltInRegistries.ITEM.get(controller).getDefaultInstance();
9393
SortedMap<Item, Integer> materials = new TreeMap<>(Comparator.comparing(BuiltInRegistries.ITEM::getKey));
9494

95-
for (var entry : shapeTemplate.simpleMembers.entrySet()) {
96-
BlockState state = entry.getValue().getPreviewState();
97-
Item item = state.getBlock().asItem();
95+
for (var entry : shapeTemplate.members().entrySet()) {
96+
// TODO SWEDZ MULTIBLOCKS: account for nbt
97+
MultiblockMemberState state = entry.getValue().getPreviewState();
98+
Item item = state.blockState().getBlock().asItem();
9899
if (item != Items.AIR) {
99100
materials.put(item, 1 + materials.getOrDefault(item, 0));
100101
}

src/client/java/aztech/modern_industrialization/machines/multiblocks/MultiblockErrorHighlight.java

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

26+
import aztech.modern_industrialization.machines.multiblocks.shape.member.MultiblockMemberState;
2627
import aztech.modern_industrialization.util.RenderHelper;
2728
import com.mojang.blaze3d.systems.RenderSystem;
2829
import com.mojang.blaze3d.vertex.ByteBufferBuilder;
@@ -32,21 +33,20 @@
3233
import net.minecraft.client.renderer.MultiBufferSource;
3334
import net.minecraft.client.renderer.texture.OverlayTexture;
3435
import net.minecraft.core.BlockPos;
35-
import net.minecraft.world.level.block.state.BlockState;
3636
import net.minecraft.world.phys.Vec3;
3737
import net.neoforged.neoforge.client.event.RenderLevelStageEvent;
3838
import net.neoforged.neoforge.common.NeoForge;
3939
import org.jetbrains.annotations.Nullable;
4040

4141
public class MultiblockErrorHighlight {
42-
private static final Map<BlockPos, @Nullable BlockState> highlightQueue = new HashMap<>();
42+
private static final Map<BlockPos, @Nullable MultiblockMemberState> highlightQueue = new HashMap<>();
4343
private static final MultiBufferSource.BufferSource immediate = MultiBufferSource.immediate(new ByteBufferBuilder(128));
4444

4545
public static void init() {
4646
NeoForge.EVENT_BUS.addListener(MultiblockErrorHighlight::end);
4747
}
4848

49-
public static void enqueueHighlight(BlockPos pos, @Nullable BlockState state) {
49+
public static void enqueueHighlight(BlockPos pos, @Nullable MultiblockMemberState state) {
5050
highlightQueue.put(pos.immutable(), state);
5151
}
5252

@@ -59,7 +59,7 @@ private static void end(RenderLevelStageEvent event) {
5959
var poseStack = event.getPoseStack();
6060
poseStack.pushPose();
6161
poseStack.mulPose(event.getModelViewMatrix());
62-
for (Map.Entry<BlockPos, @Nullable BlockState> entry : highlightQueue.entrySet()) {
62+
for (Map.Entry<BlockPos, @Nullable MultiblockMemberState> entry : highlightQueue.entrySet()) {
6363
poseStack.pushPose();
6464
Vec3 cameraPos = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition();
6565
BlockPos pos = entry.getKey();
@@ -69,11 +69,12 @@ private static void end(RenderLevelStageEvent event) {
6969
poseStack.translate(x + 0.25, y + 0.25, z + 0.25);
7070
poseStack.scale(0.5f, 0.5f, 0.5f);
7171

72-
BlockState state = entry.getValue();
72+
MultiblockMemberState state = entry.getValue();
7373
if (state == null) {
7474
RenderHelper.drawCube(poseStack, immediate, 1, 50f / 256, 50f / 256, 15728880, OverlayTexture.NO_OVERLAY);
7575
} else {
76-
Minecraft.getInstance().getBlockRenderer().renderSingleBlock(state, poseStack, immediate, 15728880,
76+
// TODO SWEDZ MULTIBLOCKS: account for nbt + rotation
77+
Minecraft.getInstance().getBlockRenderer().renderSingleBlock(state.blockState(), poseStack, immediate, 15728880,
7778
OverlayTexture.NO_OVERLAY);
7879
}
7980

src/client/java/aztech/modern_industrialization/machines/multiblocks/MultiblockMachineBER.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import aztech.modern_industrialization.config.MIClientConfig;
2828
import aztech.modern_industrialization.machines.MachineBlock;
2929
import aztech.modern_industrialization.machines.MachineBlockEntityRenderer;
30+
import aztech.modern_industrialization.machines.multiblocks.shape.ShapeMatcher;
31+
import aztech.modern_industrialization.machines.multiblocks.shape.member.HatchMultiblockMember;
3032
import aztech.modern_industrialization.util.RenderHelper;
3133
import com.mojang.blaze3d.vertex.PoseStack;
3234
import net.minecraft.client.Minecraft;
@@ -68,21 +70,21 @@ public void render(MultiblockMachineBlockEntity be, float tickDelta, PoseStack m
6870
matrices.pushPose();
6971
matrices.translate(pos.getX() - be.getBlockPos().getX(), pos.getY() - be.getBlockPos().getY(), pos.getZ() - be.getBlockPos().getZ());
7072

71-
HatchFlags hatchFlag = matcher.getHatchFlags(pos);
72-
if (hatchType != null) {
73-
if (MIClientConfig.INSTANCE.hatchPlacementOverlay.getAsBoolean() && hatchFlag != null && hatchFlag.allows(hatchType)) {
73+
var member = matcher.getMember(pos);
74+
if (hatchType != null && member instanceof HatchMultiblockMember hatchMember) {
75+
if (MIClientConfig.INSTANCE.hatchPlacementOverlay.getAsBoolean() && hatchMember.hatchFlags().allows(hatchType)) {
7476
// Highlight placeable hatches in green
7577
matrices.translate(-0.005, -0.005, -0.005);
7678
matrices.scale(1.01f, 1.01f, 1.01f);
7779
RenderHelper.drawOverlay(matrices, vcp, overlay);
7880
}
7981
}
8082
if (drawHighlights) {
81-
if (!matcher.matches(pos, be.getLevel(), null)) {
83+
if (!matcher.matches(pos, be.getLevel())) {
8284
var existingState = be.getLevel().getBlockState(pos);
8385
if (existingState.isAir() || /* approximate check for e.g. grass and snow */ existingState.canBeReplaced()) {
8486
// Enqueue state preview
85-
MultiblockErrorHighlight.enqueueHighlight(pos, matcher.getSimpleMember(pos).getPreviewState());
87+
MultiblockErrorHighlight.enqueueHighlight(pos, matcher.getMember(pos).getPreviewState());
8688
} else {
8789
// Enqueue red cube
8890
MultiblockErrorHighlight.enqueueHighlight(pos, null);

src/main/java/aztech/modern_industrialization/compat/kubejs/machine/RegisterMachinesEventJS.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import aztech.modern_industrialization.machines.init.MultiblockMachines;
4444
import aztech.modern_industrialization.machines.init.SingleBlockCraftingMachines;
4545
import aztech.modern_industrialization.machines.models.MachineCasings;
46-
import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate;
46+
import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate;
4747
import aztech.modern_industrialization.machines.recipe.MachineRecipeType;
4848
import dev.latvian.mods.kubejs.event.KubeEvent;
4949
import java.util.List;

src/main/java/aztech/modern_industrialization/compat/kubejs/machine/ShapeTemplateHelper.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424
package aztech.modern_industrialization.compat.kubejs.machine;
2525

2626
import aztech.modern_industrialization.machines.models.MachineCasings;
27-
import aztech.modern_industrialization.machines.multiblocks.HatchFlags;
2827
import aztech.modern_industrialization.machines.multiblocks.HatchType;
29-
import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate;
30-
import aztech.modern_industrialization.machines.multiblocks.SimpleMember;
28+
import aztech.modern_industrialization.machines.multiblocks.shape.HatchFlags;
29+
import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate;
30+
import aztech.modern_industrialization.machines.multiblocks.shape.member.MultiblockMember;
31+
import aztech.modern_industrialization.machines.multiblocks.shape.member.SimpleMultiblockMember;
3132
import net.minecraft.resources.ResourceLocation;
3233

3334
public interface ShapeTemplateHelper {
@@ -39,8 +40,8 @@ default ShapeTemplate.Builder startShape(String hatchCasing) {
3940
return new ShapeTemplate.Builder(MachineCasings.get(hatchCasing));
4041
}
4142

42-
default SimpleMember memberOfBlock(String blockId) {
43-
return SimpleMember.forBlockId(ResourceLocation.parse(blockId));
43+
default SimpleMultiblockMember memberOfBlock(String blockId) {
44+
return MultiblockMember.simple(ResourceLocation.parse(blockId));
4445
}
4546

4647
default HatchFlags noHatch() {

src/main/java/aztech/modern_industrialization/compat/rei/machines/ReiMachineRecipes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
package aztech.modern_industrialization.compat.rei.machines;
2525

2626
import aztech.modern_industrialization.MI;
27-
import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate;
27+
import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate;
2828
import aztech.modern_industrialization.util.Rectangle;
2929
import java.util.*;
3030
import net.minecraft.resources.ResourceLocation;

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import aztech.modern_industrialization.machines.MachineBlock;
2828
import aztech.modern_industrialization.machines.multiblocks.HatchType;
2929
import aztech.modern_industrialization.machines.multiblocks.MultiblockMachineBlockEntity;
30+
import aztech.modern_industrialization.machines.multiblocks.shape.member.HatchMultiblockMember;
3031
import guideme.color.SymbolicColor;
3132
import guideme.compiler.PageCompiler;
3233
import guideme.compiler.tags.MdxAttrs;
@@ -68,28 +69,29 @@ public void compile(GuidebookScene scene, PageCompiler compiler, LytErrorSink er
6869
// Controller
6970
scene.getLevel().setBlockAndUpdate(controllerPos, controller.getRight().defaultBlockState());
7071
// 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);
72+
for (var entry : shape.members().entrySet()) {
73+
var member = entry.getValue();
74+
member.getPreviewState().setBlock(scene.getLevel(), entry.getKey().offset(controllerPos));
75+
76+
// Annotations for allowed hatches
77+
if (member instanceof HatchMultiblockMember hatchMember) {
78+
var minCorner = Vec3.atLowerCornerOf(entry.getKey().offset(controllerPos));
79+
var annotation = new InWorldBoxAnnotation(minCorner.toVector3f(), minCorner.add(1, 1, 1).toVector3f(), SymbolicColor.GREEN);
7880

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());
81+
List<Component> tooltipLines = new ArrayList<>();
82+
// Add name of the block because the annotation overrides the usual tooltip
83+
tooltipLines.add(member.getPreviewState().blockState().getBlock().getName());
8384

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()));
85+
tooltipLines.add(MIText.AcceptsHatches.text());
86+
var flags = hatchMember.hatchFlags();
87+
for (var type : HatchType.values()) {
88+
if (flags.allows(type)) {
89+
tooltipLines.add(Component.literal("- ").append(type.description()));
90+
}
8991
}
92+
annotation.setTooltip(new TextTooltip(tooltipLines));
93+
scene.addAnnotation(annotation);
9094
}
91-
annotation.setTooltip(new TextTooltip(tooltipLines));
92-
scene.addAnnotation(annotation);
9395
}
9496
}
9597
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
import aztech.modern_industrialization.machines.guicomponents.ReiSlotLocking;
3333
import aztech.modern_industrialization.machines.models.MachineModelClientData;
3434
import aztech.modern_industrialization.machines.multiblocks.MultiblockMachineBlockEntity;
35-
import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher;
36-
import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate;
35+
import aztech.modern_industrialization.machines.multiblocks.shape.ShapeMatcher;
36+
import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate;
3737
import aztech.modern_industrialization.util.Tickable;
3838

3939
public abstract class AbstractCraftingMultiblockBlockEntity extends MultiblockMachineBlockEntity implements Tickable,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import aztech.modern_industrialization.machines.components.*;
2929
import aztech.modern_industrialization.machines.guicomponents.CraftingMultiblockGui;
3030
import aztech.modern_industrialization.machines.multiblocks.HatchBlockEntity;
31-
import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher;
32-
import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate;
31+
import aztech.modern_industrialization.machines.multiblocks.shape.ShapeMatcher;
32+
import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate;
3333
import aztech.modern_industrialization.util.Simulation;
3434
import java.util.ArrayList;
3535
import java.util.List;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
import aztech.modern_industrialization.machines.init.MachineTier;
3838
import aztech.modern_industrialization.machines.models.MachineCasings;
3939
import aztech.modern_industrialization.machines.multiblocks.*;
40+
import aztech.modern_industrialization.machines.multiblocks.shape.HatchFlags;
41+
import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate;
42+
import aztech.modern_industrialization.machines.multiblocks.shape.member.MultiblockMember;
4043
import aztech.modern_industrialization.machines.recipe.MachineRecipeType;
4144
import java.util.stream.IntStream;
4245

@@ -112,8 +115,8 @@ public static void registerReiShapes() {
112115
static {
113116
shapeTemplates = new ShapeTemplate[MAX_HEIGHT];
114117

115-
SimpleMember casing = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("clean_stainless_steel_machine_casing")));
116-
SimpleMember pipe = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("stainless_steel_machine_casing_pipe")));
118+
var casing = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("clean_stainless_steel_machine_casing")));
119+
var pipe = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("stainless_steel_machine_casing_pipe")));
117120
HatchFlags bottom = new HatchFlags.Builder().with(HatchType.ENERGY_INPUT, HatchType.FLUID_INPUT).build();
118121
HatchFlags layer = new HatchFlags.Builder().with(HatchType.FLUID_OUTPUT).build();
119122
for (int i = 0; i < MAX_HEIGHT; ++i) {

0 commit comments

Comments
 (0)