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..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())); @@ -103,6 +97,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..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 @@ -227,13 +242,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 +275,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 +291,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); } } } 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..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,23 +7,30 @@ 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; 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; +@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(); } } @@ -36,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) { @@ -47,11 +57,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,16 +79,49 @@ 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(); } + @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()); } + @Override + public List getTooltip() { + List list; + EmiIngredient ingredient = this.get(); + if (ingredient != null) { + list = ingredient.getTooltip(); + list.add(EmiTooltip.chance("produce", ingredient.getChance() / this.maxChance)); + } else list = List.of(); + return list; + } + @Override public List getTooltipText() { return List.of();