Skip to content

Commit

Permalink
⚠️ Extremely Wip ⚠️ Jei & Rei Compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAHuman-xD committed Mar 17, 2023
1 parent c6b1ecb commit 4f77e9a
Show file tree
Hide file tree
Showing 41 changed files with 1,238 additions and 188 deletions.
15 changes: 11 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ repositories {
url = "https://maven.terraformersmc.com/"
}
maven {
name = "Progwml6 maven"
url = "https://dvs1.progwml6.com/files/maven/"
name = "Jei"
url = "https://maven.blamejared.com/"
}
maven {
name = "ModMaven"
url = "https://modmaven.dev"
}
maven {
name = "Cloth Config"
name = "Cloth Config, Rei"
url = "https://maven.shedaniel.me/"
}

mavenCentral()
}

Expand All @@ -37,6 +36,14 @@ dependencies {
exclude(group: "net.fabricmc.fabric-api")
}

modImplementation("mezz.jei:${project.jei_version}") {
exclude(group: "mezz.jei")
}

modRuntimeOnly("me.shedaniel:RoughlyEnoughItems-fabric:$rei_version")
modCompileOnly("me.shedaniel:RoughlyEnoughItems-api-fabric:$rei_version")
modCompileOnly("me.shedaniel:RoughlyEnoughItems-default-plugin-fabric:$rei_version")

modApi "com.terraformersmc:modmenu:${project.mod_menu_version}"
modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") {
exclude(group: "net.fabricmc.fabric-api")
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ archives_base_name=Slimefun Essentials
# check this on https://modmuss50.me/fabric.html
fabric_version=0.75.1+1.19.3
emi_version=0.7.0+1.19.3
jei_version=jei-1.19.2-fabric:11.4.0.288
rei_version=9.1.580
mod_menu_version=5.0.2
cloth_config_version=9.0.94
lombok_version=1.18.26
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

