From 4177c15771e9b91b1e4e114dc229c4bdf62480ac Mon Sep 17 00:00:00 2001 From: Ivan Kh <47220198+Ivan-Khar@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:44:16 +0300 Subject: [PATCH] karkinos flipped thing is now working --- .../aquatic/entity/critter/KarkinosEntity.kt | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/dev/hybridlabs/aquatic/entity/critter/KarkinosEntity.kt b/src/main/kotlin/dev/hybridlabs/aquatic/entity/critter/KarkinosEntity.kt index 7b2e2b726..08533c5dd 100644 --- a/src/main/kotlin/dev/hybridlabs/aquatic/entity/critter/KarkinosEntity.kt +++ b/src/main/kotlin/dev/hybridlabs/aquatic/entity/critter/KarkinosEntity.kt @@ -14,10 +14,13 @@ import net.minecraft.entity.data.DataTracker import net.minecraft.entity.data.TrackedData import net.minecraft.entity.data.TrackedDataHandlerRegistry import net.minecraft.entity.mob.Angerable +import net.minecraft.entity.mob.MobEntity import net.minecraft.entity.mob.WaterCreatureEntity import net.minecraft.entity.player.PlayerEntity import net.minecraft.world.Difficulty import net.minecraft.world.World +import org.slf4j.Logger +import org.slf4j.LoggerFactory import software.bernie.geckolib.core.animatable.GeoAnimatable import software.bernie.geckolib.core.animation.AnimationState import software.bernie.geckolib.core.`object`.PlayState @@ -27,21 +30,23 @@ class KarkinosEntity(entityType: EntityType, wor HybridAquaticCrabEntity(entityType, world), Angerable { private var flipTimer: Int = 0 - private val flipDuration: Int = 10 + private val flipDuration: Int = 40 private var angerTime = 0 private var angryAt: UUID? = null - private var isFlipped: Boolean + var isFlipped: Boolean get() = dataTracker.get(FLIPPED) set(bool) = dataTracker.set(FLIPPED, bool) + private var LOGGER: Logger = LoggerFactory.getLogger("karkinos") + override fun initDataTracker() { super.initDataTracker() dataTracker.startTracking(FLIPPED, false) } override fun initGoals() { - goalSelector.add(1, AttackGoal(this)) - goalSelector.add(1, WanderAroundGoal(this, 0.4)) + goalSelector.add(1, KarkinosAttackGoal(this)) + goalSelector.add(1, KarkinosWanderAroundGoal(this, 0.4)) goalSelector.add(4, LookAroundGoal(this)) goalSelector.add(5, LookAtEntityGoal(this, PlayerEntity::class.java, 6.0f)) @@ -56,8 +61,12 @@ class KarkinosEntity(entityType: EntityType, wor override fun tick() { super.tick() + if(world.isClient) LOGGER.info("[C] Flipped: $isFlipped, $flipTimer") + else LOGGER.info("[S] Flipped: $isFlipped, $flipTimer") + + if (!world.isClient && isFlipped) { + target = null - if (isFlipped) { flipTimer-- attributes.getCustomInstance(EntityAttributes.GENERIC_MOVEMENT_SPEED)?.baseValue = 0.0 @@ -145,4 +154,16 @@ class KarkinosEntity(entityType: EntityType, wor val FLIPPED: TrackedData = DataTracker.registerData(KarkinosEntity::class.java, TrackedDataHandlerRegistry.BOOLEAN) } + + class KarkinosAttackGoal(private val karkinos: KarkinosEntity) : AttackGoal(karkinos) { + override fun shouldContinue(): Boolean { + return !karkinos.isFlipped && super.shouldContinue() + } + } + + class KarkinosWanderAroundGoal(private val karkinos: KarkinosEntity, speed: Double) : WanderAroundGoal(karkinos, speed) { + override fun shouldContinue(): Boolean { + return !karkinos.isFlipped && super.shouldContinue() + } + } } \ No newline at end of file