diff options
author | Guillaume Mercier <C0bra5@users.noreply.github.com> | 2023-10-11 17:18:24 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-11 23:18:24 +0200 |
commit | 1a03cd053126d48e21fd483bc2e5d3f92eb2cab9 (patch) | |
tree | 551a1a0687aed4e64007b331a6449f12fc0fd8f1 /src/main | |
parent | 257b8b181c751f0b62c9302efc09b0f444deb730 (diff) | |
download | GT5-Unofficial-1a03cd053126d48e21fd483bc2e5d3f92eb2cab9.tar.gz GT5-Unofficial-1a03cd053126d48e21fd483bc2e5d3f92eb2cab9.tar.bz2 GT5-Unofficial-1a03cd053126d48e21fd483bc2e5d3f92eb2cab9.zip |
GT_BaseCrop Modularisation (#2330)
- Add layout.json from idea to gitignore
- Modularizes the code for the isBlockBelow check
- No functionality changes should appear to the end user
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/gregtech/api/util/GT_BaseCrop.java | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/src/main/java/gregtech/api/util/GT_BaseCrop.java b/src/main/java/gregtech/api/util/GT_BaseCrop.java index 90c1619472..c379cec52a 100644 --- a/src/main/java/gregtech/api/util/GT_BaseCrop.java +++ b/src/main/java/gregtech/api/util/GT_BaseCrop.java @@ -165,7 +165,8 @@ public class GT_BaseCrop extends CropCard implements ICropCardInfo { @Override public final boolean canGrow(ICropTile aCrop) { - if (GT_Mod.gregtechproxy.mCropNeedBlock && mBlock != null && aCrop.getSize() == mMaxSize - 1) { + // block check is only performed at the last stage of growth + if (this.needsBlockBelow() && aCrop.getSize() == mMaxSize - 1) { return isBlockBelow(aCrop); } return aCrop.getSize() < maxSize(); @@ -223,6 +224,15 @@ public class GT_BaseCrop extends CropCard implements ICropCardInfo { return maxSize(); } + /** + * Checks if the crop needs a block below it + * + * @return True if the crop needs a block below it to grow to its max size + */ + public boolean needsBlockBelow() { + return GT_Mod.gregtechproxy.mCropNeedBlock && this.mBlock != null; + } + public boolean isBlockBelow(ICropTile aCrop) { if (aCrop == null) { return false; @@ -243,13 +253,7 @@ public class GT_BaseCrop extends CropCard implements ICropCardInfo { } else { int tMetaID = aCrop.getWorld() .getBlockMetadata(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ); - ItemData tAssotiation = GT_OreDictUnificator.getAssociation(new ItemStack(tBlock, 1, tMetaID)); - if ((tAssotiation != null) && (tAssotiation.mPrefix.toString() - .startsWith("ore")) && (tAssotiation.mMaterial.mMaterial == mBlock)) { - return true; - } - if ((tAssotiation != null) && (tAssotiation.mPrefix == OrePrefixes.block) - && (tAssotiation.mMaterial.mMaterial == mBlock)) { + if (isBlockBelow(new ItemStack(tBlock, 1, tMetaID))) { return true; } } @@ -257,6 +261,34 @@ public class GT_BaseCrop extends CropCard implements ICropCardInfo { return false; } + /** + * An isolated function to check if an item stack is a block that should be below this crop + * + * @param aItem a stack of the block placed under the crop + * @return The result of the check + */ + public boolean isBlockBelow(ItemStack aItem) { + // safety in case someone calls this without checking if we have a block + if (!this.needsBlockBelow()) return true; + + // get material from stack + ItemData tAssociation = GT_OreDictUnificator.getAssociation(aItem); + if (tAssociation == null) return false; + + // return true if it's an ore of the material + // note: some ores don't appear to have associations in testing, naq ore is an example of that + if (tAssociation.mPrefix.toString() + .startsWith("ore") && tAssociation.mMaterial.mMaterial == mBlock) { + return true; + } + + // return true if it's a block of the material + if (tAssociation.mPrefix == OrePrefixes.block && tAssociation.mMaterial.mMaterial == mBlock) { + return true; + } + return false; + } + @Override public List<String> getCropInformation() { if (mBlock != null) { |