Skip to content

Commit

Permalink
Merge branch '1.20' into 1.19.4
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyploszaj committed Jan 11, 2025
2 parents e26b4ba + d65c84e commit b6a9eb8
Show file tree
Hide file tree
Showing 27 changed files with 218 additions and 33 deletions.
22 changes: 15 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
### Additions
* Added visibility options for the EMI config and recipe tree buttons
* EMI config button now is visible by default when toggled, to prevent people from accidentally hiding the mod without knowing how to undo it
* Search sidebar target can be configured

### Tweaks
* EMI visibility toast is now only shown when help level is verbose, due to other features preventing accidental hiding
* EMI config enum selection screen now is consistent with the rest of the config screen on later versions
* Notable performance improvements to ingredient construction
* Wrap packet sends with a check in later versions
* Improved accuracy of EMI reloading errors

### Fixes
* Fixed JEI dependency on 1.19 versions #780
* Fixed stack default bind not toggling in recipe tree
* #689
* Serialization of stacks with sizes other than 1 now serialize properly #803
* Fix tag ingredient rendering in Fabulous #811
* Fix stack batcher causing certain recipe tree categories to render at the wrong position #790
* Populate item groupps in correct order (fixing duplicate items) #774 #603 #621
* Pick which sidebar search targets #377
* Fix search baking hang #800
* Fix certain JEI integration breaking inconsistently on NeoForge

### API
* Added experimental API to get query if stack is disabled from EmiRegistry
* Added experimental API to get EmiTooltipMetadata from composed tooltips being rendered for mod compatibility
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ minecraft_version=1.19.4
enabled_platforms=fabric,forge

archives_base_name=emi
mod_version=1.1.18
mod_version=1.1.19
maven_group=dev.emi

architectury_version=4.9.83
Expand Down
3 changes: 3 additions & 0 deletions xplat/src/main/java/dev/emi/emi/EmiRenderHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ public static void drawTooltip(Screen screen, EmiDrawContext context, List<Toolt
}

