From 2ae1686e2bf04a3c5f748a2fb7c746445091d5f4 Mon Sep 17 00:00:00 2001 From: Gugle Date: Wed, 12 Jun 2024 11:19:33 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=20SelectOne=20=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../emi/stack/SelectOneEmiStack.java | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/stack/SelectOneEmiStack.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/stack/SelectOneEmiStack.java index a8a7cdb32..81308cfae 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/stack/SelectOneEmiStack.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/stack/SelectOneEmiStack.java @@ -9,10 +9,12 @@ import dev.emi.emi.api.stack.EmiStack; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -47,11 +49,16 @@ public SelectOneEmiStack copy() { return new SelectOneEmiStack(this.stacks); } + private @Nullable EmiIngredient get() { + if (MINECRAFT.level == null || this.stacks.isEmpty()) return null; + int index = (int) Math.floor((MINECRAFT.level.getGameTime() % (this.stacks.size() * 20)) / 20.0); + return this.stacks.get(index); + } + @Override public void render(GuiGraphics draw, int x, int y, float delta, int flags) { - if (MINECRAFT.level == null || this.stacks.isEmpty()) return; - int index = (int) Math.floor((MINECRAFT.level.getGameTime() % (this.stacks.size() * 20)) / 20.0); - this.stacks.get(index).render(draw, x, y, delta, flags); + EmiIngredient ingredient = this.get(); + if (ingredient != null) ingredient.render(draw, x, y, delta, flags); } @Override @@ -64,6 +71,20 @@ public CompoundTag getNbt() { return new CompoundTag(); } + @Override + public float getChance() { + EmiIngredient ingredient = this.get(); + if (ingredient != null) return ingredient.getChance(); + return super.getChance(); + } + + @Override + public long getAmount() { + EmiIngredient ingredient = this.get(); + if (ingredient != null) return ingredient.getAmount(); + return super.getAmount(); + } + @Override public Object getKey() { return "SelectOne$" + this.stacks.hashCode(); @@ -74,6 +95,13 @@ public ResourceLocation getId() { return AnvilCraft.of("select_one_" + this.stacks.hashCode()); } + @Override + public List getTooltip() { + EmiIngredient ingredient = this.get(); + if (ingredient != null) return ingredient.getTooltip(); + return List.of(); + } + @Override public List getTooltipText() { return List.of(); From a8065c25354b87804ee55ef6c58a9992eaae16db Mon Sep 17 00:00:00 2001 From: Gugle Date: Wed, 12 Jun 2024 12:34:59 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../integration/emi/AnvilCraftEmiPlugin.java | 1 + .../emi/recipe/AnvilProcessEmiRecipe.java | 31 ++++++++++++------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/AnvilCraftEmiPlugin.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/AnvilCraftEmiPlugin.java index 35cb8c253..d9f3bfe78 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/AnvilCraftEmiPlugin.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/AnvilCraftEmiPlugin.java @@ -103,6 +103,7 @@ public void register(EmiRegistry registry) { registry.addWorkstation(AnvilRecipeCategory.SQUEEZE, EmiStack.of(Blocks.CHIPPED_ANVIL)); registry.addWorkstation(AnvilRecipeCategory.SQUEEZE, EmiStack.of(Blocks.DAMAGED_ANVIL)); + registry.addWorkstation(AnvilRecipeCategory.SUPER_HEATING, EmiStack.of(Blocks.CAULDRON)); registry.addWorkstation(AnvilRecipeCategory.SUPER_HEATING, EmiStack.of(ModBlocks.HEATER)); registry.addWorkstation(AnvilRecipeCategory.SUPER_HEATING, EmiStack.of(ModBlocks.ROYAL_ANVIL)); registry.addWorkstation(AnvilRecipeCategory.SUPER_HEATING, EmiStack.of(Blocks.ANVIL)); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/recipe/AnvilProcessEmiRecipe.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/recipe/AnvilProcessEmiRecipe.java index 6ca3e8392..cf02cd9d0 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/recipe/AnvilProcessEmiRecipe.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/recipe/AnvilProcessEmiRecipe.java @@ -227,13 +227,13 @@ protected void addOutputArrow(@NotNull WidgetHolder widgets, int x, int y) { } protected void addInputSlots(WidgetHolder widgets) { - List posLis = this.getSlotsPosList(inputs.size()); + List posList = this.getSlotsPosList(inputs.size()); Vec2 size = this.getSlotsComposeSize(inputs.size()); int x = this.inputs.size() == 1 ? 40 : (int) ((26 - size.x / 2) + 10); int y = (int) ((26 - size.y / 2) + 15); Iterator ingredientIterator = inputs.iterator(); - for (Vec2 vec2 : posLis) { - addSlot(ingredientIterator.next(), (int) (x + vec2.x), (int) (y + vec2.y), widgets); + for (Vec2 vec2 : posList) { + this.addSlot(ingredientIterator.next(), (int) (x + vec2.x), (int) (y + vec2.y), widgets); } } @@ -260,11 +260,15 @@ protected Vec2 getSlotsComposeSize(int length) { } protected void addSlot(@NotNull EmiIngredient ingredient, int x, int y, WidgetHolder widgets) { + if (ingredient instanceof SelectOneEmiStack) { + this.addSelectOneSlot(ingredient, x, y, widgets); + return; + } if (ingredient.getChance() < 1) { - addChangeSlot(ingredient, x, y, widgets); + this.addChanceSlot(ingredient, x, y, widgets); return; } - addSimpleSlot(ingredient, x, y, widgets); + this.addSimpleSlot(ingredient, x, y, widgets); } protected void addSimpleSlot(EmiIngredient ingredient, int x, int y, @NotNull WidgetHolder widgets) { @@ -272,21 +276,26 @@ protected void addSimpleSlot(EmiIngredient ingredient, int x, int y, @NotNull Wi .customBackground(EMI_GUI_TEXTURES, 0, 0, 18, 18)); } - protected void addChangeSlot(EmiIngredient ingredient, int x, int y, @NotNull WidgetHolder widgets) { + protected void addChanceSlot(EmiIngredient ingredient, int x, int y, @NotNull WidgetHolder widgets) { widgets.add(new SlotWidget(ingredient, x, y).recipeContext(this) .customBackground(EMI_GUI_TEXTURES, 19, 0, 18, 18)); } + protected void addSelectOneSlot(EmiIngredient ingredient, int x, int y, @NotNull WidgetHolder widgets) { + widgets.add(new SlotWidget(ingredient, x, y).recipeContext(this) + .customBackground(EMI_GUI_TEXTURES, 38, 0, 18, 18)); + } + protected void addOutputs(WidgetHolder widgets) { - int outputSize = outputs.size(); - List posLis = getSlotsPosList(outputSize); - Vec2 composeSize = getSlotsComposeSize(outputSize); + int outputSize = this.outputs.size(); + List posList = this.getSlotsPosList(outputSize); + Vec2 composeSize = this.getSlotsComposeSize(outputSize); int x = outputSize == 1 ? 190 : (int) ((26 - composeSize.x / 2) + 190); int y = (int) ((26 - composeSize.y / 2) + 15); Iterator emiStackIterator = outputs.iterator(); - for (Vec2 vec2 : posLis) { + for (Vec2 vec2 : posList) { if (emiStackIterator.hasNext()) { - addSlot(emiStackIterator.next(), (int) (x + vec2.x), (int) (y + vec2.y), widgets); + this.addSlot(emiStackIterator.next(), (int) (x + vec2.x), (int) (y + vec2.y), widgets); } } } From 7a0cbad6001dc798223b99b9b0fdca30fa364066 Mon Sep 17 00:00:00 2001 From: Gugle Date: Wed, 12 Jun 2024 13:11:23 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../emi/recipe/AnvilProcessEmiRecipe.java | 19 ++++++++++-- .../emi/stack/SelectOneEmiStack.java | 30 +++++++++++++++---- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/recipe/AnvilProcessEmiRecipe.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/recipe/AnvilProcessEmiRecipe.java index cf02cd9d0..68e0f34ce 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/recipe/AnvilProcessEmiRecipe.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/recipe/AnvilProcessEmiRecipe.java @@ -175,14 +175,29 @@ public EmiRecipeCategory getCategory() { return this.recipe.getId(); } + @SuppressWarnings("UnstableApiUsage") @Override public List getInputs() { - return this.inputs; + List in = new ArrayList<>(); + in.addAll(this.inputs); + in.addAll(this.inputBlocks); + for (EmiIngredient input : this.inputs) { + if (input instanceof ListEmiIngredient ingredients) in.addAll(ingredients.getEmiStacks()); + } + return in; } @Override public List getOutputs() { - return this.outputs; + List out = new ArrayList<>(); + out.addAll(this.outputs); + out.addAll(this.outputBlocks); + for (EmiStack output : this.outputs) { + if (output instanceof SelectOneEmiStack stack) { + out.addAll(stack.getStacks()); + } + } + return out; } @Override diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/stack/SelectOneEmiStack.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/stack/SelectOneEmiStack.java index 81308cfae..d50c86507 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/stack/SelectOneEmiStack.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/stack/SelectOneEmiStack.java @@ -7,6 +7,8 @@ import dev.dubhe.anvilcraft.data.recipe.anvil.outcome.SpawnItem; import dev.emi.emi.api.stack.EmiIngredient; import dev.emi.emi.api.stack.EmiStack; +import dev.emi.emi.screen.tooltip.EmiTooltip; +import lombok.Getter; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; @@ -19,13 +21,16 @@ import java.util.ArrayList; import java.util.List; +@Getter public class SelectOneEmiStack extends EmiStack { private static final Minecraft MINECRAFT = Minecraft.getInstance(); - private final List stacks = new ArrayList<>(); + private final List stacks = new ArrayList<>(); + private float maxChance = 0; - private SelectOneEmiStack(@NotNull List stacks) { - for (EmiIngredient stack : stacks) { + private SelectOneEmiStack(@NotNull List stacks) { + for (EmiStack stack : stacks) { this.stacks.add(stack.copy()); + this.maxChance += stack.getChance(); } } @@ -38,6 +43,9 @@ private SelectOneEmiStack(@NotNull SelectOne selectOne) { this.stacks.add(BlockStateEmiStack.of(block.getResult()).setChance((float) outcome.getChance())); } } + for (EmiStack stack : this.stacks) { + this.maxChance += stack.getChance(); + } } public static @NotNull SelectOneEmiStack of(@NotNull SelectOne selectOne) { @@ -90,6 +98,14 @@ public Object getKey() { return "SelectOne$" + this.stacks.hashCode(); } + @Override + public boolean isEqual(EmiStack stack) { + for (EmiStack stack1 : this.stacks) { + if (stack1.isEqual(stack)) return true; + } + return super.isEqual(stack); + } + @Override public ResourceLocation getId() { return AnvilCraft.of("select_one_" + this.stacks.hashCode()); @@ -97,9 +113,13 @@ public ResourceLocation getId() { @Override public List getTooltip() { + List list; EmiIngredient ingredient = this.get(); - if (ingredient != null) return ingredient.getTooltip(); - return List.of(); + if (ingredient != null) { + list = ingredient.getTooltip(); + list.add(EmiTooltip.chance("produce", ingredient.getChance() / this.maxChance)); + } else list = List.of(); + return list; } @Override From 5d237e29439d00c0b855f2a69f0fcbc4530a6410 Mon Sep 17 00:00:00 2001 From: Gugle Date: Wed, 12 Jun 2024 13:31:23 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E4=BE=A7=E8=BE=B9?= =?UTF-8?q?=E6=A0=8F=E7=9A=84=E6=96=B9=E5=9D=97=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../integration/emi/AnvilCraftEmiPlugin.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/AnvilCraftEmiPlugin.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/AnvilCraftEmiPlugin.java index d9f3bfe78..4f95703ed 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/AnvilCraftEmiPlugin.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/emi/AnvilCraftEmiPlugin.java @@ -3,23 +3,17 @@ import dev.dubhe.anvilcraft.api.recipe.AnvilRecipeManager; import dev.dubhe.anvilcraft.init.ModBlocks; import dev.dubhe.anvilcraft.integration.emi.recipe.AnvilProcessEmiRecipe; -import dev.dubhe.anvilcraft.integration.emi.stack.BlockStateEmiStack; import dev.emi.emi.api.EmiEntrypoint; import dev.emi.emi.api.EmiPlugin; import dev.emi.emi.api.EmiRegistry; import dev.emi.emi.api.stack.EmiStack; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; +import org.jetbrains.annotations.NotNull; @EmiEntrypoint public class AnvilCraftEmiPlugin implements EmiPlugin { @Override - public void register(EmiRegistry registry) { - for (Block block : BuiltInRegistries.BLOCK) { - EmiStack stack = BlockStateEmiStack.of(block.defaultBlockState()); - registry.addEmiStack(stack); - } + public void register(@NotNull EmiRegistry registry) { AnvilRecipeCategory.ALL.forEach(registry::addCategory); registry.addWorkstation(AnvilRecipeCategory.STAMPING, EmiStack.of(ModBlocks.STAMPING_PLATFORM.get()));