Reorganized Imports/Packages
This commit is contained in:
parent
cb9459f176
commit
3ee10482ab
721 changed files with 34873 additions and 33558 deletions
349
src/main/java/org/betterx/bclib/recipes/AnvilRecipe.java
Normal file
349
src/main/java/org/betterx/bclib/recipes/AnvilRecipe.java
Normal file
|
@ -0,0 +1,349 @@
|
|||
package org.betterx.bclib.recipes;
|
||||
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.TagParser;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TieredItem;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.api.tag.CommonItemTags;
|
||||
import org.betterx.bclib.config.PathConfig;
|
||||
import org.betterx.bclib.interfaces.UnknownReceipBookCategory;
|
||||
import org.betterx.bclib.util.ItemUtil;
|
||||
import org.betterx.bclib.util.RecipeHelper;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class AnvilRecipe implements Recipe<Container>, UnknownReceipBookCategory {
|
||||
public final static String GROUP = "smithing";
|
||||
public final static RecipeType<AnvilRecipe> TYPE = BCLRecipeManager.registerType(BCLib.MOD_ID, GROUP);
|
||||
public final static Serializer SERIALIZER = BCLRecipeManager.registerSerializer(
|
||||
BCLib.MOD_ID,
|
||||
GROUP,
|
||||
new Serializer()
|
||||
);
|
||||
public final static ResourceLocation ID = BCLib.makeID(GROUP);
|
||||
|
||||
public static void register() {
|
||||
|
||||
}
|
||||
|
||||
private final ResourceLocation id;
|
||||
private final Ingredient input;
|
||||
private final ItemStack output;
|
||||
private final int damage;
|
||||
private final int toolLevel;
|
||||
private final int anvilLevel;
|
||||
private final int inputCount;
|
||||
|
||||
public AnvilRecipe(ResourceLocation identifier,
|
||||
Ingredient input,
|
||||
ItemStack output,
|
||||
int inputCount,
|
||||
int toolLevel,
|
||||
int anvilLevel,
|
||||
int damage) {
|
||||
this.id = identifier;
|
||||
this.input = input;
|
||||
this.output = output;
|
||||
this.toolLevel = toolLevel;
|
||||
this.anvilLevel = anvilLevel;
|
||||
this.inputCount = inputCount;
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
public static Builder create(String id) {
|
||||
return create(BCLib.makeID(id));
|
||||
}
|
||||
|
||||
public static Builder create(ResourceLocation id) {
|
||||
Builder.INSTANCE.id = id;
|
||||
Builder.INSTANCE.input = null;
|
||||
Builder.INSTANCE.output = null;
|
||||
Builder.INSTANCE.inputCount = 1;
|
||||
Builder.INSTANCE.toolLevel = 1;
|
||||
Builder.INSTANCE.anvilLevel = 1;
|
||||
Builder.INSTANCE.damage = 1;
|
||||
Builder.INSTANCE.alright = true;
|
||||
Builder.INSTANCE.exist = true;
|
||||
|
||||
return Builder.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeSerializer<?> getSerializer() {
|
||||
return SERIALIZER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getResultItem() {
|
||||
return this.output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Container craftingInventory, Level world) {
|
||||
return this.matches(craftingInventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack assemble(Container craftingInventory) {
|
||||
return this.output.copy();
|
||||
}
|
||||
|
||||
public ItemStack craft(Container craftingInventory, Player player) {
|
||||
if (!player.isCreative()) {
|
||||
if (!checkHammerDurability(craftingInventory, player)) return ItemStack.EMPTY;
|
||||
ItemStack hammer = craftingInventory.getItem(1);
|
||||
hammer.hurtAndBreak(this.damage, player, entity -> entity.broadcastBreakEvent((InteractionHand) null));
|
||||
}
|
||||
return this.assemble(craftingInventory);
|
||||
}
|
||||
|
||||
public boolean checkHammerDurability(Container craftingInventory, Player player) {
|
||||
if (player.isCreative()) return true;
|
||||
ItemStack hammer = craftingInventory.getItem(1);
|
||||
int damage = hammer.getDamageValue() + this.damage;
|
||||
return damage < hammer.getMaxDamage();
|
||||
}
|
||||
|
||||
public boolean matches(Container craftingInventory) {
|
||||
ItemStack hammer = craftingInventory.getItem(1);
|
||||
//TODO: 1.18.2 Test if hammer still works
|
||||
if (hammer.isEmpty() || !hammer.is(CommonItemTags.HAMMERS)) {
|
||||
return false;
|
||||
}
|
||||
ItemStack material = craftingInventory.getItem(0);
|
||||
int materialCount = material.getCount();
|
||||
int level = ((TieredItem) hammer.getItem()).getTier().getLevel();
|
||||
return this.input.test(craftingInventory.getItem(0)) && materialCount >= this.inputCount && level >= this.toolLevel;
|
||||
}
|
||||
|
||||
public int getDamage() {
|
||||
return this.damage;
|
||||
}
|
||||
|
||||
public int getInputCount() {
|
||||
return this.inputCount;
|
||||
}
|
||||
|
||||
public int getAnvilLevel() {
|
||||
return this.anvilLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<Ingredient> getIngredients() {
|
||||
NonNullList<Ingredient> defaultedList = NonNullList.create();
|
||||
defaultedList.add(Ingredient.of(Registry.ITEM.stream()
|
||||
.filter(item -> item.builtInRegistryHolder()
|
||||
.is(CommonItemTags.HAMMERS))
|
||||
.filter(hammer -> ((TieredItem) hammer).getTier()
|
||||
.getLevel() >= toolLevel)
|
||||
.map(ItemStack::new))
|
||||
);
|
||||
defaultedList.add(input);
|
||||
return defaultedList;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public boolean canCraftInDimensions(int width, int height) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeType<?> getType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSpecial() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
AnvilRecipe that = (AnvilRecipe) o;
|
||||
return damage == that.damage && toolLevel == that.toolLevel && id.equals(that.id) && input.equals(that.input) && output.equals(
|
||||
that.output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, input, output, damage, toolLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AnvilRecipe [" + id + "]";
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final static Builder INSTANCE = new Builder();
|
||||
|
||||
private ResourceLocation id;
|
||||
private Ingredient input;
|
||||
private ItemStack output;
|
||||
private int inputCount = 1;
|
||||
private int toolLevel = 1;
|
||||
private int anvilLevel = 1;
|
||||
private int damage = 1;
|
||||
private boolean alright;
|
||||
private boolean exist;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public Builder setInput(ItemLike... inputItems) {
|
||||
this.alright &= RecipeHelper.exists(inputItems);
|
||||
this.setInput(Ingredient.of(inputItems));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setInput(TagKey<Item> inputTag) {
|
||||
this.setInput(Ingredient.of(inputTag));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setInput(Ingredient ingredient) {
|
||||
this.input = ingredient;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setInputCount(int count) {
|
||||
this.inputCount = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setOutput(ItemLike output) {
|
||||
return this.setOutput(output, 1);
|
||||
}
|
||||
|
||||
public Builder setOutput(ItemLike output, int amount) {
|
||||
this.alright &= RecipeHelper.exists(output);
|
||||
this.output = new ItemStack(output, amount);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setToolLevel(int level) {
|
||||
this.toolLevel = level;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setAnvilLevel(int level) {
|
||||
this.anvilLevel = level;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setDamage(int damage) {
|
||||
this.damage = damage;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder checkConfig(PathConfig config) {
|
||||
exist &= config.getBoolean("anvil", id.getPath(), true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void build() {
|
||||
if (!exist) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (input == null) {
|
||||
BCLib.LOGGER.warning("Input for Anvil recipe can't be 'null', recipe {} will be ignored!", id);
|
||||
return;
|
||||
}
|
||||
if (output == null) {
|
||||
BCLib.LOGGER.warning("Output for Anvil recipe can't be 'null', recipe {} will be ignored!", id);
|
||||
return;
|
||||
}
|
||||
if (BCLRecipeManager.getRecipe(TYPE, id) != null) {
|
||||
BCLib.LOGGER.warning("Can't add Anvil recipe! Id {} already exists!", id);
|
||||
return;
|
||||
}
|
||||
if (!alright) {
|
||||
BCLib.LOGGER.debug("Can't add Anvil recipe {}! Ingeredient or output not exists.", id);
|
||||
return;
|
||||
}
|
||||
BCLRecipeManager.addRecipe(TYPE,
|
||||
new AnvilRecipe(id, input, output, inputCount, toolLevel, anvilLevel, damage));
|
||||
}
|
||||
}
|
||||
|
||||
public static class Serializer implements RecipeSerializer<AnvilRecipe> {
|
||||
@Override
|
||||
public AnvilRecipe fromJson(ResourceLocation id, JsonObject json) {
|
||||
Ingredient input = Ingredient.fromJson(json.get("input"));
|
||||
JsonObject result = GsonHelper.getAsJsonObject(json, "result");
|
||||
ItemStack output = ItemUtil.fromJsonRecipe(result);
|
||||
if (output == null) {
|
||||
throw new IllegalStateException("Output item does not exists!");
|
||||
}
|
||||
if (result.has("nbt")) {
|
||||
try {
|
||||
String nbtData = GsonHelper.getAsString(result, "nbt");
|
||||
CompoundTag nbt = TagParser.parseTag(nbtData);
|
||||
output.setTag(nbt);
|
||||
} catch (CommandSyntaxException ex) {
|
||||
BCLib.LOGGER.warning("Error parse nbt data for output.", ex);
|
||||
}
|
||||
}
|
||||
int inputCount = GsonHelper.getAsInt(json, "inputCount", 1);
|
||||
int toolLevel = GsonHelper.getAsInt(json, "toolLevel", 1);
|
||||
int anvilLevel = GsonHelper.getAsInt(json, "anvilLevel", 1);
|
||||
int damage = GsonHelper.getAsInt(json, "damage", 1);
|
||||
|
||||
return new AnvilRecipe(id, input, output, inputCount, toolLevel, anvilLevel, damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnvilRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf packetBuffer) {
|
||||
Ingredient input = Ingredient.fromNetwork(packetBuffer);
|
||||
ItemStack output = packetBuffer.readItem();
|
||||
int inputCount = packetBuffer.readVarInt();
|
||||
int toolLevel = packetBuffer.readVarInt();
|
||||
int anvilLevel = packetBuffer.readVarInt();
|
||||
int damage = packetBuffer.readVarInt();
|
||||
|
||||
return new AnvilRecipe(id, input, output, inputCount, toolLevel, anvilLevel, damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toNetwork(FriendlyByteBuf packetBuffer, AnvilRecipe recipe) {
|
||||
recipe.input.toNetwork(packetBuffer);
|
||||
packetBuffer.writeItem(recipe.output);
|
||||
packetBuffer.writeVarInt(recipe.inputCount);
|
||||
packetBuffer.writeVarInt(recipe.toolLevel);
|
||||
packetBuffer.writeVarInt(recipe.anvilLevel);
|
||||
packetBuffer.writeVarInt(recipe.damage);
|
||||
}
|
||||
}
|
||||
}
|
114
src/main/java/org/betterx/bclib/recipes/BCLRecipeManager.java
Normal file
114
src/main/java/org/betterx/bclib/recipes/BCLRecipeManager.java
Normal file
|
@ -0,0 +1,114 @@
|
|||
package org.betterx.bclib.recipes;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.betterx.bclib.util.CollectionsUtil;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class BCLRecipeManager {
|
||||
private static final Map<RecipeType<?>, Map<ResourceLocation, Recipe<?>>> RECIPES = Maps.newHashMap();
|
||||
private static final Map<RecipeType<?>, Object> SORTED = Maps.newHashMap();
|
||||
private static final String MINECRAFT = "minecraft";
|
||||
|
||||
public static <C extends Container, T extends Recipe<C>> Optional<T> getSortedRecipe(RecipeType<T> type,
|
||||
C inventory,
|
||||
Level level,
|
||||
Function<RecipeType<T>, Map<ResourceLocation, Recipe<C>>> getter) {
|
||||
List<Recipe<C>> recipes = (List<Recipe<C>>) SORTED.computeIfAbsent(type, t -> {
|
||||
Collection<Recipe<C>> values = getter.apply(type).values();
|
||||
List<Recipe<C>> list = new ArrayList<>(values);
|
||||
list.sort((v1, v2) -> {
|
||||
boolean b1 = v1.getId().getNamespace().equals(MINECRAFT);
|
||||
boolean b2 = v2.getId().getNamespace().equals(MINECRAFT);
|
||||
return b1 ^ b2 ? (b1 ? 1 : -1) : 0;
|
||||
});
|
||||
return ImmutableList.copyOf(list);
|
||||
});
|
||||
return (Optional<T>) recipes.stream().filter(recipe -> recipe.matches(inventory, level)).findFirst();
|
||||
}
|
||||
|
||||
public static void addRecipe(RecipeType<?> type, Recipe<?> recipe) {
|
||||
Map<ResourceLocation, Recipe<?>> list = RECIPES.computeIfAbsent(type, i -> Maps.newHashMap());
|
||||
list.put(recipe.getId(), recipe);
|
||||
}
|
||||
|
||||
public static <T extends Recipe<?>> T getRecipe(RecipeType<T> type, ResourceLocation id) {
|
||||
Map<ResourceLocation, Recipe<?>> map = RECIPES.get(type);
|
||||
return map != null ? (T) map.get(id) : 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);
|
||||
}
|
||||
|
||||
SORTED.clear();
|
||||
RECIPES.forEach((type, list) -> {
|
||||
if (list != null) {
|
||||
Map<ResourceLocation, Recipe<?>> typeList = result.computeIfAbsent(type, i -> Maps.newHashMap());
|
||||
for (Entry<ResourceLocation, Recipe<?>> entry : list.entrySet()) {
|
||||
ResourceLocation id = entry.getKey();
|
||||
typeList.computeIfAbsent(id, i -> entry.getValue());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Map<ResourceLocation, Recipe<?>> getMapByName(Map<ResourceLocation, Recipe<?>> recipes) {
|
||||
Map<ResourceLocation, Recipe<?>> result = CollectionsUtil.getMutable(recipes);
|
||||
RECIPES.values()
|
||||
.forEach(map -> map.forEach((location, recipe) -> result.computeIfAbsent(location, i -> recipe)));
|
||||
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 {
|
||||
return Registry.ITEM.getKey(item.asItem()) != Registry.ITEM.getDefaultKey();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean exists(ItemLike... items) {
|
||||
for (ItemLike item : items) {
|
||||
if (!exists(item)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
88
src/main/java/org/betterx/bclib/recipes/CraftingRecipes.java
Normal file
88
src/main/java/org/betterx/bclib/recipes/CraftingRecipes.java
Normal file
|
@ -0,0 +1,88 @@
|
|||
package org.betterx.bclib.recipes;
|
||||
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.api.tag.CommonItemTags;
|
||||
import org.betterx.bclib.config.Configs;
|
||||
|
||||
public class CraftingRecipes {
|
||||
public static void init() {
|
||||
GridRecipe.make(BCLib.MOD_ID, "tag_smith_table", Blocks.SMITHING_TABLE)
|
||||
.setShape("II", "##", "##")
|
||||
.addMaterial('#', ItemTags.PLANKS)
|
||||
.addMaterial('I', CommonItemTags.IRON_INGOTS)
|
||||
.checkConfig(Configs.RECIPE_CONFIG)
|
||||
.build();
|
||||
GridRecipe.make(BCLib.MOD_ID, "tag_cauldron", Blocks.CAULDRON)
|
||||
.setShape("I I", "I I", "III")
|
||||
.addMaterial('I', CommonItemTags.IRON_INGOTS)
|
||||
.checkConfig(Configs.RECIPE_CONFIG)
|
||||
.build();
|
||||
GridRecipe.make(BCLib.MOD_ID, "tag_hopper", Blocks.HOPPER)
|
||||
.setShape("I I", "ICI", " I ")
|
||||
.addMaterial('I', CommonItemTags.IRON_INGOTS)
|
||||
.addMaterial('C', CommonItemTags.CHEST)
|
||||
.checkConfig(Configs.RECIPE_CONFIG)
|
||||
.build();
|
||||
GridRecipe.make(BCLib.MOD_ID, "tag_piston", Blocks.PISTON)
|
||||
.setShape("WWW", "CIC", "CDC")
|
||||
.addMaterial('I', CommonItemTags.IRON_INGOTS)
|
||||
.addMaterial('D', Items.REDSTONE)
|
||||
.addMaterial('C', Items.COBBLESTONE)
|
||||
.addMaterial('W', ItemTags.PLANKS)
|
||||
.checkConfig(Configs.RECIPE_CONFIG)
|
||||
.build();
|
||||
GridRecipe.make(BCLib.MOD_ID, "tag_rail", Blocks.RAIL)
|
||||
.setOutputCount(16)
|
||||
.setShape("I I", "ISI", "I I")
|
||||
.addMaterial('I', CommonItemTags.IRON_INGOTS)
|
||||
.addMaterial('S', Items.STICK)
|
||||
.checkConfig(Configs.RECIPE_CONFIG)
|
||||
.build();
|
||||
GridRecipe.make(BCLib.MOD_ID, "tag_stonecutter", Blocks.STONECUTTER)
|
||||
.setShape(" I ", "SSS")
|
||||
.addMaterial('I', CommonItemTags.IRON_INGOTS)
|
||||
.addMaterial('S', Items.STONE)
|
||||
.checkConfig(Configs.RECIPE_CONFIG)
|
||||
.build();
|
||||
GridRecipe.make(BCLib.MOD_ID, "tag_bucket", Items.BUCKET)
|
||||
.setShape("I I", " I ")
|
||||
.addMaterial('I', CommonItemTags.IRON_INGOTS)
|
||||
.checkConfig(Configs.RECIPE_CONFIG)
|
||||
.build();
|
||||
GridRecipe.make(BCLib.MOD_ID, "tag_compass", Items.COMPASS)
|
||||
.setShape(" I ", "IDI", " I ")
|
||||
.addMaterial('I', CommonItemTags.IRON_INGOTS)
|
||||
.addMaterial('D', Items.REDSTONE)
|
||||
.checkConfig(Configs.RECIPE_CONFIG)
|
||||
.build();
|
||||
GridRecipe.make(BCLib.MOD_ID, "tag_minecart", Items.MINECART)
|
||||
.setShape("I I", "III")
|
||||
.addMaterial('I', CommonItemTags.IRON_INGOTS)
|
||||
.checkConfig(Configs.RECIPE_CONFIG)
|
||||
.build();
|
||||
GridRecipe.make(BCLib.MOD_ID, "tag_shield", Items.SHIELD)
|
||||
.setShape("WIW", "WWW", " W ")
|
||||
.addMaterial('I', CommonItemTags.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', CommonItemTags.IRON_INGOTS)
|
||||
.addMaterial('C', CommonItemTags.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', CommonItemTags.CHEST)
|
||||
.checkConfig(Configs.RECIPE_CONFIG)
|
||||
.build();
|
||||
}
|
||||
}
|
125
src/main/java/org/betterx/bclib/recipes/FurnaceRecipe.java
Normal file
125
src/main/java/org/betterx/bclib/recipes/FurnaceRecipe.java
Normal file
|
@ -0,0 +1,125 @@
|
|||
package org.betterx.bclib.recipes;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.*;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
import org.betterx.bclib.config.PathConfig;
|
||||
|
||||
public class FurnaceRecipe {
|
||||
private static final FurnaceRecipe INSTANCE = new FurnaceRecipe();
|
||||
|
||||
private ResourceLocation id;
|
||||
private ItemLike input;
|
||||
private ItemLike output;
|
||||
private boolean exist;
|
||||
private String group;
|
||||
private int count;
|
||||
private int time;
|
||||
private float xp;
|
||||
|
||||
private FurnaceRecipe() {
|
||||
}
|
||||
|
||||
public static FurnaceRecipe make(String modID, String name, ItemLike input, ItemLike output) {
|
||||
INSTANCE.id = new ResourceLocation(modID, name);
|
||||
INSTANCE.group = "";
|
||||
INSTANCE.input = input;
|
||||
INSTANCE.output = output;
|
||||
INSTANCE.count = 1;
|
||||
INSTANCE.time = 200;
|
||||
INSTANCE.xp = 0;
|
||||
INSTANCE.exist = BCLRecipeManager.exists(output) && BCLRecipeManager.exists(input);
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public FurnaceRecipe checkConfig(PathConfig config) {
|
||||
exist &= config.getBoolean("furnace", id.getPath(), true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FurnaceRecipe setGroup(String group) {
|
||||
this.group = group;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FurnaceRecipe setOutputCount(int count) {
|
||||
this.count = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FurnaceRecipe setXP(float xp) {
|
||||
this.xp = xp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FurnaceRecipe setCookTime(int time) {
|
||||
this.time = time;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void build() {
|
||||
build(false, false, false);
|
||||
}
|
||||
|
||||
public void buildWithBlasting() {
|
||||
build(true, false, false);
|
||||
}
|
||||
|
||||
public void buildFoodlike() {
|
||||
build(false, true, true);
|
||||
}
|
||||
|
||||
public void build(boolean blasting, boolean campfire, boolean smoker) {
|
||||
if (!exist) {
|
||||
return;
|
||||
}
|
||||
|
||||
SmeltingRecipe recipe = new SmeltingRecipe(
|
||||
new ResourceLocation(id + "_smelting"),
|
||||
group,
|
||||
Ingredient.of(input),
|
||||
new ItemStack(output, count),
|
||||
xp,
|
||||
time
|
||||
);
|
||||
BCLRecipeManager.addRecipe(RecipeType.SMELTING, recipe);
|
||||
|
||||
if (blasting) {
|
||||
BlastingRecipe recipe2 = new BlastingRecipe(
|
||||
new ResourceLocation(id + "_blasting"),
|
||||
group,
|
||||
Ingredient.of(input),
|
||||
new ItemStack(output, count),
|
||||
xp,
|
||||
time / 2
|
||||
);
|
||||
BCLRecipeManager.addRecipe(RecipeType.BLASTING, recipe2);
|
||||
}
|
||||
|
||||
if (campfire) {
|
||||
CampfireCookingRecipe recipe2 = new CampfireCookingRecipe(
|
||||
new ResourceLocation(id + "_campfire"),
|
||||
group,
|
||||
Ingredient.of(input),
|
||||
new ItemStack(output, count),
|
||||
xp,
|
||||
time * 3
|
||||
);
|
||||
BCLRecipeManager.addRecipe(RecipeType.CAMPFIRE_COOKING, recipe2);
|
||||
}
|
||||
|
||||
if (smoker) {
|
||||
SmokingRecipe recipe2 = new SmokingRecipe(
|
||||
new ResourceLocation(id + "_smoker"),
|
||||
group,
|
||||
Ingredient.of(input),
|
||||
new ItemStack(output, count),
|
||||
xp,
|
||||
time / 2
|
||||
);
|
||||
BCLRecipeManager.addRecipe(RecipeType.SMOKING, recipe2);
|
||||
}
|
||||
}
|
||||
}
|
133
src/main/java/org/betterx/bclib/recipes/GridRecipe.java
Normal file
133
src/main/java/org/betterx/bclib/recipes/GridRecipe.java
Normal file
|
@ -0,0 +1,133 @@
|
|||
package org.betterx.bclib.recipes;
|
||||
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.*;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import org.betterx.bclib.config.PathConfig;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
public class GridRecipe {
|
||||
private static final GridRecipe INSTANCE = new GridRecipe();
|
||||
|
||||
private ResourceLocation id;
|
||||
private ItemLike output;
|
||||
|
||||
private String group;
|
||||
private RecipeType<?> type;
|
||||
private boolean shaped;
|
||||
private String[] shape;
|
||||
private final Map<Character, Ingredient> materialKeys = Maps.newHashMap();
|
||||
private int count;
|
||||
private boolean exist;
|
||||
|
||||
private GridRecipe() {
|
||||
}
|
||||
|
||||
public static GridRecipe make(String modID, String name, ItemLike output) {
|
||||
return make(new ResourceLocation(modID, name), output);
|
||||
}
|
||||
|
||||
public static GridRecipe make(ResourceLocation id, ItemLike output) {
|
||||
INSTANCE.id = id;
|
||||
INSTANCE.output = output;
|
||||
|
||||
INSTANCE.group = "";
|
||||
INSTANCE.type = RecipeType.CRAFTING;
|
||||
INSTANCE.shaped = true;
|
||||
INSTANCE.shape = new String[]{"#"};
|
||||
INSTANCE.materialKeys.clear();
|
||||
INSTANCE.count = 1;
|
||||
|
||||
INSTANCE.exist = output != null && BCLRecipeManager.exists(output);
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public GridRecipe checkConfig(PathConfig config) {
|
||||
exist &= config.getBoolean("grid", id.getPath(), true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public GridRecipe setGroup(String group) {
|
||||
this.group = group;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GridRecipe setShape(String... shape) {
|
||||
this.shape = shape;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GridRecipe setList(String shape) {
|
||||
this.shape = new String[]{shape};
|
||||
this.shaped = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GridRecipe addMaterial(char key, TagKey<Item> value) {
|
||||
return addMaterial(key, Ingredient.of(value));
|
||||
}
|
||||
|
||||
public GridRecipe addMaterial(char key, ItemStack... value) {
|
||||
return addMaterial(key, Ingredient.of(Arrays.stream(value)));
|
||||
}
|
||||
|
||||
public GridRecipe addMaterial(char key, ItemLike... values) {
|
||||
for (ItemLike item : values) {
|
||||
exist &= BCLRecipeManager.exists(item);
|
||||
}
|
||||
return addMaterial(key, Ingredient.of(values));
|
||||
}
|
||||
|
||||
private GridRecipe addMaterial(char key, Ingredient value) {
|
||||
materialKeys.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public GridRecipe setOutputCount(int count) {
|
||||
this.count = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
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 (int i = 0; i < width; i++) {
|
||||
char c = line.charAt(i);
|
||||
Ingredient material = materialKeys.get(c);
|
||||
materials.set(pos++, material == null ? Ingredient.EMPTY : material);
|
||||
}
|
||||
}
|
||||
return materials;
|
||||
}
|
||||
|
||||
public void build() {
|
||||
if (!exist) {
|
||||
return;
|
||||
}
|
||||
|
||||
int height = shape.length;
|
||||
int width = shape[0].length();
|
||||
ItemStack result = new ItemStack(output, count);
|
||||
NonNullList<Ingredient> materials = this.getMaterials(width, height);
|
||||
|
||||
CraftingRecipe recipe = shaped ? new ShapedRecipe(
|
||||
id,
|
||||
group,
|
||||
width,
|
||||
height,
|
||||
materials,
|
||||
result
|
||||
) : new ShapelessRecipe(id, group, result, materials);
|
||||
BCLRecipeManager.addRecipe(type, recipe);
|
||||
}
|
||||
}
|
104
src/main/java/org/betterx/bclib/recipes/SmithingTableRecipe.java
Normal file
104
src/main/java/org/betterx/bclib/recipes/SmithingTableRecipe.java
Normal file
|
@ -0,0 +1,104 @@
|
|||
package org.betterx.bclib.recipes;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.item.crafting.UpgradeRecipe;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.config.PathConfig;
|
||||
|
||||
public class SmithingTableRecipe {
|
||||
|
||||
private final static SmithingTableRecipe BUILDER = new SmithingTableRecipe();
|
||||
private final static RecipeType<UpgradeRecipe> TYPE = RecipeType.SMITHING;
|
||||
|
||||
public static SmithingTableRecipe create(String modID, String name) {
|
||||
return create(new ResourceLocation(modID, name));
|
||||
}
|
||||
|
||||
public static SmithingTableRecipe create(ResourceLocation id) {
|
||||
BUILDER.id = id;
|
||||
BUILDER.base = null;
|
||||
BUILDER.addition = null;
|
||||
BUILDER.result = null;
|
||||
BUILDER.exist = true;
|
||||
|
||||
return BUILDER;
|
||||
}
|
||||
|
||||
private ResourceLocation id;
|
||||
private Ingredient base;
|
||||
private Ingredient addition;
|
||||
private ItemStack result;
|
||||
private boolean exist;
|
||||
|
||||
private SmithingTableRecipe() {
|
||||
}
|
||||
|
||||
public SmithingTableRecipe checkConfig(PathConfig config) {
|
||||
exist &= config.getBoolean("smithing", id.getPath(), true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SmithingTableRecipe setResult(ItemLike item) {
|
||||
return this.setResult(item, 1);
|
||||
}
|
||||
|
||||
public SmithingTableRecipe setResult(ItemLike item, int count) {
|
||||
this.exist &= BCLRecipeManager.exists(item);
|
||||
this.result = new ItemStack(item, count);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SmithingTableRecipe setBase(ItemLike... items) {
|
||||
this.exist &= BCLRecipeManager.exists(items);
|
||||
this.base = Ingredient.of(items);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SmithingTableRecipe setBase(TagKey<Item> tag) {
|
||||
this.base = (Ingredient.of(tag));
|
||||
return this;
|
||||
}
|
||||
|
||||
public SmithingTableRecipe setAddition(ItemLike... items) {
|
||||
this.exist &= BCLRecipeManager.exists(items);
|
||||
this.addition = Ingredient.of(items);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SmithingTableRecipe setAddition(TagKey<Item> tag) {
|
||||
this.addition = (Ingredient.of(tag));
|
||||
return this;
|
||||
}
|
||||
|
||||
public void build() {
|
||||
if (!exist) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (base == null) {
|
||||
BCLib.LOGGER.warning("Base input for Smithing recipe can't be 'null', recipe {} will be ignored!", id);
|
||||
return;
|
||||
}
|
||||
if (addition == null) {
|
||||
BCLib.LOGGER.warning("Addition input for Smithing recipe can't be 'null', recipe {} will be ignored!", id);
|
||||
return;
|
||||
}
|
||||
if (result == null) {
|
||||
BCLib.LOGGER.warning("Result for Smithing recipe can't be 'null', recipe {} will be ignored!", id);
|
||||
return;
|
||||
}
|
||||
if (BCLRecipeManager.getRecipe(TYPE, id) != null) {
|
||||
BCLib.LOGGER.warning("Can't add Smithing recipe! Id {} already exists!", id);
|
||||
return;
|
||||
}
|
||||
|
||||
BCLRecipeManager.addRecipe(TYPE, new UpgradeRecipe(id, base, addition, result));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue