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;
|
||||
|
||||
|
||||
public AlloyingRecipe(Identifier id, String group, Ingredient primaryInput, Ingredient secondaryInput,
|
||||
ItemStack output, float experience, int smeltTime) {
|
||||
|
||||
public AlloyingRecipe(Identifier id, String group, Ingredient primaryInput, Ingredient secondaryInput, ItemStack output, float experience, int smeltTime) {
|
||||
this.group = group;
|
||||
this.id = id;
|
||||
this.primaryInput = primaryInput;
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
package ru.betterend.recipe;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemConvertible;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import ru.betterend.registry.BlockRegistry;
|
||||
import ru.betterend.registry.ItemRegistry;
|
||||
|
||||
public class CraftingRecipes {
|
||||
|
||||
public static void register() {
|
||||
if (exists(BlockRegistry.ENDER_BLOCK)) {
|
||||
RecipeBuilder.make("ender_pearl_to_block", BlockRegistry.ENDER_BLOCK)
|
||||
.setShape(new String[] { "OO", "OO" })
|
||||
.addMaterial('O', Items.ENDER_PEARL)
|
||||
|
@ -22,16 +18,13 @@ public class CraftingRecipes {
|
|||
.setOutputCount(4)
|
||||
.setList("#")
|
||||
.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();
|
||||
|
||||
}
|
||||
if (exists(ItemRegistry.TERMINITE_INGOT)) {
|
||||
String material = "terminite";
|
||||
RecipeBuilder.make(material + "_block", BlockRegistry.TERMINITE_BLOCK)
|
||||
.setShape(new String[] { "III", "III", "III" })
|
||||
|
@ -48,9 +41,8 @@ public class CraftingRecipes {
|
|||
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";
|
||||
|
||||
material = "aeternium";
|
||||
RecipeBuilder.make(material + "_block", BlockRegistry.AETERNIUM_BLOCK)
|
||||
.setShape(new String[] { "III", "III", "III" })
|
||||
.addMaterial('I', ItemRegistry.AETERNIUM_INGOT)
|
||||
|
@ -66,16 +58,16 @@ public class CraftingRecipes {
|
|||
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("golden", Items.GOLD_INGOT, ItemRegistry.GOLDEN_HAMMER);
|
||||
registerHammer("diamond", Items.DIAMOND, ItemRegistry.DIAMOND_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("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) {
|
||||
|
@ -153,13 +145,4 @@ public class CraftingRecipes {
|
|||
.addMaterial('#', Items.STICK)
|
||||
.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.collection.DefaultedList;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.util.RecipeHelper;
|
||||
|
||||
public class RecipeBuilder {
|
||||
private static final RecipeBuilder INSTANCE = new RecipeBuilder();
|
||||
|
@ -29,6 +30,7 @@ public class RecipeBuilder {
|
|||
private String[] shape;
|
||||
private Map<Character, Ingredient> materialKeys = Maps.newHashMap();
|
||||
private int count;
|
||||
private boolean exist = true;
|
||||
|
||||
private RecipeBuilder() {}
|
||||
|
||||
|
@ -43,6 +45,8 @@ public class RecipeBuilder {
|
|||
INSTANCE.materialKeys.clear();
|
||||
INSTANCE.count = 1;
|
||||
|
||||
INSTANCE.exist = RecipeHelper.exists(output);
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
@ -67,10 +71,13 @@ public class RecipeBuilder {
|
|||
}
|
||||
|
||||
public RecipeBuilder addMaterial(char key, ItemConvertible... values) {
|
||||
for (ItemConvertible item: values) {
|
||||
exist &= RecipeHelper.exists(item);
|
||||
}
|
||||
return addMaterial(key, Ingredient.ofItems(values));
|
||||
}
|
||||
|
||||
public RecipeBuilder addMaterial(char key, Ingredient value) {
|
||||
private RecipeBuilder addMaterial(char key, Ingredient value) {
|
||||
materialKeys.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
@ -94,6 +101,7 @@ public class RecipeBuilder {
|
|||
}
|
||||
|
||||
public void build() {
|
||||
if (exist) {
|
||||
int height = shape.length;
|
||||
int width = shape[0].length();
|
||||
ItemStack result = new ItemStack(output, count);
|
||||
|
@ -103,4 +111,8 @@ public class RecipeBuilder {
|
|||
CraftingRecipe recipe = shaped ? new ShapedRecipe(id, group, width, height, materials, result) : new ShapelessRecipe(id, group, result, materials);
|
||||
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