-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d994b8
commit db42c1b
Showing
26 changed files
with
125 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/dev/hybridlabs/aquatic/entity/SpawnRestrictionRegistry.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...uatic/entity/critter/CoconutCrabEntity.kt → ...ic/entity/crustacean/CoconutCrabEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
.../aquatic/entity/critter/CrayfishEntity.kt → ...uatic/entity/crustacean/CrayfishEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...tic/entity/critter/DungenessCrabEntity.kt → .../entity/crustacean/DungenessCrabEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...uatic/entity/critter/FiddlerCrabEntity.kt → ...ic/entity/crustacean/FiddlerCrabEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...quatic/entity/critter/FlowerCrabEntity.kt → ...tic/entity/crustacean/FlowerCrabEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...aquatic/entity/critter/GhostCrabEntity.kt → ...atic/entity/crustacean/GhostCrabEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...uatic/entity/critter/GiantIsopodEntity.kt → ...ic/entity/crustacean/GiantIsopodEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...quatic/entity/critter/HermitCrabEntity.kt → ...tic/entity/crustacean/HermitCrabEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...tic/entity/critter/HorseshoeCrabEntity.kt → .../entity/crustacean/HorseshoeCrabEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...entity/critter/HybridAquaticCrabEntity.kt → ...ity/crustacean/HybridAquaticCrabEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
.../aquatic/entity/critter/KarkinosEntity.kt → ...uatic/entity/crustacean/KarkinosEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...tic/entity/critter/LightfootCrabEntity.kt → .../entity/crustacean/LightfootCrabEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...s/aquatic/entity/critter/LobsterEntity.kt → ...quatic/entity/crustacean/LobsterEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...bs/aquatic/entity/critter/ShrimpEntity.kt → ...aquatic/entity/crustacean/ShrimpEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...quatic/entity/critter/SpiderCrabEntity.kt → ...tic/entity/crustacean/SpiderCrabEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...uatic/entity/critter/VampireCrabEntity.kt → ...ic/entity/crustacean/VampireCrabEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
.../aquatic/entity/critter/YetiCrabEntity.kt → ...uatic/entity/crustacean/YetiCrabEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 40 additions & 66 deletions
106
src/main/kotlin/dev/hybridlabs/aquatic/entity/fish/ClownfishEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,71 @@ | ||
package dev.hybridlabs.aquatic.entity.fish | ||
|
||
import dev.hybridlabs.aquatic.block.HybridAquaticBlocks.ANEMONE | ||
import dev.hybridlabs.aquatic.block.HybridAquaticBlocks | ||
import net.minecraft.entity.EntityType | ||
import net.minecraft.entity.ai.goal.Goal | ||
import net.minecraft.entity.attribute.DefaultAttributeContainer | ||
import net.minecraft.entity.attribute.EntityAttributes | ||
import net.minecraft.entity.mob.WaterCreatureEntity | ||
import net.minecraft.util.math.BlockPos | ||
import net.minecraft.world.World | ||
import java.util.* | ||
|
||
class ClownfishEntity(entityType: EntityType<out ClownfishEntity>, world: World) : | ||
HybridAquaticFishEntity(entityType, world) { | ||
|
||
private val isAttacked = false | ||
private var targetAnemonePos: BlockPos? = null | ||
|
||
override fun initGoals() { | ||
goalSelector.add(2, GoalHideInAnemone(this)) | ||
super.initGoals() | ||
companion object { | ||
fun createMobAttributes(): DefaultAttributeContainer.Builder { | ||
return WaterCreatureEntity.createMobAttributes() | ||
.add(EntityAttributes.GENERIC_MAX_HEALTH, 2.0) | ||
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.6) | ||
} | ||
} | ||
|
||
class GoalHideInAnemone(private val clownfish: ClownfishEntity) : Goal() { | ||
private var targetAnemonePos: BlockPos? = null | ||
override fun getMaxSize(): Int { | ||
return 5 | ||
} | ||
|
||
init { | ||
controls = EnumSet.of(Control.MOVE) | ||
} | ||
override fun getMinSize(): Int { | ||
return -5 | ||
} | ||
|
||
override fun canStart(): Boolean { | ||
return clownfish.attacker != null | ||
} | ||
override fun tick() { | ||
super.tick() | ||
|
||
override fun start() { | ||
findNearestAnemone()?.let { nearestAnemonePos -> | ||
targetAnemonePos = nearestAnemonePos | ||
clownfish.getNavigation().startMovingTo( | ||
nearestAnemonePos.x.toDouble(), | ||
nearestAnemonePos.y.toDouble(), | ||
nearestAnemonePos.z.toDouble(), | ||
1.0 | ||
) | ||
} | ||
if (targetAnemonePos == null || world.getBlockState(targetAnemonePos).isOf(HybridAquaticBlocks.ANEMONE)) { | ||
targetAnemonePos = findNearbyAnemone() | ||
} | ||
|
||
override fun shouldContinue(): Boolean { | ||
return targetAnemonePos != null && clownfish.isAlive && clownfish.isAttacked | ||
} | ||
if (targetAnemonePos != null) { | ||
val distanceToAnemone = distanceTo(targetAnemonePos!!) | ||
|
||
override fun tick() { | ||
targetAnemonePos?.let { pos -> | ||
clownfish.getNavigation().startMovingTo( | ||
pos.x.toDouble(), | ||
pos.y.toDouble(), | ||
pos.z.toDouble(), | ||
1.0 | ||
) | ||
if (distanceToAnemone > 5.0) { | ||
navigateToAnemone(targetAnemonePos!!) | ||
} | ||
} | ||
} | ||
|
||
override fun stop() { | ||
targetAnemonePos = null | ||
clownfish.getNavigation().stop() | ||
} | ||
private fun navigateToAnemone(ventBlockPos: BlockPos) { | ||
this.navigation.startMovingTo(ventBlockPos.x.toDouble(), ventBlockPos.y.toDouble(), ventBlockPos.z.toDouble(), this.getAttributeValue(EntityAttributes.GENERIC_MOVEMENT_SPEED)) | ||
} | ||
|
||
private fun findNearestAnemone(): BlockPos? { | ||
val currentPos = clownfish.blockPos | ||
for (i in -8..8) { | ||
for (j in -8..8) { | ||
for (k in -8..8) { | ||
val checkPos = currentPos.add(i, j, k) | ||
val block = clownfish.world.getBlockState(checkPos).block | ||
if (block === ANEMONE) { | ||
return checkPos | ||
} | ||
private fun findNearbyAnemone(): 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.isOf(HybridAquaticBlocks.ANEMONE)) { | ||
return blockPos | ||
} | ||
} | ||
} | ||
return null | ||
} | ||
} | ||
|
||
companion object { | ||
fun createClownfishAttributes(): DefaultAttributeContainer.Builder { | ||
return createMobAttributes() | ||
.add(EntityAttributes.GENERIC_MAX_HEALTH, 4.0) | ||
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.6) | ||
} | ||
return null | ||
} | ||
|
||
override fun getMaxSize(): Int { | ||
return 5 | ||
} | ||
|
||
override fun getMinSize(): Int { | ||
return -5 | ||
private fun distanceTo(pos: BlockPos): Double { | ||
return this.blockPos.getSquaredDistance(pos.x.toDouble(), pos.y.toDouble(), pos.z.toDouble()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.