Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.classpath
.gradle/
.metadata/
.project
.settings/
110/.gradle/
110/build/
110/src/
111/.gradle/
111/.idea/
111/.metadata/
111/.project
111/.settings/
111/build/
111/src/
19/.classpath
19/.gradle/
19/.project
19/.settings/
19/19_Client.launch
19/19_Server.launch
19/bin/
19/build/
194/.gradle/
194/build/
194/src/
eclipse/

74 changes: 54 additions & 20 deletions 19/src/main/java/mobi/omegacentauri/raspberryjammod/APIHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,28 @@
// TODO: getHeight() should check block queue

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.ServerSocket;
import java.net.Socket;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.Set;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.main.GameConfiguration;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
Expand All @@ -44,7 +38,6 @@
import net.minecraft.nbt.NBTException;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.BlockPos;
Expand All @@ -53,12 +46,14 @@
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.WorldSettings;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;

public class APIHandler {
protected static final String CLICKLEFT = "click.left";
protected static final String CLICKRIGHT = "click.right";
protected static final String POLLFISH = "poll.fish";

// world.checkpoint.save/restore, player.setting, world.setting(nametags_visible,*),
// camera.setFixed() unsupported
// camera.setNormal(id) and camera.setFollow(id) uses spectating, and so it moves the
Expand Down Expand Up @@ -252,7 +247,6 @@ public class APIHandler {
public static final String PASSWORD_DATA = "raspberryjammod_passwords.dat";
public static final String PERMISSION_DATA = "raspberryjammod_permissions.dat";
private String salt = null;
private boolean authenticationSetup;
private List<HitDescription> hits = new LinkedList<HitDescription>();
protected List<ChatDescription> chats = new LinkedList<ChatDescription>();
private boolean restrictToSword = true;
Expand Down Expand Up @@ -529,8 +523,6 @@ void process(String clientSentence) throws IOException {
private void handlePermission() {
File perm = new File(PERMISSION_DATA);
if (perm.exists()) {
String permissionString = "";

try {
permission = new Permission(serverWorlds);
BufferedReader r = new BufferedReader(new FileReader(perm));
Expand Down Expand Up @@ -566,6 +558,8 @@ else if (toMatch != null && l.startsWith(toMatch)) {
protected void runCommand(String cmd, String args, Scanner scan)
throws InputMismatchException, NoSuchElementException, IndexOutOfBoundsException {

RaspberryJamMod.LOGGER.info("Running command: "+cmd);

if (cmd.equals(SETBLOCK)) {
Location pos = getBlockLocation(scan);

Expand Down Expand Up @@ -827,11 +821,55 @@ else if(cmd.equals(APISUPPORTS)) {
else if (cmd.equals(APIVERSION)) {
sendLine(RaspberryJamMod.MODID+","+RaspberryJamMod.VERSION+","+"java"+","+mcVersion());
}
else if (cmd.equals(CLICKLEFT)) {
toggle(mc.gameSettings.keyBindAttack);
}
else if (cmd.equals(CLICKRIGHT)) {
toggle(mc.gameSettings.keyBindUseItem);
}
else if (cmd.equals(POLLFISH)) {
new Thread() {
public void run() {
float y = 0.0f;
int count = 0;
while (true) {
try {
Thread.sleep(100);
int new_y = Minecraft.getMinecraft().thePlayer.fishEntity.getPosition().getY();
float delta = new_y - y;
if (count > 5 && -0.99 > delta && delta > -1.01) {
sendLine("got.fish");
return;
}
y = new_y;
count++;
} catch (Throwable t) {
System.err.println("Error waiting for fish");
t.printStackTrace();
}
}
}
}.start();
}
else {
unknownCommand();
}
}

private static void toggle(KeyBinding k) {
try {
// toggle key quickly
KeyBinding.setKeyBindState(k.getKeyCode(), true);
KeyBinding.onTick(k.getKeyCode());
try { Thread.sleep(32); } catch (InterruptedException e) {}
KeyBinding.setKeyBindState(k.getKeyCode(), false);
//KeyBinding.onTick(k.getKeyCode()); // this breaks fishing???
} catch (Exception e) {
RaspberryJamMod.LOGGER.error("Error toggling key "+k);
e.printStackTrace((PrintStream) RaspberryJamMod.LOGGER);
}
}

private boolean tooManyPlayerCommandArguments(String subcommand, String args) {
// check if there are more arguments than are needed; this detects if the
// script slipped in a username, for compatibility with RaspberryJuice
Expand Down Expand Up @@ -1090,7 +1128,7 @@ else if (cmd.equals(SETDEBUG)) {
}
else if (cmd.equals(SETDISTANCE)) {
Float d = scan.nextFloat();
Class c = net.minecraft.client.renderer.EntityRenderer.class;
Class<EntityRenderer> c = net.minecraft.client.renderer.EntityRenderer.class;
try {
Field f = c.getDeclaredField("thirdPersonDistance");
f.setAccessible(true);
Expand Down Expand Up @@ -1359,15 +1397,13 @@ protected void entityGetTile(int id) {
Entity e = getServerEntityByID(id);
if (e != null) {
World w = e.getEntityWorld();
Vec3d pos0 = e.getPositionVector();

while (w != e.getEntityWorld()) {
// Rare concurrency issue: entity switched worlds between getting w and pos0.
// To be somewhat safe, let's sleep for approximately a server tick and get
// everything again.
try { Thread.sleep(50); } catch(Exception exc) {}
w = e.getEntityWorld();
pos0 = e.getPositionVector();
}

Vec3d pos = Location.encodeVec3(serverWorlds, w, e.getPositionVector());
Expand Down Expand Up @@ -1492,7 +1528,6 @@ public String getHitsAndClear() {
String out = "";

synchronized(hits) {
int count = hits.size();
for (HitDescription e : hits) {
if (out.length() > 0)
out += "|";
Expand All @@ -1508,7 +1543,6 @@ public String getChatsAndClear() {
StringBuilder out = new StringBuilder();

synchronized(chats) {
int count = hits.size();
for (ChatDescription c : chats) {
if (out.length() > 0)
out.append("|");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package mobi.omegacentauri.raspberryjammod;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;

// This class is meant to provide most of the APIHandler facility while one is connected to a
// server. Of course, any block changes won't get written back to the server.
Expand Down Expand Up @@ -74,7 +71,7 @@ protected void spawnParticle(Scanner scan) {
double dx = scan.nextDouble();
double dy = scan.nextDouble();
double dz = scan.nextDouble();
double speed = scan.nextDouble();
/* speed */ scan.nextDouble();
int count = scan.nextInt();

int[] extras = null;
Expand Down
27 changes: 0 additions & 27 deletions 19/src/main/java/mobi/omegacentauri/raspberryjammod/APIServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,14 @@
// TODO: getHeight() should check block queue

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Scanner;

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.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.nbt.NBTException;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import net.minecraft.world.WorldSettings;
import net.minecraft.world.chunk.Chunk;

public class APIServer {
private static final int MAX_CONNECTIONS = 64;
Expand Down Expand Up @@ -93,7 +67,6 @@ public int getPortNumber() {

void communicate() throws IOException {
while(listening) {
Socket connectionSocket = null;
if (! RaspberryJamMod.concurrent) {
try {
socketCommunicate(serverSocket.accept());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.ArrayList;
import java.util.List;

import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;

public class AddLocalPythonExternalCommand extends PythonExternalCommand {
Expand All @@ -18,7 +16,7 @@ public String getCommandName() {
}

@Override
public List getCommandAliases() {
public List<String> getCommandAliases() {
List<String> aliases = new ArrayList<String>();
aliases.add(getCommandName());
aliases.add("alpy");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.ArrayList;
import java.util.List;

import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;

public class AddPythonExternalCommand extends PythonExternalCommand {
Expand All @@ -19,7 +17,7 @@ public String getCommandName() {
}

@Override
public List getCommandAliases() {
public List<String> getCommandAliases() {
List<String> aliases = new ArrayList<String>();
aliases.add(getCommandName());
aliases.add("apy");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,24 @@
package mobi.omegacentauri.raspberryjammod;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.Packet;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;

public class CameraCommand implements ICommand {
public CameraCommand() {
}

@Override
public List getTabCompletionOptions(MinecraftServer server,
public List<String> getTabCompletionOptions(MinecraftServer server,
ICommandSender sender, String[] args,
BlockPos pos) {

Expand All @@ -57,7 +41,7 @@ else if (args.length == 2 && args[0].equals("debug")) {
}

@Override
public List getCommandAliases() {
public List<String> getCommandAliases() {
List<String> aliases = new ArrayList<String>();
aliases.add(getCommandName());
return aliases;
Expand Down Expand Up @@ -96,7 +80,7 @@ public void usage(ICommandSender sender) {
new TextComponentString(getCommandUsage(sender)));
}

static public void setField(Class c, String field, Object object, Object value) {
static public void setField(Class<?> c, String field, Object object, Object value) {
try {
Field f = c.getDeclaredField(field);
f.setAccessible(true);
Expand All @@ -108,7 +92,7 @@ static public void setField(Class c, String field, Object object, Object value)
}

private void setThirdPersonDistance(float x) {
Class c = net.minecraft.client.renderer.EntityRenderer.class;
Class<EntityRenderer> c = net.minecraft.client.renderer.EntityRenderer.class;
EntityRenderer r = Minecraft.getMinecraft().entityRenderer;
setField(c, "thirdPersonDistance", r, x);
setField(c, "thirdPersonDistanceTemp", r, x);
Expand Down
Loading