From d75067976a48c7d2335b18c1cf07250a7c9999ef Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Tue, 9 Aug 2022 14:13:53 +0800 Subject: autoplace integration (#1117) --- .../gregtech/api/interfaces/IHatchElement.java | 134 +++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 src/main/java/gregtech/api/interfaces/IHatchElement.java (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 new file mode 100644 index 0000000000..b93cbeacbc --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/IHatchElement.java @@ -0,0 +1,134 @@ +package gregtech.api.interfaces; + +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.util.GT_StructureUtility; +import gregtech.api.util.IGT_HatchAdder; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.function.BiPredicate; +import java.util.function.ToLongFunction; + +public interface IHatchElement> { + List> mteClasses(); + + IGT_HatchAdder adder(); + + String name(); + + long count(T t); + + default IHatchElement withMteClass(Class aClass) { + if (aClass == null) throw new IllegalArgumentException(); + return withMteClasses(Collections.singletonList(aClass)); + } + + @SuppressWarnings("unchecked") // can't set SafeVarargs :( + default IHatchElement withMteClasses(Class... aClasses) { + if (aClasses == null) throw new IllegalArgumentException(); + return withMteClasses(Arrays.asList(aClasses)); + } + + default IHatchElement withMteClasses(List> aClasses) { + if (aClasses == null) throw new IllegalArgumentException(); + return new HatchElement<>(aClasses, null, null, null, this); + } + + default IHatchElement withAdder(IGT_HatchAdder aAdder) { + if (aAdder == null) throw new IllegalArgumentException(); + return new HatchElement<>(null, aAdder, null, null, this); + } + + default IHatchElement withName(String aName) { + if (aName == null) throw new IllegalArgumentException(); + return new HatchElement<>(null, null, aName, null, this); + } + + default IHatchElement withCount(ToLongFunction aCount) { + if (aCount == null) throw new IllegalArgumentException(); + return new HatchElement<>(null, null, null, aCount, this); + } + + default IStructureElement newAny(int aCasingIndex, int aDot) { + if (aCasingIndex < 0 || aDot < 0) throw new IllegalArgumentException(); + return GT_StructureUtility.buildHatchAdder() + .anyOf(this) + .casingIndex(aCasingIndex) + .dot(aDot) + .build(); + } + + default IStructureElement newAny(int aCasingIndex, int aDot, BiPredicate aShouldSkip) { + if (aCasingIndex < 0 || aDot < 0 || aShouldSkip == null) throw new IllegalArgumentException(); + return GT_StructureUtility.buildHatchAdder() + .anyOf(this) + .casingIndex(aCasingIndex) + .dot(aDot) + .shouldSkip(aShouldSkip) + .build(); + } +} + +class HatchElement> implements IHatchElement { + private final List> mClasses; + private final IGT_HatchAdder mAdder; + private final String mName; + private final IHatchElement mBacking; + private final ToLongFunction mCount; + + public HatchElement(List> aMteClasses, IGT_HatchAdder aAdder, String aName, ToLongFunction aCount, IHatchElement aBacking) { + this.mClasses = aMteClasses; + this.mAdder = aAdder; + this.mName = aName; + this.mCount = aCount; + this.mBacking = aBacking; + } + + @Override + public List> mteClasses() { + return mClasses == null ? mBacking.mteClasses() : mClasses; + } + + @Override + public IGT_HatchAdder adder() { + return mAdder == null ? mBacking.adder() : mAdder; + } + + @Override + public String name() { + return mName == null ? mBacking.name() : mName; + } + + @Override + public long count(T t) { + return mCount == null ? mBacking.count(t) : mCount.applyAsLong(t); + } + + @Override + public IHatchElement withMteClasses(List> aClasses) { + if (aClasses == null) throw new IllegalArgumentException(); + return new HatchElement<>(aClasses, mAdder, mName, mCount, mBacking); + } + + @Override + public IHatchElement withAdder(IGT_HatchAdder aAdder) { + if (aAdder == null) throw new IllegalArgumentException(); + return new HatchElement<>(mClasses, aAdder, mName, mCount, mBacking); + } + + @Override + public IHatchElement withName(String aName) { + if (aName == null) throw new IllegalArgumentException(); + return new HatchElement<>(mClasses, mAdder, aName, mCount, mBacking); + } + + @Override + public IHatchElement withCount(ToLongFunction aCount) { + if (aCount == null) throw new IllegalArgumentException(); + return new HatchElement<>(mClasses, mAdder, mName, aCount, mBacking); + } +} -- cgit