Skip to content

Commit

Permalink
tonssssssssssss of work
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAHuman-xD committed Apr 25, 2024
1 parent 2435b44 commit aa10cc7
Show file tree
Hide file tree
Showing 43 changed files with 691 additions and 393 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package me.justahuman.slimefun_essentials.api;

import me.justahuman.slimefun_essentials.client.DrawMode;
import me.justahuman.slimefun_essentials.client.SlimefunLabel;
import me.justahuman.slimefun_essentials.client.SlimefunRecipe;
import me.justahuman.slimefun_essentials.utils.TextureUtils;
import me.justahuman.slimefun_essentials.utils.Utils;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;

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

default void addLabels(DrawContext graphics, OffsetBuilder offsets, SlimefunRecipe recipe) {
if (recipe.hasLabels()) {
Utils.warn("WHAT THE FUCK IS HAPPENING (labels)");
for (SlimefunLabel slimefunLabel : recipe.labels()) {
slimefunLabel.draw(graphics, offsets.getX(), offsets.label());
offsets.x().addLabel();
Expand All @@ -22,6 +25,7 @@ default void addLabels(DrawContext graphics, OffsetBuilder offsets, SlimefunReci

default void addEnergyWithCheck(DrawContext graphics, OffsetBuilder offsets, SlimefunRecipe recipe) {
if (recipe.hasEnergy() && recipe.hasOutputs()) {
Utils.warn("WHAT THE FUCK IS HAPPENING (energy)");
addEnergy(graphics, offsets, recipe.energy() < 0);
}
}
Expand Down Expand Up @@ -64,8 +68,10 @@ default void addFillingArrow(DrawContext graphics, int x, int y, int sfTicks, bo

default void addInputsOrCatalyst(DrawContext graphics, OffsetBuilder offsets, SlimefunRecipe recipe) {
if (recipe.hasInputs()) {
Utils.warn("WHAT THE FUCK IS HAPPENING (inputs)");
addInputs(graphics, offsets, recipe);
} else {
Utils.warn("WHAT THE FUCK IS HAPPENING (catalyst)");
addCatalyst(graphics, offsets, recipe);
}
}
Expand Down Expand Up @@ -96,7 +102,7 @@ default void addOutputs(DrawContext graphics, OffsetBuilder offsets, SlimefunRec

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);
offsets.x().add((output ? TextureUtils.OUTPUT.size(getDrawMode()) : TextureUtils.SLOT.size(getDrawMode())) + TextureUtils.PADDING);
}

default void addSlot(DrawContext graphics, int x, int y, boolean output) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.justahuman.slimefun_essentials.api;

import me.justahuman.slimefun_essentials.client.DrawMode;
import me.justahuman.slimefun_essentials.client.SlimefunRecipe;
import me.justahuman.slimefun_essentials.utils.TextureUtils;

Expand All @@ -10,6 +11,7 @@ public class OffsetBuilder {
protected final int arrowOffset;
protected final int outputOffset;
protected final int minY;
protected DrawMode drawMode;
protected Offset xOffset;
protected Offset yOffset;

Expand All @@ -26,14 +28,15 @@ public OffsetBuilder(RecipeRenderer recipeRenderer, SlimefunRecipe slimefunRecip
}

public OffsetBuilder(RecipeRenderer recipeRenderer, SlimefunRecipe slimefunRecipe, int x, int y, int minY) {
this.labelOffset = recipeRenderer.calculateYOffset(slimefunRecipe, TextureUtils.LABEL_SIZE) + minY;
this.energyOffset = recipeRenderer.calculateYOffset(slimefunRecipe, TextureUtils.ENERGY_HEIGHT) + minY;
this.slotOffset = recipeRenderer.calculateYOffset(slimefunRecipe, TextureUtils.SLOT_SIZE) + minY;
this.arrowOffset = recipeRenderer.calculateYOffset(slimefunRecipe, TextureUtils.ARROW_HEIGHT) + minY;
this.outputOffset = recipeRenderer.calculateYOffset(slimefunRecipe, TextureUtils.OUTPUT_SIZE) + minY;
this.drawMode = recipeRenderer.getDrawMode();
this.labelOffset = recipeRenderer.calculateYOffset(slimefunRecipe, 14) + minY;
this.energyOffset = recipeRenderer.calculateYOffset(slimefunRecipe, TextureUtils.ENERGY.height(this.drawMode)) + minY;
this.slotOffset = recipeRenderer.calculateYOffset(slimefunRecipe, TextureUtils.SLOT.size(this.drawMode)) + minY;
this.arrowOffset = recipeRenderer.calculateYOffset(slimefunRecipe, TextureUtils.ARROW.height(this.drawMode)) + minY;
this.outputOffset = recipeRenderer.calculateYOffset(slimefunRecipe, TextureUtils.OUTPUT.height(this.drawMode)) + minY;
this.minY = minY;
this.xOffset = new Offset(x);
this.yOffset = new Offset(y);
this.xOffset = new Offset(this.drawMode, x, false);
this.yOffset = new Offset(this.drawMode, y, true);
}

public Offset x() {
Expand Down Expand Up @@ -87,10 +90,14 @@ public int output() {
}

public static class Offset {
DrawMode drawMode;
int value;
boolean y;

public Offset(int value) {
public Offset(DrawMode drawMode, int value, boolean y) {
this.drawMode = drawMode;
this.value = value;
this.y = y;
}

public int get() {
Expand All @@ -117,7 +124,7 @@ public Offset addLabel() {
}

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

Expand All @@ -126,7 +133,7 @@ public Offset addEnergy() {
}

public Offset addEnergy(boolean padding) {
this.value += TextureUtils.ENERGY_WIDTH + (padding ? TextureUtils.PADDING : 0);
this.value += TextureUtils.ENERGY.size(this.drawMode, this.y) + (padding ? TextureUtils.PADDING : 0);
return this;
}

Expand All @@ -135,7 +142,7 @@ public Offset addSlot() {
}

public Offset addSlot(boolean padding) {
this.value += TextureUtils.SLOT_SIZE + (padding ? TextureUtils.PADDING : 0);
this.value += TextureUtils.SLOT.size(this.drawMode, this.y) + (padding ? TextureUtils.PADDING : 0);
return this;
}

Expand All @@ -144,7 +151,7 @@ public Offset addArrow() {
}

public Offset addArrow(boolean padding) {
this.value += TextureUtils.ARROW_WIDTH + (padding ? TextureUtils.PADDING : 0);
this.value += TextureUtils.ARROW.size(this.drawMode, this.y) + (padding ? TextureUtils.PADDING : 0);
return this;
}

Expand All @@ -153,7 +160,7 @@ public Offset addOutput() {
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
package me.justahuman.slimefun_essentials.api;

import me.justahuman.slimefun_essentials.client.DrawMode;
import me.justahuman.slimefun_essentials.client.SlimefunRecipe;
import me.justahuman.slimefun_essentials.client.SlimefunRecipeCategory;
import me.justahuman.slimefun_essentials.utils.TextureUtils;

public interface RecipeRenderer {
Type getType();
DrawMode getDrawMode();

default int getContentsWidth(SlimefunRecipeCategory slimefunRecipeCategory) {
return getType().getContentsWidth(slimefunRecipeCategory);
return getType().getContentsWidth(getDrawMode(), slimefunRecipeCategory);
}

default int getContentsWidth(SlimefunRecipe slimefunRecipe) {
return getType().getContentsWidth(slimefunRecipe);
return getType().getContentsWidth(getDrawMode(), slimefunRecipe);
}

default int getContentsHeight(SlimefunRecipeCategory slimefunRecipeCategory) {
return getType().getContentsHeight(slimefunRecipeCategory);
return getType().getContentsHeight(getDrawMode(), slimefunRecipeCategory);
}

default int getContentsHeight(SlimefunRecipe slimefunRecipe) {
return getType().getContentsHeight(slimefunRecipe);
return getType().getContentsHeight(getDrawMode(), slimefunRecipe);
}

default int getDisplayWidth(SlimefunRecipeCategory slimefunRecipeCategory) {
return getContentsWidth(slimefunRecipeCategory) + TextureUtils.PADDING * 2;
}

default int getDisplayWidth(SlimefunRecipe slimefunRecipe) {
return getContentsWidth(slimefunRecipe) + TextureUtils.PADDING * 2;
return getDrawMode() == DrawMode.BOOK ? TextureUtils.PAGE_WIDTH : getContentsWidth(slimefunRecipe) + TextureUtils.PADDING * 2;
}

default int getDisplayHeight(SlimefunRecipeCategory slimefunRecipeCategory) {
Expand Down Expand Up @@ -58,112 +60,112 @@ default int calculateYOffset(SlimefunRecipe slimefunRecipe, int height) {
abstract class Type {
public static final Type ANCIENT_ALTAR = new Type() {
@Override
public int getContentsWidth(SlimefunRecipeCategory slimefunRecipeCategory) {
public int getContentsWidth(DrawMode drawMode, SlimefunRecipeCategory slimefunRecipeCategory) {
return 140;
}

@Override
public int getContentsWidth(SlimefunRecipe slimefunRecipe) {
public int getContentsWidth(DrawMode drawMode, SlimefunRecipe slimefunRecipe) {
return 140;
}

@Override
public int getContentsHeight(SlimefunRecipeCategory slimefunRecipeCategory) {
public int getContentsHeight(DrawMode drawMode, SlimefunRecipeCategory slimefunRecipeCategory) {
return 90;
}

@Override
public int getContentsHeight(SlimefunRecipe slimefunRecipe) {
public int getContentsHeight(DrawMode drawMode, SlimefunRecipe slimefunRecipe) {
return 90;
}
};

public static final Type PROCESS = new Type() {
@Override
public int getContentsWidth(SlimefunRecipeCategory slimefunRecipeCategory) {
return TextureUtils.getProcessWidth(slimefunRecipeCategory);
public int getContentsWidth(DrawMode drawMode, SlimefunRecipeCategory slimefunRecipeCategory) {
return TextureUtils.getProcessWidth(drawMode, slimefunRecipeCategory);
}

@Override
public int getContentsWidth(SlimefunRecipe slimefunRecipe) {
return TextureUtils.getProcessWidth(slimefunRecipe);
public int getContentsWidth(DrawMode drawMode, SlimefunRecipe slimefunRecipe) {
return TextureUtils.getProcessWidth(drawMode, slimefunRecipe);
}

@Override
public int getContentsHeight(SlimefunRecipeCategory slimefunRecipeCategory) {
return TextureUtils.getProcessHeight(slimefunRecipeCategory);
public int getContentsHeight(DrawMode drawMode, SlimefunRecipeCategory slimefunRecipeCategory) {
return TextureUtils.getProcessHeight(drawMode, slimefunRecipeCategory);
}

@Override
public int getContentsHeight(SlimefunRecipe slimefunRecipe) {
return TextureUtils.getProcessHeight(slimefunRecipe);
public int getContentsHeight(DrawMode drawMode, SlimefunRecipe slimefunRecipe) {
return TextureUtils.getProcessHeight(drawMode, slimefunRecipe);
}
};

public static final Type REACTOR = new Type() {
@Override
public int getContentsWidth(SlimefunRecipeCategory slimefunRecipeCategory) {
return TextureUtils.getReactorWidth(slimefunRecipeCategory);
public int getContentsWidth(DrawMode drawMode, SlimefunRecipeCategory slimefunRecipeCategory) {
return TextureUtils.getReactorWidth(drawMode, slimefunRecipeCategory);
}

@Override
public int getContentsWidth(SlimefunRecipe slimefunRecipe) {
return TextureUtils.getReactorWidth(slimefunRecipe);
public int getContentsWidth(DrawMode drawMode, SlimefunRecipe slimefunRecipe) {
return TextureUtils.getReactorWidth(drawMode, slimefunRecipe);
}

@Override
public int getContentsHeight(SlimefunRecipeCategory slimefunRecipeCategory) {
return TextureUtils.getReactorHeight(slimefunRecipeCategory);
public int getContentsHeight(DrawMode drawMode, SlimefunRecipeCategory slimefunRecipeCategory) {
return TextureUtils.getReactorHeight(drawMode, slimefunRecipeCategory);
}

@Override
public int getContentsHeight(SlimefunRecipe slimefunRecipe) {
return TextureUtils.getReactorHeight(slimefunRecipe);
public int getContentsHeight(DrawMode drawMode, SlimefunRecipe slimefunRecipe) {
return TextureUtils.getReactorHeight(drawMode, slimefunRecipe);
}
};

public static final Type SMELTERY = new Type() {
@Override
public int getContentsWidth(SlimefunRecipeCategory slimefunRecipeCategory) {
return TextureUtils.getSmelteryWidth(slimefunRecipeCategory);
public int getContentsWidth(DrawMode drawMode, SlimefunRecipeCategory slimefunRecipeCategory) {
return TextureUtils.getSmelteryWidth(drawMode, slimefunRecipeCategory);
}

@Override
public int getContentsWidth(SlimefunRecipe slimefunRecipe) {
return TextureUtils.getSmelteryWidth(slimefunRecipe);
public int getContentsWidth(DrawMode drawMode, SlimefunRecipe slimefunRecipe) {
return TextureUtils.getSmelteryWidth(drawMode, slimefunRecipe);
}

@Override
public int getContentsHeight(SlimefunRecipeCategory slimefunRecipeCategory) {
return TextureUtils.SLOT_SIZE * 3;
public int getContentsHeight(DrawMode drawMode, SlimefunRecipeCategory slimefunRecipeCategory) {
return TextureUtils.SLOT.size(drawMode) * 3;
}

@Override
public int getContentsHeight(SlimefunRecipe slimefunRecipe) {
return TextureUtils.SLOT_SIZE * 3;
public int getContentsHeight(DrawMode drawMode, SlimefunRecipe slimefunRecipe) {
return TextureUtils.SLOT.size(drawMode) * 3;
}
};

public static Type grid(int side) {
return new Type() {
@Override
public int getContentsWidth(SlimefunRecipeCategory slimefunRecipeCategory) {
return TextureUtils.getGridWidth(slimefunRecipeCategory, side);
public int getContentsWidth(DrawMode drawMode, SlimefunRecipeCategory slimefunRecipeCategory) {
return TextureUtils.getGridWidth(drawMode, slimefunRecipeCategory, side);
}

@Override
public int getContentsWidth(SlimefunRecipe slimefunRecipe) {
return TextureUtils.getGridWidth(slimefunRecipe, side);
public int getContentsWidth(DrawMode drawMode, SlimefunRecipe slimefunRecipe) {
return TextureUtils.getGridWidth(drawMode, slimefunRecipe, side);
}

@Override
public int getContentsHeight(SlimefunRecipeCategory slimefunRecipeCategory) {
return TextureUtils.getGridHeight(side);
public int getContentsHeight(DrawMode drawMode, SlimefunRecipeCategory slimefunRecipeCategory) {
return TextureUtils.getGridHeight(drawMode, side);
}

@Override
public int getContentsHeight(SlimefunRecipe slimefunRecipe) {
return TextureUtils.getGridHeight(side);
public int getContentsHeight(DrawMode drawMode, SlimefunRecipe slimefunRecipe) {
return TextureUtils.getGridHeight(drawMode, side);
}
};
}
Expand All @@ -182,12 +184,12 @@ public static Type from(String type) {
}
}

public abstract int getContentsWidth(SlimefunRecipeCategory slimefunRecipeCategory);
public abstract int getContentsWidth(DrawMode drawMode, SlimefunRecipeCategory slimefunRecipeCategory);

public abstract int getContentsWidth(SlimefunRecipe slimefunRecipe);
public abstract int getContentsWidth(DrawMode drawMode, SlimefunRecipe slimefunRecipe);

public abstract int getContentsHeight(SlimefunRecipeCategory slimefunRecipeCategory);
public abstract int getContentsHeight(DrawMode drawMode, SlimefunRecipeCategory slimefunRecipeCategory);

public abstract int getContentsHeight(SlimefunRecipe slimefunRecipe);
public abstract int getContentsHeight(DrawMode drawMode, SlimefunRecipe slimefunRecipe);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.justahuman.slimefun_essentials.client;

import me.justahuman.slimefun_essentials.utils.TextureUtils;
import net.minecraft.util.Identifier;

public enum DrawMode {
LIGHT, DARK, BOOK;

public Identifier defaultIdentifier() {
return switch (this) {
case LIGHT -> TextureUtils.WIDGETS;
case DARK -> TextureUtils.WIDGETS_DARK;
case BOOK -> TextureUtils.WIDGETS_BOOK;
};
}
}
Loading

0 comments on commit aa10cc7

Please sign in to comment.