Skip to content

Commit

Permalink
Portable Edition mod start
Browse files Browse the repository at this point in the history
  • Loading branch information
arpruss committed May 29, 2015
1 parent 52f3fd5 commit 4e94fda
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 0 deletions.
161 changes: 161 additions & 0 deletions pe/droidjam.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
// droidjam.js (c) 2015 by Alexander R. Pruss
//
// Based on : Simple finger server
// Copyright (c) 2009 by James K. Lawless ([email protected] http://www.radiks.net/~jimbo)
//
// License: MIT / X11
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

//importPackage(java.net);
//importPackage(java.io);

var serv;
var socket;
var reader;
var writer;
var thread;
var running;

function newLevel() {
print("new Level");
running = true;
thread = new java.lang.Thread(runServer);
thread.start();
}

function runServer() {
try {
serv=new java.net.ServerSocket(4711,1);
}
catch(e) {
print("Error "+e);
return;
}
while(running) {
reader = undefined;
writer = undefined;
socket = undefined;

try {
// print("awaiting connection");
if (!running)
break;
socket=serv.accept();
reader=new java.io.BufferedReader(
new java.io.InputStreamReader(
socket.getInputStream()));
writer=new java.io.PrintWriter(socket.getOutputStream(),true);

while(running) {
var str = reader.readLine();
if (undefined == str)
break;
// android.util.Log.v("droidjam", str);
handleCommand(str);
//writer.println("Received message "+str);
}
}
catch(e) {
if (running)
print("Error "+e);
}
print("closing connection");
android.util.Log.v("droidjam", "closing connection");
try {
reader.close();
} catch(e) {}
reader = undefined;
try {
writer.close();
} catch(e) {}
writer = undefined;
try {
socket.close();
} catch(e) {}
socket = undefined;
android.util.Log.v("droidjam", "closed connection");
}
try {
serv.close();
android.util.Log.v("droidjam", "closed socket");
} catch(e) {}
}

function leaveGame() {
android.util.Log.v("droidjam", "leaveGame()");
print("leaveGame()");
running = false;
try {
reader.close();
}
catch(e) {}
try {
writer.close();
}
catch(e) {}
try {
socket.close();
}
catch(e) {}
try {
serv.close();
print("closed server");
}
catch(e) {}
}

function handleCommand(cmd) {
cmd = cmd.trim();
var n = cmd.indexOf("(");
if (n==-1 || cmd.slice(-1) != ")") {
err("Cannot parse");
return;
}
var m = cmd.substring(0,n);
var argList = cmd.substring(n+1,cmd.length()-1);
var args = argList.split(",");
if (m == "world.setBlock") {
setBlock(args);
}
else if (m == "player.getPos") {
writer.println(""+Player.getX()+","+Player.getY()+","+Player.getZ());
}
else if (m == "player.setPos") {
Entity.setPosition(Player.getEntity(),args[0],args[1],args[2]);
}
else if (m == "chat.post") {
clientMessage(argList);
}
else {
err("Unknown command");
}
}

function setBlock(args) {
Level.setTile(args[0], args[1], args[2], args[3], args[4]);
}

function err(msg) {
writer.println("ERR "+msg);
print("ERR "+msg);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.BlockPos;
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;
Expand All @@ -43,6 +45,12 @@ public void setStopChanges(boolean stopChanges) {
this.stopChanges = stopChanges;
}

// @SubscribeEvent
// public void onInitMapGenEvent(InitMapGenEvent event) {
// System.out.println("Init map gen");
// MinecraftServer.getServer().setDifficultyForAllWorlds(EnumDifficulty.PEACEFUL);
// }

// @SubscribeEvent
// public void onKeyInput(InputEvent.KeyInputEvent event) {
// if(KeyBindings.superchat.isPressed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class RaspberryJamMod
private PythonExternalCommand pythonExternalCommand = null;
public static Configuration configFile;
public static int portNumber = 4711;
// public static int defaultDifficulty = -1;

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
Expand All @@ -59,6 +60,7 @@ public void preInit(FMLPreInitializationEvent event) {

public static void synchronizeConfig() {
portNumber = configFile.getInt("Port Number", Configuration.CATEGORY_GENERAL, 4711, 1, 65535, "Port number");
// defaultDifficulty = configFile.getInt("Default Difficulty", Configuration.CATEGORY_GENERAL, 4711, 1, 65535, "-1=default,0=peaceful,1=easy,2=normal,3=hard");

if (configFile.hasChanged())
configFile.save();
Expand All @@ -84,6 +86,7 @@ public void onServerStarting(FMLServerStartingEvent event) {
final MCEventHandler eventHandler = new MCEventHandler();
FMLCommonHandler.instance().bus().register(eventHandler);
MinecraftForge.EVENT_BUS.register(eventHandler);
// MinecraftForge.TERRAIN_GEN_BUS.register(eventHandler);
try {
mcc = new MinecraftCommunicator(eventHandler);

Expand Down

0 comments on commit 4e94fda

Please sign in to comment.