Skip to content

Commit

Permalink
make trinkets and curios optional dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
PinkGoosik committed Jan 23, 2024
1 parent 235b50e commit 618d9f7
Show file tree
Hide file tree
Showing 17 changed files with 362 additions and 192 deletions.
6 changes: 6 additions & 0 deletions common/src/main/resources/assets/winterly/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

"modmenu.descriptionTranslation.winterly": "Winter expansion mod adding cold and sloppy stuff.",

"tip.winterly.requires_trinkets.0": "Requires Trinkets mod to be installed",
"tip.winterly.requires_trinkets.1": "in order to be wearable.",

"tip.winterly.requires_curios.0": "Requires Curios API to be installed",
"tip.winterly.requires_curios.1": "in order to be wearable.",

"item.winterly.red_candy_cane": "Red Candy Cane",
"item.winterly.green_candy_cane": "Green Candy Cane",
"item.winterly.blue_candy_cane": "Blue Candy Cane",
Expand Down
6 changes: 6 additions & 0 deletions common/src/main/resources/assets/winterly/lang/ru_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

"modmenu.descriptionTranslation.winterly": "Мод расширяющий зиму и добавляющий праздничные предметы.",

"tip.winterly.requires_trinkets.0": "Для ношения требуется",
"tip.winterly.requires_trinkets.1": "установка мода Trinkets.",

"tip.winterly.requires_curios.0": "Для ношения требуется",
"tip.winterly.requires_curios.1": "установка мода Curios API.",

"item.winterly.red_candy_cane": "Красный леденец",
"item.winterly.green_candy_cane": "Зеленый леденец",
"item.winterly.blue_candy_cane": "Синий леденец",
Expand Down
6 changes: 6 additions & 0 deletions common/src/main/resources/assets/winterly/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

"modmenu.descriptionTranslation.winterly": "Winter expansion mod adding cold and sloppy stuff.",

"tip.winterly.requires_trinkets.0": "Requires Trinkets mod to be installed",
"tip.winterly.requires_trinkets.1": "in order to be wearable.",

"tip.winterly.requires_curios.0": "Requires Curios API to be installed",
"tip.winterly.requires_curios.1": "in order to be wearable.",

"item.winterly.red_candy_cane": "红色条纹拐杖糖",
"item.winterly.green_candy_cane": "绿色条纹拐杖糖",
"item.winterly.blue_candy_cane": "蓝色条纹拐杖糖",
Expand Down
4 changes: 2 additions & 2 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ dependencies {
modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}"
// Remove the next line if you don't want to depend on the API
//modApi "dev.architectury:architectury-fabric:${rootProject.architectury_version}"

modImplementation "dev.emi:trinkets:${project.trinkets_version}"
modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-base:${project.cca_version}"
modImplementation include("dev.onyxstudios.cardinal-components-api:cardinal-components-base:${project.cca_version}")
modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${project.cca_version}"
modImplementation include("dev.onyxstudios.cardinal-components-api:cardinal-components-world:${project.cca_version}")
modApi "io.wispforest:owo-lib:${project.owo_lib}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package winterly.fabric.client;

import dev.emi.trinkets.api.client.TrinketRenderer;
import dev.emi.trinkets.api.client.TrinketRendererRegistry;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.rendering.v1.LivingEntityFeatureRendererRegistrationCallback;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.DrownedRenderer;
import net.minecraft.client.renderer.entity.SkeletonRenderer;
Expand All @@ -15,6 +14,9 @@
import winterly.client.model.ScarfModel;
import winterly.client.render.DecorationFeatureRenderer;
import winterly.client.render.MobDecorationRenderers;
import winterly.fabric.compat.WinterlyTrinketsIntegration;
import winterly.item.CommonSantaHatItem;
import winterly.item.CommonScarfItem;
import winterly.registry.CommonWinterlyBlocks;
import winterly.registry.CommonWinterlyItems;

