Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ repositories {
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.

maven { url 'https://jitpack.io' }
}

dependencies {
Expand All @@ -22,6 +24,9 @@ dependencies {

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation "com.github.Chocohead:Fabric-ASM:v2.3"
include "com.github.Chocohead:Fabric-ASM:v2.3"
}

processResources {
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.1
yarn_mappings=1.21.1+build.3
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.2
loader_version=0.18.4

# Mod Properties
mod_version = 0.4.0+1.21.1
mod_version = 0.5.0+1.21.3
maven_group = net.errorcraft
archives_base_name = itematic

# Dependencies
fabric_version=0.116.7+1.21.1
fabric_version=0.114.1+1.21.3

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.errorcraft.itematic.access.client.recipebook;

import net.errorcraft.itematic.item.ItemAccess;
import net.minecraft.item.ItemStack;

import java.util.Optional;

public interface RecipeBookWidgetTabAccess {
ItemStack itematic$primaryIconItem(ItemAccess items);
Optional<ItemStack> itematic$secondaryIconItem(ItemAccess items);
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.errorcraft.itematic.client.gui.screen.ingame;

import net.errorcraft.itematic.client.gui.screen.recipebook.BrewingRecipeBookWidget;
import net.errorcraft.itematic.mixin.client.gui.screen.ingame.BrewingStandScreenAccessor;
import net.errorcraft.itematic.mixin.client.gui.screen.ingame.HandledScreenAccessor;
import net.errorcraft.itematic.screen.BrewingStandMenuDelegate;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.ScreenPos;
import net.minecraft.client.gui.screen.ingame.BrewingStandScreen;
import net.minecraft.client.gui.screen.ingame.RecipeBookScreen;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.text.Text;

public class BrewingStandScreenDelegate extends RecipeBookScreen<BrewingStandMenuDelegate> {
private final BrewingStandScreen delegate;

public BrewingStandScreenDelegate(BrewingStandMenuDelegate handler, PlayerInventory inventory, Text title, BrewingStandScreen delegate) {
super(handler, new BrewingRecipeBookWidget(handler), inventory, title);
this.delegate = delegate;
}

@Override
@SuppressWarnings("DataFlowIssue")
protected void init() {
this.delegate.init(this.client, this.width, this.height);
super.init();
((HandledScreenAccessor) this.delegate).itematic$setX(this.x);
}

@Override
protected ScreenPos getRecipeBookButtonPos() {
return new ScreenPos(this.x + 15, this.y + 50);
}

@Override
protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) {
((BrewingStandScreenAccessor) this.delegate).itematic$drawBackground(context, delta, mouseX, mouseY);
}

@Override
protected void onRecipeBookToggled() {
((HandledScreenAccessor) this.delegate).itematic$setX(this.x);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package net.errorcraft.itematic.client.gui.screen.recipebook;

import net.errorcraft.itematic.client.recipebook.ItematicSearchRecipeBookTypes;
import net.errorcraft.itematic.mixin.client.gui.screen.recipebook.GhostRecipeAccessor;
import net.errorcraft.itematic.recipe.book.ItematicRecipeBookCategories;
import net.errorcraft.itematic.recipe.display.BrewingRecipeDisplay;
import net.errorcraft.itematic.screen.BrewingStandMenuDelegate;
import net.minecraft.client.gui.screen.ButtonTextures;
import net.minecraft.client.gui.screen.recipebook.GhostRecipe;
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
import net.minecraft.client.gui.screen.recipebook.RecipeResultCollection;
import net.minecraft.item.Items;
import net.minecraft.recipe.RecipeFinder;
import net.minecraft.recipe.display.RecipeDisplay;
import net.minecraft.screen.slot.Slot;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.context.ContextParameterMap;

import java.util.List;

public class BrewingRecipeBookWidget extends RecipeBookWidget<BrewingStandMenuDelegate> {
private static final ButtonTextures TEXTURES = new ButtonTextures(
Identifier.ofVanilla("recipe_book/brewing_stand_filter_enabled"),
Identifier.ofVanilla("recipe_book/brewing_stand_filter_disabled"),
Identifier.ofVanilla("recipe_book/brewing_stand_filter_enabled_highlighted"),
Identifier.ofVanilla("recipe_book/brewing_stand_filter_disabled_highlighted")
);
private static final Text TOGGLE_BREWABLE_TEXT = Text.translatable("gui.recipebook.toggleRecipes.brewable");
private static final List<Tab> TABS = List.of(
new Tab(ItematicSearchRecipeBookTypes.BREWING),
// Item references are intended as key conversion is handled by a mixin
new Tab(Items.NETHER_WART, Items.MAGMA_CREAM, ItematicRecipeBookCategories.BREWING_MODIFY),
new Tab(Items.SPLASH_POTION, Items.LINGERING_POTION, ItematicRecipeBookCategories.BREWING_AMPLIFY)
);

public BrewingRecipeBookWidget(BrewingStandMenuDelegate menu) {
super(menu, TABS);
}

@Override
protected void setBookButtonTexture() {
this.toggleCraftableButton.setTextures(TEXTURES);
}

@Override
protected boolean isValid(Slot slot) {
return false;
}

@Override
protected void populateRecipes(RecipeResultCollection recipeResultCollection, RecipeFinder recipeFinder) {
recipeResultCollection.populateRecipes(recipeFinder, display -> display instanceof BrewingRecipeDisplay);
}

@Override
protected Text getToggleCraftableButtonText() {
return TOGGLE_BREWABLE_TEXT;
}

@Override
protected void showGhostRecipe(GhostRecipe ghostRecipe, RecipeDisplay display, ContextParameterMap context) {
if (display instanceof BrewingRecipeDisplay brewingRecipeDisplay) {
((GhostRecipeAccessor) ghostRecipe).itematic$addInputs(this.craftingScreenHandler.firstInputSlot(), context, brewingRecipeDisplay.base());
((GhostRecipeAccessor) ghostRecipe).itematic$addInputs(this.craftingScreenHandler.ingredientSlot(), context, brewingRecipeDisplay.reagent());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.dynamic.Codecs;
import net.minecraft.util.math.ColorHelper;

import java.util.List;

Expand All @@ -26,15 +27,17 @@ public Identifier progressTexture(ItemStack stack) {
if (progress <= 0.0f) {
return this.textures.getFirst();
}

if (progress >= 1.0f) {
return this.textures.getLast();
}

int index = (int) (progress * (this.textures.size() - 1));
return this.textures.get(index);
}

public int color(ItemStack stack) {
float progress = this.progress.get(stack);
return this.color.get(progress);
return ColorHelper.fullAlpha(this.color.get(progress));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceReloader;
import net.minecraft.util.Identifier;
import net.minecraft.util.profiler.Profiler;
import org.slf4j.Logger;

import java.io.BufferedReader;
Expand All @@ -25,7 +24,7 @@ public class ItemBarStyleLoader implements ResourceReloader {
private final Map<Identifier, ItemBarStyle> styles = new HashMap<>();

@Override
public CompletableFuture<Void> reload(Synchronizer synchronizer, ResourceManager manager, Profiler prepareProfiler, Profiler applyProfiler, Executor prepareExecutor, Executor applyExecutor) {
public CompletableFuture<Void> reload(Synchronizer synchronizer, ResourceManager manager, Executor prepareExecutor, Executor applyExecutor) {
return CompletableFuture.supplyAsync(() -> FINDER.findResources(manager), prepareExecutor)
.thenCompose(synchronizer::whenPrepared)
.thenAcceptAsync(this::apply, applyExecutor);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.errorcraft.itematic.client.item.bar;

import net.errorcraft.itematic.client.item.bar.color.provider.ConstantColorProvider;
import net.errorcraft.itematic.client.item.bar.color.provider.FirstToPassConditionColorProvider;
import net.errorcraft.itematic.client.item.bar.color.provider.HueShiftColorProvider;
import net.errorcraft.itematic.client.item.bar.progress.ProgressProvider;
import net.errorcraft.itematic.item.ItemBarStyleKeys;
Expand Down Expand Up @@ -36,7 +36,13 @@ public static void bootstrap(BiConsumer<Identifier, ItemBarStyle> provider) {
));
provider.accept(ItemBarStyleKeys.BUNDLE, new ItemBarStyle(
ProgressProvider.ITEM_HOLDER_OCCUPANCY,
new ConstantColorProvider(BundleItemAccessor.itemBarColor()),
FirstToPassConditionColorProvider.of(
BundleItemAccessor.itemBarColor(),
FirstToPassConditionColorProvider.Entry.of(
BundleItemAccessor.fullItemBarColor(),
1.0f
)
),
List.of(
Identifier.ofVanilla("item_bar/progress/0"),
Identifier.ofVanilla("item_bar/progress/0"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.mojang.serialization.Codec;

public interface ColorProvider {
Codec<ColorProvider> CODEC = ColorProviderTypes.CODEC.dispatch(ColorProvider::type, ColorProviderType::codec);
Codec<ColorProvider> CODEC = Codec.lazyInitialized(() -> ColorProviderTypes.CODEC.dispatch(ColorProvider::type, ColorProviderType::codec));

ColorProviderType<?> type();
int get(float progress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public class ColorProviderTypeKeys {
public static final Identifier CONSTANT = of("constant");
public static final Identifier HUE_SHIFT = of("hue_shift");
public static final Identifier FIRST_TO_PASS_CONDITION = of("first_to_pass_condition");

private ColorProviderTypeKeys() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mojang.serialization.DataResult;
import com.mojang.serialization.MapCodec;
import net.errorcraft.itematic.client.item.bar.color.provider.ConstantColorProvider;
import net.errorcraft.itematic.client.item.bar.color.provider.FirstToPassConditionColorProvider;
import net.errorcraft.itematic.client.item.bar.color.provider.HueShiftColorProvider;
import net.minecraft.util.Identifier;

Expand All @@ -19,6 +20,7 @@ public class ColorProviderTypes {

public static final ColorProviderType<ConstantColorProvider> CONSTANT = register(ColorProviderTypeKeys.CONSTANT, ConstantColorProvider.CODEC);
public static final ColorProviderType<HueShiftColorProvider> HUE_SHIFT = register(ColorProviderTypeKeys.HUE_SHIFT, HueShiftColorProvider.CODEC);
public static final ColorProviderType<FirstToPassConditionColorProvider> FIRST_TO_PASS_CONDITION = register(ColorProviderTypeKeys.FIRST_TO_PASS_CONDITION, FirstToPassConditionColorProvider.CODEC);

private ColorProviderTypes() {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package net.errorcraft.itematic.client.item.bar.color.provider;

import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.errorcraft.itematic.client.item.bar.color.ColorProvider;
import net.errorcraft.itematic.client.item.bar.color.ColorProviderType;
import net.errorcraft.itematic.client.item.bar.color.ColorProviderTypes;
import net.errorcraft.itematic.predicate.NumberRangeUtil;
import net.minecraft.util.dynamic.Codecs;

import java.util.List;

public record FirstToPassConditionColorProvider(List<Entry> entries, ColorProvider fallback) implements ColorProvider {
public static final MapCodec<FirstToPassConditionColorProvider> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
Codecs.nonEmptyList(Entry.CODEC.listOf()).fieldOf("entries").forGetter(FirstToPassConditionColorProvider::entries),
ColorProvider.CODEC.fieldOf("fallback").forGetter(FirstToPassConditionColorProvider::fallback)
).apply(instance, FirstToPassConditionColorProvider::new));

public static FirstToPassConditionColorProvider of(int fallback, Entry... entries) {
return new FirstToPassConditionColorProvider(List.of(entries), new ConstantColorProvider(fallback));
}

@Override
public ColorProviderType<?> type() {
return ColorProviderTypes.FIRST_TO_PASS_CONDITION;
}

@Override
public int get(float progress) {
for (Entry entry : this.entries) {
if (entry.condition.test(progress)) {
return entry.color.get(progress);
}
}

return this.fallback.get(progress);
}

public record Entry(ColorProvider color, Condition condition) {
public static final Codec<Entry> CODEC = RecordCodecBuilder.create(instance -> instance.group(
ColorProvider.CODEC.fieldOf("color").forGetter(Entry::color),
Condition.CODEC.fieldOf("condition").forGetter(Entry::condition)
).apply(instance, Entry::new));

public static Entry of(int color, float progress) {
return new Entry(new ConstantColorProvider(color), new Condition(NumberRangeUtil.FloatRange.exactly(progress)));
}
}

public record Condition(NumberRangeUtil.FloatRange progress) {
public static final Codec<Condition> CODEC = RecordCodecBuilder.create(instance -> instance.group(
NumberRangeUtil.FloatRange.CODEC.fieldOf("progress").forGetter(Condition::progress)
).apply(instance, Condition::new));

public boolean test(float progress) {
return this.progress.test(progress);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public float get(ItemStack stack) {
}

private static Optional<Fraction> occupancy(ItemStack stack) {
return stack.itematic$getComponent(ItemComponentTypes.ITEM_HOLDER)
return stack.itematic$getBehavior(ItemComponentTypes.ITEM_HOLDER)
.map(c -> c.occupancy(stack));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package net.errorcraft.itematic.client.recipebook;

import com.chocohead.mm.api.ClassTinkerers;
import net.minecraft.client.recipebook.RecipeBookType;

public class ItematicSearchRecipeBookTypes {
public static final RecipeBookType BREWING = ClassTinkerers.getEnum(RecipeBookType.class, "ITEMATIC$BREWING");

private ItematicSearchRecipeBookTypes() {}
}
Loading