Skip to content

Commit

Permalink
Fixed brain logic for baby glare
Browse files Browse the repository at this point in the history
  • Loading branch information
Faboslav committed Jan 21, 2024
1 parent e0bc489 commit bf96f4a
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public final class GlareEntity extends TameableEntity implements Flutterer, Anim

private Vec2f targetEyesPositionOffset;

public CachedPathHolder cachedPathHolder = null;
public CachedPathHolder cachedPathHolder = new CachedPathHolder();
private AnimationContextTracker animationContextTracker;

@Override
Expand Down Expand Up @@ -189,12 +189,12 @@ protected void mobTick() {
this.getWorld().getProfiler().push("glareBrain");
this.getBrain().tick((ServerWorld) this.getWorld(), this);
this.getWorld().getProfiler().pop();
this.getWorld().getProfiler().push("glareActivityUpdate");
GlareBrain.updateActivities(this);
this.getWorld().getProfiler().pop();
this.getWorld().getProfiler().push("glareMemoryUpdate");
GlareBrain.updateMemories(this);
this.getWorld().getProfiler().pop();
this.getWorld().getProfiler().push("glareActivityUpdate");
GlareBrain.updateActivities(this);
this.getWorld().getProfiler().pop();

super.mobTick();
}
Expand Down Expand Up @@ -297,7 +297,9 @@ protected EntityNavigation createNavigation(World world) {
BirdNavigation birdNavigation = new BirdNavigation(this, world)
{
public boolean isValidPosition(BlockPos pos) {
return this.world.getBlockState(pos.down()).isAir() == false;
boolean isValidPos = this.world.getBlockState(pos.down()).isAir() == false && this.world.getBlockState(pos.down()).getMaterial().isLiquid() == false;

return isValidPos;
}
};

Expand Down Expand Up @@ -361,6 +363,15 @@ public void playRustleSound() {
this.playSound(soundEvent, 0.1F, 0.1F);
}

private SoundEvent getShakeSound() {
return FriendsAndFoesSoundEvents.ENTITY_GLARE_SHAKE.get();
}

public void playShakeSound() {
SoundEvent soundEvent = this.getShakeSound();
this.playSound(soundEvent, 0.1F, 0.1F);
}

@Override
public SoundEvent getEatSound(ItemStack stack) {
return FriendsAndFoesSoundEvents.ENTITY_GLARE_EAT.get();
Expand Down Expand Up @@ -653,7 +664,11 @@ public Vec3d getLeashOffset() {

@Override
protected float getActiveEyeHeight(EntityPose poseIn, EntityDimensions sizeIn) {
return 1.1F;
if (this.isBaby()) {
return 0.5F;
}

return 1.0F;
}

@Override
Expand All @@ -665,10 +680,6 @@ public float getMovementSpeed() {
return MOVEMENT_SPEED;
}

public float getFastMovementSpeed() {
return MOVEMENT_SPEED * 1.25F;
}

public void setGrumpy(boolean grumpy) {
this.setGlareFlag(GRUMPY_BITMASK, grumpy);
}
Expand All @@ -677,10 +688,6 @@ public boolean isGrumpy() {
return this.hasGlareFlag(GRUMPY_BITMASK);
}

public boolean isMoving() {
return this.isOnGround() == false && this.getVelocity().lengthSquared() >= 0.0001;
}

final class GlareMoveControl extends FlightMoveControl
{
public GlareMoveControl(GlareEntity glare, int maxPitchChange, boolean noGravity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ public static void updateActivities(GlareEntity glare) {
}

public static void updateMemories(GlareEntity glare) {
if (
glare.isBaby()
&& glare.getBrain().isMemoryInState(FriendsAndFoesMemoryModuleTypes.GLARE_DARK_SPOT_LOCATING_COOLDOWN.get(), MemoryModuleState.VALUE_ABSENT)
) {
GlareBrain.setDarkSpotLocatingCooldown(glare);
}

if (
glare.isSitting()
|| glare.isLeashed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public GlareLocateDarkSpotTask() {
super(Map.of(
FriendsAndFoesMemoryModuleTypes.GLARE_DARK_SPOT_LOCATING_COOLDOWN.get(), MemoryModuleState.VALUE_ABSENT,
FriendsAndFoesMemoryModuleTypes.GLARE_DARK_SPOT_POS.get(), MemoryModuleState.VALUE_ABSENT
));
), 1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.faboslav.friendsandfoes.entity.ai.brain.task.glare;

import com.faboslav.friendsandfoes.entity.GlareEntity;
import com.faboslav.friendsandfoes.entity.ai.pathing.CachedPathHolder;
import net.minecraft.block.BlockState;
import net.minecraft.entity.ai.brain.MemoryModuleState;
import net.minecraft.entity.ai.brain.MemoryModuleType;
Expand Down Expand Up @@ -42,8 +41,7 @@ protected boolean shouldKeepRunning(ServerWorld world, GlareEntity glare, long t

public void updateCachedPathHolder(GlareEntity glare) {
if (
glare.cachedPathHolder == null
|| glare.cachedPathHolder.pathTimer > 50
glare.cachedPathHolder.pathTimer > 20
|| glare.cachedPathHolder.cachedPath == null
|| (glare.getMovementSpeed() <= 0.05d && glare.cachedPathHolder.pathTimer > 5)
|| glare.getBlockPos().getManhattanDistance(glare.cachedPathHolder.cachedPath.getTarget()) <= 4
Expand Down Expand Up @@ -82,11 +80,8 @@ public void updateCachedPathHolder(GlareEntity glare) {
break;
}
}
Path newPath = glare.getNavigation().findPathTo(mutable, 1);

if (glare.cachedPathHolder == null) {
glare.cachedPathHolder = new CachedPathHolder();
}
Path newPath = glare.getNavigation().findPathTo(mutable, 1);

glare.cachedPathHolder.cachedPath = newPath;
glare.cachedPathHolder.pathTimer = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public final class CachedPathHolder
{
public Path cachedPath;
public Path cachedPath = null;
public int pathTimer = 0;

public CachedPathHolder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public final class FriendsAndFoesEntityTypes
static {
SharedConstants.useChoiceTypeRegistrations = false;
COPPER_GOLEM = RegistryHelper.registerEntityType("copper_golem", () -> EntityType.Builder.create(CopperGolemEntity::new, SpawnGroup.MISC).setDimensions(0.75F, 1.375F).maxTrackingRange(10).build(FriendsAndFoes.makeStringID("copper_golem")));
GLARE = RegistryHelper.registerEntityType("glare", () -> EntityType.Builder.create(GlareEntity::new, CustomSpawnGroup.getGlaresCategory()).setDimensions(0.875F, 1.4375F).maxTrackingRange(8).trackingTickInterval(2).build(FriendsAndFoes.makeStringID("glare")));
GLARE = RegistryHelper.registerEntityType("glare", () -> EntityType.Builder.create(GlareEntity::new, CustomSpawnGroup.getGlaresCategory()).setDimensions(0.875F, 1.0F).maxTrackingRange(8).trackingTickInterval(2).build(FriendsAndFoes.makeStringID("glare")));
ICEOLOGER = RegistryHelper.registerEntityType("iceologer", () -> EntityType.Builder.create(IceologerEntity::new, SpawnGroup.MONSTER).setDimensions(0.6F, 1.95F).maxTrackingRange(10).build(FriendsAndFoes.makeStringID("iceologer")));
ICE_CHUNK = RegistryHelper.registerEntityType("ice_chunk", () -> EntityType.Builder.create(IceologerIceChunkEntity::new, SpawnGroup.MISC).makeFireImmune().setDimensions(2.5F, 1.0F).maxTrackingRange(6).build(FriendsAndFoes.makeStringID("ice_chunk")));
MAULER = RegistryHelper.registerEntityType("mauler", () -> EntityType.Builder.create(MaulerEntity::new, SpawnGroup.CREATURE).setDimensions(0.5625F, 0.5625F).maxTrackingRange(10).build(FriendsAndFoes.makeStringID("mauler")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public final class FriendsAndFoesSoundEvents
public static final Supplier<SoundEvent> ENTITY_GLARE_GRUMPINESS_SHORT;
public static final Supplier<SoundEvent> ENTITY_GLARE_HURT;
public static final Supplier<SoundEvent> ENTITY_GLARE_RUSTLE;
public static final Supplier<SoundEvent> ENTITY_GLARE_SHAKE;
public static final Supplier<SoundEvent> ENTITY_ICE_CHUNK_AMBIENT;
public static final Supplier<SoundEvent> ENTITY_ICE_CHUNK_HIT;
public static final Supplier<SoundEvent> ENTITY_ICE_CHUNK_SUMMON;
Expand Down Expand Up @@ -77,6 +78,7 @@ public final class FriendsAndFoesSoundEvents
ENTITY_GLARE_GRUMPINESS_SHORT = register("entity", "glare.grumpiness_short");
ENTITY_GLARE_HURT = register("entity", "glare.hurt");
ENTITY_GLARE_RUSTLE = register("entity", "glare.rustle");
ENTITY_GLARE_SHAKE = register("entity", "glare.shake");
ENTITY_ICE_CHUNK_AMBIENT = register("entity", "ice_chunk.ambient");
ENTITY_ICE_CHUNK_HIT = register("entity", "ice_chunk.hit");
ENTITY_ICE_CHUNK_SUMMON = register("entity", "ice_chunk.summon");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"subtitle.entity.friendsandfoes.glare.grumpiness_short": "Glare grumps",
"subtitle.entity.friendsandfoes.glare.hurt": "Glare hurts",
"subtitle.entity.friendsandfoes.glare.rustle": "Glare grumps",
"subtitle.entity.friendsandfoes.glare.shake": "Glare shakes off glow berries",
"subtitle.entity.friendsandfoes.copper_golem.death": "Copper Golem dies",
"subtitle.entity.friendsandfoes.copper_golem.head_spin": "Copper Golem spins head",
"subtitle.entity.friendsandfoes.copper_golem.hurt": "Copper Golem hurts",
Expand Down
8 changes: 8 additions & 0 deletions common/src/main/resources/assets/friendsandfoes/sounds.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@
],
"subtitle": "subtitle.entity.friendsandfoes.glare.rustle"
},
"entity.glare.shake": {
"sounds": [
"friendsandfoes:entity/glare/shake1",
"friendsandfoes:entity/glare/shake2",
"friendsandfoes:entity/glare/shake3"
],
"subtitle": "subtitle.entity.friendsandfoes.glare.shake"
},
"entity.ice_chunk.ambient": {
"sounds": [
"friendsandfoes:entity/ice_chunk/ambient"
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static <T extends Packet<T>> void registerS2CPacket(
}
channel.channel.registerMessage(++channel.packets, packetClass, handler::encode, handler::decode, (msg, ctx) -> {
NetworkEvent.Context context = ctx.get();

context.enqueueWork(() -> {
PlayerEntity player = null;
if (context.getSender() == null) {
Expand Down

0 comments on commit bf96f4a

Please sign in to comment.