Skip to content

Commit

Permalink
better multiuser
Browse files Browse the repository at this point in the history
  • Loading branch information
arpruss committed Jun 23, 2015
1 parent a314d6c commit 475ec27
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 73 deletions.
Binary file modified python2-scripts.zip
Binary file not shown.
1 change: 1 addition & 0 deletions python2-scripts/mcpipy/grenade.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from mc import *
import time
import sys
import os

GRAVITIES = {
'sun':274,
Expand Down
19 changes: 15 additions & 4 deletions python2-scripts/mcpipy/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def moveTo(self,x,y,z,angleDegrees):
if __name__ == '__main__':
import time
import sys
import os

bubble = False
nondestructive = False
Expand All @@ -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")
Expand All @@ -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)
Binary file modified python3-scripts.zip
Binary file not shown.
3 changes: 2 additions & 1 deletion python3-scripts/mcpipy/grenade.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from .mc import *
import time
import sys
import os

GRAVITIES = {
'sun':274,
Expand Down Expand Up @@ -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.
Expand Down
19 changes: 15 additions & 4 deletions python3-scripts/mcpipy/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def moveTo(self,x,y,z,angleDegrees):
if __name__ == '__main__':
import time
import sys
import os

bubble = False
nondestructive = False
Expand All @@ -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")
Expand All @@ -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)
Original file line number Diff line number Diff line change
@@ -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<String> aliases = new ArrayList<String>();
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;
}
}

Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> options = new ArrayList<String>();
options.add("off");
Expand All @@ -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
Expand All @@ -113,6 +113,4 @@ public boolean canCommandSenderUse(ICommandSender sender) {
public boolean isUsernameIndex(String[] args, int index) {
return false;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 475ec27

Please sign in to comment.