-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make trinkets and curios optional dependencies
- Loading branch information
1 parent
235b50e
commit 618d9f7
Showing
17 changed files
with
362 additions
and
192 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
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
71 changes: 71 additions & 0 deletions
71
fabric/src/main/java/winterly/fabric/compat/WinterlyTrinketsIntegration.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,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
60
fabric/src/main/java/winterly/fabric/item/SantaHatItem.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,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; | ||
} | ||
} | ||
} | ||
} | ||
} |
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,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; | ||
} | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.