Skip to content

Commit

Permalink
I fucking hate jellyfish
Browse files Browse the repository at this point in the history
  • Loading branch information
MysticKoko committed Nov 27, 2024
1 parent 6fb7864 commit bf416fc
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import dev.hybridlabs.aquatic.client.model.entity.jellyfish.CosmicJellyfishEntit
import dev.hybridlabs.aquatic.entity.jellyfish.HybridAquaticJellyfishEntity
import net.minecraft.client.render.entity.EntityRendererFactory.Context

class CosmicJellyfishEntityRenderer(context: Context) : HybridAquaticJellyfishEntityRenderer<HybridAquaticJellyfishEntity>(context, CosmicJellyfishEntityModel(), true, true)
class CosmicJellyfishEntityRenderer(context: Context) : HybridAquaticJellyfishEntityRenderer<HybridAquaticJellyfishEntity>(context, CosmicJellyfishEntityModel(), true, false)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import dev.hybridlabs.aquatic.entity.jellyfish.HybridAquaticJellyfishEntity
import net.minecraft.client.render.VertexConsumerProvider
import net.minecraft.client.render.entity.EntityRendererFactory
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.util.math.MathHelper
import net.minecraft.util.math.RotationAxis
import software.bernie.geckolib.model.GeoModel
import software.bernie.geckolib.renderer.GeoEntityRenderer
import software.bernie.geckolib.renderer.layer.AutoGlowingGeoLayer
Expand All @@ -15,6 +17,16 @@ open class HybridAquaticJellyfishEntityRenderer<T: HybridAquaticJellyfishEntity>
if(canGlow) addRenderLayer(AutoGlowingGeoLayer(this))
}

override fun applyRotations(jellyfishEntity: T, matrixStack: MatrixStack, f: Float, g: Float, h: Float) {
val i = MathHelper.lerp(h, jellyfishEntity.prevTiltAngle, jellyfishEntity.tiltAngle)
val j = MathHelper.lerp(h, jellyfishEntity.prevRollAngle, jellyfishEntity.rollAngle)
matrixStack.translate(0.0f, 0.25f, 0.0f)
matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180.0f - g))
matrixStack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(i))
matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(j))
matrixStack.translate(0.0f, 0.0f, 0.0f)
}