public static void drawTooltip(Screen screen, EmiDrawContext context, List<TooltipComponent> components, int x, int y, int maxWidth) {
if (components.isEmpty()) {
return;
}
y = Math.max(16, y);
// Some mods assume this list will be mutable, oblige them
List<TooltipComponent> mutable = Lists.newArrayList();
Expand Down
8 changes: 8 additions & 0 deletions xplat/src/main/java/dev/emi/emi/api/EmiRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@

public interface EmiRegistry {

/**
* @return Whether the provided stack is disabled.
* Generally, this is not important to check before registering recipes, EMI will handle recipe hiding.
* There are certain cases where checking this and not including stacks in recipes is desired behavior, however.
*/
@ApiStatus.Experimental
boolean isStackDisabled(EmiIngredient stack);

/**
* @return The vanilla recipe manager, for iterating recipe types.
*/
Expand Down
64 changes: 64 additions & 0 deletions xplat/src/main/java/dev/emi/emi/api/render/EmiTooltipMetadata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package dev.emi.emi.api.render;

import java.util.List;

import org.jetbrains.annotations.ApiStatus;

import dev.emi.emi.api.recipe.EmiRecipe;
import dev.emi.emi.api.stack.EmiIngredient;
import dev.emi.emi.api.stack.EmiStack;
import dev.emi.emi.screen.tooltip.EmiTextTooltipWrapper;
import dev.emi.emi.screen.tooltip.RecipeTooltipComponent;
import net.minecraft.client.gui.tooltip.TooltipComponent;

/**
* Represents metadata about tooltips that EMI creates.
* Context includes what stack is having its tooltip rendered.
* This information can be useful for mods modifying the display of tooltips.
*/
@ApiStatus.Experimental
public class EmiTooltipMetadata {
private static final EmiTooltipMetadata EMPTY = new EmiTooltipMetadata(EmiStack.EMPTY, null);
private final EmiIngredient stack;
private final EmiRecipe recipe;

private EmiTooltipMetadata(EmiIngredient stack, EmiRecipe recipe) {
this.stack = stack;
this.recipe = recipe;
}

/**
* @return The stack responsible for the tooltip, or {@link EmiStack#EMPTY} if not present.
*/
public EmiIngredient getStack() {
return stack;
}

/**
* @return The recipe context for the tooltip, or {@code null} if not present.
*/
public EmiRecipe getRecipe() {
return recipe;
}

/**
* Constructs an {@link EmiTooltipMetadata} object based on a list of tooltip components.
* This can be useful for retrieving otherwised erased information, like the {@link EmiIngredient}, from a tooltip.
*/
public static EmiTooltipMetadata of(List<TooltipComponent> tooltip) {
if (!tooltip.isEmpty()) {
TooltipComponent title = tooltip.get(0);
EmiRecipe recipe = null;
for (TooltipComponent comp : tooltip) {
if (comp instanceof RecipeTooltipComponent rtc) {
recipe = rtc.getRecipe();
break;
}
}
if (title instanceof EmiTextTooltipWrapper ettw && !ettw.stack.isEmpty()) {
return new EmiTooltipMetadata(ettw.stack, recipe);
}
}
return EMPTY;
}
}
10 changes: 9 additions & 1 deletion xplat/src/main/java/dev/emi/emi/api/stack/FluidEmiStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import com.google.common.collect.Lists;

import dev.emi.emi.EmiPort;
import dev.emi.emi.api.render.EmiRender;
import dev.emi.emi.api.render.EmiTooltipComponents;
import dev.emi.emi.platform.EmiAgnos;
import dev.emi.emi.screen.tooltip.EmiTextTooltipWrapper;
import net.minecraft.client.gui.tooltip.TooltipComponent;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.fluid.Fluid;
Expand Down Expand Up @@ -82,7 +85,12 @@ public List<Text> getTooltipText() {

@Override
public List<TooltipComponent> getTooltip() {
List<TooltipComponent> list = getTooltipText().stream().map(EmiTooltipComponents::of).collect(Collectors.toList());
List<TooltipComponent> list = Lists.newArrayList();
List<Text> text = getTooltipText();
if (!text.isEmpty()) {
list.add(new EmiTextTooltipWrapper(this, EmiPort.ordered(text.get(0))));
}
list.addAll(text.stream().skip(1).map(EmiTooltipComponents::of).collect(Collectors.toList()));
if (amount > 1) {
list.add(EmiTooltipComponents.getAmount(this));
}
Expand Down
5 changes: 5 additions & 0 deletions xplat/src/main/java/dev/emi/emi/api/stack/ItemEmiStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import dev.emi.emi.platform.EmiAgnos;
import dev.emi.emi.runtime.EmiDrawContext;
import dev.emi.emi.screen.StackBatcher.Batchable;
import dev.emi.emi.screen.tooltip.EmiTextTooltipWrapper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.tooltip.OrderedTextTooltipComponent;
import net.minecraft.client.gui.tooltip.TooltipComponent;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.client.render.DiffuseLighting;
Expand Down Expand Up @@ -158,6 +160,9 @@ public List<TooltipComponent> getTooltip() {
List<TooltipComponent> list = Lists.newArrayList();
if (!isEmpty()) {
list.addAll(EmiAgnos.getItemTooltip(stack));
if (!list.isEmpty() && list.get(0) instanceof OrderedTextTooltipComponent ottc) {
list.set(0, new EmiTextTooltipWrapper(this, ottc));
}
//String namespace = EmiPort.getItemRegistry().getId(stack.getItem()).getNamespace();
//String mod = EmiUtil.getModName(namespace);
//list.add(TooltipComponent.of(EmiLang.literal(mod, Formatting.BLUE, Formatting.ITALIC)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import dev.emi.emi.EmiPort;
import dev.emi.emi.api.render.EmiRender;
import dev.emi.emi.screen.tooltip.EmiTextTooltipWrapper;
import dev.emi.emi.screen.tooltip.IngredientTooltipComponent;
import net.minecraft.client.gui.tooltip.TooltipComponent;
import net.minecraft.client.util.math.MatrixStack;
Expand Down Expand Up @@ -99,7 +100,7 @@ public void render(MatrixStack matrices, int x, int y, float delta, int flags) {
@Override
public List<TooltipComponent> getTooltip() {
List<TooltipComponent> tooltip = Lists.newArrayList();
tooltip.add(TooltipComponent.of(EmiPort.ordered(EmiPort.translatable("tooltip.emi.accepts"))));
tooltip.add(new EmiTextTooltipWrapper(this, EmiPort.ordered(EmiPort.translatable("tooltip.emi.accepts"))));
tooltip.add(new IngredientTooltipComponent(ingredients));
int item = (int) (System.currentTimeMillis() / 1000 % ingredients.size());
tooltip.addAll(ingredients.get(item).copy().setAmount(amount).getTooltip());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import dev.emi.emi.mixin.accessor.ItemRendererAccessor;
import dev.emi.emi.registry.EmiTags;
import dev.emi.emi.runtime.EmiDrawContext;
import dev.emi.emi.screen.tooltip.EmiTextTooltipWrapper;
import dev.emi.emi.screen.tooltip.RemainderTooltipComponent;
import dev.emi.emi.screen.tooltip.TagTooltipComponent;
import net.minecraft.client.MinecraftClient;
Expand Down Expand Up @@ -134,7 +135,7 @@ public void render(MatrixStack matrices, int x, int y, float delta, int flags) {
.invokeRenderBakedItemModel(model,
ItemStack.EMPTY, LightmapTextureManager.MAX_LIGHT_COORDINATE, OverlayTexture.DEFAULT_UV, ms,
ItemRenderer.getDirectItemGlintConsumer(immediate,
TexturedRenderLayers.getItemEntityTranslucentCull(), true, false));
TexturedRenderLayers.getEntityTranslucentCull(), true, false));
immediate.draw();

if (!model.isSideLit()) {
Expand Down Expand Up @@ -163,7 +164,7 @@ public void render(MatrixStack matrices, int x, int y, float delta, int flags) {
@Override
public List<TooltipComponent> getTooltip() {
List<TooltipComponent> list = Lists.newArrayList();
list.add(TooltipComponent.of(EmiPort.ordered(EmiTags.getTagName(key))));
list.add(new EmiTextTooltipWrapper(this, EmiPort.ordered(EmiTags.getTagName(key))));
if (EmiUtil.showAdvancedTooltips()) {
list.add(TooltipComponent.of(EmiPort.ordered(EmiPort.literal("#" + id, Formatting.DARK_GRAY))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ default JsonElement serialize(T stack) {
JsonObject json = new JsonObject();
json.addProperty("type", getType());
json.addProperty("id", stack.getId().toString());
if (stack.hasNbt()) {
json.addProperty("nbt", stack.getNbt().asString());
}
if (stack.getAmount() != 1) {
json.addProperty("amount", stack.getAmount());
}
Expand Down
4 changes: 4 additions & 0 deletions xplat/src/main/java/dev/emi/emi/config/EmiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public class EmiConfig {
public static IndexSource indexSource = IndexSource.CREATIVE;

@ConfigGroup("general.search")
@Comment("Which sidebar should be searched using the search bar.")
@ConfigValue("general.search-sidebar")
public static SidebarSide searchSidebar = SidebarSide.RIGHT;

@Comment("Whether normal search queries should include the tooltip.")
@ConfigValue("general.search-tooltip-by-default")
public static boolean searchTooltipByDefault = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.emi.emi.api.EmiApi;
import dev.emi.emi.jemi.JemiUtil;
import dev.emi.emi.screen.EmiScreenManager;
import dev.emi.emi.screen.EmiScreenManager.SidebarPanel;
import mezz.jei.api.ingredients.IIngredientType;
import mezz.jei.api.runtime.IIngredientFilter;

Expand All @@ -23,7 +24,11 @@ public String getFilterText() {

@Override
public <T> List<T> getFilteredIngredients(IIngredientType<T> ingredientType) {
return EmiScreenManager.getSearchPanel().space.getStacks().stream()
SidebarPanel search = EmiScreenManager.getSearchPanel();
if (search == null || search.space == null) {
return List.of();
}
return search.space.getStacks().stream()
.map(i -> JemiUtil.getTyped(i.getEmiStacks().get(0)))
.filter(Optional::isPresent).map(Optional::get)
.map(i -> i.getIngredient(ingredientType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import mezz.jei.api.recipe.RecipeType;
import mezz.jei.api.runtime.IRecipesGui;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;

public class JemiRecipesGui implements IRecipesGui {

Expand Down Expand Up @@ -59,4 +60,9 @@ public <T> Optional<T> getIngredientUnderMouse(IIngredientType<T> ingredientType
}
return Optional.empty();
}

//@Override
public Optional<Screen> getParentScreen() {
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class PluginCallerMixin {
@Unique
private static final Set<Identifier> SKIPPED = Sets.newHashSet(
EmiPort.id("jei", "minecraft"), EmiPort.id("jei", "gui"), EmiPort.id("jei", "fabric_gui"), EmiPort.id("jei", "forge_gui")
EmiPort.id("jei", "minecraft"), EmiPort.id("jei", "gui"), EmiPort.id("jei", "fabric_gui"), EmiPort.id("jei", "forge_gui"), EmiPort.id("jei", "neoforge_gui")
);
@Unique
private static final Set<String> SKIPPED_MODS = JemiUtil.getHandledMods();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public static List<Bounds> getExclusion(EmiScreenBase base) {
// EMI buttons
list.add(new Bounds(0, screen.height - 22, base.bounds().left(), 22));
// Search bar
list.add(new Bounds(EmiScreenManager.search.x - 1, EmiScreenManager.search.y - 1, EmiScreenManager.search.getWidth() + 2, EmiScreenManager.search.getHeight() + 2));
if (EmiScreenManager.search.isVisible()) {
list.add(new Bounds(EmiScreenManager.search.x - 1, EmiScreenManager.search.y - 1, EmiScreenManager.search.getWidth() + 2, EmiScreenManager.search.getHeight() + 2));
}
try {
if (fromClass.containsKey(screen.getClass())) {
for (EmiExclusionArea exclusion : fromClass.get(screen.getClass())) {
Expand Down
6 changes: 6 additions & 0 deletions xplat/src/main/java/dev/emi/emi/registry/EmiRegistryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import dev.emi.emi.api.stack.EmiIngredient;
import dev.emi.emi.api.stack.EmiStack;
import dev.emi.emi.api.stack.serializer.EmiIngredientSerializer;
import dev.emi.emi.runtime.EmiHidden;
import dev.emi.emi.runtime.EmiReloadLog;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
Expand All @@ -28,6 +29,11 @@
public class EmiRegistryImpl implements EmiRegistry {
private static final MinecraftClient client = MinecraftClient.getInstance();

@Override
public boolean isStackDisabled(EmiIngredient stack) {
return EmiHidden.isDisabled(stack);
}

@Override
public RecipeManager getRecipeManager() {
return client.world.getRecipeManager();
Expand Down
10 changes: 8 additions & 2 deletions xplat/src/main/java/dev/emi/emi/registry/EmiStackList.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.Supplier;

Expand Down Expand Up @@ -80,7 +81,7 @@ public static void reload() {
EmiLog.info("Reloading item groups on client thread...");
Map<ItemGroup, Collection<ItemStack>> itemGroupToStacksMap = client.submit(() -> {
Map<ItemGroup, Collection<ItemStack>> map = new Reference2ReferenceOpenHashMap<>();
for (ItemGroup group : ItemGroups.getGroups()) {
Consumer<ItemGroup> itemGroupConsumer = group -> {
String groupName = "null";
try {
groupName = group.getDisplayName().toString();
Expand All @@ -90,7 +91,12 @@ public static void reload() {
EmiLog.error("Creative item group " + groupName + " threw while EMI was attempting to construct the index, items may be missing.");
EmiLog.error(e);
}
}
};
List<ItemGroup> itemGroups = ItemGroups.getGroups();
// Category item groups must be updated before non-category ones, otherwise the search group will
// read outdated item lists
itemGroups.stream().filter(g -> g.getType() == ItemGroup.Type.CATEGORY).forEach(itemGroupConsumer);
itemGroups.stream().filter(g -> g.getType() != ItemGroup.Type.CATEGORY).forEach(itemGroupConsumer);
return map;
}).join();
EmiLog.info("Reloading item groups on client thread took " + (System.currentTimeMillis() - groupReloadStart) + "ms");
Expand Down
4 changes: 2 additions & 2 deletions xplat/src/main/java/dev/emi/emi/registry/EmiTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static <T> EmiIngredient getIngredient(Class<T> clazz, List<EmiStack> sta
if (keys != null) {
for (TagKey<T> key : keys) {
List<T> values = (List<T>) TAG_CONTENTS.get(key);
map.keySet().removeAll(values);
values.forEach(map::remove);
}
} else {
keys = Lists.newArrayList();
Expand All @@ -117,7 +117,7 @@ public static <T> EmiIngredient getIngredient(Class<T> clazz, List<EmiStack> sta
continue;
}
if (map.keySet().containsAll(values)) {
map.keySet().removeAll(values);
values.forEach(map::remove);
keys.add(key);
}
if (map.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ public void run() {
continue;
}
MinecraftClient client = MinecraftClient.getInstance();
if (client.world.getRecipeManager() == null) {
if (client.world == null) {
EmiReloadLog.warn("World is null");
break;
} else if (client.world.getRecipeManager() == null) {
EmiReloadLog.warn("Recipe Manager is null");
break;
}
Expand Down
Loading

0 comments on commit b6a9eb8

Please sign in to comment.