Skip to content

Commit

Permalink
work on 1.21 update, nearly done
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAHuman-xD committed Nov 14, 2024
1 parent 91f6546 commit 4ebd3a6
Show file tree
Hide file tree
Showing 19 changed files with 79 additions and 92 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ yarn_mappings=1.20.6+build.3
loader_version=0.16.5

# Mod Properties
mod_version=0.4.0
mod_version=0.4.1
maven_group=me.justahuman
archives_base_name=Slimefun Essentials

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.math.ChunkPos;
import org.lwjgl.glfw.GLFW;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

public class SlimefunEssentials implements ClientModInitializer {
public static final String MOD_ID = "slimefun_essentials";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

@Override
public void onInitializeClient() {
PayloadTypeRegistry.playS2C().register(Payloads.ADDON_CHANNEL, SlimefunAddonPayload.CODEC);
Expand All @@ -54,7 +59,7 @@ public void onInitializeClient() {
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
@Override
public Identifier getFabricId() {
return Utils.newIdentifier("reload_listener");
return Utils.id("reload_listener");
}

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

import me.justahuman.slimefun_essentials.SlimefunEssentials;
import me.justahuman.slimefun_essentials.client.ResourceLoader;
import me.justahuman.slimefun_essentials.client.SlimefunRecipeComponent;
import me.justahuman.slimefun_essentials.utils.Utils;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
Expand All @@ -19,7 +19,7 @@ default T interpretId(@NotNull SlimefunRecipeComponent component, @NotNull Strin
}

if (!id.contains(":")) {
Utils.warn("Invalid Ingredient Id:" + id);
SlimefunEssentials.LOGGER.error("Invalid Ingredient Id: {}", id);
return def;
}

Expand Down Expand Up @@ -65,25 +65,29 @@ else if (type.startsWith("?")) {
// Entity
else if (type.startsWith("@")) {
final boolean baby = type.startsWith("baby_", 1);
final Identifier identifier = new Identifier("minecraft:" + type.substring(baby ? 6 : 1));
if (! Registries.ENTITY_TYPE.containsId(identifier)) {
Utils.warn("Invalid Ingredient Entity Id: " + id);
final Identifier identifier = Identifier.tryParse("minecraft:" + type.substring(baby ? 6 : 1));
if (identifier == null || !Registries.ENTITY_TYPE.containsId(identifier)) {
SlimefunEssentials.LOGGER.error("Invalid Ingredient Entity Id: {}", id);
return def;
}
return fromEntityType(chance, Registries.ENTITY_TYPE.get(identifier), baby, amount, def);
}
// Fluid
else if (type.startsWith("~")) {
final Identifier identifier = new Identifier("minecraft:" + type.substring(1));
if (!Registries.FLUID.containsId(identifier)) {
Utils.warn("Invalid Ingredient Fluid Id: " + id);
final Identifier identifier = Identifier.tryParse("minecraft:" + type.substring(1));
if (identifier == null || !Registries.FLUID.containsId(identifier)) {
SlimefunEssentials.LOGGER.error("Invalid Ingredient Fluid Id: {}", id);
return def;
}
return fromFluid(chance, FluidVariant.of(Registries.FLUID.get(identifier)), amount, def);
}
// Tag
else if (type.startsWith("#")) {
final Identifier identifier = new Identifier("minecraft:" + type.substring(1));
final Identifier identifier = Identifier.tryParse("minecraft:" + type.substring(1));
if (identifier == null) {
SlimefunEssentials.LOGGER.error("Invalid Ingredient Tag Id: {}", id);
return def;
}
return fromTag(chance, TagKey.of(Registries.ITEM.getKey(), identifier), amount, def);
}
// Experience
Expand All @@ -92,9 +96,9 @@ else if (type.equals("$")) {
}
// Item (Or Mistake)
else {
final Identifier identifier = new Identifier("minecraft:" + type.toLowerCase());
if (!Registries.ITEM.containsId(identifier)) {
Utils.warn("Invalid Ingredient ItemStack Id: " + id);
final Identifier identifier = Identifier.tryParse("minecraft:" + type.toLowerCase());
if (identifier == null || !Registries.ITEM.containsId(identifier)) {
SlimefunEssentials.LOGGER.error("Invalid Ingredient Item Id: {}", id);
return def;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static JsonObject jsonObjectFromResource(Resource resource) {
final InputStream inputStream = resource.getInputStream();
return gson.fromJson(new InputStreamReader(inputStream, StandardCharsets.UTF_8), JsonObject.class);
} catch(IOException e) {
Utils.error(e);
SlimefunEssentials.LOGGER.error("Failed to load resource", e);
return new JsonObject();
}
}
Expand Down Expand Up @@ -281,7 +281,7 @@ public static void loadBlockModels(ResourceManager manager) {
* @param id The {@link String} id that represents a Slimefun Item
*/
public static void addBlockModel(String id) {
blockModels.put(id, new Identifier("minecraft", "block/" + id));
blockModels.put(id, Identifier.of("minecraft", "block/" + id));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import lombok.NonNull;
import me.justahuman.slimefun_essentials.SlimefunEssentials;
import me.justahuman.slimefun_essentials.utils.JsonUtils;
import me.justahuman.slimefun_essentials.utils.Utils;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;

Expand All @@ -19,10 +21,10 @@
public record SlimefunItemGroup(Identifier identifier, ItemStack itemStack, List<String> content, List<String> requirements) {
private static final Map<String, SlimefunItemGroup> itemGroups = new LinkedHashMap<>();
private static final Map<String, SlimefunItemGroup> byContent = new HashMap<>();
private static final SlimefunItemGroup EMPTY = new SlimefunItemGroup(new Identifier("slimefun_essentials", "empty"), ItemStack.EMPTY, List.of(), List.of());
private static final SlimefunItemGroup EMPTY = new SlimefunItemGroup(Utils.id("empty"), ItemStack.EMPTY, List.of(), List.of());

public static void deserialize(String addon, String id, JsonObject groupObject) {
final Identifier identifier = new Identifier(addon, id);
final Identifier identifier = Identifier.of(addon, id);
final ItemStack itemStack = JsonUtils.deserializeItem(JsonUtils.getObject(groupObject, "item", null));
final List<String> content = new ArrayList<>();
final List<String> requirements = new ArrayList<>();
Expand Down Expand Up @@ -64,7 +66,7 @@ public static void addParents() {
for (String content : itemGroup.content()) {
final SlimefunItemGroup child = itemGroups.get(content);
if (child != null) {
child.requirements().add("slimefun_essentials:" + itemGroup.identifier().toString().replace(":", "_"));
child.requirements().add(SlimefunEssentials.MOD_ID + ":" + itemGroup.identifier().toString().replace(":", "_"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.emi.emi.api.stack.EmiIngredient;
import dev.emi.emi.api.stack.EmiStack;
import me.justahuman.slimefun_essentials.SlimefunEssentials;
import me.justahuman.slimefun_essentials.api.IdInterpreter;
import me.justahuman.slimefun_essentials.client.SlimefunRecipe;
import me.justahuman.slimefun_essentials.client.SlimefunRecipeComponent;
Expand Down Expand Up @@ -34,7 +35,7 @@ public EmiStack emiStackFromComponent(SlimefunRecipeComponent component) {
return emiStack;
}

Utils.warn("Invalid EmiStack Component: " + component);
SlimefunEssentials.LOGGER.error("Failed to interpret EmiStack from component: {}", component);
return EmiStack.EMPTY;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.util.Identifier;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -45,7 +43,7 @@ public void register(EmiRegistry emiRegistry) {

for (SlimefunRecipeCategory slimefunRecipeCategory : SlimefunRecipeCategory.getRecipeCategories().values()) {
final String workstationId = slimefunRecipeCategory.id();
final Identifier categoryIdentifier = Utils.newIdentifier(workstationId);
final Identifier categoryIdentifier = Utils.id(workstationId);
final EmiStack workStation = EmiStack.of(slimefunRecipeCategory.itemStack());
final SlimefunEmiCategory slimefunEmiCategory;
if (slimefunCategories.containsKey(workstationId)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.justahuman.slimefun_essentials.compat.jei;

import me.justahuman.slimefun_essentials.SlimefunEssentials;
import me.justahuman.slimefun_essentials.client.ResourceLoader;
import me.justahuman.slimefun_essentials.client.SlimefunItemGroup;
import me.justahuman.slimefun_essentials.client.SlimefunItemStack;
Expand Down Expand Up @@ -44,7 +45,7 @@ public class JeiIntegration implements IModPlugin {
@Override
@NotNull
public Identifier getPluginUid() {
return Utils.newIdentifier("jei_integration");
return Utils.id("jei_integration");
}

@Override
Expand Down Expand Up @@ -91,7 +92,7 @@ public void registerRecipes(IRecipeRegistration registration) {
}

for (SlimefunRecipeCategory recipeCategory : SlimefunRecipeCategory.getRecipeCategories().values()) {
registration.addRecipes(RecipeType.create(Utils.ID, recipeCategory.id().toLowerCase(), SlimefunRecipe.class), recipeCategory.childRecipes());
registration.addRecipes(RecipeType.create(SlimefunEssentials.MOD_ID, recipeCategory.id().toLowerCase(), SlimefunRecipe.class), recipeCategory.childRecipes());
}
}

Expand All @@ -102,7 +103,7 @@ public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
}

for (SlimefunRecipeCategory recipeCategory : SlimefunRecipeCategory.getRecipeCategories().values()) {
registration.addRecipeCatalyst(recipeCategory.itemStack(), RecipeType.create(Utils.ID, recipeCategory.id().toLowerCase(), SlimefunRecipe.class));
registration.addRecipeCatalyst(recipeCategory.itemStack(), RecipeType.create(SlimefunEssentials.MOD_ID, recipeCategory.id().toLowerCase(), SlimefunRecipe.class));
}
}

Expand All @@ -113,7 +114,7 @@ public void registerRecipeTransferHandlers(IRecipeTransferRegistration registrat
return;
}

final RecipeType<SlimefunRecipe> recipeType = RecipeType.create(Utils.ID, recipeCategory.id().toLowerCase(), SlimefunRecipe.class);
final RecipeType<SlimefunRecipe> recipeType = RecipeType.create(SlimefunEssentials.MOD_ID, recipeCategory.id().toLowerCase(), SlimefunRecipe.class);
if (recipeCategory.type().contains("grid")) {
registration.addRecipeTransferHandler(Generic3x3ContainerScreenHandler.class, ScreenHandlerType.GENERIC_3X3, recipeType, 0, 9, 9, 36);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import me.justahuman.slimefun_essentials.SlimefunEssentials;
import me.justahuman.slimefun_essentials.api.OffsetBuilder;
import me.justahuman.slimefun_essentials.api.SimpleRecipeRenderer;
import me.justahuman.slimefun_essentials.client.SlimefunRecipeCategory;
Expand All @@ -12,7 +13,6 @@
import me.justahuman.slimefun_essentials.compat.jei.JeiIntegration;
import me.justahuman.slimefun_essentials.api.ManualRecipeRenderer;
import me.justahuman.slimefun_essentials.utils.TextureUtils;
import me.justahuman.slimefun_essentials.utils.Utils;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
Expand Down Expand Up @@ -84,7 +84,7 @@ public int yPadding() {
@Override
@NotNull
public RecipeType<SlimefunRecipe> getRecipeType() {
return RecipeType.create(Utils.ID, this.slimefunRecipeCategory.id().toLowerCase(), SlimefunRecipe.class);
return RecipeType.create(SlimefunEssentials.MOD_ID, this.slimefunRecipeCategory.id().toLowerCase(), SlimefunRecipe.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
import vazkii.patchouli.client.book.ClientBookRegistry;

public class PatchouliIntegration {
public static final Identifier BOOK_IDENTIFIER = Utils.newIdentifier("slimefun");
public static final Identifier BOOK_IDENTIFIER = Utils.id("slimefun");
public static final PatchouliIdInterpreter INTERPRETER = new PatchouliIdInterpreter();

public static void init() {
ClientBookRegistry.INSTANCE.pageTypes.put(Utils.newIdentifier("ancient_altar"), AncientAltarPage.class);
ClientBookRegistry.INSTANCE.pageTypes.put(Utils.newIdentifier("grid"), GridPage.class);
ClientBookRegistry.INSTANCE.pageTypes.put(Utils.newIdentifier("process"), ProcessPage.class);
ClientBookRegistry.INSTANCE.pageTypes.put(Utils.newIdentifier("reactor"), ReactorPage.class);
ClientBookRegistry.INSTANCE.pageTypes.put(Utils.newIdentifier("smeltery"), SmelteryPage.class);
ClientBookRegistry.INSTANCE.pageTypes.put(Utils.id("ancient_altar"), AncientAltarPage.class);
ClientBookRegistry.INSTANCE.pageTypes.put(Utils.id("grid"), GridPage.class);
ClientBookRegistry.INSTANCE.pageTypes.put(Utils.id("process"), ProcessPage.class);
ClientBookRegistry.INSTANCE.pageTypes.put(Utils.id("reactor"), ReactorPage.class);
ClientBookRegistry.INSTANCE.pageTypes.put(Utils.id("smeltery"), SmelteryPage.class);
}

public static JsonObject getItemGroupCategory(SlimefunItemGroup itemGroup, int sortnum) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public DrawMode getDrawMode() {
@Override
@NotNull
public CategoryIdentifier<T> getCategoryIdentifier() {
return CategoryIdentifier.of(Utils.newIdentifier(this.slimefunRecipeCategory.id().toLowerCase()));
return CategoryIdentifier.of(Utils.id(this.slimefunRecipeCategory.id().toLowerCase()));
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public List<EntryIngredient> getOutputEntries() {

@Override
public CategoryIdentifier<?> getCategoryIdentifier() {
return CategoryIdentifier.of(Utils.newIdentifier(this.slimefunRecipeCategory.id().toLowerCase()));
return CategoryIdentifier.of(Utils.id(this.slimefunRecipeCategory.id().toLowerCase()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.google.gson.JsonPrimitive;
import lombok.Getter;
import lombok.Setter;
import me.justahuman.slimefun_essentials.SlimefunEssentials;
import me.justahuman.slimefun_essentials.utils.JsonUtils;
import me.justahuman.slimefun_essentials.utils.Utils;
import net.fabricmc.loader.api.FabricLoader;
Expand Down Expand Up @@ -51,8 +52,7 @@ public static void loadConfig() {
jsonObject.entrySet().forEach(entry -> root.add(entry.getKey(), entry.getValue()));
}
} catch (Exception e) {
Utils.warn("Error occurred while loading Config!");
Utils.warn(e.getMessage());
SlimefunEssentials.LOGGER.error("Error occurred while reading Config!", e);
}

loadConfigOption(() -> blockFeatures = JsonUtils.getBool(root, "block_features", true, true));
Expand Down Expand Up @@ -87,8 +87,7 @@ private static void loadConfigOption(Runnable runnable) {
try {
runnable.run();
} catch (Exception e) {
Utils.warn("Error occurred while loading Config!");
Utils.warn(e.getMessage());
SlimefunEssentials.LOGGER.error("Error occurred while loading Config!", e);
}
}

Expand Down Expand Up @@ -125,8 +124,7 @@ public static void saveConfig() {
gson.toJson(root, fileWriter);
fileWriter.flush();
} catch (IOException e) {
Utils.warn("Error occurred while saving Config!");
Utils.warn(e.getMessage());
SlimefunEssentials.LOGGER.error("Error occurred while saving Config!", e);
}
}

Expand Down Expand Up @@ -189,8 +187,7 @@ public static File getConfigFile() {
throw new IOException();
}
} catch(IOException | SecurityException e) {
Utils.warn("Failed to create config file!");
Utils.warn(e.getMessage());
SlimefunEssentials.LOGGER.error("Error occurred creating Config file!", e);
}
}
return configFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ private void buildSlimefun(World level, CallbackInfoReturnable<BookContents> cir
int i = 0;
final Map<String, SlimefunRecipeCategory> recipeCategories = SlimefunRecipeCategory.getAllCategories();
for (SlimefunItemGroup itemGroup : SlimefunItemGroup.getItemGroups().values()) {
final Identifier identifier = Utils.newIdentifier(itemGroup.identifier().toString().replace(":", "_"));
final Identifier identifier = Utils.id(itemGroup.identifier().toString().replace(":", "_"));
final BookCategory category = new BookCategory(PatchouliIntegration.getItemGroupCategory(itemGroup, i), identifier, this.book);
this.categories.put(identifier, category);

int c = 0;
for (String content : itemGroup.content()) {
final SlimefunRecipeCategory recipeCategory = recipeCategories.get(content);
if (recipeCategory != null) {
final Identifier recipe = Utils.newIdentifier(content);
final Identifier recipe = Utils.id(content);
final BookEntry recipeEntry = new BookEntry(PatchouliIntegration.getRecipeEntry(category, recipeCategory, c), recipe, book, null);
recipeEntry.initCategory(recipe, ignored -> category);
this.entries.put(recipe, recipeEntry);
Expand Down
Loading

0 comments on commit 4ebd3a6

Please sign in to comment.