-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
224 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Binary file not shown.
Binary file not shown.
Binary file not shown.
19 changes: 19 additions & 0 deletions
19
src/main/java/com/minelittlepony/sockies/SItemComponents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.minelittlepony.sockies; | ||
|
||
import java.util.function.UnaryOperator; | ||
|
||
import com.minelittlepony.sockies.item.SockColorsComponent; | ||
|
||
import net.minecraft.component.ComponentType; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.Registry; | ||
|
||
public interface SItemComponents { | ||
ComponentType<SockColorsComponent> SOCK_COLORS = register("sock_colors", builder -> builder.codec(SockColorsComponent.CODEC).packetCodec(SockColorsComponent.PACKET_CODEC)); | ||
|
||
static void bootstrap() { } | ||
|
||
private static <T> ComponentType<T> register(String id, UnaryOperator<ComponentType.Builder<T>> builderOperator) { | ||
return Registry.register(Registries.DATA_COMPONENT_TYPE, Sockies.id(id), builderOperator.apply(ComponentType.builder()).build()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
src/main/java/com/minelittlepony/sockies/client/SockiesClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
package com.minelittlepony.sockies.client; | ||
|
||
import com.minelittlepony.sockies.SItems; | ||
import com.minelittlepony.sockies.item.SockColorsComponent; | ||
import com.minelittlepony.sockies.item.SocksItem; | ||
import net.fabricmc.api.ClientModInitializer; | ||
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; | ||
import net.minecraft.util.Colors; | ||
|
||
public class SockiesClient implements ClientModInitializer { | ||
@Override | ||
public void onInitializeClient() { | ||
AccessoryFeatureRenderer.register(SocksFeature::new); | ||
|
||
ColorProviderRegistry.ITEM.register((stack, i) -> { | ||
return ((SocksItem)stack.getItem()).getColor(stack, i); | ||
}, SItems.ALL_SOCKS.toArray(SocksItem[]::new)); | ||
ColorProviderRegistry.ITEM.register((stack, i) -> SockColorsComponent.getColor(stack, i, Colors.WHITE), SItems.ALL_SOCKS.toArray(SocksItem[]::new)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/main/java/com/minelittlepony/sockies/compat/minelittlepony/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
package com.minelittlepony.sockies.compat.minelittlepony; | ||
|
||
import com.minelittlepony.api.model.gear.IGear; | ||
import com.minelittlepony.api.model.gear.Gear; | ||
|
||
import net.fabricmc.api.ClientModInitializer; | ||
|
||
public class Main implements ClientModInitializer { | ||
@Override | ||
public void onInitializeClient() { | ||
IGear.register(SocksGear::new); | ||
Gear.register(SocksGear::new); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/com/minelittlepony/sockies/item/SockColorsComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.minelittlepony.sockies.item; | ||
|
||
import java.util.stream.IntStream; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.minelittlepony.sockies.SItemComponents; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import it.unimi.dsi.fastutil.ints.IntArrayList; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.network.codec.PacketCodec; | ||
import net.minecraft.network.codec.PacketCodecs; | ||
|
||
public record SockColorsComponent(int[] colors, boolean showInTooltip) { | ||
private static final int[] DEFAULT_COLORS = new int[0]; | ||
public static final Codec<SockColorsComponent> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
Codec.INT_STREAM.xmap(IntStream::toArray, IntStream::of).fieldOf("colors").forGetter(SockColorsComponent::colors), | ||
Codec.BOOL.fieldOf("show_in_tooltip").forGetter(SockColorsComponent::showInTooltip) | ||
).apply(instance, SockColorsComponent::new)); | ||
public static final PacketCodec<ByteBuf, SockColorsComponent> PACKET_CODEC = PacketCodec.tuple( | ||
PacketCodecs.INTEGER.collect(PacketCodecs.toCollection(IntArrayList::new)).xmap(l -> l.toIntArray(), IntArrayList::new), SockColorsComponent::colors, | ||
PacketCodecs.BOOL, SockColorsComponent::showInTooltip, | ||
SockColorsComponent::new | ||
); | ||
|
||
public static int[] getColors(ItemStack stack) { | ||
@Nullable | ||
SockColorsComponent component = stack.get(SItemComponents.SOCK_COLORS); | ||
return component == null ? DEFAULT_COLORS : component.colors(); | ||
} | ||
|
||
public static int getColor(ItemStack stack, int index, int fallback) { | ||
@Nullable | ||
SockColorsComponent component = stack.get(SItemComponents.SOCK_COLORS); | ||
if (component == null || component.colors().length <= index) { | ||
return fallback; | ||
} | ||
return component.colors()[index]; | ||
} | ||
|
||
public static ItemStack setColors(ItemStack stack, int[] colors) { | ||
stack.set(SItemComponents.SOCK_COLORS, new SockColorsComponent(colors, false)); | ||
return stack; | ||
} | ||
} |
Oops, something went wrong.