Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pathing debug additions #10357

Merged
merged 4 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.minecolonies.api.entity.pathfinding;

import com.minecolonies.core.entity.pathfinding.pathresults.PathResult;
import com.minecolonies.core.entity.pathfinding.PathingOptions;
import com.minecolonies.core.entity.pathfinding.pathresults.PathResult;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.pathfinder.Path;

import java.util.concurrent.Callable;
Expand All @@ -22,4 +25,10 @@ public interface IPathJob extends Callable<Path>
* @return
*/
public PathingOptions getPathingOptions();

Mob getEntity();

Level getActualWorld();

BlockPos getStart();
}
5 changes: 3 additions & 2 deletions src/main/java/com/minecolonies/core/commands/EntryPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public static void register(final CommandDispatcher<CommandSourceStack> dispatch
.addNode(new CommandCitizenSpawnNew().build())
.addNode(new CommandCitizenTeleport().build())
.addNode(new CommandCitizenTriggerWalkTo().build())
.addNode(new CommandCitizenTrack().build());
.addNode(new CommandCitizenTrack().build())
.addNode(new CommandTrackType().build());

/*
* Root minecolonies command tree, all subtrees are added here.
Expand All @@ -92,7 +93,7 @@ public static void register(final CommandDispatcher<CommandSourceStack> dispatch
.addNode(new CommandBackup().build())
.addNode(new CommandResetPlayerSupplies().build())
.addNode(new CommandHelp().build())
.addNode(new ScanCommand().build())
.addNode(ScanCommand.build())
.addNode(new CommandPruneWorld().build());
someaddons marked this conversation as resolved.
Show resolved Hide resolved

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.minecolonies.core.commands.citizencommands;

import com.minecolonies.core.commands.commandTypes.IMCCommand;
import com.minecolonies.core.commands.commandTypes.IMCOPCommand;
import com.minecolonies.core.entity.pathfinding.PathfindingUtils;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.Component;

/**
* Displays information about a chosen citizen in a chosen colony.
*/
public class CommandTrackType implements IMCOPCommand
{
/**
* What happens when the command is executed after preConditions are successful.
*
* @param context the context of the command execution
*/
@Override
public int onExecute(final CommandContext<CommandSourceStack> context)
{
if (!context.getSource().isPlayer())
{
return 1;
}

final String className = StringArgumentType.getString(context, "pathjobname");
if (className.equals("clear"))
{
PathfindingUtils.trackByType.entrySet().removeIf(entry -> entry.getValue().equals(context.getSource().getPlayer().getUUID()));
context.getSource().sendSystemMessage(Component.literal("Removed tracking for player"));
return 1;
}

PathfindingUtils.trackByType.put(className, context.getSource().getPlayer().getUUID());
context.getSource().sendSystemMessage(Component.literal("Tracking enabled for pathjobs containing: " + className));
return 1;
}

/**
* Name string of the command.
*/
@Override
public String getName()
{
return "trackPathType";
}

@Override
public LiteralArgumentBuilder<CommandSourceStack> build()
{
return IMCCommand.newLiteral(getName())
.then(IMCCommand.newArgument("pathjobname", StringArgumentType.word()).suggests((context, builder) -> {
builder.suggest("clear");
return builder.buildFuture();
}).executes(this::checkPreConditionAndExecute));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.minecolonies.api.colony.IColonyManager;
import com.minecolonies.api.colony.colonyEvents.registry.ColonyEventTypeRegistryEntry;
import com.minecolonies.api.colony.managers.interfaces.IRaiderManager;
import com.minecolonies.api.util.Log;
import com.minecolonies.api.util.constant.translation.CommandTranslationConstants;
import com.minecolonies.core.colony.events.raid.norsemenevent.NorsemenShipRaidEvent;
import com.minecolonies.core.colony.events.raid.pirateEvent.PirateGroundRaidEvent;
Expand Down Expand Up @@ -39,18 +40,28 @@ public int onExecute(final CommandContext<CommandSourceStack> context)

public int onSpecificExecute(final CommandContext<CommandSourceStack> context)
{
if(!checkPreCondition(context))
try
{
return 0;
if (!checkPreCondition(context))
{
return 0;
}
return raidExecute(context, StringArgumentType.getString(context, RAID_TYPE_ARG));
}
return raidExecute(context, StringArgumentType.getString(context, RAID_TYPE_ARG));
catch (Throwable e)
{
Log.getLogger().warn("Error during running command:", e);
}

return 0;
}

/**
* Actually find the colony and assign the raid event.
* @param context command context from the user.
* @param raidType type of raid, or "" if determining naturally.
* @return zero if failed, one if successful.
*
* @param context command context from the user.
* @param raidType type of raid, or "" if determining naturally.
* @return zero if failed, one if successful.
*/
public int raidExecute(final CommandContext<CommandSourceStack> context, final String raidType)
{
Expand All @@ -64,7 +75,7 @@ public int raidExecute(final CommandContext<CommandSourceStack> context, final S
}

final boolean allowShips = BoolArgumentType.getBool(context, SHIP_ARG);
if(StringArgumentType.getString(context, RAID_TIME_ARG).equals(RAID_NOW))
if (StringArgumentType.getString(context, RAID_TIME_ARG).equals(RAID_NOW))
{
final IRaiderManager.RaidSpawnResult result = colony.getRaiderManager().raiderEvent(raidType, true, allowShips);
if (result == IRaiderManager.RaidSpawnResult.SUCCESS)
Expand All @@ -74,11 +85,13 @@ public int raidExecute(final CommandContext<CommandSourceStack> context, final S
}
context.getSource().sendFailure(Component.translatable(CommandTranslationConstants.COMMAND_RAID_NOW_FAILURE, colony.getName(), result));
}
else if(StringArgumentType.getString(context, RAID_TIME_ARG).equals(RAID_TONIGHT))
else if (StringArgumentType.getString(context, RAID_TIME_ARG).equals(RAID_TONIGHT))
{
if (!colony.getRaiderManager().canRaid())
{
context.getSource().sendSuccess(() -> Component.translatable(CommandTranslationConstants.COMMAND_RAID_NOW_FAILURE, colony.getName(), IRaiderManager.RaidSpawnResult.CANNOT_RAID), true);
context.getSource()
.sendSuccess(() -> Component.translatable(CommandTranslationConstants.COMMAND_RAID_NOW_FAILURE, colony.getName(), IRaiderManager.RaidSpawnResult.CANNOT_RAID),
true);
return 1;
}
colony.getRaiderManager().setRaidNextNight(true, raidType, allowShips);
Expand All @@ -100,10 +113,10 @@ public String getName()
public LiteralArgumentBuilder<CommandSourceStack> build()
{
final List<String> raidTypes = new ArrayList<>();
for(final ColonyEventTypeRegistryEntry type : IMinecoloniesAPI.getInstance().getColonyEventRegistry().getValues())
for (final ColonyEventTypeRegistryEntry type : IMinecoloniesAPI.getInstance().getColonyEventRegistry().getValues())
{
if(!type.getRegistryName().getPath().equals(PirateGroundRaidEvent.PIRATE_GROUND_RAID_EVENT_TYPE_ID.getPath())
&& !type.getRegistryName().getPath().equals(NorsemenShipRaidEvent.NORSEMEN_RAID_EVENT_TYPE_ID.getPath()))
if (!type.getRegistryName().getPath().equals(PirateGroundRaidEvent.PIRATE_GROUND_RAID_EVENT_TYPE_ID.getPath())
&& !type.getRegistryName().getPath().equals(NorsemenShipRaidEvent.NORSEMEN_RAID_EVENT_TYPE_ID.getPath()))
{
raidTypes.add(type.getRegistryName().getPath());
}
Expand All @@ -116,11 +129,11 @@ public LiteralArgumentBuilder<CommandSourceStack> build()
return IMCCommand.newLiteral(getName())
.then(IMCCommand.newArgument(RAID_TIME_ARG, StringArgumentType.string())
.suggests((ctx, builder) -> SharedSuggestionProvider.suggest(opt, builder))
.then(IMCCommand.newArgument(COLONYID_ARG, IntegerArgumentType.integer(1))
.then(IMCCommand.newArgument(RAID_TYPE_ARG, StringArgumentType.string())
.suggests((ctx, builder) -> SharedSuggestionProvider.suggest(raidTypes, builder))
.then(IMCCommand.newArgument(SHIP_ARG, BoolArgumentType.bool())
.executes(this::onSpecificExecute)))
.executes(this::checkPreConditionAndExecute)));
.then(IMCCommand.newArgument(COLONYID_ARG, IntegerArgumentType.integer(1))
.then(IMCCommand.newArgument(RAID_TYPE_ARG, StringArgumentType.string())
.suggests((ctx, builder) -> SharedSuggestionProvider.suggest(raidTypes, builder))
.then(IMCCommand.newArgument(SHIP_ARG, BoolArgumentType.bool())
.executes(this::onSpecificExecute)))
.executes(this::checkPreConditionAndExecute)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
import com.minecolonies.api.entity.ai.statemachine.states.IAIState;
import com.minecolonies.api.entity.citizen.AbstractEntityCitizen;
import com.minecolonies.api.equipment.ModEquipmentTypes;
import com.minecolonies.core.entity.pathfinding.Pathfinding;
import com.minecolonies.core.entity.pathfinding.PathfindingUtils;
import com.minecolonies.core.entity.pathfinding.pathjobs.PathJobFindWater;
import com.minecolonies.core.entity.pathfinding.pathresults.WaterPathResult;
import com.minecolonies.api.loot.ModLootTables;
import com.minecolonies.api.sounds.EventType;
import com.minecolonies.api.util.*;
import com.minecolonies.core.colony.buildings.workerbuildings.BuildingFisherman;
import com.minecolonies.core.colony.interactionhandling.StandardInteraction;
import com.minecolonies.core.colony.jobs.JobFisherman;
import com.minecolonies.core.entity.other.NewBobberEntity;
import com.minecolonies.core.entity.ai.workers.AbstractEntityAISkill;
import com.minecolonies.core.entity.citizen.EntityCitizen;
import com.minecolonies.core.entity.other.NewBobberEntity;
import com.minecolonies.core.entity.pathfinding.Pathfinding;
import com.minecolonies.core.entity.pathfinding.PathfindingUtils;
import com.minecolonies.core.entity.pathfinding.pathjobs.PathJobFindWater;
import com.minecolonies.core.entity.pathfinding.pathresults.WaterPathResult;
import com.minecolonies.core.util.WorkerUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
Expand All @@ -46,8 +46,8 @@

import static com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState.*;
import static com.minecolonies.api.util.constant.Constants.TICKS_SECOND;
import static com.minecolonies.api.util.constant.StatisticsConstants.FISH_CAUGHT;
import static com.minecolonies.api.util.constant.EquipmentLevelConstants.TOOL_LEVEL_WOOD_OR_GOLD;
import static com.minecolonies.api.util.constant.StatisticsConstants.FISH_CAUGHT;
import static com.minecolonies.api.util.constant.TranslationConstants.WATER_TOO_FAR;
import static com.minecolonies.core.colony.buildings.modules.BuildingModules.STATS_MODULE;
import static com.minecolonies.core.entity.other.NewBobberEntity.XP_PER_CATCH;
Expand Down Expand Up @@ -417,10 +417,6 @@ private IAIState findNewWater()
pathResult = searchWater(SEARCH_RANGE * 3, 1.0D, job.getPonds());
return getState();
}
if (pathResult.isDone())
{
pathResult.getJob().syncDebug();
}
if (pathResult.failedToReachDestination())
{
return setRandomWater();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import net.minecraft.tags.BlockTags;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
Expand All @@ -29,9 +28,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashSet;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class PathfindingUtils
Expand All @@ -42,33 +39,33 @@ public class PathfindingUtils
private static Object empty = Fluids.EMPTY.defaultFluidState();

/**
* Which citizens are being tracked by which players.
* Which citizens are being tracked by which players. Player to entity uuid
*/
public static final Map<UUID, UUID> trackingMap = new ConcurrentHashMap<>();

/**
* Map for tracking specific path types, type to player uuid
*/
public static final Map<String, UUID> trackByType = new HashMap<>();

/**
* Set the set of reached blocks to the client.
*
* @param reached the reached blocks.
* @param mob the tracked mob.
*/
public static void syncDebugReachedPositions(final HashSet<BlockPos> reached, final Mob mob)
public static void syncDebugReachedPositions(final HashSet<BlockPos> reached, final List<ServerPlayer> players)
{
if (reached.isEmpty())
if (reached.isEmpty() || players.isEmpty())
{
return;
}

for (final Map.Entry<UUID, UUID> entry : trackingMap.entrySet())
final SyncPathReachedMessage message = new SyncPathReachedMessage(reached);

for (final ServerPlayer player : players)
{
if (entry.getValue().equals(mob.getUUID()))
{
final ServerPlayer player = mob.level.getServer().getPlayerList().getPlayer(entry.getKey());
if (player != null)
{
Network.getNetwork().sendToPlayer(new SyncPathReachedMessage(reached), player);
}
}
Network.getNetwork().sendToPlayer(message, player);
}
}

Expand Down Expand Up @@ -328,8 +325,8 @@ public static boolean isLadder(final BlockState blockState, @Nullable final Path
return true;
}
return blockState.is(BlockTags.CLIMBABLE) && ((options != null && options.canClimbAdvanced()) ||
blockState.getBlock() instanceof LadderBlock ||
blockState.is(ModTags.freeClimbBlocks));
blockState.getBlock() instanceof LadderBlock ||
blockState.is(ModTags.freeClimbBlocks));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,6 @@ private void processCompletedCalculationResult()
return;
}

pathResult.getJob().syncDebug();
moveTo(pathResult.getPath(), getSpeedFactor());
if (pathResult != null)
{
Expand Down Expand Up @@ -1003,7 +1002,7 @@ protected void followThePath()

if (isTracking)
{
PathfindingUtils.syncDebugReachedPositions(reached, ourEntity);
PathfindingUtils.syncDebugReachedPositions(reached, pathResult.getDebugWatchers());
reached.clear();
}

Expand Down Expand Up @@ -1047,7 +1046,7 @@ else if (isTracking)

if (isTracking)
{
PathfindingUtils.syncDebugReachedPositions(reached, ourEntity);
PathfindingUtils.syncDebugReachedPositions(reached, pathResult.getDebugWatchers());
reached.clear();
}
}
Expand Down
Loading