Skip to content
Open
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
  •  
  •  
  •  
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-preview.1+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
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));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ItemColorsExtender {
*/
@Overwrite
public int getColor(ItemStack item, int tintIndex) {
return item.itematic$getComponent(ItemComponentTypes.TINTED)
return item.itematic$getBehavior(ItemComponentTypes.TINTED)
.map(TintedItemComponent::tint)
.map(c -> c.color(item, tintIndex))
.orElse(ItemColor.DEFAULT_COLOR);
Expand Down
Loading