aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/gregtech/api/interfaces/IHatchElement.java47
-rw-r--r--src/main/java/gregtech/api/util/GT_HatchElementBuilder.java64
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DistillationTower.java7
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeChemicalReactor.java104
4 files changed, 168 insertions, 54 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> {
diff --git a/src/main/java/gregtech/api/util/GT_HatchElementBuilder.java b/src/main/java/gregtech/api/util/GT_HatchElementBuilder.java
index 91d4d9a156..be6236b94f 100644
--- a/src/main/java/gregtech/api/util/GT_HatchElementBuilder.java
+++ b/src/main/java/gregtech/api/util/GT_HatchElementBuilder.java
@@ -9,14 +9,11 @@ import gnu.trove.set.hash.TIntHashSet;
import gregtech.api.interfaces.IHatchElement;
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.common.blocks.GT_Item_Machines;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
-import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.World;
@@ -24,7 +21,6 @@ import net.minecraft.world.World;
import java.util.*;
import java.util.function.*;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain;
@@ -37,10 +33,11 @@ public class GT_HatchElementBuilder<T> {
private int mCasingIndex = -1;
private int mDot = -1;
private BiPredicate<? super T, ? super IGregTechTileEntity> mShouldSkip;
- private Function<? super T, ? extends Predicate<ItemStack>> mHatchItemFilter;
+ private BiFunction<? super T, ItemStack, ? extends Predicate<ItemStack>> mHatchItemFilter;
private Supplier<String> mHatchItemType;
private Predicate<? super T> mReject, mBuiltinReject;
private boolean mCacheHint;
+ private boolean mNoStop;
private GT_HatchElementBuilder() {
}
@@ -60,7 +57,7 @@ public class GT_HatchElementBuilder<T> {
if (elements == null || elements.length == 0) throw new IllegalArgumentException();
return adder(Arrays.stream(elements).map(e -> e.adder().rebrand()).reduce(IGT_HatchAdder::orElse).get())
.hatchClasses(Arrays.stream(elements).map(IHatchElement::mteClasses).flatMap(Collection::stream).collect(Collectors.toList()))
- .cacheHint(() -> Arrays.stream(elements).map(IHatchElement::name).collect(Collectors.joining(" or ", "of type ", "")));
+ .cacheHint(() -> Arrays.stream(elements).map(IHatchElement::name).sorted().collect(Collectors.joining(" or ", "of type ", "")));
}
/**
@@ -102,7 +99,7 @@ public class GT_HatchElementBuilder<T> {
.collect(Collectors.toList())))
.shouldReject(obj -> elements.entrySet().stream().allMatch(e-> e.getKey().count(obj) >= e.getValue().longValue()))
.shouldSkip((BiPredicate<? super T, ? super IGregTechTileEntity> & Builtin) (c, t) -> t != null && list.stream().anyMatch(clazz -> clazz.isInstance(t.getMetaTileEntity())))
- .cacheHint(() -> elements.keySet().stream().map(IHatchElement::name).collect(Collectors.joining(" or ", "of type ", "")));
+ .cacheHint(() -> elements.keySet().stream().map(IHatchElement::name).sorted().collect(Collectors.joining(" or ", "of type ", "")));
}
//endregion
@@ -151,14 +148,27 @@ public class GT_HatchElementBuilder<T> {
public GT_HatchElementBuilder<T> hatchItemFilter(Function<? super T, ? extends Predicate<ItemStack>> aHatchItemFilter) {
if (aHatchItemFilter == null) throw new IllegalArgumentException();
- mHatchItemFilter = aHatchItemFilter;
+ mHatchItemFilter = (t, s) -> aHatchItemFilter.apply(t);
return this;
}
public GT_HatchElementBuilder<T> hatchItemFilterAnd(Function<? super T, ? extends Predicate<ItemStack>> aHatchItemFilter) {
if (aHatchItemFilter == null) throw new IllegalArgumentException();
- Function<? super T, ? extends Predicate<ItemStack>> tOldFilter = mHatchItemFilter;
- mHatchItemFilter = t -> tOldFilter.apply(t).and(aHatchItemFilter.apply(t));
+ BiFunction<? super T, ItemStack, ? extends Predicate<ItemStack>> tOldFilter = mHatchItemFilter;
+ mHatchItemFilter = (t, s) -> tOldFilter.apply(t, s).and(aHatchItemFilter.apply(t));
+ return this;
+ }
+
+ public GT_HatchElementBuilder<T> hatchItemFilter(BiFunction<? super T, ItemStack, ? extends Predicate<ItemStack>> aHatchItemFilter) {
+ if (aHatchItemFilter == null) throw new IllegalArgumentException();
+ mHatchItemFilter = aHatchItemFilter;
+ return this;
+ }
+
+ public GT_HatchElementBuilder<T> hatchItemFilterAnd(BiFunction<? super T, ItemStack, ? extends Predicate<ItemStack>> aHatchItemFilter) {
+ if (aHatchItemFilter == null) throw new IllegalArgumentException();
+ BiFunction<? super T, ItemStack, ? extends Predicate<ItemStack>> tOldFilter = mHatchItemFilter;
+ mHatchItemFilter = (t, s) -> tOldFilter.apply(t, s).and(aHatchItemFilter.apply(t, s));
return this;
}
@@ -183,12 +193,23 @@ public class GT_HatchElementBuilder<T> {
return this;
}
// endregion
+
+ public GT_HatchElementBuilder<T> continueIfSuccess() {
+ mNoStop = true;
+ return this;
+ }
+
+ public GT_HatchElementBuilder<T> stopIfSuccess() {
+ mNoStop = false;
+ return this;
+ }
// endregion
// region intermediate
public GT_HatchElementBuilder<T> hatchClass(Class<? extends IMetaTileEntity> clazz) {
return hatchItemFilter(c -> is -> clazz.isInstance(GT_Item_Machines.getMetaTileEntity(is)))
- .cacheHint(() -> "of class " + clazz.getSimpleName());
+ .cacheHint(() -> "of class " + clazz.getSimpleName())
+ .shouldSkip((BiPredicate<? super T, ? super IGregTechTileEntity> & Builtin) (c, t) -> clazz.isInstance(t.getMetaTileEntity()));
}
@SafeVarargs
@@ -199,13 +220,14 @@ public class GT_HatchElementBuilder<T> {
public final GT_HatchElementBuilder<T> hatchClasses(List<? extends Class<? extends IMetaTileEntity>> classes) {
List<? extends Class<? extends IMetaTileEntity>> list = new ArrayList<>(classes);
return hatchItemFilter(obj -> GT_StructureUtility.filterByMTEClass(list))
- .cacheHint(() -> list.stream().map(Class::getSimpleName).collect(Collectors.joining(" or ", "of class ", "")))
+ .cacheHint(() -> list.stream().map(Class::getSimpleName).sorted().collect(Collectors.joining(" or ", "of class ", "")))
.shouldSkip((BiPredicate<? super T, ? super IGregTechTileEntity> & Builtin) (c, t) -> t != null && list.stream().anyMatch(clazz -> clazz.isInstance(t.getMetaTileEntity())));
}
public GT_HatchElementBuilder<T> hatchId(int aId) {
return hatchItemFilter(c -> is -> GT_Utility.isStackValid(is) && is.getItem() instanceof GT_Item_Machines && is.getItemDamage() == aId)
- .cacheHint(() -> "of id " + aId);
+ .cacheHint(() -> "of id " + aId)
+ .shouldSkip((BiPredicate<? super T, ? super IGregTechTileEntity> & Builtin) (c, t) -> t != null && t.getMetaTileID() == aId);
}
public GT_HatchElementBuilder<T> hatchIds(int... aIds) {
@@ -213,7 +235,8 @@ public class GT_HatchElementBuilder<T> {
if (aIds.length == 1) return hatchId(aIds[0]);
TIntCollection coll = aIds.length < 16 ? new TIntArrayList(aIds) : new TIntHashSet(aIds);
return hatchItemFilter(c -> is -> GT_Utility.isStackValid(is) && is.getItem() instanceof GT_Item_Machines && coll.contains(is.getItemDamage()))
- .cacheHint(() -> Arrays.stream(coll.toArray()).mapToObj(String::valueOf).collect(Collectors.joining(" or ", "of id ", "")));
+ .cacheHint(() -> Arrays.stream(coll.toArray()).sorted().mapToObj(String::valueOf).collect(Collectors.joining(" or ", "of id ", "")))
+ .shouldSkip((BiPredicate<? super T, ? super IGregTechTileEntity> & Builtin) (c, t) -> t != null && coll.contains(t.getMetaTileID()));
}
//endregion
@@ -276,8 +299,15 @@ public class GT_HatchElementBuilder<T> {
private String getHint() {
if (mHint != null) return mHint;
String tHint = mHatchItemType.get();
- if (mCacheHint)
+ if (tHint == null) return "?";
+ // TODO move this to some .lang instead of half ass it into the crappy gt lang file
+ tHint = GT_LanguageManager.addStringLocalization("Hatch_Type_" + tHint.replace(' ', '_'), tHint);
+ if (mCacheHint) {
mHint = tHint;
+ if (mHint != null)
+ // yeet the getter, since its product is retrieved and cached
+ mHatchItemType = null;
+ }
return tHint;
}
@@ -291,13 +321,13 @@ public class GT_HatchElementBuilder<T> {
if (!StructureLibAPI.isBlockTriviallyReplaceable(world, x, y, z, actor))
return PlaceResult.REJECT;
if (mReject != null && mReject.test(t)) return PlaceResult.REJECT;
- ItemStack taken = s.takeOne(mHatchItemFilter.apply(t), true);
+ ItemStack taken = s.takeOne(mHatchItemFilter.apply(t, trigger), true);
if (GT_Utility.isStackInvalid(taken)) {
String type = getHint();
chatter.accept(new ChatComponentTranslation("GT5U.autoplace.error.no_hatch", type));
return PlaceResult.REJECT;
}
- return StructureUtility.survivalPlaceBlock(taken, ItemStackPredicate.NBTMode.IGNORE, null, true, world, x, y, z, s, actor) == PlaceResult.ACCEPT ? PlaceResult.ACCEPT_STOP : PlaceResult.REJECT;
+ return StructureUtility.survivalPlaceBlock(taken, ItemStackPredicate.NBTMode.IGNORE, null, true, world, x, y, z, s, actor) == PlaceResult.ACCEPT ? (mNoStop ? PlaceResult.ACCEPT : PlaceResult.ACCEPT_STOP) : PlaceResult.REJECT;
}
};
}
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DistillationTower.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DistillationTower.java
index 16bc02eeec..867ffa6d02 100644
--- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DistillationTower.java
+++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_DistillationTower.java
@@ -90,12 +90,6 @@ public class GT_MetaTileEntity_DistillationTower extends GT_MetaTileEntity_Enhan
onElementPass(t -> t.onTopLayerFound(true), ofBlock(GregTech_API.sBlockCasings4, 1)),
isAir()
))
- .addElement('C', ofChain(
- onElementPass(t -> t.onTopLayerFound(false), ofHatchAdder(GT_MetaTileEntity_DistillationTower::addOutputToMachineList, CASING_INDEX, 3)),
- onElementPass(t -> t.onTopLayerFound(false), ofHatchAdder(GT_MetaTileEntity_DistillationTower::addMaintenanceToMachineList, CASING_INDEX, 3)),
- onElementPass(t -> t.onTopLayerFound(true), ofBlock(GregTech_API.sBlockCasings4, 1)),
- isAir()
- ))
.build();
}
@@ -336,6 +330,7 @@ public class GT_MetaTileEntity_DistillationTower extends GT_MetaTileEntity_Enhan
@Override
public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) {
+ if (mMachine) return -1;
mHeight = 0;
int built = survivialBuildPiece(STRUCTURE_PIECE_BASE, stackSize, 1, 0, 0, elementBudget, source, actor, false, true);
if (built >= 0) return built;
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeChemicalReactor.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeChemicalReactor.java
index 8802ef0f3a..54758167f1 100644
--- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeChemicalReactor.java
+++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeChemicalReactor.java
@@ -1,9 +1,13 @@
package gregtech.common.tileentities.machines.multi;
-import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
-import com.gtnewhorizon.structurelib.structure.StructureDefinition;
+import com.gtnewhorizon.structurelib.StructureLibAPI;
+import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable;
+import com.gtnewhorizon.structurelib.structure.*;
+import com.gtnewhorizon.structurelib.util.ItemStackPredicate;
import gregtech.api.GregTech_API;
+import gregtech.api.enums.HeatingCoilLevel;
import gregtech.api.gui.GT_GUIContainer_MultiMachine;
+import gregtech.api.interfaces.IHeatingCoil;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
@@ -13,24 +17,31 @@ import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Single_Recipe_Check;
import gregtech.api.util.GT_Utility;
+import net.minecraft.block.Block;
+import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
+import net.minecraft.util.IChatComponent;
+import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import java.util.ArrayList;
+import java.util.function.Consumer;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofChain;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.onElementPass;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose;
+import static gregtech.api.enums.GT_HatchElement.*;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_LARGE_CHEMICAL_REACTOR;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_LARGE_CHEMICAL_REACTOR_ACTIVE;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_LARGE_CHEMICAL_REACTOR_ACTIVE_GLOW;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_LARGE_CHEMICAL_REACTOR_GLOW;
import static gregtech.api.enums.Textures.BlockIcons.casingTexturePages;
+import static gregtech.api.util.GT_StructureUtility.buildHatchAdder;
import static gregtech.api.util.GT_StructureUtility.ofHatchAdder;
-public class GT_MetaTileEntity_LargeChemicalReactor extends GT_MetaTileEntity_EnhancedMultiBlockBase<GT_MetaTileEntity_LargeChemicalReactor> {
+public class GT_MetaTileEntity_LargeChemicalReactor extends GT_MetaTileEntity_EnhancedMultiBlockBase<GT_MetaTileEntity_LargeChemicalReactor> implements ISurvivalConstructable {
private static final int CASING_INDEX = 176;
private static final String STRUCTURE_PIECE_MAIN = "main";
private static final IStructureDefinition<GT_MetaTileEntity_LargeChemicalReactor> STRUCTURE_DEFINITION = StructureDefinition.<GT_MetaTileEntity_LargeChemicalReactor>builder()
@@ -40,34 +51,21 @@ public class GT_MetaTileEntity_LargeChemicalReactor extends GT_MetaTileEntity_En
{"ccc", "cxc", "ccc"},
}))
.addElement('P', ofBlock(GregTech_API.sBlockCasings8, 1))
- .addElement('c', ofChain(
- ofHatchAdder(GT_MetaTileEntity_LargeChemicalReactor::addInputToMachineList, CASING_INDEX, 1),
- ofHatchAdder(GT_MetaTileEntity_LargeChemicalReactor::addOutputToMachineList, CASING_INDEX, 1),
- ofHatchAdder(GT_MetaTileEntity_LargeChemicalReactor::addMaintenanceToMachineList, CASING_INDEX, 1),
- ofHatchAdder(GT_MetaTileEntity_LargeChemicalReactor::addEnergyInputToMachineList, CASING_INDEX, 1),
- onElementPass(GT_MetaTileEntity_LargeChemicalReactor::onCasingAdded, ofBlock(GregTech_API.sBlockCasings8, 0))
+ .addElement('c', buildHatchAdder(GT_MetaTileEntity_LargeChemicalReactor.class)
+ .atLeast(InputHatch, OutputHatch, InputBus, OutputBus, Maintenance, Energy)
+ .casingIndex(CASING_INDEX)
+ .dot(1)
+ .buildAndChain(onElementPass(GT_MetaTileEntity_LargeChemicalReactor::onCasingAdded, ofBlock(GregTech_API.sBlockCasings8, 0))
))
- .addElement('x', ofChain(
- ofHatchAdder(GT_MetaTileEntity_LargeChemicalReactor::addInputToMachineList, CASING_INDEX, 2),
- ofHatchAdder(GT_MetaTileEntity_LargeChemicalReactor::addOutputToMachineList, CASING_INDEX, 2),
- ofHatchAdder(GT_MetaTileEntity_LargeChemicalReactor::addMaintenanceToMachineList, CASING_INDEX, 2),
- ofHatchAdder(GT_MetaTileEntity_LargeChemicalReactor::addEnergyInputToMachineList, CASING_INDEX, 2),
- onElementPass(GT_MetaTileEntity_LargeChemicalReactor::onCoilAdded, ofBlock(GregTech_API.sBlockCasings5, 0)),
- onElementPass(GT_MetaTileEntity_LargeChemicalReactor::onCoilAdded, ofBlock(GregTech_API.sBlockCasings5, 1)),
- onElementPass(GT_MetaTileEntity_LargeChemicalReactor::onCoilAdded, ofBlock(GregTech_API.sBlockCasings5, 2)),
- onElementPass(GT_MetaTileEntity_LargeChemicalReactor::onCoilAdded, ofBlock(GregTech_API.sBlockCasings5, 3)),
- onElementPass(GT_MetaTileEntity_LargeChemicalReactor::onCoilAdded, ofBlock(GregTech_API.sBlockCasings5, 4)),
- onElementPass(GT_MetaTileEntity_LargeChemicalReactor::onCoilAdded, ofBlock(GregTech_API.sBlockCasings5, 5)),
- onElementPass(GT_MetaTileEntity_LargeChemicalReactor::onCoilAdded, ofBlock(GregTech_API.sBlockCasings5, 6)),
- onElementPass(GT_MetaTileEntity_LargeChemicalReactor::onCoilAdded, ofBlock(GregTech_API.sBlockCasings5, 7)),
- onElementPass(GT_MetaTileEntity_LargeChemicalReactor::onCoilAdded, ofBlock(GregTech_API.sBlockCasings5, 8)),
- onElementPass(GT_MetaTileEntity_LargeChemicalReactor::onCoilAdded, ofBlock(GregTech_API.sBlockCasings5, 9)),
- onElementPass(GT_MetaTileEntity_LargeChemicalReactor::onCoilAdded, ofBlock(GregTech_API.sBlockCasings5, 10)),
- onElementPass(GT_MetaTileEntity_LargeChemicalReactor::onCoilAdded, ofBlock(GregTech_API.sBlockCasings5, 11)),
- onElementPass(GT_MetaTileEntity_LargeChemicalReactor::onCoilAdded, ofBlock(GregTech_API.sBlockCasings5, 12)),
- onElementPass(GT_MetaTileEntity_LargeChemicalReactor::onCoilAdded, ofBlock(GregTech_API.sBlockCasings5, 13)),
+ .addElement('x', buildHatchAdder(GT_MetaTileEntity_LargeChemicalReactor.class)
+ .atLeast(InputHatch, OutputHatch, InputBus, OutputBus, Maintenance, Energy)
+ .casingIndex(CASING_INDEX)
+ .dot(1)
+ .buildAndChain(
+ CoilStructureElement.INSTANCE,
onElementPass(GT_MetaTileEntity_LargeChemicalReactor::onCasingAdded, ofBlock(GregTech_API.sBlockCasings8, 0))
- ))
+ )
+ )
.build();
private int mCasingAmount;
@@ -238,6 +236,54 @@ public class GT_MetaTileEntity_LargeChemicalReactor extends GT_MetaTileEntity_En
@Override
public void construct(ItemStack stackSize, boolean hintsOnly) {
+ mCoilAmount = 0;
buildPiece(STRUCTURE_PIECE_MAIN, stackSize, hintsOnly, 1, 1, 0);
}
+
+ @Override
+ public int survivalConstruct(ItemStack stackSize, int elementBudget, IItemSource source, EntityPlayerMP actor) {
+ if (mMachine) return -1;
+ mCoilAmount = 0;
+ return survivialBuildPiece(STRUCTURE_PIECE_MAIN, stackSize, 1, 1, 0, elementBudget, source, actor, false, true);
+ }
+
+ private enum CoilStructureElement implements IStructureElement<GT_MetaTileEntity_LargeChemicalReactor> {
+ INSTANCE;
+
+ @Override
+ public boolean check(GT_MetaTileEntity_LargeChemicalReactor t, World world, int x, int y, int z) {
+ Block block = world.getBlock(x, y, z);
+ if (block instanceof IHeatingCoil && ((IHeatingCoil) block).getCoilHeat(world.getBlockMetadata(x, y, z)) != HeatingCoilLevel.None) {
+ return t.mCoilAmount++ == 0;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean spawnHint(GT_MetaTileEntity_LargeChemicalReactor t, World world, int x, int y, int z, ItemStack trigger) {
+ StructureLibAPI.hintParticle(world, x, y, z, GregTech_API.sBlockCasings5, 0);
+ return true;
+ }
+
+ @Override
+ public boolean placeBlock(GT_MetaTileEntity_LargeChemicalReactor t, World world, int x, int y, int z, ItemStack trigger) {
+ if (t.mCoilAmount > 0) return false;
+ boolean b = world.setBlock(x, y, z, GregTech_API.sBlockCasings5, 0, 3);
+ if (b) t.mCoilAmount++;
+ return b;
+ }
+
+ @Override
+ public PlaceResult survivalPlaceBlock(GT_MetaTileEntity_LargeChemicalReactor t, World world, int x, int y, int z, ItemStack trigger, IItemSource s, EntityPlayerMP actor, Consumer<IChatComponent> chatter) {
+ if (t.mCoilAmount > 0) return PlaceResult.SKIP;
+ if (check(t, world, x, y,z)) return PlaceResult.SKIP;
+ if (!StructureLibAPI.isBlockTriviallyReplaceable(world, x, y, z, actor)) return PlaceResult.REJECT;
+ ItemStack result = s.takeOne(ItemStackPredicate.from(GregTech_API.sBlockCasings5), true);
+ if (result == null) return PlaceResult.REJECT;
+ PlaceResult ret = StructureUtility.survivalPlaceBlock(result, ItemStackPredicate.NBTMode.EXACT, null, true, world, x, y, z, s, actor, chatter);
+ if (ret == PlaceResult.ACCEPT) t.mCoilAmount++;
+ return ret;
+ }
+ }
}