Smithing recipe builder + REI tool damage diplay
This commit is contained in:
parent
2f6014d441
commit
c1b7c83569
8 changed files with 116 additions and 20 deletions
|
@ -1,9 +1,10 @@
|
||||||
package ru.betterend;
|
package ru.betterend;
|
||||||
|
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
import ru.betterend.config.MainConfig;
|
import ru.betterend.config.MainConfig;
|
||||||
import ru.betterend.recipe.AlloyingRecipes;
|
|
||||||
import ru.betterend.recipe.CraftingRecipes;
|
import ru.betterend.recipe.CraftingRecipes;
|
||||||
import ru.betterend.registry.BiomeRegistry;
|
import ru.betterend.registry.BiomeRegistry;
|
||||||
import ru.betterend.registry.BlockEntityRegistry;
|
import ru.betterend.registry.BlockEntityRegistry;
|
||||||
|
@ -38,7 +39,6 @@ public class BetterEnd implements ModInitializer {
|
||||||
ItemTagRegistry.register();
|
ItemTagRegistry.register();
|
||||||
BlockTagRegistry.register();
|
BlockTagRegistry.register();
|
||||||
CraftingRecipes.register();
|
CraftingRecipes.register();
|
||||||
AlloyingRecipes.register();
|
|
||||||
StructureRegistry.register();
|
StructureRegistry.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import me.shedaniel.rei.gui.widget.Widget;
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.client.gui.DrawableHelper;
|
import net.minecraft.client.gui.DrawableHelper;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.text.TranslatableText;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import ru.betterend.util.LangUtil;
|
import ru.betterend.util.LangUtil;
|
||||||
|
|
||||||
|
@ -46,12 +47,14 @@ public class REIAnvilCategory implements TransferRecipeCategory<REIAnvilDisplay>
|
||||||
widgets.add(Widgets.createRecipeBase(bounds));
|
widgets.add(Widgets.createRecipeBase(bounds));
|
||||||
int x = startPoint.x + 10;
|
int x = startPoint.x + 10;
|
||||||
int y = startPoint.y;
|
int y = startPoint.y;
|
||||||
widgets.add(Widgets.createResultSlotBackground(new Point(x + 61, y + 9)));
|
widgets.add(Widgets.createResultSlotBackground(new Point(x + 61, y + 4)));
|
||||||
List<List<EntryStack>> inputEntries = display.getInputEntries();
|
List<List<EntryStack>> inputEntries = display.getInputEntries();
|
||||||
widgets.add(Widgets.createArrow(new Point(x + 24, y + 8)));
|
widgets.add(Widgets.createArrow(new Point(x + 24, y + 3)));
|
||||||
widgets.add(Widgets.createSlot(new Point(x - 20, y + 8)).entries(inputEntries.get(0)).markInput());
|
widgets.add(Widgets.createLabel(new Point(bounds.x + bounds.width - 5, bounds.y + bounds.height - 12),
|
||||||
widgets.add(Widgets.createSlot(new Point(x + 1, y + 8)).entries(inputEntries.get(1)).markInput());
|
new TranslatableText("category.rei.damage.amount&dmg", display.getDamage())).noShadow().rightAligned().color(0xFF404040, 0xFFBBBBBB));
|
||||||
widgets.add(Widgets.createSlot(new Point(x + 61, y + 9)).entries(display.getResultingEntries().get(0)).disableBackground().markOutput());
|
widgets.add(Widgets.createSlot(new Point(x - 20, y + 3)).entries(inputEntries.get(0)).markInput());
|
||||||
|
widgets.add(Widgets.createSlot(new Point(x + 1, y + 3)).entries(inputEntries.get(1)).markInput());
|
||||||
|
widgets.add(Widgets.createSlot(new Point(x + 61, y + 4)).entries(display.getResultingEntries().get(0)).disableBackground().markOutput());
|
||||||
return widgets;
|
return widgets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,8 +65,8 @@ public class REIAnvilCategory implements TransferRecipeCategory<REIAnvilDisplay>
|
||||||
matrices.push();
|
matrices.push();
|
||||||
matrices.translate(0, 0, 400);
|
matrices.translate(0, 0, 400);
|
||||||
if (redSlots.contains(0)) {
|
if (redSlots.contains(0)) {
|
||||||
DrawableHelper.fill(matrices, startPoint.x - 20, startPoint.y + 8, startPoint.x - 20 + 16, startPoint.y + 8 + 16, 1090453504);
|
DrawableHelper.fill(matrices, startPoint.x - 20, startPoint.y + 3, startPoint.x - 20 + 16, startPoint.y + 3 + 16, 1090453504);
|
||||||
DrawableHelper.fill(matrices, startPoint.x + 1, startPoint.y + 8, startPoint.x + 1 + 16, startPoint.y + 8 + 16, 1090453504);
|
DrawableHelper.fill(matrices, startPoint.x + 1, startPoint.y + 3, startPoint.x + 1 + 16, startPoint.y + 3 + 16, 1090453504);
|
||||||
}
|
}
|
||||||
matrices.pop();
|
matrices.pop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,10 @@ public class REIAnvilDisplay implements TransferRecipeDisplay {
|
||||||
this.output = Collections.singletonList(EntryStack.create(recipe.getOutput()));
|
this.output = Collections.singletonList(EntryStack.create(recipe.getOutput()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getDamage() {
|
||||||
|
return this.recipe.getDamage();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Optional<Identifier> getRecipeLocation() {
|
public @NotNull Optional<Identifier> getRecipeLocation() {
|
||||||
return Optional.ofNullable(recipe).map(Recipe::getId);
|
return Optional.ofNullable(recipe).map(Recipe::getId);
|
||||||
|
|
|
@ -4,8 +4,11 @@ import com.google.gson.JsonObject;
|
||||||
|
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.inventory.Inventory;
|
import net.minecraft.inventory.Inventory;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemConvertible;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.ToolItem;
|
import net.minecraft.item.ToolItem;
|
||||||
import net.minecraft.network.PacketByteBuf;
|
import net.minecraft.network.PacketByteBuf;
|
||||||
|
@ -13,11 +16,13 @@ import net.minecraft.recipe.Ingredient;
|
||||||
import net.minecraft.recipe.Recipe;
|
import net.minecraft.recipe.Recipe;
|
||||||
import net.minecraft.recipe.RecipeSerializer;
|
import net.minecraft.recipe.RecipeSerializer;
|
||||||
import net.minecraft.recipe.RecipeType;
|
import net.minecraft.recipe.RecipeType;
|
||||||
|
import net.minecraft.tag.Tag;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.JsonHelper;
|
import net.minecraft.util.JsonHelper;
|
||||||
import net.minecraft.util.collection.DefaultedList;
|
import net.minecraft.util.collection.DefaultedList;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import ru.betterend.BetterEnd;
|
import ru.betterend.BetterEnd;
|
||||||
import ru.betterend.registry.ItemTagRegistry;
|
import ru.betterend.registry.ItemTagRegistry;
|
||||||
|
|
||||||
|
@ -82,6 +87,10 @@ public class AnvilSmithingRecipe implements Recipe<Inventory> {
|
||||||
int level = ((ToolItem) hammer.getItem()).getMaterial().getMiningLevel();
|
int level = ((ToolItem) hammer.getItem()).getMaterial().getMiningLevel();
|
||||||
return level >= this.level && this.input.test(craftingInventory.getStack(1));
|
return level >= this.level && this.input.test(craftingInventory.getStack(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getDamage() {
|
||||||
|
return this.damage;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DefaultedList<Ingredient> getPreviewInputs() {
|
public DefaultedList<Ingredient> getPreviewInputs() {
|
||||||
|
@ -114,6 +123,68 @@ public class AnvilSmithingRecipe implements Recipe<Inventory> {
|
||||||
public boolean isIgnoredInRecipeBook() {
|
public boolean isIgnoredInRecipeBook() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
private final static Builder INSTANCE = new Builder();
|
||||||
|
|
||||||
|
public static Builder create(String id) {
|
||||||
|
INSTANCE.id = BetterEnd.makeID(id);
|
||||||
|
INSTANCE.input = null;
|
||||||
|
INSTANCE.output = null;
|
||||||
|
INSTANCE.level = 1;
|
||||||
|
INSTANCE.damage = 1;
|
||||||
|
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Identifier id;
|
||||||
|
private Ingredient input;
|
||||||
|
private ItemStack output;
|
||||||
|
private int level = 1;
|
||||||
|
private int damage = 1;
|
||||||
|
|
||||||
|
private Builder() {}
|
||||||
|
|
||||||
|
public Builder setInput(ItemConvertible... inputItem) {
|
||||||
|
this.setInput(Ingredient.ofItems(inputItem));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setInput(Tag<Item> inputTag) {
|
||||||
|
this.setInput(Ingredient.fromTag(inputTag));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setInput(Ingredient ingredient) {
|
||||||
|
this.input = ingredient;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setOutput(ItemConvertible output, int amount) {
|
||||||
|
this.output = new ItemStack(output, amount);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setLevel(int level) {
|
||||||
|
this.level = level;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setDamage(int damage) {
|
||||||
|
this.damage = damage;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void build() {
|
||||||
|
if (input == null) {
|
||||||
|
throw new IllegalArgumentException("Input can't be null!");
|
||||||
|
} else if(output == null) {
|
||||||
|
throw new IllegalArgumentException("Output can't be null!");
|
||||||
|
}
|
||||||
|
|
||||||
|
EndRecipeManager.addRecipe(TYPE, new AnvilSmithingRecipe(id, input, output, level, damage));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class Serializer implements RecipeSerializer<AnvilSmithingRecipe> {
|
public static class Serializer implements RecipeSerializer<AnvilSmithingRecipe> {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,10 +2,8 @@ package ru.betterend.recipe;
|
||||||
|
|
||||||
import net.minecraft.block.Blocks;
|
import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.recipe.Ingredient;
|
|
||||||
import ru.betterend.BetterEnd;
|
|
||||||
import ru.betterend.registry.BlockRegistry;
|
import ru.betterend.registry.BlockRegistry;
|
||||||
import ru.betterend.registry.ItemRegistry;
|
import ru.betterend.registry.ItemRegistry;
|
||||||
|
|
||||||
|
@ -71,8 +69,9 @@ public class CraftingRecipes {
|
||||||
RecipeBuilder.make("creeping_moss_dye", Items.CYAN_DYE).setList("#").addMaterial('#', BlockRegistry.CREEPING_MOSS).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_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();
|
RecipeBuilder.make("umbrella_moss_tall_dye", Items.YELLOW_DYE).setList("#").addMaterial('#', BlockRegistry.UMBRELLA_MOSS_TALL).build();
|
||||||
|
|
||||||
EndRecipeManager.addRecipe(AnvilSmithingRecipe.TYPE, new AnvilSmithingRecipe(BetterEnd.makeID("ender_pearl_to_dust"), Ingredient.ofItems(Items.ENDER_PEARL), new ItemStack(ItemRegistry.ENDER_DUST), 4, 1));
|
AlloyingRecipes.register();
|
||||||
|
SmithingRecipes.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerHelmet(String name, Item material, Item result) {
|
private static void registerHelmet(String name, Item material, Item result) {
|
||||||
|
@ -145,9 +144,9 @@ public class CraftingRecipes {
|
||||||
|
|
||||||
private static void registerHammer(String name, Item material, Item result) {
|
private static void registerHammer(String name, Item material, Item result) {
|
||||||
RecipeBuilder.make(name + "_hammer", result)
|
RecipeBuilder.make(name + "_hammer", result)
|
||||||
.setShape(new String[] { "I I", "I#I", " # " })
|
.setShape(new String[] { "I I", "I#I", " # " })
|
||||||
.addMaterial('I', material)
|
.addMaterial('I', material)
|
||||||
.addMaterial('#', Items.STICK)
|
.addMaterial('#', Items.STICK)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
15
src/main/java/ru/betterend/recipe/SmithingRecipes.java
Normal file
15
src/main/java/ru/betterend/recipe/SmithingRecipes.java
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package ru.betterend.recipe;
|
||||||
|
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import ru.betterend.registry.ItemRegistry;
|
||||||
|
|
||||||
|
public class SmithingRecipes {
|
||||||
|
public static void register() {
|
||||||
|
AnvilSmithingRecipe.Builder.create("ender_pearl_to_dust")
|
||||||
|
.setInput(Items.ENDER_PEARL)
|
||||||
|
.setOutput(ItemRegistry.ENDER_DUST, 1)
|
||||||
|
.setLevel(4)
|
||||||
|
.setDamage(5)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -82,5 +82,7 @@
|
||||||
"block.betterend.blue_vine_lantern": "Blue Vine Lantern",
|
"block.betterend.blue_vine_lantern": "Blue Vine Lantern",
|
||||||
"block.betterend.blue_vine_fur": "Blue Vine Fur",
|
"block.betterend.blue_vine_fur": "Blue Vine Fur",
|
||||||
|
|
||||||
"block.betterend.dense_vine": "Dense Vine"
|
"block.betterend.dense_vine": "Dense Vine",
|
||||||
|
|
||||||
|
"category.rei.damage.amount&dmg": "Tool damage: %s"
|
||||||
}
|
}
|
|
@ -82,5 +82,7 @@
|
||||||
"block.betterend.blue_vine_lantern": "Фонарь синей лозы",
|
"block.betterend.blue_vine_lantern": "Фонарь синей лозы",
|
||||||
"block.betterend.blue_vine_fur": "Пух синей лозы",
|
"block.betterend.blue_vine_fur": "Пух синей лозы",
|
||||||
|
|
||||||
"block.betterend.dense_vine": "Плотная лоза"
|
"block.betterend.dense_vine": "Плотная лоза",
|
||||||
|
|
||||||
|
"category.rei.damage.amount&dmg": "Износ инструмента: %s"
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue