Skip to content

Commit

Permalink
Workaround fix for slimeskull usage not showing modifier recipes (#4924)
Browse files Browse the repository at this point in the history
Really its a JEI missing feature, as I cannot make one recipe type treat slimeskulls as the same while another treats them as different
So instead, fill all slimeskull modifier recipes with all variants of slimeskull from the material registry
  • Loading branch information
KnightMiner committed Dec 27, 2022
1 parent 9fd7f8d commit f8e5b5d
Showing 1 changed file with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,20 @@
import slimeknights.mantle.client.model.NBTKeyModel;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.library.client.GuiUtil;
import slimeknights.tconstruct.library.materials.IMaterialRegistry;
import slimeknights.tconstruct.library.materials.MaterialRegistry;
import slimeknights.tconstruct.library.recipe.modifiers.adding.IDisplayModifierRecipe;
import slimeknights.tconstruct.library.tools.SlotType;
import slimeknights.tconstruct.library.tools.SlotType.SlotCount;
import slimeknights.tconstruct.library.tools.helper.ToolBuildHandler;
import slimeknights.tconstruct.library.tools.item.IModifiable;
import slimeknights.tconstruct.library.tools.nbt.MaterialNBT;
import slimeknights.tconstruct.plugin.jei.TConstructJEIConstants;
import slimeknights.tconstruct.tools.TinkerModifiers;
import slimeknights.tconstruct.tools.TinkerTools;
import slimeknights.tconstruct.tools.item.ArmorSlotType;
import slimeknights.tconstruct.tools.item.CreativeSlotItem;
import slimeknights.tconstruct.tools.stats.SkullStats;

import javax.annotation.Nullable;
import java.awt.Color;
Expand Down Expand Up @@ -212,20 +220,29 @@ public void setRecipe(IRecipeLayoutBuilder builder, IDisplayModifierRecipe recip
List<ItemStack> toolWithoutModifier = recipe.getToolWithoutModifier();
List<ItemStack> toolWithModifier = recipe.getToolWithModifier();

// hack: if any slimeskull is selected, add all known variants to the recipe lookup
Item slimeskull = TinkerTools.slimesuit.get(ArmorSlotType.HELMET);
for (ItemStack stack : toolWithoutModifier) {
if (stack.is(slimeskull)) {
builder.addInvisibleIngredients(RecipeIngredientRole.CATALYST).addItemStacks(getSlimeskullHelmets());
break;
}
}

// JEI is currently being dumb and using ingredient subtypes within recipe focuses
// we use a more strict subtype for tools in ingredients so they all show in JEI, but do not care in recipes
// thus, manually handle the focuses
IFocus<ItemStack> focus = focuses.getFocuses(VanillaTypes.ITEM_STACK).filter(f -> f.getRole() == RecipeIngredientRole.CATALYST).findFirst().orElse(null);
if (focus != null) {
Item item = focus.getTypedValue().getIngredient().getItem();
for (ItemStack stack : toolWithoutModifier) {
if (stack.getItem() == item) {
if (stack.is(item)) {
toolWithoutModifier = List.of(stack);
break;
}
}
for (ItemStack stack : toolWithModifier) {
if (stack.getItem() == item) {
if (stack.is(item)) {
toolWithModifier = List.of(stack);
break;
}
Expand All @@ -234,4 +251,27 @@ public void setRecipe(IRecipeLayoutBuilder builder, IDisplayModifierRecipe recip
builder.addSlot(RecipeIngredientRole.CATALYST, 25, 38).addItemStacks(toolWithoutModifier);
builder.addSlot(RecipeIngredientRole.CATALYST, 105, 34).addItemStacks(toolWithModifier);
}


/* Slimeskull workaround */
/** internal list of slimeskulls for the sake of ingredient lookup, needed since they are technically distinct but modifiers treat them as the same */
private static List<ItemStack> SLIMESKULL_HELMETS = null;

/** called to clear the cache on ingredient reload as materials may have changed */
public static void clearSlimeskullCache() {
SLIMESKULL_HELMETS = null;
}

/** gets the list of slimeskull helmets, loading it if needed */
private static List<ItemStack> getSlimeskullHelmets() {
if (SLIMESKULL_HELMETS == null) {
IMaterialRegistry registry = MaterialRegistry.getInstance();
IModifiable slimeskull = TinkerTools.slimesuit.get(ArmorSlotType.HELMET);
SLIMESKULL_HELMETS = registry.getAllMaterials().stream()
.filter(material -> registry.getMaterialStats(material.getIdentifier(), SkullStats.ID).isPresent())
.map(material -> ToolBuildHandler.buildItemFromMaterials(slimeskull, MaterialNBT.of(material)))
.toList();
}
return SLIMESKULL_HELMETS;
}
}

0 comments on commit f8e5b5d

Please sign in to comment.