Skip to content

Commit

Permalink
backport recipe changes to 1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Treetrain1 committed Nov 5, 2023
1 parent 785196a commit e1cea00
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 121 deletions.

This file was deleted.

47 changes: 0 additions & 47 deletions src/main/java/net/frozenblock/lib/recipe/mixin/ItemValueMixin.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.mojang.serialization.JsonOps;
import net.frozenblock.lib.recipe.api.ShapedRecipeBuilderExtension;
import net.minecraft.data.recipes.FinishedRecipe;
import net.minecraft.data.recipes.RecipeOutput;
import net.minecraft.data.recipes.ShapedRecipeBuilder;
import net.minecraft.nbt.CompoundTag;
import org.jetbrains.annotations.Nullable;
Expand All @@ -35,6 +34,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.function.Consumer;

@Mixin(ShapedRecipeBuilder.class)
public class ShapedRecipeBuilderMixin implements ShapedRecipeBuilderExtension {
Expand All @@ -60,10 +60,10 @@ public class ShapedRecipeBuilderMixin implements ShapedRecipeBuilderExtension {
method = "save",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/data/recipes/RecipeOutput;accept(Lnet/minecraft/data/recipes/FinishedRecipe;)V"
target = "Ljava/util/function/Consumer;accept(Ljava/lang/Object;)V"
)
)
private void modifySave(RecipeOutput instance, FinishedRecipe recipe, Operation<?> operation) {
private void modifySave(Consumer<FinishedRecipe> instance, Object recipe, Operation<?> operation) {
((ShapedRecipeBuilderExtension) recipe).frozenLib$tag(this.tag);
operation.call(instance, recipe);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2023 FrozenBlock
* This file is part of FrozenLib.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see <https://www.gnu.org/licenses/>.
*/

package net.frozenblock.lib.recipe.mixin;

import com.google.gson.JsonObject;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.mojang.serialization.JsonOps;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.ShapedRecipe;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

/**
* Adds {@link CompoundTag} data support to crafting recipes.
* @since 1.4.1
*/
@Mixin(ShapedRecipe.class)
public class ShapedRecipeMixin {

@ModifyReturnValue(method = "itemStackFromJson", at = @At("RETURN"))
private static ItemStack itemStackFromJson(ItemStack stack, JsonObject stackObject) {
if (stackObject.has("tag"))
stack.setTag(CompoundTag.CODEC.decode(JsonOps.INSTANCE, stackObject.get("tag")).getOrThrow(false, error -> {}).getFirst());
return stack;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/frozenlib.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ transitive-mutable field net/minecraft/advancements/AdvancementRewards function

# Recipe
transitive-accessible method net/minecraft/world/item/crafting/Ingredient$ItemValue <init> (Lnet/minecraft/world/item/ItemStack;)V
transitive-accessible field net/minecraft/world/item/crafting/CraftingRecipeCodecs ITEMSTACK_NONAIR_CODEC Lcom/mojang/serialization/Codec;
#transitive-accessible field net/minecraft/world/item/crafting/CraftingRecipeCodecs ITEMSTACK_NONAIR_CODEC Lcom/mojang/serialization/Codec;
transitive-accessible class net/minecraft/data/recipes/ShapedRecipeBuilder$Result

# Sculk Spreading
Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/mixin/frozenlib.recipe.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"defaultRequire": 1
},
"mixins": [
"CraftingRecipeCodecsMixin",
"ItemValueMixin",
"ShapedRecipeMixin",
"ShapedRecipeBuilderMixin",
"ShapedRecipeBuilderMixin$ResultMixin"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"requirements": [
[
"has_the_recipe",
"has_dragon_egg"
"has_dragon_egg",
"has_the_recipe"
]
],
"rewards": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,33 @@

import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricLootTableProvider;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
import net.fabricmc.fabric.api.datagen.v1.provider.SimpleFabricLootTableProvider;
import net.fabricmc.fabric.api.recipe.v1.ingredient.DefaultCustomIngredients;
import net.frozenblock.lib.datagen.api.FrozenBiomeTagProvider;
import net.frozenblock.lib.ingamedevtools.RegisterInGameDevTools;
import net.frozenblock.lib.recipe.api.ShapedRecipeUtil;
import net.frozenblock.lib.tag.api.FrozenBlockTags;
import net.frozenblock.lib.testmod.FrozenTestMain;
import net.minecraft.advancements.critereon.InventoryChangeTrigger;
import net.minecraft.core.HolderLookup;
import net.minecraft.data.recipes.FinishedRecipe;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.data.recipes.RecipeOutput;
import net.minecraft.data.recipes.ShapedRecipeBuilder;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BiomeTags;
import net.minecraft.world.item.Instruments;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.biome.Biomes;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.storage.loot.LootPool;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.entries.LootItem;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSet;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;

Expand All @@ -73,7 +68,7 @@ public TestRecipeProvider(FabricDataOutput output) {
}

@Override
public void buildRecipes(RecipeOutput exporter) {
public void buildRecipes(Consumer<FinishedRecipe> exporter) {
ShapedRecipeUtil.withResultTag(
ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, Items.GOAT_HORN)
.define('E', Items.DRAGON_EGG)
Expand Down

0 comments on commit e1cea00

Please sign in to comment.