Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/12.x-1.20' into feature/13.1
Browse files Browse the repository at this point in the history
# Conflicts:
#	default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java
#	default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultSmithingDisplay.java
  • Loading branch information
shedaniel committed Apr 15, 2024
2 parents 5f61d89 + d96699c commit 9fcf1fa
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
import dev.architectury.event.EventResult;
import dev.architectury.networking.NetworkManager;
import dev.architectury.platform.Platform;
import it.unimi.dsi.fastutil.objects.Object2FloatMap;
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
import it.unimi.dsi.fastutil.objects.ReferenceSet;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.favorites.FavoriteEntry;
import me.shedaniel.rei.api.client.favorites.FavoriteEntryType;
Expand Down Expand Up @@ -310,7 +307,7 @@ public void registerDisplays(DisplayRegistry registry) {
registry.registerRecipeFiller(CampfireCookingRecipe.class, RecipeType.CAMPFIRE_COOKING, DefaultCampfireDisplay::new);
registry.registerRecipeFiller(StonecutterRecipe.class, RecipeType.STONECUTTING, DefaultStoneCuttingDisplay::new);
registry.registerRecipeFiller(SmithingTransformRecipe.class, RecipeType.SMITHING, DefaultSmithingDisplay::ofTransforming);
registry.registerRecipeFiller(SmithingTrimRecipe.class, RecipeType.SMITHING, DefaultSmithingDisplay::ofTrimming);
registry.registerRecipesFiller(SmithingTrimRecipe.class, RecipeType.SMITHING, DefaultSmithingDisplay::fromTrimming);
registry.registerFiller(AnvilRecipe.class, DefaultAnvilDisplay::new);
registry.registerFiller(BrewingRecipe.class, DefaultBrewingDisplay::new);
registry.registerFiller(TagKey.class, tagKey -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@
import me.shedaniel.rei.api.common.display.basic.BasicDisplay;
import me.shedaniel.rei.api.common.entry.EntryIngredient;
import me.shedaniel.rei.api.common.util.EntryIngredients;
import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.plugin.common.BuiltinPlugin;
import net.minecraft.core.Holder;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.armortrim.*;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.SmithingRecipe;
import net.minecraft.world.item.crafting.SmithingTransformRecipe;
import net.minecraft.world.item.crafting.SmithingTrimRecipe;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

Expand All @@ -53,7 +59,7 @@ public static DefaultSmithingDisplay ofTransforming(RecipeHolder<SmithingTransfo
);
}

@ApiStatus.Experimental
@Deprecated(forRemoval = true)
public static DefaultSmithingDisplay ofTrimming(RecipeHolder<SmithingTrimRecipe> recipe) {
return new DefaultSmithingDisplay(
recipe.value(),
Expand All @@ -66,44 +72,43 @@ public static DefaultSmithingDisplay ofTrimming(RecipeHolder<SmithingTrimRecipe>
);
}

// @ApiStatus.Experimental
// public DefaultSmithingDisplay(SmithingTrimRecipe recipe) {
// this(
// List.of(
// EntryIngredients.ofIngredient(recipe.template),
// EntryIngredients.ofIngredient(recipe.base),
// EntryIngredients.ofIngredient(recipe.addition)
// ),
// List.of(EntryIngredients.ofItemStacks(((Supplier<List<ItemStack>>) () -> {
// RegistryAccess registryAccess = BasicDisplay.registryAccess();
// ItemStack[] templateItems = recipe.template.getItems();
// ItemStack[] baseItems = recipe.base.getItems();
// if (templateItems.length != 0) {
// Holder.Reference<TrimPattern> trimPattern = TrimPatterns.getFromTemplate(registryAccess, templateItems[0])
// .orElse(null);
// if (trimPattern != null) {
// for (ItemStack additionItem : recipe.addition.getItems()) {
// Holder.Reference<TrimMaterial> trimMaterial = TrimMaterials.getFromIngredient(registryAccess, additionItem)
// .orElse(null);
// if (trimMaterial != null) {
// Optional<ArmorTrim> trim = ArmorTrim.getTrim(registryAccess, itemStack);
// if (trim.isEmpty() || !trim.get().hasPatternAndMaterial(trimPattern, trimMaterial)) {
// ItemStack itemStack2 = itemStack.copy();
// itemStack2.setCount(1);
// ArmorTrim armorTrim = new ArmorTrim((Holder) optional.get(), (Holder) optional2.get());
// if (ArmorTrim.setTrim(registryAccess, itemStack2, armorTrim)) {
// return itemStack2;
// }
// }
// }
// }
// }
// }
// return List.of(recipe.getResultItem(registryAccess));
// }).get())),
// Optional.ofNullable(recipe.getId())
// );
// }
@ApiStatus.Experimental
public static List<DefaultSmithingDisplay> fromTrimming(RecipeHolder<SmithingTrimRecipe> recipe) {
RegistryAccess registryAccess = BasicDisplay.registryAccess();
List<DefaultSmithingDisplay> displays = new ArrayList<>();
for (ItemStack templateItem : recipe.value().template.getItems()) {
Holder.Reference<TrimPattern> trimPattern = TrimPatterns.getFromTemplate(registryAccess, templateItem)
.orElse(null);
if (trimPattern == null) continue;

for (ItemStack additionStack : recipe.value().addition.getItems()) {
Holder.Reference<TrimMaterial> trimMaterial = TrimMaterials.getFromIngredient(registryAccess, additionStack)
.orElse(null);
if (trimMaterial == null) continue;

ArmorTrim armorTrim = new ArmorTrim(trimMaterial, trimPattern);
EntryIngredient.Builder baseItems = EntryIngredient.builder(), outputItems = EntryIngredient.builder();
for (ItemStack item : recipe.value().base.getItems()) {
Optional<ArmorTrim> trim = ArmorTrim.getTrim(registryAccess, item, true);
if (trim.isEmpty() || !trim.get().hasPatternAndMaterial(trimPattern, trimMaterial)) {
ItemStack newItem = item.copy();
newItem.setCount(1);
if (ArmorTrim.setTrim(registryAccess, newItem, armorTrim)) {
baseItems.add(EntryStacks.of(item.copy()));
outputItems.add(EntryStacks.of(newItem));
}
}
}
displays.add(new DefaultSmithingDisplay(List.of(
EntryIngredients.of(templateItem),
baseItems.build(),
EntryIngredients.of(additionStack)
), List.of(outputItems.build()),
Optional.ofNullable(recipe.id())));
}
}
return displays;
}

public DefaultSmithingDisplay(SmithingRecipe recipe, @Nullable ResourceLocation id, List<EntryIngredient> inputs) {
this(
Expand Down

0 comments on commit 9fcf1fa

Please sign in to comment.