Skip to content
This repository has been archived by the owner on May 26, 2024. It is now read-only.

Commit

Permalink
fix structure check
Browse files Browse the repository at this point in the history
  • Loading branch information
HoleFish committed Mar 16, 2024
1 parent 639706e commit 4bc0033
Showing 1 changed file with 65 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,58 +89,94 @@ protected GT_Multiblock_Tooltip_Builder createTooltip() {
return tt;
}

/**
* The front part of multi. Used to determine the tier, or in other words, determine the size of multi.
*/
private static final String STRUCTURE_PIECE_FRONT = "front";
/**
* The rest part of multi.
*/
private static final String STRUCTURE_PIECE_REST = "rest";
private static final int MAX_TIER = 3;

@Override
public IStructureDefinition<GregtechMetaTileEntity_IndustrialArcFurnace> getStructureDefinition() {
if (STRUCTURE_DEFINITION == null) {
STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialArcFurnace>builder().addShape(
mName + "3",
new String[][] { { "CCC", "C~C", "CCC" }, { "CCC", "C-C", "CCC" }, { "CCC", "CCC", "CCC" }, })
STRUCTURE_DEFINITION = StructureDefinition.<GregtechMetaTileEntity_IndustrialArcFurnace>builder()
.addShape(STRUCTURE_PIECE_FRONT + 1, new String[][] { { "CCC", "C~C", "CCC" } })
.addShape(
STRUCTURE_PIECE_FRONT + 2,
new String[][] { { "CCCCC", "C C", "C C", "C C", "CCCCC" } })
.addShape(
STRUCTURE_PIECE_FRONT + 3,
new String[][] { { "CCCCCCC", "C C", "C C", "C C", "C C", "C C",
" CCCCCCC " }, })
.addShape(
STRUCTURE_PIECE_REST + 1,
new String[][] { { "CCC", "C-C", "CCC" }, { "CCC", "CCC", "CCC" } })
.addShape(
mName + "5",
new String[][] { { "CCCCC", "CCCCC", "CC~CC", "CCCCC", "CCCCC" },
{ "CCCCC", "C---C", "C---C", "C---C", "CCCCC" },
{ "CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC" }, })
STRUCTURE_PIECE_REST + 2,
new String[][] { { "CCCCC", "C---C", "C---C", "C---C", "CCCCC" },
{ "CCCCC", "CCCCC", "CCCCC", "CCCCC", "CCCCC" } })
.addShape(
mName + "7",
STRUCTURE_PIECE_REST + 3,
new String[][] {
{ "CCCCCCC", "CCCCCCC", "CCCCCCC", "CCC~CCC", "CCCCCCC", "CCCCCCC", "CCCCCCC" },
{ "CCCCCCC", "C-----C", "C-----C", "C-----C", "C-----C", "C-----C", "CCCCCCC" },
{ "CCCCCCC", "CCCCCCC", "CCCCCCC", "CCCCCCC", "CCCCCCC", "CCCCCCC", "CCCCCCC" }, })
.addElement(
'C',

buildHatchAdder(GregtechMetaTileEntity_IndustrialArcFurnace.class)
.atLeast(InputBus, InputHatch, OutputBus, OutputHatch, Maintenance, Energy, Muffler)
.casingIndex(getCasingTextureIndex()).dot(1).buildAndChain(
.casingIndex(getCasingTextureIndex()).dot(1).allowOnly(ForgeDirection.NORTH)
.buildAndChain(
onElementPass(x -> ++x.mCasing, ofBlock(ModBlocks.blockCasings4Misc, 3))))
.build();
}
return STRUCTURE_DEFINITION;
}

private int getSizeFromHint(ItemStack stackSize) {
return switch (stackSize.stackSize) {
case 1 -> 3;
case 2 -> 5;
default -> 7;
};
private int getTierFromHint(ItemStack stackSize) {
if (stackSize.stackSize <= 0 || stackSize.stackSize >= MAX_TIER) {
return MAX_TIER;
}
return stackSize.stackSize;
}

@Override
public void construct(ItemStack stackSize, boolean hintsOnly) {
int size = getSizeFromHint(stackSize);
buildPiece(mName + size, stackSize, hintsOnly, (size - 1) / 2, (size - 1) / 2, 0);
int maxTier = getTierFromHint(stackSize);
for (int tier = 1; tier <= maxTier; tier++) {
buildPiece(STRUCTURE_PIECE_FRONT + tier, stackSize, hintsOnly, tier, tier, 0);
}
buildPiece(STRUCTURE_PIECE_REST + maxTier, stackSize, hintsOnly, maxTier, maxTier, -1);
}

@Override
public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBuildEnvironment env) {
if (mMachine) return -1;
int size = getSizeFromHint(stackSize);
int maxTier = getTierFromHint(stackSize);
int built;
for (int tier = 1; tier <= maxTier; tier++) {
built = survivialBuildPiece(
STRUCTURE_PIECE_FRONT + tier,
stackSize,
tier,
tier,
0,
elementBudget,
env,
false,
true);
if (built >= 0) return built;
}

return survivialBuildPiece(
mName + size,
STRUCTURE_PIECE_REST + maxTier,
stackSize,
(size - 1) / 2,
(size - 1) / 2,
0,
maxTier,
maxTier,
-1,
elementBudget,
env,
false,
Expand All @@ -151,18 +187,13 @@ public int survivalConstruct(ItemStack stackSize, int elementBudget, ISurvivalBu
public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) {
mCasing = 0;
mSize = 0;
if (checkPiece(mName + "3", 1, 1, 0)) {
mSize = 3;
return mCasing >= 10 && checkHatch();
int tier = 0;
while (tier < MAX_TIER && checkPiece(STRUCTURE_PIECE_FRONT + (tier + 1), (tier + 1), (tier + 1), 0)) {
tier++;
}
mCasing = 0;
if (checkPiece(mName + "5", 2, 2, 0)) {
mSize = 5;
return mCasing >= 10 && checkHatch();
}
mCasing = 0;
if (checkPiece(mName + "7", 3, 3, 0)) {
mSize = 7;
if (tier <= 0) return false;
if (checkPiece(STRUCTURE_PIECE_REST + tier, tier, tier, -1)) {
mSize = 2 * tier + 1;
return mCasing >= 10 && checkHatch();
}
return false;
Expand Down

0 comments on commit 4bc0033

Please sign in to comment.