Skip to content

Commit

Permalink
Added jumping behaviour to threshers, great whites, and manta rays
Browse files Browse the repository at this point in the history
  • Loading branch information
MysticKoko committed Dec 1, 2024
1 parent 83f83dd commit 3481e46
Show file tree
Hide file tree
Showing 22 changed files with 311 additions and 561 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.hybridlabs.aquatic.client.model.entity.fish

import dev.hybridlabs.aquatic.entity.fish.HybridAquaticFishEntity
import dev.hybridlabs.aquatic.entity.fish.ray.HybridAquaticRayEntity

class MantaRayEntityModel : HybridAquaticRayEntityModel<HybridAquaticRayEntity>("manta_ray")
class MantaRayEntityModel : HybridAquaticFishEntityModel<HybridAquaticFishEntity>("manta_ray")
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package dev.hybridlabs.aquatic.client.model.entity.fish

import dev.hybridlabs.aquatic.entity.fish.ray.HybridAquaticRayEntity
import dev.hybridlabs.aquatic.entity.fish.HybridAquaticFishEntity

class StingrayEntityModel : HybridAquaticRayEntityModel<HybridAquaticRayEntity>("stingray")
class StingrayEntityModel : HybridAquaticFishEntityModel<HybridAquaticFishEntity>("stingray")

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dev.hybridlabs.aquatic.client.render.entity.fish

import dev.hybridlabs.aquatic.client.model.entity.fish.MantaRayEntityModel
import dev.hybridlabs.aquatic.entity.fish.HybridAquaticFishEntity
import dev.hybridlabs.aquatic.entity.fish.ray.HybridAquaticRayEntity
import net.minecraft.client.render.entity.EntityRendererFactory.Context

class MantaRayEntityRenderer(context: Context) : HybridAquaticRayEntityRenderer<HybridAquaticRayEntity>(context, MantaRayEntityModel(), true, false)
class MantaRayEntityRenderer(context: Context) : HybridAquaticFishEntityRenderer<HybridAquaticFishEntity>(context, MantaRayEntityModel(), true, false)
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package dev.hybridlabs.aquatic.client.render.entity.fish

import dev.hybridlabs.aquatic.client.model.entity.fish.StingrayEntityModel
import dev.hybridlabs.aquatic.entity.fish.HybridAquaticFishEntity
import dev.hybridlabs.aquatic.entity.fish.ray.HybridAquaticRayEntity
import net.minecraft.client.render.entity.EntityRendererFactory.Context