public class ResourceLoader {
private static final Gson gson = new Gson().newBuilder().setPrettyPrinting().create();
private static final Map<String, ItemStack> slimefunItems = new LinkedHashMap<>();
private static final Map<String, SlimefunItemStack> slimefunItems = new LinkedHashMap<>();
private static final Map<Identifier, ItemGroup> itemGroups = new HashMap<>();

/**
Expand Down Expand Up @@ -75,7 +75,7 @@ public static void loadItems(Resource resource) {
continue;
}

slimefunItems.put(id, JsonUtils.deserializeItem(itemObject));
slimefunItems.put(id, new SlimefunItemStack(id, JsonUtils.deserializeItem(itemObject)));
}

sortItems();
Expand Down Expand Up @@ -103,7 +103,7 @@ public static void loadItemGroups(Resource resource) {
continue;
}

displayStacks.add(slimefunItems.get(entryPrimitive.getAsString()));
displayStacks.add(slimefunItems.get(entryPrimitive.getAsString()).itemStack());
}
searchTabStacks.addAll(displayStacks);

Expand Down Expand Up @@ -148,7 +148,7 @@ public static void loadLabels(Resource resource) {
* @return {@link Map}
*/
@NonNull
public static Map<String, ItemStack> getSlimefunItems() {
public static Map<String, SlimefunItemStack> getSlimefunItems() {
return Collections.unmodifiableMap(slimefunItems);
}

Expand All @@ -163,7 +163,7 @@ public static Map<Identifier, ItemGroup> getItemGroups() {
}

private static void sortItems() {
final Map<String, ItemStack> sortedSlimefunItems = new HashMap<>();
final Map<String, SlimefunItemStack> sortedSlimefunItems = new LinkedHashMap<>();
final List<String> ids = new ArrayList<>(slimefunItems.keySet());
ids.sort(Comparator.naturalOrder());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import lombok.Getter;
import lombok.NonNull;
import me.justahuman.slimefun_essentials.utils.JsonUtils;

Expand All @@ -13,48 +12,27 @@
import java.util.List;
import java.util.Map;

public class SlimefunCategory {
public record SlimefunCategory(String id, String type, Integer speed, Integer energy, List<SlimefunRecipe> recipes) {
private static final Map<String, SlimefunCategory> slimefunCategories = new LinkedHashMap<>();

@Getter
private final String id;
@Getter
private final String type;
@Getter
private final Integer speed;
@Getter
private final Integer energy;
@Getter
private final List<SlimefunRecipe> recipes;

public SlimefunCategory(String id, String type, Integer speed, Integer energy, List<SlimefunRecipe> recipes) {
this.id = id;
this.type = type;
this.speed = speed;
this.energy = energy;
this.recipes = recipes;

slimefunCategories.put(id, this);
}

public static void deserialize(String id, JsonObject categoryObject) {
final String type = JsonUtils.getStringOrDefault(categoryObject, "type", "process");
final Integer speed = JsonUtils.getIntegerOrDefault(categoryObject, "speed", null);
final Integer energy = JsonUtils.getIntegerOrDefault(categoryObject, "energy", null);
final List<SlimefunRecipe> recipes = new ArrayList<>();
for (JsonElement recipeElement : JsonUtils.getArrayOrDefault(categoryObject, "recipes", new JsonArray())) {
if (!(recipeElement instanceof JsonObject recipeObject)) {
if (! (recipeElement instanceof JsonObject recipeObject)) {
continue;
}
recipes.add(SlimefunRecipe.deserialize(recipeObject));

recipes.add(SlimefunRecipe.deserialize(recipeObject, energy));
}

final String copy = JsonUtils.getStringOrDefault(categoryObject, "copy", "");
final List<SlimefunRecipe> copiedRecipes = slimefunCategories.containsKey(copy) ? slimefunCategories.get(copy).getRecipes() : new ArrayList<>();
final List<SlimefunRecipe> copiedRecipes = slimefunCategories.containsKey(copy) ? slimefunCategories.get(copy).recipes() : new ArrayList<>();
recipes.addAll(copiedRecipes);
new SlimefunCategory(id, type, speed, energy, recipes);

slimefunCategories.put(id, new SlimefunCategory(id, type, speed, energy, recipes));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package me.justahuman.slimefun_essentials.client;

import net.minecraft.item.ItemStack;

public record SlimefunItemStack(String id, ItemStack itemStack) {
public SlimefunItemStack setAmount(int amount) {
itemStack.setCount(amount);
return this;
}

public SlimefunItemStack copy() {
return new SlimefunItemStack(id, itemStack.copy());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.justahuman.slimefun_essentials.client;

import com.google.gson.JsonObject;
import lombok.Getter;
import lombok.NonNull;
import me.justahuman.slimefun_essentials.utils.JsonUtils;
import net.minecraft.util.Identifier;
Expand All @@ -10,25 +9,9 @@
import java.util.LinkedHashMap;
import java.util.Map;

public class SlimefunLabel {
public record SlimefunLabel(String id, Identifier identifier, int u, int v) {
private static final Map<String, SlimefunLabel> slimefunLabels = new LinkedHashMap<>();

@Getter
private final String id;
@Getter
private final Identifier identifier;
@Getter
private final int u;
@Getter
private final int v;

public SlimefunLabel(String id, Identifier identifier, int u, int v) {
this.id = id;
this.identifier = identifier;
this.u = u;
this.v = v;
}

public static void deserialize(String id, JsonObject labelObject) {
slimefunLabels.put(id, new SlimefunLabel(
id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,15 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import lombok.Getter;
import me.justahuman.slimefun_essentials.utils.JsonUtils;

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

public class SlimefunRecipe {
@Getter
private final Integer time;
@Getter
private final Integer energy;
@Getter
private final List<SlimefunRecipeComponent> inputs;
@Getter
private final List<SlimefunRecipeComponent> outputs;
@Getter
private final List<SlimefunLabel> labels;

public SlimefunRecipe(Integer time, Integer energy, List<SlimefunRecipeComponent> inputs, List<SlimefunRecipeComponent> outputs, List<SlimefunLabel> labels) {
this.time = time;
this.energy = energy;
this.inputs = inputs;
this.outputs = outputs;
this.labels = labels;
}

public static SlimefunRecipe deserialize(JsonObject recipeObject) {
public record SlimefunRecipe(Integer time, Integer energy, List<SlimefunRecipeComponent> inputs, List<SlimefunRecipeComponent> outputs, List<SlimefunLabel> labels) {
public static SlimefunRecipe deserialize(JsonObject recipeObject, Integer workstationEnergy) {
final Integer time = JsonUtils.getIntegerOrDefault(recipeObject, "time", null);
final Integer energy = JsonUtils.getIntegerOrDefault(recipeObject, "energy", null);
final Integer energy = JsonUtils.getIntegerOrDefault(recipeObject, "energy", workstationEnergy);
final List<SlimefunRecipeComponent> inputs = new ArrayList<>();
final List<SlimefunRecipeComponent> outputs = new ArrayList<>();
final List<SlimefunLabel> labels = new ArrayList<>();
Expand All @@ -43,7 +23,7 @@ public static SlimefunRecipe deserialize(JsonObject recipeObject) {
inputs.add(inputRecipeElement);
}
}

for (JsonElement outputElement : JsonUtils.getArrayOrDefault(recipeObject, "outputs", new JsonArray())) {
final SlimefunRecipeComponent outputRecipeElement = SlimefunRecipeComponent.deserialize(outputElement);
if (outputRecipeElement != null) {
Expand All @@ -52,7 +32,7 @@ public static SlimefunRecipe deserialize(JsonObject recipeObject) {
}

for (JsonElement labelElement : JsonUtils.getArrayOrDefault(recipeObject, "labels", new JsonArray())) {
if (!(labelElement instanceof JsonPrimitive jsonPrimitive) || !jsonPrimitive.isString()) {
if (! (labelElement instanceof JsonPrimitive jsonPrimitive) || ! jsonPrimitive.isString()) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dev.emi.emi.api.stack.EmiStack;
import me.justahuman.slimefun_essentials.client.ResourceLoader;
import me.justahuman.slimefun_essentials.client.SlimefunCategory;
import me.justahuman.slimefun_essentials.client.SlimefunItemStack;
import me.justahuman.slimefun_essentials.client.SlimefunLabel;
import me.justahuman.slimefun_essentials.client.SlimefunRecipe;
import me.justahuman.slimefun_essentials.client.SlimefunRecipeComponent;
Expand All @@ -17,7 +18,6 @@
import me.justahuman.slimefun_essentials.compat.emi.recipes.ReactorRecipe;
import me.justahuman.slimefun_essentials.compat.emi.recipes.SmelteryRecipe;
import me.justahuman.slimefun_essentials.utils.Utils;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.util.Identifier;
Expand All @@ -32,42 +32,41 @@ public class EmiIntegration implements EmiPlugin {

@Override
public void register(EmiRegistry emiRegistry) {
for (Map.Entry<String, ItemStack> entry : ResourceLoader.getSlimefunItems().entrySet()) {
emiRegistry.setDefaultComparison(EmiStack.of(entry.getValue()), original -> original.copy().nbt(true).build());
for (Map.Entry<String, SlimefunItemStack> entry : ResourceLoader.getSlimefunItems().entrySet()) {
emiRegistry.setDefaultComparison(EmiStack.of(entry.getValue().itemStack()), original -> original.copy().nbt(true).build());
}

for (SlimefunCategory slimefunCategory : SlimefunCategory.getSlimefunCategories().values()) {
final String workstationId = slimefunCategory.getId();
final String type = slimefunCategory.getType();
final Integer speed = slimefunCategory.getSpeed();
final Integer energy = slimefunCategory.getEnergy();
final String workstationId = slimefunCategory.id();
final String type = slimefunCategory.type();
final Integer speed = slimefunCategory.speed();
final Identifier categoryIdentifier = Utils.newIdentifier(workstationId);
final EmiStack workStation = emiStackFromId(workstationId + ":1");
final SlimefunEmiCategory slimefunEmiCategory;
if (slimefunCategories.containsKey(workstationId)) {
slimefunEmiCategory = slimefunCategories.get(workstationId);
} else {
slimefunEmiCategory = new SlimefunEmiCategory(emiRegistry, categoryIdentifier, workStation, workStation.getItemStack().getName());
slimefunEmiCategory = new SlimefunEmiCategory(emiRegistry, categoryIdentifier, workStation);
slimefunCategories.put(workstationId, slimefunEmiCategory);
emiRegistry.addCategory(slimefunEmiCategory);
}

for (SlimefunRecipe slimefunRecipe : slimefunCategory.getRecipes()) {
for (SlimefunRecipe slimefunRecipe : slimefunCategory.recipes()) {
final List<EmiIngredient> inputs = new ArrayList<>();
final List<EmiStack> outputs = new ArrayList<>();
final List<SlimefunLabel> labels = slimefunRecipe.getLabels();
final Integer time = slimefunRecipe.getTime();
final Integer recipeEnergy = slimefunRecipe.getEnergy();
final List<SlimefunLabel> labels = slimefunRecipe.labels();
final Integer time = slimefunRecipe.time();
final Integer recipeEnergy = slimefunRecipe.energy();

for (SlimefunRecipeComponent input : slimefunRecipe.getInputs()) {
for (SlimefunRecipeComponent input : slimefunRecipe.inputs()) {
inputs.add(emiIngredientFromComponent(input));
}

for (SlimefunRecipeComponent output : slimefunRecipe.getOutputs()) {
for (SlimefunRecipeComponent output : slimefunRecipe.outputs()) {
outputs.add(emiStackFromComponent(output));
}

final EmiRecipe emiRecipe = getEmiRecipe(type, slimefunEmiCategory, inputs, outputs, labels, recipeEnergy == null ? energy : recipeEnergy, time, speed);
final EmiRecipe emiRecipe = getEmiRecipe(type, slimefunEmiCategory, inputs, outputs, labels, recipeEnergy, time, speed);
emiRegistry.addRecipe(emiRecipe);
}
}
Expand Down Expand Up @@ -127,7 +126,7 @@ public static EmiIngredient emiIngredientFromId(String id) {
}

if (ResourceLoader.getSlimefunItems().containsKey(type)) {
return EmiStack.of(ResourceLoader.getSlimefunItems().get(type)).copy().setAmount(amount);
return EmiStack.of(ResourceLoader.getSlimefunItems().get(type).itemStack()).copy().setAmount(amount);
}

if (type.equals("entity")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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 java.util.List;
Expand All @@ -16,6 +17,6 @@ public EmiLabel(String id, EmiTexture texture, int x, int y) {
}

public EmiLabel(SlimefunLabel slimefunLabel, int x, int y) {
this(slimefunLabel.getId(), new EmiTexture(slimefunLabel.getIdentifier(), slimefunLabel.getU(), slimefunLabel.getV(), EmiUtils.label, EmiUtils.label), x, y);
this(slimefunLabel.id(), new EmiTexture(slimefunLabel.identifier(), slimefunLabel.u(), slimefunLabel.v(), TextureUtils.label, TextureUtils.label), x, y);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@

import dev.emi.emi.EmiRenderHelper;
import dev.emi.emi.api.render.EmiTexture;
import me.justahuman.slimefun_essentials.utils.TextureUtils;
import me.justahuman.slimefun_essentials.utils.Utils;

import java.text.NumberFormat;

public class EmiUtils {
public static final int padding = 4;
public static final int bigSlot = 26;
public static final int slot = 18;
public static final int arrowHeight = 17;
public static final int arrowWidth = 24;
public static final int chargeWidth = 7;
public static final int chargeHeight = 9;
public static final int label = 13;
public static final EmiTexture EMPTY_CHARGE = new EmiTexture(Utils.WIDGETS, 36, 0, chargeWidth, chargeHeight);
public static final EmiTexture GAIN_CHARGE = new EmiTexture(Utils.WIDGETS, 43, 0, chargeWidth, chargeHeight);
public static final EmiTexture LOOSE_CHARGE = new EmiTexture(Utils.WIDGETS, 50, 0, chargeWidth, chargeHeight);
public static final EmiTexture EMPTY_CHARGE = new EmiTexture(Utils.WIDGETS, 36, 0, TextureUtils.chargeWidth, TextureUtils.chargeHeight);
public static final EmiTexture GAIN_CHARGE = new EmiTexture(Utils.WIDGETS, 43, 0, TextureUtils.chargeWidth, TextureUtils.chargeHeight);
public static final EmiTexture LOOSE_CHARGE = new EmiTexture(Utils.WIDGETS, 50, 0, TextureUtils.chargeWidth, TextureUtils.chargeHeight);
public static final EmiTexture BACKWARDS_EMPTY_ARROW = new EmiTexture(EmiRenderHelper.WIDGETS, 68, 0, 24, 17);
public static final NumberFormat numberFormat = NumberFormat.getInstance();
static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
public class SlimefunEmiCategory extends EmiRecipeCategory {
private final Text displayName;

public SlimefunEmiCategory(EmiRegistry emiRegistry, Identifier id, EmiStack workstation, Text displayName) {
public SlimefunEmiCategory(EmiRegistry emiRegistry, Identifier id, EmiStack workstation) {
super(id, workstation);

this.displayName = displayName;
this.displayName = workstation.getItemStack().getName();
emiRegistry.addWorkstation(this, workstation);
}

Expand Down
Loading

1 comment on commit 4f77e9a

@RawDiamondMC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good!

Please sign in to comment.