Skip to content

Commit

Permalink
Ported the mod to 1.19.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Kir-Antipov committed Dec 21, 2023
1 parent 7569539 commit b4b95f6
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 30 deletions.
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
minecraft_version=1.19
yarn_mappings=1.19+build.1
loader_version=0.14.6
minecraft_version=1.19.3
yarn_mappings=1.19.3+build.5
loader_version=0.15.3

# Mod Properties
mod_version=0.2.1
maven_group=dev.kir
archives_base_name=smart-recipes

# Dependencies
fabric_version=0.55.2+1.19
fabric_version=0.68.1+1.19.3
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.minecraft.util.JsonHelper;
import net.minecraft.util.registry.Registry;
import org.jetbrains.annotations.Nullable;

@FunctionalInterface
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/dev/kir/smartrecipes/api/RecipeConditions.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.metadata.version.VersionPredicate;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.SimpleRegistry;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.util.registry.SimpleRegistry;
import net.minecraft.world.Difficulty;
import net.minecraft.world.GameMode;
import net.minecraft.world.WorldProperties;
Expand All @@ -24,7 +25,7 @@

final class RecipeConditions {
public static final RegistryKey<Registry<RecipeCondition>> KEY = RegistryKey.ofRegistry(SmartRecipes.locate("recipe_condition"));
public static final Registry<RecipeCondition> REGISTRY = new SimpleRegistry<>(KEY, Lifecycle.experimental(), null);
public static final Registry<RecipeCondition> REGISTRY = new SimpleRegistry<>(KEY, Lifecycle.experimental());


public static final RecipeCondition FALSE = (e, i) -> false;
Expand Down Expand Up @@ -151,15 +152,15 @@ final class RecipeConditions {


public static final RecipeCondition ENTRIES_REGISTERED = (e, i) -> JsonUtil.flatMap(e, RegistryEntry::parse, RegistryEntry::parse).allMatch(x -> {
Registry<?> registry = Registry.REGISTRIES.get(new Identifier(x.registry()));
Registry<?> registry = Registries.REGISTRIES.get(new Identifier(x.registry()));
return registry != null && registry.containsId(new Identifier(x.entry()));
});

public static final RecipeCondition BLOCKS_REGISTERED = (e, i) -> JsonUtil.flatMap(e).allMatch(x -> Registry.BLOCK.containsId(new Identifier(x.getAsString())));
public static final RecipeCondition BLOCKS_REGISTERED = (e, i) -> JsonUtil.flatMap(e).allMatch(x -> Registries.BLOCK.containsId(new Identifier(x.getAsString())));

public static final RecipeCondition ITEMS_REGISTERED = (e, i) -> JsonUtil.flatMap(e).allMatch(x -> Registry.ITEM.containsId(new Identifier(x.getAsString())));
public static final RecipeCondition ITEMS_REGISTERED = (e, i) -> JsonUtil.flatMap(e).allMatch(x -> Registries.ITEM.containsId(new Identifier(x.getAsString())));

public static final RecipeCondition BLOCK_ENTITIES_REGISTERED = (e, i) -> JsonUtil.flatMap(e).allMatch(x -> Registry.BLOCK_ENTITY_TYPE.containsId(new Identifier(x.getAsString())));
public static final RecipeCondition BLOCK_ENTITIES_REGISTERED = (e, i) -> JsonUtil.flatMap(e).allMatch(x -> Registries.BLOCK_ENTITY_TYPE.containsId(new Identifier(x.getAsString())));


public static final RecipeCondition MODS_LOADED = (e, i) -> JsonUtil.flatMap(e, ModEntry::parse, ModEntry::parse).allMatch(x -> {
Expand Down Expand Up @@ -197,7 +198,7 @@ private static Stream<Boolean> test(JsonElement element, RecipeInfo info) {
}

private static Difficulty parseDifficulty(JsonPrimitive jsonPrimitive) {
return jsonPrimitive.isNumber() ? Difficulty.byOrdinal(jsonPrimitive.getAsInt()) : Difficulty.byName(jsonPrimitive.getAsString().toLowerCase());
return jsonPrimitive.isNumber() ? Difficulty.byId(jsonPrimitive.getAsInt()) : Difficulty.byName(jsonPrimitive.getAsString().toLowerCase());
}

private static GameMode parseGameMode(JsonPrimitive jsonPrimitive) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/kir/smartrecipes/api/RecipeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import net.minecraft.recipe.Recipe;
import net.minecraft.recipe.RecipeManager;
import net.minecraft.recipe.RecipeType;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import org.jetbrains.annotations.Contract;

import java.util.Optional;
Expand Down Expand Up @@ -39,7 +39,7 @@ public Optional<RecipeType<?>> getRecipeType() {
String type = this.recipeObject.get("type") instanceof JsonPrimitive typePrimitive && typePrimitive.isString() ? typePrimitive.getAsString() : null;
Identifier id = type == null ? null : Identifier.tryParse(type);
if (id != null) {
this.recipeType = Registry.RECIPE_TYPE.getOrEmpty(id).or(() -> Registry.RECIPE_TYPE.getOrEmpty(new Identifier(id.getNamespace(), id.getPath().split("_")[0]))).orElse(null);
this.recipeType = Registries.RECIPE_TYPE.getOrEmpty(id).or(() -> Registries.RECIPE_TYPE.getOrEmpty(new Identifier(id.getNamespace(), id.getPath().split("_")[0]))).orElse(null);
}
}
return Optional.ofNullable(this.recipeType);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.kir.smartrecipes.api;

import net.minecraft.registry.Registry;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import org.jetbrains.annotations.Nullable;

public interface RecipeReloadCondition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import net.fabricmc.fabric.api.event.EventFactory;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.util.registry.SimpleRegistry;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.SimpleRegistry;

import java.util.function.BiConsumer;

final class RecipeReloadConditions {
public static final RegistryKey<Registry<RecipeReloadCondition>> KEY = RegistryKey.ofRegistry(SmartRecipes.locate("recipe_reload_condition"));
public static final Registry<RecipeReloadCondition> REGISTRY = new SimpleRegistry<>(KEY, Lifecycle.experimental(), null);
public static final Registry<RecipeReloadCondition> REGISTRY = new SimpleRegistry<>(KEY, Lifecycle.experimental());


public static final RecipeReloadCondition END_DATA_PACK_RELOAD = create(ServerLifecycleEvents.END_DATA_PACK_RELOAD, ServerLifecycleEvents.SERVER_STARTED, (e, c) -> e.register((s, __, ___) -> c.invoker().onRecipeReloadEvent(s, c.getId())), (e, c) -> e.register(s -> c.invoker().onRecipeReloadEvent(s, c.getId())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.google.gson.JsonObject;
import dev.kir.smartrecipes.SmartRecipes;
import dev.kir.smartrecipes.api.RecipeInfo;
import dev.kir.smartrecipes.api.ReloadableRecipeManager;
import dev.kir.smartrecipes.util.recipe.RecipeBookUtil;
import dev.kir.smartrecipes.api.RecipeInfo;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
Expand All @@ -17,10 +17,10 @@
import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.recipe.RecipeType;
import net.minecraft.recipe.book.RecipeBook;
import net.minecraft.registry.Registries;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.Pair;
import net.minecraft.util.registry.Registry;

import java.util.Collection;
import java.util.Optional;
Expand Down Expand Up @@ -67,27 +67,27 @@ private static <T extends Recipe<?>> void writeRecipeEntry(PacketByteBuf buf, Pa
T recipe = (T)recipeInfo.getRecipe().orElseThrow(() -> new IllegalArgumentException("Unable to parse recipe '" + recipeInfo.getRecipeId() + "'"));

buf.writeBoolean(true);
buf.writeIdentifier(Registry.RECIPE_SERIALIZER.getId(recipe.getSerializer()));
buf.writeIdentifier(Registries.RECIPE_SERIALIZER.getId(recipe.getSerializer()));
buf.writeIdentifier(recipe.getId());
((RecipeSerializer<T>)recipe.getSerializer()).write(buf, recipe);
} else {
buf.writeBoolean(false);
buf.writeIdentifier(recipeInfo.getRecipeId());
buf.writeIdentifier(Registry.RECIPE_TYPE.getId(recipeInfo.getRecipeType().orElseThrow(() -> new IllegalArgumentException("Recipe '" + recipeInfo.getRecipeId() + "' uses invalid or unsupported recipe type"))));
buf.writeIdentifier(Registries.RECIPE_TYPE.getId(recipeInfo.getRecipeType().orElseThrow(() -> new IllegalArgumentException("Recipe '" + recipeInfo.getRecipeId() + "' uses invalid or unsupported recipe type"))));
}
}

private static Pair<ReloadableRecipeManager.RecipeState, RecipeInfo> readRecipeEntry(PacketByteBuf buf) {
if (buf.readBoolean()) {
Identifier serializerId = buf.readIdentifier();
RecipeSerializer<?> serializer = Registry.RECIPE_SERIALIZER.getOrEmpty(serializerId).orElseThrow(() -> new IllegalArgumentException("Unknown recipe serializer " + serializerId));
RecipeSerializer<?> serializer = Registries.RECIPE_SERIALIZER.getOrEmpty(serializerId).orElseThrow(() -> new IllegalArgumentException("Unknown recipe serializer " + serializerId));
Identifier recipeId = buf.readIdentifier();
Recipe<?> recipe = serializer.read(recipeId, buf);
return new Pair<>(ReloadableRecipeManager.RecipeState.KEEP, new SerializableRecipeInfo(recipeId, recipe));
} else {
Identifier recipeId = buf.readIdentifier();
Identifier recipeTypeId = buf.readIdentifier();
RecipeType<?> recipeType = Registry.RECIPE_TYPE.getOrEmpty(recipeTypeId).orElseThrow(() -> new IllegalArgumentException("Invalid or unsupported recipe type '" + recipeTypeId + "'"));
RecipeType<?> recipeType = Registries.RECIPE_TYPE.getOrEmpty(recipeTypeId).orElseThrow(() -> new IllegalArgumentException("Invalid or unsupported recipe type '" + recipeTypeId + "'"));
return new Pair<>(ReloadableRecipeManager.RecipeState.REMOVE, new SerializableRecipeInfo(recipeId, recipeType));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import dev.kir.smartrecipes.api.event.WorldStateEvents;
import dev.kir.smartrecipes.util.world.TimeOfDay;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.WorldGenerationProgressListener;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.profiler.Profiler;
import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.MutableWorldProperties;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionOptions;
Expand Down Expand Up @@ -42,7 +42,7 @@ abstract class ServerWorldMixin extends World {
@Unique
private TimeOfDay timeOfDay;

private ServerWorldMixin(MutableWorldProperties properties, RegistryKey<World> registryRef, RegistryEntry<DimensionType> dimension, Supplier<Profiler> profiler, boolean isClient, boolean debugWorld, long seed, int maxChainedNeighborUpdates) {
protected ServerWorldMixin(MutableWorldProperties properties, RegistryKey<World> registryRef, RegistryEntry<DimensionType> dimension, Supplier<Profiler> profiler, boolean isClient, boolean debugWorld, long seed, int maxChainedNeighborUpdates) {
super(properties, registryRef, dimension, profiler, isClient, debugWorld, seed, maxChainedNeighborUpdates);
}

Expand Down

0 comments on commit b4b95f6

Please sign in to comment.