diff options
Diffstat (limited to 'src')
4 files changed, 40 insertions, 3 deletions
diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_computer.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_computer.java index 12b69eeb47..c3aef39047 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_computer.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_computer.java @@ -9,7 +9,6 @@ import static com.github.technus.tectech.thing.metaTileEntity.multi.base.LedStat import static com.github.technus.tectech.util.CommonValues.MULTI_CHECK_AT; import static com.github.technus.tectech.util.CommonValues.V; import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock; -import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain; import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose; import static gregtech.api.enums.GT_HatchElement.Energy; import static gregtech.api.enums.GT_HatchElement.Maintenance; @@ -115,7 +114,7 @@ public class GT_MetaTileEntity_EM_computer extends GT_MetaTileEntity_MultiblockB .casingIndex(textureOffset + 1) .dot(1) .buildAndChain(ofBlock(sBlockCasingsTT, 1))) - .addElement('E', ofChain(RackHatchElement.INSTANCE.newAny(textureOffset + 3, 2), ofBlock(sBlockCasingsTT, 3))) + .addElement('E', RackHatchElement.INSTANCE.newAnyOrCasing(textureOffset + 3, 2, sBlockCasingsTT, 3)) .build(); // endregion diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_dataBank.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_dataBank.java index 0723dc52de..b084e632d4 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_dataBank.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_EM_dataBank.java @@ -95,7 +95,7 @@ public class GT_MetaTileEntity_EM_dataBank extends GT_MetaTileEntity_MultiblockB DataBankHatches.WirelessOutboundConnector) .casingIndex(textureOffset + 1) .dot(2) - .buildAndChain(DataBankHatches.DataStick.newAny(textureOffset + 1, 2), ofBlock(sBlockCasingsTT, 1))) + .buildAndChain(DataBankHatches.DataStick.newAnyOrCasing(textureOffset + 1, 2, sBlockCasingsTT, 1))) .build(); // endregion 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)) { |