Skip to content

Commit

Permalink
Check if creature was created from fishing net(janky but works I think)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan-Khar committed Apr 16, 2024
1 parent a239b75 commit 708487a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ open class HybridAquaticCephalopodEntity(
override fun initGoals() {
goalSelector.add(2, SwimGoal(this))
goalSelector.add(2, SwimToRandomPlaceGoal(this, 0.50, 6))
goalSelector.add(1, FleeEntityGoal(this, LivingEntity::class.java, 8.0f, 1.2, 1.0) {it.type.isIn(predator)})
goalSelector.add(1, FleeEntityGoal(this, PlayerEntity::class.java, 5.0f, 1.0, 1.0))
targetSelector.add(1, ActiveTargetGoal(this, LivingEntity::class.java, 10, true, true) {hunger <= 1200 && it.type.isIn(prey)})
goalSelector.add(1, FleeEntityGoal(this, LivingEntity::class.java, 8.0f, 1.2, 1.0) { !fromFishingNet && it.type.isIn(predator) })
goalSelector.add(1, FleeEntityGoal(this, PlayerEntity::class.java, 5.0f, 1.0, 1.0) { !fromFishingNet })
targetSelector.add(1, ActiveTargetGoal(this, LivingEntity::class.java, 10, true, true) { hunger <= 1200 && it.type.isIn(prey) })
}

override fun initDataTracker() {
Expand Down Expand Up @@ -440,14 +440,17 @@ open class HybridAquaticCephalopodEntity(
nbt.putInt(VARIANT_KEY, variant)
nbt.putInt(CEPHALOPOD_SIZE_KEY, size)
nbt.putInt(HUNGER_KEY, hunger)
nbt.putBoolean("FromFishingNet", fromFishingNet)
}

private var fromFishingNet = false
override fun readCustomDataFromNbt(nbt: NbtCompound) {
super.readCustomDataFromNbt(nbt)
moistness = nbt.getInt(MOISTNESS_KEY)
variant = nbt.getInt(VARIANT_KEY).coerceAtLeast(0).coerceAtMost(variantCount-1)
size = nbt.getInt(CEPHALOPOD_SIZE_KEY)
hunger = nbt.getInt(HUNGER_KEY)
fromFishingNet = nbt.getBoolean("FromFishingNet")
}

internal class SwimToRandomPlaceGoal(private val cephalopod: HybridAquaticCephalopodEntity, d: Double, i: Int) :
Expand All @@ -458,6 +461,10 @@ open class HybridAquaticCephalopodEntity(
}

internal class AttackGoal(private val cephalopod: HybridAquaticCephalopodEntity) : MeleeAttackGoal(cephalopod, 1.0,true) {
override fun canStart(): Boolean {
return !cephalopod.fromFishingNet && super.canStart()
}

override fun attack(target: LivingEntity, squaredDistance: Double) {
val d = getSquaredMaxAttackDistance(target)
if (squaredDistance <= d && this.isCooledDown) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ open class HybridAquaticFishEntity(
goalSelector.add(2, MoveIntoWaterGoal(this))
goalSelector.add(2, SwimAroundGoal(this, 0.50, 6))
goalSelector.add(1, AttackGoal(this))
goalSelector.add(1, FleeEntityGoal(this, LivingEntity::class.java, 8.0f, 1.2, 1.0) {it.type.isIn(predator)})
goalSelector.add(2, FleeEntityGoal(this, PlayerEntity::class.java, 5.0f, 1.0, 1.0))
targetSelector.add(1, ActiveTargetGoal(this, LivingEntity::class.java, 10, true, true) {hunger <= 1200 && it.type.isIn(prey)})
goalSelector.add(1, FleeEntityGoal(this, LivingEntity::class.java, 8.0f, 1.2, 1.0) { !fromFishingNet && it.type.isIn(predator) })
goalSelector.add(2, FleeEntityGoal(this, PlayerEntity::class.java, 5.0f, 1.0, 1.0) { !fromFishingNet })
targetSelector.add(1, ActiveTargetGoal(this, LivingEntity::class.java, 10, true, true) { hunger <= 1200 && it.type.isIn(prey) })
}

override fun initDataTracker() {
Expand Down Expand Up @@ -158,18 +158,21 @@ open class HybridAquaticFishEntity(
nbt.putInt(VARIANT_KEY, variant)
nbt.putInt(FISH_SIZE_KEY, size)
nbt.putInt(HUNGER_KEY, hunger)
nbt.putBoolean("FromFishingNet", fromFishingNet)
}

open fun shouldFlopOnLand(): Boolean {
return true
}

private var fromFishingNet = false
override fun readCustomDataFromNbt(nbt: NbtCompound) {
super.readCustomDataFromNbt(nbt)
moistness = nbt.getInt(MOISTNESS_KEY)
variant = nbt.getInt(VARIANT_KEY).coerceAtLeast(0).coerceAtMost(variantCount-1)
size = nbt.getInt(FISH_SIZE_KEY)
hunger = nbt.getInt(HUNGER_KEY)
fromFishingNet = nbt.getBoolean("FromFishingNet")
}

open fun <E : GeoAnimatable> predicate(event: AnimationState<E>): PlayState {
Expand Down Expand Up @@ -334,6 +337,10 @@ open class HybridAquaticFishEntity(
}

internal class AttackGoal(private val fish: HybridAquaticFishEntity) : MeleeAttackGoal(fish, 1.0,true) {
override fun canStart(): Boolean {
return !fish.fromFishingNet && super.canStart()
}

override fun attack(target: LivingEntity, squaredDistance: Double) {
val d = getSquaredMaxAttackDistance(target)
if (squaredDistance <= d && this.isCooledDown) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,18 @@ open class HybridAquaticMinibossEntity(type: EntityType<out HybridAquaticMinibos
override fun writeCustomDataToNbt(nbt: NbtCompound) {
super.writeCustomDataToNbt(nbt)
nbt.putInt(MOISTNESS_KEY, moistness)
nbt.putBoolean("FromFishingNet", fromFishingNet)
}

open fun shouldFlopOnLand(): Boolean {
return false
}

private var fromFishingNet = false
override fun readCustomDataFromNbt(nbt: NbtCompound) {
super.readCustomDataFromNbt(nbt)
moistness = nbt.getInt(MOISTNESS_KEY)
fromFishingNet = nbt.getBoolean("FromFishingNet")
}

private var moistness: Int
Expand Down Expand Up @@ -100,8 +103,11 @@ open class HybridAquaticMinibossEntity(type: EntityType<out HybridAquaticMinibos
return factory
}

internal class AttackGoal(private val miniboss: HybridAquaticMinibossEntity) :
MeleeAttackGoal(miniboss, 1.0, true) {
internal class AttackGoal(private val miniboss: HybridAquaticMinibossEntity) : MeleeAttackGoal(miniboss, 1.0, true) {
override fun canStart(): Boolean {
return !miniboss.fromFishingNet && super.canStart()
}

override fun attack(target: LivingEntity, squaredDistance: Double) {
val d = getSquaredMaxAttackDistance(target)
if (squaredDistance <= d && this.isCooledDown) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,17 @@ open class HybridAquaticSharkEntity(
nbt.putInt(MOISTNESS_KEY, moistness)
nbt.putInt(HUNGER_KEY, hunger)
nbt.putInt(SHARK_SIZE_KEY, size)
nbt.putBoolean("FromFishingNet", fromFishingNet)
}

private var fromFishingNet = false
override fun readCustomDataFromNbt(nbt: NbtCompound) {
super.readCustomDataFromNbt(nbt)
this.readAngerFromNbt(this.world, nbt)
moistness = nbt.getInt(MOISTNESS_KEY)
hunger = nbt.getInt(HUNGER_KEY)
size = nbt.getInt(SHARK_SIZE_KEY)
fromFishingNet = nbt.getBoolean("FromFishingNet")
}

open fun <E : GeoAnimatable> predicate(event: AnimationState<E>): PlayState {
Expand Down Expand Up @@ -345,6 +348,10 @@ open class HybridAquaticSharkEntity(
}

internal class AttackGoal(private val shark: HybridAquaticSharkEntity) : MeleeAttackGoal(shark, 1.5,true) {
override fun canStart(): Boolean {
return !shark.fromFishingNet && super.canStart()
}

override fun attack(target: LivingEntity, squaredDistance: Double) {
val d = getSquaredMaxAttackDistance(target)
if (squaredDistance <= d && this.isCooledDown) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class FishingNetItem(settings: Settings?): Item(settings) {
val entityCompound = NbtCompound()
entity.saveNbt(entityCompound)
entityCompound.putBoolean("PersistenceRequired", true)

entityCompound.putBoolean("FromFishingNet", true)
val itemStack = user.getStackInHand(hand)
itemStack.orCreateNbt.put(ENTITY_KEY, entityCompound)
}
Expand Down

0 comments on commit 708487a

Please sign in to comment.