diff --git a/python2-scripts.zip b/python2-scripts.zip index b8f097f..cbe69a9 100755 Binary files a/python2-scripts.zip and b/python2-scripts.zip differ diff --git a/python2-scripts/mcpipy/grenade.py b/python2-scripts/mcpipy/grenade.py index 230997e..3c5c1b6 100755 --- a/python2-scripts/mcpipy/grenade.py +++ b/python2-scripts/mcpipy/grenade.py @@ -13,6 +13,7 @@ from mc import * import time import sys +import os GRAVITIES = { 'sun':274, diff --git a/python2-scripts/mcpipy/vehicle.py b/python2-scripts/mcpipy/vehicle.py index e45fa07..1ab24ab 100755 --- a/python2-scripts/mcpipy/vehicle.py +++ b/python2-scripts/mcpipy/vehicle.py @@ -294,6 +294,7 @@ def moveTo(self,x,y,z,angleDegrees): if __name__ == '__main__': import time import sys + import os bubble = False nondestructive = False @@ -309,11 +310,21 @@ def moveTo(self,x,y,z,angleDegrees): flash = False minecraft = Minecraft() - vehiclePos = minecraft.player.getTilePos() + + try: + player = int(os.environ['MINECRAFT_PLAYER_ID']) + playerGetTilePos = lambda: minecraft.entity.getTilePos(player) + playerGetRotation = lambda: minecraft.entity.getRotation(player) + except: + player = minecraft.getPlayerId() + playerGetTilePos = minecraft.player.getTilePos + playerGetRotation = minecraft.player.getRotation + + vehiclePos = playerGetTilePos() vehicle = Vehicle(minecraft,nondestructive) minecraft.postToChat("Scanning vehicle") - vehicle.scan(vehiclePos.x,vehiclePos.y,vehiclePos.z,minecraft.player.getRotation(),flash) + vehicle.scan(vehiclePos.x,vehiclePos.y,vehiclePos.z,playerGetRotation(),flash) minecraft.postToChat("Number of blocks: "+str(len(vehicle.baseVehicle))) if bubble: minecraft.postToChat("Scanning for air bubble") @@ -326,6 +337,6 @@ def moveTo(self,x,y,z,angleDegrees): minecraft.postToChat("Now walk around.") while True: - pos = minecraft.player.getTilePos() - vehicle.moveTo(pos.x,pos.y,pos.z,minecraft.player.getRotation()) + pos = playerGetTilePos() + vehicle.moveTo(pos.x,pos.y,pos.z,playerGetRotation()) time.sleep(0.25) diff --git a/python3-scripts.zip b/python3-scripts.zip index f4d77e0..87c99ed 100644 Binary files a/python3-scripts.zip and b/python3-scripts.zip differ diff --git a/python3-scripts/mcpipy/grenade.py b/python3-scripts/mcpipy/grenade.py index 60cab10..03f1351 100755 --- a/python3-scripts/mcpipy/grenade.py +++ b/python3-scripts/mcpipy/grenade.py @@ -13,6 +13,7 @@ from .mc import * import time import sys +import os GRAVITIES = { 'sun':274, @@ -90,7 +91,7 @@ def getXYZ(path, t1): try: player = int(os.environ['MINECRAFT_PLAYER_ID']) except: - player = mc.world.getPlayerId() + player = mc.getPlayerId() center = mc.entity.getPos(player) azi = mc.entity.getRotation(player) * pi/180. diff --git a/python3-scripts/mcpipy/vehicle.py b/python3-scripts/mcpipy/vehicle.py index e78a05e..99fce69 100644 --- a/python3-scripts/mcpipy/vehicle.py +++ b/python3-scripts/mcpipy/vehicle.py @@ -294,6 +294,7 @@ def moveTo(self,x,y,z,angleDegrees): if __name__ == '__main__': import time import sys + import os bubble = False nondestructive = False @@ -309,11 +310,21 @@ def moveTo(self,x,y,z,angleDegrees): flash = False minecraft = Minecraft() - vehiclePos = minecraft.player.getTilePos() + + try: + player = int(os.environ['MINECRAFT_PLAYER_ID']) + playerGetTilePos = lambda: minecraft.entity.getTilePos(player) + playerGetRotation = lambda: minecraft.entity.getRotation(player) + except: + player = minecraft.getPlayerId() + playerGetTilePos = minecraft.player.getTilePos + playerGetRotation = minecraft.player.getRotation + + vehiclePos = playerGetTilePos() vehicle = Vehicle(minecraft,nondestructive) minecraft.postToChat("Scanning vehicle") - vehicle.scan(vehiclePos.x,vehiclePos.y,vehiclePos.z,minecraft.player.getRotation(),flash) + vehicle.scan(vehiclePos.x,vehiclePos.y,vehiclePos.z,playerGetRotation(),flash) minecraft.postToChat("Number of blocks: "+str(len(vehicle.baseVehicle))) if bubble: minecraft.postToChat("Scanning for air bubble") @@ -326,6 +337,6 @@ def moveTo(self,x,y,z,angleDegrees): minecraft.postToChat("Now walk around.") while True: - pos = minecraft.player.getTilePos() - vehicle.moveTo(pos.x,pos.y,pos.z,minecraft.player.getRotation()) + pos = playerGetTilePos() + vehicle.moveTo(pos.x,pos.y,pos.z,playerGetRotation()) time.sleep(0.25) diff --git a/src/main/java/mobi/omegacentauri/raspberryjammod/AddPythonExternalCommand.java b/src/main/java/mobi/omegacentauri/raspberryjammod/AddPythonExternalCommand.java new file mode 100644 index 0000000..a99b0f7 --- /dev/null +++ b/src/main/java/mobi/omegacentauri/raspberryjammod/AddPythonExternalCommand.java @@ -0,0 +1,40 @@ +package mobi.omegacentauri.raspberryjammod; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommand; +import net.minecraft.command.ICommandSender; +import net.minecraft.util.BlockPos; + +public class AddPythonExternalCommand extends PythonExternalCommand { + + public AddPythonExternalCommand() { + super(); + } + + @Override + public String getName() { + return "addpython"; + } + + @Override + public List getAliases() { + List aliases = new ArrayList(); + aliases.add(getName()); + aliases.add("apy"); + return aliases; + } + + @Override + public String getCommandUsage(ICommandSender sender) { + return "addpython script arguments: run a new script without stopping old one(s)"; + } + + @Override + public boolean addMode() { + return true; + } +} + diff --git a/src/main/java/mobi/omegacentauri/raspberryjammod/ClientEventHandler.java b/src/main/java/mobi/omegacentauri/raspberryjammod/ClientEventHandler.java new file mode 100644 index 0000000..e16df2e --- /dev/null +++ b/src/main/java/mobi/omegacentauri/raspberryjammod/ClientEventHandler.java @@ -0,0 +1,61 @@ +package mobi.omegacentauri.raspberryjammod; + +import java.beans.EventSetDescriptor; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.gui.GuiChat; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.event.ClickEvent; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemSword; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.potion.Potion; +import net.minecraft.potion.PotionEffect; +import net.minecraft.server.MinecraftServer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.IChatComponent; +import net.minecraft.world.EnumDifficulty; +import net.minecraft.world.World; +import net.minecraftforge.client.event.MouseEvent; +import net.minecraftforge.event.CommandEvent; +import net.minecraftforge.event.ServerChatEvent; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import net.minecraftforge.event.terraingen.InitMapGenEvent; +import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.common.eventhandler.Event; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.InputEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import net.minecraftforge.fml.relauncher.Side; + +public class ClientEventHandler { + private volatile boolean nightVision = false; + private int clientTickCount = 0; + + @SubscribeEvent + public void onClientTick(TickEvent.ClientTickEvent event) { + if (nightVision && clientTickCount % 1024 == 0) { + EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; + + if (player != null) { + player.addPotionEffect(new PotionEffect(Potion.nightVision.id, 4096)); + } + } + clientTickCount++; + } + public void setNightVision(boolean b) { + nightVision = b; + } + + public boolean getNightVision() { + return nightVision; + } +} diff --git a/src/main/java/mobi/omegacentauri/raspberryjammod/NightVisionExternalCommand.java b/src/main/java/mobi/omegacentauri/raspberryjammod/NightVisionExternalCommand.java index dfdbcf9..b71861a 100755 --- a/src/main/java/mobi/omegacentauri/raspberryjammod/NightVisionExternalCommand.java +++ b/src/main/java/mobi/omegacentauri/raspberryjammod/NightVisionExternalCommand.java @@ -30,16 +30,16 @@ import net.minecraft.util.IChatComponent; public class NightVisionExternalCommand implements ICommand { - private MCEventHandler eventHandler; + private ClientEventHandler eventHandler; - public NightVisionExternalCommand(MCEventHandler eventHandler) { - this.eventHandler = eventHandler; + public NightVisionExternalCommand(ClientEventHandler eventHandler2) { + this.eventHandler = eventHandler2; } @Override public List addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) { - + if (args.length == 1) { List options = new ArrayList(); options.add("off"); @@ -60,33 +60,33 @@ public List getAliases() { @Override public void execute(ICommandSender sender, String[] args) throws CommandException { - boolean nv; + boolean nv; if (args.length == 0) { - nv = ! eventHandler.getNightVision(); + nv = ! eventHandler.getNightVision(); } else if (args[0].toLowerCase().equals("on")) { - nv = true; - } - else if (args[0].toLowerCase().equals("off")) { - nv = false; - } - else { - throw new CommandException("Usage: /nightvision [on|off]"); - } + nv = true; + } + else if (args[0].toLowerCase().equals("off")) { + nv = false; + } + else { + throw new CommandException("Usage: /nightvision [on|off]"); + } eventHandler.setNightVision(nv); EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; if (player != null) { - if (nv) { - player.addPotionEffect(new PotionEffect(Potion.nightVision.id, 4096)); - player.addChatComponentMessage(new ChatComponentText("Enabled night vision")); - } - else { - player.removePotionEffect(Potion.nightVision.id); - player.addChatComponentMessage(new ChatComponentText("Disabled night vision")); - } - } + if (nv) { + player.addPotionEffect(new PotionEffect(Potion.nightVision.id, 4096)); + player.addChatComponentMessage(new ChatComponentText("Enabled night vision")); + } + else { + player.removePotionEffect(Potion.nightVision.id); + player.addChatComponentMessage(new ChatComponentText("Disabled night vision")); + } + } } @Override @@ -113,6 +113,4 @@ public boolean canCommandSenderUse(ICommandSender sender) { public boolean isUsernameIndex(String[] args, int index) { return false; } - } - diff --git a/src/main/java/mobi/omegacentauri/raspberryjammod/PythonExternalCommand.java b/src/main/java/mobi/omegacentauri/raspberryjammod/PythonExternalCommand.java index d4f098c..7d2e328 100755 --- a/src/main/java/mobi/omegacentauri/raspberryjammod/PythonExternalCommand.java +++ b/src/main/java/mobi/omegacentauri/raspberryjammod/PythonExternalCommand.java @@ -29,7 +29,7 @@ public List getAliases() { @Override public String getCommandUsage(ICommandSender sender) { - return "python script [arguments]: run script (omit script to stop previous script)"; + return "python script [arguments]: run script, stopping old one(s) (omit script to stop previous script)"; } @Override diff --git a/src/main/java/mobi/omegacentauri/raspberryjammod/RaspberryJamMod.java b/src/main/java/mobi/omegacentauri/raspberryjammod/RaspberryJamMod.java index 5d62e23..804f3d5 100644 --- a/src/main/java/mobi/omegacentauri/raspberryjammod/RaspberryJamMod.java +++ b/src/main/java/mobi/omegacentauri/raspberryjammod/RaspberryJamMod.java @@ -11,6 +11,8 @@ import java.util.InputMismatchException; import java.util.Scanner; +import scala.collection.script.Script; + import net.minecraft.block.state.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; @@ -20,6 +22,7 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.util.BlockPos; import net.minecraft.world.World; +import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.config.Configuration; @@ -35,17 +38,20 @@ import net.minecraftforge.fml.common.event.FMLServerStoppedEvent; import net.minecraftforge.fml.common.event.FMLServerStoppingEvent; import net.minecraftforge.fml.common.registry.EntityRegistry; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; @Mod(modid = RaspberryJamMod.MODID, version = RaspberryJamMod.VERSION, name = RaspberryJamMod.NAME, guiFactory = "mobi.omegacentauri.raspberryjammod.GuiFactory") public class RaspberryJamMod { public static final String MODID = "raspberryjammod"; - public static final String VERSION = "0.31"; + public static final String VERSION = "0.32"; public static final String NAME = "Raspberry Jam Mod"; private APIServer mcc; private PythonExternalCommand pythonExternalCommand = null; private NightVisionExternalCommand nightVisionExternalCommand = null; + public static ScriptExternalCommand[] scriptExternalCommands = null; public static Configuration configFile; public static int portNumber = 4711; public static boolean concurrent = true; @@ -53,6 +59,7 @@ public class RaspberryJamMod public static boolean allowRemote = true; public static volatile boolean active = false; public static String pythonInterpreter = "python"; + public MCEventHandler serverEventHandler = null; @Mod.EventHandler public void preInit(FMLPreInitializationEvent event) { @@ -63,6 +70,15 @@ public void preInit(FMLPreInitializationEvent event) { synchronizeConfig(); } + + @Mod.EventHandler + @SideOnly(Side.CLIENT) + public void Init(FMLInitializationEvent event) { + final ClientEventHandler eventHandler = new ClientEventHandler(); + FMLCommonHandler.instance().bus().register(eventHandler); + nightVisionExternalCommand = new NightVisionExternalCommand(eventHandler); + net.minecraftforge.client.ClientCommandHandler.instance.registerCommand(nightVisionExternalCommand); + } public static void synchronizeConfig() { portNumber = configFile.getInt("Port Number", Configuration.CATEGORY_GENERAL, 4711, 1, 65535, "Port number"); @@ -75,17 +91,29 @@ public static void synchronizeConfig() { configFile.save(); } + public static int closeAllScripts() { + if (scriptExternalCommands == null) + return 0; + int count = 0; + for (ScriptExternalCommand c : scriptExternalCommands) + count += c.close(); + return count; + } + @EventHandler public void onServerStopping(FMLServerStoppingEvent event) { active = false; + if (serverEventHandler != null) { + FMLCommonHandler.instance().bus().unregister(serverEventHandler); + serverEventHandler = null; + } + if (mcc != null) { mcc.close(); } - if (pythonExternalCommand != null) { - pythonExternalCommand.close(); - pythonExternalCommand = null; - } + closeAllScripts(); + scriptExternalCommands = null; } @EventHandler @@ -96,11 +124,11 @@ public void onServerStarting(FMLServerStartingEvent event) { active = true; - final MCEventHandler eventHandler = new MCEventHandler(); - FMLCommonHandler.instance().bus().register(eventHandler); - MinecraftForge.EVENT_BUS.register(eventHandler); + serverEventHandler = new MCEventHandler(); + FMLCommonHandler.instance().bus().register(serverEventHandler); + MinecraftForge.EVENT_BUS.register(serverEventHandler); try { - mcc = new APIServer(eventHandler); + mcc = new APIServer(serverEventHandler); new Thread(new Runnable() { @Override @@ -122,9 +150,12 @@ public void run() { System.out.println("Threw "+e1); } - pythonExternalCommand = new PythonExternalCommand(); - event.registerServerCommand(pythonExternalCommand); - nightVisionExternalCommand = new NightVisionExternalCommand(eventHandler); - event.registerServerCommand(nightVisionExternalCommand); + scriptExternalCommands = new ScriptExternalCommand[] { + new PythonExternalCommand(), + new AddPythonExternalCommand() + }; + for (ScriptExternalCommand c : scriptExternalCommands) { + event.registerServerCommand(c); + } } } diff --git a/src/main/java/mobi/omegacentauri/raspberryjammod/ScriptExternalCommand.java b/src/main/java/mobi/omegacentauri/raspberryjammod/ScriptExternalCommand.java index cf070ce..f79a12f 100755 --- a/src/main/java/mobi/omegacentauri/raspberryjammod/ScriptExternalCommand.java +++ b/src/main/java/mobi/omegacentauri/raspberryjammod/ScriptExternalCommand.java @@ -36,7 +36,6 @@ public abstract class ScriptExternalCommand implements ICommand { private List runningScripts; final String scriptProcessorPath; private World serverWorld; - private static final String[] allOptions = { "-add" }; public ScriptExternalCommand() { runningScripts = new LinkedList(); @@ -63,22 +62,11 @@ public List addTabCompletionOptions(ICommandSender sender, String[] args, if (args.length == 0) { return null; } - - for (int i = 0 ; i < args.length - 1 ; i++) - if (! args[i].startsWith("-")) - return null; - int arg = args.length - 1; - - if (args[arg].startsWith("-")) { - List list = new ArrayList(); - for (String o : allOptions) { - if (o.toLowerCase().startsWith(args[arg].toLowerCase())) { - list.add(o); - } - } - return list; - } + if (args.length != 1) + return null; + + int arg = 0; if (! sandboxedScriptPath(args[arg])) return null; @@ -187,6 +175,10 @@ public int close() { return closed; } + + public boolean addMode() { + return false; + } @Override public void execute(ICommandSender sender, String[] args) @@ -204,17 +196,10 @@ public void execute(ICommandSender sender, String[] args) return; } - int arg = 0; - boolean addMode = false; - - while (arg < args.length && args[arg].startsWith("-")) { - if (args[arg].startsWith("-a")) - addMode = true; - arg++; - } + boolean addMode = addMode(); if (!addMode) { - int c = close(); + int c = RaspberryJamMod.closeAllScripts(); if (0 < c) { String message; if (1 < c) @@ -225,6 +210,8 @@ public void execute(ICommandSender sender, String[] args) } } + int arg = 0; + if (args.length <= arg) { return; }