From 9d6af7a62681b8f62ae1fd4b635437087fd0c47b Mon Sep 17 00:00:00 2001 From: UselessBullets <80850784+UselessBullets@users.noreply.github.com> Date: Wed, 20 Dec 2023 02:15:57 -0600 Subject: [PATCH 1/3] recipe entrypoint now loads on server --- .../mixin/mixins/MinecraftServerMixin.java | 17 +++++++++++++++++ src/main/resources/halplibe.mixins.json | 14 +++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 src/main/java/turniplabs/halplibe/mixin/mixins/MinecraftServerMixin.java diff --git a/src/main/java/turniplabs/halplibe/mixin/mixins/MinecraftServerMixin.java b/src/main/java/turniplabs/halplibe/mixin/mixins/MinecraftServerMixin.java new file mode 100644 index 0000000..939d110 --- /dev/null +++ b/src/main/java/turniplabs/halplibe/mixin/mixins/MinecraftServerMixin.java @@ -0,0 +1,17 @@ +package turniplabs.halplibe.mixin.mixins; + +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.server.MinecraftServer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import turniplabs.halplibe.util.RecipeEntrypoint; + +@Mixin(value = MinecraftServer.class, remap = false) +public class MinecraftServerMixin { + @Inject(method = "startServer", at = @At(value = "INVOKE",target = "Lnet/minecraft/core/data/DataLoader;loadRecipes(Ljava/lang/String;)V", ordinal = 3, shift = At.Shift.AFTER)) + public void recipeEntrypoint(CallbackInfoReturnable cir){ + FabricLoader.getInstance().getEntrypoints("recipesReady", RecipeEntrypoint.class).forEach(RecipeEntrypoint::onRecipesReady); + } +} diff --git a/src/main/resources/halplibe.mixins.json b/src/main/resources/halplibe.mixins.json index 0a38044..69f079e 100644 --- a/src/main/resources/halplibe.mixins.json +++ b/src/main/resources/halplibe.mixins.json @@ -18,23 +18,23 @@ "mixins.registry.BlockMixin", "mixins.registry.ItemMixin", "mixins.version.NetHandlerMixin" - ], "client": [ "accessors.RenderManagerAccessor", "accessors.TileEntityRendererAccessor", "mixins.BlockSoundDispatcherMixin", - "mixins.RenderGlobalMixin", - "mixins.RenderEngineMixin", "mixins.EntityClientPlayerMPMixin", - "mixins.network.NetClientHandlerMixin", + "mixins.GuiIngameMenuMixin", "mixins.MinecraftMixin", + "mixins.RenderEngineMixin", + "mixins.RenderGlobalMixin", "mixins.network.MinecraftMixin", - "mixins.version.NetClientHandlerMixin", - "mixins.GuiIngameMenuMixin", - "mixins.registry.MinecraftMixin" + "mixins.network.NetClientHandlerMixin", + "mixins.registry.MinecraftMixin", + "mixins.version.NetClientHandlerMixin" ], "server": [ + "mixins.MinecraftServerMixin", "mixins.network.MinecraftServerMixin", "mixins.registry.MinecraftServerMixin", "mixins.version.NetLoginHandlerMixin" From 0d23e28306cf58e8d903e36bc6d11e9c9301d0dc Mon Sep 17 00:00:00 2001 From: UselessBullets <80850784+UselessBullets@users.noreply.github.com> Date: Wed, 20 Dec 2023 02:34:15 -0600 Subject: [PATCH 2/3] Added "key" component as alternative to "id" --- .../mixins/ItemStackJsonAdapterMixin.java | 40 +++++++++++++++++++ src/main/resources/halplibe.mixins.json | 1 + 2 files changed, 41 insertions(+) create mode 100644 src/main/java/turniplabs/halplibe/mixin/mixins/ItemStackJsonAdapterMixin.java diff --git a/src/main/java/turniplabs/halplibe/mixin/mixins/ItemStackJsonAdapterMixin.java b/src/main/java/turniplabs/halplibe/mixin/mixins/ItemStackJsonAdapterMixin.java new file mode 100644 index 0000000..a1234a2 --- /dev/null +++ b/src/main/java/turniplabs/halplibe/mixin/mixins/ItemStackJsonAdapterMixin.java @@ -0,0 +1,40 @@ +package turniplabs.halplibe.mixin.mixins; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import net.minecraft.core.data.registry.recipe.adapter.ItemStackJsonAdapter; +import net.minecraft.core.item.Item; +import net.minecraft.core.item.ItemStack; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.lang.reflect.Type; + +@Mixin(value = ItemStackJsonAdapter.class, remap = false) +public class ItemStackJsonAdapterMixin { + @Inject(method = "deserialize(Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Lnet/minecraft/core/item/ItemStack;", + at = @At("HEAD"), cancellable = true) + protected void deserializeKey(JsonElement json, Type typeOfT, JsonDeserializationContext context, CallbackInfoReturnable cir){ + JsonObject obj = json.getAsJsonObject(); + if (obj.has("key")){ + ItemStack stack = obj.has("amount") ? new ItemStack(getItemFromKey(obj.get("key").getAsString()), obj.get("amount").getAsInt(), obj.get("meta").getAsInt()) : new ItemStack(getItemFromKey(obj.get("key").getAsString()), 1, obj.get("meta").getAsInt()); + cir.setReturnValue(stack); + } + } + @Unique + private Item getItemFromKey(String key){ + for(Item item : Item.itemsList) { + if (item != null) { + if (item.getKey().equalsIgnoreCase(key)) { + return item; + } + } + } + throw new NullPointerException("Could not find an item that corresponds to key '" + key + "'"); + } +} + diff --git a/src/main/resources/halplibe.mixins.json b/src/main/resources/halplibe.mixins.json index 69f079e..82df10b 100644 --- a/src/main/resources/halplibe.mixins.json +++ b/src/main/resources/halplibe.mixins.json @@ -12,6 +12,7 @@ "accessors.TileEntityAccessor", "mixins.BlockFireMixin", "mixins.I18nMixin", + "mixins.ItemStackJsonAdapterMixin", "mixins.network.EntityTrackerEntryMixin", "mixins.network.NetworkManagerMixin", "mixins.network.PacketMixin", From c203665070c8df1d121a910e434818b2adfeff27 Mon Sep 17 00:00:00 2001 From: UselessBullets <80850784+UselessBullets@users.noreply.github.com> Date: Wed, 20 Dec 2023 02:48:13 -0600 Subject: [PATCH 3/3] Update gradle.properties --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index f2ef618..7f36703 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ bta_version=7.1-pre1 loader_version=0.14.19-babric.2-bta # Mod -mod_version=3.0.2 +mod_version=3.0.3 mod_group=turniplabs mod_name=halplibe