Skip to content

Commit

Permalink
you guessed it, more work on the guide
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAHuman-xD committed Apr 25, 2024
1 parent f187abe commit 2435b44
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
import net.minecraft.text.Text;

public interface ManualRecipeRenderer extends RecipeRenderer {
default SlimefunLabel.DrawMode getDrawMode() {
return SlimefunLabel.DrawMode.LIGHT;
}

default void addLabels(DrawContext graphics, OffsetBuilder offsets, SlimefunRecipe recipe) {
if (recipe.hasLabels()) {
for (SlimefunLabel slimefunLabel : recipe.labels()) {
slimefunLabel.draw(graphics, offsets.getX(), offsets.label());
offsets.x().addLabel();
}
}
}

default void addEnergyWithCheck(DrawContext graphics, OffsetBuilder offsets, SlimefunRecipe recipe) {
if (recipe.hasEnergy() && recipe.hasOutputs()) {
addEnergy(graphics, offsets, recipe.energy() < 0);
Expand All @@ -19,7 +32,7 @@ default void addEnergy(DrawContext graphics, OffsetBuilder offsets, boolean nega
}

default void addEnergy(DrawContext graphics, int x, int y, boolean negative) {
TextureUtils.ENERGY.draw(graphics, x, y);
TextureUtils.ENERGY.draw(graphics, x, y, getDrawMode());
drawEnergyFill(graphics, x, y, negative);
}

Expand All @@ -39,7 +52,7 @@ default void addArrow(DrawContext graphics, SlimefunRecipe recipe, int x, int y,
}

default void addArrow(DrawContext graphics, int x, int y, boolean backwards) {
(backwards ? TextureUtils.BACKWARDS_ARROW : TextureUtils.ARROW).draw(graphics, x, y);
(backwards ? TextureUtils.BACKWARDS_ARROW : TextureUtils.ARROW).draw(graphics, x, y, getDrawMode());
}

default void addFillingArrow(DrawContext graphics, int x, int y, int sfTicks, boolean backwards) {
Expand All @@ -49,6 +62,24 @@ default void addFillingArrow(DrawContext graphics, int x, int y, int sfTicks, bo

void drawArrowFill(DrawContext graphics, int x, int y, int sfTicks, boolean backwards);

default void addInputsOrCatalyst(DrawContext graphics, OffsetBuilder offsets, SlimefunRecipe recipe) {
if (recipe.hasInputs()) {
addInputs(graphics, offsets, recipe);
} else {
addCatalyst(graphics, offsets, recipe);
}
}

default void addInputs(DrawContext graphics, OffsetBuilder offsets, SlimefunRecipe recipe) {
for (int i = 0; i < recipe.inputs().size(); i++) {
addSlot(graphics, offsets, false);
}
}

default void addCatalyst(DrawContext graphics, OffsetBuilder offsets, SlimefunRecipe recipe) {
addSlot(graphics, offsets, false);
}

default void addOutputsOrEnergy(DrawContext graphics, OffsetBuilder offsets, SlimefunRecipe recipe) {
if (recipe.hasOutputs()) {
addOutputs(graphics, offsets, recipe);
Expand All @@ -59,11 +90,19 @@ default void addOutputsOrEnergy(DrawContext graphics, OffsetBuilder offsets, Sli

default void addOutputs(DrawContext graphics, OffsetBuilder offsets, SlimefunRecipe recipe) {
for (int i = 0; i < recipe.outputs().size(); i++) {
TextureUtils.OUTPUT.draw(graphics, offsets.getX(), offsets.output());
offsets.x().addOutput();
addSlot(graphics, offsets, true);
}
}

default void addSlot(DrawContext graphics, OffsetBuilder offsets, boolean output) {
addSlot(graphics, offsets.getX(), output ? offsets.output() : offsets.slot(), output);
offsets.x().add((output ? TextureUtils.OUTPUT_SIZE : TextureUtils.SLOT_SIZE) + TextureUtils.PADDING);
}

default void addSlot(DrawContext graphics, int x, int y, boolean output) {
(output ? TextureUtils.OUTPUT : TextureUtils.SLOT).draw(graphics, x, y, getDrawMode());
}

default boolean tooltipActive(double mouseX, double mouseY, OffsetBuilder offsets, SlimefunLabel label) {
return tooltipActive(mouseX, mouseY, offsets.getX(), offsets.getY(), label);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,23 @@
import java.util.LinkedHashMap;
import java.util.Map;

public record SlimefunLabel(String id, Identifier light, Identifier dark, int u, int v, int width, int height) {
public record SlimefunLabel(String id, Identifier light, Identifier dark, Identifier book, int u, int v, int width, int height) {
private static final Map<String, SlimefunLabel> slimefunLabels = new LinkedHashMap<>();

public SlimefunLabel(String id, Identifier light, Identifier dark, int u, int v) {
this(id, light, dark, u, v, TextureUtils.LABEL_SIZE, TextureUtils.LABEL_SIZE);
public SlimefunLabel(String id, int u, int v, int width, int height) {
this(id, TextureUtils.WIDGETS, TextureUtils.WIDGETS_DARK, TextureUtils.WIDGETS_BOOK, u, v, width, height);
}

public SlimefunLabel(String id, Identifier light, Identifier dark, Identifier book, int u, int v) {
this(id, light, dark, book, u, v, TextureUtils.LABEL_SIZE, TextureUtils.LABEL_SIZE);
}

public static void deserialize(String id, JsonObject labelObject) {
slimefunLabels.put(id, new SlimefunLabel(
id,
new Identifier(JsonUtils.getStringOrDefault(labelObject, "light", "slimefun_essentials:textures/gui/widgets.png")),
new Identifier(JsonUtils.getStringOrDefault(labelObject, "dark", "slimefun_essentials:textures/gui/widgets_dark.png")),
new Identifier(JsonUtils.getStringOrDefault(labelObject, "dark", "slimefun_essentials:textures/gui/widgets_book.png")),
JsonUtils.getIntegerOrDefault(labelObject, "u", 0),
JsonUtils.getIntegerOrDefault(labelObject, "v", 0)
));
Expand All @@ -44,20 +49,31 @@ public static void clear() {
slimefunLabels.clear();
}

public void draw(DrawContext graphics, int x, int y, int width, int height, int u, int v, int regionWidth, int regionHeight, boolean dark) {
public void draw(DrawContext graphics, int x, int y, int width, int height, int u, int v, int regionWidth, int regionHeight, DrawMode drawMode) {
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
graphics.drawTexture(dark ? this.dark : this.light, x, y, width, height, u, v, regionWidth, regionHeight, 256, 256);
graphics.drawTexture(drawMode.get(this), x, y, width, height, u, v, regionWidth, regionHeight, 256, 256);
}

public void draw(DrawContext graphics, int x, int y, boolean dark) {
draw(graphics, x, y, this.width, this.height, this.u, this.v, this.width, this.height, dark);
public void draw(DrawContext graphics, int x, int y, DrawMode drawMode) {
draw(graphics, x, y, this.width, this.height, this.u, this.v, this.width, this.height, drawMode);
}

public void draw(DrawContext graphics, int x, int y) {
draw(graphics, x, y, false);
draw(graphics, x, y, DrawMode.LIGHT);
}

public Text text() {
return Text.translatable("slimefun_essentials.recipes.label." + this.id);
}

public enum DrawMode {
LIGHT, DARK, BOOK;
public Identifier get(SlimefunLabel slimefunLabel) {
return switch (this) {
case LIGHT -> slimefunLabel.light();
case DARK -> slimefunLabel.dark();
case BOOK -> slimefunLabel.book();
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,33 +147,10 @@ public void setRecipe(IRecipeLayoutBuilder builder, SlimefunRecipe recipe, IFocu
@Override
public void draw(SlimefunRecipe recipe, IRecipeSlotsView recipeSlotsView, DrawContext graphics, double mouseX, double mouseY) {
final OffsetBuilder offsets = new OffsetBuilder(this, recipe, calculateXOffset(this.slimefunRecipeCategory, recipe));

// Display Labels
if (recipe.hasLabels()) {
for (SlimefunLabel slimefunLabel : recipe.labels()) {
slimefunLabel.draw(graphics, offsets.getX(), offsets.label());
offsets.x().addLabel();
}
}

// Display Energy
addLabels(graphics, offsets, recipe);
addEnergyWithCheck(graphics, offsets, recipe);

// Display Inputs, only the slot icon
if (recipe.hasInputs()) {
for (int i = 0; i < recipe.inputs().size(); i++) {
TextureUtils.SLOT.draw(graphics, offsets.getX(), offsets.slot());
offsets.x().addSlot();
}
} else {
TextureUtils.SLOT.draw(graphics, offsets.getX(), offsets.slot());
offsets.x().addSlot();
}

// Display Arrow
addInputsOrCatalyst(graphics, offsets, recipe);
addArrow(graphics, offsets, recipe);

// Display Outputs
addOutputsOrEnergy(graphics, offsets, recipe);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import vazkii.patchouli.client.book.BookCategory;
import vazkii.patchouli.client.book.ClientBookRegistry;

import java.util.List;

public class PatchouliIntegration {
public static final Identifier BOOK_IDENTIFIER = Utils.newIdentifier("slimefun");
public static final PatchouliIdInterpreter INTERPRETER = new PatchouliIdInterpreter();
Expand Down Expand Up @@ -64,18 +66,22 @@ public static JsonObject getRecipeEntry(BookCategory category, SlimefunRecipeCat
entry.addProperty("sortnum", sortnum);

final JsonArray pages = new JsonArray();
for (SlimefunRecipe recipe : recipeCategory.recipesFor()) {
pages.add(getPage(recipe));
List<SlimefunRecipe> recipesFor = recipeCategory.recipesFor();
for (int i = 0; i < recipesFor.size(); i++) {
SlimefunRecipe recipe = recipesFor.get(i);
pages.add(getPage(recipeCategory, recipe, i));
}
entry.add("pages", pages);

return entry;
}

public static JsonObject getPage(SlimefunRecipe recipe) {
public static JsonObject getPage(SlimefunRecipeCategory category, SlimefunRecipe recipe, int recipeIndex) {
final String type = recipe.parent().type();
final JsonObject page = new JsonObject();
page.addProperty("id", recipe.parent().id());

page.addProperty("id", category.id());
page.addProperty("recipe_index", recipeIndex);

if (type.contains("grid")) {
page.addProperty("type", "slimefun_essentials:grid_recipe");
Expand All @@ -84,38 +90,6 @@ public static JsonObject getPage(SlimefunRecipe recipe) {
page.addProperty("type", "slimefun_essentials:" + type);
}

if (recipe.hasTime()) {
page.addProperty("sfTicks", recipe.sfTicks());
}

if (recipe.hasEnergy()) {
page.addProperty("energy", recipe.energy());
}

if (recipe.hasLabels()) {
final JsonArray labels = new JsonArray();
for (SlimefunLabel label : recipe.labels()) {
labels.add(label.id());
}
page.add("labels", labels);
}

if (recipe.hasInputs()) {
final JsonArray inputs = new JsonArray();
for (SlimefunRecipeComponent input : recipe.inputs()) {
inputs.add(input.serialize());
}
page.add("inputs", inputs);
}

if (recipe.hasOutputs()) {
final JsonArray outputs = new JsonArray();
for (SlimefunRecipeComponent output : recipe.outputs()) {
outputs.add(output.serialize());
}
page.add("outputs", outputs);
}

return page;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.justahuman.slimefun_essentials.compat.patchouli;

import me.justahuman.slimefun_essentials.api.OffsetBuilder;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
Expand All @@ -12,20 +11,20 @@

@FunctionalInterface
public interface PatchouliWidget {
PatchouliWidget EMPTY = (o1, o2, o3, o4, o5, o6) -> {};
PatchouliWidget EMPTY = (o1, o2, o3, o4, o5, o6, o7) -> {};

void render(GuiBookEntry gui, DrawContext graphics, OffsetBuilder offsets, int mouseX, int mouseY, float pTicks);
void render(GuiBookEntry gui, DrawContext graphics, int x, int y, int mouseX, int mouseY, float pTicks);

static PatchouliWidget wrap(List<PatchouliWidget> widgets) {
return (gui, graphics, offsets, mouseX, mouseY, pTicks) -> {
return (gui, graphics, x, y, mouseX, mouseY, pTicks) -> {
// Picks widgets on an interval of 10 ticks or half a second
int index = (int) (pTicks / (widgets.size() * 10)) % widgets.size();
widgets.get(index).render(gui, graphics, offsets, mouseX, mouseY, pTicks);
widgets.get(index).render(gui, graphics, x, y, mouseX, mouseY, pTicks);
};
}

static PatchouliWidget wrap(ItemStack itemStack) {
return (gui, graphics, offsets, mouseX, mouseY, pTicks) -> gui.renderItemStack(graphics, offsets.getX(), offsets.getY(), mouseX, mouseY, itemStack);
return (gui, graphics, x, y, mouseX, mouseY, pTicks) -> gui.renderItemStack(graphics, x, y, mouseX, mouseY, itemStack);
}

static PatchouliWidget wrap(Entity entity, int amount) {
Expand All @@ -35,9 +34,9 @@ static PatchouliWidget wrap(Entity entity, int amount) {
float renderScale = 100F / entitySize * 0.8F;
float offset = Math.max(height, entitySize) * 0.5F;

return (gui, graphics, offsets, mouseX, mouseY, pTicks) -> {
return (gui, graphics, x, y, mouseX, mouseY, pTicks) -> {
// TODO: render xAmount, render slot
PageEntity.renderEntity(graphics, entity, offsets.getX(), offsets.getY(), ClientTicker.total, renderScale, offset);
PageEntity.renderEntity(graphics, entity, x, y, ClientTicker.total, renderScale, offset);
};
}
}
Loading

0 comments on commit 2435b44

Please sign in to comment.