From 5a747ce93c1e5b0386474e03e14d381d505acf66 Mon Sep 17 00:00:00 2001 From: patryk3211 Date: Tue, 10 May 2022 14:51:38 +0200 Subject: [PATCH 1/3] Added support for wearing goggles on curios head slot --- build.gradle | 7 +++++ gradle.properties | 2 ++ src/main/java/com/simibubi/create/Create.java | 5 +++ .../java/com/simibubi/create/compat/Mods.java | 3 +- .../simibubi/create/compat/curios/Curios.java | 31 +++++++++++++++++++ .../data/curios/tags/items/head.json | 6 ++++ 6 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/simibubi/create/compat/curios/Curios.java create mode 100644 src/main/resources/data/curios/tags/items/head.json diff --git a/build.gradle b/build.gradle index 7fe024dcc..b5c3bafa4 100644 --- a/build.gradle +++ b/build.gradle @@ -135,6 +135,10 @@ repositories { //location of the maven for dynamic trees url 'https://harleyoconnor.com/maven' } + maven { + //location of the maven for curios api + url = "https://maven.theillusivec4.top/" + } } configurations { @@ -157,6 +161,9 @@ dependencies { compileOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}:${jei_version}:api") runtimeOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}:${jei_version}") + compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:${curios_minecraft_version}-${curios_version}:api") + runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:${curios_minecraft_version}-${curios_version}") + // implementation fg.deobf("curse.maven:druidcraft-340991:3101903") // implementation fg.deobf("com.ferreusveritas.dynamictrees:DynamicTrees-1.16.5:0.10.0-Beta25") // runtimeOnly fg.deobf("vazkii.arl:AutoRegLib:1.4-35.69") diff --git a/gradle.properties b/gradle.properties index 943a79117..fa671c50f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,6 +22,8 @@ registrate_version = MC1.18.2-1.0.25 flywheel_version = 1.18-0.7.0.67 jei_minecraft_version = 1.18.2 jei_version = 9.5.3.143 +curios_minecraft_version = 1.18.2 +curios_version = 5.0.7.0 # curseforge information projectId = 328085 diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index 951b0f95e..a98390755 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -2,6 +2,9 @@ package com.simibubi.create; import java.util.Random; +import com.simibubi.create.compat.Mods; +import com.simibubi.create.compat.curios.Curios; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -119,6 +122,8 @@ public class Create { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> CreateClient.onCtorClient(modEventBus, forgeEventBus)); + + Mods.CURIOS.executeIfInstalled(() -> Curios::init); } public static void init(final FMLCommonSetupEvent event) { diff --git a/src/main/java/com/simibubi/create/compat/Mods.java b/src/main/java/com/simibubi/create/compat/Mods.java index 1aba89709..52201bb24 100644 --- a/src/main/java/com/simibubi/create/compat/Mods.java +++ b/src/main/java/com/simibubi/create/compat/Mods.java @@ -12,7 +12,8 @@ import net.minecraftforge.fml.ModList; */ public enum Mods { DYNAMICTREES, - TCONSTRUCT; + TCONSTRUCT, + CURIOS; /** * @return a boolean of whether the mod is loaded or not based on mod id diff --git a/src/main/java/com/simibubi/create/compat/curios/Curios.java b/src/main/java/com/simibubi/create/compat/curios/Curios.java new file mode 100644 index 000000000..5d55aef84 --- /dev/null +++ b/src/main/java/com/simibubi/create/compat/curios/Curios.java @@ -0,0 +1,31 @@ +package com.simibubi.create.compat.curios; + +import com.simibubi.create.AllItems; +import com.simibubi.create.content.contraptions.goggles.GogglesItem; + +import net.minecraftforge.fml.InterModComms; +import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import top.theillusivec4.curios.api.CuriosCapability; +import top.theillusivec4.curios.api.SlotTypeMessage; +import top.theillusivec4.curios.api.SlotTypePreset; + +import java.util.concurrent.atomic.AtomicBoolean; + +public class Curios { + public static void init() { + FMLJavaModLoadingContext.get().getModEventBus().addListener(Curios::onInterModEnqueue); + + GogglesItem.addIsWearingPredicate(player -> { + AtomicBoolean hasGoggles = new AtomicBoolean(false); + player.getCapability(CuriosCapability.INVENTORY).ifPresent(handler -> { + hasGoggles.set(handler.getCurios().get("head").getStacks().getStackInSlot(0).getItem() == AllItems.GOGGLES.get()); + }); + return hasGoggles.get(); + }); + } + + private static void onInterModEnqueue(final InterModEnqueueEvent event) { + InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, () -> SlotTypePreset.HEAD.getMessageBuilder().build()); + } +} diff --git a/src/main/resources/data/curios/tags/items/head.json b/src/main/resources/data/curios/tags/items/head.json new file mode 100644 index 000000000..635bc6fe7 --- /dev/null +++ b/src/main/resources/data/curios/tags/items/head.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "create:goggles" + ] +} From 5af222a99b84c1e66075cfa94983bc383a2c9fcb Mon Sep 17 00:00:00 2001 From: patryk3211 Date: Wed, 11 May 2022 14:23:55 +0200 Subject: [PATCH 2/3] Goggles render correctly when worn as a Curio --- .../simibubi/create/compat/curios/Curios.java | 18 ++++- .../create/compat/curios/CuriosRenderers.java | 21 ++++++ .../compat/curios/GogglesCurioRenderer.java | 67 +++++++++++++++++++ 3 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/simibubi/create/compat/curios/CuriosRenderers.java create mode 100644 src/main/java/com/simibubi/create/compat/curios/GogglesCurioRenderer.java diff --git a/src/main/java/com/simibubi/create/compat/curios/Curios.java b/src/main/java/com/simibubi/create/compat/curios/Curios.java index 5d55aef84..566677125 100644 --- a/src/main/java/com/simibubi/create/compat/curios/Curios.java +++ b/src/main/java/com/simibubi/create/compat/curios/Curios.java @@ -1,31 +1,43 @@ package com.simibubi.create.compat.curios; +import java.util.concurrent.atomic.AtomicBoolean; + import com.simibubi.create.AllItems; import com.simibubi.create.content.contraptions.goggles.GogglesItem; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.InterModComms; +import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import top.theillusivec4.curios.api.CuriosCapability; import top.theillusivec4.curios.api.SlotTypeMessage; import top.theillusivec4.curios.api.SlotTypePreset; - -import java.util.concurrent.atomic.AtomicBoolean; +import top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler; public class Curios { public static void init() { FMLJavaModLoadingContext.get().getModEventBus().addListener(Curios::onInterModEnqueue); + FMLJavaModLoadingContext.get().getModEventBus().addListener(Curios::onClientSetup); GogglesItem.addIsWearingPredicate(player -> { AtomicBoolean hasGoggles = new AtomicBoolean(false); player.getCapability(CuriosCapability.INVENTORY).ifPresent(handler -> { - hasGoggles.set(handler.getCurios().get("head").getStacks().getStackInSlot(0).getItem() == AllItems.GOGGLES.get()); + ICurioStacksHandler stacksHandler = handler.getCurios().get("head"); + if(stacksHandler != null) hasGoggles.set(stacksHandler.getStacks().getStackInSlot(0).getItem() == AllItems.GOGGLES.get()); }); return hasGoggles.get(); }); + + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> FMLJavaModLoadingContext.get().getModEventBus().addListener(CuriosRenderers::onLayerRegister)); } private static void onInterModEnqueue(final InterModEnqueueEvent event) { InterModComms.sendTo("curios", SlotTypeMessage.REGISTER_TYPE, () -> SlotTypePreset.HEAD.getMessageBuilder().build()); } + + private static void onClientSetup(final FMLClientSetupEvent event) { + CuriosRenderers.register(); + } } diff --git a/src/main/java/com/simibubi/create/compat/curios/CuriosRenderers.java b/src/main/java/com/simibubi/create/compat/curios/CuriosRenderers.java new file mode 100644 index 000000000..740d251b0 --- /dev/null +++ b/src/main/java/com/simibubi/create/compat/curios/CuriosRenderers.java @@ -0,0 +1,21 @@ +package com.simibubi.create.compat.curios; + +import com.simibubi.create.AllItems; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.model.geom.builders.LayerDefinition; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.client.event.EntityRenderersEvent; +import top.theillusivec4.curios.api.client.CuriosRendererRegistry; + +@OnlyIn(Dist.CLIENT) +public class CuriosRenderers { + public static void register() { + CuriosRendererRegistry.register(AllItems.GOGGLES.get(), () -> new GogglesCurioRenderer(Minecraft.getInstance().getEntityModels().bakeLayer(GogglesCurioRenderer.LAYER))); + } + + public static void onLayerRegister(final EntityRenderersEvent.RegisterLayerDefinitions event) { + event.registerLayerDefinition(GogglesCurioRenderer.LAYER, () -> LayerDefinition.create(GogglesCurioRenderer.mesh(), 1, 1)); + } +} diff --git a/src/main/java/com/simibubi/create/compat/curios/GogglesCurioRenderer.java b/src/main/java/com/simibubi/create/compat/curios/GogglesCurioRenderer.java new file mode 100644 index 000000000..940822439 --- /dev/null +++ b/src/main/java/com/simibubi/create/compat/curios/GogglesCurioRenderer.java @@ -0,0 +1,67 @@ +package com.simibubi.create.compat.curios; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Vector3f; +import com.simibubi.create.Create; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.model.EntityModel; +import net.minecraft.client.model.HumanoidModel; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.model.geom.PartPose; +import net.minecraft.client.model.geom.builders.CubeDeformation; +import net.minecraft.client.model.geom.builders.CubeListBuilder; +import net.minecraft.client.model.geom.builders.MeshDefinition; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.block.model.ItemTransforms; +import net.minecraft.client.renderer.entity.RenderLayerParent; +import net.minecraft.client.renderer.texture.OverlayTexture; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import top.theillusivec4.curios.api.SlotContext; +import top.theillusivec4.curios.api.client.ICurioRenderer; + +@OnlyIn(Dist.CLIENT) +public class GogglesCurioRenderer implements ICurioRenderer { + public static final ModelLayerLocation LAYER = new ModelLayerLocation(new ResourceLocation(Create.ID, "goggles"), "goggles"); + + private final HumanoidModel model; + + public GogglesCurioRenderer(ModelPart part) { + this.model = new HumanoidModel<>(part); + } + + @Override + public > void render(ItemStack stack, SlotContext slotContext, PoseStack matrixStack, RenderLayerParent renderLayerParent, MultiBufferSource renderTypeBuffer, int light, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) { + // Prepare values for transformation + model.setupAnim(slotContext.entity(), limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch); + model.prepareMobModel(slotContext.entity(), limbSwing, limbSwingAmount, partialTicks); + ICurioRenderer.followHeadRotations(slotContext.entity(), model.head); + + // Translate and rotate with our head + matrixStack.pushPose(); + matrixStack.translate(model.head.x / 16.0, model.head.y / 16.0, model.head.z / 16.0); + matrixStack.mulPose(Vector3f.YP.rotation(model.head.yRot)); + matrixStack.mulPose(Vector3f.XP.rotation(model.head.xRot)); + + // Translate and scale to our head + matrixStack.translate(0, -0.25, 0); + matrixStack.mulPose(Vector3f.ZP.rotationDegrees(180.0f)); + matrixStack.scale(0.625f, 0.625f, 0.625f); + + // Render + Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemTransforms.TransformType.HEAD, light, OverlayTexture.NO_OVERLAY, matrixStack, renderTypeBuffer, 0); + matrixStack.popPose(); + } + + public static MeshDefinition mesh() { + CubeListBuilder builder = new CubeListBuilder(); + MeshDefinition mesh = HumanoidModel.createMesh(CubeDeformation.NONE, 0); + mesh.getRoot().addOrReplaceChild("head", builder, PartPose.ZERO); + return mesh; + } +} From 2ed5ee9f3b274f036f5080358cd302d26cfef0e1 Mon Sep 17 00:00:00 2001 From: patryk3211 Date: Wed, 11 May 2022 14:42:43 +0200 Subject: [PATCH 3/3] Goggles are on your eyes if you wear something on your head. --- .../simibubi/create/compat/curios/GogglesCurioRenderer.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/simibubi/create/compat/curios/GogglesCurioRenderer.java b/src/main/java/com/simibubi/create/compat/curios/GogglesCurioRenderer.java index 940822439..25a243fc2 100644 --- a/src/main/java/com/simibubi/create/compat/curios/GogglesCurioRenderer.java +++ b/src/main/java/com/simibubi/create/compat/curios/GogglesCurioRenderer.java @@ -18,6 +18,7 @@ import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.renderer.entity.RenderLayerParent; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; @@ -53,6 +54,11 @@ public class GogglesCurioRenderer implements ICurioRenderer { matrixStack.mulPose(Vector3f.ZP.rotationDegrees(180.0f)); matrixStack.scale(0.625f, 0.625f, 0.625f); + if(!slotContext.entity().getItemBySlot(EquipmentSlot.HEAD).isEmpty()) { + matrixStack.mulPose(Vector3f.ZP.rotationDegrees(180.0f)); + matrixStack.translate(0, -0.25, 0); + } + // Render Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemTransforms.TransformType.HEAD, light, OverlayTexture.NO_OVERLAY, matrixStack, renderTypeBuffer, 0); matrixStack.popPose();