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