Merge branch 'clean/recipes'

This commit is contained in:
FlorianMichael 2024-01-02 16:09:36 +01:00
commit 3dddc5b75e
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
10 changed files with 217 additions and 111 deletions

View File

@ -36,4 +36,5 @@ public interface ChangeProtocolVersionCallback {
});
void onChangeProtocolVersion(final VersionEnum oldVersion, final VersionEnum newVersion);
}

View File

@ -35,4 +35,5 @@ public interface LoadClassicProtocolExtensionCallback {
});
void onLoadClassicProtocolExtension(final ClassicProtocolExtension classicProtocolExtension);
}

View File

@ -34,4 +34,5 @@ public interface PostGameLoadCallback {
});
void postGameLoad();
}

View File

@ -34,4 +34,5 @@ public interface PostViaVersionLoadCallback {
});
void onPostViaVersionLoad();
}

View File

@ -82,7 +82,6 @@ public class GridItemSelectionScreen extends VFPScreen {
this.client.player.playerScreenHandler.sendContentUpdates();
playClickSound();
this.close();
}
return super.mouseClicked(mouseX, mouseY, button);

View File

@ -130,7 +130,7 @@ public class AddBannerPatternRecipe extends SpecialCraftingRecipe {
}
foundDye = true;
} else {
if (foundBaseItem || !(!stack.isEmpty() && ItemStack.areItemsEqual(stack, pattern.getBaseStack()))) {
if (foundBaseItem || !ItemStack.areItemsEqual(stack, pattern.getBaseStack())) {
matches = false;
break;
}

View File

@ -23,7 +23,6 @@ import net.minecraft.block.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
// safe from vanilla modification + removal of recipes
public enum BannerPattern_1_13_2 {
BASE("b"),

View File

@ -27,61 +27,75 @@ import net.minecraft.recipe.book.CraftingRecipeCategory;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.function.Supplier;
public final class RecipeInfo<T extends Recipe<?>> {
/**
* A helper class for creating recipes.
*/
public final class RecipeInfo {
private final Supplier<Recipe<?>> creator;
private final RecipeSerializer<T> recipeType;
private final ItemStack output;
private String distinguisher = "";
private RecipeInfo(Supplier<Recipe<?>> creator, RecipeSerializer<T> recipeType, ItemStack output) {
private RecipeInfo(Supplier<Recipe<?>> creator) {
this.creator = creator;
this.recipeType = recipeType;
this.output = output;
}
public static <T extends Recipe<?>> RecipeInfo<T> of(Supplier<Recipe<?>> creator, RecipeSerializer<T> recipeType, ItemStack output) {
return new RecipeInfo<>(creator, recipeType, output);
/**
* Creates a new recipe info with the given creator.
*
* @param creator The creator
* @return The recipe info
*/
public static RecipeInfo of(Supplier<Recipe<?>> creator) {
return new RecipeInfo(creator);
}
public static <T extends Recipe<?>> RecipeInfo<T> of(Supplier<Recipe<?>> creator, RecipeSerializer<T> recipeType, ItemConvertible output) {
return of(creator, recipeType, new ItemStack(output));
}
public static <T extends Recipe<?>> RecipeInfo<T> of(Supplier<Recipe<?>> creator, RecipeSerializer<T> recipeType, ItemConvertible output, int count) {
return of(creator, recipeType, new ItemStack(output, count));
}
public static RecipeInfo<ShapedRecipe> shaped(ItemStack output, Object... args) {
/**
* Creates a new shaped recipe info with the given creator.
*
* @param output The output
* @param args The arguments
* @return The recipe info containing a shaped recipe
*/
public static RecipeInfo shaped(ItemConvertible output, Object... args) {
return shaped("", output, args);
}
public static RecipeInfo<ShapedRecipe> shaped(ItemConvertible output, Object... args) {
return shaped("", output, args);
}
public static RecipeInfo<ShapedRecipe> shaped(int count, ItemConvertible output, Object... args) {
/**
* Creates a new shaped recipe info with the given creator.
*
* @param count The count
* @param output The output
* @param args The arguments
* @return The recipe info containing a shaped recipe
*/
public static RecipeInfo shaped(int count, ItemConvertible output, Object... args) {
return shaped("", count, output, args);
}
public static RecipeInfo<ShapedRecipe> shaped(String group, ItemStack output, Object... args) {
/**
* Creates a new shaped recipe info with the given creator.
*
* @param group The group
* @param output The output
* @param args The arguments
* @return The recipe info containing a shaped recipe
*/
public static RecipeInfo shaped(String group, ItemStack output, Object... args) {
final List<String> shape = new ArrayList<>();
int i;
int width = 0;
List<String> shape = new ArrayList<>();
for (i = 0; i < args.length && args[i] instanceof String str; i++) {
if (i == 0)
if (i == 0) {
width = str.length();
else if (str.length() != width)
} else if (str.length() != width) {
throw new IllegalArgumentException("Rows do not have consistent width");
}
shape.add(str);
}
var legend = new HashMap<Character, Ingredient>();
Map<Character, Ingredient> legend = new HashMap<>();
while (i < args.length && args[i] instanceof Character key) {
i++;
List<ItemConvertible> items = new ArrayList<>();
@ -90,129 +104,219 @@ public final class RecipeInfo<T extends Recipe<?>> {
}
legend.put(key, Ingredient.ofItems(items.toArray(new ItemConvertible[0])));
}
if (i != args.length)
if (i != args.length) {
throw new IllegalArgumentException("Unexpected argument at index " + i + ": " + args[i]);
}
int height = shape.size();
DefaultedList<Ingredient> ingredients = DefaultedList.of();
final int height = shape.size();
final DefaultedList<Ingredient> ingredients = DefaultedList.of();
for (String row : shape) {
for (int x = 0; x < width; x++) {
char key = row.charAt(x);
final char key = row.charAt(x);
Ingredient ingredient = legend.get(key);
if (ingredient == null) {
if (key == ' ')
if (key == ' ') {
ingredient = Ingredient.EMPTY;
else
} else {
throw new IllegalArgumentException("Unknown character in shape: " + key);
}
}
ingredients.add(ingredient);
}
}
final int width_f = width;
return new RecipeInfo<>(() -> new ShapedRecipe(group, CraftingRecipeCategory.MISC, new RawShapedRecipe(width_f, height, ingredients, Optional.empty()), output, false), RecipeSerializer.SHAPED, output);
return new RecipeInfo(() -> new ShapedRecipe(group, CraftingRecipeCategory.MISC, new RawShapedRecipe(width_f, height, ingredients, Optional.empty()), output, false));
}
public static RecipeInfo<ShapedRecipe> shaped(String group, ItemConvertible output, Object... args) {
/**
* Creates a new shaped recipe info with the given creator.
*
* @param group The group
* @param output The output
* @param args The arguments
* @return The recipe info containing a shaped recipe
*/
public static RecipeInfo shaped(String group, ItemConvertible output, Object... args) {
return shaped(group, new ItemStack(output), args);
}
public static RecipeInfo<ShapedRecipe> shaped(String group, int count, ItemConvertible output, Object... args) {
/**
* Creates a new shaped recipe info with the given creator.
*
* @param group The group
* @param count The count
* @param output The output
* @param args The arguments
* @return The recipe info containing a shaped recipe
*/
public static RecipeInfo shaped(String group, int count, ItemConvertible output, Object... args) {
return shaped(group, new ItemStack(output, count), args);
}
public static RecipeInfo<ShapelessRecipe> shapeless(String group, ItemStack output, ItemConvertible... inputs) {
ItemConvertible[][] newInputs = new ItemConvertible[inputs.length][1];
for (int i = 0; i < inputs.length; i++)
/**
* Creates a new shapeless recipe info with the given creator.
*
* @param group The group
* @param output The output
* @param inputs The inputs
* @return The recipe info containing a shapeless recipe
*/
public static RecipeInfo shapeless(String group, ItemStack output, ItemConvertible... inputs) {
final ItemConvertible[][] newInputs = new ItemConvertible[inputs.length][1];
for (int i = 0; i < inputs.length; i++) {
newInputs[i] = new ItemConvertible[]{inputs[i]};
}
return shapeless(group, output, newInputs);
}
public static RecipeInfo<ShapelessRecipe> shapeless(String group, ItemConvertible output, ItemConvertible... inputs) {
/**
* Creates a new shapeless recipe info with the given creator.
*
* @param group The group
* @param output The output
* @param inputs The inputs
* @return The recipe info containing a shapeless recipe
*/
public static RecipeInfo shapeless(String group, ItemConvertible output, ItemConvertible... inputs) {
return shapeless(group, new ItemStack(output), inputs);
}
public static RecipeInfo<ShapelessRecipe> shapeless(String group, int count, ItemConvertible output, ItemConvertible... inputs) {
/**
* Creates a new shapeless recipe info with the given creator.
*
* @param group The group
* @param count The count
* @param output The output
* @param inputs The inputs
* @return The recipe info containing a shapeless recipe
*/
public static RecipeInfo shapeless(String group, int count, ItemConvertible output, ItemConvertible... inputs) {
return shapeless(group, new ItemStack(output, count), inputs);
}
public static RecipeInfo<ShapelessRecipe> shapeless(String group, ItemStack output, ItemConvertible[]... inputs) {
DefaultedList<Ingredient> ingredients = DefaultedList.of();
/**
* Creates a new shapeless recipe info with the given creator.
*
* @param group The group
* @param output The output
* @param inputs The inputs
* @return The recipe info containing a shapeless recipe
*/
public static RecipeInfo shapeless(String group, ItemStack output, ItemConvertible[]... inputs) {
final DefaultedList<Ingredient> ingredients = DefaultedList.of();
for (ItemConvertible[] input : inputs) {
ingredients.add(Ingredient.ofItems(input));
}
return new RecipeInfo<>(() -> new ShapelessRecipe(group, CraftingRecipeCategory.MISC, output, ingredients), RecipeSerializer.SHAPELESS, output);
return new RecipeInfo(() -> new ShapelessRecipe(group, CraftingRecipeCategory.MISC, output, ingredients));
}
public static RecipeInfo<ShapelessRecipe> shapeless(String group, ItemConvertible output, ItemConvertible[]... inputs) {
return shapeless(group, new ItemStack(output), inputs);
}
public static RecipeInfo<ShapelessRecipe> shapeless(String group, int count, ItemConvertible output, ItemConvertible[]... inputs) {
/**
* Creates a new shapeless recipe info with the given creator.
*
* @param group The group
* @param count The count
* @param output The output
* @param inputs The inputs
* @return The recipe info containing a shapeless recipe
*/
public static RecipeInfo shapeless(String group, int count, ItemConvertible output, ItemConvertible[]... inputs) {
return shapeless(group, new ItemStack(output, count), inputs);
}
public static RecipeInfo<ShapelessRecipe> shapeless(ItemStack output, ItemConvertible... inputs) {
/**
* Creates a new shapeless recipe info with the given creator.
*
* @param output The output
* @param inputs The inputs
* @return The recipe info containing a shapeless recipe
*/
public static RecipeInfo shapeless(ItemConvertible output, ItemConvertible... inputs) {
return shapeless("", output, inputs);
}
public static RecipeInfo<ShapelessRecipe> shapeless(ItemConvertible output, ItemConvertible... inputs) {
return shapeless("", output, inputs);
}
public static RecipeInfo<ShapelessRecipe> shapeless(int count, ItemConvertible output, ItemConvertible... inputs) {
/**
* Creates a new shapeless recipe info with the given creator.
*
* @param count The count
* @param output The output
* @param inputs The inputs
* @return The recipe info containing a shapeless recipe
*/
public static RecipeInfo shapeless(int count, ItemConvertible output, ItemConvertible... inputs) {
return shapeless("", count, output, inputs);
}
public static RecipeInfo<ShapelessRecipe> shapeless(ItemStack output, ItemConvertible[]... inputs) {
return shapeless("", output, inputs);
}
public static RecipeInfo<ShapelessRecipe> shapeless(ItemConvertible output, ItemConvertible[]... inputs) {
return shapeless("", output, inputs);
}
public static RecipeInfo<ShapelessRecipe> shapeless(int count, ItemConvertible output, ItemConvertible[]... inputs) {
/**
* Creates a new shapeless recipe info with the given creator.
*
* @param count The count
* @param output The output
* @param inputs The inputs
* @return The recipe info containing a shapeless recipe
*/
public static RecipeInfo shapeless(int count, ItemConvertible output, ItemConvertible[]... inputs) {
return shapeless("", count, output, inputs);
}
public static RecipeInfo<SmeltingRecipe> smelting(ItemConvertible output, ItemConvertible input, float experience) {
/**
* Creates a new smelting recipe info with the given creator.
*
* @param output The output
* @param input The input
* @param experience The experience
* @return The recipe info containing a shapeless recipe
*/
public static RecipeInfo smelting(ItemConvertible output, ItemConvertible input, float experience) {
return smelting(output, input, experience, 200);
}
public static RecipeInfo<SmeltingRecipe> smelting(ItemConvertible output, Ingredient input, float experience) {
/**
* Creates a new smelting recipe info with the given creator.
*
* @param output The output
* @param input The input
* @param experience The experience
* @return The recipe info containing a shapeless recipe
*/
public static RecipeInfo smelting(ItemConvertible output, Ingredient input, float experience) {
return smelting(output, input, experience, 200);
}
public static RecipeInfo<SmeltingRecipe> smelting(ItemConvertible output, ItemConvertible input, float experience, int cookTime) {
/**
* Creates a new smelting recipe info with the given creator.
*
* @param output The output
* @param input The input
* @param experience The experience
* @param cookTime The cook time
* @return The recipe info containing a shapeless recipe
*/
public static RecipeInfo smelting(ItemConvertible output, ItemConvertible input, float experience, int cookTime) {
return smelting(output, Ingredient.ofItems(input), experience, cookTime);
}
public static RecipeInfo<SmeltingRecipe> smelting(ItemConvertible output, Ingredient input, float experience, int cookTime) {
ItemStack outputStack = new ItemStack(output);
return new RecipeInfo<>(() -> new SmeltingRecipe("", CookingRecipeCategory.MISC, input, outputStack, experience, cookTime), RecipeSerializer.SMELTING, outputStack);
/**
* Creates a new smelting recipe info with the given creator.
*
* @param output The output
* @param input The input
* @param experience The experience
* @param cookTime The cook time
* @return The recipe info containing a shapeless recipe
*/
public static RecipeInfo smelting(ItemConvertible output, Ingredient input, float experience, int cookTime) {
return new RecipeInfo(() -> new SmeltingRecipe("", CookingRecipeCategory.MISC, input, new ItemStack(output), experience, cookTime));
}
public RecipeInfo<T> distinguisher(String distinguisher) {
this.distinguisher = distinguisher;
return this;
}
/**
* Creates a new recipe info with the given creator.
*
* @param id The id
* @return The recipe info
*/
public RecipeEntry<?> create(Identifier id) {
return new RecipeEntry<Recipe<?>>(id, this.creator.get());
}
public RecipeSerializer<T> getRecipeType() {
return this.recipeType;
}
public ItemStack getOutput() {
return this.output;
}
public String getDistinguisher() {
return this.distinguisher;
}
}

View File

@ -43,31 +43,31 @@ public class Recipes1_11_2 {
/**
* @return A list of all recipes for the given version.
*/
public static List<RecipeInfo<?>> getRecipes(final VersionEnum targetVersion) {
final List<RecipeInfo<?>> recipes = new ArrayList<>();
public static List<RecipeInfo> getRecipes(final VersionEnum targetVersion) {
final List<RecipeInfo> recipes = new ArrayList<>();
if (targetVersion.isNewerThanOrEqualTo(VersionEnum.r1_4_2)) {
recipes.add(RecipeInfo.of(() -> new ArmorDyeRecipe(CraftingRecipeCategory.MISC), RecipeSerializer.ARMOR_DYE, Items.LEATHER_HELMET));
recipes.add(RecipeInfo.of(() -> new MapCloningRecipe(CraftingRecipeCategory.MISC), RecipeSerializer.MAP_CLONING, Items.FILLED_MAP, 2));
recipes.add(RecipeInfo.of(() -> new MapExtendingRecipe(CraftingRecipeCategory.MISC), RecipeSerializer.MAP_EXTENDING, Items.FILLED_MAP));
recipes.add(RecipeInfo.of(() -> new ArmorDyeRecipe(CraftingRecipeCategory.MISC)));
recipes.add(RecipeInfo.of(() -> new MapCloningRecipe(CraftingRecipeCategory.MISC)));
recipes.add(RecipeInfo.of(() -> new MapExtendingRecipe(CraftingRecipeCategory.MISC)));
}
if (targetVersion.isNewerThanOrEqualTo(VersionEnum.r1_4_6tor1_4_7)) {
recipes.add(RecipeInfo.of(() -> new FireworkRocketRecipe(CraftingRecipeCategory.MISC), RecipeSerializer.FIREWORK_ROCKET, Items.FIREWORK_ROCKET));
recipes.add(RecipeInfo.of(() -> new FireworkRocketRecipe(CraftingRecipeCategory.MISC)));
}
if (targetVersion.isNewerThanOrEqualTo(VersionEnum.r1_11)) {
recipes.add(RecipeInfo.of(() -> new ShulkerBoxColoringRecipe(CraftingRecipeCategory.MISC), RecipeSerializer.SHULKER_BOX, Items.WHITE_SHULKER_BOX));
recipes.add(RecipeInfo.of(() -> new ShulkerBoxColoringRecipe(CraftingRecipeCategory.MISC)));
}
if (targetVersion.isNewerThanOrEqualTo(VersionEnum.r1_9)) {
recipes.add(RecipeInfo.of(() -> new TippedArrowRecipe(CraftingRecipeCategory.MISC), RecipeSerializer.TIPPED_ARROW, Items.TIPPED_ARROW));
recipes.add(RecipeInfo.of(() -> new ShieldDecorationRecipe(CraftingRecipeCategory.MISC), RecipeSerializer.SHIELD_DECORATION, Items.SHIELD));
recipes.add(RecipeInfo.of(() -> new TippedArrowRecipe(CraftingRecipeCategory.MISC)));
recipes.add(RecipeInfo.of(() -> new ShieldDecorationRecipe(CraftingRecipeCategory.MISC)));
}
if (targetVersion.isNewerThanOrEqualTo(VersionEnum.r1_8)) {
recipes.add(RecipeInfo.of(() -> new RepairItemRecipe(CraftingRecipeCategory.MISC), RecipeSerializer.REPAIR_ITEM, Items.WOODEN_SWORD));
recipes.add(RecipeInfo.of(() -> new BannerDuplicateRecipe(CraftingRecipeCategory.MISC), RecipeSerializer.BANNER_DUPLICATE, Items.WHITE_BANNER, 2));
recipes.add(RecipeInfo.of(() -> new AddBannerPatternRecipe(CraftingRecipeCategory.MISC), AddBannerPatternRecipe.SERIALIZER, Items.WHITE_BANNER));
recipes.add(RecipeInfo.of(() -> new RepairItemRecipe(CraftingRecipeCategory.MISC)));
recipes.add(RecipeInfo.of(() -> new BannerDuplicateRecipe(CraftingRecipeCategory.MISC)));
recipes.add(RecipeInfo.of(() -> new AddBannerPatternRecipe(CraftingRecipeCategory.MISC)));
}
if (targetVersion.isNewerThanOrEqualTo(VersionEnum.r1_7_2tor1_7_5)) {
recipes.add(RecipeInfo.of(() -> new BookCloningRecipe(CraftingRecipeCategory.MISC), RecipeSerializer.BOOK_CLONING, Items.WRITABLE_BOOK, 2));
recipes.add(RecipeInfo.of(() -> new BookCloningRecipe(CraftingRecipeCategory.MISC)));
}
recipes.add(RecipeInfo.shaped(Items.WOODEN_SWORD, "X", "X", "#", '#', Items.STICK, 'X', Blocks.OAK_PLANKS, Blocks.SPRUCE_PLANKS, Blocks.BIRCH_PLANKS, Blocks.JUNGLE_PLANKS, Blocks.ACACIA_PLANKS, Blocks.DARK_OAK_PLANKS));
@ -200,7 +200,7 @@ public class Recipes1_11_2 {
}
if (targetVersion.isNewerThanOrEqualTo(VersionEnum.r1_11_1to1_11_2)) {
recipes.add(RecipeInfo.shaped(9, Items.IRON_NUGGET, "#", '#', Items.IRON_INGOT));
recipes.add(RecipeInfo.shaped("iron_ingot", Items.IRON_INGOT, "###", "###", "###", '#', Items.IRON_NUGGET).distinguisher("iron_nugget_to_ingot"));
recipes.add(RecipeInfo.shaped("iron_ingot", Items.IRON_INGOT, "###", "###", "###", '#', Items.IRON_NUGGET));
}
if (targetVersion.isNewerThanOrEqualTo(VersionEnum.r1_11)) {
recipes.add(RecipeInfo.shaped(Blocks.OBSERVER, "###", "RRQ", "###", 'Q', Items.QUARTZ, 'R', Blocks.REDSTONE_WIRE, '#', Blocks.COBBLESTONE));

View File

@ -164,7 +164,7 @@ public abstract class MixinClientPlayNetworkHandler extends ClientCommonNetworkH
if (targetVersion.isOlderThanOrEqualTo(VersionEnum.r1_11_1to1_11_2)) {
final List<RecipeEntry<?>> recipes = new ArrayList<>();
final List<RecipeInfo<?>> recipeInfos = Recipes1_11_2.getRecipes(targetVersion);
final List<RecipeInfo> recipeInfos = Recipes1_11_2.getRecipes(targetVersion);
for (int i = 0; i < recipeInfos.size(); i++) {
recipes.add(recipeInfos.get(i).create(new Identifier("viafabricplus", "recipe/" + i)));
}