Skip to content

Commit

Permalink
1.20.4
Browse files Browse the repository at this point in the history
  • Loading branch information
UnlikePaladin committed Jan 27, 2025
1 parent f4003a1 commit 4b8a78f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public List<EntryIngredient> getInputEntries() {

List<Ingredient> inputEntries = new ArrayList<>();
this.itemsPerInnerRecipe = recipe.value().getMaxInnerRecipeSize();
for (FurnitureRecipe.CraftableFurnitureRecipe innerRecipe: recipe.getInnerRecipes()) {
List<Ingredient> ingredients = innerRecipe.value().getIngredients();
for (FurnitureRecipe.CraftableFurnitureRecipe innerRecipe: recipe.value().getInnerRecipes()) {
List<Ingredient> ingredients = innerRecipe.getIngredients();
HashMap<Item, Integer> containedItems = new HashMap<>();
for (Ingredient ingredient : ingredients) {
for (ItemStack stack : ingredient.getMatchingStacks()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public static class FurnitureOutput {
private final int outputCount;
private final NbtCompound nbt;

private FurnitureOutput(String outputClass, int outputCount, NbtCompound nbt) {
public FurnitureOutput(String outputClass, int outputCount, NbtCompound nbt) {
this.outputClass = outputClass;
this.outputCount = outputCount;
this.nbt = nbt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
import com.google.gson.JsonObject;
import com.mojang.serialization.JsonOps;
import com.unlikepaladin.pfm.PaladinFurnitureMod;
import com.unlikepaladin.pfm.recipes.DynamicFurnitureRecipe;
import com.unlikepaladin.pfm.registry.RecipeTypes;
import net.minecraft.advancement.*;
import net.minecraft.advancement.criterion.CriterionConditions;
import net.minecraft.advancement.criterion.RecipeUnlockedCriterion;
import net.minecraft.block.Block;
import net.minecraft.data.server.recipe.RecipeExporter;
import net.minecraft.data.server.recipe.RecipeJsonProvider;
import net.minecraft.item.Item;
import net.minecraft.item.ItemConvertible;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.NbtTypes;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.registry.tag.TagKey;
Expand Down Expand Up @@ -163,8 +165,11 @@ public DynamicFurnitureRecipeJsonFactory childInput(String ingredient) {
}

public void offerTo(RecipeExporter exporter, Identifier recipeId) {
this.builder.parent(new Identifier("recipes/root")).criterion("has_the_recipe", RecipeUnlockedCriterion.create(recipeId)).rewards(AdvancementRewards.Builder.recipe(recipeId)).criteriaMerger(AdvancementRequirements.CriterionMerger.OR);
exporter.accept(new DynamicFurnitureRecipeJsonProvider(recipeId, outputClass, nbtElement, outputCount, group, vanillaIngredients, supportedVariants, variantChildren, builder.build(new Identifier(recipeId.getNamespace(), "recipes/furniture/" + recipeId.getPath()))));
exporter.accept(recipeId,
new DynamicFurnitureRecipe(this.group == null || this.group.isBlank() ? " " : this.group,
new DynamicFurnitureRecipe.FurnitureOutput(outputClass, outputCount, nbtElement != null && nbtElement.getNbtType() == NbtCompound.TYPE ? (NbtCompound) nbtElement : new NbtCompound()), supportedVariants,
new DynamicFurnitureRecipe.FurnitureIngredients(vanillaIngredients, variantChildren)),
builder.build(recipeId.withPrefixedPath("recipes/furniture/")));
}


Expand All @@ -180,87 +185,4 @@ public void offerTo(RecipeExporter exporter, String recipePath) {
}
this.offerTo(exporter, identifier2);
}


public static class DynamicFurnitureRecipeJsonProvider
implements RecipeJsonProvider {
private final Identifier recipeId;
private final String outputClass;
private final int count;
private final String group;
private final List<Ingredient> vanillaIngredients;
private final Map<String, Integer> variantChildren;
private final List<Identifier> supportedVariants;
private final AdvancementEntry advancement;
@Nullable
private final NbtElement nbtElement;

public DynamicFurnitureRecipeJsonProvider(Identifier recipeId, String outputClass, @Nullable NbtElement nbtElement, int outputCount, String group, List<Ingredient> vanillaIngredients, List<Identifier> supportedVariants, Map<String, Integer> variantChildren, AdvancementEntry advancement) {
this.recipeId = recipeId;
this.outputClass = outputClass;
this.count = outputCount;
this.group = group;
this.vanillaIngredients = vanillaIngredients;
this.advancement = advancement;
this.nbtElement = nbtElement;
this.variantChildren = variantChildren;
this.supportedVariants = supportedVariants;
}

@Override
public void serialize(JsonObject json) {
if (this.group != null && !this.group.isEmpty()) {
json.addProperty("group", this.group);
}
JsonArray identifierArray = new JsonArray();
for (Identifier identifier : this.supportedVariants) {
identifierArray.add(identifier.toString());
}
json.add("supportedVariants", identifierArray);

JsonObject ingredients = new JsonObject();

JsonArray ingredientArray = new JsonArray();
for (Ingredient ingredient : this.vanillaIngredients) {
ingredientArray.add(ingredient.toJson(true));
}
ingredients.add("vanillaIngredients", ingredientArray);

JsonObject variantChildrenObject = new JsonObject();
for (Map.Entry<String, Integer> entry : this.variantChildren.entrySet()) {
variantChildrenObject.addProperty(entry.getKey(), entry.getValue());
}
ingredients.add("variantChildren", variantChildrenObject);

json.add("ingredients", ingredients);

JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("outputClass", outputClass);
if (this.count > 1) {
jsonObject.addProperty("count", this.count);
}
if (nbtElement != null) {
JsonElement object = NbtOps.INSTANCE.convertTo(JsonOps.INSTANCE, this.nbtElement);
jsonObject.add("tag", object);
}
json.add("result", jsonObject);

}

@Override
public Identifier id() {
return this.recipeId;
}

@Override
public RecipeSerializer<?> serializer() {
return RecipeTypes.DYNAMIC_FURNITURE_SERIALIZER;
}

@Nullable
@Override
public AdvancementEntry advancement() {
return this.advancement;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.google.gson.JsonObject;
import com.mojang.serialization.JsonOps;
import com.unlikepaladin.pfm.recipes.FurnitureRecipe;
import com.unlikepaladin.pfm.recipes.SimpleFurnitureRecipe;
import com.unlikepaladin.pfm.registry.RecipeTypes;
import net.minecraft.advancement.*;
import net.minecraft.advancement.criterion.RecipeUnlockedCriterion;
Expand Down Expand Up @@ -123,77 +124,14 @@ public void offerTo(RecipeExporter exporter, Identifier recipeId) {
this.criteria.forEach(advancement$builder::criterion);
ItemStack stack = new ItemStack(this.output, this.outputCount);
stack.setNbt(nbtElement);
exporter.accept(new SimpleFurnitureRecipeJsonProvider(recipeId, this.output, this.nbtElement, this.outputCount, this.group == null ? "" : this.group, this.inputs, advancement$builder.build(recipeId.withPrefixedPath("recipes/furniture/")), this.showNotification));
exporter.accept(recipeId, new SimpleFurnitureRecipe(this.group == null || this.group.isBlank() ? " " : this.group, stack, this.inputs), advancement$builder.build(recipeId.withPrefixedPath("recipes/furniture/")));
}

private void validate(Identifier recipeId) {
if (this.criteria.isEmpty()) {
throw new IllegalStateException("No way of obtaining recipe " + recipeId);
}
}

public static class SimpleFurnitureRecipeJsonProvider
implements RecipeJsonProvider {
private final Identifier recipeId;
private final Item output;
private final int count;
private final String group;
private final List<Ingredient> inputs;
private final AdvancementEntry advancement;
private final boolean showNotification;
@Nullable
private final NbtElement nbtElement;

public SimpleFurnitureRecipeJsonProvider(Identifier recipeId, Item output, @Nullable NbtElement nbtElement, int outputCount, String group, List<Ingredient> inputs, AdvancementEntry entry, boolean showNotification) {
this.recipeId = recipeId;
this.output = output;
this.count = outputCount;
this.group = group;
this.inputs = inputs;
this.nbtElement = nbtElement;
this.advancement = entry;
this.showNotification = showNotification;
}

@Override
public void serialize(JsonObject json) {
if (!this.group.isEmpty()) {
json.addProperty("group", this.group);
}
JsonArray jsonArray = new JsonArray();
for (Ingredient ingredient : this.inputs) {
jsonArray.add(ingredient.toJson(true));
}
json.add("ingredients", jsonArray);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("item", Registries.ITEM.getId(this.output).toString());
if (this.count > 1) {
jsonObject.addProperty("count", this.count);
}
json.addProperty("show_notification", this.showNotification);
if (nbtElement != null) {
JsonElement object = NbtOps.INSTANCE.convertTo(JsonOps.INSTANCE, this.nbtElement);
jsonObject.add("tag", object);
}
json.add("result", jsonObject);
}

@Nullable
@Override
public AdvancementEntry advancement() {
return this.advancement;
}

@Override
public RecipeSerializer<?> serializer() {
return RecipeTypes.SIMPLE_FURNITURE_SERIALIZER;
}

@Override
public Identifier id() {
return this.recipeId;
}
}
}


This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.unlikepaladin.pfm.utilities.fabric;

import com.unlikepaladin.pfm.mixin.fabric.PFMGroupResourcePackAccessor;
import net.fabricmc.fabric.impl.resource.loader.GroupResourcePack;
import com.unlikepaladin.pfm.utilities.PFMFileUtil;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.resource.ResourcePack;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class PFMFileUtilImpl {
Expand All @@ -16,12 +14,7 @@ public static Path getGamePath() {
}

public static List<ResourcePack> getSubPacks(ResourcePack pack) {
List<ResourcePack> list = new ArrayList<>();
if (pack instanceof GroupResourcePack groupResourcePack) {
list.addAll(((PFMGroupResourcePackAccessor)groupResourcePack).getPacks());
}
list.add(pack);
return list;
return Collections.singletonList(pack);
}

public static PFMFileUtil.ModLoader getModLoader() {
Expand Down
3 changes: 1 addition & 2 deletions fabric/src/main/resources/pfm.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
"PFMCookingPotBlockEntityMixin",
"PFMModResourcePackCreatorMixin",
"PFMReloadableResourceManagerImplMixin",
"PFMGroupResourcePackAccessor",
"PFMMinecraftServerMixin",
"PFMSaveLoaderMixin",
"PFMKitchenImplMixin",
"PFMMinecraftServerMixin",
"PFMMinecraftServerMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 4b8a78f

Please sign in to comment.