Skip to content

Commit

Permalink
Fix citizenskillhandler npe (#10374)
Browse files Browse the repository at this point in the history
Fix citizen skill handler npe
Fix colony stat command not always caculating the right average level
Improve entity navigator performance
  • Loading branch information
someaddons authored Oct 30, 2024
1 parent 0790bb6 commit 8e12c2c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.minecolonies.api.colony.IColony;
import com.minecolonies.api.colony.IColonyManager;
import com.minecolonies.api.colony.buildings.IBuilding;
import com.minecolonies.api.util.Log;
import com.minecolonies.core.colony.events.raid.RaidManager;
import com.minecolonies.core.commands.commandTypes.IMCCommand;
Expand Down Expand Up @@ -83,16 +84,24 @@ public int onExecute(final CommandContext<CommandSourceStack> context)
context.getSource().sendSuccess(() -> literalAndRemember(last.toString()), false);
}

if (colony.getBuildingManager().getBuildings().size() > 0)
if (!colony.getBuildingManager().getBuildings().isEmpty())
{
int count = 0;
int levels = 0;

for (final IBuilding building : colony.getBuildingManager().getBuildings().values())
{
if (building.getBuildingLevel() != 0)
{
count++;
levels += building.getBuildingLevel();
}
}

final double average = (double) levels / count;

context.getSource()
.sendSuccess(() -> literalAndRemember("Buildings:" + colony.getBuildingManager().getBuildings().size() + " average level:" + colony.getBuildingManager()
.getBuildings()
.values()
.stream()
.filter(iBuilding -> iBuilding.getBuildingLevel() != 0)
.collect(
Collectors.summingInt(ibuilding -> ibuilding.getBuildingLevel())) / colony.getBuildingManager().getBuildings().size()), false);
.sendSuccess(() -> literalAndRemember("Buildings:" + colony.getBuildingManager().getBuildings().size() + " average level:" + average), false);
context.getSource()
.sendSuccess(() -> literalAndRemember(colony.getBuildingManager()
.getBuildings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public class CitizenSkillHandler implements ICitizenSkillHandler
*/
public Map<Skill, SkillData> skillMap = new EnumMap<>(Skill.class);

public CitizenSkillHandler()
{
for (final Skill skill : Skill.values())
{
skillMap.put(skill, new SkillData(1, 0.0D));
}
}

@Override
public void init(final int levelCap)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ public class MinecoloniesAdvancedPathNavigate extends AbstractAdvancedPathNaviga
*/
private BlockPos.MutableBlockPos tempPos = new BlockPos.MutableBlockPos();

/**
* wanted position for movecontrol
*/
private Vec3 wantedPosition = null;

/**
* Instantiates the navigation of an ourEntity.
*
Expand Down Expand Up @@ -368,19 +373,19 @@ else if (this.path != null && !this.path.isDone())

DebugPackets.sendPathFindingPacket(this.level, this.mob, this.path, this.maxDistanceToWaypoint);

if (!this.isDone())
if ((wantedPosition == null || path != null && currentPathIndex != path.getNextNodeIndex() && path.getNextNodeIndex() < path.getNodeCount()))
{
Vec3 vector3d2 = path.getNextEntityPos(mob);
tempPos.set(Mth.floor(vector3d2.x), Mth.floor(vector3d2.y), Mth.floor(vector3d2.z));
if (ChunkPos.asLong(tempPos) == mob.chunkPosition().toLong() || WorldUtil.isEntityBlockLoaded(level, tempPos))
if (wantedPosition == null || ChunkPos.asLong(tempPos) == mob.chunkPosition().toLong() || WorldUtil.isEntityBlockLoaded(level, tempPos))
{
mob.getMoveControl()
.setWantedPosition(vector3d2.x,
wantedPosition = new Vec3(vector3d2.x,
getSmartGroundY(this.level, tempPos, vector3d2.y),
vector3d2.z,
speedModifier);
vector3d2.z);
}
}

mob.getMoveControl().setWantedPosition(wantedPosition.x, wantedPosition.y, wantedPosition.z, speedModifier);
}
// End of super.tick.

Expand All @@ -398,7 +403,7 @@ else if (this.path != null && !this.path.isDone())
*
* @param world the world.
* @param pos the position to check.
* @param y
* @param orgY original y level
* @return the next y level to go to.
*/
public static double getSmartGroundY(final BlockGetter world, final BlockPos.MutableBlockPos pos, final double orgY)
Expand Down

0 comments on commit 8e12c2c

Please sign in to comment.