diff --git a/.github/workflows/publish-modrinth.yml b/.github/workflows/publish-modrinth.yml index b3f8808..9102484 100644 --- a/.github/workflows/publish-modrinth.yml +++ b/.github/workflows/publish-modrinth.yml @@ -34,7 +34,7 @@ jobs: fabric/build/libs/winterly-fabric-${{ github.event.release.tag_name }}.jar fabric/build/libs/winterly-fabric-${{ github.event.release.tag_name }}-sources.jar - name: Winterly Fabric ${{ github.event.release.tag_name }} + name: ${{ github.event.release.tag_name }}+fabric version: ${{ github.event.release.tag_name }}+fabric version-type: release @@ -67,7 +67,7 @@ jobs: neoforge/build/libs/winterly-neoforge-${{ github.event.release.tag_name }}.jar neoforge/build/libs/winterly-neoforge-${{ github.event.release.tag_name }}-sources.jar - name: Winterly NeoForge ${{ github.event.release.tag_name }} + name: ${{ github.event.release.tag_name }}+neoforge version: ${{ github.event.release.tag_name }}+neoforge version-type: alpha diff --git a/common/src/main/java/winterly/registry/CommonWinterlyItems.java b/common/src/main/java/winterly/registry/CommonWinterlyItems.java index d316d9f..fb3ff4b 100644 --- a/common/src/main/java/winterly/registry/CommonWinterlyItems.java +++ b/common/src/main/java/winterly/registry/CommonWinterlyItems.java @@ -10,18 +10,9 @@ public class CommonWinterlyItems { public static final Map ITEMS = new LinkedHashMap<>(); - // public static final Item GINGERBREAD_MAN = add("gingerbread_man", new Item(settings().food(new FoodComponent.Builder().hunger(3).saturationModifier(0.5F).build()))); -// public static final Item EDIBLE_SNOW = add("edible_snow", new Item(settings().food(new FoodComponent.Builder().hunger(1).saturationModifier(0.1F).statusEffect(new StatusEffectInstance(StatusEffects.NAUSEA, 120, 0), 0.5F).statusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, 120, 1), 0.5F).build()))); -// public static final Item PISS_SNOW = add("yellow_snow", new Item(settings().food(new FoodComponent.Builder().hunger(1).saturationModifier(0F).statusEffect(new StatusEffectInstance(StatusEffects.NAUSEA, 200, 0), 0.9F).statusEffect(new StatusEffectInstance(StatusEffects.POISON, 80, 1), 0.8F).build()))); public static Item RED_CANDY_CANE; public static Item GREEN_CANDY_CANE; public static Item BLUE_CANDY_CANE; -// public static final Item YELLOW_CANDY_CANE = add("yellow_candy_cane", new Item(settings().food(new FoodComponent.Builder().hunger(2).saturationModifier(0.1F).snack().build()))); -// public static final Item CANDY_CANE = add("candy_cane", new Item(settings().food(new FoodComponent.Builder().hunger(2).saturationModifier(0.1F).snack().build()))); -// public static final Item MULLED_WINE = add("mulled_wine", new Item(settings().food(new FoodComponent.Builder().hunger(4).saturationModifier(0.2F).build()))); -// public static final Item EGGNOG = add("eggnog", new Item(settings().food(new FoodComponent.Builder().hunger(2).saturationModifier(0.4F).statusEffect(new StatusEffectInstance(StatusEffects.NAUSEA, 200, 0), 0.2F).build()))); -// public static final Item COCOA = add("cocoa", new Item(settings().food(new FoodComponent.Builder().hunger(4).saturationModifier(0.5F).build()))); -// public static final Item KIDS_CHAMPAGNE = add("kids_champagne", new Item(settings().food(new FoodComponent.Builder().hunger(10).saturationModifier(0.1F).statusEffect(new StatusEffectInstance(StatusEffects.REGENERATION, 100, 0), 0.3F).statusEffect(new StatusEffectInstance(StatusEffects.ABSORPTION, 400, 0), 0.3F).statusEffect(new StatusEffectInstance(StatusEffects.INSTANT_HEALTH, 0, 0), 0.3F).build()))); public static Item CRYOMARBLE_SHARD; public static Item CRYOMARBLE; @@ -40,5 +31,9 @@ public class CommonWinterlyItems { public static Item GREEN_SCARF; public static Item BLUE_SCARF; public static Item RAINBOW_SCARF; + + public static Item.Properties settings() { + return new Item.Properties(); + } } diff --git a/fabric/src/main/java/winterly/fabric/WinterlyFabric.java b/fabric/src/main/java/winterly/fabric/WinterlyFabric.java index 543514a..1dcf386 100644 --- a/fabric/src/main/java/winterly/fabric/WinterlyFabric.java +++ b/fabric/src/main/java/winterly/fabric/WinterlyFabric.java @@ -9,7 +9,6 @@ import net.minecraft.network.chat.Component; import net.minecraft.world.item.CreativeModeTab; import winterly.Winterly; -import winterly.config.WinterlyClothConfig; import winterly.fabric.compat.WinterlyOwoLibIntegration; import winterly.fabric.registry.WinterlyBlockEntities; import winterly.fabric.registry.WinterlyBlocks; diff --git a/fabric/src/main/java/winterly/fabric/compat/WinterlyTrinketsIntegration.java b/fabric/src/main/java/winterly/fabric/compat/WinterlyTrinketsIntegration.java index f5911c7..03c59b2 100644 --- a/fabric/src/main/java/winterly/fabric/compat/WinterlyTrinketsIntegration.java +++ b/fabric/src/main/java/winterly/fabric/compat/WinterlyTrinketsIntegration.java @@ -28,7 +28,6 @@ public class WinterlyTrinketsIntegration { - public static void registerTrinket(Item item) { TrinketsApi.registerTrinket(item, new Trinket() {}); } diff --git a/fabric/src/main/java/winterly/fabric/registry/WinterlyItems.java b/fabric/src/main/java/winterly/fabric/registry/WinterlyItems.java index ab97b59..0af8e7f 100644 --- a/fabric/src/main/java/winterly/fabric/registry/WinterlyItems.java +++ b/fabric/src/main/java/winterly/fabric/registry/WinterlyItems.java @@ -1,6 +1,5 @@ package winterly.fabric.registry; -import net.fabricmc.fabric.api.item.v1.FabricItemSettings; import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.food.FoodProperties; @@ -46,8 +45,4 @@ private static T add(String name, T item) { ITEMS.put(Winterly.id(name), item); return item; } - - private static FabricItemSettings settings() { - return new FabricItemSettings(); - } } diff --git a/neoforge/src/main/java/winterly/neoforge/WinterlyNeoforge.java b/neoforge/src/main/java/winterly/neoforge/WinterlyNeoforge.java index a1edb5e..4e5b71a 100644 --- a/neoforge/src/main/java/winterly/neoforge/WinterlyNeoforge.java +++ b/neoforge/src/main/java/winterly/neoforge/WinterlyNeoforge.java @@ -26,7 +26,7 @@ public class WinterlyNeoforge { public static final DeferredRegister CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, "winterly"); - public static Supplier WINTERLY_TAB = CREATIVE_MODE_TABS.register("winterly", () -> CreativeModeTab.builder().icon(CommonWinterlyBlocks.SNOWGUY.asItem()::getDefaultInstance).title(Component.literal("Winterly")).build()); + public static final Supplier WINTERLY_TAB = CREATIVE_MODE_TABS.register("winterly", () -> CreativeModeTab.builder().icon(CommonWinterlyBlocks.SNOWGUY.asItem()::getDefaultInstance).title(Component.translatable("itemGroup.winterly.items")).build()); public WinterlyNeoforge(IEventBus bus) { CREATIVE_MODE_TABS.register(bus); @@ -41,7 +41,7 @@ public WinterlyNeoforge(IEventBus bus) { bus.addListener(this::commonSetup); if(FMLEnvironment.dist.isClient()) { - new WinterlyNeoforgeClient().init(bus); + WinterlyNeoforgeClient.init(bus); } } diff --git a/neoforge/src/main/java/winterly/neoforge/client/WinterlyNeoforgeClient.java b/neoforge/src/main/java/winterly/neoforge/client/WinterlyNeoforgeClient.java index 2ed92bf..bc22eee 100644 --- a/neoforge/src/main/java/winterly/neoforge/client/WinterlyNeoforgeClient.java +++ b/neoforge/src/main/java/winterly/neoforge/client/WinterlyNeoforgeClient.java @@ -25,18 +25,18 @@ @OnlyIn(Dist.CLIENT) public class WinterlyNeoforgeClient { - public void init(IEventBus bus) { - bus.addListener(this::clientSetup); - bus.addListener(this::registerModelLayers); - bus.addListener(this::registerRenderLayers); + public static void init(IEventBus bus) { + bus.addListener(WinterlyNeoforgeClient::clientSetup); + bus.addListener(WinterlyNeoforgeClient::registerModelLayers); + bus.addListener(WinterlyNeoforgeClient::registerRenderLayers); } - private void registerModelLayers(EntityRenderersEvent.RegisterLayerDefinitions event) { + private static void registerModelLayers(EntityRenderersEvent.RegisterLayerDefinitions event) { event.registerLayerDefinition(WinterlyModelLayers.SANTA_HAT_LAYER, SantaHatModel::getTexturedModelData); event.registerLayerDefinition(WinterlyModelLayers.SCARF_LAYER, ScarfModel::getTexturedModelData); } - private void registerRenderLayers(EntityRenderersEvent.AddLayers event) { + private static void registerRenderLayers(EntityRenderersEvent.AddLayers event) { event.getContext().getEntityRenderDispatcher().renderers.forEach((entityType, entityRenderer) -> { if(entityRenderer instanceof ZombieRenderer renderer) { renderer.addLayer(new DecorationFeatureRenderer<>(renderer)); @@ -50,7 +50,7 @@ private void registerRenderLayers(EntityRenderersEvent.AddLayers event) { }); } - private void clientSetup(FMLClientSetupEvent event) { + private static void clientSetup(FMLClientSetupEvent event) { if(ModList.get().isLoaded("curios")) { CommonWinterlyItems.ITEMS.forEach((resourceLocation, item) -> { if(item instanceof CommonScarfItem scarf) WinterlyCuriosIntegration.registerScarfRenderer(scarf); diff --git a/neoforge/src/main/java/winterly/neoforge/compat/WinterlyCuriosIntegration.java b/neoforge/src/main/java/winterly/neoforge/compat/WinterlyCuriosIntegration.java index 4c5f71e..27263b2 100644 --- a/neoforge/src/main/java/winterly/neoforge/compat/WinterlyCuriosIntegration.java +++ b/neoforge/src/main/java/winterly/neoforge/compat/WinterlyCuriosIntegration.java @@ -8,7 +8,9 @@ import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.entity.RenderLayerParent; import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.core.NonNullList; 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 top.theillusivec4.curios.api.CuriosApi; @@ -16,24 +18,55 @@ import top.theillusivec4.curios.api.client.CuriosRendererRegistry; import top.theillusivec4.curios.api.client.ICurioRenderer; import top.theillusivec4.curios.api.type.capability.ICurioItem; +import top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler; +import top.theillusivec4.curios.api.type.inventory.IDynamicStackHandler; import winterly.Winterly; import winterly.client.model.WinterlyModels; import winterly.item.CommonSantaHatItem; import winterly.item.CommonScarfItem; +import java.util.Map; + public class WinterlyCuriosIntegration { public static void registerCurio(Item item) { CuriosApi.registerCurio(item, new ICurioItem() {}); } + public static boolean hasVisibleHat(Player player) { + var curiosItemHandler = CuriosApi.getCuriosInventory(player); + if(curiosItemHandler.isPresent()) { + for (Map.Entry entry : curiosItemHandler.get().getCurios().entrySet()) { + IDynamicStackHandler stackHandler = entry.getValue().getStacks(); + IDynamicStackHandler cosmeticStacksHandler = entry.getValue().getCosmeticStacks(); + + for(int i = 0; i < stackHandler.getSlots(); ++i) { + ItemStack stack = cosmeticStacksHandler.getStackInSlot(i); + + NonNullList renderStates = entry.getValue().getRenders(); + boolean renderable = renderStates.size() > i && renderStates.get(i); + + if (stack.isEmpty() && renderable) { + stack = stackHandler.getStackInSlot(i); + } + + if (!stack.isEmpty() && stack.getItem() instanceof CommonSantaHatItem) { + return true; + } + } + } + } + + return false; + } + public static void registerScarfRenderer(CommonScarfItem scarf) { CuriosRendererRegistry.register(scarf, () -> { return new ICurioRenderer() { @Override public > void render(ItemStack stack, SlotContext slotContext, PoseStack matrices, RenderLayerParent renderLayerParent, MultiBufferSource renderTypeBuffer, int light, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) { - if(renderLayerParent.getModel() instanceof HumanoidModel biped){ - WinterlyModels.SCARF_MODEL.scarf.copyFrom(biped.body); + if(renderLayerParent.getModel() instanceof HumanoidModel humanoid) { + WinterlyModels.SCARF_MODEL.scarf.copyFrom(humanoid.body); VertexConsumer vertexConsumer = renderTypeBuffer.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); } @@ -47,8 +80,8 @@ public static void registerSantaHatRenderer(CommonSantaHatItem hat) { return new ICurioRenderer() { @Override public > void render(ItemStack stack, SlotContext slotContext, PoseStack matrices, RenderLayerParent renderLayerParent, MultiBufferSource renderTypeBuffer, int light, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) { - if(renderLayerParent.getModel() instanceof HumanoidModel biped) { - WinterlyModels.SANTA_HAT_MODEL.hat.copyFrom(biped.head); + if(renderLayerParent.getModel() instanceof HumanoidModel humanoid) { + WinterlyModels.SANTA_HAT_MODEL.hat.copyFrom(humanoid.head); VertexConsumer vertexConsumer = renderTypeBuffer.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); } diff --git a/neoforge/src/main/java/winterly/neoforge/mixin/client/ArmorRendererMixin.java b/neoforge/src/main/java/winterly/neoforge/mixin/client/ArmorRendererMixin.java new file mode 100644 index 0000000..16dc4b7 --- /dev/null +++ b/neoforge/src/main/java/winterly/neoforge/mixin/client/ArmorRendererMixin.java @@ -0,0 +1,34 @@ +package winterly.neoforge.mixin.client; + +import com.mojang.blaze3d.vertex.PoseStack; +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.world.entity.EquipmentSlot; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.neoforged.fml.ModList; +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.neoforge.compat.WinterlyCuriosIntegration; + +@Mixin(HumanoidArmorLayer.class) +public abstract class ArmorRendererMixin, A extends HumanoidModel> extends RenderLayer { + + public ArmorRendererMixin(RenderLayerParent context) { + super(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(ModList.get().isLoaded("curios") && armorSlot.equals(EquipmentSlot.HEAD)) { + if(WinterlyCuriosIntegration.hasVisibleHat(player)) ci.cancel(); + } + } + } +} diff --git a/neoforge/src/main/java/winterly/neoforge/registry/WinterlyItems.java b/neoforge/src/main/java/winterly/neoforge/registry/WinterlyItems.java index 479437c..f22601d 100644 --- a/neoforge/src/main/java/winterly/neoforge/registry/WinterlyItems.java +++ b/neoforge/src/main/java/winterly/neoforge/registry/WinterlyItems.java @@ -42,21 +42,14 @@ public static void init(IEventBus eventBus) { add("blue_scarf", () -> BLUE_SCARF = new ScarfItem(settings(), "blue")); add("rainbow_scarf", () -> RAINBOW_SCARF = new ScarfItem(settings(), "rainbow")); -// ITEMS.forEach((id, item) -> Registry.register(BuiltInRegistries.ITEM, id, item)); ITEMS_REGISTERER.register(eventBus); } - private static T add(String name, Supplier sup) { -// ITEMS.put(Winterly.id(name), null); + private static void add(String name, Supplier sup) { ITEMS_REGISTERER.register(name, () -> { var item = sup.get(); ITEMS.put(Winterly.id(name), item); return item; }); - return null; - } - - private static Item.Properties settings() { - return new Item.Properties(); } } diff --git a/neoforge/src/main/resources/winterly.mixins.json b/neoforge/src/main/resources/winterly.mixins.json index 176b208..0282bb3 100644 --- a/neoforge/src/main/resources/winterly.mixins.json +++ b/neoforge/src/main/resources/winterly.mixins.json @@ -4,10 +4,11 @@ "compatibilityLevel": "JAVA_17", "minVersion": "0.8", "client": [ + "client.ArmorRendererMixin" ], "mixins": [ ], "injectors": { "defaultRequire": 1 } -} \ No newline at end of file +}