Skip to content

Commit

Permalink
Pathing debug additions (#10357)
Browse files Browse the repository at this point in the history
* Reworked debug tracking, now also allows tracking path jobs by type and can add players to a specific pathresult for direct tracking
  • Loading branch information
someaddons authored Nov 2, 2024
1 parent c11e5d6 commit 4abf648
Show file tree
Hide file tree
Showing 12 changed files with 363 additions and 161 deletions.
6 changes: 4 additions & 2 deletions documentation/formatter/intellij/Minecolonies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<option name="WRAP_COMMENTS" value="true" />
<JavaCodeStyleSettings>
<option name="BLANK_LINES_AROUND_INITIALIZER" value="0" />
<option name="RECORD_COMPONENTS_WRAP" value="2"/>
<option name="NEW_LINE_AFTER_LPAREN_IN_RECORD_HEADER" value="true"/>
</JavaCodeStyleSettings>
<MarkdownNavigatorCodeStyleSettings>
<option name="RIGHT_MARGIN" value="72" />
Expand Down Expand Up @@ -66,8 +68,8 @@
<option name="FOR_BRACE_FORCE" value="3" />
<option name="ENUM_CONSTANTS_WRAP" value="2" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="2" />
<option name="USE_RELATIVE_INDENTS" value="true" />
<option name="CONTINUATION_INDENT_SIZE" value="4"/>
<option name="USE_RELATIVE_INDENTS" value="false"/>
</indentOptions>
<arrangement>
<groups>
Expand Down
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();
}
133 changes: 67 additions & 66 deletions src/main/java/com/minecolonies/core/commands/EntryPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,92 +27,93 @@ public static void register(final CommandDispatcher<CommandSourceStack> dispatch
* Kill commands subtree
*/
final CommandTree killCommands = new CommandTree("kill")
.addNode(new CommandKillAnimal().build())
.addNode(new CommandKillChicken().build())
.addNode(new CommandKillCow().build())
.addNode(new CommandKillMonster().build())
.addNode(new CommandKillPig().build())
.addNode(new CommandKillRaider().build())
.addNode(new CommandKillSheep().build());
.addNode(new CommandKillAnimal().build())
.addNode(new CommandKillChicken().build())
.addNode(new CommandKillCow().build())
.addNode(new CommandKillMonster().build())
.addNode(new CommandKillPig().build())
.addNode(new CommandKillRaider().build())
.addNode(new CommandKillSheep().build());

/*
* Colony commands subtree
*/
final CommandTree colonyCommands = new CommandTree("colony")
.addNode(new CommandAddOfficer().build())
.addNode(new CommandSetRank().build())
.addNode(new CommandChangeOwner().build())
.addNode(new CommandClaimChunks().build())
.addNode(new CommandShowClaim().build())
.addNode(new CommandTeleport().build())
.addNode(new CommandDeleteColony().build())
.addNode(new CommandCanRaiderSpawn().build())
.addNode(new CommandRaid().build())
.addNode(new CommandHomeTeleport().build())
.addNode(new CommandListColonies().build())
.addNode(new CommandSetDeletable().build())
.addNode(new CommandReclaimChunks().build())
.addNode(new CommandLoadBackup().build())
.addNode(new CommandLoadAllBackups().build())
.addNode(new CommandColonyInfo().build())
.addNode(new CommandColonyPrintStats().build())
.addNode(new CommandColonyRaidsInfo().build())
.addNode(new CommandColonyChunks().build())
.addNode(new CommandRSReset().build())
.addNode(new CommandRSResetAll().build())
.addNode(new CommandSetAbandoned().build())
.addNode(new CommandExportColony().build());
.addNode(new CommandAddOfficer().build())
.addNode(new CommandSetRank().build())
.addNode(new CommandChangeOwner().build())
.addNode(new CommandClaimChunks().build())
.addNode(new CommandShowClaim().build())
.addNode(new CommandTeleport().build())
.addNode(new CommandDeleteColony().build())
.addNode(new CommandCanRaiderSpawn().build())
.addNode(new CommandRaid().build())
.addNode(new CommandHomeTeleport().build())
.addNode(new CommandListColonies().build())
.addNode(new CommandSetDeletable().build())
.addNode(new CommandReclaimChunks().build())
.addNode(new CommandLoadBackup().build())
.addNode(new CommandLoadAllBackups().build())
.addNode(new CommandColonyInfo().build())
.addNode(new CommandColonyPrintStats().build())
.addNode(new CommandColonyRaidsInfo().build())
.addNode(new CommandColonyChunks().build())
.addNode(new CommandRSReset().build())
.addNode(new CommandRSResetAll().build())
.addNode(new CommandSetAbandoned().build())
.addNode(new CommandExportColony().build());

/*
* Citizen commands subtree
*/
final CommandTree citizenCommands = new CommandTree("citizens")
.addNode(new CommandCitizenInfo().build())
.addNode(new CommandCitizenKill().build())
.addNode(new CommandCitizenList().build())
.addNode(new CommandCitizenReload().build())
.addNode(new CommandCitizenSpawnNew().build())
.addNode(new CommandCitizenTeleport().build())
.addNode(new CommandCitizenTriggerWalkTo().build())
.addNode(new CommandCitizenTrack().build());
.addNode(new CommandCitizenInfo().build())
.addNode(new CommandCitizenKill().build())
.addNode(new CommandCitizenList().build())
.addNode(new CommandCitizenReload().build())
.addNode(new CommandCitizenSpawnNew().build())
.addNode(new CommandCitizenTeleport().build())
.addNode(new CommandCitizenTriggerWalkTo().build())
.addNode(new CommandCitizenTrack().build())
.addNode(new CommandTrackType().build());

/*
* Root minecolonies command tree, all subtrees are added here.
*/
final CommandTree minecoloniesRoot = new CommandTree(Constants.MOD_ID)
.addNode(killCommands)
.addNode(colonyCommands)
.addNode(new CommandHomeTeleport().build())
.addNode(citizenCommands)
.addNode(new CommandWhereAmI().build())
.addNode(new CommandWhoAmI().build())
.addNode(new CommandRTP().build())
.addNode(new CommandUnloadForcedChunks().build())
.addNode(new CommandRaidAll().build())
.addNode(new CommandBackup().build())
.addNode(new CommandResetPlayerSupplies().build())
.addNode(new CommandHelp().build())
.addNode(new ScanCommand().build())
.addNode(new CommandPruneWorld().build());
.addNode(killCommands)
.addNode(colonyCommands)
.addNode(new CommandHomeTeleport().build())
.addNode(citizenCommands)
.addNode(new CommandWhereAmI().build())
.addNode(new CommandWhoAmI().build())
.addNode(new CommandRTP().build())
.addNode(new CommandUnloadForcedChunks().build())
.addNode(new CommandRaidAll().build())
.addNode(new CommandBackup().build())
.addNode(new CommandResetPlayerSupplies().build())
.addNode(new CommandHelp().build())
.addNode(ScanCommand.build())
.addNode(new CommandPruneWorld().build());

/*
* Root minecolonies alias command tree, all subtrees are added here.
*/
final CommandTree minecoloniesRootAlias = new CommandTree("mc")
.addNode(new CommandEntityTrack().build())
.addNode(killCommands)
.addNode(colonyCommands)
.addNode(new CommandHomeTeleport().build())
.addNode(citizenCommands)
.addNode(new CommandWhereAmI().build())
.addNode(new CommandWhoAmI().build())
.addNode(new CommandRTP().build())
.addNode(new CommandUnloadForcedChunks().build())
.addNode(new CommandRaidAll().build())
.addNode(new CommandBackup().build())
.addNode(new CommandResetPlayerSupplies().build())
.addNode(new CommandHelp().build())
.addNode(new CommandPruneWorld().build());
.addNode(new CommandEntityTrack().build())
.addNode(killCommands)
.addNode(colonyCommands)
.addNode(new CommandHomeTeleport().build())
.addNode(citizenCommands)
.addNode(new CommandWhereAmI().build())
.addNode(new CommandWhoAmI().build())
.addNode(new CommandRTP().build())
.addNode(new CommandUnloadForcedChunks().build())
.addNode(new CommandRaidAll().build())
.addNode(new CommandBackup().build())
.addNode(new CommandResetPlayerSupplies().build())
.addNode(new CommandHelp().build())
.addNode(new CommandPruneWorld().build());

// Adds all command trees to the dispatcher to register the commands.
dispatcher.register(minecoloniesRoot.build());
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)));
}
}
Loading

0 comments on commit 4abf648

Please sign in to comment.