diff --git a/src/client/java/aztech/modern_industrialization/compat/viewer/usage/MultiblockCategory.java b/src/client/java/aztech/modern_industrialization/compat/viewer/usage/MultiblockCategory.java index b3fb78352f..6d4698e498 100644 --- a/src/client/java/aztech/modern_industrialization/compat/viewer/usage/MultiblockCategory.java +++ b/src/client/java/aztech/modern_industrialization/compat/viewer/usage/MultiblockCategory.java @@ -28,7 +28,8 @@ import aztech.modern_industrialization.MIText; import aztech.modern_industrialization.compat.rei.machines.ReiMachineRecipes; import aztech.modern_industrialization.compat.viewer.abstraction.ViewerCategory; -import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate; +import aztech.modern_industrialization.machines.multiblocks.shape.member.MultiblockMemberState; import java.util.ArrayList; import java.util.Comparator; import java.util.List; @@ -42,7 +43,6 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.RecipeManager; -import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; public class MultiblockCategory extends ViewerCategory { @@ -92,9 +92,10 @@ public Recipe(ResourceLocation controller, ShapeTemplate shapeTemplate, @Nullabl this.controller = BuiltInRegistries.ITEM.get(controller).getDefaultInstance(); SortedMap materials = new TreeMap<>(Comparator.comparing(BuiltInRegistries.ITEM::getKey)); - for (var entry : shapeTemplate.simpleMembers.entrySet()) { - BlockState state = entry.getValue().getPreviewState(); - Item item = state.getBlock().asItem(); + for (var entry : shapeTemplate.members().entrySet()) { + // TODO SWEDZ MULTIBLOCKS: account for nbt + MultiblockMemberState state = entry.getValue().getPreviewState(); + Item item = state.state().getBlock().asItem(); if (item != Items.AIR) { materials.put(item, 1 + materials.getOrDefault(item, 0)); } diff --git a/src/client/java/aztech/modern_industrialization/machines/multiblocks/MultiblockErrorHighlight.java b/src/client/java/aztech/modern_industrialization/machines/multiblocks/MultiblockErrorHighlight.java index 052628310a..83cda8e31a 100644 --- a/src/client/java/aztech/modern_industrialization/machines/multiblocks/MultiblockErrorHighlight.java +++ b/src/client/java/aztech/modern_industrialization/machines/multiblocks/MultiblockErrorHighlight.java @@ -23,6 +23,7 @@ */ package aztech.modern_industrialization.machines.multiblocks; +import aztech.modern_industrialization.machines.multiblocks.shape.member.MultiblockMemberState; import aztech.modern_industrialization.util.RenderHelper; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.ByteBufferBuilder; @@ -32,21 +33,20 @@ import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.core.BlockPos; -import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec3; import net.neoforged.neoforge.client.event.RenderLevelStageEvent; import net.neoforged.neoforge.common.NeoForge; import org.jetbrains.annotations.Nullable; public class MultiblockErrorHighlight { - private static final Map highlightQueue = new HashMap<>(); + private static final Map highlightQueue = new HashMap<>(); private static final MultiBufferSource.BufferSource immediate = MultiBufferSource.immediate(new ByteBufferBuilder(128)); public static void init() { NeoForge.EVENT_BUS.addListener(MultiblockErrorHighlight::end); } - public static void enqueueHighlight(BlockPos pos, @Nullable BlockState state) { + public static void enqueueHighlight(BlockPos pos, @Nullable MultiblockMemberState state) { highlightQueue.put(pos.immutable(), state); } @@ -59,7 +59,7 @@ private static void end(RenderLevelStageEvent event) { var poseStack = event.getPoseStack(); poseStack.pushPose(); poseStack.mulPose(event.getModelViewMatrix()); - for (Map.Entry entry : highlightQueue.entrySet()) { + for (Map.Entry entry : highlightQueue.entrySet()) { poseStack.pushPose(); Vec3 cameraPos = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition(); BlockPos pos = entry.getKey(); @@ -69,11 +69,12 @@ private static void end(RenderLevelStageEvent event) { poseStack.translate(x + 0.25, y + 0.25, z + 0.25); poseStack.scale(0.5f, 0.5f, 0.5f); - BlockState state = entry.getValue(); + MultiblockMemberState state = entry.getValue(); if (state == null) { RenderHelper.drawCube(poseStack, immediate, 1, 50f / 256, 50f / 256, 15728880, OverlayTexture.NO_OVERLAY); } else { - Minecraft.getInstance().getBlockRenderer().renderSingleBlock(state, poseStack, immediate, 15728880, + // TODO SWEDZ MULTIBLOCKS: account for nbt + rotation + Minecraft.getInstance().getBlockRenderer().renderSingleBlock(state.state(), poseStack, immediate, 15728880, OverlayTexture.NO_OVERLAY); } diff --git a/src/client/java/aztech/modern_industrialization/machines/multiblocks/MultiblockMachineBER.java b/src/client/java/aztech/modern_industrialization/machines/multiblocks/MultiblockMachineBER.java index bb06246e7b..88b6b48b70 100644 --- a/src/client/java/aztech/modern_industrialization/machines/multiblocks/MultiblockMachineBER.java +++ b/src/client/java/aztech/modern_industrialization/machines/multiblocks/MultiblockMachineBER.java @@ -27,6 +27,8 @@ import aztech.modern_industrialization.config.MIClientConfig; import aztech.modern_industrialization.machines.MachineBlock; import aztech.modern_industrialization.machines.MachineBlockEntityRenderer; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeMatcher; +import aztech.modern_industrialization.machines.multiblocks.shape.member.HatchMultiblockMember; import aztech.modern_industrialization.util.RenderHelper; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; @@ -68,9 +70,9 @@ public void render(MultiblockMachineBlockEntity be, float tickDelta, PoseStack m matrices.pushPose(); matrices.translate(pos.getX() - be.getBlockPos().getX(), pos.getY() - be.getBlockPos().getY(), pos.getZ() - be.getBlockPos().getZ()); - HatchFlags hatchFlag = matcher.getHatchFlags(pos); - if (hatchType != null) { - if (MIClientConfig.INSTANCE.hatchPlacementOverlay.getAsBoolean() && hatchFlag != null && hatchFlag.allows(hatchType)) { + var member = matcher.getMember(pos); + if (hatchType != null && member instanceof HatchMultiblockMember hatchMember) { + if (MIClientConfig.INSTANCE.hatchPlacementOverlay.getAsBoolean() && hatchMember.hatchFlags().allows(hatchType)) { // Highlight placeable hatches in green matrices.translate(-0.005, -0.005, -0.005); matrices.scale(1.01f, 1.01f, 1.01f); @@ -82,7 +84,7 @@ public void render(MultiblockMachineBlockEntity be, float tickDelta, PoseStack m var existingState = be.getLevel().getBlockState(pos); if (existingState.isAir() || /* approximate check for e.g. grass and snow */ existingState.canBeReplaced()) { // Enqueue state preview - MultiblockErrorHighlight.enqueueHighlight(pos, matcher.getSimpleMember(pos).getPreviewState()); + MultiblockErrorHighlight.enqueueHighlight(pos, matcher.getMember(pos).getPreviewState()); } else { // Enqueue red cube MultiblockErrorHighlight.enqueueHighlight(pos, null); diff --git a/src/main/java/aztech/modern_industrialization/compat/kubejs/machine/RegisterMachinesEventJS.java b/src/main/java/aztech/modern_industrialization/compat/kubejs/machine/RegisterMachinesEventJS.java index 890c50686a..429942d3db 100644 --- a/src/main/java/aztech/modern_industrialization/compat/kubejs/machine/RegisterMachinesEventJS.java +++ b/src/main/java/aztech/modern_industrialization/compat/kubejs/machine/RegisterMachinesEventJS.java @@ -43,7 +43,7 @@ import aztech.modern_industrialization.machines.init.MultiblockMachines; import aztech.modern_industrialization.machines.init.SingleBlockCraftingMachines; import aztech.modern_industrialization.machines.models.MachineCasings; -import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate; import aztech.modern_industrialization.machines.recipe.MachineRecipeType; import dev.latvian.mods.kubejs.event.KubeEvent; import java.util.List; diff --git a/src/main/java/aztech/modern_industrialization/compat/kubejs/machine/ShapeTemplateHelper.java b/src/main/java/aztech/modern_industrialization/compat/kubejs/machine/ShapeTemplateHelper.java index bdd494b350..48399eaf4d 100644 --- a/src/main/java/aztech/modern_industrialization/compat/kubejs/machine/ShapeTemplateHelper.java +++ b/src/main/java/aztech/modern_industrialization/compat/kubejs/machine/ShapeTemplateHelper.java @@ -24,10 +24,11 @@ package aztech.modern_industrialization.compat.kubejs.machine; import aztech.modern_industrialization.machines.models.MachineCasings; -import aztech.modern_industrialization.machines.multiblocks.HatchFlags; import aztech.modern_industrialization.machines.multiblocks.HatchType; -import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate; -import aztech.modern_industrialization.machines.multiblocks.SimpleMember; +import aztech.modern_industrialization.machines.multiblocks.shape.HatchFlags; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate; +import aztech.modern_industrialization.machines.multiblocks.shape.member.MultiblockMember; +import aztech.modern_industrialization.machines.multiblocks.shape.member.SimpleMultiblockMember; import net.minecraft.resources.ResourceLocation; public interface ShapeTemplateHelper { @@ -39,8 +40,8 @@ default ShapeTemplate.Builder startShape(String hatchCasing) { return new ShapeTemplate.Builder(MachineCasings.get(hatchCasing)); } - default SimpleMember memberOfBlock(String blockId) { - return SimpleMember.forBlockId(ResourceLocation.parse(blockId)); + default SimpleMultiblockMember memberOfBlock(String blockId) { + return MultiblockMember.simple(ResourceLocation.parse(blockId)); } default HatchFlags noHatch() { diff --git a/src/main/java/aztech/modern_industrialization/compat/rei/machines/ReiMachineRecipes.java b/src/main/java/aztech/modern_industrialization/compat/rei/machines/ReiMachineRecipes.java index 8d5b412253..a1c869849b 100644 --- a/src/main/java/aztech/modern_industrialization/compat/rei/machines/ReiMachineRecipes.java +++ b/src/main/java/aztech/modern_industrialization/compat/rei/machines/ReiMachineRecipes.java @@ -24,7 +24,7 @@ package aztech.modern_industrialization.compat.rei.machines; import aztech.modern_industrialization.MI; -import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate; import aztech.modern_industrialization.util.Rectangle; import java.util.*; import net.minecraft.resources.ResourceLocation; diff --git a/src/main/java/aztech/modern_industrialization/guidebook/MultiblockShapeCompiler.java b/src/main/java/aztech/modern_industrialization/guidebook/MultiblockShapeCompiler.java index 7c2224cb0f..9cbd39ec38 100644 --- a/src/main/java/aztech/modern_industrialization/guidebook/MultiblockShapeCompiler.java +++ b/src/main/java/aztech/modern_industrialization/guidebook/MultiblockShapeCompiler.java @@ -27,6 +27,7 @@ import aztech.modern_industrialization.machines.MachineBlock; import aztech.modern_industrialization.machines.multiblocks.HatchType; import aztech.modern_industrialization.machines.multiblocks.MultiblockMachineBlockEntity; +import aztech.modern_industrialization.machines.multiblocks.shape.member.HatchMultiblockMember; import guideme.color.SymbolicColor; import guideme.compiler.PageCompiler; import guideme.compiler.tags.MdxAttrs; @@ -68,28 +69,29 @@ public void compile(GuidebookScene scene, PageCompiler compiler, LytErrorSink er // Controller scene.getLevel().setBlockAndUpdate(controllerPos, controller.getRight().defaultBlockState()); // Shape blocks - for (var entry : shape.simpleMembers.entrySet()) { - scene.getLevel().setBlockAndUpdate(entry.getKey().offset(controllerPos), entry.getValue().getPreviewState()); - } - // Annotations for allowed hatches - for (var entry : shape.hatchFlags.entrySet()) { - var minCorner = Vec3.atLowerCornerOf(entry.getKey().offset(controllerPos)); - var annotation = new InWorldBoxAnnotation(minCorner.toVector3f(), minCorner.add(1, 1, 1).toVector3f(), SymbolicColor.GREEN); + for (var entry : shape.members().entrySet()) { + var member = entry.getValue(); + member.getPreviewState().setBlock(scene.getLevel(), entry.getKey().offset(controllerPos)); + + // Annotations for allowed hatches + if (member instanceof HatchMultiblockMember hatchMember) { + var minCorner = Vec3.atLowerCornerOf(entry.getKey().offset(controllerPos)); + var annotation = new InWorldBoxAnnotation(minCorner.toVector3f(), minCorner.add(1, 1, 1).toVector3f(), SymbolicColor.GREEN); - List tooltipLines = new ArrayList<>(); - // Add name of the block because the annotation overrides the usual tooltip - var member = shape.simpleMembers.get(entry.getKey()); - tooltipLines.add(member.getPreviewState().getBlock().getName()); + List tooltipLines = new ArrayList<>(); + // Add name of the block because the annotation overrides the usual tooltip + tooltipLines.add(member.getPreviewState().state().getBlock().getName()); - tooltipLines.add(MIText.AcceptsHatches.text()); - var flags = entry.getValue(); - for (var type : HatchType.values()) { - if (flags.allows(type)) { - tooltipLines.add(Component.literal("- ").append(type.description())); + tooltipLines.add(MIText.AcceptsHatches.text()); + var flags = hatchMember.hatchFlags(); + for (var type : HatchType.values()) { + if (flags.allows(type)) { + tooltipLines.add(Component.literal("- ").append(type.description())); + } } + annotation.setTooltip(new TextTooltip(tooltipLines)); + scene.addAnnotation(annotation); } - annotation.setTooltip(new TextTooltip(tooltipLines)); - scene.addAnnotation(annotation); } } } diff --git a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractCraftingMultiblockBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractCraftingMultiblockBlockEntity.java index dc9e3440e8..876cf72eeb 100644 --- a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractCraftingMultiblockBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractCraftingMultiblockBlockEntity.java @@ -32,8 +32,8 @@ import aztech.modern_industrialization.machines.guicomponents.ReiSlotLocking; import aztech.modern_industrialization.machines.models.MachineModelClientData; import aztech.modern_industrialization.machines.multiblocks.MultiblockMachineBlockEntity; -import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher; -import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeMatcher; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate; import aztech.modern_industrialization.util.Tickable; public abstract class AbstractCraftingMultiblockBlockEntity extends MultiblockMachineBlockEntity implements Tickable, diff --git a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractElectricCraftingMultiblockBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractElectricCraftingMultiblockBlockEntity.java index 5b8a8b0b4a..4d49dcd18f 100644 --- a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractElectricCraftingMultiblockBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/AbstractElectricCraftingMultiblockBlockEntity.java @@ -28,8 +28,8 @@ import aztech.modern_industrialization.machines.components.*; import aztech.modern_industrialization.machines.guicomponents.CraftingMultiblockGui; import aztech.modern_industrialization.machines.multiblocks.HatchBlockEntity; -import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher; -import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeMatcher; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate; import aztech.modern_industrialization.util.Simulation; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/DistillationTowerBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/DistillationTowerBlockEntity.java index 7574197449..ef23bde443 100644 --- a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/DistillationTowerBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/DistillationTowerBlockEntity.java @@ -37,6 +37,9 @@ import aztech.modern_industrialization.machines.init.MachineTier; import aztech.modern_industrialization.machines.models.MachineCasings; import aztech.modern_industrialization.machines.multiblocks.*; +import aztech.modern_industrialization.machines.multiblocks.shape.HatchFlags; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate; +import aztech.modern_industrialization.machines.multiblocks.shape.member.MultiblockMember; import aztech.modern_industrialization.machines.recipe.MachineRecipeType; import java.util.stream.IntStream; @@ -112,8 +115,8 @@ public static void registerReiShapes() { static { shapeTemplates = new ShapeTemplate[MAX_HEIGHT]; - SimpleMember casing = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("clean_stainless_steel_machine_casing"))); - SimpleMember pipe = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("stainless_steel_machine_casing_pipe"))); + var casing = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("clean_stainless_steel_machine_casing"))); + var pipe = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("stainless_steel_machine_casing_pipe"))); HatchFlags bottom = new HatchFlags.Builder().with(HatchType.ENERGY_INPUT, HatchType.FLUID_INPUT).build(); HatchFlags layer = new HatchFlags.Builder().with(HatchType.FLUID_OUTPUT).build(); for (int i = 0; i < MAX_HEIGHT; ++i) { diff --git a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/ElectricBlastFurnaceBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/ElectricBlastFurnaceBlockEntity.java index 41d255f536..2ffbdbf27d 100644 --- a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/ElectricBlastFurnaceBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/ElectricBlastFurnaceBlockEntity.java @@ -37,7 +37,9 @@ import aztech.modern_industrialization.machines.init.MIMachineRecipeTypes; import aztech.modern_industrialization.machines.init.MachineTier; import aztech.modern_industrialization.machines.models.MachineCasings; -import aztech.modern_industrialization.machines.multiblocks.*; +import aztech.modern_industrialization.machines.multiblocks.shape.HatchFlags; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate; +import aztech.modern_industrialization.machines.multiblocks.shape.member.MultiblockMember; import aztech.modern_industrialization.machines.recipe.MachineRecipe; import aztech.modern_industrialization.machines.recipe.MachineRecipeType; import com.google.common.base.Preconditions; @@ -94,8 +96,8 @@ public Component getDisplayName() { for (int i = 0; i < tiers.size(); ++i) { var tier = tiers.get(i); - SimpleMember invarCasings = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("heatproof_machine_casing"))); - SimpleMember coilsBlocks = SimpleMember.forBlockId(tier.coilBlockId()); + var invarCasings = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("heatproof_machine_casing"))); + var coilsBlocks = MultiblockMember.simple(tier.coilBlockId()); HatchFlags ebfHatches = new HatchFlags.Builder().with(ITEM_INPUT, ITEM_OUTPUT, FLUID_INPUT, FLUID_OUTPUT, ENERGY_INPUT).build(); ShapeTemplate ebfShape = new ShapeTemplate.Builder(MachineCasings.HEATPROOF) .add3by3(0, invarCasings, false, ebfHatches) diff --git a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/ElectricCraftingMultiblockBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/ElectricCraftingMultiblockBlockEntity.java index f756b9e561..74c00f75df 100644 --- a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/ElectricCraftingMultiblockBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/ElectricCraftingMultiblockBlockEntity.java @@ -28,7 +28,7 @@ import aztech.modern_industrialization.machines.components.*; import aztech.modern_industrialization.machines.guicomponents.SlotPanel; import aztech.modern_industrialization.machines.init.MachineTier; -import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate; import aztech.modern_industrialization.machines.recipe.MachineRecipeType; public class ElectricCraftingMultiblockBlockEntity extends AbstractElectricCraftingMultiblockBlockEntity implements EnergyListComponentHolder { diff --git a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/FusionReactorBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/FusionReactorBlockEntity.java index 1ebcbb4c88..1157da3060 100644 --- a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/FusionReactorBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/FusionReactorBlockEntity.java @@ -28,7 +28,7 @@ import aztech.modern_industrialization.machines.components.OrientationComponent; import aztech.modern_industrialization.machines.guicomponents.SlotPanel; import aztech.modern_industrialization.machines.init.MIMachineRecipeTypes; -import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate; import aztech.modern_industrialization.machines.recipe.MachineRecipeType; public class FusionReactorBlockEntity extends AbstractElectricCraftingMultiblockBlockEntity implements EnergyListComponentHolder { diff --git a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/GeneratorMultiblockBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/GeneratorMultiblockBlockEntity.java index b190f1f0db..b27b4d37c7 100644 --- a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/GeneratorMultiblockBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/GeneratorMultiblockBlockEntity.java @@ -33,8 +33,8 @@ import aztech.modern_industrialization.machines.models.MachineModelClientData; import aztech.modern_industrialization.machines.multiblocks.HatchBlockEntity; import aztech.modern_industrialization.machines.multiblocks.MultiblockMachineBlockEntity; -import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher; -import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeMatcher; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate; import aztech.modern_industrialization.util.Simulation; import aztech.modern_industrialization.util.Tickable; import java.util.ArrayList; diff --git a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/LargeTankMultiblockBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/LargeTankMultiblockBlockEntity.java index d40ece0ae6..2a5b4af721 100644 --- a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/LargeTankMultiblockBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/LargeTankMultiblockBlockEntity.java @@ -41,6 +41,10 @@ import aztech.modern_industrialization.machines.models.MachineCasings; import aztech.modern_industrialization.machines.models.MachineModelClientData; import aztech.modern_industrialization.machines.multiblocks.*; +import aztech.modern_industrialization.machines.multiblocks.shape.HatchFlags; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeMatcher; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate; +import aztech.modern_industrialization.machines.multiblocks.shape.member.MultiblockMember; import aztech.modern_industrialization.thirdparty.fabrictransfer.api.fluid.FluidVariant; import aztech.modern_industrialization.util.Tickable; import java.util.List; @@ -107,9 +111,10 @@ private static ShapeTemplate buildShape(int index) { int sizeZ = Z_SIZES[getZComponent(index)]; ShapeTemplate.Builder templateBuilder = new ShapeTemplate.Builder(MachineCasings.STEEL); - SimpleMember steelCasing = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("steel_machine_casing"))); - SimpleMember glass = SimpleMember.forBlock(() -> Blocks.GLASS); - HatchFlags hatchFlags = new HatchFlags.Builder().with(HatchType.LARGE_TANK).build(); + var steelCasing = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("steel_machine_casing"))); + var steelHatch = MultiblockMember.hatch(steelCasing, MachineCasings.STEEL, new HatchFlags.Builder().with(HatchType.LARGE_TANK).build()); + var glass = MultiblockMember.simple(() -> Blocks.GLASS); + var glassHatch = MultiblockMember.hatch(glass, MachineCasings.STEEL, new HatchFlags.Builder().with(HatchType.LARGE_TANK).build()); for (int x = -sizeX / 2; x <= sizeX / 2; x++) { for (int y = -1; y < sizeY - 1; y++) { @@ -128,9 +133,9 @@ private static ShapeTemplate buildShape(int index) { } if (x != 0 || y != 0 || z != 0) { if (lim == 1) { - templateBuilder.add(x, y, z, glass, hatchFlags); + templateBuilder.add(x, y, z, glassHatch); } else if (lim >= 2) { - templateBuilder.add(x, y, z, steelCasing, hatchFlags); + templateBuilder.add(x, y, z, steelHatch); } } // TODO ADD AIR EMPTY CONDITION diff --git a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/NuclearReactorMultiblockBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/NuclearReactorMultiblockBlockEntity.java index 59c95cd256..2d78b173f3 100644 --- a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/NuclearReactorMultiblockBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/NuclearReactorMultiblockBlockEntity.java @@ -38,6 +38,10 @@ import aztech.modern_industrialization.machines.models.MachineCasings; import aztech.modern_industrialization.machines.models.MachineModelClientData; import aztech.modern_industrialization.machines.multiblocks.*; +import aztech.modern_industrialization.machines.multiblocks.shape.HatchFlags; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeMatcher; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate; +import aztech.modern_industrialization.machines.multiblocks.shape.member.MultiblockMember; import aztech.modern_industrialization.nuclear.*; import aztech.modern_industrialization.util.Tickable; import java.util.List; @@ -198,8 +202,8 @@ public static void registerReiShapes() { shapeTemplates = new ShapeTemplate[4]; gridLayout = new boolean[4][][]; - SimpleMember casing = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("nuclear_casing"))); - SimpleMember pipe = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("nuclear_alloy_machine_casing_pipe"))); + var casing = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("nuclear_casing"))); + var pipe = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("nuclear_alloy_machine_casing_pipe"))); HatchFlags top = new HatchFlags.Builder().with(HatchType.NUCLEAR_FLUID, HatchType.NUCLEAR_ITEM).build(); for (int i = 0; i < 4; i++) { ShapeTemplate.Builder builder = new ShapeTemplate.Builder(MachineCasings.NUCLEAR); diff --git a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/SteamBoilerMultiblockBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/SteamBoilerMultiblockBlockEntity.java index 3365c06c91..eea07522be 100644 --- a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/SteamBoilerMultiblockBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/SteamBoilerMultiblockBlockEntity.java @@ -35,8 +35,8 @@ import aztech.modern_industrialization.machines.guicomponents.TemperatureBar; import aztech.modern_industrialization.machines.models.MachineModelClientData; import aztech.modern_industrialization.machines.multiblocks.MultiblockMachineBlockEntity; -import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher; -import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeMatcher; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate; import aztech.modern_industrialization.util.Tickable; import java.util.List; import net.minecraft.network.chat.Component; diff --git a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/SteamCraftingMultiblockBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/SteamCraftingMultiblockBlockEntity.java index 025d6c755a..dc101ae6f8 100644 --- a/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/SteamCraftingMultiblockBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/blockentities/multiblocks/SteamCraftingMultiblockBlockEntity.java @@ -30,8 +30,8 @@ import aztech.modern_industrialization.machines.guicomponents.CraftingMultiblockGui; import aztech.modern_industrialization.machines.helper.SteamHelper; import aztech.modern_industrialization.machines.multiblocks.HatchBlockEntity; -import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher; -import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeMatcher; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate; import aztech.modern_industrialization.machines.recipe.MachineRecipeType; import aztech.modern_industrialization.util.Simulation; import java.util.List; diff --git a/src/main/java/aztech/modern_industrialization/machines/components/ActiveShapeComponent.java b/src/main/java/aztech/modern_industrialization/machines/components/ActiveShapeComponent.java index d00a81c592..6719f05fc7 100644 --- a/src/main/java/aztech/modern_industrialization/machines/components/ActiveShapeComponent.java +++ b/src/main/java/aztech/modern_industrialization/machines/components/ActiveShapeComponent.java @@ -25,7 +25,7 @@ import aztech.modern_industrialization.machines.IComponent; import aztech.modern_industrialization.machines.multiblocks.MultiblockMachineBlockEntity; -import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate; import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.util.Mth; diff --git a/src/main/java/aztech/modern_industrialization/machines/components/MultiblockInventoryComponent.java b/src/main/java/aztech/modern_industrialization/machines/components/MultiblockInventoryComponent.java index de74fbaa7f..c10289c955 100644 --- a/src/main/java/aztech/modern_industrialization/machines/components/MultiblockInventoryComponent.java +++ b/src/main/java/aztech/modern_industrialization/machines/components/MultiblockInventoryComponent.java @@ -29,7 +29,7 @@ import aztech.modern_industrialization.inventory.ConfigurableFluidStack; import aztech.modern_industrialization.inventory.ConfigurableItemStack; import aztech.modern_industrialization.machines.multiblocks.HatchBlockEntity; -import aztech.modern_industrialization.machines.multiblocks.ShapeMatcher; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeMatcher; import aztech.modern_industrialization.thirdparty.fabrictransfer.api.storage.TransferVariant; import java.util.ArrayList; import java.util.Comparator; diff --git a/src/main/java/aztech/modern_industrialization/machines/init/MultiblockMachines.java b/src/main/java/aztech/modern_industrialization/machines/init/MultiblockMachines.java index 9fa3bb3763..27c42e3036 100644 --- a/src/main/java/aztech/modern_industrialization/machines/init/MultiblockMachines.java +++ b/src/main/java/aztech/modern_industrialization/machines/init/MultiblockMachines.java @@ -42,9 +42,10 @@ import aztech.modern_industrialization.machines.guicomponents.ProgressBar; import aztech.modern_industrialization.machines.models.MachineCasing; import aztech.modern_industrialization.machines.models.MachineCasings; -import aztech.modern_industrialization.machines.multiblocks.HatchFlags; -import aztech.modern_industrialization.machines.multiblocks.ShapeTemplate; -import aztech.modern_industrialization.machines.multiblocks.SimpleMember; +import aztech.modern_industrialization.machines.multiblocks.shape.HatchFlags; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate; +import aztech.modern_industrialization.machines.multiblocks.shape.member.MultiblockMember; +import aztech.modern_industrialization.machines.multiblocks.shape.member.SimpleMultiblockMember; import aztech.modern_industrialization.machines.recipe.MachineRecipe; import aztech.modern_industrialization.machines.recipe.MachineRecipeType; import aztech.modern_industrialization.util.Rectangle; @@ -86,27 +87,27 @@ public class MultiblockMachines { public static Supplier> FUSION_REACTOR; public static Supplier> PLASMA_TURBINE; - private static SimpleMember invarCasings; + private static SimpleMultiblockMember invarCasings; - private static SimpleMember bronzePlatedBricks; - private static SimpleMember bronzePipe; + private static SimpleMultiblockMember bronzePlatedBricks; + private static SimpleMultiblockMember bronzePipe; - private static SimpleMember frostproofMachineCasing; + private static SimpleMultiblockMember frostproofMachineCasing; - private static SimpleMember stainlessSteelClean; - private static SimpleMember stainlessSteelPipe; + private static SimpleMultiblockMember stainlessSteelClean; + private static SimpleMultiblockMember stainlessSteelPipe; - private static SimpleMember titaniumCasing; - private static SimpleMember titaniumPipe; + private static SimpleMultiblockMember titaniumCasing; + private static SimpleMultiblockMember titaniumPipe; - private static SimpleMember blastProofCasing; + private static SimpleMultiblockMember blastProofCasing; - private static SimpleMember highlyAdvancedHull; - private static SimpleMember fusionChamber; + private static SimpleMultiblockMember highlyAdvancedHull; + private static SimpleMultiblockMember fusionChamber; - private static SimpleMember plasmaHandlingIridium; - private static SimpleMember iridiumPipe; + private static SimpleMultiblockMember plasmaHandlingIridium; + private static SimpleMultiblockMember iridiumPipe; private static final HatchFlags fluidInputs = new HatchFlags.Builder().with(FLUID_INPUT).build(); private static final HatchFlags energyOutput = new HatchFlags.Builder().with(ENERGY_OUTPUT).build(); @@ -114,7 +115,7 @@ public class MultiblockMachines { private static void cokeOven() { - SimpleMember bricks = SimpleMember.forBlock(() -> Blocks.BRICKS); + var bricks = MultiblockMember.simple(() -> Blocks.BRICKS); HatchFlags cokeOvenHatches = new HatchFlags.Builder().with(ITEM_INPUT).with(ITEM_OUTPUT).with(FLUID_INPUT).with(FLUID_OUTPUT).build(); ShapeTemplate cokeOvenShape = new ShapeTemplate.Builder(MachineCasings.BRICKS).add3by3Levels(-1, 1, bricks, cokeOvenHatches).build(); COKE_OVEN = MachineRegistrationHelper.registerMachine("Coke Oven", "coke_oven", @@ -123,7 +124,7 @@ private static void cokeOven() { } private static void steamBlastFurnace() { - SimpleMember fireclayBricks = SimpleMember.forBlock(MIBlock.BLOCK_FIRE_CLAY_BRICKS); + var fireclayBricks = MultiblockMember.simple(MIBlock.BLOCK_FIRE_CLAY_BRICKS); HatchFlags sbfHatches = new HatchFlags.Builder().with(ITEM_INPUT, ITEM_OUTPUT, FLUID_INPUT, FLUID_OUTPUT).build(); ShapeTemplate sbfShape = new ShapeTemplate.Builder(MachineCasings.FIREBRICKS).add3by3Levels(-1, 2, fireclayBricks, sbfHatches).build(); STEAM_BLAST_FURNACE = MachineRegistrationHelper.registerMachine("Steam Blast Furnace", "steam_blast_furnace", @@ -200,8 +201,8 @@ private static void steamBoilers() { } private static void quarries() { - SimpleMember steelCasing = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("steel_machine_casing"))); - SimpleMember steelPipe = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("steel_machine_casing_pipe"))); + var steelCasing = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("steel_machine_casing"))); + var steelPipe = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("steel_machine_casing_pipe"))); HatchFlags quarryHatchFlags = new HatchFlags.Builder().with(ITEM_INPUT, FLUID_INPUT, ITEM_OUTPUT).build(); HatchFlags quarryElectricHatchFlags = new HatchFlags.Builder().with(ITEM_INPUT, ITEM_OUTPUT, ENERGY_INPUT).build(); @@ -220,7 +221,7 @@ private static void quarries() { quarryShapeBuilder.add(0, 4, 1, steelCasing, null); quarryElectricShapeBuilder.add(0, 4, 1, steelCasing, null); - SimpleMember chain = SimpleMember.verticalChain(); + var chain = MultiblockMember.verticalChain(); for (int y = 0; y <= 3; y++) { quarryShapeBuilder.add(0, y, 1, chain, null); @@ -243,9 +244,9 @@ private static void quarries() { } private static void oilDrillingRig() { - SimpleMember steelCasing = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("steel_machine_casing"))); - SimpleMember steelPipe = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("steel_machine_casing_pipe"))); - SimpleMember chain = SimpleMember.verticalChain(); + var steelCasing = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("steel_machine_casing"))); + var steelPipe = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("steel_machine_casing_pipe"))); + var chain = MultiblockMember.verticalChain(); HatchFlags hatchFlags = new HatchFlags.Builder().with(ITEM_INPUT).with(FLUID_OUTPUT).with(ENERGY_INPUT).build(); ShapeTemplate oilDrillingRigShape = new ShapeTemplate.LayeredBuilder(MachineCasings.STEEL, new String[][] { @@ -316,7 +317,7 @@ private static void largeDieselGenerator() { ReiMachineRecipes.registerMultiblockShape("large_diesel_generator", largeDieselGeneratorShape); } - private static ShapeTemplate largeTurbineShape(MachineCasing mainCasing, SimpleMember casing, SimpleMember pipe) { + private static ShapeTemplate largeTurbineShape(MachineCasing mainCasing, SimpleMultiblockMember casing, SimpleMultiblockMember pipe) { ShapeTemplate.Builder largeTurbineBuilder = new ShapeTemplate.Builder(mainCasing); for (int z = 0; z < 4; z++) { for (int x = -1; x <= 1; x++) { @@ -395,7 +396,7 @@ private static void heatExchanger() { private static void pressurizer() { ShapeTemplate.Builder pressurizeShapeBuilder = new ShapeTemplate.Builder(MachineCasings.TITANIUM); for (int y = -1; y < 3; y++) { - SimpleMember member = (y == -1 || y == 2) ? titaniumCasing : titaniumPipe; + var member = (y == -1 || y == 2) ? titaniumCasing : titaniumPipe; HatchFlags flag = null; if (y == -1) { flag = new HatchFlags.Builder().with(ENERGY_INPUT, FLUID_OUTPUT).build(); @@ -550,27 +551,27 @@ private static void plasmaTurbine() { public static void init() { - invarCasings = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("heatproof_machine_casing"))); + invarCasings = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("heatproof_machine_casing"))); - bronzePlatedBricks = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("bronze_plated_bricks"))); - bronzePipe = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("bronze_machine_casing_pipe"))); + bronzePlatedBricks = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("bronze_plated_bricks"))); + bronzePipe = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("bronze_machine_casing_pipe"))); - frostproofMachineCasing = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("frostproof_machine_casing"))); + frostproofMachineCasing = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("frostproof_machine_casing"))); - stainlessSteelClean = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("clean_stainless_steel_machine_casing"))); - stainlessSteelPipe = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("stainless_steel_machine_casing_pipe"))); + stainlessSteelClean = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("clean_stainless_steel_machine_casing"))); + stainlessSteelPipe = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("stainless_steel_machine_casing_pipe"))); - titaniumCasing = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("solid_titanium_machine_casing"))); - titaniumPipe = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("titanium_machine_casing_pipe"))); + titaniumCasing = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("solid_titanium_machine_casing"))); + titaniumPipe = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("titanium_machine_casing_pipe"))); - blastProofCasing = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("blastproof_casing"))); + blastProofCasing = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("blastproof_casing"))); - highlyAdvancedHull = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("highly_advanced_machine_hull"))); - fusionChamber = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("fusion_chamber"))); + highlyAdvancedHull = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("highly_advanced_machine_hull"))); + fusionChamber = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("fusion_chamber"))); - plasmaHandlingIridium = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("plasma_handling_iridium_machine_casing"))); - iridiumPipe = SimpleMember.forBlock(MIBlock.BLOCK_DEFINITIONS.get(MI.id("iridium_machine_casing_pipe"))); + plasmaHandlingIridium = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("plasma_handling_iridium_machine_casing"))); + iridiumPipe = MultiblockMember.simple(MIBlock.BLOCK_DEFINITIONS.get(MI.id("iridium_machine_casing_pipe"))); cokeOven(); steamBlastFurnace(); diff --git a/src/main/java/aztech/modern_industrialization/machines/multiblocks/MultiblockMachineBlockEntity.java b/src/main/java/aztech/modern_industrialization/machines/multiblocks/MultiblockMachineBlockEntity.java index ecf53a1d60..772fd3ca43 100644 --- a/src/main/java/aztech/modern_industrialization/machines/multiblocks/MultiblockMachineBlockEntity.java +++ b/src/main/java/aztech/modern_industrialization/machines/multiblocks/MultiblockMachineBlockEntity.java @@ -28,6 +28,8 @@ import aztech.modern_industrialization.machines.components.OrientationComponent; import aztech.modern_industrialization.machines.components.ShapeValidComponent; import aztech.modern_industrialization.machines.gui.MachineGuiParameters; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeMatcher; +import aztech.modern_industrialization.machines.multiblocks.shape.ShapeTemplate; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; import net.minecraft.world.phys.BlockHitResult; diff --git a/src/main/java/aztech/modern_industrialization/machines/multiblocks/SimpleMember.java b/src/main/java/aztech/modern_industrialization/machines/multiblocks/SimpleMember.java deleted file mode 100644 index 7abc15b2e5..0000000000 --- a/src/main/java/aztech/modern_industrialization/machines/multiblocks/SimpleMember.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2020 Azercoco & Technici4n - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package aztech.modern_industrialization.machines.multiblocks; - -import java.util.Objects; -import java.util.function.Supplier; -import net.minecraft.core.Direction; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.RotatedPillarBlock; -import net.minecraft.world.level.block.state.BlockState; - -/** - * The representation of a simple logic-less member that is part of a shape, - * e.g. a casing. - */ -public interface SimpleMember { - boolean matchesState(BlockState state); - - BlockState getPreviewState(); - - static SimpleMember forBlock(Supplier block) { - Objects.requireNonNull(block); - - return new SimpleMember() { - @Override - public boolean matchesState(BlockState state) { - return state.is(block.get()); - } - - @Override - public BlockState getPreviewState() { - return block.get().defaultBlockState(); - } - }; - } - - static SimpleMember forBlockId(ResourceLocation id) { - return forBlock(() -> BuiltInRegistries.BLOCK.get(id)); - } - - static SimpleMember forBlockState(BlockState state) { - Objects.requireNonNull(state); - - return new SimpleMember() { - @Override - public boolean matchesState(BlockState state2) { - return state == state2; - } - - @Override - public BlockState getPreviewState() { - return state; - } - }; - } - - static SimpleMember verticalChain() { - return new SimpleMember() { - @Override - public boolean matchesState(BlockState state) { - return state.is(Blocks.CHAIN) && state.getValue(RotatedPillarBlock.AXIS) == Direction.Axis.Y; - } - - @Override - public BlockState getPreviewState() { - return Blocks.CHAIN.defaultBlockState().setValue(RotatedPillarBlock.AXIS, Direction.Axis.Y); - } - }; - } -} diff --git a/src/main/java/aztech/modern_industrialization/machines/multiblocks/HatchFlags.java b/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/HatchFlags.java similarity index 93% rename from src/main/java/aztech/modern_industrialization/machines/multiblocks/HatchFlags.java rename to src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/HatchFlags.java index 821096a07b..5a55d32f28 100644 --- a/src/main/java/aztech/modern_industrialization/machines/multiblocks/HatchFlags.java +++ b/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/HatchFlags.java @@ -21,7 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package aztech.modern_industrialization.machines.multiblocks; +package aztech.modern_industrialization.machines.multiblocks.shape; + +import aztech.modern_industrialization.machines.multiblocks.HatchType; public class HatchFlags { public static final HatchFlags NO_HATCH = new Builder().build(); diff --git a/src/main/java/aztech/modern_industrialization/machines/multiblocks/ShapeMatcher.java b/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/ShapeMatcher.java similarity index 80% rename from src/main/java/aztech/modern_industrialization/machines/multiblocks/ShapeMatcher.java rename to src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/ShapeMatcher.java index 23dfae24b5..7e1eb30fd2 100644 --- a/src/main/java/aztech/modern_industrialization/machines/multiblocks/ShapeMatcher.java +++ b/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/ShapeMatcher.java @@ -21,10 +21,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package aztech.modern_industrialization.machines.multiblocks; +package aztech.modern_industrialization.machines.multiblocks.shape; import static net.minecraft.core.Direction.*; +import aztech.modern_industrialization.machines.multiblocks.HatchBlockEntity; +import aztech.modern_industrialization.machines.multiblocks.shape.member.HatchMultiblockMember; +import aztech.modern_industrialization.machines.multiblocks.shape.member.MultiblockMember; import aztech.modern_industrialization.machines.multiblocks.world.ChunkEventListener; import aztech.modern_industrialization.machines.multiblocks.world.ChunkEventListeners; import java.util.*; @@ -43,14 +46,12 @@ public class ShapeMatcher implements ChunkEventListener { public ShapeMatcher(Level world, BlockPos controllerPos, Direction controllerDirection, ShapeTemplate template) { this.controllerPos = controllerPos; this.template = template; - this.simpleMembers = toWorldPos(controllerPos, controllerDirection, template.simpleMembers); - this.hatchFlags = toWorldPos(controllerPos, controllerDirection, template.hatchFlags); + this.members = toWorldPos(controllerPos, controllerDirection, template.members()); } protected final BlockPos controllerPos; protected final ShapeTemplate template; - protected final Map simpleMembers; - protected final Map hatchFlags; + protected final Map members; private boolean needsRematch = true; private boolean matchSuccessful = false; @@ -82,16 +83,11 @@ protected static Map toWorldPos(BlockPos controllerPos, Directi } public Set getPositions() { - return new HashSet<>(simpleMembers.keySet()); + return new HashSet<>(members.keySet()); } - public SimpleMember getSimpleMember(BlockPos pos) { - return Objects.requireNonNull(simpleMembers.get(pos)); - } - - @Nullable - public HatchFlags getHatchFlags(BlockPos pos) { - return hatchFlags.get(pos); + public MultiblockMember getMember(BlockPos pos) { + return Objects.requireNonNull(members.get(pos)); } public List getMatchedHatches() { @@ -112,18 +108,19 @@ public void unlinkHatches() { * Return true if there was a match, and append matched hatches to the list if * it's not null. */ - public boolean matches(BlockPos pos, Level world, @Nullable List hatches) { - SimpleMember simpleMember = simpleMembers.get(pos); - if (simpleMember == null) + public boolean matches(BlockPos pos, Level world, @Nullable List matchedHatches) { + var member = members.get(pos); + if (member == null) return false; + // TODO SWEDZ MULTIBLOCKS: account for nbt + rotation BlockState state = world.getBlockState(pos); - if (simpleMember.matchesState(state)) + if (member.matchesState(state)) return true; BlockEntity be = world.getBlockEntity(pos); - if (be instanceof HatchBlockEntity hatch) { - HatchFlags flags = hatchFlags.get(pos); + if (be instanceof HatchBlockEntity hatch && member instanceof HatchMultiblockMember hatchMember) { + HatchFlags flags = hatchMember.hatchFlags(); if (flags != null && flags.allows(hatch.getHatchType()) && !hatch.isMatched()) { if (matchedHatches != null) { matchedHatches.add(hatch); @@ -151,7 +148,7 @@ public void rematch(Level world) { unlinkHatches(); matchSuccessful = true; - for (BlockPos pos : simpleMembers.keySet()) { + for (BlockPos pos : members.keySet()) { // TODO: check if the chunk is loaded if (!matches(pos, world, matchedHatches)) { @@ -166,7 +163,11 @@ public void rematch(Level world) { matchedHatches.clear(); } else { for (HatchBlockEntity hatch : matchedHatches) { - hatch.link(template.hatchCasing); + var member = members.get(hatch.getBlockPos()); + if (!(member instanceof HatchMultiblockMember hatchMember)) { + throw new IllegalStateException("Cannot match hatch to non-hatch multiblock member"); + } + hatch.link(hatchMember.casing()); } } @@ -175,7 +176,7 @@ public void rematch(Level world) { public Set getSpannedChunks() { Set spannedChunks = new HashSet<>(); - for (BlockPos pos : simpleMembers.keySet()) { + for (BlockPos pos : members.keySet()) { spannedChunks.add(new ChunkPos(pos)); } return spannedChunks; @@ -196,10 +197,10 @@ public void unregisterListeners(Level world) { public int buildMultiblock(Level level) { int setBlocks = 0; - for (var entry : simpleMembers.entrySet()) { + for (var entry : members.entrySet()) { var current = level.getBlockState(entry.getKey()); if (!entry.getValue().matchesState(current)) { - level.setBlockAndUpdate(entry.getKey(), entry.getValue().getPreviewState()); + entry.getValue().getPreviewState().setBlock(level, entry.getKey()); ++setBlocks; } } @@ -209,7 +210,7 @@ public int buildMultiblock(Level level) { @Override public void onBlockUpdate(BlockPos pos) { - if (simpleMembers.containsKey(pos)) { + if (members.containsKey(pos)) { needsRematch = true; } } diff --git a/src/main/java/aztech/modern_industrialization/machines/multiblocks/ShapeTemplate.java b/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/ShapeTemplate.java similarity index 66% rename from src/main/java/aztech/modern_industrialization/machines/multiblocks/ShapeTemplate.java rename to src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/ShapeTemplate.java index 4f3fa8a2ac..20a39c388e 100644 --- a/src/main/java/aztech/modern_industrialization/machines/multiblocks/ShapeTemplate.java +++ b/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/ShapeTemplate.java @@ -21,36 +21,61 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package aztech.modern_industrialization.machines.multiblocks; +package aztech.modern_industrialization.machines.multiblocks.shape; +import aztech.modern_industrialization.MI; import aztech.modern_industrialization.machines.models.MachineCasing; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import aztech.modern_industrialization.machines.multiblocks.shape.member.MultiblockMember; +import aztech.modern_industrialization.machines.multiblocks.shape.member.SimpleMultiblockMember; +import java.util.*; import net.minecraft.core.BlockPos; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; import org.jetbrains.annotations.Nullable; /** * An immutable description of a multiblock shape. */ -public class ShapeTemplate { - public final Map simpleMembers = new HashMap<>(); - public final Map hatchFlags = new HashMap<>(); - public final MachineCasing hatchCasing; +@EventBusSubscriber(modid = MI.ID, bus = EventBusSubscriber.Bus.MOD) +public final class ShapeTemplate { + private static final List templates = new ArrayList<>(); - private ShapeTemplate(MachineCasing hatchCasing) { - this.hatchCasing = hatchCasing; + private final Map members = new HashMap<>(); + + private ShapeTemplate() { + templates.add(this); + } + + public Map members() { + return Collections.unmodifiableMap(members); + } + + /** + * Forces all lazy block states in structures to get loaded during startup as soon as blocks are in the registry. + * This prevents any delay later where we otherwise would need to be parsing json elements during play. It also + * ensures that we get consistent results (e.g. if a file changes during play). + */ + @SubscribeEvent + private static void onSetup(FMLCommonSetupEvent event) { + for (ShapeTemplate template : templates) { + for (var member : template.members().values()) { + member.forceLoad(); + } + } + MI.LOGGER.info("Initialized {} multiblock shapes", templates.size()); } public static class Builder { private final ShapeTemplate template; + private final MachineCasing hatchCasing; public Builder(MachineCasing hatchCasing) { - template = new ShapeTemplate(hatchCasing); + template = new ShapeTemplate(); + this.hatchCasing = hatchCasing; } - public Builder add3by3Levels(int minY, int maxY, SimpleMember member, @Nullable HatchFlags flags) { + public ShapeTemplate.Builder add3by3Levels(int minY, int maxY, SimpleMultiblockMember member, @Nullable HatchFlags flags) { for (int y = minY; y <= maxY; ++y) { add3by3(y, member, y != minY, (y == minY || y == maxY) ? flags : null); } @@ -58,7 +83,7 @@ public Builder add3by3Levels(int minY, int maxY, SimpleMember member, @Nullable return this; } - public Builder add3by3LevelsRoofed(int minY, int maxY, SimpleMember member, @Nullable HatchFlags flags) { + public ShapeTemplate.Builder add3by3LevelsRoofed(int minY, int maxY, SimpleMultiblockMember member, @Nullable HatchFlags flags) { for (int y = minY; y <= maxY; ++y) { add3by3(y, member, y != minY && y != maxY, (y == minY || y == maxY) ? flags : null); } @@ -66,20 +91,18 @@ public Builder add3by3LevelsRoofed(int minY, int maxY, SimpleMember member, @Nul return this; } - public Builder add(int x, int y, int z, SimpleMember member, @Nullable HatchFlags flags) { + public ShapeTemplate.Builder add(int x, int y, int z, SimpleMultiblockMember member, @Nullable HatchFlags flags) { + member = flags == null ? member : MultiblockMember.hatch(member, hatchCasing, flags); BlockPos pos = new BlockPos(x, y, z); - template.simpleMembers.put(pos, member); - if (flags != null) { - template.hatchFlags.put(pos, flags); - } + template.members.put(pos, member); return this; } - public Builder add(int x, int y, int z, SimpleMember member) { + public ShapeTemplate.Builder add(int x, int y, int z, SimpleMultiblockMember member) { return add(x, y, z, member, null); } - public Builder add3by3(int y, SimpleMember member, boolean hollow, @Nullable HatchFlags flags) { + public ShapeTemplate.Builder add3by3(int y, SimpleMultiblockMember member, boolean hollow, @Nullable HatchFlags flags) { for (int x = -1; x <= 1; x++) { for (int z = 0; z <= 2; z++) { if (hollow && x == 0 && z == 1) { @@ -91,10 +114,9 @@ public Builder add3by3(int y, SimpleMember member, boolean hollow, @Nullable Hat return this; } - public Builder remove(int x, int y, int z) { + public ShapeTemplate.Builder remove(int x, int y, int z) { BlockPos pos = new BlockPos(x, y, z); - template.simpleMembers.remove(pos); - template.hatchFlags.remove(pos); + template.members.remove(pos); return this; } @@ -108,15 +130,12 @@ public static class LayeredBuilder { private final ShapeTemplate.Builder innerBuilder; private final String[][] layers; private final Set missingKeys = new HashSet<>(); - private final Map keyDefinitions = new HashMap<>(); + private final Map keyDefinitions = new HashMap<>(); private int iController, jController, kController; - private record KeyDefinition(SimpleMember member, @Nullable HatchFlags flags) { - } - public LayeredBuilder(MachineCasing hatchCasing, String[][] layers) { - innerBuilder = new Builder(hatchCasing); + innerBuilder = new ShapeTemplate.Builder(hatchCasing); // Find layout size if (layers.length == 0) { @@ -164,15 +183,16 @@ public LayeredBuilder(MachineCasing hatchCasing, String[][] layers) { this.layers = layers; } - public LayeredBuilder key(char key, SimpleMember member, @Nullable HatchFlags flags) { + public ShapeTemplate.LayeredBuilder key(char key, SimpleMultiblockMember member, @Nullable HatchFlags flags) { if (keyDefinitions.containsKey(key)) { throw new IllegalArgumentException("Key '%c' was already defined".formatted(key)); } if (!missingKeys.contains(key)) { throw new IllegalArgumentException("Key '%c' it not part of the shape layers".formatted(key)); } + member = flags == null ? member : MultiblockMember.hatch(member, innerBuilder.hatchCasing, flags); missingKeys.remove(key); - keyDefinitions.put(key, new KeyDefinition(member, flags)); + keyDefinitions.put(key, member); return this; } @@ -186,12 +206,12 @@ public ShapeTemplate build() { for (int k = 0; k < layers[i][j].length(); ++k) { char c = layers[i][j].charAt(k); if (c != ' ' && c != '#') { - KeyDefinition def = keyDefinitions.get(c); + var member = keyDefinitions.get(c); int iAdjusted = i - iController; int jAdjusted = j - jController; int kAdjusted = k - kController; - innerBuilder.add(kAdjusted, jAdjusted, -iAdjusted, def.member, def.flags); + innerBuilder.add(kAdjusted, jAdjusted, -iAdjusted, member); } } } diff --git a/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/member/HatchMultiblockMember.java b/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/member/HatchMultiblockMember.java new file mode 100644 index 0000000000..493bb17569 --- /dev/null +++ b/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/member/HatchMultiblockMember.java @@ -0,0 +1,63 @@ +/* + * MIT License + * + * Copyright (c) 2020 Azercoco & Technici4n + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package aztech.modern_industrialization.machines.multiblocks.shape.member; + +import aztech.modern_industrialization.machines.models.MachineCasing; +import aztech.modern_industrialization.machines.multiblocks.shape.HatchFlags; +import aztech.modern_industrialization.machines.multiblocks.shape.test.MultiblockMemberTest; +import java.util.List; +import java.util.Objects; + +public class HatchMultiblockMember extends SimpleMultiblockMember { + private final MachineCasing casing; + private final HatchFlags hatchFlags; + + public HatchMultiblockMember(MultiblockMemberState preview, List tests, MachineCasing casing, HatchFlags hatchFlags) { + super(preview, tests); + Objects.requireNonNull(casing); + Objects.requireNonNull(hatchFlags); + this.casing = casing; + this.hatchFlags = hatchFlags; + } + + public MachineCasing casing() { + return casing; + } + + public HatchFlags hatchFlags() { + return hatchFlags; + } + + @Override + public boolean equals(Object o) { + if (o instanceof HatchMultiblockMember other && this.getClass() == other.getClass()) { + return preview.equals(other.preview) && + // Ensures the lists are equal ignoring order + tests.containsAll(other.tests) && other.tests.containsAll(tests) && + casing.equals(other.casing) && + hatchFlags.equals(other.hatchFlags); + } + return false; + } +} diff --git a/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/member/MultiblockMember.java b/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/member/MultiblockMember.java new file mode 100644 index 0000000000..43d0322280 --- /dev/null +++ b/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/member/MultiblockMember.java @@ -0,0 +1,93 @@ +/* + * MIT License + * + * Copyright (c) 2020 Azercoco & Technici4n + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package aztech.modern_industrialization.machines.multiblocks.shape.member; + +import aztech.modern_industrialization.machines.models.MachineCasing; +import aztech.modern_industrialization.machines.multiblocks.shape.HatchFlags; +import aztech.modern_industrialization.machines.multiblocks.shape.test.BlockMultiblockMemberTest; +import aztech.modern_industrialization.machines.multiblocks.shape.test.MultiblockMemberTest; +import aztech.modern_industrialization.machines.multiblocks.shape.test.StateMultiblockMemberTest; +import java.util.List; +import java.util.function.Supplier; +import net.minecraft.core.Direction; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.ChainBlock; +import net.minecraft.world.level.block.RotatedPillarBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.neoforged.neoforge.common.util.Lazy; + +// TODO SWEDZ MULTIBLOCKS: remove methods that become irrelevant once structures have been implemented fully and we are +// done making multiblocks using code +public abstract class MultiblockMember { + public static SimpleMultiblockMember simple(MultiblockMemberState preview, List tests) { + return new SimpleMultiblockMember(preview, tests); + } + + public static SimpleMultiblockMember simple(Supplier block) { + return simple(new MultiblockMemberState(Lazy.of(() -> block.get().defaultBlockState())), + List.of(new BlockMultiblockMemberTest(Lazy.of(block)))); + } + + public static SimpleMultiblockMember simple(ResourceLocation blockId) { + return simple(() -> BuiltInRegistries.BLOCK.get(blockId)); + } + + public static SimpleMultiblockMember simple(BlockState state) { + var memberState = new MultiblockMemberState(Lazy.of(() -> state)); + return simple(memberState, List.of(new StateMultiblockMemberTest(memberState))); + } + + public static SimpleMultiblockMember verticalChain() { + var chainState = new MultiblockMemberState( + Lazy.of(() -> Blocks.CHAIN.defaultBlockState().setValue(RotatedPillarBlock.AXIS, Direction.Axis.Y))); + var chainStateWaterlogged = new MultiblockMemberState(Lazy.of( + () -> Blocks.CHAIN.defaultBlockState().setValue(RotatedPillarBlock.AXIS, Direction.Axis.Y).setValue(ChainBlock.WATERLOGGED, true))); + return MultiblockMember.simple(chainState, List.of(new StateMultiblockMemberTest(List.of(chainState, chainStateWaterlogged)))); + } + + public static HatchMultiblockMember hatch(MultiblockMemberState preview, List tests, MachineCasing casing, + HatchFlags hatchFlags) { + return new HatchMultiblockMember(preview, tests, casing, hatchFlags); + } + + public static HatchMultiblockMember hatch(SimpleMultiblockMember parent, MachineCasing casing, HatchFlags hatchFlags) { + return new HatchMultiblockMember(parent.preview(), parent.tests(), casing, hatchFlags); + } + + public abstract void forceLoad(); + + // TODO SWEDZ MULTIBLOCKS: account for nbt + public abstract boolean matchesState(BlockState state); + + public abstract MultiblockMemberState getPreviewState(); + + /** + * It is required that {@link Object#equals(Object)} be implemented so that codecs can reliably identify + * differences between types. + */ + public abstract boolean equals(Object o); +} diff --git a/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/member/MultiblockMemberState.java b/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/member/MultiblockMemberState.java new file mode 100644 index 0000000000..322c5cb789 --- /dev/null +++ b/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/member/MultiblockMemberState.java @@ -0,0 +1,61 @@ +/* + * MIT License + * + * Copyright (c) 2020 Azercoco & Technici4n + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package aztech.modern_industrialization.machines.multiblocks.shape.member; + +import net.minecraft.commands.arguments.blocks.BlockStateParser; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import net.neoforged.neoforge.common.util.Lazy; + +/** + *

+ * A specific member state represented as a {@link BlockState}. Used for previews in the hologram and recipe + * category, as well as for representing such data in a string for users to write/read. + *

+ * + *

+ * The {@link BlockState} is stored lazily so that instances can be created before all blocks are registered. This + * allows us to load multiblock structure files on startup without any problems. + *

+ */ +public record MultiblockMemberState(Lazy lazyState) { + public MultiblockMemberState(BlockState state) { + this(Lazy.of(() -> state)); + } + + public MultiblockMemberState(BlockStateParser.BlockResult result) { + this(Lazy.of(result::blockState)); + } + + public BlockState state() { + return lazyState.get(); + } + + // TODO SWEDZ MULTIBLOCKS: account for nbt + rotation + // TODO SWEDZ MULTIBLOCKS: boolean field for if we want the structure block + public void setBlock(Level level, BlockPos pos) { + level.setBlockAndUpdate(pos, this.state()); + } +} diff --git a/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/member/SimpleMultiblockMember.java b/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/member/SimpleMultiblockMember.java new file mode 100644 index 0000000000..4accdf2222 --- /dev/null +++ b/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/member/SimpleMultiblockMember.java @@ -0,0 +1,83 @@ +/* + * MIT License + * + * Copyright (c) 2020 Azercoco & Technici4n + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package aztech.modern_industrialization.machines.multiblocks.shape.member; + +import aztech.modern_industrialization.machines.multiblocks.shape.test.MultiblockMemberTest; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import net.minecraft.world.level.block.state.BlockState; + +public class SimpleMultiblockMember extends MultiblockMember { + protected final MultiblockMemberState preview; + protected final List tests; + + public SimpleMultiblockMember(MultiblockMemberState preview, List tests) { + Objects.requireNonNull(preview); + Objects.requireNonNull(tests); + this.preview = preview; + this.tests = Collections.unmodifiableList(tests); + } + + public MultiblockMemberState preview() { + return preview; + } + + public List tests() { + return tests; + } + + @Override + public void forceLoad() { + preview.state(); + for (var test : tests) { + test.forceLoad(); + } + } + + @Override + public boolean matchesState(BlockState state) { + for (var test : tests) { + if (test.matchesState(state)) { + return true; + } + } + return false; + } + + @Override + public MultiblockMemberState getPreviewState() { + return preview; + } + + @Override + public boolean equals(Object o) { + if (o instanceof SimpleMultiblockMember other && this.getClass() == other.getClass()) { + return preview.equals(other.preview) && + // Ensures the lists are equal ignoring order + tests.containsAll(other.tests) && other.tests.containsAll(tests); + } + return false; + } +} diff --git a/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/test/BlockMultiblockMemberTest.java b/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/test/BlockMultiblockMemberTest.java new file mode 100644 index 0000000000..913545332a --- /dev/null +++ b/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/test/BlockMultiblockMemberTest.java @@ -0,0 +1,54 @@ +/* + * MIT License + * + * Copyright (c) 2020 Azercoco & Technici4n + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package aztech.modern_industrialization.machines.multiblocks.shape.test; + +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.neoforged.neoforge.common.util.Lazy; + +public class BlockMultiblockMemberTest extends MultiblockMemberTest { + private final Lazy block; + + public BlockMultiblockMemberTest(Lazy block) { + this.block = block; + } + + @Override + public void forceLoad() { + block.get(); + } + + @Override + public boolean matchesState(BlockState state) { + return state.is(block.get()); + } + + @Override + public boolean equals(Object o) { + if (o instanceof BlockMultiblockMemberTest other) { + return block.equals(other.block); + } + return false; + } +} diff --git a/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/test/MultiblockMemberTest.java b/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/test/MultiblockMemberTest.java new file mode 100644 index 0000000000..26df3b6af6 --- /dev/null +++ b/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/test/MultiblockMemberTest.java @@ -0,0 +1,38 @@ +/* + * MIT License + * + * Copyright (c) 2020 Azercoco & Technici4n + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package aztech.modern_industrialization.machines.multiblocks.shape.test; + +import net.minecraft.world.level.block.state.BlockState; + +public abstract class MultiblockMemberTest { + public abstract void forceLoad(); + + public abstract boolean matchesState(BlockState state); + + /** + * It is required that {@link Object#equals(Object)} be implemented so that codecs can reliably identify + * differences between types. + */ + public abstract boolean equals(Object o); +} diff --git a/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/test/StateMultiblockMemberTest.java b/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/test/StateMultiblockMemberTest.java new file mode 100644 index 0000000000..3a80daf7f2 --- /dev/null +++ b/src/main/java/aztech/modern_industrialization/machines/multiblocks/shape/test/StateMultiblockMemberTest.java @@ -0,0 +1,67 @@ +/* + * MIT License + * + * Copyright (c) 2020 Azercoco & Technici4n + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package aztech.modern_industrialization.machines.multiblocks.shape.test; + +import aztech.modern_industrialization.machines.multiblocks.shape.member.MultiblockMemberState; +import java.util.Collections; +import java.util.List; +import net.minecraft.world.level.block.state.BlockState; + +public class StateMultiblockMemberTest extends MultiblockMemberTest { + private final List states; + + public StateMultiblockMemberTest(List states) { + this.states = Collections.unmodifiableList(states); + } + + public StateMultiblockMemberTest(MultiblockMemberState state) { + this(List.of(state)); + } + + @Override + public void forceLoad() { + for (var state : states) { + state.state(); + } + } + + @Override + public boolean matchesState(BlockState state) { + for (var other : states) { + if (state == other.state()) { + return true; + } + } + return false; + } + + @Override + public boolean equals(Object o) { + if (o instanceof StateMultiblockMemberTest other) { + // Ensures the lists are equal ignoring order + return states.containsAll(other.states) && other.states.containsAll(states); + } + return false; + } +}