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

Commit

Permalink
Merge remote-tracking branch 'AbdielKavash/TreeGrowthSim' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Dream-Master committed Feb 28, 2024
2 parents ece12a2 + 739feb8 commit afe057c
Show file tree
Hide file tree
Showing 9 changed files with 1,450 additions and 524 deletions.
9 changes: 8 additions & 1 deletion src/main/java/gtPlusPlus/api/recipe/GTPPRecipeMaps.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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 {

Expand Down Expand Up @@ -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();
}
132 changes: 105 additions & 27 deletions src/main/java/gtPlusPlus/api/recipe/TGSFrontend.java
Original file line number Diff line number Diff line change
@@ -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"));
}
}
}
57 changes: 0 additions & 57 deletions src/main/java/gtPlusPlus/xmod/forestry/HANDLER_FR.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
package gtPlusPlus.xmod.forestry;

import static gregtech.api.enums.Mods.ExtraTrees;
import static gregtech.api.enums.Mods.Forestry;

import net.minecraft.item.ItemStack;

import binnie.extratrees.genetics.ExtraTreeSpecies;
import cpw.mods.fml.common.Optional;
import forestry.api.arboriculture.EnumGermlingType;
import forestry.api.arboriculture.EnumWoodType;
import forestry.api.arboriculture.TreeManager;
import forestry.arboriculture.genetics.TreeDefinition;
import gregtech.api.enums.Mods;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
import gtPlusPlus.xmod.forestry.bees.items.FR_ItemRegistry;
import gtPlusPlus.xmod.forestry.bees.recipe.FR_Gregtech_Recipes;
import gtPlusPlus.xmod.forestry.bees.registry.GTPP_Bees;
import gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.production.GregtechMetaTileEntityTreeFarm;

public class HANDLER_FR {

Expand All @@ -30,51 +18,6 @@ public static void postInit() {
if (Forestry.isModLoaded()) {
FR_Gregtech_Recipes.registerItems();
new GTPP_Bees();
mapForestrySaplingToLog();
}

if (ExtraTrees.isModLoaded()) {
mapExtraTreesSaplingToLog();
}
}

@Optional.Method(modid = Mods.Names.FORESTRY)
private static void mapForestrySaplingToLog() {
for (TreeDefinition value : TreeDefinition.values()) {
ItemStack aSaplingStack = value.getMemberStack(EnumGermlingType.SAPLING);
EnumWoodType woodType = ReflectionUtils.getField(value, "woodType");
ItemStack aLog;
if (woodType != null) {
aLog = TreeManager.woodItemAccess.getLog(woodType, false);

GregtechMetaTileEntityTreeFarm.sLogCache.put(value.getUID(), aLog);
GregtechMetaTileEntityTreeFarm.sLogCache
.put(value.getUID() + "fireproof", TreeManager.woodItemAccess.getLog(woodType, true));
} else {
aLog = ReflectionUtils.getField(value, "vanillaWood");

GregtechMetaTileEntityTreeFarm.sLogCache
.put(value.getUID(), ReflectionUtils.getField(value, "vanillaWood"));
}

GregtechMetaTileEntityTreeFarm.addFakeRecipeToNEI(aSaplingStack, aLog);
}
}

@Optional.Method(modid = Mods.Names.EXTRA_TREES)
private static void mapExtraTreesSaplingToLog() {
for (ExtraTreeSpecies value : ExtraTreeSpecies.values()) {
ItemStack aSaplingStack = TreeManager.treeRoot
.getMemberStack(TreeManager.treeRoot.templateAsIndividual(value.getTemplate()), 0);
ItemStack aLog = null;
if (value.getLog() != null) {
aLog = value.getLog().getItemStack();

GregtechMetaTileEntityTreeFarm.sLogCache.put(value.getUID(), aLog);
GregtechMetaTileEntityTreeFarm.sLogCache.put(value.getUID() + "fireproof", aLog);
}

GregtechMetaTileEntityTreeFarm.addFakeRecipeToNEI(aSaplingStack, aLog);
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/gtPlusPlus/xmod/gregtech/HANDLER_GT.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import gtPlusPlus.xmod.gregtech.loaders.misc.AddCustomMachineToPA;
import gtPlusPlus.xmod.gregtech.loaders.recipe.RecipeLoader_AlgaeFarm;
import gtPlusPlus.xmod.gregtech.loaders.recipe.RecipeLoader_MolecularTransformer;
import gtPlusPlus.xmod.gregtech.loaders.recipe.RecipeLoader_TreeFarm;
import gtPlusPlus.xmod.gregtech.registration.gregtech.GregtechConduits;

public class HANDLER_GT {
Expand Down Expand Up @@ -89,6 +90,7 @@ public static void onLoadComplete(FMLLoadCompleteEvent event) {
CokeAndPyrolyseOven.onLoadComplete();
Meta_GT_Proxy.fixIC2FluidNames();
RecipeLoader_AlgaeFarm.generateRecipes();
RecipeLoader_TreeFarm.generateRecipes();
if (AdvancedSolarPanel.isModLoaded()) {
RecipeLoader_MolecularTransformer.run();
}
Expand Down

This file was deleted.

Loading

0 comments on commit afe057c

Please sign in to comment.