aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/api
diff options
context:
space:
mode:
authorAbdiel Kavash <19243993+AbdielKavash@users.noreply.github.com>2024-02-28 05:45:44 -0600
committerGitHub <noreply@github.com>2024-02-28 12:45:44 +0100
commit5497075f54732ccf3c7580fe311a2327ebb05cb2 (patch)
tree8060f3d7bed0d8d62426541e83307f051a03da02 /src/main/java/gtPlusPlus/api
parentece12a200879adfb16fd9d8701f6e75a3d7c072e (diff)
downloadGT5-Unofficial-5497075f54732ccf3c7580fe311a2327ebb05cb2.tar.gz
GT5-Unofficial-5497075f54732ccf3c7580fe311a2327ebb05cb2.tar.bz2
GT5-Unofficial-5497075f54732ccf3c7580fe311a2327ebb05cb2.zip
Tree Growth Simulator can now harvest leaves and fruits, using appropriate tools. (#839)
* TGS logic rework and new outputs * TGS logic rework and new outputs * NEI frontend. * NEI frontend part 2 * Recover saws from controller slot to input bus. * Added documentation and removed unused stuff. * Recipes for non-Forestry trees. * Updated tooltip. * Better handling of saws in controller slot from previous versions + grafter support. * Added Forestry and Extra Trees trees registration and processing. * BS + deps. * Disable ME stocking bus to fix an exploit. * Fixes based on feedback. --------- Co-authored-by: Martin Robertz <dream-master@gmx.net>
Diffstat (limited to 'src/main/java/gtPlusPlus/api')
-rw-r--r--src/main/java/gtPlusPlus/api/recipe/GTPPRecipeMaps.java9
-rw-r--r--src/main/java/gtPlusPlus/api/recipe/TGSFrontend.java132
2 files changed, 113 insertions, 28 deletions
diff --git a/src/main/java/gtPlusPlus/api/recipe/GTPPRecipeMaps.java b/src/main/java/gtPlusPlus/api/recipe/GTPPRecipeMaps.java
index 3977d69fe7..f28216450d 100644
--- a/src/main/java/gtPlusPlus/api/recipe/GTPPRecipeMaps.java
+++ b/src/main/java/gtPlusPlus/api/recipe/GTPPRecipeMaps.java
@@ -21,6 +21,7 @@ import gregtech.nei.formatter.SimpleSpecialValueFormatter;
import gtPlusPlus.core.util.math.MathUtils;
import gtPlusPlus.core.util.minecraft.ItemUtils;
import gtPlusPlus.xmod.gregtech.api.gui.GTPP_UITextures;
+import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.GregtechMetaTileEntityTreeFarm;
public class GTPPRecipeMaps {
@@ -153,5 +154,11 @@ public class GTPPRecipeMaps {
public static final RecipeMap<RecipeMapBackend> flotationCellRecipes = RecipeMapBuilder
.of("gtpp.recipe.flotationcell").maxIO(6, 0, 1, 1).build();
public static final RecipeMap<RecipeMapBackend> treeGrowthSimulatorFakeRecipes = RecipeMapBuilder
- .of("gtpp.recipe.treefarm").maxIO(1, 2, 1, 0).minInputs(1, 0).frontend(TGSFrontend::new).build();
+ .of("gtpp.recipe.treefarm")
+ .maxIO(
+ GregtechMetaTileEntityTreeFarm.Mode.values().length,
+ GregtechMetaTileEntityTreeFarm.Mode.values().length,
+ 0,
+ 0)
+ .minInputs(1, 0).useSpecialSlot().frontend(TGSFrontend::new).build();
}
diff --git a/src/main/java/gtPlusPlus/api/recipe/TGSFrontend.java b/src/main/java/gtPlusPlus/api/recipe/TGSFrontend.java
index 10a9fe4da6..b36bf62b56 100644
--- a/src/main/java/gtPlusPlus/api/recipe/TGSFrontend.java
+++ b/src/main/java/gtPlusPlus/api/recipe/TGSFrontend.java
@@ -1,68 +1,146 @@
package gtPlusPlus.api.recipe;
-import static net.minecraft.util.EnumChatFormatting.GRAY;
-
+import java.awt.Rectangle;
import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import javax.annotation.ParametersAreNonnullByDefault;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
+import com.gtnewhorizons.modularui.api.math.Pos2d;
+
import gregtech.api.recipe.BasicUIPropertiesBuilder;
import gregtech.api.recipe.NEIRecipePropertiesBuilder;
import gregtech.api.recipe.RecipeMapFrontend;
+import gregtech.api.util.GT_Recipe;
import gregtech.api.util.MethodsReturnNonnullByDefault;
+import gregtech.common.gui.modularui.UIHelper;
import gregtech.nei.GT_NEI_DefaultHandler;
import gregtech.nei.RecipeDisplayInfo;
import gregtech.nei.formatter.INEISpecialInfoFormatter;
-import gtPlusPlus.core.item.ModItems;
+import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.GregtechMetaTileEntityTreeFarm;
+import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.GregtechMetaTileEntityTreeFarm.Mode;
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
public class TGSFrontend extends RecipeMapFrontend {
+ private static final int SLOT_SIZE = 18;
+ private static final int CENTER_X = 90;
+ private static final int SPECIAL_X = CENTER_X - SLOT_SIZE / 2;
+ private static final int SPECIAL_Y = 9;
+ private static final int INPUTS_X = CENTER_X - SLOT_SIZE * 3;
+ private static final int INPUTS_Y = SPECIAL_Y + SLOT_SIZE + SLOT_SIZE / 2;
+ private static final int OUTPUTS_X = CENTER_X + SLOT_SIZE;
+ private static final int OUTPUTS_Y = INPUTS_Y;
+
public TGSFrontend(BasicUIPropertiesBuilder uiPropertiesBuilder, NEIRecipePropertiesBuilder neiPropertiesBuilder) {
- super(uiPropertiesBuilder, neiPropertiesBuilder.neiSpecialInfoFormatter(new TGSSpecialValueFormatter()));
+ super(
+ uiPropertiesBuilder.addNEITransferRect(
+ new Rectangle(INPUTS_X + SLOT_SIZE * 2, INPUTS_Y + SLOT_SIZE / 2, SLOT_SIZE * 2, SLOT_SIZE))
+ .progressBarPos(new Pos2d(CENTER_X - 10, INPUTS_Y + SLOT_SIZE / 2)),
+ neiPropertiesBuilder.neiSpecialInfoFormatter(new TGSSpecialValueFormatter()));
}
@Override
- protected void drawEnergyInfo(RecipeDisplayInfo recipeInfo) {}
+ protected void drawEnergyInfo(RecipeDisplayInfo recipeInfo) {
+ // Do not.
+ }
@Override
- protected void drawDurationInfo(RecipeDisplayInfo recipeInfo) {}
+ public Pos2d getSpecialItemPosition() {
+ return new Pos2d(SPECIAL_X, SPECIAL_Y);
+ }
@Override
- protected List<String> handleNEIItemOutputTooltip(List<String> currentTip,
- GT_NEI_DefaultHandler.FixedPositionedStack pStack) {
- if (ModItems.fluidFertBasic != null && pStack.isChanceBased()) {
- currentTip.add(
- GRAY + StatCollector.translateToLocalFormatted(
- "gtpp.nei.tgs.sapling",
- StatCollector.translateToLocal(ModItems.fluidFertBasic.getUnlocalizedName())));
- } else {
- super.handleNEIItemOutputTooltip(currentTip, pStack);
- }
- return currentTip;
+ public List<Pos2d> getItemInputPositions(int itemInputCount) {
+ return UIHelper.getGridPositions(Mode.values().length, INPUTS_X, INPUTS_Y, 2);
}
@Override
- protected void drawNEIOverlayForOutput(GT_NEI_DefaultHandler.FixedPositionedStack stack) {}
+ public List<Pos2d> getItemOutputPositions(int itemOutputCount) {
+ return UIHelper.getGridPositions(Mode.values().length, OUTPUTS_X, OUTPUTS_Y, 2);
+ }
+
+ private static final String[] tooltipInputs = { StatCollector.translateToLocal("gtpp.nei.tgs.tooltip.saw"),
+ StatCollector.translateToLocal("gtpp.nei.tgs.tooltip.cutter"),
+ StatCollector.translateToLocal("gtpp.nei.tgs.tooltip.shears"),
+ StatCollector.translateToLocal("gtpp.nei.tgs.tooltip.knife") };
+
+ private static final String[] tooltipOutputs = { StatCollector.translateToLocal("gtpp.nei.tgs.tooltip.needsSaw"),
+ StatCollector.translateToLocal("gtpp.nei.tgs.tooltip.needsCutter"),
+ StatCollector.translateToLocal("gtpp.nei.tgs.tooltip.needsShears"),
+ StatCollector.translateToLocal("gtpp.nei.tgs.tooltip.needsKnife") };
+ private static final String tooltipSapling = StatCollector.translateToLocal("gtpp.nei.tgs.tooltip.sapling");
+ private static final String tooltipMultiplier = StatCollector.translateToLocal("gtpp.nei.tgs.tooltip.multiplier");
+
+ @Override
+ public List<String> handleNEIItemTooltip(ItemStack stack, List<String> currentTip,
+ GT_NEI_DefaultHandler.CachedDefaultRecipe neiCachedRecipe) {
+
+ /*
+ * This gets a little complicated, because we want to assign tooltips to inputs/outputs based on which mode
+ * (saw, shears, etc.) they correspond to. But CachedDefaultRecipe does not retain this information for us. This
+ * is because some recipes don't output any items for some modes. For example, if a recipe only yields logs and
+ * leaves, then the outputs of GT_Recipe will be {log, null, leaves}. However, in CachedDefaultRecipe this gets
+ * condensed to just {log, leaves}, with null values omitted. So to figure out which item came from which mode,
+ * we need to step through both of these arrays simultaneously and match non-null inputs/outputs in GT_Recipe to
+ * inputs/outputs in CachedDefaultRecipe.
+ */
+
+ // The last input in neiCachedRecipe is always the special slot, this is the input sapling.
+ if (stack == neiCachedRecipe.mInputs.get(neiCachedRecipe.mInputs.size() - 1).item) {
+ currentTip.add(EnumChatFormatting.YELLOW + tooltipSapling);
+ super.handleNEIItemTooltip(stack, currentTip, neiCachedRecipe);
+ return currentTip;
+ }
+
+ GT_Recipe.GT_Recipe_WithAlt recipe = (GT_Recipe.GT_Recipe_WithAlt) neiCachedRecipe.mRecipe;
+
+ // Inputs
+ int slot = 0;
+ for (int mode = 0; mode < Mode.values().length; ++mode) {
+ if (mode < recipe.mOreDictAlt.length && recipe.mOreDictAlt[mode] != null) {
+ // There is a valid input in this mode.
+ if (slot < neiCachedRecipe.mInputs.size() && stack == neiCachedRecipe.mInputs.get(slot).item) {
+ int toolMultiplier = GregtechMetaTileEntityTreeFarm.getToolMultiplier(stack, Mode.values()[mode]);
+ currentTip.add(EnumChatFormatting.YELLOW + tooltipInputs[mode]);
+ if (toolMultiplier > 0) {
+ currentTip.add(EnumChatFormatting.YELLOW + tooltipMultiplier + " " + toolMultiplier + "x");
+ }
+ return currentTip;
+ }
+ ++slot;
+ }
+ }
+
+ // Outputs
+ slot = 0;
+ for (int mode = 0; mode < Mode.values().length; ++mode) {
+ if (mode < recipe.mOutputs.length && recipe.mOutputs[mode] != null) {
+ // There is a valid output in this mode.
+ if (slot < neiCachedRecipe.mOutputs.size() && stack == neiCachedRecipe.mOutputs.get(slot).item) {
+ currentTip.add(EnumChatFormatting.YELLOW + tooltipOutputs[mode]);
+ return currentTip;
+ }
+ ++slot;
+ }
+ }
+
+ return currentTip;
+ }
private static class TGSSpecialValueFormatter implements INEISpecialInfoFormatter {
@Override
public List<String> format(RecipeDisplayInfo recipeInfo) {
- if (ModItems.fluidFertBasic == null) {
- return Collections.emptyList();
- }
return Arrays.asList(
- StatCollector.translateToLocal("gtpp.nei.tgs.1"),
- StatCollector.translateToLocalFormatted(
- "gtpp.nei.tgs.2",
- StatCollector.translateToLocal(ModItems.fluidFertBasic.getUnlocalizedName())),
- StatCollector.translateToLocal("gtpp.nei.tgs.3"));
+ StatCollector.translateToLocal("gtpp.nei.tgs.info-1"),
+ StatCollector.translateToLocal("gtpp.nei.tgs.info-2"),
+ StatCollector.translateToLocal("gtpp.nei.tgs.info-3"));
}
}
}