Fixed structure features and code style
This commit is contained in:
parent
d431f2555c
commit
5a9365e2bb
153 changed files with 2304 additions and 2459 deletions
|
@ -1,10 +1,6 @@
|
|||
package ru.bclib.recipes;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
|
@ -13,9 +9,12 @@ import net.minecraft.world.item.crafting.RecipeType;
|
|||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class BCLRecipeManager {
|
||||
private static final Map<RecipeType<?>, Map<ResourceLocation, Recipe<?>>> RECIPES = Maps.newHashMap();
|
||||
|
||||
|
||||
public static void addRecipe(RecipeType<?> type, Recipe<?> recipe) {
|
||||
Map<ResourceLocation, Recipe<?>> list = RECIPES.get(type);
|
||||
if (list == null) {
|
||||
|
@ -32,16 +31,16 @@ public class BCLRecipeManager {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static Map<RecipeType<?>, Map<ResourceLocation, Recipe<?>>> getMap(Map<RecipeType<?>, Map<ResourceLocation, Recipe<?>>> recipes) {
|
||||
Map<RecipeType<?>, Map<ResourceLocation, Recipe<?>>> result = Maps.newHashMap();
|
||||
|
||||
|
||||
for (RecipeType<?> type : recipes.keySet()) {
|
||||
Map<ResourceLocation, Recipe<?>> typeList = Maps.newHashMap();
|
||||
typeList.putAll(recipes.get(type));
|
||||
result.put(type, typeList);
|
||||
}
|
||||
|
||||
|
||||
for (RecipeType<?> type : RECIPES.keySet()) {
|
||||
Map<ResourceLocation, Recipe<?>> list = RECIPES.get(type);
|
||||
if (list != null) {
|
||||
|
@ -52,32 +51,32 @@ public class BCLRecipeManager {
|
|||
}
|
||||
for (Entry<ResourceLocation, Recipe<?>> entry : list.entrySet()) {
|
||||
ResourceLocation id = entry.getKey();
|
||||
if (!typeList.containsKey(id))
|
||||
typeList.put(id, entry.getValue());
|
||||
if (!typeList.containsKey(id)) typeList.put(id, entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static <S extends RecipeSerializer<T>, T extends Recipe<?>> S registerSerializer(String modID, String id, S serializer) {
|
||||
return Registry.register(Registry.RECIPE_SERIALIZER, modID + ":" + id, serializer);
|
||||
}
|
||||
|
||||
|
||||
public static <T extends Recipe<?>> RecipeType<T> registerType(String modID, String type) {
|
||||
ResourceLocation recipeTypeId = new ResourceLocation(modID, type);
|
||||
return Registry.register(Registry.RECIPE_TYPE, recipeTypeId, new RecipeType<T>() {
|
||||
public String toString() {
|
||||
return type;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean exists(ItemLike item) {
|
||||
if (item instanceof Block) {
|
||||
return Registry.BLOCK.getKey((Block) item) != Registry.BLOCK.getDefaultKey();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return Registry.ITEM.getKey(item.asItem()) != Registry.ITEM.getDefaultKey();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,18 +20,8 @@ public class CraftingRecipes {
|
|||
GridRecipe.make(BCLib.MOD_ID, "tag_minecart", Items.MINECART).setShape("I I", "III").addMaterial('I', TagAPI.IRON_INGOTS).checkConfig(Configs.RECIPE_CONFIG).build();
|
||||
GridRecipe.make(BCLib.MOD_ID, "tag_shield", Items.SHIELD).setShape("WIW", "WWW", " W ").addMaterial('I', TagAPI.IRON_INGOTS).addMaterial('W', ItemTags.PLANKS).checkConfig(Configs.RECIPE_CONFIG).build();
|
||||
|
||||
GridRecipe.make(BCLib.MOD_ID, "tag_hopper", Blocks.HOPPER)
|
||||
.setShape("I I", "ICI", " I ")
|
||||
.addMaterial('I', TagAPI.IRON_INGOTS)
|
||||
.addMaterial('C', TagAPI.ITEM_CHEST)
|
||||
.checkConfig(Configs.RECIPE_CONFIG)
|
||||
.build();
|
||||
|
||||
GridRecipe.make(BCLib.MOD_ID, "tag_shulker_box", Blocks.SHULKER_BOX)
|
||||
.setShape("S", "C", "S")
|
||||
.addMaterial('S', Items.SHULKER_SHELL)
|
||||
.addMaterial('C', TagAPI.ITEM_CHEST)
|
||||
.checkConfig(Configs.RECIPE_CONFIG)
|
||||
.build();
|
||||
GridRecipe.make(BCLib.MOD_ID, "tag_hopper", Blocks.HOPPER).setShape("I I", "ICI", " I ").addMaterial('I', TagAPI.IRON_INGOTS).addMaterial('C', TagAPI.ITEM_CHEST).checkConfig(Configs.RECIPE_CONFIG).build();
|
||||
|
||||
GridRecipe.make(BCLib.MOD_ID, "tag_shulker_box", Blocks.SHULKER_BOX).setShape("S", "C", "S").addMaterial('S', Items.SHULKER_SHELL).addMaterial('C', TagAPI.ITEM_CHEST).checkConfig(Configs.RECIPE_CONFIG).build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
package ru.bclib.recipes;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.Tag;
|
||||
|
@ -19,6 +15,9 @@ import net.minecraft.world.level.ItemLike;
|
|||
import ru.bclib.BCLib;
|
||||
import ru.bclib.config.PathConfig;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
public class GridRecipe {
|
||||
private static final GridRecipe INSTANCE = new GridRecipe();
|
||||
|
||||
|
@ -55,7 +54,7 @@ public class GridRecipe {
|
|||
exist |= config.getBoolean("grid", id.getPath(), true);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public GridRecipe setGroup(String group) {
|
||||
this.group = group;
|
||||
return this;
|
||||
|
@ -67,7 +66,7 @@ public class GridRecipe {
|
|||
}
|
||||
|
||||
public GridRecipe setList(String shape) {
|
||||
this.shape = new String[] { shape };
|
||||
this.shape = new String[] {shape};
|
||||
this.shaped = false;
|
||||
return this;
|
||||
}
|
||||
|
@ -81,7 +80,7 @@ public class GridRecipe {
|
|||
}
|
||||
|
||||
public GridRecipe addMaterial(char key, ItemLike... values) {
|
||||
for (ItemLike item: values) {
|
||||
for (ItemLike item : values) {
|
||||
exist &= BCLRecipeManager.exists(item);
|
||||
}
|
||||
return addMaterial(key, Ingredient.of(values));
|
||||
|
@ -100,11 +99,11 @@ public class GridRecipe {
|
|||
private NonNullList<Ingredient> getMaterials(int width, int height) {
|
||||
NonNullList<Ingredient> materials = NonNullList.withSize(width * height, Ingredient.EMPTY);
|
||||
int pos = 0;
|
||||
for (String line: shape) {
|
||||
for (String line : shape) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
char c = line.charAt(i);
|
||||
Ingredient material = materialKeys.get(c);
|
||||
materials.set(pos ++, material == null ? Ingredient.EMPTY : material);
|
||||
materials.set(pos++, material == null ? Ingredient.EMPTY : material);
|
||||
}
|
||||
}
|
||||
return materials;
|
||||
|
@ -119,7 +118,8 @@ public class GridRecipe {
|
|||
|
||||
CraftingRecipe recipe = shaped ? new ShapedRecipe(id, group, width, height, materials, result) : new ShapelessRecipe(id, group, result, materials);
|
||||
BCLRecipeManager.addRecipe(type, recipe);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
BCLib.LOGGER.debug("Recipe {} couldn't be added", id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ public class SmithingTableRecipe {
|
|||
BCLib.LOGGER.warning("Addition input for Smithing recipe can't be 'null', recipe {} will be ignored!", id);
|
||||
return;
|
||||
}
|
||||
if(result == null) {
|
||||
if (result == null) {
|
||||
BCLib.LOGGER.warning("Result for Smithing recipe can't be 'null', recipe {} will be ignored!", id);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue