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

Added initial support for discrete movement #81

Merged
merged 12 commits into from
Dec 26, 2024
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) {

}
}
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; }

}
11 changes: 11 additions & 0 deletions src/main/java/io/singularitynet/Server/ServerStateMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// --------------------------------------------------------------------------------------------------
package io.singularitynet.Server;

import com.mojang.authlib.GameProfile;
import io.singularitynet.*;
import io.singularitynet.MissionHandlers.MissionBehaviour;
import io.singularitynet.events.ServerEntityEventsVereya;
Expand All @@ -40,6 +41,7 @@

import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.OperatorEntry;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
Expand Down Expand Up @@ -783,6 +785,15 @@ else if (messageType == VereyaMessageType.CLIENT_AGENTRUNNING)
episodeHasCompleted(ServerState.RUNNING);
}
}
MinecraftServer minecraftServer = server.get();
if (minecraftServer == null){
LOGGER.error("WaitingForAgentsEpisode.onMessage: server is null");
return;
}
GameProfile gameProfile = player.getGameProfile();
OperatorEntry operatorEntry = new OperatorEntry(gameProfile, 4, true);
minecraftServer.getPlayerManager().getOpList().add(operatorEntry);
LOGGER.info(player.getName() + " was given op permissions");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public void onInitialize() {
this.stateMachine.queueStateChange(ServerState.WAITING_FOR_MOD_READY);
}
});

}

public void sendMissionInitDirectToServer(MissionInit minit) throws Exception
Expand Down