Skip to content

Commit

Permalink
It Builds Again :D Also REI Tooltips 👀
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAHuman-xD committed Jan 10, 2024
1 parent 3feb2ab commit 5493dab
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 14 deletions.
12 changes: 7 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repositories {
url = "https://modmaven.dev"
}
maven {
name = "Cloth Config, Rei"
name = "Cloth Config, Cloth Math, Rei"
url = "https://maven.shedaniel.me/"
}
maven {
Expand Down Expand Up @@ -57,12 +57,14 @@ dependencies {
exclude(group: "net.fabricmc.fabric-api")
}

modRuntimeOnly("me.shedaniel:RoughlyEnoughItems-fabric:$rei_version")
modCompileOnly("me.shedaniel:RoughlyEnoughItems-runtime-fabric:$rei_version") {
modRuntimeOnly("me.shedaniel:RoughlyEnoughItems-fabric:${rei_version}")
modCompileOnly("me.shedaniel:RoughlyEnoughItems-runtime-fabric:${rei_version}") {
exclude(group: "net.fabricmc.fabric-api")
}
modCompileOnly("me.shedaniel:RoughlyEnoughItems-api-fabric:$rei_version")
modCompileOnly("me.shedaniel:RoughlyEnoughItems-default-plugin-fabric:$rei_version")
modCompileOnly("me.shedaniel:RoughlyEnoughItems-api-fabric:${rei_version}")
modCompileOnly("me.shedaniel:RoughlyEnoughItems-default-plugin-fabric:${rei_version}")
modCompileOnly("dev.architectury:architectury-fabric:${architectury_version}")
modCompileOnly("me.shedaniel.cloth:basic-math:${cloth_math_version}")

modApi "com.terraformersmc:modmenu:${project.mod_menu_version}"
modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") {
Expand Down
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ mod_menu_version=9.0.0-pre.1
cloth_config_version=13.0.114

# https://www.curseforge.com/minecraft/mc-mods/architectury-api/files?page=1&pageSize=20&gameVersionTypeId=4
architectury_version=11.0.8
architectury_version=11.0.9

# https://github.com/shedaniel/cloth-basic-math
cloth_math_version=0.6.1

# https://projectlombok.org/setup/gradle
lombok_version=1.18.30
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import me.justahuman.slimefun_essentials.utils.JsonUtils;
import me.justahuman.slimefun_essentials.utils.TextureUtils;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.OrderedText;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import java.util.Collections;
Expand Down Expand Up @@ -55,4 +57,8 @@ public void draw(DrawContext graphics, int x, int y, boolean dark) {
public void draw(DrawContext graphics, int x, int y) {
draw(graphics, x, y, false);
}

public Text text() {
return Text.translatable("slimefun_essentials.recipe.label." + this.id);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package me.justahuman.slimefun_essentials.compat.emi;

import dev.emi.emi.EmiPort;
import dev.emi.emi.api.render.EmiTexture;
import dev.emi.emi.api.widget.TextureWidget;
import me.justahuman.slimefun_essentials.client.SlimefunLabel;
import me.justahuman.slimefun_essentials.utils.TextureUtils;
import net.minecraft.client.gui.tooltip.TooltipComponent;
import net.minecraft.text.Text;

import java.util.List;

public class EmiLabel extends TextureWidget {
public EmiLabel(String id, EmiTexture texture, int x, int y) {
super(texture.texture, x, y, texture.width, texture.height, texture.u, texture.v, texture.regionWidth, texture.regionHeight, texture.textureWidth, texture.textureHeight);

tooltip((mx, my) -> List.of(TooltipComponent.of(EmiPort.ordered(EmiPort.translatable("slimefun_essentials.recipe.label." + id)))));
tooltip((mx, my) -> List.of(TooltipComponent.of(Text.translatable("slimefun_essentials.recipe.label." + id).asOrderedText())));
}

public EmiLabel(SlimefunLabel slimefunLabel, int x, int y) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.justahuman.slimefun_essentials.compat.emi.recipes;

import dev.emi.emi.EmiPort;
import dev.emi.emi.api.recipe.EmiRecipe;
import dev.emi.emi.api.recipe.EmiRecipeCategory;
import dev.emi.emi.api.render.EmiTexture;
Expand All @@ -19,11 +18,13 @@
import me.justahuman.slimefun_essentials.compat.emi.ReverseFillingArrowWidget;
import me.justahuman.slimefun_essentials.utils.TextureUtils;
import net.minecraft.client.gui.tooltip.TooltipComponent;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.function.BiFunction;

public class ProcessRecipe extends RecipeRenderer implements EmiRecipe {
protected final SlimefunCategory slimefunCategory;
Expand Down Expand Up @@ -129,7 +130,7 @@ protected void addEnergy(WidgetHolder widgets, OffsetBuilder offsets) {
protected void addEnergy(WidgetHolder widgets, int x, int y) {
final int totalEnergy = this.slimefunRecipe.energy() * Math.max(1, this.slimefunRecipe.time() / 10 / (this.slimefunCategory.hasSpeed() ? this.slimefunCategory.speed() : 1));
widgets.addTexture(EmiUtils.EMPTY_CHARGE, x, y);
widgets.addAnimatedTexture(totalEnergy >= 0 ? EmiUtils.GAIN_CHARGE : EmiUtils.LOOSE_CHARGE, x, y, 1000, false, totalEnergy < 0, totalEnergy < 0).tooltip((mx, my) -> List.of(TooltipComponent.of(EmiPort.ordered(EmiPort.translatable("slimefun_essentials.recipe.energy." + (totalEnergy >= 0 ? "generate" : "use"), TextureUtils.numberFormat.format(Math.abs(totalEnergy)))))));
widgets.addAnimatedTexture(totalEnergy >= 0 ? EmiUtils.GAIN_CHARGE : EmiUtils.LOOSE_CHARGE, x, y, 1000, false, totalEnergy < 0, totalEnergy < 0).tooltip(tooltip("slimefun_essentials.recipe.energy." + (totalEnergy >= 0 ? "generate" : "use"), TextureUtils.numberFormat.format(Math.abs(totalEnergy))));
}

protected void addArrowWithCheck(WidgetHolder widgets, OffsetBuilder offsets) {
Expand All @@ -152,7 +153,7 @@ protected void addArrow(WidgetHolder widgets, int x, int y, boolean backwards) {
}

protected void addFillingArrow(WidgetHolder widgets, int x, int y, boolean backwards, int sfTicks, int millis) {
widgets.add(backwards ? new ReverseFillingArrowWidget(x, y, millis) : new FillingArrowWidget(x, y, millis)).tooltip((mx, my) -> List.of(TooltipComponent.of(EmiPort.ordered(EmiPort.translatable("slimefun_essentials.recipes.time", TextureUtils.numberFormat.format(sfTicks / 2f), TextureUtils.numberFormat.format(sfTicks * 10L))))));
widgets.add(backwards ? new ReverseFillingArrowWidget(x, y, millis) : new FillingArrowWidget(x, y, millis)).tooltip(tooltip("slimefun_essentials.recipes.time", TextureUtils.numberFormat.format(sfTicks / 2f), TextureUtils.numberFormat.format(sfTicks * 10L)));
}

protected void addOutputsOrEnergy(WidgetHolder widgets, OffsetBuilder offsets) {
Expand All @@ -169,4 +170,8 @@ protected void addOutputs(WidgetHolder widgets, OffsetBuilder offsets) {
offsets.x().addOutput();
}
}

protected BiFunction<Integer, Integer, List<TooltipComponent>> tooltip(String key, Object... args) {
return (mx, my) -> List.of(TooltipComponent.of(Text.translatable(key, args).asOrderedText()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public void addWidgets(WidgetHolder widgets) {
// Display Energy
addEnergyWithCheck(widgets, offsets);


int i = 0;
for (int y = 1; y <= 3; y++) {
for (int x = 1; x <= 2; x++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import me.justahuman.slimefun_essentials.compat.rei.displays.SmelteryDisplay;
import me.justahuman.slimefun_essentials.utils.TextureUtils;
import me.justahuman.slimefun_essentials.utils.Utils;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.REIRuntime;
import me.shedaniel.rei.api.client.gui.widgets.Widget;
import me.shedaniel.rei.api.client.gui.widgets.Widgets;
Expand Down Expand Up @@ -106,6 +107,10 @@ public static Widget widgetFromSlimefunLabel(SlimefunLabel slimefunLabel, int x,
return Widgets.createDrawableWidget((graphics, mouseX, mouseY, delta) -> slimefunLabel.draw(graphics, x, y, REIRuntime.getInstance().isDarkThemeEnabled()));
}

public static Widget toolTipForSlimefunLabel(SlimefunLabel slimefunLabel, int x, int y) {
return Widgets.createTooltip(new Rectangle(x, y, slimefunLabel.width(), slimefunLabel.height()), slimefunLabel.text());
}

/**
* I would like to note that a lot of the logic for this method came from EMI: AnimatedTextureWidget.java
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.util.EntryStacks;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;

import java.util.List;

Expand Down Expand Up @@ -50,6 +51,7 @@ public List<Widget> setupDisplay(OffsetBuilder offsets, List<Widget> widgets, Re
if (this.slimefunRecipe.hasLabels()) {
for (SlimefunLabel slimefunLabel : this.slimefunRecipe.labels()) {
widgets.add(ReiIntegration.widgetFromSlimefunLabel(slimefunLabel, offsets.getX(), offsets.label()));
widgets.add(ReiIntegration.toolTipForSlimefunLabel(slimefunLabel, offsets.getX(), offsets.label()));
offsets.x().addLabel();
}
}
Expand Down Expand Up @@ -88,6 +90,7 @@ protected void addEnergy(List<Widget> widgets, int x, int y) {
final int totalEnergy = this.slimefunRecipe.energy() * Math.max(1, this.slimefunRecipe.time() / 10 / (this.slimefunCategory.hasSpeed() ? this.slimefunCategory.speed() : 1));
widgets.add(ReiIntegration.widgetFromSlimefunLabel(TextureUtils.ENERGY, x, y));
widgets.add(ReiIntegration.widgetFromSlimefunLabel((totalEnergy >= 0 ? TextureUtils.ENERGY_POSITIVE : TextureUtils.ENERGY_NEGATIVE), x, y, 1000, false, totalEnergy < 0, totalEnergy < 0));
widgets.add(Widgets.createTooltip(new Rectangle(x, y, TextureUtils.ENERGY_WIDTH, TextureUtils.ENERGY_HEIGHT), Text.translatable("slimefun_essentials.recipe.energy." + (totalEnergy >= 0 ? "generate" : "use"), TextureUtils.numberFormat.format(Math.abs(totalEnergy)))));
}

protected void addSlot(List<Widget> widgets, OffsetBuilder offsets, EntryIngredient entryIngredient) {
Expand Down Expand Up @@ -132,6 +135,7 @@ protected void addArrow(List<Widget> widgets, int x, int y, boolean backwards) {
final int sfTicks = Math.max(1, this.slimefunRecipe.time() / 10 / (this.slimefunCategory.hasSpeed() ? this.slimefunCategory.speed() : 1));
final int millis = sfTicks * 500;
widgets.add(ReiIntegration.widgetFromSlimefunLabel((backwards ? TextureUtils.FILLED_BACKWARDS_ARROW : TextureUtils.FILLED_ARROW), x, y, millis, true, backwards, false));
widgets.add(Widgets.createTooltip(new Rectangle(x, y, TextureUtils.ARROW_WIDTH, TextureUtils.ARROW_HEIGHT), Text.translatable("slimefun_essentials.recipes.time", TextureUtils.numberFormat.format(sfTicks / 2), TextureUtils.numberFormat.format(sfTicks * 10L))));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"slimefun_essentials.mixins.json"
],
"depends": {
"fabricloader": ">=0.14.22",
"fabricloader": ">=0.15.2",
"fabric": "*",
"minecraft": "1.20.2"
"minecraft": "1.20.4"
}
}

0 comments on commit 5493dab

Please sign in to comment.