Move to correct place
This commit is contained in:
parent
ea7cca31d5
commit
02477b2e31
3 changed files with 3 additions and 3 deletions
|
@ -22,7 +22,7 @@ import net.minecraft.util.Identifier;
|
|||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.profiler.Profiler;
|
||||
import net.minecraft.world.World;
|
||||
import ru.betterend.mixin.recipe.EndRecipeManager;
|
||||
import ru.betterend.recipe.EndRecipeManager;
|
||||
|
||||
@Mixin(RecipeManager.class)
|
||||
public class RecipeManagerMixin
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
package ru.betterend.mixin.recipe;
|
||||
|
||||
import java.util.Map;
|
||||
import com.google.common.collect.Maps;
|
||||
import net.minecraft.recipe.Recipe;
|
||||
import net.minecraft.recipe.RecipeType;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class EndRecipeManager {
|
||||
private static final Map<RecipeType<?>, Map<Identifier, Recipe<?>>> RECIPES = Maps.newHashMap();
|
||||
|
||||
public static void addRecipe(RecipeType<?> type, Recipe<?> recipe) {
|
||||
Map<Identifier, Recipe<?>> list = RECIPES.get(type);
|
||||
if (list == null) {
|
||||
list = Maps.newHashMap();
|
||||
RECIPES.put(type, list);
|
||||
}
|
||||
list.put(recipe.getId(), recipe);
|
||||
}
|
||||
|
||||
public static Map<RecipeType<?>, Map<Identifier, Recipe<?>>> getMap(Map<RecipeType<?>, Map<Identifier, Recipe<?>>> recipes) {
|
||||
Map<RecipeType<?>, Map<Identifier, Recipe<?>>> result = Maps.newHashMap();
|
||||
|
||||
for (RecipeType<?> type : recipes.keySet()) {
|
||||
Map<Identifier, Recipe<?>> typeList = Maps.newHashMap();
|
||||
typeList.putAll(recipes.get(type));
|
||||
result.put(type, typeList);
|
||||
}
|
||||
|
||||
for (RecipeType<?> type : RECIPES.keySet()) {
|
||||
Map<Identifier, Recipe<?>> list = RECIPES.get(type);
|
||||
if (list != null) {
|
||||
Map<Identifier, Recipe<?>> typeList = result.get(type);
|
||||
list.forEach((id, recipe) -> {
|
||||
if (!typeList.containsKey(id))
|
||||
typeList.put(id, recipe);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
package ru.betterend.mixin.recipe;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.CraftingRecipe;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.recipe.RecipeType;
|
||||
import net.minecraft.recipe.ShapedRecipe;
|
||||
import net.minecraft.recipe.ShapelessRecipe;
|
||||
import net.minecraft.tag.Tag;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import ru.betterend.BetterEnd;
|
||||
|
||||
public class RecipeBuilder {
|
||||
private final String name;
|
||||
private final Item output;
|
||||
|
||||
private String group = "";
|
||||
private RecipeType<?> type = RecipeType.CRAFTING;
|
||||
private boolean shaped = true;
|
||||
private String[] shape = new String[] {"#"};
|
||||
private Map<Character, Ingredient> materialKeys = Maps.newHashMap();
|
||||
private int count;
|
||||
|
||||
public RecipeBuilder(String name, Item output) {
|
||||
this.name = name;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
public RecipeBuilder(String name, Block output) {
|
||||
this.name = name;
|
||||
this.output = output.asItem();
|
||||
}
|
||||
|
||||
public RecipeBuilder setGroup(String group) {
|
||||
this.group = group;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecipeBuilder setShape(String[] shape) {
|
||||
this.shape = shape;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecipeBuilder addMaterial(char key, Item value) {
|
||||
materialKeys.put(key, Ingredient.ofItems(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecipeBuilder addMaterial(char key, Block value) {
|
||||
materialKeys.put(key, Ingredient.ofItems(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecipeBuilder addMaterial(char key, Tag<Item> value) {
|
||||
materialKeys.put(key, Ingredient.fromTag(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecipeBuilder setOutputCount(int count) {
|
||||
this.count = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
private DefaultedList<Ingredient> getMaterials(int width, int height) {
|
||||
DefaultedList<Ingredient> materials = DefaultedList.ofSize(width * height, Ingredient.EMPTY);
|
||||
for (String line: shape) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
char c = line.charAt(i);
|
||||
Ingredient material = materialKeys.get(c);
|
||||
materials.add(material == null ? Ingredient.EMPTY : material);
|
||||
}
|
||||
}
|
||||
return materials;
|
||||
}
|
||||
|
||||
public void build() {
|
||||
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);
|
||||
|
||||
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