Skip to content

Commit

Permalink
Merge pull request #41 from UselessBullets/recipeFixes
Browse files Browse the repository at this point in the history
Recipe fixes
  • Loading branch information
UselessBullets authored Dec 20, 2023
2 parents 61f7917 + c203665 commit 3c5fab7
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
@@ -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<ItemStack> 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 + "'");
}
}

Original file line number Diff line number Diff line change
@@ -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<Boolean> cir){
FabricLoader.getInstance().getEntrypoints("recipesReady", RecipeEntrypoint.class).forEach(RecipeEntrypoint::onRecipesReady);
}
}
15 changes: 8 additions & 7 deletions src/main/resources/halplibe.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,30 @@
"accessors.TileEntityAccessor",
"mixins.BlockFireMixin",
"mixins.I18nMixin",
"mixins.ItemStackJsonAdapterMixin",
"mixins.network.EntityTrackerEntryMixin",
"mixins.network.NetworkManagerMixin",
"mixins.network.PacketMixin",
"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"
Expand Down

0 comments on commit 3c5fab7

Please sign in to comment.