Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.
at master 115 lines 3.9 kB view raw
1package net.lerariemann.infinity.item.function; 2 3import net.lerariemann.infinity.registry.core.ModComponentTypes; 4import net.lerariemann.infinity.registry.core.ModItemFunctions; 5import net.lerariemann.infinity.registry.core.ModItems; 6import net.lerariemann.infinity.util.VersionMethods; 7import net.minecraft.core.RegistryAccess; 8//? if >1.21 { 9import net.minecraft.world.item.crafting.CraftingInput; 10import net.minecraft.core.HolderLookup; 11//?} 12import net.minecraft.resources.ResourceLocation; 13import net.minecraft.world.inventory.CraftingContainer; 14import net.minecraft.world.item.ItemStack; 15import net.minecraft.world.item.crafting.CraftingBookCategory; 16 17import net.minecraft.world.item.crafting.CustomRecipe; 18import net.minecraft.world.item.crafting.RecipeSerializer; 19import net.minecraft.world.level.Level; 20import org.jetbrains.annotations.NotNull; 21 22public class ChromaCarpetRecipe extends CustomRecipe { 23 public ChromaCarpetRecipe( 24 //? if <1.21 25 /*ResourceLocation id,*/ 26 CraftingBookCategory craftingRecipeCategory) { 27 super( 28 //? if <1.21 29 /*id,*/ 30 craftingRecipeCategory); 31 } 32 33 public boolean matches( 34 //? if >1.21 { 35 CraftingInput 36 //?} else { 37 /*CraftingContainer 38 *///?} 39 craftingRecipeInput, Level world) { 40 Integer color = null; 41 int k_first = 0; 42 boolean carpetDone = false; 43 //? if >1.21 { 44 int w = craftingRecipeInput.width(); 45 int size = craftingRecipeInput.size(); 46 //?} else { 47 /*int w = craftingRecipeInput.getWidth(); 48 int size = craftingRecipeInput.getContainerSize(); 49 *///?} 50 for (int k = 0; k < size; k++) { 51 ItemStack itemStack = craftingRecipeInput.getItem(k); 52 if (itemStack.is(ModItems.CHROMATIC_WOOL.get())) { 53 if (carpetDone) return false; 54 int newColor = VersionMethods.getOrDefaultInt(itemStack, ModComponentTypes.COLOR, 0); 55 if (color == null) { 56 color = newColor; 57 if (k % w == w - 1) return false; 58 k_first = k; 59 } 60 else { 61 if (k - k_first != 1 || color != newColor) return false; 62 carpetDone = true; 63 } 64 } 65 else if (!itemStack.isEmpty()) return false; 66 } 67 return carpetDone; 68 } 69 70 public @NotNull ItemStack assemble( 71 //? if >1.21 { 72 CraftingInput 73 //?} else { 74 /*CraftingContainer 75 *///?} 76 craftingRecipeInput, 77 //? if >1.21 { 78 HolderLookup.Provider 79 //?} else { 80 /*RegistryAccess 81 *///?} 82 registryAccess 83 ) { 84 int color = 0; 85 //? if >1.21 { 86 87 int size = craftingRecipeInput.size(); 88 //?} else { 89 /*int size = craftingRecipeInput.getContainerSize(); 90 *///?} 91 for (int k = 0; k < size; k++) { 92 ItemStack itemStack = craftingRecipeInput.getItem(k); 93 if (itemStack.is(ModItems.CHROMATIC_WOOL.get())) { 94 color = VersionMethods.getOrDefaultInt(itemStack, ModComponentTypes.COLOR, 0); 95 break; 96 } 97 } 98 ItemStack result = ModItems.CHROMATIC_CARPET.get().getDefaultInstance(); 99 VersionMethods.apply(result, ModComponentTypes.COLOR, color); 100 return result.copyWithCount(3); 101 } 102 103 //? if <1.21.2 { 104 /*@Override 105 public boolean canCraftInDimensions(int width, int height) { 106 return width >= 2 && height >= 1; 107 } 108 *///?} 109 110 @Override 111 public RecipeSerializer<ChromaCarpetRecipe> getSerializer() { 112 return ModItemFunctions.CARPET.get(); 113 } 114} 115