diff options
author | Linnea Gräf <nea@nea.moe> | 2024-04-01 21:57:16 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-04-01 21:57:16 +0200 |
commit | ab30c1128b42eed24d0decf9ecf9e6a2c98a79e2 (patch) | |
tree | e0b23161678b97c09e89fda00dfa5f3d7569238f /src/client | |
parent | 0fe5e487922a6ff50b9c415b9384157fbd64b2b5 (diff) | |
download | potato-crimes-ab30c1128b42eed24d0decf9ecf9e6a2c98a79e2.tar.gz potato-crimes-ab30c1128b42eed24d0decf9ecf9e6a2c98a79e2.tar.bz2 potato-crimes-ab30c1128b42eed24d0decf9ecf9e6a2c98a79e2.zip |
Add potato guard
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/kotlin/moe/nea/potatocrime/PotatoCrimeClient.kt | 16 | ||||
-rw-r--r-- | src/client/kotlin/moe/nea/potatocrime/client/entity/PotatoGuardRenderer.kt | 95 | ||||
-rw-r--r-- | src/client/resources/assets/potato-crime/textures/entity/potato_guard.png | bin | 0 -> 385 bytes |
3 files changed, 108 insertions, 3 deletions
diff --git a/src/client/kotlin/moe/nea/potatocrime/PotatoCrimeClient.kt b/src/client/kotlin/moe/nea/potatocrime/PotatoCrimeClient.kt index b724800..baba5d2 100644 --- a/src/client/kotlin/moe/nea/potatocrime/PotatoCrimeClient.kt +++ b/src/client/kotlin/moe/nea/potatocrime/PotatoCrimeClient.kt @@ -1,9 +1,19 @@ package moe.nea.potatocrime +import moe.nea.potatocrime.client.entity.PotatoGuardModel +import moe.nea.potatocrime.client.entity.PotatoGuardRenderer +import moe.nea.potatocrime.registry.PotatoRegistry import net.fabricmc.api.ClientModInitializer +import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry +import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry + object PotatoCrimeClient : ClientModInitializer { - override fun onInitializeClient() { - // This entrypoint is suitable for setting up client-specific logic, such as rendering. - } + override fun onInitializeClient() { + EntityRendererRegistry.register(PotatoRegistry.potatoGuard, ::PotatoGuardRenderer) + EntityModelLayerRegistry.registerModelLayer( + PotatoGuardRenderer.modelLayer, + PotatoGuardModel::getTexturedModelData + ) + } }
\ No newline at end of file diff --git a/src/client/kotlin/moe/nea/potatocrime/client/entity/PotatoGuardRenderer.kt b/src/client/kotlin/moe/nea/potatocrime/client/entity/PotatoGuardRenderer.kt new file mode 100644 index 0000000..c22e2e0 --- /dev/null +++ b/src/client/kotlin/moe/nea/potatocrime/client/entity/PotatoGuardRenderer.kt @@ -0,0 +1,95 @@ +package moe.nea.potatocrime.client.entity + +import moe.nea.potatocrime.entity.PotatoGuardEntity +import moe.nea.potatocrime.registry.PotatoRegistry +import net.minecraft.client.model.* +import net.minecraft.client.render.VertexConsumer +import net.minecraft.client.render.entity.EntityRendererFactory +import net.minecraft.client.render.entity.MobEntityRenderer +import net.minecraft.client.render.entity.model.EntityModel +import net.minecraft.client.render.entity.model.EntityModelLayer +import net.minecraft.client.util.math.MatrixStack +import net.minecraft.util.Identifier + + +class PotatoGuardRenderer(context: EntityRendererFactory.Context) : + MobEntityRenderer<PotatoGuardEntity, PotatoGuardModel>( + context, + PotatoGuardModel(context.getPart(modelLayer)), + 0.5f + ) { + companion object { + val modelLayer = EntityModelLayer(PotatoRegistry.identifier("potato_guard"), "main") + } + + override fun getTexture(entity: PotatoGuardEntity): Identifier { + return PotatoRegistry.identifier("textures/entity/potato_guard.png") + } +} + +class PotatoGuardModel(val part: ModelPart) : EntityModel<PotatoGuardEntity>() { + val PotatoGuard = part.getChild("PotatoGuard") + val PotatoHead = part.getChild("PotatoHead") + + companion object { + fun getTexturedModelData(): TexturedModelData { + val modelData = ModelData() + val modelPartData = modelData.root + val PotatoGuard = modelPartData.addChild( + "PotatoGuard", + ModelPartBuilder.create().uv(0, 37).cuboid(-7.0f, -21.5f, -7.0f, 14.0f, 21.0f, 14.0f, Dilation(0.0f)) + .uv(0, 0).cuboid(-8.0f, 0.5f, -8.0f, 16.0f, 21.0f, 16.0f, Dilation(0.0f)), + ModelTransform.pivot(0.0f, 0.5f, 0.0f) + ) + + val PotatoHead = modelPartData.addChild( + "PotatoHead", + ModelPartBuilder.create().uv(56, 29).cuboid(-4.0f, -6.5f, -4.0f, 8.0f, 13.0f, 8.0f, Dilation(0.0f)), + ModelTransform.pivot(0.0f, -28.5f, 0.0f) + ) + + return TexturedModelData.of(modelData, 128, 128) + + } + } + + override fun render( + matrices: MatrixStack?, + vertices: VertexConsumer?, + light: Int, + overlay: Int, + red: Float, + green: Float, + blue: Float, + alpha: Float + ) { + listOf(PotatoGuard, PotatoHead).forEach { + it.render(matrices, vertices, light, overlay, red, green, blue, alpha) + } + } + fun lerpAngle(angleOne: Float, angleTwo: Float, magnitude: Float): Float { + var f = (magnitude - angleTwo) % 6.2831855f + if (f < -3.1415927f) { + f += 6.2831855f + } + + if (f >= 3.1415927f) { + f -= 6.2831855f + } + + return angleTwo + angleOne * f + } + + override fun setAngles( + entity: PotatoGuardEntity?, + limbAngle: Float, + limbDistance: Float, + animationProgress: Float, + headYaw: Float, + headPitch: Float + ) { + PotatoHead.yaw = headYaw / 180 * Math.PI.toFloat() + PotatoHead.pitch = headPitch / 180 * Math.PI.toFloat() +// PotatoGuard.setAngles(limbAngle, 0F, 0F) + } +}
\ No newline at end of file diff --git a/src/client/resources/assets/potato-crime/textures/entity/potato_guard.png b/src/client/resources/assets/potato-crime/textures/entity/potato_guard.png Binary files differnew file mode 100644 index 0000000..3cfa2f1 --- /dev/null +++ b/src/client/resources/assets/potato-crime/textures/entity/potato_guard.png |