aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api')
-rw-r--r--src/main/java/gregtech/api/interfaces/IHatchElement.java15
-rw-r--r--src/main/java/gregtech/api/util/GT_HatchElementBuilder.java23
2 files changed, 38 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/interfaces/IHatchElement.java b/src/main/java/gregtech/api/interfaces/IHatchElement.java
index 09f3385729..482b7899ab 100644
--- a/src/main/java/gregtech/api/interfaces/IHatchElement.java
+++ b/src/main/java/gregtech/api/interfaces/IHatchElement.java
@@ -6,10 +6,12 @@ import java.util.List;
import java.util.function.BiPredicate;
import java.util.function.ToLongFunction;
+import net.minecraft.block.Block;
import net.minecraftforge.common.util.ForgeDirection;
import com.google.common.collect.ImmutableList;
import com.gtnewhorizon.structurelib.structure.IStructureElement;
+import com.gtnewhorizon.structurelib.structure.StructureUtility;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
@@ -64,9 +66,21 @@ public interface IHatchElement<T> {
.casingIndex(aCasingIndex)
.dot(aDot)
.continueIfSuccess()
+ .exclusive()
.build();
}
+ default <T2 extends T> IStructureElement<T2> newAnyOrCasing(int aCasingIndex, int aDot, Block casingBlock,
+ int casingMeta) {
+ if (aCasingIndex < 0 || aDot < 0) throw new IllegalArgumentException();
+ return GT_StructureUtility.<T2>buildHatchAdder()
+ .anyOf(this)
+ .casingIndex(aCasingIndex)
+ .dot(aDot)
+ .continueIfSuccess()
+ .buildAndChain(StructureUtility.ofBlock(casingBlock, casingMeta));
+ }
+
default <T2 extends T> IStructureElement<T2> newAny(int aCasingIndex, int aDot, ForgeDirection... allowedFacings) {
if (aCasingIndex < 0 || aDot < 0) throw new IllegalArgumentException();
return GT_StructureUtility.<T2>buildHatchAdder()
@@ -75,6 +89,7 @@ public interface IHatchElement<T> {
.dot(aDot)
.continueIfSuccess()
.allowOnly(allowedFacings)
+ .exclusive()
.build();
}
diff --git a/src/main/java/gregtech/api/util/GT_HatchElementBuilder.java b/src/main/java/gregtech/api/util/GT_HatchElementBuilder.java
index 2087ad755c..416edc9c11 100644
--- a/src/main/java/gregtech/api/util/GT_HatchElementBuilder.java
+++ b/src/main/java/gregtech/api/util/GT_HatchElementBuilder.java
@@ -27,6 +27,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import com.gtnewhorizon.structurelib.StructureLibAPI;
+import com.gtnewhorizon.structurelib.alignment.constructable.ChannelDataAccessor;
import com.gtnewhorizon.structurelib.structure.AutoPlaceEnvironment;
import com.gtnewhorizon.structurelib.structure.IItemSource;
import com.gtnewhorizon.structurelib.structure.IStructureElement;
@@ -57,6 +58,7 @@ public class GT_HatchElementBuilder<T> {
private Predicate<? super T> mReject;
private boolean mCacheHint;
private boolean mNoStop;
+ private boolean mExclusive;
private EnumSet<ForgeDirection> mDisallowedDirection = EnumSet.noneOf(ForgeDirection.class);
private GT_HatchElementBuilder() {}
@@ -173,6 +175,19 @@ public class GT_HatchElementBuilder<T> {
// region primitives
+ /**
+ * Mark this hatch element as the only candidate of given structure element. (e.g. muffler hatch on top of EBF)
+ * Currently, this will make the built IStructureElement to ignore gt_no_hatch directive from player
+ *
+ * Do note that {@link #buildAndChain(IStructureElement[])} and its overloads will force the resulting structure
+ * element
+ * to be non-exclusive.
+ */
+ public GT_HatchElementBuilder<T> exclusive() {
+ mExclusive = true;
+ return this;
+ }
+
public GT_HatchElementBuilder<T> adder(IGT_HatchAdder<? super T> aAdder) {
if (aAdder == null) throw new IllegalArgumentException();
mAdder = aAdder;
@@ -360,6 +375,8 @@ public class GT_HatchElementBuilder<T> {
@SuppressWarnings("unchecked")
@SafeVarargs
public final IStructureElementChain<T> buildAndChain(IStructureElement<T>... elements) {
+ // just in case
+ mExclusive = false;
List<IStructureElement<T>> l = new ArrayList<>();
l.add(build());
l.addAll(Arrays.asList(elements));
@@ -462,6 +479,12 @@ public class GT_HatchElementBuilder<T> {
if (!StructureLibAPI.isBlockTriviallyReplaceable(world, x, y, z, env.getActor()))
return PlaceResult.REJECT;
if (mReject != null && mReject.test(t)) return PlaceResult.REJECT;
+ if (ChannelDataAccessor.hasSubChannel(trigger, "gt_no_hatch") && !mExclusive) {
+ String type = getHint();
+ env.getChatter()
+ .accept(new ChatComponentTranslation("GT5U.autoplace.error.no_hatch", type));
+ return PlaceResult.REJECT;
+ }
ItemStack taken = env.getSource()
.takeOne(mHatchItemFilter.apply(t, trigger), true);
if (GT_Utility.isStackInvalid(taken)) {