Skip to content

Commit

Permalink
1.20.1 -> 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Jun 8, 2024
1 parent 5718fbb commit 688742e
Show file tree
Hide file tree
Showing 21 changed files with 224 additions and 221 deletions.
7 changes: 2 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ buildscript {
}
}
plugins {
id 'java-library'
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'maven-publish'
id 'com.modrinth.minotaur' version '2.+'
id 'org.ajoberstar.reckon' version '0.13.0'
}
Expand Down Expand Up @@ -55,9 +55,6 @@ dependencies {
modApi "com.minelittlepony:minelittlepony:${project.minelp_version}"
modApi "dev.emi:trinkets:${project.trinkets_version}"

modApi "com.jamieswhiteshirt:reach-entity-attributes:${project.reach_attributes_version}"
include "com.jamieswhiteshirt:reach-entity-attributes:${project.reach_attributes_version}"

modCompileOnly "com.terraformersmc:modmenu:${project.modmenu_version}"

if (project.tmi_type == 'emi') {
Expand Down
19 changes: 9 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ org.gradle.daemon=false

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.9
loader_version=0.14.21
fabric_version=0.85.0+1.20.1
minecraft_version=1.21-pre2
yarn_mappings=1.21-pre2+build.2
loader_version=0.15.11
fabric_version=0.99.4+1.21

# Mod Properties
group=com.minelittlepony
Expand All @@ -15,16 +15,15 @@ org.gradle.daemon=false
description=Adds wearable socks to Minecraft

# Publishing
minecraft_version_range=1.20.1
minecraft_version_range=1.21-pre2
modrinth_loader_type=fabric
modrinth_project_id=

# Dependencies
modmenu_version=7.0.0-beta.2
minelp_version=4.10.1+1.20
reach_attributes_version=2.3.3
trinkets_version=3.7.1
modmenu_version=11.0.0-beta.1
minelp_version=4.12.0-beta.2+1.21
trinkets_version=3.10.0

# TMI Testing
tmi_type=emi
emi_version=1.0.19+1.20.1
emi_version=1.0.29+1.20.4
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
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 removed lib/reach-entity-attributes-2.3.3.jar
Binary file not shown.
Binary file added lib/trinkets-3.10.0-sources.jar
Binary file not shown.
Binary file added lib/trinkets-3.10.0.jar
Binary file not shown.
19 changes: 19 additions & 0 deletions src/main/java/com/minelittlepony/sockies/SItemComponents.java
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());
}
}
12 changes: 3 additions & 9 deletions src/main/java/com/minelittlepony/sockies/SItemGroups.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.minelittlepony.sockies;

import com.minelittlepony.sockies.item.SockPattern;

