Skip to content

Commit

Permalink
1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyploszaj committed Feb 18, 2024
1 parent a8075ce commit 5dd26c4
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 29 deletions.
12 changes: 7 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
### Fixes
* Fixed fill recipe not working in the inventory grid with JEI present #426
* Fixed 1.20.4 effects displaying with the wrong time #435
* Fixed Forge/NeoForge recipe book causing offset in EMI #425
* Fixed input behaving as if EMI is present even if it's not in certain screens
### Tweaks
* Search now has a history of previous queries #147
* Made mod name tooltip more likely to apply if other mods are making changes
* EMI's index construction is now slightly safer when other mods cause issues

### API
* Added an experimental "recipe decorator" API
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.20.4
enabled_platforms=fabric,neoforge

archives_base_name=emi
mod_version=1.1.1
mod_version=1.1.2
maven_group=dev.emi

architectury_version=4.9.83
Expand Down
2 changes: 1 addition & 1 deletion xplat/src/main/java/dev/emi/emi/mixin/ItemStackMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

@Mixin(value = ItemStack.class, priority = 2000)
@Mixin(value = ItemStack.class, priority = 500)
public class ItemStackMixin {

@Inject(at = @At("RETURN"), method = "getTooltip")
Expand Down
65 changes: 43 additions & 22 deletions xplat/src/main/java/dev/emi/emi/registry/EmiStackList.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,44 +62,65 @@ public static void reload() {
ItemGroups.updateDisplayContext(client.player.networkHandler.getEnabledFeatures(), false, client.world.getRegistryManager());
} catch (Throwable t) {
EmiLog.error("Failed to update creative tabs. Using fallback index.");
t.printStackTrace();
EmiLog.error(t);
}
List<IndexGroup> groups = Lists.newArrayList();
Map<String, IndexGroup> namespaceGroups = new LinkedHashMap<>();
for (Item item : EmiPort.getItemRegistry()) {
EmiStack stack = EmiStack.of(item);
namespaceGroups.computeIfAbsent(stack.getId().getNamespace(), (k) -> new IndexGroup()).stacks.add(stack);
String itemName = "null";
try {
itemName = item.toString();
EmiStack stack = EmiStack.of(item);
namespaceGroups.computeIfAbsent(stack.getId().getNamespace(), (k) -> new IndexGroup()).stacks.add(stack);
} catch (Exception e) {
EmiLog.error("Item " + itemName + " threw while EMI was attempting to construct the index, items may be missing.");
EmiLog.error(e);
}
}
if (EmiConfig.indexSource != IndexSource.REGISTERED) {
for (ItemGroup group : ItemGroups.getGroups()) {
Object2IntMap<String> usedNamespaces = new Object2IntOpenHashMap<>();
IndexGroup ig = new IndexGroup();
Collection<ItemStack> searchStacks = group.getSearchTabStacks();
for (ItemStack stack : searchStacks) {
EmiStack es = EmiStack.of(stack);
String namespace = es.getId().getNamespace();
usedNamespaces.put(namespace, usedNamespaces.getOrDefault(namespace, 0) + 1);
ig.stacks.add(es);
}
if (EmiConfig.indexSource == IndexSource.CREATIVE) {
for (String namespace : usedNamespaces.keySet()) {
if (namespaceGroups.containsKey(namespace)) {
IndexGroup ng = namespaceGroups.get(namespace);
if (usedNamespaces.getInt(namespace) * 3 >= searchStacks.size() || usedNamespaces.getInt(namespace) * 3 >= ng.stacks.size()) {
ng.suppressedBy.add(ig);
String groupName = "null";
try {
groupName = group.getDisplayName().getString();
Object2IntMap<String> usedNamespaces = new Object2IntOpenHashMap<>();
IndexGroup ig = new IndexGroup();
Collection<ItemStack> searchStacks = group.getSearchTabStacks();
for (ItemStack stack : searchStacks) {
EmiStack es = EmiStack.of(stack);
String namespace = es.getId().getNamespace();
usedNamespaces.put(namespace, usedNamespaces.getOrDefault(namespace, 0) + 1);
ig.stacks.add(es);
}
if (EmiConfig.indexSource == IndexSource.CREATIVE) {
for (String namespace : usedNamespaces.keySet()) {
if (namespaceGroups.containsKey(namespace)) {
IndexGroup ng = namespaceGroups.get(namespace);
if (usedNamespaces.getInt(namespace) * 3 >= searchStacks.size() || usedNamespaces.getInt(namespace) * 3 >= ng.stacks.size()) {
ng.suppressedBy.add(ig);
}
}
}
}
groups.add(ig);
} catch (Exception e) {
EmiLog.error("Creative item group " + groupName + " threw while EMI was attempting to construct the index, items may be missing.");
EmiLog.error(e);
}
groups.add(ig);
}
}
groups.addAll(namespaceGroups.values());
IndexGroup fluidGroup = new IndexGroup();
for (Fluid fluid : EmiPort.getFluidRegistry()) {
if (fluid.isStill(fluid.getDefaultState()) || (fluid instanceof FlowableFluid ff && ff.getStill() == Fluids.EMPTY)) {
EmiStack fs = EmiStack.of(fluid);
fluidGroup.stacks.add(fs);
String fluidName = null;
try {
fluidName = fluid.toString();
if (fluid.isStill(fluid.getDefaultState()) || (fluid instanceof FlowableFluid ff && ff.getStill() == Fluids.EMPTY)) {
EmiStack fs = EmiStack.of(fluid);
fluidGroup.stacks.add(fs);
}
} catch (Exception e) {
EmiLog.error("Fluid " + fluidName + " threw while EMI was attempting to construct the index, stack may be missing.");
EmiLog.error(e);
}
}
groups.add(fluidGroup);
Expand Down
24 changes: 24 additions & 0 deletions xplat/src/main/java/dev/emi/emi/screen/widget/EmiSearchWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

public class EmiSearchWidget extends TextFieldWidget {
private static final Pattern ESCAPE = Pattern.compile("\\\\.");
private List<String> searchHistory = Lists.newArrayList();
private int searchHistoryIndex = 0;
private List<Pair<Integer, Style>> styles;
private long lastClick = 0;
private String last = "";
Expand Down Expand Up @@ -145,6 +147,18 @@ public void swap() {

@Override
public void setFocused(boolean focused) {
if (!focused) {
searchHistoryIndex = 0;
String currentSearch = getText();
if (!currentSearch.isBlank() && !currentSearch.isEmpty()) {
searchHistory.removeIf(String::isBlank);
searchHistory.remove(currentSearch);
searchHistory.add(0, currentSearch);
if (searchHistory.size() > 36) {
searchHistory.remove(searchHistory.size() - 1);
}
}
}
isFocused = focused;
super.setFocused(focused);
}
Expand Down Expand Up @@ -193,6 +207,16 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
EmiPort.focus(this, false);
return true;
}
if (keyCode == GLFW.GLFW_KEY_UP || keyCode == GLFW.GLFW_KEY_DOWN) {
int offset = keyCode == GLFW.GLFW_KEY_UP ? 1 : -1;
if (searchHistoryIndex + offset >= 0 && searchHistoryIndex + offset < searchHistory.size()) {
if (searchHistoryIndex >= 0 && searchHistoryIndex < searchHistory.size()) {
searchHistory.set(searchHistoryIndex, getText());
}
searchHistoryIndex += offset;
setText(searchHistory.get(searchHistoryIndex));
}
}
}
return super.keyPressed(keyCode, scanCode, modifiers);
}
Expand Down

0 comments on commit 5dd26c4

Please sign in to comment.