diff options
Diffstat (limited to 'src/main/java/gregtech/api/interfaces')
-rw-r--r-- | src/main/java/gregtech/api/interfaces/IHatchElement.java | 47 |
1 files changed, 45 insertions, 2 deletions
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<T> { .anyOf(this) .casingIndex(aCasingIndex) .dot(aDot) + .continueIfSuccess() .build(); } @@ -70,8 +70,51 @@ public interface IHatchElement<T> { .casingIndex(aCasingIndex) .dot(aDot) .shouldSkip(aShouldSkip) + .continueIfSuccess() .build(); } + + default <T2 extends T> IHatchElement<T2> or(IHatchElement<? super T2> fallback) { + return new HatchElementEither<>(this, fallback); + } +} + +class HatchElementEither<T> implements IHatchElement<T> { + private final IHatchElement<? super T> first, second; + private ImmutableList<? extends Class<? extends IMetaTileEntity>> mMteClasses; + private String name; + + HatchElementEither(IHatchElement<? super T> first, IHatchElement<? super T> second) { + this.first = first; + this.second = second; + } + + @Override + public List<? extends Class<? extends IMetaTileEntity>> mteClasses() { + if (mMteClasses == null) + mMteClasses = ImmutableList.<Class<? extends IMetaTileEntity>>builder() + .addAll(first.mteClasses()) + .addAll(second.mteClasses()) + .build(); + return mMteClasses; + } + + @Override + public IGT_HatchAdder<? super T> 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<T> implements IHatchElement<T> { |