From 017f2176d5a565ec0823f6971894ed80cc063525 Mon Sep 17 00:00:00 2001 From: Sollace Date: Fri, 11 Oct 2024 11:23:41 +0100 Subject: [PATCH] Clean up some tla stuff and depend on our own textures for recipe decorations --- .../unicopia/compat/tla/Main.java | 8 +++++ .../compat/tla/SpellEnhancingTlaRecipe.java | 33 +++++++++++++++++++ .../compat/tla/SpellbookTlaRecipe.java | 30 ++--------------- .../tla/StructureInteractionTlaRecipe.java | 4 +-- .../compat/tla/TraitedTlaIngredient.java | 18 +++------- 5 files changed, 50 insertions(+), 43 deletions(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/compat/tla/SpellEnhancingTlaRecipe.java diff --git a/src/main/java/com/minelittlepony/unicopia/compat/tla/Main.java b/src/main/java/com/minelittlepony/unicopia/compat/tla/Main.java index ed638e3e5..46b1f3983 100644 --- a/src/main/java/com/minelittlepony/unicopia/compat/tla/Main.java +++ b/src/main/java/com/minelittlepony/unicopia/compat/tla/Main.java @@ -1,11 +1,19 @@ package com.minelittlepony.unicopia.compat.tla; +import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.item.UItems; + +import io.github.mattidragon.tlaapi.api.gui.TextureConfig; import io.github.mattidragon.tlaapi.api.plugin.PluginContext; import io.github.mattidragon.tlaapi.api.plugin.TlaApiPlugin; import io.github.mattidragon.tlaapi.api.recipe.TlaStackComparison; +import net.minecraft.util.Identifier; public class Main implements TlaApiPlugin { + static final Identifier WIDGETS = Unicopia.id("textures/gui/widgets.png"); + static final TextureConfig EMPTY_ARROW = TextureConfig.builder().texture(WIDGETS).uv(44, 0).size(24, 17).build(); + static final TextureConfig PLUS = TextureConfig.builder().texture(WIDGETS).size(13, 13).uv(82, 0).build(); + @Override public void register(PluginContext registry) { RecipeCategory.bootstrap(registry); diff --git a/src/main/java/com/minelittlepony/unicopia/compat/tla/SpellEnhancingTlaRecipe.java b/src/main/java/com/minelittlepony/unicopia/compat/tla/SpellEnhancingTlaRecipe.java new file mode 100644 index 000000000..bdd629424 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/compat/tla/SpellEnhancingTlaRecipe.java @@ -0,0 +1,33 @@ +package com.minelittlepony.unicopia.compat.tla; + +import java.util.Arrays; + +import com.minelittlepony.unicopia.ability.magic.spell.crafting.SpellEnhancingRecipe; +import com.minelittlepony.unicopia.ability.magic.spell.crafting.SpellbookRecipe; +import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; +import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait; + +import io.github.mattidragon.tlaapi.api.recipe.TlaStack; +import net.minecraft.recipe.RecipeEntry; +import net.minecraft.util.Identifier; + +class SpellEnhancingTlaRecipe extends SpellbookTlaRecipe { + + private final Identifier id; + + public SpellEnhancingTlaRecipe(RecipeEntry recipe, Trait trait) { + super(recipe); + id = recipe.id().withPath(p -> p + "/" + trait.getId().getPath()); + input(trait); + getOutputs().addAll( + Arrays.stream(((SpellEnhancingRecipe)recipe.value()).getBaseMaterial().getMatchingStacks()) + .map(stack -> TlaStack.of(SpellTraits.of(stack).add(new SpellTraits.Builder().with(trait, 1).build()).applyTo(stack))) + .toList() + ); + } + + @Override + public Identifier getId() { + return id; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/compat/tla/SpellbookTlaRecipe.java b/src/main/java/com/minelittlepony/unicopia/compat/tla/SpellbookTlaRecipe.java index 03445232a..9b2a99098 100644 --- a/src/main/java/com/minelittlepony/unicopia/compat/tla/SpellbookTlaRecipe.java +++ b/src/main/java/com/minelittlepony/unicopia/compat/tla/SpellbookTlaRecipe.java @@ -9,11 +9,9 @@ import org.jetbrains.annotations.Nullable; import com.google.common.base.Suppliers; -import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.ability.magic.spell.crafting.SpellDuplicatingRecipe; import com.minelittlepony.unicopia.ability.magic.spell.crafting.SpellEnhancingRecipe; import com.minelittlepony.unicopia.ability.magic.spell.crafting.SpellbookRecipe; -import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait; import com.minelittlepony.unicopia.client.gui.spellbook.SpellbookScreen; import com.minelittlepony.unicopia.container.inventory.HexagonalCraftingGrid; @@ -30,9 +28,6 @@ import net.minecraft.util.Identifier; class SpellbookTlaRecipe implements TlaRecipe, SpellbookRecipe.CraftingTreeBuilder { - static final Identifier WIDGETS = Unicopia.id("textures/gui/widgets.png"); - static final TextureConfig EMPTY_ARROW = TextureConfig.builder().texture(WIDGETS).uv(44, 0).size(24, 17).build(); - private final RecipeEntry recipe; protected final List inputs = new ArrayList<>(); @@ -46,27 +41,8 @@ static void generate(RecipeCategory category, PluginContext context) { return Stream.of(new SpellDuplicatingTlaRecipe(recipe)); } - if (recipe.value() instanceof SpellEnhancingRecipe enhancingRecipe) { - return Trait.all().stream().map(trait -> { - return new SpellDuplicatingTlaRecipe(recipe) { - private final Identifier id = recipe.id().withPath(p -> p + "/" + trait.getId().getPath()); - - { - input(trait); - getOutputs().addAll( - Arrays.stream(enhancingRecipe.getBaseMaterial().getMatchingStacks()) - .map(stack -> TlaStack.of(SpellTraits.of(stack).add(new SpellTraits.Builder().with(trait, 1).build()).applyTo(stack))) - .toList() - ); - } - - @Nullable - @Override - public Identifier getId() { - return id; - } - }; - }); + if (recipe.value() instanceof SpellEnhancingRecipe) { + return Trait.all().stream().map(trait -> new SpellEnhancingTlaRecipe(recipe, trait)); } return Stream.of((TlaRecipe)new SpellbookTlaRecipe(recipe)); @@ -114,7 +90,7 @@ public void buildGui(GuiBuilder builder) { .regionSize(128, 128) .textureSize(512, 256) .build(), 0, 0); - builder.addTexture(EMPTY_ARROW, 85, 30); + builder.addTexture(Main.EMPTY_ARROW, 85, 30); List grid = new ArrayList<>(); List gem = new ArrayList<>(); diff --git a/src/main/java/com/minelittlepony/unicopia/compat/tla/StructureInteractionTlaRecipe.java b/src/main/java/com/minelittlepony/unicopia/compat/tla/StructureInteractionTlaRecipe.java index 634543a48..41d388ec1 100644 --- a/src/main/java/com/minelittlepony/unicopia/compat/tla/StructureInteractionTlaRecipe.java +++ b/src/main/java/com/minelittlepony/unicopia/compat/tla/StructureInteractionTlaRecipe.java @@ -30,8 +30,6 @@ import net.minecraft.util.math.RotationAxis; public class StructureInteractionTlaRecipe implements TlaRecipe { - static final TextureConfig PLUS = TextureConfig.builder().texture(Identifier.of("emi", "textures/gui/widgets.png")).size(13, 13).uv(82, 0).build(); - private final RecipeCategory category; private final Identifier id; private final Schematic schematic; @@ -137,7 +135,7 @@ public void buildGui(GuiBuilder widgets) { row += 20; } if (i > 0) { - widgets.addTexture(PLUS, x + 3, y + 53 + row); + widgets.addTexture(Main.PLUS, x + 3, y + 53 + row); x += 20; } var slot = widgets.addSlot(allInputs.get(i), x, y + 50 + row); diff --git a/src/main/java/com/minelittlepony/unicopia/compat/tla/TraitedTlaIngredient.java b/src/main/java/com/minelittlepony/unicopia/compat/tla/TraitedTlaIngredient.java index e44eb9d81..04eb01637 100644 --- a/src/main/java/com/minelittlepony/unicopia/compat/tla/TraitedTlaIngredient.java +++ b/src/main/java/com/minelittlepony/unicopia/compat/tla/TraitedTlaIngredient.java @@ -11,9 +11,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import io.github.mattidragon.tlaapi.api.gui.GuiBuilder; -import io.github.mattidragon.tlaapi.api.gui.TlaBounds; import io.github.mattidragon.tlaapi.api.recipe.TlaIngredient; -import io.github.mattidragon.tlaapi.impl.SimpleCustomTlaWidget; import net.minecraft.client.MinecraftClient; public record TraitedTlaIngredient(Optional trait, TlaIngredient ingredient) { @@ -37,7 +35,11 @@ public void buildGui(HexagonalCraftingGrid.Slot slot, GuiBuilder builder) { } public void buildGui(TlaIngredient ingredientOverride, HexagonalCraftingGrid.Slot slot, GuiBuilder builder) { - builder.addCustomWidget(new SlotTexture(slot)); + builder.addCustomWidget(slot.left() - 7, slot.top() - 7, 32, 32, (context, mouseX, mouseY, delta) -> { + RenderSystem.enableBlend(); + context.drawTexture(SpellbookScreen.SLOT, 0, 0, 0, 0, 0, 32, 32, 32, 32); + RenderSystem.disableBlend(); + }); builder.addSlot(ingredientOverride, slot.left(), slot.top()).disableBackground(); trait.ifPresent(traitEntry -> { builder.addCustomWidget(slot.left(), slot.top(), 16, 16, (context, mouseX, mouseY, delta) -> { @@ -53,14 +55,4 @@ public void buildGui(TlaIngredient ingredientOverride, HexagonalCraftingGrid.Slo } record TraitEntry(List traits, float amount) { } - - static class SlotTexture extends SimpleCustomTlaWidget { - public SlotTexture(HexagonalCraftingGrid.Slot slot) { - super((context, mouseX, mouseY, delta) -> { - RenderSystem.enableBlend(); - context.drawTexture(SpellbookScreen.SLOT, 0, 0, 0, 0, 0, 32, 32, 32, 32); - RenderSystem.disableBlend(); - }, new TlaBounds(slot.left() - 7, slot.top() - 7, 32, 32)); - } - } }