override fun render(
entity: T,
entityYaw: Float,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ open class HybridAquaticCephalopodEntity(
set(hunger) {
dataTracker.set(HUNGER, hunger)
}

private var attemptAttack: Boolean
get() = dataTracker.get(ATTEMPT_ATTACK)
set(attemptAttack) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.hybridlabs.aquatic.entity.jellyfish

import dev.hybridlabs.aquatic.entity.ai.goal.StayDeepGoal
import net.minecraft.entity.EntityType
import net.minecraft.entity.attribute.DefaultAttributeContainer
import net.minecraft.entity.attribute.EntityAttributes
Expand All @@ -13,11 +12,6 @@ class AtollaJellyfishEntity(entityType: EntityType<out AtollaJellyfishEntity>, w
return 2
}

override fun initGoals() {
super.initGoals()
goalSelector.add(0, StayDeepGoal(this))
}

companion object {
fun createMobAttributes(): DefaultAttributeContainer.Builder {
return WaterCreatureEntity.createMobAttributes()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.hybridlabs.aquatic.entity.jellyfish

import dev.hybridlabs.aquatic.entity.ai.goal.StayDeepGoal
import net.minecraft.entity.EntityType
import net.minecraft.entity.attribute.DefaultAttributeContainer
import net.minecraft.entity.attribute.EntityAttributes
Expand All @@ -13,11 +12,6 @@ class BigRedJellyfishEntity(entityType: EntityType<out BigRedJellyfishEntity>, w
return 2
}

override fun initGoals() {
super.initGoals()
goalSelector.add(0, StayDeepGoal(this))
}

companion object {
fun createMobAttributes(): DefaultAttributeContainer.Builder {
return WaterCreatureEntity.createMobAttributes()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.hybridlabs.aquatic.entity.jellyfish

import dev.hybridlabs.aquatic.entity.ai.goal.StayDeepGoal
import net.minecraft.entity.EntityType
import net.minecraft.entity.attribute.DefaultAttributeContainer
import net.minecraft.entity.attribute.EntityAttributes
Expand All @@ -13,11 +12,6 @@ class CosmicJellyfishEntity(entityType: EntityType<out CosmicJellyfishEntity>, w
return 2
}

override fun initGoals() {
super.initGoals()
goalSelector.add(0, StayDeepGoal(this))
}

companion object {
fun createMobAttributes(): DefaultAttributeContainer.Builder {
return WaterCreatureEntity.createMobAttributes()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package dev.hybridlabs.aquatic.entity.jellyfish

import dev.hybridlabs.aquatic.entity.ai.goal.StayInWaterGoal
import net.minecraft.entity.EntityDimensions
import net.minecraft.entity.EntityPose
import net.minecraft.entity.EntityType
import net.minecraft.entity.SpawnReason
import net.minecraft.entity.*
import net.minecraft.entity.ai.control.AquaticMoveControl
import net.minecraft.entity.ai.control.YawAdjustingLookControl
import net.minecraft.entity.ai.goal.SwimAroundGoal
import net.minecraft.entity.ai.pathing.EntityNavigation
import net.minecraft.entity.ai.goal.Goal
import net.minecraft.entity.ai.pathing.PathNodeType
import net.minecraft.entity.ai.pathing.SwimNavigation
import net.minecraft.entity.damage.DamageSource
Expand All @@ -18,15 +14,15 @@ import net.minecraft.entity.data.TrackedDataHandlerRegistry
import net.minecraft.entity.effect.StatusEffectInstance
import net.minecraft.entity.effect.StatusEffects
import net.minecraft.entity.mob.WaterCreatureEntity
import net.minecraft.entity.passive.TurtleEntity
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.nbt.NbtCompound
import net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket
import net.minecraft.registry.tag.FluidTags
import net.minecraft.server.network.ServerPlayerEntity
import net.minecraft.sound.SoundEvent
import net.minecraft.sound.SoundEvents
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.MathHelper
import net.minecraft.util.math.Vec3d
import net.minecraft.util.math.random.Random
import net.minecraft.world.World
import net.minecraft.world.WorldAccess
Expand All @@ -47,8 +43,24 @@ open class HybridAquaticJellyfishEntity(

) : WaterCreatureEntity(type, world), GeoEntity {
private val factory = GeckoLibUtil.createInstanceCache(this)
var tiltAngle: Float = 0f
var prevTiltAngle: Float = 0f
var rollAngle: Float = 0f
var prevRollAngle: Float = 0f
private var thrustTimer: Float = 0f
private var prevThrustTimer: Float = 0f
private var swimVelocityScale = 0f
private var thrustTimerSpeed = 0f
private var tentacleAngle: Float = 0f
private var prevTentacleAngle: Float = 0f
private var turningSpeed = 0f
private var swimX = 0f
private var swimY = 0f
private var swimZ = 0f

init {
random.setSeed(id.toLong())
this.thrustTimerSpeed = 1.0f / (random.nextFloat() + 1.0f) * 0.2f
setPathfindingPenalty(PathNodeType.WATER, 0.0f)
setPathfindingPenalty(PathNodeType.WALKABLE, 10.0f)
moveControl = AquaticMoveControl(this, 85, 10, 0.05F, 0.1F, true)
Expand All @@ -57,7 +69,7 @@ open class HybridAquaticJellyfishEntity(
}

override fun initGoals() {
goalSelector.add(3, SwimAroundGoal(this, 1.0, 10))
goalSelector.add(0, SwimGoal(this))
goalSelector.add(0, StayInWaterGoal(this))
}

Expand Down Expand Up @@ -87,14 +99,14 @@ open class HybridAquaticJellyfishEntity(
return SoundEvents.ENTITY_SLIME_DEATH
}

override fun createNavigation(world: World): EntityNavigation {
return SwimNavigation(this, world)
}

override fun getSoundVolume(): Float {
return 0.4f
}

override fun getMoveEffect(): MoveEffect {
return MoveEffect.EVENTS
}

override fun tick() {
super.tick()
if (isAiDisabled) {
Expand All @@ -112,10 +124,83 @@ open class HybridAquaticJellyfishEntity(
}
}



override fun canImmediatelyDespawn(distanceSquared: Double): Boolean {
return !fromFishingNet && !hasCustomName()
}

override fun tickMovement() {
super.tickMovement()
this.prevTiltAngle = this.tiltAngle
this.prevRollAngle = this.rollAngle
this.prevThrustTimer = this.thrustTimer
this.prevTentacleAngle = this.tentacleAngle
this.thrustTimer += this.thrustTimerSpeed
if (thrustTimer.toDouble() > 6.283185307179586) {
if (world.isClient) {
this.thrustTimer = 6.2831855f
} else {
this.thrustTimer -= 6.2831855f
if (random.nextInt(10) == 0) {
this.thrustTimerSpeed = 1.0f / (random.nextFloat() + 1.0f) * 0.2f
}

world.sendEntityStatus(this, 19.toByte())
}
}

if (this.isInsideWaterOrBubbleColumn) {
if (this.thrustTimer < 3.1415927f) {
val f = this.thrustTimer / 3.1415927f
this.tentacleAngle = MathHelper.sin(f * f * 3.1415927f) * 3.1415927f * 0.25f
if (f.toDouble() > 0.75) {
this.swimVelocityScale = 0.5f
this.turningSpeed = 0.5f
} else {
this.turningSpeed *= 0.8f
}
} else {
this.tentacleAngle = 0.0f
this.swimVelocityScale *= 0.9f
this.turningSpeed *= 0.99f
}

if (!world.isClient) {
this.setVelocity(
(this.swimX * this.swimVelocityScale).toDouble(),
(this.swimY * this.swimVelocityScale).toDouble(),
(this.swimZ * this.swimVelocityScale).toDouble()
)
}

val vec3d = this.velocity
val d = vec3d.horizontalLength()
this.bodyYaw += (-(MathHelper.atan2(vec3d.x, vec3d.z).toFloat()) * 57.295776f - this.bodyYaw) * 0.1f
this.yaw = this.bodyYaw
this.rollAngle += 3.1415927f * this.turningSpeed * 1.5f
this.tiltAngle += (-(MathHelper.atan2(d, vec3d.y).toFloat()) * 57.295776f - this.tiltAngle) * 0.1f
} else {
this.tentacleAngle = MathHelper.abs(MathHelper.sin(this.thrustTimer)) * 3.1415927f * 0.25f
if (!world.isClient) {
var e = velocity.y
if (this.hasStatusEffect(StatusEffects.LEVITATION)) {
e = 0.05 * (getStatusEffect(StatusEffects.LEVITATION)!!.amplifier + 1).toDouble()
} else if (!this.hasNoGravity()) {
e -= 0.08
}

this.setVelocity(0.0, e * 0.9800000190734863, 0.0)


}

this.tiltAngle += (-90.0f - this.tiltAngle) * 0.02f
}


}

override fun damage(source: DamageSource?, amount: Float): Boolean {
if (super.damage(source, amount)) {

Expand All @@ -139,10 +224,44 @@ open class HybridAquaticJellyfishEntity(
}
}

override fun dropLoot(source: DamageSource, causedByPlayer: Boolean) {
val attacker = source.attacker
if (attacker !is TurtleEntity) {
super.dropLoot(source, causedByPlayer)
override fun travel(movementInput: Vec3d?) {
this.move(MovementType.SELF, this.velocity)
}

override fun handleStatus(status: Byte) {
if (status.toInt() == 19) {
this.thrustTimer = 0.0f
} else {
super.handleStatus(status)
}
}

fun setSwimmingVector(x: Float, y: Float, z: Float) {
this.swimX = x
this.swimY = y
this.swimZ = z
}

fun hasSwimmingVector(): Boolean {
return this.swimX != 0.0f || (this.swimY != 0.0f) || (this.swimZ != 0.0f)
}

internal class SwimGoal(private val jellyfish: HybridAquaticJellyfishEntity) : Goal() {
override fun canStart(): Boolean {
return true
}

override fun tick() {
val i = jellyfish.despawnCounter
if (i > 100) {
jellyfish.setSwimmingVector(0.0f, 0.0f, 0.0f)
} else if (jellyfish.random.nextInt(toGoalTicks(50)) == 0 || !jellyfish.touchingWater || !jellyfish.hasSwimmingVector()) {
val f = jellyfish.random.nextFloat() * 6.2831855f
val g = MathHelper.cos(f) * 0.2f
val h = -0.1f + jellyfish.random.nextFloat() * 0.2f
val j = MathHelper.sin(f) * 0.2f
jellyfish.setSwimmingVector(g, h, j)
}
}
}

Expand All @@ -168,7 +287,7 @@ open class HybridAquaticJellyfishEntity(
if (state.isMoving) {
state.setAndContinue(DefaultAnimations.SWIM)
} else {
state.setAndContinue(DefaultAnimations.IDLE)
state.setAndContinue(DefaultAnimations.SWIM)
}
}.setOverrideEasingType(EasingType.EASE_IN_OUT_SINE)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,57 +79,35 @@
"animation_length": 4,
"bones": {
"tentacle_1_1": {
"rotation": {
"vector": ["Math.cos(query.anim_time * 90)*-7.5", 0, 0]
}
"rotation": ["Math.cos(query.anim_time * 90)*-7.5", 0, 0]
},
"tentacle_1_2": {
"rotation": {
"vector": ["Math.sin(query.anim_time * 90)*-10", 0, 0]
}
"rotation": ["Math.sin(query.anim_time * 90)*-10", 0, 0]
},
"tentacle_2_1": {
"rotation": {
"vector": ["Math.cos(query.anim_time * 90)*7.5", 0, 0]
}
"rotation": ["Math.cos(query.anim_time * 90)*7.5", 0, 0]
},
"tentacle_2_2": {
"rotation": {
"vector": ["Math.sin(query.anim_time * 90)*10", 0, 0]
}
"rotation": ["Math.sin(query.anim_time * 90)*10", 0, 0]
},
"tentacle_3_1": {
"rotation": {
"vector": [0, "Math.cos(query.anim_time * 90)*7.5", 0]
}
"rotation": [0, "Math.cos(query.anim_time * 90)*7.5", 0]
},
"tentacle_3_2": {
"rotation": {
"vector": [0, "Math.sin(query.anim_time * 90)*10", 0]
}
"rotation": [0, "Math.sin(query.anim_time * 90)*10", 0]
},
"tentacle_4_1": {
"rotation": {
"vector": [0, "Math.cos(query.anim_time * 90)*-7.5", 0]
}
"rotation": [0, "Math.cos(query.anim_time * 90)*-7.5", 0]
},
"tentacle_4_2": {
"rotation": {
"vector": [0, "Math.sin(query.anim_time * 90)*-10", 0]
}
"rotation": [0, "Math.sin(query.anim_time * 90)*-10", 0]
},
"body": {
"position": {
"vector": [0, 0, "Math.cos(query.anim_time * 90)*1"]
},
"scale": {
"vector": [1, 1, 1]
}
"position": [0, "Math.cos(query.anim_time * 90)*1", 0],
"scale": 1
},
"bell": {
"scale": {
"vector": ["1+Math.cos(query.anim_time * 90)*0.05", "1+Math.cos(query.anim_time * 90)*0.05", "1+Math.cos(query.anim_time * 90)*0.05"]
}
"scale": "1+Math.cos(query.anim_time * 90)*0.05"
}
}
}
Expand Down
Loading

0 comments on commit bf416fc

Please sign in to comment.