Skip to content

Commit

Permalink
Clean up some tla stuff and depend on our own textures for recipe dec…
Browse files Browse the repository at this point in the history
…orations
  • Loading branch information
Sollace committed Oct 11, 2024
1 parent a540856 commit 017f217
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<SpellbookRecipe> recipe;

protected final List<TraitedTlaIngredient> inputs = new ArrayList<>();
Expand All @@ -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));
Expand Down Expand Up @@ -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<HexagonalCraftingGrid.Slot> grid = new ArrayList<>();
List<HexagonalCraftingGrid.Slot> gem = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TraitEntry> trait, TlaIngredient ingredient) {
Expand All @@ -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) -> {
Expand All @@ -53,14 +55,4 @@ public void buildGui(TlaIngredient ingredientOverride, HexagonalCraftingGrid.Slo
}

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

0 comments on commit 017f217

Please sign in to comment.