-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial support for discrete movement (#81)
* Added discrete movement support (north, south, west and east) * moved oping agents into ServerStateMachine class
- Loading branch information
Showing
4 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
...va/io/singularitynet/MissionHandlers/CommandForDiscreteRobotNavigationImplementation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package io.singularitynet.MissionHandlers; | ||
|
||
import io.singularitynet.projectmalmo.MissionInit; | ||
import net.minecraft.client.MinecraftClient; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.util.Map; | ||
|
||
|
||
public class CommandForDiscreteRobotNavigationImplementation extends CommandBase { | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(CommandForDiscreteRobotNavigationImplementation.class.getName()); | ||
|
||
private boolean moveAgent(String movement){ | ||
try { | ||
MinecraftClient client = MinecraftClient.getInstance(); | ||
LOGGER.debug("moving agent to " + movement); | ||
client.player.networkHandler.sendCommand("tp " + movement); | ||
return true; | ||
} catch (Exception e) { | ||
LogManager.getLogger().warn("Failed to move agent to " + movement); | ||
LogManager.getLogger().warn(e); | ||
return false; | ||
} | ||
} | ||
|
||
|
||
@Override | ||
protected boolean onExecute(String verb, String parameter, MissionInit missionInit) { | ||
|
||
if (verb == null || verb.length() == 0) | ||
{ | ||
return false; | ||
} | ||
Map<String, String> moveMap = Map.of( | ||
"movewest", "~-1 ~ ~", | ||
"moveeast", "~1 ~ ~", | ||
"movenorth", "~ ~ ~-1", | ||
"movesouth", "~ ~ ~1" | ||
); | ||
String parameters[] = parameter.split(" "); | ||
if (parameters.length != 1) return false; | ||
// Now parse the command: | ||
String lowerVerb = verb.toLowerCase(); | ||
if (!moveMap.containsKey(lowerVerb)){ | ||
return false; | ||
} | ||
return moveAgent(moveMap.get(lowerVerb)); | ||
} | ||
|
||
@Override | ||
public boolean isOverriding() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void setOverriding(boolean b) { | ||
|
||
} | ||
|
||
@Override | ||
public void install(MissionInit currentMissionInit) { | ||
|
||
} | ||
|
||
@Override | ||
public void deinstall(MissionInit currentMissionInit) { | ||
|
||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/io/singularitynet/MissionHandlers/DiscreteMovementCommandsImplementation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.singularitynet.MissionHandlers; | ||
|
||
import io.singularitynet.MissionHandlerInterfaces.ICommandHandler; | ||
import io.singularitynet.projectmalmo.DiscreteMovementCommands; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public class DiscreteMovementCommandsImplementation extends CommandGroup implements ICommandHandler { | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(DiscreteMovementCommandsImplementation.class.getName()); | ||
|
||
public DiscreteMovementCommandsImplementation(){ | ||
setShareParametersWithChildren(true); // Pass our parameter block on to the following children: | ||
this.addCommandHandler(new CommandForAttackAndUseImplementation()); | ||
this.addCommandHandler(new CommandForDiscreteRobotNavigationImplementation()); | ||
} | ||
|
||
@Override | ||
public boolean parseParameters(Object params) | ||
{ | ||
super.parseParameters(params); | ||
|
||
if (params == null || !(params instanceof DiscreteMovementCommands)) | ||
return false; | ||
|
||
DiscreteMovementCommands dmparams = (DiscreteMovementCommands)params; | ||
setUpAllowAndDenyLists(dmparams.getModifierList()); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isFixed() { return true; } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters