Skip to content

Commit

Permalink
Copper golem brain fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Faboslav committed Nov 26, 2023
1 parent cf4c0cd commit 84e9103
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ public final class CopperGolemEntity extends GolemEntity implements AnimatedEnti
private static final float MOVEMENT_SPEED = 0.2F;
private static final int COPPER_INGOT_HEAL_AMOUNT = 5;
private static final float SPARK_CHANCE = 0.025F;
private static final float OXIDATION_CHANCE = 0.01F;
//private static final float OXIDATION_CHANCE = 0.00002F;
private static final float OXIDATION_CHANCE = 0.00002F;
public static final int MIN_STRUCT_BY_LIGHTNING_TICKS = 1200;
public static final int MAX_STRUCT_BY_LIGHTNING_TICKS = 2400;

Expand Down Expand Up @@ -145,6 +144,10 @@ public EntityData initialize(
) {
EntityData superEntityData = super.initialize(world, difficulty, spawnReason, entityData, entityNbt);

if (spawnReason == SpawnReason.STRUCTURE) {
return superEntityData;
}

this.setPose(CopperGolemEntityPose.IDLE);
CopperGolemBrain.setSpinHeadCooldown(this);
CopperGolemBrain.setPressButtonCooldown(this);
Expand Down Expand Up @@ -232,25 +235,28 @@ public void applyEntitySnapshot() {
return;
}

this.serverYaw = entitySnapshot.getDouble("serverYaw");
this.prevYaw = entitySnapshot.getFloat("prevYaw");
this.setYaw(this.prevYaw);
if (this.hasVehicle() == false) {
this.serverYaw = entitySnapshot.getDouble("serverYaw");
this.prevYaw = entitySnapshot.getFloat("prevYaw");
this.setYaw(this.prevYaw);
this.prevBodyYaw = entitySnapshot.getFloat("prevBodyYaw");
this.bodyYaw = this.prevBodyYaw;
this.serverHeadYaw = entitySnapshot.getDouble("serverHeadYaw");
this.prevHeadYaw = entitySnapshot.getFloat("prevHeadYaw");
this.headYaw = this.prevHeadYaw;
this.prevLookDirection = entitySnapshot.getFloat("prevLookDirection");
this.lookDirection = this.prevLookDirection;
}

this.prevPitch = entitySnapshot.getFloat("prevPitch");
this.serverPitch = this.prevPitch;
this.setPitch(this.prevPitch);
this.roll = entitySnapshot.getInt("roll");
this.prevBodyYaw = entitySnapshot.getFloat("prevBodyYaw");
this.bodyYaw = this.prevBodyYaw;
this.serverHeadYaw = entitySnapshot.getDouble("serverHeadYaw");
this.prevHeadYaw = entitySnapshot.getFloat("prevHeadYaw");
this.headYaw = this.prevHeadYaw;
this.lastHandSwingProgress = entitySnapshot.getFloat("lastHandSwingProgress");
this.handSwingProgress = this.lastHandSwingProgress;
this.lastLimbDistance = entitySnapshot.getFloat("lastLimbDistance");
this.limbDistance = this.lastLimbDistance;
this.limbAngle = entitySnapshot.getFloat("limbAngle");
this.prevLookDirection = entitySnapshot.getFloat("prevLookDirection");
this.lookDirection = this.prevLookDirection;
this.prevStepBobbingAmount = entitySnapshot.getFloat("prevStepBobbingAmount");
this.stepBobbingAmount = this.prevStepBobbingAmount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ private static void addCoreActivities(Brain<CopperGolemEntity> brain) {
brain.setTaskList(Activity.CORE,
0,
ImmutableList.of(
new StayAboveWaterTask(0.8F),
new LookAroundTask(45, 90),
new WanderAroundTask(),
new TemptationCooldownTask(MemoryModuleType.TEMPTATION_COOLDOWN_TICKS),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.faboslav.friendsandfoes.entity.ai.brain.task.coppergolem;

import com.faboslav.friendsandfoes.FriendsAndFoes;
import com.faboslav.friendsandfoes.entity.CopperGolemEntity;
import com.faboslav.friendsandfoes.entity.ai.brain.CopperGolemBrain;
import com.faboslav.friendsandfoes.init.FriendsAndFoesMemoryModuleTypes;
Expand Down Expand Up @@ -31,21 +30,19 @@ public CopperGolemLocateButtonTask() {

@Override
protected void run(ServerWorld world, CopperGolemEntity copperGolem, long time) {
FriendsAndFoes.getLogger().info("CopperGolemLocateButtonTask");
BlockPos buttonBlockPos = this.findNearestRandomButton(world, copperGolem);
BlockPos buttonBlockPos = this.findNearestRandomButton(copperGolem);

if (buttonBlockPos == null) {
CopperGolemBrain.setPressButtonCooldown(copperGolem, TimeHelper.betweenSeconds(10, 10));
return;
}

FriendsAndFoes.getLogger().info("CopperGolemLocateButtonTask - done");
RegistryKey<World> registryKey = copperGolem.getWorld().getRegistryKey();
copperGolem.getBrain().remember(FriendsAndFoesMemoryModuleTypes.COPPER_GOLEM_BUTTON_POS.get(), GlobalPos.create(registryKey, buttonBlockPos));
}

private BlockPos findNearestRandomButton(ServerWorld world, CopperGolemEntity copperGolem) {
int horizontalRange = 8;
private BlockPos findNearestRandomButton(CopperGolemEntity copperGolem) {
int horizontalRange = 16;
int verticalRange = 8;

List<BlockPos> buttons = this.findAllButtonsInRange(copperGolem.getBlockPos(), horizontalRange, verticalRange, (blockPos) -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.faboslav.friendsandfoes.entity.ai.brain.task.coppergolem;

import com.faboslav.friendsandfoes.FriendsAndFoes;
import com.faboslav.friendsandfoes.client.render.entity.animation.CopperGolemAnimations;
import com.faboslav.friendsandfoes.entity.CopperGolemEntity;
import com.faboslav.friendsandfoes.entity.ai.brain.CopperGolemBrain;
Expand Down Expand Up @@ -117,7 +116,6 @@ protected void keepRunning(ServerWorld world, CopperGolemEntity copperGolem, lon
}

this.wasButtonPressed = this.tryToPressButton(copperGolem, buttonPos.getPos());
FriendsAndFoes.getLogger().info("pressing button");
}

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

import com.faboslav.friendsandfoes.FriendsAndFoes;
import com.faboslav.friendsandfoes.client.render.entity.animation.CopperGolemAnimations;
import com.faboslav.friendsandfoes.entity.CopperGolemEntity;
import com.faboslav.friendsandfoes.entity.ai.brain.CopperGolemBrain;
Expand Down Expand Up @@ -35,7 +34,6 @@ protected boolean shouldRun(ServerWorld world, CopperGolemEntity copperGolem) {

@Override
protected void run(ServerWorld world, CopperGolemEntity copperGolem, long time) {
FriendsAndFoes.getLogger().info("CopperGolemSpinHeadTask");
this.spinHeadTicks = 0;
this.maxSpinHeadTicks = CopperGolemAnimations.getSpinHeadKeyframeAnimation(copperGolem.getAnimationSpeedModifier()).getAnimationLengthInTicks();
copperGolem.startSpinHeadAnimation();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.faboslav.friendsandfoes.entity.ai.brain.task.coppergolem;

import com.faboslav.friendsandfoes.FriendsAndFoes;
import com.faboslav.friendsandfoes.entity.CopperGolemEntity;
import com.faboslav.friendsandfoes.init.FriendsAndFoesMemoryModuleTypes;
import net.minecraft.entity.ai.brain.MemoryModuleState;
Expand Down Expand Up @@ -41,7 +40,6 @@ protected boolean shouldRun(ServerWorld world, CopperGolemEntity copperGolem) {

@Override
protected void run(ServerWorld world, CopperGolemEntity copperGolem, long time) {
FriendsAndFoes.getLogger().info("CopperGolemTravelToButtonTask");
this.walkTowardsButton(copperGolem);
}

Expand Down Expand Up @@ -69,14 +67,11 @@ protected void keepRunning(ServerWorld world, CopperGolemEntity copperGolem, lon
return;
}

FriendsAndFoes.getLogger().info("CopperGolemTravelToButtonTask");

this.walkTowardsButton(copperGolem);
}

@Override
protected void finishRunning(ServerWorld world, CopperGolemEntity copperGolem, long time) {
FriendsAndFoes.getLogger().info("CopperGolemTravelToButtonTask - finished");
copperGolem.getBrain().forget(MemoryModuleType.WALK_TARGET);
GlobalPos buttonPos = copperGolem.getButtonPos();

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 84e9103

Please sign in to comment.