Skip to content

Commit 27423ce

Browse files
committed
fix #76, 3+ coven, nether and depth sound
1 parent 48bbd44 commit 27423ce

8 files changed

Lines changed: 268 additions & 33 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package dev.sterner.witchery.mixin;
2+
3+
import net.minecraft.world.entity.Entity;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
import org.spongepowered.asm.mixin.gen.Accessor;
6+
7+
@Mixin(Entity.class)
8+
public interface EntityAccessor {
9+
10+
@Accessor("eyeHeight")
11+
float witchery$getEyeHeight();
12+
13+
@Accessor("eyeHeight")
14+
void witchery$setEyeHeight(float value);
15+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package dev.sterner.witchery.client.layer
2+
3+
import com.mojang.blaze3d.vertex.PoseStack
4+
import dev.sterner.witchery.content.entity.InsanityEntity
5+
import net.minecraft.client.model.EntityModel
6+
import net.minecraft.client.renderer.MultiBufferSource
7+
import net.minecraft.client.renderer.RenderType
8+
import net.minecraft.client.renderer.entity.RenderLayerParent
9+
import net.minecraft.client.renderer.entity.layers.EyesLayer
10+
import net.minecraft.client.renderer.texture.OverlayTexture
11+
import net.minecraft.resources.ResourceLocation
12+
import net.neoforged.api.distmarker.Dist
13+
import net.neoforged.api.distmarker.OnlyIn
14+
15+
@OnlyIn(Dist.CLIENT)
16+
class InsanityEndermanEyesLayer(p_116964_: RenderLayerParent<InsanityEntity, EntityModel<InsanityEntity>>) :
17+
EyesLayer<InsanityEntity, EntityModel<InsanityEntity>>(p_116964_) {
18+
19+
override fun renderType(): RenderType {
20+
return ENDERMAN_EYES
21+
}
22+
23+
override fun render(
24+
poseStack: PoseStack,
25+
buffer: MultiBufferSource,
26+
packedLight: Int,
27+
livingEntity: InsanityEntity,
28+
limbSwing: Float,
29+
limbSwingAmount: Float,
30+
partialTicks: Float,
31+
ageInTicks: Float,
32+
netHeadYaw: Float,
33+
headPitch: Float
34+
) {
35+
if (livingEntity.entityData.get(InsanityEntity.DATA_MIMIC) == "enderman") {
36+
val vertexconsumer = buffer.getBuffer(this.renderType())
37+
this.parentModel.renderToBuffer(poseStack, vertexconsumer, 15728640, OverlayTexture.NO_OVERLAY)
38+
}
39+
}
40+
41+
companion object {
42+
private val ENDERMAN_EYES: RenderType =
43+
RenderType.eyes(ResourceLocation.withDefaultNamespace("textures/entity/enderman/enderman_eyes.png"))
44+
}
45+
}

src/main/kotlin/dev/sterner/witchery/client/renderer/entity/InsanityEntityRenderer.kt

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dev.sterner.witchery.client.renderer.entity
22

33
import com.mojang.blaze3d.vertex.PoseStack
44
import com.mojang.blaze3d.vertex.VertexConsumer
5+
import dev.sterner.witchery.client.layer.InsanityEndermanEyesLayer
56
import dev.sterner.witchery.content.entity.InsanityEntity
67
import net.minecraft.client.model.CreeperModel
78
import net.minecraft.client.model.EntityModel
@@ -12,6 +13,8 @@ import net.minecraft.client.renderer.MultiBufferSource
1213
import net.minecraft.client.renderer.RenderType
1314
import net.minecraft.client.renderer.entity.EntityRendererProvider
1415
import net.minecraft.client.renderer.entity.MobRenderer
16+
import net.minecraft.client.renderer.texture.OverlayTexture
17+
import net.minecraft.core.particles.ParticleTypes
1518
import net.minecraft.resources.ResourceLocation
1619
import net.minecraft.util.Mth
1720

@@ -28,6 +31,11 @@ class InsanityEntityRenderer(ctx: EntityRendererProvider.Context) :
2831
private val zombieTexture = ResourceLocation.withDefaultNamespace("textures/entity/zombie/zombie.png")
2932
private val skeletonTexture = ResourceLocation.withDefaultNamespace("textures/entity/skeleton/skeleton.png")
3033
private val endermanTexture = ResourceLocation.withDefaultNamespace("textures/entity/enderman/enderman.png")
34+
private val endermanEyesTexture = ResourceLocation.withDefaultNamespace("textures/entity/enderman/enderman_eyes.png")
35+
36+
init {
37+
addLayer(InsanityEndermanEyesLayer(this))
38+
}
3139

3240
private class DummyModel : EntityModel<InsanityEntity>() {
3341
override fun setupAnim(
@@ -99,6 +107,62 @@ class InsanityEntityRenderer(ctx: EntityRendererProvider.Context) :
99107
leftArm.xRot = Mth.cos(limbSwing * 0.6662f) * 2.0f * limbSwingAmount * 0.5f
100108
rightLeg.xRot = Mth.cos(limbSwing * 0.6662f) * 1.4f * limbSwingAmount
101109
leftLeg.xRot = Mth.cos(limbSwing * 0.6662f + Math.PI.toFloat()) * 1.4f * limbSwingAmount
110+
111+
112+
this.head.visible = true
113+
this.body.xRot = 0.0F
114+
this.body.y = -14.0F
115+
this.body.z = -0.0F
116+
this.rightLeg.xRot -= 0.0F
117+
this.leftLeg.xRot -= 0.0F
118+
this.rightArm.xRot *= 0.5F
119+
this.leftArm.xRot *= 0.5F
120+
this.rightLeg.xRot *= 0.5F
121+
this.leftLeg.xRot *= 0.5F
122+
123+
if (this.rightArm.xRot > 0.4F) {
124+
this.rightArm.xRot = 0.4F
125+
}
126+
127+
if (this.leftArm.xRot > 0.4F) {
128+
this.leftArm.xRot = 0.4F
129+
}
130+
131+
if (this.rightArm.xRot < -0.4F) {
132+
this.rightArm.xRot = -0.4F
133+
}
134+
135+
if (this.leftArm.xRot < -0.4F) {
136+
this.leftArm.xRot = -0.4F
137+
}
138+
139+
if (this.rightLeg.xRot > 0.4F) {
140+
this.rightLeg.xRot = 0.4F
141+
}
142+
143+
if (this.leftLeg.xRot > 0.4F) {
144+
this.leftLeg.xRot = 0.4F
145+
}
146+
147+
if (this.rightLeg.xRot < -0.4F) {
148+
this.rightLeg.xRot = -0.4F
149+
}
150+
151+
if (this.leftLeg.xRot < -0.4F) {
152+
this.leftLeg.xRot = -0.4F
153+
}
154+
155+
this.rightLeg.z = 0.0F
156+
this.leftLeg.z = 0.0F
157+
this.rightLeg.y = -5.0F
158+
this.leftLeg.y = -5.0F
159+
this.head.z = -0.0F
160+
this.head.y = -13.0F
161+
162+
this.head.y -= 5.0F
163+
164+
this.rightArm.setPos(-5.0F, -12.0F, 0.0F)
165+
this.leftArm.setPos(5.0F, -12.0F, 0.0F)
102166
}
103167

104168
override fun renderToBuffer(
@@ -137,6 +201,25 @@ class InsanityEntityRenderer(ctx: EntityRendererProvider.Context) :
137201
insanityModel.let { currentModel ->
138202
model = currentModel
139203
super.render(entity, entityYaw, partialTicks, poseStack, buffer, packedLight)
204+
205+
if (entity.entityData.get(InsanityEntity.DATA_MIMIC) == "enderman") {
206+
val vertexConsumer = buffer.getBuffer(RenderType.eyes(endermanEyesTexture))
207+
currentModel.renderToBuffer(poseStack, vertexConsumer, 15728640, OverlayTexture.NO_OVERLAY)
208+
209+
if (entity.isAggressive && entity.level().isClientSide) {
210+
if (entity.level().random.nextFloat() < 0.3f) {
211+
entity.level().addParticle(
212+
ParticleTypes.PORTAL,
213+
entity.x + (entity.level().random.nextDouble() - 0.5) * entity.bbWidth,
214+
entity.y + entity.level().random.nextDouble() * entity.bbHeight,
215+
entity.z + (entity.level().random.nextDouble() - 0.5) * entity.bbWidth,
216+
(entity.level().random.nextDouble() - 0.5) * 2.0,
217+
-entity.level().random.nextDouble(),
218+
(entity.level().random.nextDouble() - 0.5) * 2.0
219+
)
220+
}
221+
}
222+
}
140223
}
141224
}
142225

src/main/kotlin/dev/sterner/witchery/content/entity/InsanityEntity.kt

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.sterner.witchery.content.entity
22

33
import dev.sterner.witchery.core.registry.WitcheryEntityTypes
4+
import dev.sterner.witchery.mixin.EntityAccessor
45
import net.minecraft.core.particles.ParticleTypes
56
import net.minecraft.nbt.CompoundTag
67
import net.minecraft.network.syncher.EntityDataAccessor
@@ -28,11 +29,12 @@ class InsanityEntity(level: Level) : PathfinderMob(WitcheryEntityTypes.INSANITY.
2829
private var oldSwell = 0
2930
private var swell = 0
3031
private var maxSwell = 30
32+
private var hasPlayedAggroSound = false
3133

3234
override fun registerGoals() {
3335
this.goalSelector.addGoal(1, MeleeAttackGoal(this, 1.0, false))
3436
this.goalSelector.addGoal(2, WaterAvoidingRandomStrollGoal(this, 1.0))
35-
this.goalSelector.addGoal(3, LookAtPlayerGoal(this, Player::class.java, 8.0f))
37+
this.goalSelector.addGoal(3, LookAtPlayerGoal(this, Player::class.java, 16.0f))
3638
this.goalSelector.addGoal(4, RandomLookAroundGoal(this))
3739
this.goalSelector.addGoal(2, SwellGoal(this))
3840

@@ -43,6 +45,7 @@ class InsanityEntity(level: Level) : PathfinderMob(WitcheryEntityTypes.INSANITY.
4345
super.defineSynchedData(builder)
4446
builder.define(DATA_SWELL_DIR, -1)
4547
builder.define(DATA_MIMIC, "")
48+
builder.define(DATA_IS_AGGRESSIVE, false)
4649
}
4750

4851
fun getSwelling(partialTicks: Float): Float {
@@ -57,14 +60,19 @@ class InsanityEntity(level: Level) : PathfinderMob(WitcheryEntityTypes.INSANITY.
5760
): SpawnGroupData? {
5861
val mimicType: InsanityMobType = InsanityMobType.entries[Random.nextInt(InsanityMobType.entries.size)]
5962
entityData.set(DATA_MIMIC, mimicType.name.lowercase())
63+
if (mimicType.name.lowercase() == "enderman") {
64+
val accessor: EntityAccessor = this as EntityAccessor
65+
accessor.`witchery$setEyeHeight`(2.55f)
66+
67+
}
6068
return super.finalizeSpawn(level, difficulty, spawnType, spawnGroupData)
6169
}
6270

6371
companion object {
6472
fun createAttributes(): AttributeSupplier.Builder {
6573
return createMobAttributes()
6674
.add(Attributes.MAX_HEALTH, 1.0)
67-
.add(Attributes.MOVEMENT_SPEED, 0.25)
75+
.add(Attributes.MOVEMENT_SPEED, 0.32)
6876
.add(Attributes.ATTACK_DAMAGE, 0.0)
6977
}
7078

@@ -74,9 +82,28 @@ class InsanityEntity(level: Level) : PathfinderMob(WitcheryEntityTypes.INSANITY.
7482
val DATA_MIMIC: EntityDataAccessor<String> = SynchedEntityData.defineId(
7583
InsanityEntity::class.java, EntityDataSerializers.STRING
7684
)
85+
val DATA_IS_AGGRESSIVE: EntityDataAccessor<Boolean> = SynchedEntityData.defineId(
86+
InsanityEntity::class.java, EntityDataSerializers.BOOLEAN
87+
)
7788
}
7889

7990
override fun tick() {
91+
92+
93+
if (entityData.get(DATA_MIMIC) == InsanityMobType.ENDERMAN.name.lowercase()) {
94+
val hasTarget = target != null
95+
if (hasTarget && !entityData.get(DATA_IS_AGGRESSIVE)) {
96+
entityData.set(DATA_IS_AGGRESSIVE, true)
97+
if (!hasPlayedAggroSound) {
98+
playSound(SoundEvents.ENDERMAN_SCREAM, 0.7f, 1.0f)
99+
hasPlayedAggroSound = true
100+
}
101+
} else if (!hasTarget && entityData.get(DATA_IS_AGGRESSIVE)) {
102+
entityData.set(DATA_IS_AGGRESSIVE, false)
103+
hasPlayedAggroSound = false
104+
}
105+
}
106+
80107
if (entityData.get(DATA_MIMIC) == InsanityMobType.CREEPER.name.lowercase()) {
81108
if (this.isAlive) {
82109
this.oldSwell = this.swell
@@ -103,34 +130,33 @@ class InsanityEntity(level: Level) : PathfinderMob(WitcheryEntityTypes.INSANITY.
103130
if (Random.nextInt(200) == 0) {
104131
playMobSound()
105132
}
133+
this.target?.let {
134+
if (this.distanceToSqr(this.target!!) < 2f) {
135+
hurt(level().damageSources().generic(), 1f)
136+
}
137+
}
106138

107139
super.tick()
108140
}
109141

110142
private fun playMobSound() {
111143
if (entityData.get(DATA_MIMIC) == "zombie") {
112-
this.playSound(SoundEvents.ZOMBIE_AMBIENT, 1.0f, 1.0f)
144+
this.makeSound(SoundEvents.ZOMBIE_AMBIENT)
113145
}
114146
if (entityData.get(DATA_MIMIC) == "skeleton") {
115-
this.playSound(SoundEvents.SKELETON_AMBIENT, 1.0f, 1.0f)
147+
this.makeSound(SoundEvents.SKELETON_AMBIENT)
116148
}
117149
if (entityData.get(DATA_MIMIC) == "enderman") {
118-
this.playSound(SoundEvents.ENDERMAN_AMBIENT, 1.0f, 1.0f)
150+
this.makeSound(SoundEvents.ENDERMAN_AMBIENT)
119151
}
120152
}
121153

122154
private fun playerDeathSound() {
123-
if (entityData.get(DATA_MIMIC) == "zombie") {
124-
this.playSound(SoundEvents.ZOMBIE_HURT, 1.0f, 1.0f)
125-
}
126-
if (entityData.get(DATA_MIMIC) == "skeleton") {
127-
this.playSound(SoundEvents.SKELETON_HURT, 1.0f, 1.0f)
128-
}
129-
if (entityData.get(DATA_MIMIC) == "enderman") {
130-
this.playSound(SoundEvents.ENDERMAN_HURT, 1.0f, 1.0f)
131-
}
132-
if (entityData.get(DATA_MIMIC) == "creeper") {
133-
this.playSound(SoundEvents.CREEPER_HURT, 1.0f, 1.0f)
155+
when (entityData.get(DATA_MIMIC)) {
156+
"zombie" -> makeSound(SoundEvents.ZOMBIE_DEATH)
157+
"skeleton" -> makeSound(SoundEvents.SKELETON_DEATH)
158+
"enderman" -> makeSound(SoundEvents.ENDERMAN_DEATH)
159+
"creeper" -> makeSound(SoundEvents.CREEPER_DEATH)
134160
}
135161
}
136162

@@ -142,6 +168,7 @@ class InsanityEntity(level: Level) : PathfinderMob(WitcheryEntityTypes.INSANITY.
142168
super.addAdditionalSaveData(compound)
143169
compound.putShort("Fuse", maxSwell.toShort())
144170
compound.putString("Mimic", entityData.get(DATA_MIMIC))
171+
compound.putBoolean("IsAggressive", entityData.get(DATA_IS_AGGRESSIVE))
145172
}
146173

147174
override fun readAdditionalSaveData(compound: CompoundTag) {
@@ -152,32 +179,35 @@ class InsanityEntity(level: Level) : PathfinderMob(WitcheryEntityTypes.INSANITY.
152179
if (compound.contains("Mimic", 99)) {
153180
entityData.set(DATA_MIMIC, compound.getString("Mimic"))
154181
}
182+
if (compound.contains("IsAggressive")) {
183+
entityData.set(DATA_IS_AGGRESSIVE, compound.getBoolean("IsAggressive"))
184+
}
155185
}
156186

157187
override fun hurt(source: DamageSource, amount: Float): Boolean {
158-
if (source.entity is Player) {
159-
(0 until 20).forEach { i ->
160-
this.level().addParticle(
161-
ParticleTypes.POOF,
162-
this.x + (Random.nextDouble() - 0.5) * this.bbWidth,
163-
this.y + Random.nextDouble() * this.bbHeight,
164-
this.z + (Random.nextDouble() - 0.5) * this.bbWidth,
165-
0.0, 0.0, 0.0
166-
)
167-
playerDeathSound()
168-
}
169-
170-
this.remove(RemovalReason.KILLED)
171-
return true
188+
(0 until 20).forEach { i ->
189+
this.level().addParticle(
190+
ParticleTypes.POOF,
191+
this.x + (Random.nextDouble() - 0.5) * this.bbWidth,
192+
this.y + Random.nextDouble() * this.bbHeight,
193+
this.z + (Random.nextDouble() - 0.5) * this.bbWidth,
194+
0.0, 0.0, 0.0
195+
)
172196
}
197+
playerDeathSound()
173198

174-
return false
199+
this.remove(RemovalReason.KILLED)
200+
return true
175201
}
176202

177203
override fun isInvulnerableTo(source: DamageSource): Boolean {
178204
return source.entity !is Player || super.isInvulnerableTo(source)
179205
}
180206

207+
override fun isAggressive(): Boolean {
208+
return entityData.get(DATA_IS_AGGRESSIVE)
209+
}
210+
181211
enum class InsanityMobType {
182212
CREEPER,
183213
ZOMBIE,

src/main/kotlin/dev/sterner/witchery/core/registry/WitcheryEntityTypes.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ object WitcheryEntityTypes {
5050
{ _: EntityType<InsanityEntity>, level: Level ->
5151
InsanityEntity(level)
5252
}, MobCategory.MONSTER
53-
).sized(0.6f, 1.8f).build(Witchery.id("insanity").toString())
53+
).sized(0.75f, 2.0f).build(Witchery.id("insanity").toString())
5454
})
5555

5656
val AREA_EFFECT_CLOUD =

0 commit comments

Comments
 (0)