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