From 3cf3352e58908b202d3607911e1a4e8f94450061 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Fri, 19 Aug 2022 19:40:34 +0800 Subject: more autoplace utility/fixes (#1245) * allow building multiple anyOf structure elements in same batch * port utility from gt++ * add shouldSkip to hatchClass and hatchIds * minor improvement to DT structure code * pass in trigger stack * add makeshift translation for item hint * fix lcr not having autoplace --- .../gregtech/api/interfaces/IHatchElement.java | 47 +++++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'src/main/java/gregtech/api/interfaces') diff --git a/src/main/java/gregtech/api/interfaces/IHatchElement.java b/src/main/java/gregtech/api/interfaces/IHatchElement.java index 46deb5383c..22dbbdf013 100644 --- a/src/main/java/gregtech/api/interfaces/IHatchElement.java +++ b/src/main/java/gregtech/api/interfaces/IHatchElement.java @@ -1,10 +1,9 @@ package gregtech.api.interfaces; +import com.google.common.collect.ImmutableList; import com.gtnewhorizon.structurelib.structure.IStructureElement; import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_EnhancedMultiBlockBase; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; import gregtech.api.util.GT_StructureUtility; import gregtech.api.util.IGT_HatchAdder; @@ -60,6 +59,7 @@ public interface IHatchElement { .anyOf(this) .casingIndex(aCasingIndex) .dot(aDot) + .continueIfSuccess() .build(); } @@ -70,8 +70,51 @@ public interface IHatchElement { .casingIndex(aCasingIndex) .dot(aDot) .shouldSkip(aShouldSkip) + .continueIfSuccess() .build(); } + + default IHatchElement or(IHatchElement fallback) { + return new HatchElementEither<>(this, fallback); + } +} + +class HatchElementEither implements IHatchElement { + private final IHatchElement first, second; + private ImmutableList> mMteClasses; + private String name; + + HatchElementEither(IHatchElement first, IHatchElement second) { + this.first = first; + this.second = second; + } + + @Override + public List> mteClasses() { + if (mMteClasses == null) + mMteClasses = ImmutableList.>builder() + .addAll(first.mteClasses()) + .addAll(second.mteClasses()) + .build(); + return mMteClasses; + } + + @Override + public IGT_HatchAdder adder() { + return ((t, te, i) -> first.adder().apply(t, te, i) || second.adder().apply(t, te, i)); + } + + @Override + public String name() { + if (name == null) + name = first.name() + " or " + second.name(); + return name; + } + + @Override + public long count(T t) { + return first.count(t) + second.count(t); + } } class HatchElement implements IHatchElement { -- cgit