From 54f98cd732f1ce1dc5a8a6ed69490a25d676c8b1 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Fri, 16 Aug 2024 09:14:09 +0800 Subject: makeshift solution of skipping gt hatches (#2881) * makeshift solution of telling structurelib to not place gt hatches * Spotless apply for branch feature/gt-no-hatch for #2881 (#2882) spotlessApply Co-authored-by: GitHub GTNH Actions <> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Martin Robertz --- .../gregtech/api/util/GT_HatchElementBuilder.java | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/main/java/gregtech/api/util') 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 { private Predicate mReject; private boolean mCacheHint; private boolean mNoStop; + private boolean mExclusive; private EnumSet mDisallowedDirection = EnumSet.noneOf(ForgeDirection.class); private GT_HatchElementBuilder() {} @@ -173,6 +175,19 @@ public class GT_HatchElementBuilder { // 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 exclusive() { + mExclusive = true; + return this; + } + public GT_HatchElementBuilder adder(IGT_HatchAdder aAdder) { if (aAdder == null) throw new IllegalArgumentException(); mAdder = aAdder; @@ -360,6 +375,8 @@ public class GT_HatchElementBuilder { @SuppressWarnings("unchecked") @SafeVarargs public final IStructureElementChain buildAndChain(IStructureElement... elements) { + // just in case + mExclusive = false; List> l = new ArrayList<>(); l.add(build()); l.addAll(Arrays.asList(elements)); @@ -462,6 +479,12 @@ public class GT_HatchElementBuilder { 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)) { -- cgit