Skip to content

Commit

Permalink
Tooltips, fixes, adjustments, README
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAHuman-xD committed Jan 10, 2024
1 parent 5493dab commit c31f002
Show file tree
Hide file tree
Showing 16 changed files with 285 additions and 61 deletions.
39 changes: 25 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
### SlimefunEssentials
Slimefun Essentials is a minecraft mod dedicated to add support for Slimefun4 items and mechanics to other client sided mods.

### What does it do:
- Adds Support for Slimefun Recipes to EMI, REI, JEI
- Adds Support for Custom Textures for Placed Slimefun Blocks (Requires More Block Predicates on the Client and Requires Slimefun Server Essentials on the Server)
- Adds Support for Jade Tooltips for Placed Slimefun Blocks (Requires Jade on the Client and Requires Slimefun Server Essentials on the Server)
- More Coming Soon™

### Downloads
- [Github](https://github.com/JustAHuman-xD/SlimefunEssentials/releases)
- [Modrinth](https://modrinth.com/mod/slimefun-essentials)
- [Curseforge](https://www.curseforge.com/minecraft/mc-mods/slimefun-essentials)

### Dependencies
- Mod Menu (Optional)
- Cloth Config API (Optional)
- More Block Predicates (Optional)
- Jade (Optional)
- One of the following: (Optional)
- EMI
- JEI
- REI

### Configuration:
- "use_custom_textures"
- Should Slimefun Essentials enabled support for Custom Textures
- Requires More Block Predicates
- Requires Slimefun Server Essentials on the Server
- "block_features"
- Should Slimefun Essentials enabled support for Custom Textures & Jade Integration
- Requires More Block Predicates (For Custom Textures)
- Requires Jade (For Well Jade Integration)
- Requires Slimefun Server Essentials on the Server (For Any Features)
- "recipe_features"
- Should Slimefun Essentials add support for Slimefun Recipes
- Requires EMI, JEI, or REI
- "auto_toggle_addons"
- Should Slimefun Essentials attempt to automatically toggle on or off Addons when Joining a Server with Slimefun Server Essentials installed

### Downloads
- https://github.com/JustAHuman-xD/SlimefunEssentials/releases
- https://modrinth.com/mod/slimefun-essentials
- https://www.curseforge.com/minecraft/mc-mods/slimefun-essentials

### What does it do:
- Adds Support for Slimefun Recipes to EMI, REI, JEI
- Adds Support for Custom Textures for Placed Slimefun Blocks (Requires More Block Predicates on the Client and Requires Slimefun Server Essentials on the Server)
- More Coming Soon™
- "addons"
- A list of addons to support
- Items **for all features** will only be supported if the addon they come from is in this list
Original file line number Diff line number Diff line change
Expand Up @@ -112,44 +112,49 @@ public Offset subtract(int subtract) {
return this;
}

public void addLabel() {
addLabel(true);
public Offset addLabel() {
return addLabel(true);
}

public void addLabel(boolean padding) {
public Offset addLabel(boolean padding) {
this.value += TextureUtils.LABEL_SIZE + (padding ? TextureUtils.PADDING : 0);
return this;
}

public void addEnergy() {
addEnergy(true);
public Offset addEnergy() {
return addEnergy(true);
}

public void addEnergy(boolean padding) {
public Offset addEnergy(boolean padding) {
this.value += TextureUtils.ENERGY_WIDTH + (padding ? TextureUtils.PADDING : 0);
return this;
}

public void addSlot() {
addSlot(true);
public Offset addSlot() {
return addSlot(true);
}

public void addSlot(boolean padding) {
public Offset addSlot(boolean padding) {
this.value += TextureUtils.SLOT_SIZE + (padding ? TextureUtils.PADDING : 0);
return this;
}

public void addArrow() {
addArrow(true);
public Offset addArrow() {
return addArrow(true);
}

public void addArrow(boolean padding) {
public Offset addArrow(boolean padding) {
this.value += TextureUtils.ARROW_WIDTH + (padding ? TextureUtils.PADDING : 0);
return this;
}

public void addOutput() {
addOutput(true);
public Offset addOutput() {
return addOutput(true);
}

public void addOutput(boolean padding) {
public Offset addOutput(boolean padding) {
this.value += TextureUtils.OUTPUT_SIZE + (padding ? TextureUtils.PADDING : 0);
return this;
}

public Offset addPadding() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package me.justahuman.slimefun_essentials.client;

import me.justahuman.slimefun_essentials.utils.Utils;
import net.minecraft.item.ItemStack;

public record SlimefunItemStack(String id, ItemStack itemStack) {
public SlimefunItemStack(ItemStack itemStack) {
this(Utils.getSlimefunId(itemStack), itemStack);
}

public SlimefunItemStack setAmount(int amount) {
itemStack.setCount(amount);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ public void draw(DrawContext graphics, int x, int y) {
}

public Text text() {
return Text.translatable("slimefun_essentials.recipe.label." + this.id);
return Text.translatable("slimefun_essentials.recipes.label." + this.id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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(Text.translatable("slimefun_essentials.recipe.label." + id).asOrderedText())));
tooltip((mx, my) -> List.of(TooltipComponent.of(Text.translatable("slimefun_essentials.recipes.label." + id).asOrderedText())));
}

public EmiLabel(SlimefunLabel slimefunLabel, int x, int y) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public AncientAltarRecipe(SlimefunCategory slimefunCategory, SlimefunRecipe slim
@Override
public void addWidgets(WidgetHolder widgets) {
final OffsetBuilder offsets = new OffsetBuilder(this, this.slimefunRecipe);


// Special Inputs
widgets.addSlot(this.inputs.get(3), offsets.getX(), offsets.slot()).backgroundTexture(TextureUtils.WIDGETS, 0, 0);
offsets.x().addSlot(false);
widgets.addSlot(this.inputs.get(0), offsets.getX(), offsets.slot() + TextureUtils.SLOT_SIZE).backgroundTexture(TextureUtils.WIDGETS, 0, 0);
Expand All @@ -34,8 +35,11 @@ public void addWidgets(WidgetHolder widgets) {
offsets.x().addSlot(false);
widgets.addSlot(this.inputs.get(5), offsets.getX(), offsets.slot()).backgroundTexture(TextureUtils.WIDGETS, 0, 0);
offsets.x().addSlot();
widgets.addFillingArrow(offsets.getX(), offsets.arrow(), this.slimefunRecipe.time() * 1000);
offsets.x().addArrow();

// Add Arrow
addArrowWithCheck(widgets, offsets);

// Output
widgets.addSlot(this.outputs.get(0), offsets.getX(), offsets.slot());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,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(tooltip("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.recipes.energy." + (totalEnergy >= 0 ? "generate" : "use"), TextureUtils.numberFormat.format(Math.abs(totalEnergy))));
}

protected void addArrowWithCheck(WidgetHolder widgets, OffsetBuilder offsets) {
Expand All @@ -140,7 +140,7 @@ protected void addArrowWithCheck(WidgetHolder widgets, OffsetBuilder offsets) {

protected void addArrowWithCheck(WidgetHolder widgets, int x, int y, boolean backwards) {
if (this.slimefunRecipe.hasTime()) {
final int sfTicks = Math.max(1, this.slimefunRecipe.time() / 10 / (this.slimefunCategory.hasSpeed() ? this.slimefunCategory.speed() : 1));
final int sfTicks = this.slimefunRecipe.sfTicks(this.slimefunCategory.hasSpeed() ? this.slimefunCategory.speed() : 1);
final int millis = sfTicks * 500;
addFillingArrow(widgets, x, y, backwards, sfTicks, millis);
} else {
Expand Down Expand Up @@ -171,7 +171,7 @@ protected void addOutputs(WidgetHolder widgets, OffsetBuilder offsets) {
}
}

protected BiFunction<Integer, Integer, List<TooltipComponent>> tooltip(String key, Object... args) {
return (mx, my) -> List.of(TooltipComponent.of(Text.translatable(key, args).asOrderedText()));
protected List<TooltipComponent> tooltip(String key, Object... args) {
return List.of(TooltipComponent.of(Text.translatable(key, args).asOrderedText()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
import mezz.jei.api.recipe.RecipeIngredientRole;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class AncientAltarCategory extends ProcessCategory {
public AncientAltarCategory(IGuiHelper guiHelper, SlimefunCategory slimefunCategory, ItemStack catalyst) {
Expand Down Expand Up @@ -62,8 +67,20 @@ public void draw(SlimefunRecipe recipe, IRecipeSlotsView recipeSlotsView, DrawCo
offsets.x().addSlot(false);
TextureUtils.PEDESTAL.draw(graphics, offsets.getX(), offsets.slot());
offsets.x().addSlot();
addArrow(graphics, offsets.getX(), offsets.arrow(), false);
addArrow(graphics, recipe, offsets.getX(), offsets.arrow(), false);
offsets.x().addArrow();
TextureUtils.SLOT.draw(graphics, offsets.getX(), offsets.slot());
}

@NotNull
@Override
public List<Text> getTooltipStrings(SlimefunRecipe recipe, IRecipeSlotsView recipeSlotsView, double mouseX, double mouseY) {
final List<Text> tooltips = new ArrayList<>();
final OffsetBuilder offsets = new OffsetBuilder(this, recipe);
offsets.x().addSlot(false).addSlot(false).addSlot(false).addSlot(false).addSlot();
if (tooltipActive(mouseX, mouseY, offsets.getX(), offsets.arrow(), TextureUtils.ARROW)) {
tooltips.add(timeTooltip(recipe));
}
return tooltips;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
import mezz.jei.api.recipe.RecipeIngredientRole;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class GridCategory extends ProcessCategory {
protected final int side;
Expand Down Expand Up @@ -76,4 +81,33 @@ public void draw(SlimefunRecipe recipe, IRecipeSlotsView recipeSlotsView, DrawCo
// Display Outputs
addOutputsOrEnergy(graphics, offsets, recipe);
}

@NotNull
@Override
public List<Text> getTooltipStrings(SlimefunRecipe recipe, IRecipeSlotsView recipeSlotsView, double mouseX, double mouseY) {
final List<Text> tooltips = new ArrayList<>();
final OffsetBuilder offsets = new OffsetBuilder(this, recipe, calculateXOffset(recipe), TextureUtils.PADDING);

// Energy Tooltip Option 1
if (recipe.hasEnergy() && recipe.hasOutputs()) {
if (tooltipActive(mouseX, mouseY, offsets.getX(), offsets.energy(), TextureUtils.ENERGY)) {
tooltips.add(energyTooltip(recipe));
}
offsets.x().addEnergy();
}

offsets.x().add(TextureUtils.SLOT_SIZE * this.side).addPadding();
offsets.y().add(TextureUtils.SLOT_SIZE * this.side);

if (recipe.hasTime() && tooltipActive(mouseX, mouseY, offsets.getX(), offsets.arrow(), TextureUtils.ARROW)) {
tooltips.add(timeTooltip(recipe));
}
offsets.x().addArrow();

// Energy Tooltip Option 2
if (!recipe.hasOutputs() && tooltipActive(mouseX, mouseY, offsets.getX(), offsets.energy(), TextureUtils.ENERGY)) {
tooltips.add(energyTooltip(recipe));
}
return tooltips;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class ProcessCategory extends RecipeRenderer implements IRecipeCategory<SlimefunRecipe> {
protected final IGuiHelper guiHelper;
protected final SlimefunCategory slimefunCategory;
Expand Down Expand Up @@ -169,6 +172,46 @@ public void draw(SlimefunRecipe recipe, IRecipeSlotsView recipeSlotsView, DrawCo
addOutputsOrEnergy(graphics, offsets, recipe);
}

@NotNull
@Override
public List<Text> getTooltipStrings(SlimefunRecipe recipe, IRecipeSlotsView recipeSlotsView, double mouseX, double mouseY) {
final List<Text> tooltips = new ArrayList<>();
final OffsetBuilder offsets = new OffsetBuilder(this, recipe, calculateXOffset(this.slimefunCategory, recipe));

// Label Tooltips
if (recipe.hasLabels()) {
for (SlimefunLabel slimefunLabel : recipe.labels()) {
if (tooltipActive(mouseX, mouseY, offsets.getX(), offsets.label(), slimefunLabel)) {
tooltips.add(labelTooltip(slimefunLabel));
}
offsets.x().addLabel();
}
}

// Energy Tooltip Option 1
if (recipe.hasEnergy() && recipe.hasOutputs()) {
if (tooltipActive(mouseX, mouseY, offsets.getX(), offsets.energy(), TextureUtils.ENERGY)) {
tooltips.add(energyTooltip(recipe));
}
offsets.x().addEnergy();
}

offsets.x().add((TextureUtils.SLOT_SIZE + TextureUtils.PADDING) * (recipe.hasInputs() ? recipe.inputs().size() : 1));

// Arrow Tooltip
if (recipe.hasTime() && tooltipActive(mouseX, mouseY, offsets.getX(), offsets.arrow(), TextureUtils.ARROW)) {
tooltips.add(timeTooltip(recipe));
}
offsets.x().addArrow();

// Energy Tooltip Option 2
if (!recipe.hasOutputs() && tooltipActive(mouseX, mouseY, offsets.getX(), offsets.energy(), TextureUtils.ENERGY)) {
tooltips.add(energyTooltip(recipe));
}

return tooltips;
}

protected void addEnergyWithCheck(DrawContext graphics, OffsetBuilder offsets, SlimefunRecipe recipe) {
if (recipe.hasEnergy() && recipe.hasOutputs()) {
addEnergy(graphics, offsets, recipe.energy() < 0);
Expand All @@ -192,7 +235,7 @@ protected void addArrow(DrawContext graphics, OffsetBuilder offsets, SlimefunRec

protected void addArrow(DrawContext graphics, SlimefunRecipe recipe, int x, int y, boolean backwards) {
if (recipe.hasTime()) {
addFillingArrow(graphics, x, y, backwards, getTime(recipe));
addFillingArrow(graphics, x, y, backwards, getSfTicks(recipe));
} else {
addArrow(graphics, x, y, backwards);
}
Expand Down Expand Up @@ -222,11 +265,32 @@ protected void addOutputs(DrawContext graphics, OffsetBuilder offsets, SlimefunR
}
}

protected int getTime(SlimefunRecipe slimefunRecipe) {
protected int getSfTicks(SlimefunRecipe slimefunRecipe) {
if (slimefunRecipe.hasTime()) {
return slimefunRecipe.sfTicks(this.slimefunCategory.hasSpeed() ? this.slimefunCategory.speed() : 1);
} else {
return 2;
}
}

protected boolean tooltipActive(double mouseX, double mouseY, OffsetBuilder offsets, SlimefunLabel label) {
return tooltipActive(mouseX, mouseY, offsets.getX(), offsets.getY(), label);
}

protected boolean tooltipActive(double mouseX, double mouseY, int x, int y, SlimefunLabel label) {
return mouseX >= x && mouseX <= x + label.width() && mouseY >= y && mouseY <= y + label.height();
}

protected Text labelTooltip(SlimefunLabel label) {
return Text.translatable("slimefun_essentials.recipes.label." + label.id());
}

protected Text timeTooltip(SlimefunRecipe recipe) {
return Text.translatable("slimefun_essentials.recipes.time", TextureUtils.numberFormat.format(getSfTicks(recipe) / 2), TextureUtils.numberFormat.format(getSfTicks(recipe) * 10L));
}

protected Text energyTooltip(SlimefunRecipe recipe) {
final int totalEnergy = recipe.energy() * Math.max(1, recipe.time() / 10 / (this.slimefunCategory.hasSpeed() ? this.slimefunCategory.speed() : 1));
return Text.translatable("slimefun_essentials.recipes.energy." + (totalEnergy >= 0 ? "generate" : "use"), TextureUtils.numberFormat.format(Math.abs(totalEnergy)));
}
}
Loading

0 comments on commit c31f002

Please sign in to comment.