Clean up some tla stuff and depend on our own textures for recipe decorations

This commit is contained in:
Sollace 2024-10-11 11:23:41 +01:00
parent a540856f5f
commit 017f2176d5
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
5 changed files with 50 additions and 43 deletions

View file

@ -1,11 +1,19 @@
package com.minelittlepony.unicopia.compat.tla; package com.minelittlepony.unicopia.compat.tla;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.item.UItems; 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.PluginContext;
import io.github.mattidragon.tlaapi.api.plugin.TlaApiPlugin; import io.github.mattidragon.tlaapi.api.plugin.TlaApiPlugin;
import io.github.mattidragon.tlaapi.api.recipe.TlaStackComparison; import io.github.mattidragon.tlaapi.api.recipe.TlaStackComparison;
import net.minecraft.util.Identifier;
public class Main implements TlaApiPlugin { 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 @Override
public void register(PluginContext registry) { public void register(PluginContext registry) {
RecipeCategory.bootstrap(registry); RecipeCategory.bootstrap(registry);

View file

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

View file

@ -9,11 +9,9 @@ import java.util.stream.Stream;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.google.common.base.Suppliers; 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.SpellDuplicatingRecipe;
import com.minelittlepony.unicopia.ability.magic.spell.crafting.SpellEnhancingRecipe; 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.crafting.SpellbookRecipe;
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait; import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
import com.minelittlepony.unicopia.client.gui.spellbook.SpellbookScreen; import com.minelittlepony.unicopia.client.gui.spellbook.SpellbookScreen;
import com.minelittlepony.unicopia.container.inventory.HexagonalCraftingGrid; import com.minelittlepony.unicopia.container.inventory.HexagonalCraftingGrid;
@ -30,9 +28,6 @@ import net.minecraft.recipe.RecipeEntry;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
class SpellbookTlaRecipe implements TlaRecipe, SpellbookRecipe.CraftingTreeBuilder { 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<SpellbookRecipe> recipe; private final RecipeEntry<SpellbookRecipe> recipe;
protected final List<TraitedTlaIngredient> inputs = new ArrayList<>(); protected final List<TraitedTlaIngredient> inputs = new ArrayList<>();
@ -46,27 +41,8 @@ class SpellbookTlaRecipe implements TlaRecipe, SpellbookRecipe.CraftingTreeBuild
return Stream.of(new SpellDuplicatingTlaRecipe(recipe)); return Stream.of(new SpellDuplicatingTlaRecipe(recipe));
} }
if (recipe.value() instanceof SpellEnhancingRecipe enhancingRecipe) { if (recipe.value() instanceof SpellEnhancingRecipe) {
return Trait.all().stream().map(trait -> { return Trait.all().stream().map(trait -> new SpellEnhancingTlaRecipe(recipe, 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;
}
};
});
} }
return Stream.of((TlaRecipe)new SpellbookTlaRecipe(recipe)); return Stream.of((TlaRecipe)new SpellbookTlaRecipe(recipe));
@ -114,7 +90,7 @@ class SpellbookTlaRecipe implements TlaRecipe, SpellbookRecipe.CraftingTreeBuild
.regionSize(128, 128) .regionSize(128, 128)
.textureSize(512, 256) .textureSize(512, 256)
.build(), 0, 0); .build(), 0, 0);
builder.addTexture(EMPTY_ARROW, 85, 30); builder.addTexture(Main.EMPTY_ARROW, 85, 30);
List<HexagonalCraftingGrid.Slot> grid = new ArrayList<>(); List<HexagonalCraftingGrid.Slot> grid = new ArrayList<>();
List<HexagonalCraftingGrid.Slot> gem = new ArrayList<>(); List<HexagonalCraftingGrid.Slot> gem = new ArrayList<>();

View file

@ -30,8 +30,6 @@ import net.minecraft.util.Util;
import net.minecraft.util.math.RotationAxis; import net.minecraft.util.math.RotationAxis;
public class StructureInteractionTlaRecipe implements TlaRecipe { 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 RecipeCategory category;
private final Identifier id; private final Identifier id;
private final Schematic schematic; private final Schematic schematic;
@ -137,7 +135,7 @@ public class StructureInteractionTlaRecipe implements TlaRecipe {
row += 20; row += 20;
} }
if (i > 0) { if (i > 0) {
widgets.addTexture(PLUS, x + 3, y + 53 + row); widgets.addTexture(Main.PLUS, x + 3, y + 53 + row);
x += 20; x += 20;
} }
var slot = widgets.addSlot(allInputs.get(i), x, y + 50 + row); var slot = widgets.addSlot(allInputs.get(i), x, y + 50 + row);

View file

@ -11,9 +11,7 @@ import com.minelittlepony.unicopia.container.inventory.HexagonalCraftingGrid;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import io.github.mattidragon.tlaapi.api.gui.GuiBuilder; 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.api.recipe.TlaIngredient;
import io.github.mattidragon.tlaapi.impl.SimpleCustomTlaWidget;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
public record TraitedTlaIngredient(Optional<TraitEntry> trait, TlaIngredient ingredient) { public record TraitedTlaIngredient(Optional<TraitEntry> trait, TlaIngredient ingredient) {
@ -37,7 +35,11 @@ public record TraitedTlaIngredient(Optional<TraitEntry> trait, TlaIngredient ing
} }
public void buildGui(TlaIngredient ingredientOverride, 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(); builder.addSlot(ingredientOverride, slot.left(), slot.top()).disableBackground();
trait.ifPresent(traitEntry -> { trait.ifPresent(traitEntry -> {
builder.addCustomWidget(slot.left(), slot.top(), 16, 16, (context, mouseX, mouseY, delta) -> { builder.addCustomWidget(slot.left(), slot.top(), 16, 16, (context, mouseX, mouseY, delta) -> {
@ -53,14 +55,4 @@ public record TraitedTlaIngredient(Optional<TraitEntry> trait, TlaIngredient ing
} }
record TraitEntry(List<Trait> traits, float amount) { } record TraitEntry(List<Trait> 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));
}
}
} }