Improved Anvil-Level handling

This commit is contained in:
Frank 2022-07-28 19:52:07 +02:00
parent bb15db429d
commit 2aa13a76ee
9 changed files with 64 additions and 53 deletions

View file

@ -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) {

View file

@ -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));
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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();
}

View file

@ -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];
}
}
}
}

View file

@ -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);
}
}

View file

@ -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"
}

View file

@ -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"
}