Recipe check
This commit is contained in:
parent
62698e8bf5
commit
26eb6165a7
4 changed files with 91 additions and 82 deletions
|
@ -40,9 +40,7 @@ public class AlloyingRecipe implements Recipe<Inventory> {
|
||||||
protected final int smeltTime;
|
protected final int smeltTime;
|
||||||
|
|
||||||
|
|
||||||
public AlloyingRecipe(Identifier id, String group, Ingredient primaryInput, Ingredient secondaryInput,
|
public AlloyingRecipe(Identifier id, String group, Ingredient primaryInput, Ingredient secondaryInput, ItemStack output, float experience, int smeltTime) {
|
||||||
ItemStack output, float experience, int smeltTime) {
|
|
||||||
|
|
||||||
this.group = group;
|
this.group = group;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.primaryInput = primaryInput;
|
this.primaryInput = primaryInput;
|
||||||
|
|
|
@ -1,81 +1,73 @@
|
||||||
package ru.betterend.recipe;
|
package ru.betterend.recipe;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemConvertible;
|
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.util.registry.Registry;
|
|
||||||
import ru.betterend.registry.BlockRegistry;
|
import ru.betterend.registry.BlockRegistry;
|
||||||
import ru.betterend.registry.ItemRegistry;
|
import ru.betterend.registry.ItemRegistry;
|
||||||
|
|
||||||
public class CraftingRecipes {
|
public class CraftingRecipes {
|
||||||
|
|
||||||
public static void register() {
|
public static void register() {
|
||||||
if (exists(BlockRegistry.ENDER_BLOCK)) {
|
RecipeBuilder.make("ender_pearl_to_block", BlockRegistry.ENDER_BLOCK)
|
||||||
RecipeBuilder.make("ender_pearl_to_block", BlockRegistry.ENDER_BLOCK)
|
.setShape(new String[] { "OO", "OO" })
|
||||||
.setShape(new String[] { "OO", "OO" })
|
.addMaterial('O', Items.ENDER_PEARL)
|
||||||
.addMaterial('O', Items.ENDER_PEARL)
|
.build();
|
||||||
.build();
|
RecipeBuilder.make("ender_block_to_pearl", Items.ENDER_PEARL)
|
||||||
RecipeBuilder.make("ender_block_to_pearl", Items.ENDER_PEARL)
|
.addMaterial('#', BlockRegistry.ENDER_BLOCK)
|
||||||
.addMaterial('#', BlockRegistry.ENDER_BLOCK)
|
.setOutputCount(4)
|
||||||
.setOutputCount(4)
|
.setList("#")
|
||||||
.setList("#")
|
.build();
|
||||||
.build();
|
|
||||||
}
|
|
||||||
if (exists(BlockRegistry.END_STONE_SMELTER)) {
|
|
||||||
RecipeBuilder.make("end_stone_smelter", BlockRegistry.END_STONE_SMELTER)
|
|
||||||
.setShape(new String[] { "###", "V V", "###" })
|
|
||||||
.addMaterial('#', Blocks.END_STONE_BRICKS)
|
|
||||||
.addMaterial('V', Items.BUCKET)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
}
|
RecipeBuilder.make("end_stone_smelter", BlockRegistry.END_STONE_SMELTER)
|
||||||
if (exists(ItemRegistry.TERMINITE_INGOT)) {
|
.setShape(new String[] { "###", "V V", "###" })
|
||||||
String material = "terminite";
|
.addMaterial('#', Blocks.END_STONE_BRICKS)
|
||||||
RecipeBuilder.make(material + "_block", BlockRegistry.TERMINITE_BLOCK)
|
.addMaterial('V', Items.BUCKET)
|
||||||
.setShape(new String[] { "III", "III", "III" })
|
.build();
|
||||||
.addMaterial('I', ItemRegistry.TERMINITE_INGOT)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
registerHelmet(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_HELMET);
|
String material = "terminite";
|
||||||
registerChestplate(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_CHESTPLATE);
|
RecipeBuilder.make(material + "_block", BlockRegistry.TERMINITE_BLOCK)
|
||||||
registerLeggings(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_LEGGINGS);
|
.setShape(new String[] { "III", "III", "III" })
|
||||||
registerBoots(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_BOOTS);
|
.addMaterial('I', ItemRegistry.TERMINITE_INGOT)
|
||||||
registerShovel(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_SHOVEL);
|
.build();
|
||||||
registerSword(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_SWORD);
|
|
||||||
registerPickaxe(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_PICKAXE);
|
|
||||||
registerAxe(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_AXE);
|
|
||||||
registerHoe(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_HOE);
|
|
||||||
registerHammer(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_HAMMER);
|
|
||||||
}
|
|
||||||
if (exists(ItemRegistry.AETERNIUM_INGOT)) {
|
|
||||||
String material = "aeternium";
|
|
||||||
RecipeBuilder.make(material + "_block", BlockRegistry.AETERNIUM_BLOCK)
|
|
||||||
.setShape(new String[] { "III", "III", "III" })
|
|
||||||
.addMaterial('I', ItemRegistry.AETERNIUM_INGOT)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
registerHelmet(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_HELMET);
|
registerHelmet(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_HELMET);
|
||||||
registerChestplate(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_CHESTPLATE);
|
registerChestplate(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_CHESTPLATE);
|
||||||
registerLeggings(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_LEGGINGS);
|
registerLeggings(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_LEGGINGS);
|
||||||
registerBoots(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_BOOTS);
|
registerBoots(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_BOOTS);
|
||||||
registerShovel(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_SHOVEL);
|
registerShovel(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_SHOVEL);
|
||||||
registerSword(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_SWORD);
|
registerSword(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_SWORD);
|
||||||
registerPickaxe(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_PICKAXE);
|
registerPickaxe(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_PICKAXE);
|
||||||
registerAxe(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_AXE);
|
registerAxe(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_AXE);
|
||||||
registerHoe(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_HOE);
|
registerHoe(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_HOE);
|
||||||
registerHammer(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_HAMMER);
|
registerHammer(material, ItemRegistry.TERMINITE_INGOT, ItemRegistry.TERMINITE_HAMMER);
|
||||||
}
|
|
||||||
|
material = "aeternium";
|
||||||
|
RecipeBuilder.make(material + "_block", BlockRegistry.AETERNIUM_BLOCK)
|
||||||
|
.setShape(new String[] { "III", "III", "III" })
|
||||||
|
.addMaterial('I', ItemRegistry.AETERNIUM_INGOT)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
registerHelmet(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_HELMET);
|
||||||
|
registerChestplate(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_CHESTPLATE);
|
||||||
|
registerLeggings(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_LEGGINGS);
|
||||||
|
registerBoots(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_BOOTS);
|
||||||
|
registerShovel(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_SHOVEL);
|
||||||
|
registerSword(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_SWORD);
|
||||||
|
registerPickaxe(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_PICKAXE);
|
||||||
|
registerAxe(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_AXE);
|
||||||
|
registerHoe(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_HOE);
|
||||||
|
registerHammer(material, ItemRegistry.AETERNIUM_INGOT, ItemRegistry.AETERNIUM_HAMMER);
|
||||||
|
|
||||||
registerHammer("iron", Items.IRON_INGOT, ItemRegistry.IRON_HAMMER);
|
registerHammer("iron", Items.IRON_INGOT, ItemRegistry.IRON_HAMMER);
|
||||||
registerHammer("golden", Items.GOLD_INGOT, ItemRegistry.GOLDEN_HAMMER);
|
registerHammer("golden", Items.GOLD_INGOT, ItemRegistry.GOLDEN_HAMMER);
|
||||||
registerHammer("diamond", Items.DIAMOND, ItemRegistry.DIAMOND_HAMMER);
|
registerHammer("diamond", Items.DIAMOND, ItemRegistry.DIAMOND_HAMMER);
|
||||||
registerHammer("netherite", Items.NETHERITE_INGOT, ItemRegistry.NETHERITE_HAMMER);
|
registerHammer("netherite", Items.NETHERITE_INGOT, ItemRegistry.NETHERITE_HAMMER);
|
||||||
|
|
||||||
if (exists(BlockRegistry.BLUE_VINE_SEED)) {
|
RecipeBuilder.make("blue_vine_seed_dye", Items.BLUE_DYE).setList("#").addMaterial('#', BlockRegistry.BLUE_VINE_SEED).build();
|
||||||
RecipeBuilder.make("blue_vine_seed_dye", Items.BLUE_DYE).setList("#").addMaterial('#', BlockRegistry.BLUE_VINE_SEED).build();
|
RecipeBuilder.make("creeping_moss_dye", Items.CYAN_DYE).setList("#").addMaterial('#', BlockRegistry.CREEPING_MOSS).build();
|
||||||
}
|
RecipeBuilder.make("umbrella_moss_dye", Items.YELLOW_DYE).setList("#").addMaterial('#', BlockRegistry.UMBRELLA_MOSS).build();
|
||||||
|
RecipeBuilder.make("umbrella_moss_tall_dye", Items.YELLOW_DYE).setList("#").addMaterial('#', BlockRegistry.UMBRELLA_MOSS_TALL).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerHelmet(String name, Item material, Item result) {
|
private static void registerHelmet(String name, Item material, Item result) {
|
||||||
|
@ -153,13 +145,4 @@ public class CraftingRecipes {
|
||||||
.addMaterial('#', Items.STICK)
|
.addMaterial('#', Items.STICK)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean exists(ItemConvertible item) {
|
|
||||||
if (item instanceof Block) {
|
|
||||||
return Registry.BLOCK.getId((Block) item) != Registry.BLOCK.getDefaultId();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return Registry.ITEM.getId(item.asItem()) != Registry.ITEM.getDefaultId();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import net.minecraft.tag.Tag;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.collection.DefaultedList;
|
import net.minecraft.util.collection.DefaultedList;
|
||||||
import ru.betterend.BetterEnd;
|
import ru.betterend.BetterEnd;
|
||||||
|
import ru.betterend.util.RecipeHelper;
|
||||||
|
|
||||||
public class RecipeBuilder {
|
public class RecipeBuilder {
|
||||||
private static final RecipeBuilder INSTANCE = new RecipeBuilder();
|
private static final RecipeBuilder INSTANCE = new RecipeBuilder();
|
||||||
|
@ -29,6 +30,7 @@ public class RecipeBuilder {
|
||||||
private String[] shape;
|
private String[] shape;
|
||||||
private Map<Character, Ingredient> materialKeys = Maps.newHashMap();
|
private Map<Character, Ingredient> materialKeys = Maps.newHashMap();
|
||||||
private int count;
|
private int count;
|
||||||
|
private boolean exist = true;
|
||||||
|
|
||||||
private RecipeBuilder() {}
|
private RecipeBuilder() {}
|
||||||
|
|
||||||
|
@ -43,6 +45,8 @@ public class RecipeBuilder {
|
||||||
INSTANCE.materialKeys.clear();
|
INSTANCE.materialKeys.clear();
|
||||||
INSTANCE.count = 1;
|
INSTANCE.count = 1;
|
||||||
|
|
||||||
|
INSTANCE.exist = RecipeHelper.exists(output);
|
||||||
|
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,10 +71,13 @@ public class RecipeBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public RecipeBuilder addMaterial(char key, ItemConvertible... values) {
|
public RecipeBuilder addMaterial(char key, ItemConvertible... values) {
|
||||||
|
for (ItemConvertible item: values) {
|
||||||
|
exist &= RecipeHelper.exists(item);
|
||||||
|
}
|
||||||
return addMaterial(key, Ingredient.ofItems(values));
|
return addMaterial(key, Ingredient.ofItems(values));
|
||||||
}
|
}
|
||||||
|
|
||||||
public RecipeBuilder addMaterial(char key, Ingredient value) {
|
private RecipeBuilder addMaterial(char key, Ingredient value) {
|
||||||
materialKeys.put(key, value);
|
materialKeys.put(key, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -94,13 +101,18 @@ public class RecipeBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void build() {
|
public void build() {
|
||||||
int height = shape.length;
|
if (exist) {
|
||||||
int width = shape[0].length();
|
int height = shape.length;
|
||||||
ItemStack result = new ItemStack(output, count);
|
int width = shape[0].length();
|
||||||
Identifier id = BetterEnd.makeID(name);
|
ItemStack result = new ItemStack(output, count);
|
||||||
DefaultedList<Ingredient> materials = this.getMaterials(width, height);
|
Identifier id = BetterEnd.makeID(name);
|
||||||
|
DefaultedList<Ingredient> materials = this.getMaterials(width, height);
|
||||||
|
|
||||||
CraftingRecipe recipe = shaped ? new ShapedRecipe(id, group, width, height, materials, result) : new ShapelessRecipe(id, group, result, materials);
|
CraftingRecipe recipe = shaped ? new ShapedRecipe(id, group, width, height, materials, result) : new ShapelessRecipe(id, group, result, materials);
|
||||||
EndRecipeManager.addRecipe(type, recipe);
|
EndRecipeManager.addRecipe(type, recipe);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
BetterEnd.LOGGER.debug("recipe {} couldn't be added", name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
src/main/java/ru/betterend/util/RecipeHelper.java
Normal file
16
src/main/java/ru/betterend/util/RecipeHelper.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package ru.betterend.util;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.item.ItemConvertible;
|
||||||
|
import net.minecraft.util.registry.Registry;
|
||||||
|
|
||||||
|
public class RecipeHelper {
|
||||||
|
public static boolean exists(ItemConvertible item) {
|
||||||
|
if (item instanceof Block) {
|
||||||
|
return Registry.BLOCK.getId((Block) item) != Registry.BLOCK.getDefaultId();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return Registry.ITEM.getId(item.asItem()) != Registry.ITEM.getDefaultId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue