Skip to content

Commit

Permalink
Update to latest JEI, fixes #2720
Browse files Browse the repository at this point in the history
This does set a hard requirement on the most recent JEI, which might delay this release a bit until JEI makes the latest version not break all the mods

(cherry picked from commit 1e9fd16)
  • Loading branch information
KnightMiner committed Mar 15, 2022
1 parent 15034ac commit 559341d
Show file tree
Hide file tree
Showing 40 changed files with 658 additions and 615 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ def modsTomlSpec = copySpec{
'minecraft_range': minecraft_range,
'forge_range': forge_range,
'mantle_range': mantle_range,
'jei_range': jei_range,
'crt_range': crt_range
}
}
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ mantle_version=1.8.36
mantle_range=[1.8.36,)

# Optional compat
jei_version=9.1.+
jei_version=9.3.+
jei_range=[9.3.2.92,)
probe_version=3.0.6-8
crt_version=7.1.0.307
crt_range=[7.1.0.245,)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import slimeknights.tconstruct.library.recipe.modifiers.adding.IDisplayModifierRecipe;
import slimeknights.tconstruct.tools.TinkerModifiers;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -64,10 +65,6 @@ public class ContentModifier extends PageContent {
public String[] effects;
public boolean more_text_space = false;

@SuppressWarnings({"FieldCanBeLocal", "FieldMayBeFinal"})
@SerializedName("required_mod")
private String requiredMod = "";

@SerializedName("modifier_id")
public String modifierID;

Expand All @@ -81,7 +78,7 @@ public Modifier getModifier() {
return this.modifier;
}

@Override
@Override @Nonnull
public String getTitle() {
return this.getModifier().getDisplayName().getString();
}
Expand Down Expand Up @@ -151,15 +148,15 @@ public void build(BookData book, ArrayList<BookElement> list, boolean brightSide
*/
public void buildAndAddRecipeDisplay(BookData book, ArrayList<BookElement> list, @Nullable IDisplayModifierRecipe recipe, @Nullable BookScreen parent) {
if (recipe != null) {
List<List<ItemStack>> inputs = recipe.getDisplayItems();
ImageData img = IMG_SLOTS[Math.min(inputs.size() - 2, 4)];
if (inputs.size() > 6) {
TConstruct.LOG.warn("Too many inputs in recipe {}, size {}", recipe, inputs.size() - 2);
int inputs = recipe.getInputCount();
ImageData img = IMG_SLOTS[Math.min(inputs - 1, 4)];
if (inputs > 5) {
TConstruct.LOG.warn("Too many inputs in recipe {}, size {}", recipe, inputs);
}
int[] slotsX = SLOTS_X;
int[] slotsY = SLOTS_Y;

if (inputs.size() == 5) {
if (inputs == 4) {
slotsX = SLOTS_X_4;
slotsY = SLOTS_Y_4;
}
Expand Down Expand Up @@ -204,12 +201,9 @@ public void buildAndAddRecipeDisplay(BookData book, ArrayList<BookElement> list,
this.parts.add(image);
list.add(image);

for (int i = 1; i < Math.min(inputs.size(), 6); i++) {
TinkerItemElement part = new TinkerItemElement(imgX + slotsX[i - 1], imgY + slotsY[i - 1], 1f, inputs.get(i));

if (parent != null)
part.parent = parent;

for (int i = 0; i < Math.min(inputs, 5); i++) {
TinkerItemElement part = new TinkerItemElement(imgX + slotsX[i], imgY + slotsY[i], 1f, recipe.getDisplayItems(i));
if (parent != null) part.parent = parent;
this.parts.add(part);
list.add(part);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import net.minecraft.util.GsonHelper;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.ForgeSpawnEggItem;
import net.minecraftforge.fluids.FluidStack;
import slimeknights.mantle.recipe.ICustomOutputRecipe;
import slimeknights.mantle.recipe.container.IEmptyContainer;
Expand All @@ -25,6 +27,7 @@
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

/**
* Recipe to melt an entity into a fluid
Expand All @@ -40,7 +43,8 @@ public class EntityMeltingRecipe implements ICustomOutputRecipe<IEmptyContainer>
private final int damage;

@SuppressWarnings("rawtypes")
private List<List<EntityType>> displayInputs;
private List<EntityType> entityInputs;
private List<ItemStack> itemInputs;

/**
* Checks if the recipe matches the given type
Expand All @@ -65,11 +69,26 @@ public FluidStack getOutput(LivingEntity entity) {
* @return Entity type inputs
*/
@SuppressWarnings("rawtypes")
public List<List<EntityType>> getDisplayInputs() {
if (displayInputs == null) {
displayInputs = ImmutableList.of(ImmutableList.copyOf(getInputs()));
public List<EntityType> getEntityInputs() {
if (entityInputs == null) {
entityInputs = ImmutableList.copyOf(ingredient.getTypes());
}
return displayInputs;
return entityInputs;
}

/**
* Gets a list of item inputs for recipe lookup in JEI
* @return Item inputs
*/
public List<ItemStack> getItemInputs() {
if (itemInputs == null) {
itemInputs = getEntityInputs().stream()
.map(ForgeSpawnEggItem::fromEntityType)
.filter(Objects::nonNull)
.map(ItemStack::new)
.toList();
}
return itemInputs;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.common.collect.ImmutableList;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.minecraft.core.NonNullList;
Expand Down Expand Up @@ -37,8 +36,9 @@ public class MeltingRecipe implements IMeltingRecipe {
private final ResourceLocation id;
@Getter
protected final String group;
@Getter
protected final Ingredient input;
@Getter(AccessLevel.PROTECTED)
@Getter
protected final FluidStack output;
@Getter
protected final int temperature;
Expand Down Expand Up @@ -92,11 +92,6 @@ public void handleByproducts(IMeltingContainer inv, IFluidHandler handler) {
}
}

/** Gets the recipe output for display in JEI */
public List<List<FluidStack>> getDisplayOutput() {
return Collections.singletonList(Collections.singletonList(output));
}

/** Gets the recipe output for display in JEI */
public List<List<FluidStack>> getOutputWithByproducts() {
if (outputWithByproducts == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;

/** Shared logic between modifier and incremental modifier recipes */
Expand Down Expand Up @@ -131,23 +130,12 @@ public ModifierEntry getDisplayResult() {
return displayResult;
}

/**
* Add extra ingredients for display in JEI
* @param builder Ingredient list builder
*/
protected abstract void addIngredients(Consumer<List<ItemStack>> builder);

@Override
public List<List<ItemStack>> getDisplayItems() {
public List<ItemStack> getToolWithoutModifier() {
if (displayInputs == null) {
displayInputs = getToolInputs().stream().map(stack -> IDisplayModifierRecipe.withModifiers(stack, requirements, null)).collect(Collectors.toList());
}
// if empty requirement, assume any modifiable
ImmutableList.Builder<List<ItemStack>> builder = ImmutableList.builder();
// inputs
builder.add(displayInputs);
addIngredients(builder::add);
return builder.build();
return displayInputs;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@

/** Common interface for modifier recipes that can show in JEI */
public interface IDisplayModifierRecipe extends IModifierRecipe {
/** Gets the number of inputs for this recipe */
int getInputCount();

/**
* Gets a list of ingredients to display in JEI. First entry is the tool without the modifier, then next 1-5 are items to add the modifier
* Gets an ingredients to display in JEI.
* @param slot Slot index to display
* @return Display item list
*/
List<List<ItemStack>> getDisplayItems();
List<ItemStack> getDisplayItems(int slot);

/** Gets the result tool before adding the modifier */
List<ItemStack> getToolWithoutModifier();

/** Gets the result tool with this modifier added */
List<ItemStack> getToolWithModifier();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package slimeknights.tconstruct.library.recipe.modifiers.adding;

import com.google.common.collect.ImmutableList;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
Expand Down Expand Up @@ -29,8 +30,8 @@

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;

public class IncrementalModifierRecipe extends AbstractModifierRecipe {
Expand Down Expand Up @@ -153,29 +154,51 @@ public boolean isIncremental() {
return true;
}

@Override
protected void addIngredients(Consumer<List<ItemStack>> builder) {
// fill extra item slots
List<ItemStack> items = Arrays.asList(input.getItems());
int maxStackSize = items.stream().mapToInt(ItemStack::getMaxStackSize).min().orElse(64);

// split the stacks out if we need more than 1
int needed = neededPerLevel / amountPerInput;
if (neededPerLevel % amountPerInput > 0) {
needed++;
}
Lazy<List<ItemStack>> fullSize = Lazy.of(() -> items.stream().map(stack -> ItemHandlerHelper.copyStackWithSize(stack, maxStackSize)).collect(Collectors.toList()));
while (needed > maxStackSize) {
builder.accept(fullSize.get());
needed -= maxStackSize;
}
// set proper stack size on remaining
if (needed > 0) {
int remaining = needed;
builder.accept(items.stream().map(stack -> ItemHandlerHelper.copyStackWithSize(stack, remaining)).collect(Collectors.toList()));
/** Cache of the list of items for each slot */
private List<List<ItemStack>> slotCache;

/** Gets the list of input stacks for display */
private List<List<ItemStack>> getInputs() {
if (slotCache == null) {
ImmutableList.Builder<List<ItemStack>> builder = ImmutableList.builder();

// fill extra item slots
List<ItemStack> items = Arrays.asList(input.getItems());
int maxStackSize = items.stream().mapToInt(ItemStack::getMaxStackSize).min().orElse(64);

// split the stacks out if we need more than 1
int needed = neededPerLevel / amountPerInput;
if (neededPerLevel % amountPerInput > 0) {
needed++;
}
Lazy<List<ItemStack>> fullSize = Lazy.of(() -> items.stream().map(stack -> ItemHandlerHelper.copyStackWithSize(stack, maxStackSize)).collect(Collectors.toList()));
while (needed > maxStackSize) {
builder.add(fullSize.get());
needed -= maxStackSize;
}
// set proper stack size on remaining
if (needed > 0) {
int remaining = needed;
builder.add(items.stream().map(stack -> ItemHandlerHelper.copyStackWithSize(stack, remaining)).collect(Collectors.toList()));
}
slotCache = builder.build();
}
return slotCache;
}

@Override
public int getInputCount() {
return getInputs().size();
}

@Override
public List<ItemStack> getDisplayItems(int slot) {
List<List<ItemStack>> inputs = getInputs();
if (slot >= 0 && slot < inputs.size()) {
return inputs.get(slot);
}
return Collections.emptyList();
}

/* Helpers */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

import javax.annotation.Nullable;
import java.util.BitSet;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;

/**
* Standard recipe to add a modifier
Expand Down Expand Up @@ -173,10 +173,16 @@ public RecipeSerializer<?> getSerializer() {
/* JEI display */

@Override
protected void addIngredients(Consumer<List<ItemStack>> builder) {
for (SizedIngredient ingredient : inputs) {
builder.accept(ingredient.getMatchingStacks());
public int getInputCount() {
return inputs.size();
}

@Override
public List<ItemStack> getDisplayItems(int slot) {
if (slot >= 0 && slot < inputs.size()) {
return inputs.get(slot).getMatchingStacks();
}
return Collections.emptyList();
}

public static class Serializer extends AbstractModifierRecipe.Serializer<ModifierRecipe> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
* Recipe to add overslime to a tool
Expand Down Expand Up @@ -120,22 +120,27 @@ public RecipeSerializer<?> getSerializer() {
/* JEI display */
/** Cache of modifier result, same for all overslime */
private static final Lazy<ModifierEntry> RESULT = Lazy.of(() -> new ModifierEntry(TinkerModifiers.overslime.get(), 1));
/** Cache of tools for input, same for all overslime */
private static final Lazy<List<ItemStack>> DISPLAY_TOOLS = Lazy.of(() -> TinkerTags.Items.DURABILITY.getValues().stream().map(MAP_TOOL_FOR_RENDERING).collect(Collectors.toList()));
/** Cache of input and output tools for display */
private List<ItemStack> toolWithoutModifier, toolWithModifier = null;

private List<ItemStack> toolWithModifier = null;
/** Cache of display outputs, value depends on recipe */
private List<List<ItemStack>> displayItems = null;
@Override
public int getInputCount() {
return 1;
}

@Override
public List<List<ItemStack>> getDisplayItems() {
if (displayItems == null) {
// set cap and amount based on the restore amount for output
displayItems = Arrays.asList(
DISPLAY_TOOLS.get(),
Arrays.asList(ingredient.getItems()));
public List<ItemStack> getDisplayItems(int slot) {
if (slot == 0) {
return Arrays.asList(ingredient.getItems());
}
return Collections.emptyList();
}
@Override
public List<ItemStack> getToolWithoutModifier() {
if (toolWithoutModifier == null) {
toolWithoutModifier = TinkerTags.Items.DURABILITY.getValues().stream().map(MAP_TOOL_FOR_RENDERING).toList();
}
return displayItems;
return toolWithoutModifier;
}

@Override
Expand Down

0 comments on commit 559341d

Please sign in to comment.