@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
// [...]
String separator = getSeparator();
String scriptName = nbtTagCompound.getString("scriptName");
String scriptPath = "pythontool" + separator + scriptName;
proxy.runPython(world, player, scriptPath);
// [...]
}
^^^ This is how I refactored onItemRightClick(). The runPython() method does nothing on the dedicated server, while on the client:
public class ClientOnlyProxy extends CommonProxy
{
// [...]
@Override
public void runPython(World world, EntityPlayer player, String scriptPath) {
super.runPython(world, player, scriptPath);
if (world.isRemote) {
// client side
if (!Minecraft.getMinecraft().isSingleplayer()) {
// client talks to dedicated server (multiplayer game)
ClientCommandHandler.instance.executeCommand(player,
"/lpython " + scriptPath);
}
} else {
// server side
if (player.isSneaking()) { // shift pressed. Run new parallel script
Minecraft.getMinecraft().thePlayer.getServer().getCommandManager().executeCommand(player,
"/apy " + scriptPath);
} else { // shift not pressed. Cancel previous scripts and run new script
world.getMinecraftServer().getCommandManager().executeCommand(player,
"/python " + scriptPath);
}
}
}
}
I still need to figure out why they used two different approaches to execute commands on the integrated server--Minecraft.getMinecraft().thePlayer.getServer().getCommandManager().executeCommand() vs. world.getMinecraftServer().getCommandManager().executeCommand().
public abstract class CommonProxy {
// [...]
public void runPython(World world, EntityPlayer player, String scriptPath) {}
}
public class PythonTool {
// [...]
@SidedProxy(clientSide="pythontool.ClientOnlyProxy", serverSide="pythontool.DedicatedServerProxy")
public static CommonProxy proxy;
// [...]
}
Are still there significant mistakes? Thanks again!