class StingrayEntityRenderer(context: Context) : HybridAquaticRayEntityRenderer<HybridAquaticRayEntity>(context,
class StingrayEntityRenderer(context: Context) : HybridAquaticFishEntityRenderer<HybridAquaticFishEntity>(context,
StingrayEntityModel(), true, false)

Original file line number Diff line number Diff line change
Expand Up @@ -600,56 +600,56 @@ object HybridAquaticEntityTypes {
val BASKING_SHARK = registerShark(
"basking_shark",
::BaskingSharkEntity,
EntityDimensions.fixed(2.5f, 1.0f),
EntityDimensions.fixed(2.5f, 0.8f),
BaskingSharkEntity.createMobAttributes()
)

val BULL_SHARK = registerShark(
"bull_shark",
::BullSharkEntity,
EntityDimensions.fixed(1.5f, 0.6f),
EntityDimensions.fixed(1.75f, 0.6f),
BullSharkEntity.createMobAttributes()
)

val FRILLED_SHARK = registerSharkUnderground(
"frilled_shark",
::FrilledSharkEntity,
EntityDimensions.fixed(1.0f, 0.5f),
EntityDimensions.fixed(1.25f, 0.5f),
FrilledSharkEntity.createMobAttributes()
)

val GREAT_WHITE_SHARK = registerShark(
"great_white_shark",
::GreatWhiteSharkEntity,
EntityDimensions.fixed(2.0f, 0.75f),
EntityDimensions.fixed(1.75f, 0.6f),
GreatWhiteSharkEntity.createMobAttributes()
)

val HAMMERHEAD_SHARK = registerShark(
"hammerhead_shark",
::HammerheadSharkEntity,
EntityDimensions.fixed(1.5f, 0.75f),
EntityDimensions.fixed(1.5f, 0.6f),
HammerheadSharkEntity.createMobAttributes()
)

val THRESHER_SHARK = registerShark(
"thresher_shark",
::ThresherSharkEntity,
EntityDimensions.fixed(1.5f, 0.75f),
EntityDimensions.fixed(1.5f, 0.5f),
ThresherSharkEntity.createMobAttributes()
)

val TIGER_SHARK = registerShark(
"tiger_shark",
::TigerSharkEntity,
EntityDimensions.fixed(1.75f, 0.75f),
EntityDimensions.fixed(1.75f, 0.6f),
TigerSharkEntity.createMobAttributes()
)

val WHALE_SHARK = registerShark(
"whale_shark",
::WhaleSharkEntity,
EntityDimensions.fixed(2.5f, 1.0f),
EntityDimensions.fixed(2.5f, 0.8f),
WhaleSharkEntity.createMobAttributes()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import dev.hybridlabs.aquatic.entity.cephalopod.HybridAquaticCephalopodEntity
import dev.hybridlabs.aquatic.entity.critter.HybridAquaticCritterEntity
import dev.hybridlabs.aquatic.entity.crustacean.HybridAquaticCrustaceanEntity
import dev.hybridlabs.aquatic.entity.fish.HybridAquaticFishEntity
import dev.hybridlabs.aquatic.entity.fish.ray.HybridAquaticRayEntity
import dev.hybridlabs.aquatic.entity.jellyfish.HybridAquaticJellyfishEntity
import dev.hybridlabs.aquatic.entity.miniboss.HybridAquaticMinibossEntity
import dev.hybridlabs.aquatic.entity.shark.HybridAquaticSharkEntity
Expand Down Expand Up @@ -55,6 +54,8 @@ object SpawnRestrictionRegistry {
HybridAquaticEntityTypes.NEEDLEFISH,
HybridAquaticEntityTypes.MACKEREL,
HybridAquaticEntityTypes.CARP,
HybridAquaticEntityTypes.STINGRAY,
HybridAquaticEntityTypes.MANTA_RAY,
).forEach { registerFish(it) }

// underground fish
Expand All @@ -66,12 +67,6 @@ object SpawnRestrictionRegistry {
HybridAquaticEntityTypes.RATFISH,
).forEach { registerFishUnderground(it) }

// rays
setOf(
HybridAquaticEntityTypes.STINGRAY,
HybridAquaticEntityTypes.MANTA_RAY,
).forEach { registerRay(it) }

// cephalopods
setOf(
HybridAquaticEntityTypes.ARROW_SQUID,
Expand Down Expand Up @@ -167,10 +162,6 @@ object SpawnRestrictionRegistry {
registerWaterCreature(entityType, HybridAquaticFishEntity::canUndergroundSpawn)
}

private fun <T : WaterCreatureEntity> registerRay(entityType: EntityType<T>) {
registerWaterCreature(entityType, HybridAquaticRayEntity::canSpawn)
}

private fun <T : WaterCreatureEntity> registerCephalopod(entityType: EntityType<T>) {
registerWaterCreature(entityType, HybridAquaticCephalopodEntity::canSpawn)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package dev.hybridlabs.aquatic.entity.ai.goal

import dev.hybridlabs.aquatic.entity.shark.HybridAquaticSharkEntity
import net.minecraft.entity.ai.goal.DiveJumpingGoal
import net.minecraft.registry.tag.FluidTags
import net.minecraft.sound.SoundEvents
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.MathHelper
import kotlin.math.abs
import kotlin.math.atan2

@Suppress("DEPRECATION")
class SharkJumpGoal(private val shark: HybridAquaticSharkEntity, chance: Int) : DiveJumpingGoal() {
private val chance: Int = toGoalTicks(chance)
private var inWater = false

override fun canStart(): Boolean {
return if (shark.random.nextInt(chance) != 0) {
false
} else {
val direction = shark.movementDirection
val i = direction.offsetX
val j = direction.offsetZ
val blockPos = shark.blockPos
val var5 = OFFSET_MULTIPLIERS
val var6 = var5.size
for (var7 in 0 until var6) {
val k = var5[var7]
if (!isWater(blockPos, i, j, k) || !isAirAbove(blockPos, i, j, k)) {
return false
}
}
true
}
}

private fun isWater(pos: BlockPos, offsetX: Int, offsetZ: Int, multiplier: Int): Boolean {
val blockPos = pos.add(offsetX * multiplier, 0, offsetZ * multiplier)
return shark.world.getFluidState(blockPos).isIn(FluidTags.WATER) && !shark.world.getBlockState(blockPos)
.blocksMovement()
}

private fun isAirAbove(pos: BlockPos, offsetX: Int, offsetZ: Int, multiplier: Int): Boolean {
return shark.world.getBlockState(
pos.add(
offsetX * multiplier,
1,
offsetZ * multiplier
)
).isAir && shark.world.getBlockState(pos.add(offsetX * multiplier, 2, offsetZ * multiplier)).isAir
}

override fun shouldContinue(): Boolean {
val d = shark.velocity.y
return (!(d * d < 0.029999999329447746) || shark.pitch == 0.0f || !(abs(shark.pitch) < 10.0f) || !shark.isTouchingWater) && !shark.isOnGround
}

override fun canStop(): Boolean {
return false
}

override fun start() {
val direction = shark.movementDirection
shark.velocity =
shark.velocity.add(direction.offsetX.toDouble() * 0.6, 1.4, direction.offsetZ.toDouble() * 0.6)
shark.navigation.stop()
}

override fun stop() {
shark.pitch = 0.0f
}

override fun tick() {
val bl = inWater
if (!bl) {
val fluidState = shark.world.getFluidState(shark.blockPos)
inWater = fluidState.isIn(FluidTags.WATER)
}
if (inWater && !bl) {
shark.playSound(SoundEvents.ENTITY_DOLPHIN_JUMP, 1.0f, 1.0f)
}
val vec3d = shark.velocity
if (vec3d.y * vec3d.y < 0.029999999329447746 && shark.pitch != 0.0f) {
shark.pitch = MathHelper.lerpAngleDegrees(0.2f, shark.pitch, 0.0f)
} else if (vec3d.length() > 9.999999747378752E-6) {
val d = vec3d.horizontalLength()
val e = atan2(-vec3d.y, d) * 57.2957763671875
shark.pitch = e.toFloat()
}
}

companion object {
private val OFFSET_MULTIPLIERS = intArrayOf(0, 1, 4, 5, 6, 7)
}
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.hybridlabs.aquatic.entity.cephalopod

import dev.hybridlabs.aquatic.entity.fish.HybridAquaticFishEntity
import dev.hybridlabs.aquatic.entity.fish.ray.HybridAquaticRayEntity
import dev.hybridlabs.aquatic.entity.shark.HybridAquaticSharkEntity
import net.minecraft.block.Blocks
import net.minecraft.entity.*
Expand Down Expand Up @@ -154,7 +153,7 @@ open class HybridAquaticCephalopodEntity(

override fun dropLoot(source: DamageSource, causedByPlayer: Boolean) {
val attacker = source.attacker
if (attacker !is HybridAquaticFishEntity && attacker !is HybridAquaticSharkEntity && attacker !is HybridAquaticRayEntity && attacker !is HybridAquaticCephalopodEntity) {
if (attacker !is HybridAquaticFishEntity && attacker !is HybridAquaticSharkEntity && attacker !is HybridAquaticCephalopodEntity) {
super.dropLoot(source, causedByPlayer)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dev.hybridlabs.aquatic.entity.crustacean

import dev.hybridlabs.aquatic.entity.cephalopod.HybridAquaticCephalopodEntity
import dev.hybridlabs.aquatic.entity.fish.HybridAquaticFishEntity
import dev.hybridlabs.aquatic.entity.fish.ray.HybridAquaticRayEntity
import dev.hybridlabs.aquatic.entity.shark.HybridAquaticSharkEntity
import dev.hybridlabs.aquatic.tag.HybridAquaticBlockTags
import net.minecraft.block.Blocks
Expand Down Expand Up @@ -241,7 +240,7 @@ open class HybridAquaticCrustaceanEntity(

override fun dropLoot(source: DamageSource, causedByPlayer: Boolean) {
val attacker = source.attacker
if (attacker !is HybridAquaticFishEntity && attacker !is HybridAquaticSharkEntity && attacker !is HybridAquaticRayEntity && attacker !is HybridAquaticCephalopodEntity) {
if (attacker !is HybridAquaticFishEntity && attacker !is HybridAquaticSharkEntity && attacker !is HybridAquaticCephalopodEntity) {
super.dropLoot(source, causedByPlayer)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ class AfricanButterflyEntity(entityType: EntityType<out AfricanButterflyEntity>,
return 1
}

//#region Air & Jumping
override fun initGoals() {
super.initGoals()
goalSelector.add(2, BreatheAirGoal(this))
targetSelector.add(5, FishJumpGoal(this, 10))
}

init {
this.air = 300
}
Expand All @@ -36,12 +43,6 @@ class AfricanButterflyEntity(entityType: EntityType<out AfricanButterflyEntity>,
return super.getAir().coerceAtLeast(0)
}

override fun initGoals() {
super.initGoals()
goalSelector.add(2, BreatheAirGoal(this))
targetSelector.add(5, FishJumpGoal(this, 10))
}

override fun tick() {
super.tick()

Expand Down Expand Up @@ -82,6 +83,8 @@ class AfricanButterflyEntity(entityType: EntityType<out AfricanButterflyEntity>,
this.velocity = newMotion
}

//#endergion

companion object {
fun createMobAttributes(): DefaultAttributeContainer.Builder {
return WaterCreatureEntity.createMobAttributes()
Expand Down
Loading

0 comments on commit 3481e46

Please sign in to comment.