Expand Down Expand Up @@ -42,9 +44,16 @@ public void onInitializeClient() {
map.putBlock(CommonWinterlyBlocks.ICICLE_PANE, RenderType.translucent());
map.putBlock(CommonWinterlyBlocks.ICICLE_BARS, RenderType.cutout());

CommonWinterlyItems.ITEMS.forEach((id, item) -> {
if(item instanceof TrinketRenderer renderer) TrinketRendererRegistry.registerRenderer(item, renderer);
});
if(FabricLoader.getInstance().isModLoaded("trinkets")) {
CommonWinterlyItems.ITEMS.forEach((id, item) -> {
if(item instanceof CommonScarfItem scarf) {
WinterlyTrinketsIntegration.registerScarfRenderer(scarf);
}
if(item instanceof CommonSantaHatItem hat) {
WinterlyTrinketsIntegration.registerSantaHatRenderer(hat);
}
});
}

LivingEntityFeatureRendererRegistrationCallback.EVENT.register((entityType, entityRenderer, registrationHelper, context) -> {
if(entityRenderer instanceof ZombieRenderer renderer) {
Expand All @@ -57,7 +66,6 @@ public void onInitializeClient() {
registrationHelper.register(new DecorationFeatureRenderer<>(renderer));
}
});

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package winterly.fabric.compat;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import dev.emi.trinkets.api.SlotReference;
import dev.emi.trinkets.api.Trinket;
import dev.emi.trinkets.api.TrinketComponent;
import dev.emi.trinkets.api.TrinketsApi;
import dev.emi.trinkets.api.client.TrinketRenderer;
import dev.emi.trinkets.api.client.TrinketRendererRegistry;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.util.Tuple;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import winterly.Winterly;
import winterly.client.model.WinterlyModels;
import winterly.fabric.item.SantaHatItem;
import winterly.item.CommonSantaHatItem;
import winterly.item.CommonScarfItem;

import java.util.Optional;

public class WinterlyTrinketsIntegration {


public static void registerTrinket(Item item) {
TrinketsApi.registerTrinket(item, new Trinket() {});
}

public static boolean hasHatOn(Player player) {
Optional<TrinketComponent> component = TrinketsApi.getTrinketComponent(player);
if(component.isPresent()) {
for(Tuple<SlotReference, ItemStack> pair : component.get().getAllEquipped()) {
if(pair.getB().getItem() instanceof SantaHatItem) return true;
}
}
return false;
}

public static void registerScarfRenderer(CommonScarfItem scarf) {
TrinketRendererRegistry.registerRenderer(scarf, new TrinketRenderer() {
@Override
public void render(ItemStack stack, SlotReference slotReference, EntityModel<? extends LivingEntity> contextModel, PoseStack matrices, MultiBufferSource vertexConsumers, int light, LivingEntity entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
if(contextModel instanceof HumanoidModel<? extends LivingEntity> biped){
WinterlyModels.SCARF_MODEL.scarf.copyFrom(biped.body);
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(RenderType.entityCutout(Winterly.id("textures/entity/" + scarf.color + "_scarf.png")));
WinterlyModels.SCARF_MODEL.renderToBuffer(matrices, vertexConsumer, light, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
}
}
});
}

public static void registerSantaHatRenderer(CommonSantaHatItem hat) {
TrinketRendererRegistry.registerRenderer(hat, new TrinketRenderer() {
@Override
public void render(ItemStack stack, SlotReference slotReference, EntityModel<? extends LivingEntity> contextModel, PoseStack matrices, MultiBufferSource vertexConsumers, int light, LivingEntity entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
if(contextModel instanceof HumanoidModel<? extends LivingEntity> biped) {
WinterlyModels.SANTA_HAT_MODEL.hat.copyFrom(biped.head);
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(RenderType.entityCutout(Winterly.id("textures/entity/" + hat.color + "_santa_hat.png")));
WinterlyModels.SANTA_HAT_MODEL.renderToBuffer(matrices, vertexConsumer, light, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
}
}
});
}
}
60 changes: 35 additions & 25 deletions fabric/src/main/java/winterly/fabric/item/SantaHatItem.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,49 @@
package winterly.fabric.item;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import dev.emi.trinkets.api.SlotReference;
import dev.emi.trinkets.api.Trinket;
import dev.emi.trinkets.api.TrinketsApi;
import dev.emi.trinkets.api.client.TrinketRenderer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.world.entity.LivingEntity;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.ChatFormatting;
import net.minecraft.locale.Language;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import winterly.Winterly;
import winterly.client.model.WinterlyModels;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;
import winterly.fabric.compat.WinterlyTrinketsIntegration;
import winterly.item.CommonSantaHatItem;

public class SantaHatItem extends CommonSantaHatItem implements Trinket, TrinketRenderer {
import java.util.List;

public class SantaHatItem extends CommonSantaHatItem {

public SantaHatItem(Item.Properties settings, String color) {
super(settings, color);
TrinketsApi.registerTrinket(this, this);
if(FabricLoader.getInstance().isModLoaded("trinkets")) {
WinterlyTrinketsIntegration.registerTrinket(this);
}
}

@Environment(EnvType.CLIENT)
@Override
public void render(ItemStack stack, SlotReference slotReference, EntityModel<? extends LivingEntity> contextModel, PoseStack matrices, MultiBufferSource vertexConsumers, int light, LivingEntity entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
if(contextModel instanceof HumanoidModel<? extends LivingEntity> biped) {
WinterlyModels.SANTA_HAT_MODEL.hat.copyFrom(biped.head);
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(RenderType.entityCutout(Winterly.id("textures/entity/" + color + "_santa_hat.png")));
WinterlyModels.SANTA_HAT_MODEL.renderToBuffer(matrices, vertexConsumer, light, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
}
}
@Environment(EnvType.CLIENT)
@Override
public void appendHoverText(ItemStack stack, @Nullable Level world, List<Component> tooltip, TooltipFlag context) {
tooltip.add(Component.translatable("tag.winterly.cosmetic").withStyle(ChatFormatting.GRAY));
tooltip.add(Component.nullToEmpty(" "));

if(!FabricLoader.getInstance().isModLoaded("trinkets")) {
Language lang = Language.getInstance();
String key = "tip.winterly.requires_trinkets.";

for(int i = 0; i <= 32; i++) {
if(lang.has(key + i)) {
tooltip.add(Component.translatable(key + i).toFlatList(Style.EMPTY.withColor(ChatFormatting.GRAY)).get(0));
}
if(!lang.has(key + (i + 1))) {
break;
}
}
}
}
}
60 changes: 35 additions & 25 deletions fabric/src/main/java/winterly/fabric/item/ScarfItem.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,49 @@
package winterly.fabric.item;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import dev.emi.trinkets.api.SlotReference;
import dev.emi.trinkets.api.Trinket;
import dev.emi.trinkets.api.TrinketsApi;
import dev.emi.trinkets.api.client.TrinketRenderer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.world.entity.LivingEntity;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.ChatFormatting;
import net.minecraft.locale.Language;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import winterly.Winterly;
import winterly.client.model.WinterlyModels;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;
import winterly.fabric.compat.WinterlyTrinketsIntegration;
import winterly.item.CommonScarfItem;

public class ScarfItem extends CommonScarfItem implements Trinket, TrinketRenderer {
import java.util.List;

public class ScarfItem extends CommonScarfItem {

public ScarfItem(Item.Properties settings, String color) {
super(settings, color);
TrinketsApi.registerTrinket(this, this);
if(FabricLoader.getInstance().isModLoaded("trinkets")) {
WinterlyTrinketsIntegration.registerTrinket(this);
}
}

@Environment(EnvType.CLIENT)
@Override
public void render(ItemStack stack, SlotReference slotReference, EntityModel<? extends LivingEntity> contextModel, PoseStack matrices, MultiBufferSource vertexConsumers, int light, LivingEntity entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
if(contextModel instanceof HumanoidModel<? extends LivingEntity> biped){
WinterlyModels.SCARF_MODEL.scarf.copyFrom(biped.body);
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(RenderType.entityCutout(Winterly.id("textures/entity/" + color + "_scarf.png")));
WinterlyModels.SCARF_MODEL.renderToBuffer(matrices, vertexConsumer, light, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
}
}
@Environment(EnvType.CLIENT)
@Override
public void appendHoverText(ItemStack stack, @Nullable Level world, List<Component> tooltip, TooltipFlag context) {
tooltip.add(Component.translatable("tag.winterly.cosmetic").withStyle(ChatFormatting.GRAY));
tooltip.add(Component.nullToEmpty(" "));

if(!FabricLoader.getInstance().isModLoaded("trinkets")) {
Language lang = Language.getInstance();
String key = "tip.winterly.requires_trinkets.";

for(int i = 0; i <= 32; i++) {
if(lang.has(key + i)) {
tooltip.add(Component.translatable(key + i).toFlatList(Style.EMPTY.withColor(ChatFormatting.GRAY)).get(0));
}
if(!lang.has(key + (i + 1))) {
break;
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
package winterly.fabric.mixin.client;

import com.mojang.blaze3d.vertex.PoseStack;
import dev.emi.trinkets.api.SlotReference;
import dev.emi.trinkets.api.TrinketComponent;
import dev.emi.trinkets.api.TrinketsApi;
import net.fabricmc.loader.api.FabricLoader;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import winterly.fabric.item.SantaHatItem;
import java.util.Optional;
import winterly.fabric.compat.WinterlyTrinketsIntegration;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.RenderLayerParent;
import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer;
import net.minecraft.client.renderer.entity.layers.RenderLayer;
import net.minecraft.util.Tuple;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;

@Mixin(HumanoidArmorLayer.class)
public abstract class ArmorRendererMixin <T extends LivingEntity, M extends HumanoidModel<T>, A extends HumanoidModel<T>> extends RenderLayer<T, M> {
Expand All @@ -31,19 +26,9 @@ public ArmorRendererMixin(RenderLayerParent<T, M> context) {
@Inject(method = "renderArmorPiece", at = @At("HEAD"), cancellable = true)
void render(PoseStack matrices, MultiBufferSource vertexConsumers, T entity, EquipmentSlot armorSlot, int light, A model, CallbackInfo ci) {
if(entity instanceof Player player) {
if(armorSlot.equals(EquipmentSlot.HEAD)) {
if(winterly$hasHatOn(player)) ci.cancel();
if(FabricLoader.getInstance().isModLoaded("trinkets") && armorSlot.equals(EquipmentSlot.HEAD)) {
if(WinterlyTrinketsIntegration.hasHatOn(player)) ci.cancel();
}
}
}

boolean winterly$hasHatOn(Player player) {
Optional<TrinketComponent> component = TrinketsApi.getTrinketComponent(player);
if(component.isPresent()) {
for(Tuple<SlotReference, ItemStack> pair : component.get().getAllEquipped()) {
if(pair.getB().getItem() instanceof SantaHatItem) return true;
}
}
return false;
}
}
1 change: 0 additions & 1 deletion fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"fabricloader": "*",
"fabric-api": "*",
"cloth-config": "*",
"trinkets": "*",
"minecraft": "${minecraft_version_range_fabric}",
"java": ">=17"
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ maven_group = ru.pinkgoosik

# Mod Properties
mod_name = Winterly
mod_version = 0.10.0+1.20.4
mod_version = 0.10.1+1.20.4
mod_description = Winter expansion mod adding cold and sloppy stuff.
mod_id = winterly
homepage_url = https://github.com/tyap-lyap/winterly
Expand Down
Loading

0 comments on commit 618d9f7

Please sign in to comment.