import com.minelittlepony.sockies.item.SockColorsComponent;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.text.Text;
Expand All @@ -13,13 +11,9 @@ static void bootstrap() {
Registry.register(Registries.ITEM_GROUP, Sockies.id("socks"), FabricItemGroup.builder().entries((context, entries) -> {
SItems.ALL_SOCKS.forEach(sock -> {
sock.getPattern().getColors().forEach(colors -> {
ItemStack stack = sock.getDefaultStack();
for (int i = 0; i < colors.length; i++) {
sock.setColor(stack, i, colors[i]);
}
entries.add(stack);
entries.add(SockColorsComponent.setColors(sock.getDefaultStack(), colors));
});
});
}).icon(() -> SItems.RAINBOW_SOCKS.setColors(SItems.RAINBOW_SOCKS.getDefaultStack(), SockPattern.RAINBOW_DEFAULT)).displayName(Text.translatable("mod.sockies.name")).build());
}).icon(() -> SItems.RAINBOW_SOCKS.getDefaultStack()).displayName(Text.translatable("mod.sockies.name")).build());
}
}
6 changes: 5 additions & 1 deletion src/main/java/com/minelittlepony/sockies/SItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import com.minelittlepony.sockies.item.SockColorsComponent;
import com.minelittlepony.sockies.item.SockMaterial;
import com.minelittlepony.sockies.item.SockPattern;
import com.minelittlepony.sockies.item.SocksItem;
Expand All @@ -17,7 +18,9 @@ public interface SItems {
SocksItem PLAIN_SOCKS = register("plain_socks", new SocksItem(SockMaterial.WOOL, SockPattern.PLAIN, new Item.Settings()));
SocksItem STRIPED_SOCKS = register("striped_socks", new SocksItem(SockMaterial.WOOL, SockPattern.STRIPES, new Item.Settings()));
SocksItem POLKADOT_SOCKS = register("polkadot_socks", new SocksItem(SockMaterial.WOOL, SockPattern.DOTS, new Item.Settings()));
SocksItem RAINBOW_SOCKS = register("rainbow_socks", new SocksItem(SockMaterial.WOOL, SockPattern.RAINBOWS, new Item.Settings()));
SocksItem RAINBOW_SOCKS = register("rainbow_socks", new SocksItem(SockMaterial.WOOL, SockPattern.RAINBOWS, new Item.Settings()
.component(SItemComponents.SOCK_COLORS, new SockColorsComponent(SockPattern.RAINBOW_DEFAULT, false))
));

private static <T extends Item> T register(String name, T item) {
if (item instanceof SocksItem socks) {
Expand All @@ -27,6 +30,7 @@ private static <T extends Item> T register(String name, T item) {
}

static void bootstrap() {
SItemComponents.bootstrap();
SItemGroups.bootstrap();
SRecipes.bootstrap();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/minelittlepony/sockies/Sockies.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Sockies implements ModInitializer {
public static final Logger LOGGER = LogManager.getLogger();

public static Identifier id(String name) {
return new Identifier(DEFAULT_NAMESPACE, name);
return Identifier.of(DEFAULT_NAMESPACE, name);
}

@Override
Expand Down
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.minelittlepony.sockies.STags;
import com.minelittlepony.sockies.compat.trinkets.Trinkets;
import com.minelittlepony.sockies.item.SockColorsComponent;
import com.minelittlepony.sockies.item.SockPattern;
import com.minelittlepony.sockies.item.SocksItem;

Expand All @@ -14,8 +15,8 @@
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Colors;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.ColorHelper;

public class SocksFeature<T extends LivingEntity, A extends BipedEntityModel<T>> implements AccessoryFeatureRenderer.Feature<T, A> {
private final FeatureRendererContext<T, ? extends BipedEntityModel<T>> context;
Expand All @@ -30,7 +31,7 @@ public SocksFeature(FeatureRendererContext<T, ? extends BipedEntityModel<T>> con
public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, T entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
ItemStack socks = Trinkets.getSocks(entity).findFirst().orElse(ItemStack.EMPTY);

if (socks.getItem() instanceof SocksItem socksItem && socks.isIn(STags.SOCKS)) {
if (socks.getItem() instanceof SocksItem && socks.isIn(STags.SOCKS)) {
context.getModel().copyBipedStateTo(model);
model.setVisible(false);
model.leftLeg.visible = true;
Expand All @@ -42,16 +43,12 @@ public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers,
public static void renderSocks(ItemStack socks, BipedEntityModel<?> model, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) {
if (socks.getItem() instanceof SocksItem socksItem && socks.isIn(STags.SOCKS)) {
SockPattern pattern = socksItem.getPattern();
int[] colors = SockColorsComponent.getColors(socks);

for (int i = 0; i < pattern.layers(); i++) {
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(RenderLayer.getArmorCutoutNoCull(getTexture(socksItem, pattern, i)));
int color = socksItem.getColor(socks, i);
model.render(matrices, vertexConsumer, light, OverlayTexture.DEFAULT_UV,
ColorHelper.Argb.getRed(color) / 255F,
ColorHelper.Argb.getGreen(color) / 255F,
ColorHelper.Argb.getBlue(color) / 255F,
1
);
int color = i < colors.length ? colors[i] : Colors.WHITE;
model.render(matrices, vertexConsumer, light, OverlayTexture.DEFAULT_UV, color);
}
}
}
Expand Down
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import java.util.UUID;

import com.minelittlepony.api.model.BodyPart;
import com.minelittlepony.api.model.IModel;
import com.minelittlepony.api.model.armour.ArmourLayer;
import com.minelittlepony.api.model.gear.IGear;
import com.minelittlepony.client.model.IPonyModel;
import com.minelittlepony.api.model.PonyModel;
import com.minelittlepony.api.model.gear.Gear;
import com.minelittlepony.client.model.ModelType;
import com.minelittlepony.client.model.armour.ArmourLayer;
import com.minelittlepony.client.model.armour.PonyArmourModel;
import com.minelittlepony.sockies.client.SocksFeature;
import com.minelittlepony.sockies.compat.trinkets.Trinkets;
Expand All @@ -24,13 +23,13 @@
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;

public class SocksGear implements IGear {
public class SocksGear implements Gear {
private final PonyArmourModel<LivingEntity> model = ModelType.INNER_PONY_ARMOR.createModel();

private ItemStack socks;

@Override
public boolean canRender(IModel model, Entity entity) {
public boolean canRender(PonyModel<?> model, Entity entity) {
return entity instanceof LivingEntity living && Trinkets.getSocks(living).findFirst().isPresent();
}

Expand All @@ -45,22 +44,20 @@ public <T extends Entity> Identifier getTexture(T entity, Context<T, ?> context)
}

@Override
public <M extends EntityModel<?> & IPonyModel<?>> void transform(M model, MatrixStack matrices) {
public <M extends EntityModel<?> & PonyModel<?>> void transform(M model, MatrixStack matrices) {
// noop
}

@SuppressWarnings("unchecked")
@Override
public void pose(IModel model, Entity entity, boolean rainboom, UUID interpolatorId, float move, float swing, float bodySwing, float ticks) {
if (model instanceof IPonyModel<?> lmodel) {
this.model.poseModel((LivingEntity)entity, swing, move, 0, 0, 0, EquipmentSlot.FEET, ArmourLayer.OUTER, (IPonyModel<LivingEntity>)lmodel);
}
public void pose(PonyModel<?> model, Entity entity, boolean rainboom, UUID interpolatorId, float move, float swing, float bodySwing, float ticks) {
this.model.poseModel((LivingEntity)entity, swing, move, 0, 0, 0, EquipmentSlot.FEET, ArmourLayer.OUTER, (PonyModel<LivingEntity>)model);
socks = Trinkets.getSocks((LivingEntity)entity).findFirst().orElse(ItemStack.EMPTY);
}

@Override
public void render(MatrixStack stack, VertexConsumer vertices, int overlayUv, int lightUv, float red, float green, float blue, float alpha, UUID interpolatorId) {
public void render(MatrixStack stack, VertexConsumer vertices, int overlay, int light, int color, UUID interpolatorId) {
Immediate provider = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
SocksFeature.renderSocks(socks, model, stack, provider, overlayUv);
SocksFeature.renderSocks(socks, model, stack, provider, overlay);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Stream;

import com.google.common.collect.Multimap;
Expand All @@ -12,6 +11,7 @@
import dev.emi.trinkets.api.Trinket;
import dev.emi.trinkets.api.TrinketInventory;
import dev.emi.trinkets.api.TrinketsApi;
import net.minecraft.component.EnchantmentEffectComponentTypes;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.EntityAttribute;
Expand All @@ -20,10 +20,11 @@
import net.minecraft.item.Equipment;
import net.minecraft.item.ItemStack;
import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.Identifier;

class SockTrinket implements Trinket {
private static final Identifier SHOES_SLOT = new Identifier("feet:shoes");
private static final Identifier SHOES_SLOT = Identifier.of("feet", "shoes");

public static void bootstrap() {
SItems.ALL_SOCKS.forEach(sock -> {
Expand Down Expand Up @@ -64,7 +65,7 @@ public void onEquip(ItemStack stack, SlotReference slot, LivingEntity entity) {
}

if (stack.getItem() instanceof Equipment q) {
entity.playSound(q.getEquipSound(), 1, 1);
entity.playSound(q.getEquipSound().value(), 1, 1);
}
}

Expand All @@ -75,13 +76,13 @@ public boolean canEquip(ItemStack stack, SlotReference slot, LivingEntity entity

@Override
public boolean canUnequip(ItemStack stack, SlotReference slot, LivingEntity entity) {
return !(EnchantmentHelper.hasBindingCurse(stack) && EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR.test(entity));
return !(EnchantmentHelper.hasAnyEnchantmentsWith(stack, EnchantmentEffectComponentTypes.PREVENT_ARMOR_CHANGE) && EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR.test(entity));
}

@Override
public Multimap<EntityAttribute, EntityAttributeModifier> getModifiers(ItemStack stack, SlotReference slot, LivingEntity entity, UUID uuid) {
Multimap<EntityAttribute, EntityAttributeModifier> modifiers = Trinket.super.getModifiers(stack, slot, entity, uuid);
item.getAttributeModifiers(item.getSlotType());
public Multimap<RegistryEntry<EntityAttribute>, EntityAttributeModifier> getModifiers(ItemStack stack, SlotReference slot, LivingEntity entity, Identifier slotIdentifier) {
Multimap<RegistryEntry<EntityAttribute>, EntityAttributeModifier> modifiers = Trinket.super.getModifiers(stack, slot, entity, slotIdentifier);
item.getAttributeModifiers().applyModifiers(item.getSlotType(), modifiers::put);
return modifiers;
}
}
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;
}
}
Loading

0 comments on commit 688742e

Please sign in to comment.