End Stone Smelter
This commit is contained in:
parent
257307d93d
commit
a542aac45b
18 changed files with 551 additions and 77 deletions
|
@ -3,14 +3,16 @@ package ru.betterend.recipe;
|
|||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemConvertible;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.recipe.Recipe;
|
||||
import net.minecraft.recipe.RecipeSerializer;
|
||||
import net.minecraft.recipe.RecipeType;
|
||||
import net.minecraft.tag.Tag;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.World;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.registry.BlockRegistry;
|
||||
|
@ -18,8 +20,8 @@ import ru.betterend.registry.BlockRegistry;
|
|||
public class AlloyingRecipe implements Recipe<Inventory> {
|
||||
|
||||
public final static String GROUP = "alloying";
|
||||
public final static RecipeType<AlloyingRecipe> TYPE = registerType(GROUP);
|
||||
public final static AlloyingRecipeSerializer SERIALIZER = registerSerializer(GROUP, new AlloyingRecipeSerializer());
|
||||
public final static RecipeType<AlloyingRecipe> TYPE = EndRecipeManager.registerType(GROUP);
|
||||
public final static AlloyingRecipeSerializer SERIALIZER = EndRecipeManager.registerSerializer(GROUP, new AlloyingRecipeSerializer());
|
||||
|
||||
protected final RecipeType<?> type;
|
||||
protected final Identifier id;
|
||||
|
@ -104,15 +106,91 @@ public class AlloyingRecipe implements Recipe<Inventory> {
|
|||
return new ItemStack(BlockRegistry.END_STONE_SMELTER);
|
||||
}
|
||||
|
||||
private static <S extends RecipeSerializer<T>, T extends Recipe<?>> S registerSerializer(String id, S serializer) {
|
||||
return Registry.register(Registry.RECIPE_SERIALIZER, new Identifier(BetterEnd.MOD_ID, id), serializer);
|
||||
}
|
||||
|
||||
private static <T extends Recipe<?>> RecipeType<T> registerType(String name) {
|
||||
return Registry.register(Registry.RECIPE_TYPE, new Identifier(BetterEnd.MOD_ID, name), new RecipeType<T>() {
|
||||
public String toString() {
|
||||
return name;
|
||||
public static class Builder {
|
||||
private final static Builder INSTANCE = new Builder();
|
||||
|
||||
public static Builder create(String id) {
|
||||
INSTANCE.id = BetterEnd.getResId(id);
|
||||
INSTANCE.primaryInput = null;
|
||||
INSTANCE.secondaryInput = null;
|
||||
INSTANCE.output = null;
|
||||
INSTANCE.experience = 0.0F;
|
||||
INSTANCE.smeltTime = 350;
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private Identifier id;
|
||||
private Ingredient primaryInput;
|
||||
private Ingredient secondaryInput;
|
||||
private ItemStack output;
|
||||
private float experience;
|
||||
private int smeltTime;
|
||||
|
||||
private Builder() {}
|
||||
|
||||
public Builder setPrimaryInput(ItemConvertible... inputs) {
|
||||
this.primaryInput = Ingredient.ofItems(inputs);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSecondaryInput(ItemConvertible... inputs) {
|
||||
this.secondaryInput = Ingredient.ofItems(inputs);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setPrimaryInput(Tag<Item> input) {
|
||||
this.primaryInput = Ingredient.fromTag(input);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSecondaryInput(Tag<Item> input) {
|
||||
this.secondaryInput = Ingredient.fromTag(input);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setInput(ItemConvertible primaryInput, ItemConvertible secondaryInput) {
|
||||
this.setPrimaryInput(primaryInput);
|
||||
this.setSecondaryInput(secondaryInput);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setInput(Tag<Item> primaryInput, Tag<Item> secondaryInput) {
|
||||
this.setPrimaryInput(primaryInput);
|
||||
this.setSecondaryInput(secondaryInput);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setInput(Ingredient primaryInput, Ingredient secondaryInput) {
|
||||
this.primaryInput = primaryInput;
|
||||
this.secondaryInput = secondaryInput;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setOutput(ItemConvertible output, int amount) {
|
||||
this.output = new ItemStack(output, amount);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setExpiriense(float amount) {
|
||||
this.experience = amount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSmeltTime(int time) {
|
||||
this.smeltTime = time;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void build() {
|
||||
if (primaryInput == null) {
|
||||
throw new IllegalArgumentException("Primary input can't be null!");
|
||||
} else if(secondaryInput == null) {
|
||||
throw new IllegalArgumentException("Secondary input can't be null!");
|
||||
} else if(output == null) {
|
||||
throw new IllegalArgumentException("Output can't be null!");
|
||||
}
|
||||
});
|
||||
EndRecipeManager.addRecipe(AlloyingRecipe.TYPE, new AlloyingRecipe(id, primaryInput, secondaryInput, output, experience, smeltTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
38
src/main/java/ru/betterend/recipe/AlloyingRecipes.java
Normal file
38
src/main/java/ru/betterend/recipe/AlloyingRecipes.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
package ru.betterend.recipe;
|
||||
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.item.Items;
|
||||
import ru.betterend.registry.ItemRegistry;
|
||||
|
||||
public class AlloyingRecipes {
|
||||
public static void register() {
|
||||
AlloyingRecipe.Builder.create("additional_iron")
|
||||
.setInput(Blocks.IRON_ORE, Blocks.IRON_ORE)
|
||||
.setOutput(Items.IRON_INGOT, 3)
|
||||
.setExpiriense(2.1F)
|
||||
.build();
|
||||
AlloyingRecipe.Builder.create("additional_gold")
|
||||
.setInput(Blocks.GOLD_ORE, Blocks.GOLD_ORE)
|
||||
.setOutput(Items.GOLD_INGOT, 3)
|
||||
.setExpiriense(3F)
|
||||
.build();
|
||||
AlloyingRecipe.Builder.create("additional_netherite")
|
||||
.setInput(Blocks.ANCIENT_DEBRIS, Blocks.ANCIENT_DEBRIS)
|
||||
.setOutput(Items.NETHERITE_SCRAP, 3)
|
||||
.setExpiriense(6F)
|
||||
.setSmeltTime(500)
|
||||
.build();
|
||||
AlloyingRecipe.Builder.create("terminite_ingot")
|
||||
.setInput(Items.IRON_INGOT, ItemRegistry.ENDER_DUST)
|
||||
.setOutput(ItemRegistry.TERMINITE_INGOT, 1)
|
||||
.setExpiriense(2.5F)
|
||||
.setSmeltTime(450)
|
||||
.build();
|
||||
AlloyingRecipe.Builder.create("aeternium_ingot")
|
||||
.setInput(ItemRegistry.TERMINITE_INGOT, Items.NETHERITE_INGOT)
|
||||
.setOutput(ItemRegistry.AETERNIUM_INGOT, 1)
|
||||
.setExpiriense(4.5F)
|
||||
.setSmeltTime(600)
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -1,12 +1,16 @@
|
|||
package ru.betterend.recipe;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.recipe.Recipe;
|
||||
import net.minecraft.recipe.RecipeSerializer;
|
||||
import net.minecraft.recipe.RecipeType;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import ru.betterend.BetterEnd;
|
||||
|
||||
public class EndRecipeManager {
|
||||
private static final Map<RecipeType<?>, Map<Identifier, Recipe<?>>> RECIPES = Maps.newHashMap();
|
||||
|
@ -33,13 +37,30 @@ public class EndRecipeManager {
|
|||
Map<Identifier, Recipe<?>> list = RECIPES.get(type);
|
||||
if (list != null) {
|
||||
Map<Identifier, Recipe<?>> typeList = result.get(type);
|
||||
list.forEach((id, recipe) -> {
|
||||
if (typeList == null) {
|
||||
typeList = Maps.newHashMap();
|
||||
result.put(type, typeList);
|
||||
}
|
||||
for (Entry<Identifier, Recipe<?>> entry : list.entrySet()) {
|
||||
Identifier id = entry.getKey();
|
||||
if (!typeList.containsKey(id))
|
||||
typeList.put(id, recipe);
|
||||
});
|
||||
typeList.put(id, entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static <S extends RecipeSerializer<T>, T extends Recipe<?>> S registerSerializer(String id, S serializer) {
|
||||
return Registry.register(Registry.RECIPE_SERIALIZER, BetterEnd.getResId(id), serializer);
|
||||
}
|
||||
|
||||
static <T extends Recipe<?>> RecipeType<T> registerType(String name) {
|
||||
return Registry.register(Registry.RECIPE_TYPE, BetterEnd.getResId(name), new RecipeType<T>() {
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -97,8 +97,8 @@ public class RecipeBuilder {
|
|||
int height = shape.length;
|
||||
int width = shape[0].length();
|
||||
ItemStack result = new ItemStack(output, count);
|
||||
Identifier id = new Identifier(BetterEnd.MOD_ID, name);
|
||||
DefaultedList<Ingredient> materials = getMaterials(width, height);
|
||||
Identifier id = BetterEnd.getResId(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);
|
||||
EndRecipeManager.addRecipe(type, recipe);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue