Skip to content

Commit

Permalink
Fix berry bush pathfinding (#10388)
Browse files Browse the repository at this point in the history
Fix berry bush pathfinding
Fix citizen not fully pathing to the end of the path
Fix raiders getting a vanilla target goal, while they already have a custom targeting AI
Add knockback cooldown, so entities during combat do not get knocked around all the time
Fix jumping on doors
Add recovery for stuck entities
  • Loading branch information
someaddons authored Nov 3, 2024
1 parent 778ab72 commit f1fd051
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public abstract class AbstractFastMinecoloniesEntity extends PathfinderMob imple
*/
private long lastHorizontalCollision = 0;

/**
* Last knockback time
*/
protected long lastKnockBack = 0;

/**
* Create a new instance.
*
Expand Down Expand Up @@ -335,4 +340,14 @@ public boolean isShiftKeyDown()
{
return (this.entityData.get(DATA_SHARED_FLAGS_ID)).byteValue() == ENABLE.byteValue();
}

@Override
public void knockback(double power, double xRatio, double zRatio)
{
if (level.getGameTime() - lastKnockBack > 20 * 3)
{
lastKnockBack = level.getGameTime();
super.knockback(power, xRatio, zRatio);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,15 @@ private ICitizenData spawnCitizenOnPosition(

if (world instanceof ServerLevel serverLevel)
{
final Entity existing = serverLevel.getEntity(citizenData.getUUID());
Entity existing = serverLevel.getEntity(citizenData.getUUID());
if (existing != null)
{
existing.discard();
existing = serverLevel.getEntity(citizenData.getUUID());
if (existing != null)
{
serverLevel.entityManager.stopTracking(existing);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ public boolean refreshCitizenDataView()
if (colonyView != null)
{
this.citizenDataView = colonyView.getCitizen(citizenId);
// TODO: Why is this here on clientside?
this.getNavigation().getPathingOptions().setCanUseRails(canPathOnRails());
this.getNavigation().getPathingOptions().setCanClimbAdvanced(canClimbVines());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickingTransition;
import com.minecolonies.api.entity.mobs.AbstractEntityRaiderMob;
import com.minecolonies.api.entity.pathfinding.IPathJob;
import com.minecolonies.core.entity.pathfinding.pathresults.PathResult;
import com.minecolonies.api.util.BlockPosUtil;
import com.minecolonies.api.util.Log;
import com.minecolonies.core.colony.buildings.AbstractBuilding;
import com.minecolonies.core.colony.events.raid.HordeRaidEvent;
import com.minecolonies.core.colony.events.raid.pirateEvent.ShipBasedRaiderUtils;
import com.minecolonies.core.entity.pathfinding.pathresults.PathResult;
import net.minecraft.core.BlockPos;

import java.util.List;
Expand Down Expand Up @@ -156,7 +156,10 @@ protected BlockPos findRandomPositionToWalkTo()
&& !building.getCorners().getA().equals(building.getCorners().getB()))
{
randomPathResult = raider.getNavigation().moveToRandomPos(10, 0.9, building.getCorners());
randomPathResult.getJob().getPathingOptions().withCanEnterDoors(true).withToggleCost(0).withNonLadderClimbableCost(0);
if (randomPathResult != null)
{
randomPathResult.getJob().getPathingOptions().withCanEnterDoors(true).withToggleCost(0).withNonLadderClimbableCost(0);
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseRailBlock;
import net.minecraft.world.level.block.LadderBlock;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.RailShape;
import net.minecraft.world.level.pathfinder.Node;
Expand Down Expand Up @@ -383,7 +382,9 @@ else if (this.path != null && !this.path.isDone())
vector3d2.z);
}
}

}
if (wantedPosition != null)
{
mob.getMoveControl().setWantedPosition(wantedPosition.x, wantedPosition.y, wantedPosition.z, speedModifier);
}
}
Expand Down Expand Up @@ -412,6 +413,11 @@ public static double getSmartGroundY(final BlockGetter world, final BlockPos.Mut

if (!state.isAir())
{
if (state.getBlock() instanceof FenceGateBlock || state.getBlock() instanceof DoorBlock || state.getBlock() instanceof TrapDoorBlock)
{
return orgY;
}

final VoxelShape voxelshape = state.getCollisionShape(world, pos);
if (!ShapeUtil.isEmpty(voxelshape))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ protected boolean isPassable(@NotNull final BlockState block, final int x, final
if (!block.isAir())
{
final VoxelShape shape = block.getCollisionShape(world, tempWorldPos.set(x, y, z));
if (ShapeUtil.max(shape, Direction.Axis.Y) < 0.5 && PathfindingUtils.isDangerous(cachedBlockLookup.getBlockState(x, y - 1, z)))
if (!pathingOptions.canPassDanger() && ShapeUtil.max(shape, Direction.Axis.Y) < 0.5 && PathfindingUtils.isDangerous(cachedBlockLookup.getBlockState(x, y - 1, z)))
{
return false;
}
Expand Down Expand Up @@ -1280,7 +1280,7 @@ protected boolean isPassable(@NotNull final BlockState block, final int x, final
|| !block.getBlock().properties.hasCollision;
}
}
else if (PathfindingUtils.isDangerous(block))
else if (!pathingOptions.canPassDanger() && PathfindingUtils.isDangerous(block))
{
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/minecolonies/core/event/EventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ public static void onEntityAdded(@NotNull final EntityJoinLevelEvent event)
{
if (MineColonies.getConfig().getServer().mobAttackCitizens.get() && event.getEntity() instanceof Mob && event.getEntity() instanceof Enemy && !(event.getEntity()
.getType()
.is(ModTags.mobAttackBlacklist)))
.is(ModTags.mobAttackBlacklist))
&& !(event.getEntity() instanceof AbstractFastMinecoloniesEntity))
{
((Mob) event.getEntity()).targetSelector.addGoal(6,
new NearestAttackableTargetGoal<>((Mob) event.getEntity(), EntityCitizen.class, true, citizen -> !citizen.isInvisible()));
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,5 @@ public net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer f_266073_
public net.minecraft.world.entity.LivingEntity m_21333_()V # updateSwimAmount

public-f net.minecraft.world.entity.Entity m_142467_(Lnet/minecraft/world/entity/Entity$RemovalReason;)V # setRemoved

public net.minecraft.world.level.entity.PersistentEntitySectionManager m_157580_(Lnet/minecraft/world/level/entity/EntityAccess;)V # stopTracking
public net.minecraft.server.level.ServerLevel f_143244_ # entityManager

0 comments on commit f1fd051

Please sign in to comment.