Skip to content

Commit

Permalink
Changes to fish behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
MysticKoko committed Nov 18, 2023
1 parent 422c438 commit b691d90
Show file tree
Hide file tree
Showing 17 changed files with 63 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GlowingSuckerOctopusEntity(entityType: EntityType<out GlowingSuckerOctopus
fun createMobAttributes(): DefaultAttributeContainer.Builder {
return WaterCreatureEntity.createMobAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 12.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 1.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.7)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 2.0)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 20.0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MorayEelEntity(entityType: EntityType<out MorayEelEntity>, world: World) :
fun createMobAttributes(): DefaultAttributeContainer.Builder {
return WaterCreatureEntity.createMobAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 12.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 1.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.75)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 2.0)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 20.0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class OarfishEntity(entityType: EntityType<out OarfishEntity>, world: World) :
fun createMobAttributes(): DefaultAttributeContainer.Builder {
return WaterCreatureEntity.createMobAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 18.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 1.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.75)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 2.0)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 20.0)
.add(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, 100.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class OpahEntity(entityType: EntityType<out OpahEntity>, world: World) : HybridA
fun createMobAttributes(): DefaultAttributeContainer.Builder {
return WaterCreatureEntity.createMobAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 12.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 1.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.75)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 2.0)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 20.0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class RatfishEntity(entityType: EntityType<out RatfishEntity>, world: World) :
fun createMobAttributes(): DefaultAttributeContainer.Builder {
return WaterCreatureEntity.createMobAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 6.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.9)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 2.0)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 20.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.6)

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class RockfishEntity(entityType: EntityType<out RockfishEntity>, world: World) :
fun createMobAttributes(): DefaultAttributeContainer.Builder {
return WaterCreatureEntity.createMobAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 6.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 1.0)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 2.0)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 20.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.8)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class SeaAngelEntity(entityType: EntityType<out SeaAngelEntity>, world: World) :
fun createMobAttributes(): DefaultAttributeContainer.Builder {
return WaterCreatureEntity.createMobAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 3.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.85)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 2.0)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 20.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.5)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ import net.minecraft.entity.EntityType
import net.minecraft.entity.attribute.DefaultAttributeContainer
import net.minecraft.entity.attribute.EntityAttributes
import net.minecraft.entity.mob.WaterCreatureEntity
import net.minecraft.registry.tag.BlockTags
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Vec3d
import net.minecraft.world.World

class SeahorseEntity(entityType: EntityType<out SeahorseEntity>, world: World) :
HybridAquaticFishEntity(entityType, world, 6) {

private var targetCoralPos: BlockPos? = null

companion object {
fun createMobAttributes(): DefaultAttributeContainer.Builder {
return WaterCreatureEntity.createMobAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 3.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.85)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 2.0)
.add(EntityAttributes.GENERIC_MAX_HEALTH, 2.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.6)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 20.0)

}
}

Expand All @@ -26,4 +30,44 @@ class SeahorseEntity(entityType: EntityType<out SeahorseEntity>, world: World) :
override fun getMinSize(): Int {
return -5
}

override fun tick() {
super.tick()

if (targetCoralPos == null || world.getBlockState(targetCoralPos).isIn(BlockTags.CORAL_PLANTS)) {
targetCoralPos = findNearbyCoralBlock()
}

if (targetCoralPos != null) {
val distanceToCoral = distanceTo(targetCoralPos!!)

if (distanceToCoral > 5.0) {
navigateToCoral(targetCoralPos!!)
}
}
}

private fun navigateToCoral(coralBlockPos: BlockPos) {
this.navigation.startMovingTo(coralBlockPos.x.toDouble(), coralBlockPos.y.toDouble(), coralBlockPos.z.toDouble(), 1.0)
}

private fun findNearbyCoralBlock(): BlockPos? {
for (i in -5..5) {
for (j in -5..5) {
for (k in -5..5) {
val blockPos = BlockPos((x + i).toInt(), (y + j).toInt(), (z + k).toInt())
val blockState = world.getBlockState(blockPos)

if (blockState.isIn(BlockTags.CORAL_PLANTS)) {
return blockPos
}
}
}
}
return null
}

private fun distanceTo(pos: BlockPos): Double {
return this.blockPos.getSquaredDistance(pos.x.toDouble(), pos.y.toDouble(), pos.z.toDouble())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ class StonefishEntity(entityType: EntityType<out StonefishEntity>, world: World)
fun createMobAttributes(): DefaultAttributeContainer.Builder {
return WaterCreatureEntity.createMobAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 6.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.85)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 2.0)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 20.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.6)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ class SunfishEntity(entityType: EntityType<out SunfishEntity>, world: World) :
fun createMobAttributes(): DefaultAttributeContainer.Builder {
return WaterCreatureEntity.createMobAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 18.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 1.0)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 2.0)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 20.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.75)
.add(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, 100.0)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TetraEntity(entityType: EntityType<out TetraEntity>, world: World) :
fun createMobAttributes(): DefaultAttributeContainer.Builder {
return WaterCreatureEntity.createMobAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 3.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 1.2)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.8)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 2.0)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 20.0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class TigerBarbEntity(entityType: EntityType<out TigerBarbEntity>, world: World)
fun createMobAttributes(): DefaultAttributeContainer.Builder {
return WaterCreatureEntity.createMobAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 6.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 1.2)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 2.0)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 20.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.8)

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ class ToadfishEntity(entityType: EntityType<out ToadfishEntity>, world: World) :
fun createMobAttributes(): DefaultAttributeContainer.Builder {
return WaterCreatureEntity.createMobAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 6.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.9)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 2.0)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 20.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.6)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class TriggerfishEntity(entityType: EntityType<out TriggerfishEntity>, world: Wo
fun createMobAttributes(): DefaultAttributeContainer.Builder {
return WaterCreatureEntity.createMobAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 12.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 1.0)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 2.0)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 20.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.8)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class UnicornFishEntity(entityType: EntityType<out UnicornFishEntity>, world: Wo
fun createMobAttributes(): DefaultAttributeContainer.Builder {
return WaterCreatureEntity.createMobAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 6.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 1.0)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 2.0)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 20.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.8)

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class ZebraDanioEntity(entityType: EntityType<out ZebraDanioEntity>, world: Worl
fun createMobAttributes(): DefaultAttributeContainer.Builder {
return WaterCreatureEntity.createMobAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 3.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 1.0)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 2.0)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 20.0)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.8)

}
}
Expand Down

0 comments on commit b691d90

Please sign in to comment.