From 2aa13a76ee1c6af86496106f06c913be20b20025 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 28 Jul 2022 19:52:07 +0200 Subject: [PATCH] Improved Anvil-Level handling --- .../bclib/blocks/LeveledAnvilBlock.java | 6 ++-- .../bclib/integration/emi/AnvilEmiStack.java | 13 -------- .../integration/emi/EMIAlloyingRecipe.java | 4 +-- .../bclib/integration/emi/EMIAnvilRecipe.java | 4 +-- .../emi/EMIAnvilRecipeCategory.java | 33 ++++++++++--------- .../bclib/integration/emi/EMIPlugin.java | 8 +++-- .../bclib/mixin/common/AnvilMenuMixin.java | 9 ++--- .../resources/assets/bclib/lang/de_de.json | 17 ++++++++-- .../resources/assets/bclib/lang/en_us.json | 23 ++++++++----- 9 files changed, 64 insertions(+), 53 deletions(-) delete mode 100644 src/main/java/org/betterx/bclib/integration/emi/AnvilEmiStack.java diff --git a/src/main/java/org/betterx/bclib/blocks/LeveledAnvilBlock.java b/src/main/java/org/betterx/bclib/blocks/LeveledAnvilBlock.java index 6f44eccf..a8129594 100644 --- a/src/main/java/org/betterx/bclib/blocks/LeveledAnvilBlock.java +++ b/src/main/java/org/betterx/bclib/blocks/LeveledAnvilBlock.java @@ -4,6 +4,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.core.Registry; import net.minecraft.network.chat.MutableComponent; import net.minecraft.util.FormattedCharSequence; +import net.minecraft.world.item.Tiers; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.material.MaterialColor; @@ -20,8 +21,9 @@ public class LeveledAnvilBlock extends BaseAnvilBlock { public static int getAnvilCraftingLevel(Block anvil) { if (anvil instanceof LeveledAnvilBlock l) return l.getCraftingLevel(); - if (anvil == Blocks.ANVIL || anvil == Blocks.CHIPPED_ANVIL || anvil == Blocks.DAMAGED_ANVIL) return 0; - return -1; + if (anvil == Blocks.ANVIL || anvil == Blocks.CHIPPED_ANVIL || anvil == Blocks.DAMAGED_ANVIL) + return Tiers.IRON.getLevel() - 1; + return 0; } public static boolean canHandle(Block anvil, int level) { diff --git a/src/main/java/org/betterx/bclib/integration/emi/AnvilEmiStack.java b/src/main/java/org/betterx/bclib/integration/emi/AnvilEmiStack.java deleted file mode 100644 index 0551d176..00000000 --- a/src/main/java/org/betterx/bclib/integration/emi/AnvilEmiStack.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.betterx.bclib.integration.emi; - -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.ItemLike; - -import dev.emi.emi.api.stack.ItemEmiStack; - -public class AnvilEmiStack extends ItemEmiStack { - public AnvilEmiStack(ItemLike itemLike) { - super(new ItemStack(itemLike)); - } - -} diff --git a/src/main/java/org/betterx/bclib/integration/emi/EMIAlloyingRecipe.java b/src/main/java/org/betterx/bclib/integration/emi/EMIAlloyingRecipe.java index 63ca5063..077bfb82 100644 --- a/src/main/java/org/betterx/bclib/integration/emi/EMIAlloyingRecipe.java +++ b/src/main/java/org/betterx/bclib/integration/emi/EMIAlloyingRecipe.java @@ -57,7 +57,7 @@ public class EMIAlloyingRecipe implements EmiRecipe { @Override public int getDisplayWidth() { - return 76; + return 96; } @Override @@ -77,6 +77,6 @@ public class EMIAlloyingRecipe implements EmiRecipe { // Adds an output slot on the right // Note that output slots need to call `recipeContext` to inform EMI about their recipe context // This includes being able to resolve recipe trees, favorite stacks with recipe context, and more - widgets.addSlot(output.get(0), 58, 0).recipeContext(this); + widgets.addSlot(output.get(0), 78, 0).recipeContext(this); } } diff --git a/src/main/java/org/betterx/bclib/integration/emi/EMIAnvilRecipe.java b/src/main/java/org/betterx/bclib/integration/emi/EMIAnvilRecipe.java index 4d5e49da..17e3a1fb 100644 --- a/src/main/java/org/betterx/bclib/integration/emi/EMIAnvilRecipe.java +++ b/src/main/java/org/betterx/bclib/integration/emi/EMIAnvilRecipe.java @@ -70,7 +70,7 @@ public class EMIAnvilRecipe implements EmiRecipe { @Override public int getDisplayWidth() { - return 76; + return 96; } @Override @@ -90,6 +90,6 @@ public class EMIAnvilRecipe implements EmiRecipe { // Adds an output slot on the right // Note that output slots need to call `recipeContext` to inform EMI about their recipe context // This includes being able to resolve recipe trees, favorite stacks with recipe context, and more - widgetHolder.addSlot(output.get(0), 58, 0).recipeContext(this); + widgetHolder.addSlot(output.get(0), 78, 0).recipeContext(this); } } diff --git a/src/main/java/org/betterx/bclib/integration/emi/EMIAnvilRecipeCategory.java b/src/main/java/org/betterx/bclib/integration/emi/EMIAnvilRecipeCategory.java index 6d0545cc..baabdf08 100644 --- a/src/main/java/org/betterx/bclib/integration/emi/EMIAnvilRecipeCategory.java +++ b/src/main/java/org/betterx/bclib/integration/emi/EMIAnvilRecipeCategory.java @@ -5,6 +5,7 @@ import org.betterx.bclib.util.RomanNumeral; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.Tesselator; +import com.mojang.math.Matrix4f; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; @@ -60,22 +61,22 @@ public class EMIAnvilRecipeCategory extends EmiRecipeCategory { final Font font = Minecraft.getInstance().font; final String content = RomanNumeral.toRoman(anvilLevel); - MultiBufferSource.BufferSource bufferSource = MultiBufferSource - .immediate( - Tesselator.getInstance() - .getBuilder() - ); - font.drawInBatch( - content, - x + 19 - 2 - font.width(content), y + 6 + 3, - 0xFFFFFF, - true, - stack.last().pose(), - bufferSource, - false, - 0, - 0xF000F0 - ); + final MultiBufferSource.BufferSource bufferSource = MultiBufferSource + .immediate(Tesselator.getInstance().getBuilder()); + final int xx = x + 19 - 2 - font.width(content); + final int yy = y + 6 + 3; + final Matrix4f matrix = stack.last().pose(); + + font.drawInBatch(content, xx - 1, yy - 1, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0); + font.drawInBatch(content, xx, yy - 1, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0); + font.drawInBatch(content, xx + 1, yy - 1, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0); + font.drawInBatch(content, xx - 1, yy, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0); + font.drawInBatch(content, xx + 1, yy, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0); + font.drawInBatch(content, xx - 1, yy + 1, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0); + font.drawInBatch(content, xx + 1, yy + 1, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0); + font.drawInBatch(content, xx, yy + 1, 0xFF000000, false, matrix, bufferSource, false, 0, 0xF000F0); + + font.drawInBatch(content, xx, yy, 0xFFFFFFFF, true, matrix, bufferSource, false, 0, 0xF000F0); bufferSource.endBatch(); } diff --git a/src/main/java/org/betterx/bclib/integration/emi/EMIPlugin.java b/src/main/java/org/betterx/bclib/integration/emi/EMIPlugin.java index 71910275..8721eda2 100644 --- a/src/main/java/org/betterx/bclib/integration/emi/EMIPlugin.java +++ b/src/main/java/org/betterx/bclib/integration/emi/EMIPlugin.java @@ -69,20 +69,24 @@ public class EMIPlugin implements EmiPlugin { for (int anvilLevel = 0; anvilLevel <= maxAnvilLevel; anvilLevel++) { int finalAnvilLevel = anvilLevel; - ANVIL_WORKSTATIONS[anvilLevel] = new AnvilEmiStack(LeveledAnvilBlock + ANVIL_WORKSTATIONS[anvilLevel] = EmiStack.of(LeveledAnvilBlock .getAnvils() .stream() .filter(b -> LeveledAnvilBlock.canHandle(b, finalAnvilLevel)) .sorted(Comparator.comparingInt(LeveledAnvilBlock::getAnvilCraftingLevel)) .findFirst().orElse(Blocks.BARRIER) ); - ANVIL_CATEGORIES[anvilLevel] = new EMIAnvilRecipeCategory( BCLib.makeID("anvil_" + anvilLevel), ANVIL_WORKSTATIONS[anvilLevel], getSprite(0, 0), anvilLevel ); + + if (anvilLevel > 0 && ANVIL_WORKSTATIONS[anvilLevel].isEqual(ANVIL_WORKSTATIONS[anvilLevel - 1])) { + ANVIL_WORKSTATIONS[anvilLevel - 1] = ANVIL_WORKSTATIONS[anvilLevel]; + ANVIL_CATEGORIES[anvilLevel - 1] = ANVIL_CATEGORIES[anvilLevel]; + } } } } diff --git a/src/main/java/org/betterx/bclib/mixin/common/AnvilMenuMixin.java b/src/main/java/org/betterx/bclib/mixin/common/AnvilMenuMixin.java index 5976432d..8004c532 100644 --- a/src/main/java/org/betterx/bclib/mixin/common/AnvilMenuMixin.java +++ b/src/main/java/org/betterx/bclib/mixin/common/AnvilMenuMixin.java @@ -58,14 +58,11 @@ public abstract class AnvilMenuMixin extends ItemCombinerMenu implements AnvilSc if (context != ContainerLevelAccess.NULL) { int level = context.evaluate((world, blockPos) -> { Block anvilBlock = world.getBlockState(blockPos).getBlock(); - if (anvilBlock instanceof LeveledAnvilBlock) { - return ((LeveledAnvilBlock) anvilBlock).getCraftingLevel(); - } - return 1; - }, 1); + return LeveledAnvilBlock.getAnvilCraftingLevel(anvilBlock); + }, 0); anvilLevel.set(level); } else { - anvilLevel.set(1); + anvilLevel.set(0); } } diff --git a/src/main/resources/assets/bclib/lang/de_de.json b/src/main/resources/assets/bclib/lang/de_de.json index d244a409..082feaf2 100644 --- a/src/main/resources/assets/bclib/lang/de_de.json +++ b/src/main/resources/assets/bclib/lang/de_de.json @@ -83,6 +83,19 @@ "title.config.bclib.client.ui.forceBetterXPreset": "BetterX als Standard-Welt-Typ verwenden", "description.config.bclib.client.ui.forceBetterXPreset": "Der Welt-Typ bestimmt, wie eine Welt generiert wird. In den meisten Fällen solltet BetterX als Standardeinstellung beibehalten werden (Du kannst den Typ jederzeit im Welt-Erstellen-Bildschirm ändern). Dieser Typ ist für maximale Kompatibilität zwischen DataPacks, unserer Mod und anderen Fabric-Mods optimiert. Außerdem bietet er einige einzigartige Funktionen für BetterNether und BetterEnd. Du solltest diese Option nur deaktivieren, wenn Du einen Grund dazu hast!", "warning.config.bclib.client.ui.forceBetterXPreset": "IN DEN MEISTEN FÄLLEN SOLLTE DIESE OPTION AKTIVIERT BLEIBEN.\n", - "emi.category.bclib.alloying": "Endsteinschmelzofen", - "tag.c.barrel": "Fässer" + "emi.category.bclib.alloying": "Legierungen", + "tag.c.barrel": "Fässer", + "emi.category.bclib.anvil_0": "Amboss (Stufe 0)", + "emi.category.bclib.anvil_1": "Amboss (Stufe I)", + "emi.category.bclib.anvil_2": "Amboss (Stufe II)", + "emi.category.bclib.anvil_3": "Amboss (Stufe III)", + "emi.category.bclib.anvil_4": "Amboss (Stufe IV)", + "emi.category.bclib.anvil_5": "Amboss (Stufe V)", + "tag.c.wooden_barrels": "Hölzerne Fässer Barrels", + "tag.c.workbench": "Werkbänke", + "tag.c.furnaces": "Brennöfen", + "tag.c.saplings": "Setzlinge", + "tag.c.hammers": "Hämmer", + "tag.c.leaves": "Blätter", + "tag.c.soul_ground": "Seelenböden" } \ No newline at end of file diff --git a/src/main/resources/assets/bclib/lang/en_us.json b/src/main/resources/assets/bclib/lang/en_us.json index ed5b0514..c3fba53d 100644 --- a/src/main/resources/assets/bclib/lang/en_us.json +++ b/src/main/resources/assets/bclib/lang/en_us.json @@ -83,12 +83,19 @@ "title.config.bclib.client.ui.forceBetterXPreset": "Use BetterX as Default World-Type", "warning.config.bclib.client.ui.forceBetterXPreset": "MOST LIKELY YOU WILL WANT TO KEEP THIS OPTION ENABLED.\n", "description.config.bclib.client.ui.forceBetterXPreset": "The world type determines how a world is generated. In most cases, BetterX should be kept as the default (you can change the type at any time in the world creation screen). This type is optimized for maximum compatibility between DataPacks, our mod, and other Fabric mods. It also provides some unique features for BetterNether and BetterEnd. You should only disable this option if you have a reason to do so!", - "emi.category.bclib.alloying": "End Stone Smelter", - "emi.category.bclib.anvil_0": "Anvil", - "emi.category.bclib.anvil_1": "Anvil I", - "emi.category.bclib.anvil_2": "Anvil II", - "emi.category.bclib.anvil_3": "Anvil III", - "emi.category.bclib.anvil_4": "Anvil IV", - "emi.category.bclib.anvil_5": "Anvil V", - "tag.c.barrel": "Barrels" + "emi.category.bclib.alloying": "Alloying", + "emi.category.bclib.anvil_0": "Anvil (Level 0)", + "emi.category.bclib.anvil_1": "Anvil (Level I)", + "emi.category.bclib.anvil_2": "Anvil (Level II)", + "emi.category.bclib.anvil_3": "Anvil (Level III)", + "emi.category.bclib.anvil_4": "Anvil (Level IV)", + "emi.category.bclib.anvil_5": "Anvil (Level V)", + "tag.c.barrel": "Barrels", + "tag.c.wooden_barrels": "Wooden Barrels", + "tag.c.workbench": "Crafting Tables", + "tag.c.furnaces": "Furnaces", + "tag.c.saplings": "Saplings", + "tag.c.hammers": "Hammers", + "tag.c.leaves": "Leaves", + "tag.c.soul_ground": "Soul Ground" } \ No newline at end of file