server generates and saves both world and player and ticks entities
This commit is contained in:
parent
395e167728
commit
f6ab8847c6
.classpathbuild.gradle
javascript
lwjgl-rundir/resources/lang
sp-server/src
ipc/java/net/lax1dude/eaglercraft/sp/ipc
IPCPacket04RenameWorld.javaIPCPacket15ThrowException.javaIPCPacketFFProcessKeepAlive.javaIPCPacketManager.java
main/java/net
src
lwjgl/java/net/lax1dude/eaglercraft/adapter
main/java/net
lax1dude/eaglercraft
GuiScreenBackupWorld.javaGuiScreenCreateWorldSelection.javaGuiScreenSingleplayerConnecting.javaGuiScreenSingleplayerLoading.javaGuiScreenSingleplayerNotImplemented.javaGuiScreenSingleplayerNotice.javaIntegratedServer.javaIntegratedState.javaNoCatchParse.javaPKT.javaWebsocketNetworkManager.javaWorkerNetworkManager.java
minecraft
client
src
EntityList.javaEntityMinecartChest.javaEntityMinecartEmpty.javaEntityMinecartFurnace.javaEntityMinecartHopper.javaEntityMinecartMobSpawner.javaEntityMinecartTNT.javaEntityPainting.javaGameRuleValue.javaGuiConnecting.javaGuiCreateFlatWorld.javaGuiCreateFlatWorldListSlot.javaGuiCreateWorld.javaGuiDownloadTerrain.javaGuiFlatPresets.javaGuiFlatPresetsItem.javaGuiFlatPresetsListSlot.javaGuiGameOver.javaGuiIngame.javaGuiIngameMenu.javaGuiMainMenu.javaGuiProgress.javaGuiRenameWorld.javaGuiScreenChatOptions.javaGuiSelectWorld.javaGuiWorldSlot.javaNetClientHandler.javaSaveFormatComparator.javaWorldInfo.javaWorldSettings.java
teavm/java/net/lax1dude/eaglercraft/adapter
@ -12,6 +12,12 @@
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/main" path="sp-server/src/ipc/java">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
|
||||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||
<classpathentry kind="output" path="bin/default"/>
|
||||
|
@ -13,7 +13,7 @@ apply plugin: 'java'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'io.github.zebalu.teavm-gradle-plugin'
|
||||
|
||||
sourceCompatibility = 1.7
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
|
||||
sourceSets {
|
||||
@ -21,6 +21,7 @@ sourceSets {
|
||||
java {
|
||||
srcDir 'src/main/java'
|
||||
srcDir 'src/teavm/java'
|
||||
srcDir 'sp-server/src/ipc/java'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
266852
javascript/classes.js
266852
javascript/classes.js
File diff suppressed because one or more lines are too long
1
javascript/classes.js.map
Normal file
1
javascript/classes.js.map
Normal file
File diff suppressed because one or more lines are too long
202947
javascript/classes_server.js
202947
javascript/classes_server.js
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -54,10 +54,10 @@ selectWorld.empty=empty
|
||||
selectWorld.world=World
|
||||
selectWorld.select=Play Selected World
|
||||
selectWorld.create=Create New World
|
||||
selectWorld.recreate=Re-Create
|
||||
selectWorld.backup=Backup
|
||||
selectWorld.createDemo=Play New Demo World
|
||||
selectWorld.delete=Delete
|
||||
selectWorld.rename=Rename
|
||||
selectWorld.delete=Delete
|
||||
selectWorld.deleteQuestion=Are you sure you want to delete this world?
|
||||
selectWorld.deleteWarning=will be lost forever! (A long time!)
|
||||
selectWorld.deleteButton=Delete
|
||||
@ -73,6 +73,25 @@ selectWorld.seedInfo=Leave blank for a random seed
|
||||
selectWorld.cheats=Cheats
|
||||
selectWorld.customizeType=Customize
|
||||
|
||||
selectWorld.backup.title=World Backup Menu:
|
||||
selectWorld.backup.recreate=Re-Create World
|
||||
selectWorld.backup.recreate.tooltip=Create a new world with the same seed
|
||||
selectWorld.backup.seed=Seed:
|
||||
selectWorld.backup.duplicate=Duplicate World
|
||||
selectWorld.backup.duplicate.tooltip=Copy this world into a new save
|
||||
selectWorld.backup.export=Export World Backup
|
||||
selectWorld.backup.export.tooltip=Download this world as a compressed backup file
|
||||
selectWorld.backup.vanilla=Convert to Vanilla
|
||||
selectWorld.backup.vanilla.tooltip=Download this world as a vanilla 1.5.2 world
|
||||
|
||||
selectWorld.create.title=What do you wanna do?
|
||||
selectWorld.create.create=Create New World
|
||||
selectWorld.create.create.tooltip=Make a new world for eaglercraft
|
||||
selectWorld.create.import=Load World Backup
|
||||
selectWorld.create.import.tooltip=Load an Eaglercraft backup file
|
||||
selectWorld.create.vanilla=Import Vanilla World
|
||||
selectWorld.create.vanilla.tooltip=Load a vanilla minecraft 1.5.2 world
|
||||
|
||||
createWorld.customize.presets=Presets
|
||||
createWorld.customize.presets.title=Select a Preset
|
||||
createWorld.customize.presets.select=Use Preset
|
||||
|
@ -16,9 +16,10 @@ public class IPCPacket04RenameWorld implements IPCPacketBase {
|
||||
public IPCPacket04RenameWorld() {
|
||||
}
|
||||
|
||||
public IPCPacket04RenameWorld(String worldOldName, String worldNewName, boolean copy) {
|
||||
public IPCPacket04RenameWorld(String worldOldName, String worldNewName, String displayName, boolean copy) {
|
||||
this.worldOldName = worldOldName;
|
||||
this.worldNewName = worldNewName;
|
||||
this.displayName = displayName;
|
||||
this.copy = copy;
|
||||
}
|
||||
|
||||
|
@ -60,5 +60,12 @@ public class IPCPacket15ThrowException implements IPCPacketBase {
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
public void log() {
|
||||
System.err.println("Integrated server exception: " + errorMessage);
|
||||
for(String s : stackTrace) {
|
||||
System.err.println(" at " + s);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,16 +7,26 @@ import java.io.IOException;
|
||||
public class IPCPacketFFProcessKeepAlive implements IPCPacketBase {
|
||||
|
||||
public static final int ID = 0xFF;
|
||||
|
||||
public static final int KEEPALIVE = 0;
|
||||
|
||||
public int ack;
|
||||
|
||||
public IPCPacketFFProcessKeepAlive() {
|
||||
}
|
||||
|
||||
public IPCPacketFFProcessKeepAlive(int ack) {
|
||||
this.ack = ack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserialize(DataInput bin) throws IOException {
|
||||
ack = bin.readUnsignedByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(DataOutput bin) throws IOException {
|
||||
bin.writeByte(ack);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -26,7 +36,7 @@ public class IPCPacketFFProcessKeepAlive implements IPCPacketBase {
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,10 +4,11 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class IPCPacketManager {
|
||||
|
||||
public static final HashMap<Integer, Class<? extends IPCPacketBase>> mappings = new HashMap();
|
||||
public static final HashMap<Integer, Supplier<IPCPacketBase>> mappings = new HashMap();
|
||||
|
||||
public static final IPCInputStream IPC_INPUT_STREAM = new IPCInputStream();
|
||||
public static final IPCOutputStream IPC_OUTPUT_STREAM = new IPCOutputStream();
|
||||
@ -16,28 +17,28 @@ public class IPCPacketManager {
|
||||
public static final DataOutputStream IPC_DATA_OUTPUT_STREAM = new DataOutputStream(IPC_OUTPUT_STREAM);
|
||||
|
||||
static {
|
||||
mappings.put(IPCPacket00StartServer.ID, IPCPacket00StartServer.class);
|
||||
mappings.put(IPCPacket01StopServer.ID, IPCPacket01StopServer.class);
|
||||
mappings.put(IPCPacket02InitWorld.ID, IPCPacket02InitWorld.class);
|
||||
mappings.put(IPCPacket03DeleteWorld.ID, IPCPacket03DeleteWorld.class);
|
||||
mappings.put(IPCPacket04RenameWorld.ID, IPCPacket04RenameWorld.class);
|
||||
mappings.put(IPCPacket05RequestData.ID, IPCPacket05RequestData.class);
|
||||
mappings.put(IPCPacket06RenameWorldNBT.ID, IPCPacket06RenameWorldNBT.class);
|
||||
mappings.put(IPCPacket07ImportWorld.ID, IPCPacket07ImportWorld.class);
|
||||
mappings.put(IPCPacket09RequestResponse.ID, IPCPacket09RequestResponse.class);
|
||||
mappings.put(IPCPacket0ASetWorldDifficulty.ID, IPCPacket0ASetWorldDifficulty.class);
|
||||
mappings.put(IPCPacket0BPause.ID, IPCPacket0BPause.class);
|
||||
mappings.put(IPCPacket0CPlayerChannel.ID, IPCPacket0CPlayerChannel.class);
|
||||
mappings.put(IPCPacket0DProgressUpdate.ID, IPCPacket0DProgressUpdate.class);
|
||||
mappings.put(IPCPacket0EListWorlds.ID, IPCPacket0EListWorlds.class);
|
||||
mappings.put(IPCPacket0FListFiles.ID, IPCPacket0FListFiles.class);
|
||||
mappings.put(IPCPacket10FileRead.ID, IPCPacket10FileRead.class);
|
||||
mappings.put(IPCPacket12FileWrite.ID, IPCPacket12FileWrite.class);
|
||||
mappings.put(IPCPacket13FileCopyMove.ID, IPCPacket13FileCopyMove.class);
|
||||
mappings.put(IPCPacket14StringList.ID, IPCPacket14StringList.class);
|
||||
mappings.put(IPCPacket15ThrowException.ID, IPCPacket15ThrowException.class);
|
||||
mappings.put(IPCPacket16NBTList.ID, IPCPacket16NBTList.class);
|
||||
mappings.put(IPCPacketFFProcessKeepAlive.ID, IPCPacketFFProcessKeepAlive.class);
|
||||
mappings.put(IPCPacket00StartServer.ID, () -> new IPCPacket00StartServer());
|
||||
mappings.put(IPCPacket01StopServer.ID, () -> new IPCPacket01StopServer());
|
||||
mappings.put(IPCPacket02InitWorld.ID, () -> new IPCPacket02InitWorld());
|
||||
mappings.put(IPCPacket03DeleteWorld.ID, () -> new IPCPacket03DeleteWorld());
|
||||
mappings.put(IPCPacket04RenameWorld.ID, () -> new IPCPacket04RenameWorld());
|
||||
mappings.put(IPCPacket05RequestData.ID, () -> new IPCPacket05RequestData());
|
||||
mappings.put(IPCPacket06RenameWorldNBT.ID, () -> new IPCPacket06RenameWorldNBT());
|
||||
mappings.put(IPCPacket07ImportWorld.ID, () -> new IPCPacket07ImportWorld());
|
||||
mappings.put(IPCPacket09RequestResponse.ID, () -> new IPCPacket09RequestResponse());
|
||||
mappings.put(IPCPacket0ASetWorldDifficulty.ID, () -> new IPCPacket0ASetWorldDifficulty());
|
||||
mappings.put(IPCPacket0BPause.ID, () -> new IPCPacket0BPause());
|
||||
mappings.put(IPCPacket0CPlayerChannel.ID, () -> new IPCPacket0CPlayerChannel());
|
||||
mappings.put(IPCPacket0DProgressUpdate.ID, () -> new IPCPacket0DProgressUpdate());
|
||||
mappings.put(IPCPacket0EListWorlds.ID, () -> new IPCPacket0EListWorlds());
|
||||
mappings.put(IPCPacket0FListFiles.ID, () -> new IPCPacket0FListFiles());
|
||||
mappings.put(IPCPacket10FileRead.ID, () -> new IPCPacket10FileRead());
|
||||
mappings.put(IPCPacket12FileWrite.ID, () -> new IPCPacket12FileWrite());
|
||||
mappings.put(IPCPacket13FileCopyMove.ID, () -> new IPCPacket13FileCopyMove());
|
||||
mappings.put(IPCPacket14StringList.ID, () -> new IPCPacket14StringList());
|
||||
mappings.put(IPCPacket15ThrowException.ID, () -> new IPCPacket15ThrowException());
|
||||
mappings.put(IPCPacket16NBTList.ID, () -> new IPCPacket16NBTList());
|
||||
mappings.put(IPCPacketFFProcessKeepAlive.ID, () -> new IPCPacketFFProcessKeepAlive());
|
||||
}
|
||||
|
||||
public static byte[] IPCSerialize(IPCPacketBase pkt) throws IOException {
|
||||
@ -54,25 +55,20 @@ public class IPCPacketManager {
|
||||
IPC_INPUT_STREAM.feedBuffer(pkt);
|
||||
int i = IPC_INPUT_STREAM.read();
|
||||
|
||||
Class<? extends IPCPacketBase> pk = mappings.get(Integer.valueOf(i));
|
||||
Supplier<IPCPacketBase> pk = mappings.get(Integer.valueOf(i));
|
||||
if(pk == null) {
|
||||
throw new IOException("Packet type 0x" + Integer.toHexString(i) + " doesn't exist");
|
||||
}
|
||||
|
||||
IPCPacketBase p;
|
||||
try {
|
||||
p = pk.newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | SecurityException e) {
|
||||
throw new RuntimeException("Packet type 0x" + Integer.toHexString(i) + " class '" + pk.getSimpleName() + "' could not be constructed", e);
|
||||
}
|
||||
IPCPacketBase p = pk.get();
|
||||
|
||||
IPC_INPUT_STREAM.nameBuffer(pk.getSimpleName());
|
||||
IPC_INPUT_STREAM.nameBuffer(p.getClass().getSimpleName());
|
||||
|
||||
p.deserialize(IPC_DATA_INPUT_STREAM);
|
||||
|
||||
int lo = IPC_INPUT_STREAM.getLeftoverCount();
|
||||
if(lo > 0) {
|
||||
System.err.println("Packet type 0x" + Integer.toHexString(i) + " class '" + pk.getSimpleName() + "' was size " + (pkt.length - 1) + " but only " + (pkt.length - 1 - lo) + " bytes were read");
|
||||
System.err.println("Packet type 0x" + Integer.toHexString(i) + " class '" + p.getClass().getSimpleName() + "' was size " + (pkt.length - 1) + " but only " + (pkt.length - 1 - lo) + " bytes were read");
|
||||
}
|
||||
|
||||
return p;
|
||||
|
@ -19,18 +19,22 @@ public class EAGMinecraftServer extends MinecraftServer {
|
||||
public EAGMinecraftServer(String world, String owner, WorldSettings currentWorldSettings) {
|
||||
super(world);
|
||||
this.setServerOwner(owner);
|
||||
System.out.println("server owner: " + owner);
|
||||
this.setConfigurationManager(new EAGPlayerList(this));
|
||||
this.listenThreadImpl = new WorkerListenThread(this);
|
||||
this.newWorldSettings = currentWorldSettings;
|
||||
this.paused = false;
|
||||
}
|
||||
|
||||
public void setBaseServerProperties(int difficulty, EnumGameType gamemode) {
|
||||
this.difficulty = difficulty;
|
||||
this.gamemode = gamemode;
|
||||
this.setCanSpawnAnimals(true);
|
||||
this.setCanSpawnNPCs(true);
|
||||
}
|
||||
|
||||
public void mainLoop() {
|
||||
if(paused) {
|
||||
if(paused && this.playersOnline.size() <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -50,19 +54,31 @@ public class EAGMinecraftServer extends MinecraftServer {
|
||||
|
||||
if (this.worldServers[0].areAllPlayersAsleep()) {
|
||||
this.tick();
|
||||
lastTick = ctm;
|
||||
lastTick = System.currentTimeMillis();
|
||||
} else {
|
||||
boolean mustYield = false;
|
||||
while (delta > 50L) {
|
||||
if(mustYield) {
|
||||
try {
|
||||
Thread.sleep(1l); // allow some async
|
||||
}catch(InterruptedException e) {
|
||||
System.err.println("you eagler");
|
||||
}
|
||||
}
|
||||
delta -= 50L;
|
||||
this.tick();
|
||||
mustYield = true;
|
||||
lastTick = System.currentTimeMillis();
|
||||
}
|
||||
lastTick = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setPaused(boolean p) {
|
||||
paused = p;
|
||||
if(!p) {
|
||||
lastTick = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getPaused() {
|
||||
@ -71,7 +87,7 @@ public class EAGMinecraftServer extends MinecraftServer {
|
||||
|
||||
@Override
|
||||
protected boolean startServer() throws IOException {
|
||||
this.loadAllWorlds(folderName, "world", difficulty, newWorldSettings);
|
||||
this.loadAllWorlds(folderName, 0l, newWorldSettings);
|
||||
this.lastTick = System.currentTimeMillis();
|
||||
return true;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ public class EAGPlayerList extends ServerConfigurationManager {
|
||||
|
||||
public EAGPlayerList(MinecraftServer par1MinecraftServer) {
|
||||
super(par1MinecraftServer);
|
||||
this.viewDistance = 15;
|
||||
this.viewDistance = 4;
|
||||
}
|
||||
|
||||
protected void writePlayerData(EntityPlayerMP par1EntityPlayerMP) {
|
||||
@ -21,10 +21,6 @@ public class EAGPlayerList extends ServerConfigurationManager {
|
||||
}
|
||||
}
|
||||
|
||||
public String allowUserToConnect(String par2Str) {
|
||||
return par2Str.equalsIgnoreCase(this.getServerInstance().getServerOwner()) ? "fuck off don't hack your friends" : super.allowUserToConnect(par2Str);
|
||||
}
|
||||
|
||||
public NBTTagCompound getHostPlayerData() {
|
||||
return this.hostPlayerNBT;
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package net.lax1dude.eaglercraft.sp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@ -67,7 +69,9 @@ public class IntegratedServer {
|
||||
pkt[i] = (byte) a.get(i);
|
||||
}
|
||||
|
||||
messageQueue.add(new PKT(channel, pkt));
|
||||
synchronized(messageQueue) {
|
||||
messageQueue.add(new PKT(channel, pkt));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -85,7 +89,7 @@ public class IntegratedServer {
|
||||
}
|
||||
|
||||
private static boolean isServerStopped() {
|
||||
return currentProcess == null || currentProcess.isServerRunning();
|
||||
return currentProcess == null || !currentProcess.isServerRunning();
|
||||
}
|
||||
|
||||
public static void throwExceptionToClient(String msg, Throwable t) {
|
||||
@ -101,8 +105,25 @@ public class IntegratedServer {
|
||||
}
|
||||
|
||||
private static void processAsyncMessageQueue() {
|
||||
while(messageQueue.size() > 0) {
|
||||
PKT msg = messageQueue.remove(0);
|
||||
ArrayList<PKT> cur;
|
||||
synchronized(messageQueue) {
|
||||
if(messageQueue.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
cur = new ArrayList<PKT>(messageQueue);
|
||||
messageQueue.clear();
|
||||
}
|
||||
long watchDog = System.currentTimeMillis();
|
||||
Iterator<PKT> itr = cur.iterator();
|
||||
int overflow = 0;
|
||||
while(itr.hasNext()) {
|
||||
PKT msg = itr.next();
|
||||
|
||||
if(System.currentTimeMillis() - watchDog > 150l && !msg.channel.equals("IPC")) {
|
||||
++overflow;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if(msg.channel.equals("IPC")) {
|
||||
|
||||
@ -112,7 +133,7 @@ public class IntegratedServer {
|
||||
}catch(IOException e) {
|
||||
System.err.print("Failed to deserialize IPC packet: ");
|
||||
e.printStackTrace();
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
int id = packet.id();
|
||||
@ -126,9 +147,33 @@ public class IntegratedServer {
|
||||
currentProcess.stopServer();
|
||||
}
|
||||
|
||||
currentProcess = new EAGMinecraftServer("worlds/" + pkt.worldName, pkt.ownerName, newWorldSettings);
|
||||
currentProcess = new EAGMinecraftServer(pkt.worldName, pkt.ownerName, newWorldSettings);
|
||||
currentProcess.setBaseServerProperties(pkt.initialDifficulty, newWorldSettings == null ? EnumGameType.SURVIVAL : newWorldSettings.getGameType());
|
||||
currentProcess.startServer();
|
||||
|
||||
String[] worlds = SYS.VFS.getFile("worlds.txt").getAllLines();
|
||||
if(worlds == null || (worlds.length == 1 && worlds[0].trim().length() <= 0)) {
|
||||
worlds = null;
|
||||
}
|
||||
if(worlds == null) {
|
||||
SYS.VFS.getFile("worlds.txt").setAllChars(pkt.worldName);
|
||||
}else {
|
||||
boolean found = false;
|
||||
for(String s : worlds) {
|
||||
if(s.equals(pkt.worldName)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!found) {
|
||||
String[] s = new String[worlds.length + 1];
|
||||
s[0] = pkt.worldName;
|
||||
System.arraycopy(worlds, 0, s, 1, worlds.length);
|
||||
SYS.VFS.getFile("worlds.txt").setAllChars(String.join("\n", s));
|
||||
}
|
||||
}
|
||||
|
||||
sendIPCPacket(new IPCPacketFFProcessKeepAlive(IPCPacket00StartServer.ID));
|
||||
}
|
||||
break;
|
||||
case IPCPacket01StopServer.ID: {
|
||||
@ -140,8 +185,9 @@ public class IntegratedServer {
|
||||
throwExceptionToClient("Failed to stop server!", t);
|
||||
}
|
||||
}else {
|
||||
System.err.println("Client tried to stop server while it was running for some reason");
|
||||
System.err.println("Client tried to stop server while it wasn't running for some reason");
|
||||
}
|
||||
sendIPCPacket(new IPCPacketFFProcessKeepAlive(IPCPacket01StopServer.ID));
|
||||
}
|
||||
break;
|
||||
case IPCPacket02InitWorld.ID: {
|
||||
@ -164,6 +210,7 @@ public class IntegratedServer {
|
||||
if(SYS.VFS.deleteFiles("worlds/" + pkt.worldName) <= 0) {
|
||||
throwExceptionToClient("Failed to delete world!", new RuntimeException("VFS did not delete directory 'worlds/" + pkt.worldName + "' correctly"));
|
||||
}
|
||||
sendIPCPacket(new IPCPacketFFProcessKeepAlive(IPCPacket03DeleteWorld.ID));
|
||||
}
|
||||
break;
|
||||
case IPCPacket04RenameWorld.ID: {
|
||||
@ -181,6 +228,7 @@ public class IntegratedServer {
|
||||
throwExceptionToClient("Failed to copy/rename world!", new RuntimeException("Failed to change level.dat world '" + pkt.worldNewName + "' display name to '" + pkt.displayName + "' because level.dat was missing"));
|
||||
}
|
||||
}
|
||||
sendIPCPacket(new IPCPacketFFProcessKeepAlive(IPCPacket04RenameWorld.ID));
|
||||
}
|
||||
break;
|
||||
case IPCPacket05RequestData.ID:
|
||||
@ -220,7 +268,15 @@ public class IntegratedServer {
|
||||
case IPCPacket0BPause.ID: {
|
||||
IPCPacket0BPause pkt = (IPCPacket0BPause)packet;
|
||||
if(!isServerStopped()) {
|
||||
currentProcess.setPaused(pkt.pause);
|
||||
if(!pkt.pause && !currentProcess.getPaused()) {
|
||||
currentProcess.saveAllWorlds(true);
|
||||
}else {
|
||||
currentProcess.setPaused(pkt.pause);
|
||||
if(pkt.pause) {
|
||||
currentProcess.saveAllWorlds(true);
|
||||
}
|
||||
}
|
||||
sendIPCPacket(new IPCPacketFFProcessKeepAlive(IPCPacket0BPause.ID));
|
||||
}else {
|
||||
System.err.println("Client tried to " + (pkt.pause ? "pause" : "unpause") + " while server was stopped");
|
||||
}
|
||||
@ -247,6 +303,13 @@ public class IntegratedServer {
|
||||
IPCPacket0EListWorlds pkt = (IPCPacket0EListWorlds)packet;
|
||||
if(isServerStopped()) {
|
||||
String[] worlds = SYS.VFS.getFile("worlds.txt").getAllLines();
|
||||
if(worlds == null || (worlds.length == 1 && worlds[0].trim().length() <= 0)) {
|
||||
worlds = null;
|
||||
}
|
||||
if(worlds == null) {
|
||||
sendIPCPacket(new IPCPacket16NBTList(IPCPacket16NBTList.WORLD_LIST, new LinkedList<NBTTagCompound>()));
|
||||
break;
|
||||
}
|
||||
LinkedList<String> updatedList = new LinkedList();
|
||||
LinkedList<NBTTagCompound> sendListNBT = new LinkedList();
|
||||
boolean rewrite = false;
|
||||
@ -261,7 +324,9 @@ public class IntegratedServer {
|
||||
}else {
|
||||
NBTTagCompound worldDatNBT;
|
||||
try {
|
||||
sendListNBT.add(CompressedStreamTools.decompress(lvl.getAllBytes()));
|
||||
worldDatNBT = CompressedStreamTools.decompress(lvl.getAllBytes());
|
||||
worldDatNBT.setString("folderName", w);
|
||||
sendListNBT.add(worldDatNBT);
|
||||
updatedList.add(w);
|
||||
}catch(IOException e) {
|
||||
rewrite = true;
|
||||
@ -319,14 +384,18 @@ public class IntegratedServer {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
return;
|
||||
continue;
|
||||
}else if(msg.channel.startsWith("NET|")) {
|
||||
String u = msg.channel.substring(4);
|
||||
currentProcess.getNetworkThread().recievePacket(u, msg.data);
|
||||
continue;
|
||||
}
|
||||
|
||||
System.err.println("Unknown IPC channel: " + msg.channel);
|
||||
}
|
||||
if(overflow > 0) {
|
||||
System.err.println("Async ICP queue is overloaded, server dropped " + overflow + " player packets");
|
||||
}
|
||||
}
|
||||
|
||||
@JSBody(params = { "ch", "dat" }, script = "postMessage({ ch: ch, dat : dat });")
|
||||
@ -350,6 +419,7 @@ public class IntegratedServer {
|
||||
}
|
||||
|
||||
public static void sendPlayerPacket(String channel, byte[] buf) {
|
||||
//System.out.println("[Server][SEND][" + channel + "]: " + buf.length);
|
||||
ArrayBuffer arb = ArrayBuffer.create(buf.length);
|
||||
Uint8Array ar = Uint8Array.create(arb);
|
||||
ar.set(buf);
|
||||
@ -389,7 +459,7 @@ public class IntegratedServer {
|
||||
|
||||
isRunning = true;
|
||||
|
||||
sendIPCPacket(new IPCPacketFFProcessKeepAlive());
|
||||
sendIPCPacket(new IPCPacketFFProcessKeepAlive(0xFF));
|
||||
|
||||
while(isRunning) {
|
||||
|
||||
|
@ -0,0 +1,412 @@
|
||||
package net.lax1dude.eaglercraft.sp;
|
||||
|
||||
public class NoCatchParse {
|
||||
|
||||
public static final int INT_EXCEPTION = Integer.MIN_VALUE;
|
||||
public static final float FLOAT_EXCEPTION = Float.NaN;
|
||||
public static final double DOUBLE_EXCEPTION = Double.NaN;
|
||||
|
||||
public static int parseInt(String s) {
|
||||
return parseInt(s, 10, false, INT_EXCEPTION);
|
||||
}
|
||||
|
||||
public static int parseInt(String s, int radix) {
|
||||
return parseInt(s, radix, false, INT_EXCEPTION);
|
||||
}
|
||||
|
||||
public static int parseInt(String s, int radix, boolean log) {
|
||||
return parseInt(s, radix, log, INT_EXCEPTION);
|
||||
}
|
||||
|
||||
public static int parseInt(String s, int radix, boolean log, int exceptionResult) {
|
||||
if (s == null) {
|
||||
if (log) {
|
||||
System.err.println("parseInt: string was null");
|
||||
}
|
||||
return exceptionResult;
|
||||
}
|
||||
|
||||
if (s.isEmpty()) {
|
||||
if (log) {
|
||||
System.err.println("parseInt: string was empty");
|
||||
}
|
||||
return exceptionResult;
|
||||
}
|
||||
|
||||
if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) {
|
||||
if (log) {
|
||||
System.err.println("parseInt: invalid radix '" + radix + "'");
|
||||
}
|
||||
return exceptionResult;
|
||||
}
|
||||
|
||||
tryFail: {
|
||||
int result = 0;
|
||||
boolean negative = false;
|
||||
int i = 0, len = s.length();
|
||||
int limit = -Integer.MAX_VALUE;
|
||||
int multmin;
|
||||
int digit;
|
||||
|
||||
if (len > 0) {
|
||||
char firstChar = s.charAt(0);
|
||||
if (firstChar < '0') { // Possible leading "+" or "-"
|
||||
if (firstChar == '-') {
|
||||
negative = true;
|
||||
limit = Integer.MIN_VALUE;
|
||||
} else if (firstChar != '+')
|
||||
break tryFail;
|
||||
|
||||
if (len == 1)
|
||||
break tryFail;
|
||||
i++;
|
||||
}
|
||||
multmin = limit / radix;
|
||||
while (i < len) {
|
||||
// Accumulating negatively avoids surprises near MAX_VALUE
|
||||
digit = Character.digit(s.charAt(i++), radix);
|
||||
if (digit < 0 || result < multmin) {
|
||||
|
||||
break tryFail;
|
||||
}
|
||||
result *= radix;
|
||||
if (result < limit + digit) {
|
||||
break tryFail;
|
||||
}
|
||||
result -= digit;
|
||||
}
|
||||
} else {
|
||||
break tryFail;
|
||||
}
|
||||
int ret = negative ? result : -result;
|
||||
if (ret == exceptionResult) {
|
||||
System.err.println(
|
||||
"parseInt: number '" + s + "' was parsed successfully but it is equal to exceptionResult");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
if (log) {
|
||||
System.err.println("parseInt: cannot parse '" + s + "'");
|
||||
}
|
||||
return exceptionResult;
|
||||
}
|
||||
|
||||
public static double parseDouble(String s) {
|
||||
return parseDouble(s, false, DOUBLE_EXCEPTION);
|
||||
}
|
||||
|
||||
public static double parseDouble(String s, boolean log) {
|
||||
return parseDouble(s, log, DOUBLE_EXCEPTION);
|
||||
}
|
||||
|
||||
public static double parseDouble(String s, boolean log, double exceptionResult) {
|
||||
if (s == null) {
|
||||
if (log) {
|
||||
System.err.println("parseDouble: string was null");
|
||||
}
|
||||
return exceptionResult;
|
||||
}
|
||||
|
||||
if (s.isEmpty()) {
|
||||
if (log) {
|
||||
System.err.println("parseDouble: string was empty");
|
||||
}
|
||||
return exceptionResult;
|
||||
}
|
||||
|
||||
tryFail: {
|
||||
int start = 0;
|
||||
int end = s.length();
|
||||
while (s.charAt(start) <= ' ') {
|
||||
if (++start == end) {
|
||||
break tryFail;
|
||||
}
|
||||
}
|
||||
while (s.charAt(end - 1) <= ' ') {
|
||||
--end;
|
||||
}
|
||||
|
||||
boolean negative = false;
|
||||
int index = start;
|
||||
if (s.charAt(index) == '-') {
|
||||
++index;
|
||||
negative = true;
|
||||
} else if (s.charAt(index) == '+') {
|
||||
++index;
|
||||
}
|
||||
if (index == end) {
|
||||
break tryFail;
|
||||
}
|
||||
char c = s.charAt(index);
|
||||
|
||||
long mantissa = 0;
|
||||
int exp = 0;
|
||||
boolean hasOneDigit = false;
|
||||
if (c != '.') {
|
||||
hasOneDigit = true;
|
||||
if (c < '0' || c > '9') {
|
||||
break tryFail;
|
||||
}
|
||||
while (index < end && s.charAt(index) == '0') {
|
||||
++index;
|
||||
}
|
||||
while (index < end) {
|
||||
c = s.charAt(index);
|
||||
if (c < '0' || c > '9') {
|
||||
break;
|
||||
}
|
||||
if (mantissa < Long.MAX_VALUE / 10 - 9) {
|
||||
mantissa = mantissa * 10 + (c - '0');
|
||||
} else {
|
||||
++exp;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
}
|
||||
if (index < end && s.charAt(index) == '.') {
|
||||
++index;
|
||||
while (index < end) {
|
||||
c = s.charAt(index);
|
||||
if (c < '0' || c > '9') {
|
||||
break;
|
||||
}
|
||||
if (mantissa < Long.MAX_VALUE / 10 - 9) {
|
||||
mantissa = mantissa * 10 + (c - '0');
|
||||
--exp;
|
||||
}
|
||||
++index;
|
||||
hasOneDigit = true;
|
||||
}
|
||||
if (!hasOneDigit) {
|
||||
break tryFail;
|
||||
}
|
||||
}
|
||||
if (index < end) {
|
||||
c = s.charAt(index);
|
||||
if (c != 'e' && c != 'E') {
|
||||
break tryFail;
|
||||
}
|
||||
++index;
|
||||
boolean negativeExp = false;
|
||||
if (index == end) {
|
||||
break tryFail;
|
||||
}
|
||||
if (s.charAt(index) == '-') {
|
||||
++index;
|
||||
negativeExp = true;
|
||||
} else if (s.charAt(index) == '+') {
|
||||
++index;
|
||||
}
|
||||
int numExp = 0;
|
||||
hasOneDigit = false;
|
||||
while (index < end) {
|
||||
c = s.charAt(index);
|
||||
if (c < '0' || c > '9') {
|
||||
break;
|
||||
}
|
||||
numExp = 10 * numExp + (c - '0');
|
||||
hasOneDigit = true;
|
||||
++index;
|
||||
}
|
||||
if (!hasOneDigit) {
|
||||
break tryFail;
|
||||
}
|
||||
if (negativeExp) {
|
||||
numExp = -numExp;
|
||||
}
|
||||
exp += numExp;
|
||||
}
|
||||
if (exp > 308 || exp == 308 && mantissa > 17976931348623157L) {
|
||||
return !negative ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY;
|
||||
}
|
||||
if (negative) {
|
||||
mantissa = -mantissa;
|
||||
}
|
||||
return mantissa * doubleDecimalExponent(exp);
|
||||
}
|
||||
if (log) {
|
||||
System.err.println("parseDouble: cannot parse '" + s + "'");
|
||||
}
|
||||
return exceptionResult;
|
||||
}
|
||||
|
||||
public static double doubleDecimalExponent(int n) {
|
||||
double d;
|
||||
if (n < 0) {
|
||||
d = 0.1;
|
||||
n = -n;
|
||||
} else {
|
||||
d = 10;
|
||||
}
|
||||
double result = 1;
|
||||
while (n != 0) {
|
||||
if (n % 2 != 0) {
|
||||
result *= d;
|
||||
}
|
||||
d *= d;
|
||||
n /= 2;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float parseFloat(String s) {
|
||||
return parseFloat(s, false, FLOAT_EXCEPTION);
|
||||
}
|
||||
|
||||
public static float parseFloat(String s, boolean log) {
|
||||
return parseFloat(s, log, FLOAT_EXCEPTION);
|
||||
}
|
||||
|
||||
public static float parseFloat(String s, boolean log, float exceptionResult) {
|
||||
if (s == null) {
|
||||
if (log) {
|
||||
System.err.println("parseFloat: string was null");
|
||||
}
|
||||
return exceptionResult;
|
||||
}
|
||||
|
||||
if (s.isEmpty()) {
|
||||
if (log) {
|
||||
System.err.println("parseFloat: string was empty");
|
||||
}
|
||||
return exceptionResult;
|
||||
}
|
||||
|
||||
tryFail: {
|
||||
int start = 0;
|
||||
int end = s.length();
|
||||
while (s.charAt(start) <= ' ') {
|
||||
if (++start == end) {
|
||||
break tryFail;
|
||||
}
|
||||
}
|
||||
while (s.charAt(end - 1) <= ' ') {
|
||||
--end;
|
||||
}
|
||||
|
||||
boolean negative = false;
|
||||
int index = start;
|
||||
if (s.charAt(index) == '-') {
|
||||
++index;
|
||||
negative = true;
|
||||
} else if (s.charAt(index) == '+') {
|
||||
++index;
|
||||
}
|
||||
if (index == end) {
|
||||
break tryFail;
|
||||
}
|
||||
char c = s.charAt(index);
|
||||
|
||||
int mantissa = 0;
|
||||
int exp = 0;
|
||||
|
||||
boolean hasOneDigit = false;
|
||||
if (c != '.') {
|
||||
hasOneDigit = true;
|
||||
if (c < '0' || c > '9') {
|
||||
break tryFail;
|
||||
}
|
||||
|
||||
while (index < end && s.charAt(index) == '0') {
|
||||
++index;
|
||||
}
|
||||
while (index < end) {
|
||||
c = s.charAt(index);
|
||||
if (c < '0' || c > '9') {
|
||||
break;
|
||||
}
|
||||
if (mantissa < (Integer.MAX_VALUE / 10) - 9) {
|
||||
mantissa = mantissa * 10 + (c - '0');
|
||||
} else {
|
||||
++exp;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
||||
if (index < end && s.charAt(index) == '.') {
|
||||
++index;
|
||||
while (index < end) {
|
||||
c = s.charAt(index);
|
||||
if (c < '0' || c > '9') {
|
||||
break;
|
||||
}
|
||||
if (mantissa < (Integer.MAX_VALUE / 10) - 9) {
|
||||
mantissa = mantissa * 10 + (c - '0');
|
||||
--exp;
|
||||
}
|
||||
++index;
|
||||
hasOneDigit = true;
|
||||
}
|
||||
if (!hasOneDigit) {
|
||||
break tryFail;
|
||||
}
|
||||
}
|
||||
if (index < end) {
|
||||
c = s.charAt(index);
|
||||
if (c != 'e' && c != 'E') {
|
||||
break tryFail;
|
||||
}
|
||||
++index;
|
||||
boolean negativeExp = false;
|
||||
if (index == end) {
|
||||
break tryFail;
|
||||
}
|
||||
if (s.charAt(index) == '-') {
|
||||
++index;
|
||||
negativeExp = true;
|
||||
} else if (s.charAt(index) == '+') {
|
||||
++index;
|
||||
}
|
||||
int numExp = 0;
|
||||
hasOneDigit = false;
|
||||
while (index < end) {
|
||||
c = s.charAt(index);
|
||||
if (c < '0' || c > '9') {
|
||||
break;
|
||||
}
|
||||
numExp = 10 * numExp + (c - '0');
|
||||
hasOneDigit = true;
|
||||
++index;
|
||||
}
|
||||
if (!hasOneDigit) {
|
||||
break tryFail;
|
||||
}
|
||||
if (negativeExp) {
|
||||
numExp = -numExp;
|
||||
}
|
||||
exp += numExp;
|
||||
}
|
||||
if (exp > 38 || exp == 38 && mantissa > 34028234) {
|
||||
return !negative ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY;
|
||||
}
|
||||
if (negative) {
|
||||
mantissa = -mantissa;
|
||||
}
|
||||
return mantissa * floatDecimalExponent(exp);
|
||||
}
|
||||
if (log) {
|
||||
System.err.println("parseFloat: cannot parse '" + s + "'");
|
||||
}
|
||||
return exceptionResult;
|
||||
}
|
||||
|
||||
private static float floatDecimalExponent(int n) {
|
||||
double d;
|
||||
if (n < 0) {
|
||||
d = 0.1;
|
||||
n = -n;
|
||||
} else {
|
||||
d = 10;
|
||||
}
|
||||
double result = 1;
|
||||
while (n != 0) {
|
||||
if (n % 2 != 0) {
|
||||
result *= d;
|
||||
}
|
||||
d *= d;
|
||||
n /= 2;
|
||||
}
|
||||
return (float) result;
|
||||
}
|
||||
}
|
@ -43,7 +43,7 @@ public class VFSChunkLoader implements IChunkLoader {
|
||||
|
||||
@Override
|
||||
public Chunk loadChunk(World var1, int var2, int var3) throws IOException {
|
||||
VFile file = new VFile(chunkDirectory, getChunkPath(var2, var3), ".dat");
|
||||
VFile file = new VFile(chunkDirectory, getChunkPath(var2, var3) + ".dat");
|
||||
byte[] bytes = file.getAllBytes();
|
||||
|
||||
if(bytes == null) {
|
||||
@ -72,7 +72,7 @@ public class VFSChunkLoader implements IChunkLoader {
|
||||
|
||||
try {
|
||||
NBTTagCompound chunkFileSave = new NBTTagCompound();
|
||||
chunkFileSave.setCompoundTag("Level", chunkFileSave);
|
||||
chunkFileSave.setCompoundTag("Level", chunkFile);
|
||||
save = CompressedStreamTools.compress(chunkFileSave);
|
||||
}catch(IOException e) {
|
||||
System.err.println("Corrupted chunk could not be serialized: [" + var2.xPosition + ", " + var2.zPosition + "]");
|
||||
|
@ -34,7 +34,7 @@ public class VFSSaveHandler implements ISaveHandler, IPlayerFileData {
|
||||
|
||||
try {
|
||||
NBTTagCompound level_dat = CompressedStreamTools.decompress(level_dat_bin);
|
||||
return new WorldInfo(level_dat);
|
||||
return new WorldInfo(level_dat.getCompoundTag("Data"));
|
||||
}catch(Throwable t) {
|
||||
System.err.println("Could not parse level.dat!");
|
||||
t.printStackTrace();
|
||||
|
@ -557,8 +557,9 @@ public class VirtualFilesystem {
|
||||
@Override
|
||||
public void handleEvent() {
|
||||
IDBCursor c = r.getResult();
|
||||
if(c == null) {
|
||||
if(c == null || c.getKey() == null) {
|
||||
cb.complete(res[0]);
|
||||
return;
|
||||
}
|
||||
String k = readKey(c.getKey());
|
||||
if(k != null) {
|
||||
@ -593,8 +594,9 @@ public class VirtualFilesystem {
|
||||
@Override
|
||||
public void handleEvent() {
|
||||
IDBCursor c = r.getResult();
|
||||
if(c == null) {
|
||||
if(c == null || c.getKey() == null) {
|
||||
cb.complete(res[0]);
|
||||
return;
|
||||
}
|
||||
String k = readKey(c.getKey());
|
||||
if(k != null) {
|
||||
|
@ -2,14 +2,16 @@ package net.lax1dude.eaglercraft.sp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.src.NetServerHandler;
|
||||
import net.minecraft.src.NetHandler;
|
||||
|
||||
public class WorkerListenThread {
|
||||
/** Reference to the MinecraftServer object. */
|
||||
private final MinecraftServer mcServer;
|
||||
private final List connections = new ArrayList();
|
||||
private final HashSet connections = new HashSet();
|
||||
private final HashMap<String, WorkerNetworkManager> channels = new HashMap();
|
||||
|
||||
/** Whether the network listener object is listening. */
|
||||
@ -23,7 +25,8 @@ public class WorkerListenThread {
|
||||
/**
|
||||
* adds this connection to the list of currently connected players
|
||||
*/
|
||||
public void addPlayer(NetServerHandler par1NetServerHandler) {
|
||||
public void addPlayer(NetHandler par1NetServerHandler) {
|
||||
System.out.println("[Server][ADDPLAYER][" + par1NetServerHandler.getClass().getSimpleName() + "]");
|
||||
this.connections.add(par1NetServerHandler);
|
||||
}
|
||||
|
||||
@ -32,6 +35,7 @@ public class WorkerListenThread {
|
||||
}
|
||||
|
||||
public boolean openChannel(String player) {
|
||||
System.out.println("[Server][OPENCHANNEL][" + player + "]");
|
||||
return channels.put(player, new WorkerNetworkManager(player, mcServer, this)) == null;
|
||||
}
|
||||
|
||||
@ -44,26 +48,39 @@ public class WorkerListenThread {
|
||||
}
|
||||
|
||||
public boolean closeChannel(String player) {
|
||||
System.out.println("[Server][CLOSECHANNEL][" + player + "]");
|
||||
WorkerNetworkManager channel = channels.get(player);
|
||||
if(channel == null) {
|
||||
return false;
|
||||
}
|
||||
channel.networkShutdown(null, null, null);
|
||||
channels.remove(player);
|
||||
channel.networkShutdown(null, null, null);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void deleteDeadConnections() {
|
||||
Iterator<NetHandler> itr = this.connections.iterator();
|
||||
while(itr.hasNext()) {
|
||||
if(((NetHandler)itr.next()).shouldBeRemoved()) {
|
||||
itr.remove();
|
||||
//System.out.println("[Client][REMOVEDEAD]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles all incoming connections and packets
|
||||
*/
|
||||
public void handleNetworkListenThread() {
|
||||
for(WorkerNetworkManager mgr : channels.values()) {
|
||||
mgr.processReadPackets();
|
||||
}
|
||||
for (int var1 = 0; var1 < this.connections.size(); ++var1) {
|
||||
NetServerHandler var2 = (NetServerHandler) this.connections.get(var1);
|
||||
|
||||
deleteDeadConnections();
|
||||
|
||||
for (NetHandler var2 : (HashSet<NetHandler>)this.connections) {
|
||||
var2.handlePackets();
|
||||
}
|
||||
|
||||
deleteDeadConnections();
|
||||
|
||||
}
|
||||
|
||||
public MinecraftServer getServer() {
|
||||
|
@ -1,12 +1,12 @@
|
||||
package net.lax1dude.eaglercraft.sp;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.lax1dude.eaglercraft.sp.ipc.IPCInputStream;
|
||||
import net.lax1dude.eaglercraft.sp.ipc.IPCOutputStream;
|
||||
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket0CPlayerChannel;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.src.INetworkManager;
|
||||
@ -15,14 +15,9 @@ import net.minecraft.src.NetLoginHandler;
|
||||
import net.minecraft.src.Packet;
|
||||
|
||||
public class WorkerNetworkManager implements INetworkManager {
|
||||
|
||||
public static final IPCInputStream NET_INPUT_STREAM = new IPCInputStream();
|
||||
public static final IPCOutputStream NET_OUTPUT_STREAM = new IPCOutputStream();
|
||||
|
||||
public static final DataInputStream NET_DATA_INPUT_STREAM = new DataInputStream(NET_INPUT_STREAM);
|
||||
public static final DataOutputStream NET_DATA_OUTPUT_STREAM = new DataOutputStream(NET_OUTPUT_STREAM);
|
||||
|
||||
private NetHandler theNetHandler;
|
||||
private MinecraftServer minecraftServer;
|
||||
private String ipcChannel;
|
||||
private boolean isAlive;
|
||||
private WorkerListenThread listenThread;
|
||||
@ -32,6 +27,8 @@ public class WorkerNetworkManager implements INetworkManager {
|
||||
public WorkerNetworkManager(String ipcChannel, MinecraftServer srv, WorkerListenThread th) {
|
||||
this.ipcChannel = ipcChannel;
|
||||
this.theNetHandler = new NetLoginHandler(srv, this);
|
||||
th.addPlayer(theNetHandler);
|
||||
this.minecraftServer = srv;
|
||||
this.isAlive = true;
|
||||
this.listenThread = th;
|
||||
}
|
||||
@ -39,6 +36,7 @@ public class WorkerNetworkManager implements INetworkManager {
|
||||
@Override
|
||||
public void setNetHandler(NetHandler var1) {
|
||||
theNetHandler = var1;
|
||||
listenThread.addPlayer(theNetHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -46,17 +44,19 @@ public class WorkerNetworkManager implements INetworkManager {
|
||||
if(!isAlive) {
|
||||
return;
|
||||
}
|
||||
NET_OUTPUT_STREAM.feedBuffer(new byte[var1.getPacketSize() + 1], "[MC]" + var1.getClass().getSimpleName());
|
||||
try {
|
||||
Packet.writePacket(var1, NET_DATA_OUTPUT_STREAM);
|
||||
ByteArrayOutputStream bao = new ByteArrayOutputStream(var1.getPacketSize() + 1);
|
||||
Packet.writePacket(var1, new DataOutputStream(bao));
|
||||
IntegratedServer.sendPlayerPacket(ipcChannel, bao.toByteArray());
|
||||
}catch(IOException e) {
|
||||
System.err.println("Failed to serialize minecraft packet '" + var1.getPacketId() + "' for IPC channel 'NET|" + ipcChannel + "'");
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
IntegratedServer.sendPlayerPacket(ipcChannel, NET_OUTPUT_STREAM.returnBuffer());
|
||||
}
|
||||
|
||||
public void addToRecieveQueue(byte[] fragment) {
|
||||
//System.out.println("[Server][READ][QUEUE][" + ipcChannel + "]: " + fragment.length);
|
||||
if(!isAlive) {
|
||||
return;
|
||||
}
|
||||
@ -70,70 +70,37 @@ public class WorkerNetworkManager implements INetworkManager {
|
||||
|
||||
@Override
|
||||
public void processReadPackets() {
|
||||
if(!isAlive) {
|
||||
return;
|
||||
}
|
||||
if(frags.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int blockSize = 0;
|
||||
for(byte[] pkt : frags) {
|
||||
blockSize += pkt.length;
|
||||
}
|
||||
|
||||
int idx = 0;
|
||||
byte[] block = new byte[blockSize];
|
||||
for(byte[] pkt : frags) {
|
||||
System.arraycopy(pkt, 0, block, idx, pkt.length);
|
||||
idx += pkt.length;
|
||||
}
|
||||
|
||||
LinkedList<Packet> readPackets = new LinkedList();
|
||||
|
||||
NET_INPUT_STREAM.feedBuffer(block);
|
||||
|
||||
while(true) {
|
||||
while(frags.size() > 0) {
|
||||
byte[] pktBytes = frags.remove(0);
|
||||
try {
|
||||
int pktId = NET_INPUT_STREAM.read();
|
||||
ByteArrayInputStream bai = new ByteArrayInputStream(pktBytes);
|
||||
int pktId = bai.read();
|
||||
|
||||
if(pktId == -1) {
|
||||
System.err.println("Recieved invalid '-1' packet");
|
||||
NET_INPUT_STREAM.markIndex();
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
|
||||
Packet pkt = Packet.getNewPacket(IntegratedServer.logger, idx);
|
||||
Packet pkt = Packet.getNewPacket(minecraftServer.getLogAgent(), pktId);
|
||||
|
||||
if(pkt == null) {
|
||||
NET_INPUT_STREAM.markIndex();
|
||||
break;
|
||||
System.err.println("Recieved invalid '" + pktId + "' packet");
|
||||
continue;
|
||||
}
|
||||
|
||||
pkt.field_98193_m = IntegratedServer.logger;
|
||||
pkt.readPacketData(NET_DATA_INPUT_STREAM);
|
||||
pkt.readPacketData(new DataInputStream(bai));
|
||||
|
||||
readPackets.add(pkt);
|
||||
//System.out.println("[Server][" + ipcChannel + "]: packet '" + pkt.getClass().getSimpleName() + "' recieved");
|
||||
|
||||
NET_INPUT_STREAM.markIndex();
|
||||
try {
|
||||
pkt.processPacket(theNetHandler);
|
||||
}catch(Throwable t) {
|
||||
System.err.println("Could not process minecraft packet 0x" + Integer.toHexString(pkt.getPacketId()) + " class '" + pkt.getClass().getSimpleName() + "' on channel 'NET|" + ipcChannel + "'");
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
}catch(IOException ex) {
|
||||
// end
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
NET_INPUT_STREAM.rewindIndex();
|
||||
|
||||
frags.clear();
|
||||
frags.add(NET_INPUT_STREAM.getLeftover());
|
||||
|
||||
for(Packet p : readPackets) {
|
||||
try {
|
||||
p.processPacket(theNetHandler);
|
||||
}catch(Throwable t) {
|
||||
System.err.println("Could not process minecraft packet 0x" + Integer.toHexString(p.getPacketId()) + " class '" + p.getClass().getSimpleName() + "' on channel 'NET|" + ipcChannel + "'");
|
||||
t.printStackTrace();
|
||||
System.err.println("Could not deserialize a " + pktBytes.length + " byte long minecraft packet of type '" + (pktBytes.length <= 0 ? -1 : (int)(pktBytes[0] & 0xFF)) + "' on channel 'NET|" + ipcChannel + "'");
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,7 +116,7 @@ public class WorkerNetworkManager implements INetworkManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumChunkDataPackets() { // why is this a thing, it limits map (the item) updates
|
||||
public int getNumChunkDataPackets() { // why is this a thing
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -161,5 +128,13 @@ public class WorkerNetworkManager implements INetworkManager {
|
||||
}
|
||||
isAlive = false;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return (o instanceof WorkerNetworkManager) && ((WorkerNetworkManager)o).ipcChannel.equals(ipcChannel);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return ipcChannel.hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -47,12 +47,6 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
|
||||
protected final ICommandManager commandManager;
|
||||
public final Profiler theProfiler = new Profiler();
|
||||
|
||||
/** The server's hostname. */
|
||||
protected String hostname;
|
||||
|
||||
/** The server's port. */
|
||||
protected int serverPort = -1;
|
||||
|
||||
/** The server world instances. */
|
||||
public WorldServer[] worldServers;
|
||||
|
||||
@ -80,9 +74,6 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
|
||||
/** The percentage of the current task finished so far. */
|
||||
protected int percentDone;
|
||||
|
||||
/** True if the server is in online mode. */
|
||||
protected boolean onlineMode;
|
||||
|
||||
/** True if the server has animals turned on. */
|
||||
protected boolean canSpawnAnimals;
|
||||
protected boolean canSpawnNPCs;
|
||||
@ -114,8 +105,6 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
|
||||
/** Username of the server owner (for integrated servers) */
|
||||
protected String serverOwner;
|
||||
protected String folderName;
|
||||
protected boolean isDemo;
|
||||
protected boolean enableBonusChest;
|
||||
|
||||
/**
|
||||
* If true, there is no need to save chunks or stop the server, because that is
|
||||
@ -164,28 +153,23 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
|
||||
this.userMessage = par1Str;
|
||||
}
|
||||
|
||||
protected void loadAllWorlds(String par1Str, String par2Str, long par3, WorldSettings par5WorldType) {
|
||||
this.convertMapIfNeeded(par1Str);
|
||||
protected void loadAllWorlds(String par1Str, long par3, WorldSettings par5WorldType) {
|
||||
this.setUserMessage("menu.loadingLevel");
|
||||
this.worldServers = new WorldServer[3];
|
||||
this.timeOfLastDimensionTick = new long[this.worldServers.length][100];
|
||||
ISaveHandler var7 = new VFSSaveHandler(new VFile(par1Str));
|
||||
ISaveHandler var7 = new VFSSaveHandler(new VFile("worlds", par1Str));
|
||||
WorldInfo var9 = var7.loadWorldInfo();
|
||||
WorldSettings var8;
|
||||
|
||||
if (var9 == null) {
|
||||
if(par5WorldType == null) {
|
||||
throw new IllegalArgumentException("World '" + par1Str + "/" + par2Str + "' does not exist and WorldSettings is null");
|
||||
throw new IllegalArgumentException("World '" + par1Str + "' does not exist and WorldSettings is null");
|
||||
}
|
||||
var8 = par5WorldType;
|
||||
} else {
|
||||
var8 = new WorldSettings(var9);
|
||||
}
|
||||
|
||||
if (this.enableBonusChest) {
|
||||
var8.enableBonusChest();
|
||||
}
|
||||
|
||||
for (int var10 = 0; var10 < this.worldServers.length; ++var10) {
|
||||
byte var11 = 0;
|
||||
|
||||
@ -198,17 +182,14 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
|
||||
}
|
||||
|
||||
if (var10 == 0) {
|
||||
this.worldServers[var10] = new WorldServer(this, var7, par2Str, var11, var8, this.theProfiler, this.getLogAgent());
|
||||
this.worldServers[var10] = new WorldServer(this, var7, par1Str, var11, var8, this.theProfiler, this.getLogAgent());
|
||||
} else {
|
||||
this.worldServers[var10] = new WorldServerMulti(this, var7, par2Str, var11, var8, this.worldServers[0],
|
||||
this.worldServers[var10] = new WorldServerMulti(this, var7, par1Str, var11, var8, this.worldServers[0],
|
||||
this.theProfiler, this.getLogAgent());
|
||||
}
|
||||
|
||||
this.worldServers[var10].addWorldAccess(new WorldManager(this, this.worldServers[var10]));
|
||||
|
||||
if (!this.isSinglePlayer()) {
|
||||
this.worldServers[var10].getWorldInfo().setGameType(this.getGameType());
|
||||
}
|
||||
this.worldServers[var10].getWorldInfo().setGameType(this.getGameType());
|
||||
|
||||
this.serverConfigManager.setPlayerManager(this.worldServers);
|
||||
}
|
||||
@ -225,9 +206,11 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
|
||||
WorldServer var7 = this.worldServers[var6];
|
||||
ChunkCoordinates var8 = var7.getSpawnPoint();
|
||||
long var9 = System.currentTimeMillis();
|
||||
|
||||
int prepareRadius = 48;
|
||||
|
||||
for (int var11 = -192; var11 <= 192 && this.isServerRunning(); var11 += 16) {
|
||||
for (int var12 = -192; var12 <= 192 && this.isServerRunning(); var12 += 16) {
|
||||
for (int var11 = -prepareRadius; var11 <= prepareRadius && this.isServerRunning(); var11 += 16) {
|
||||
for (int var12 = -prepareRadius; var12 <= prepareRadius && this.isServerRunning(); var12 += 16) {
|
||||
long var13 = System.currentTimeMillis();
|
||||
|
||||
if (var13 - var9 > 1000L) {
|
||||
@ -278,7 +261,7 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
|
||||
/**
|
||||
* par1 indicates if a log message should be output.
|
||||
*/
|
||||
protected void saveAllWorlds(boolean par1) {
|
||||
public void saveAllWorlds(boolean par1) {
|
||||
if (!this.worldIsBeingDeleted) {
|
||||
WorldServer[] var2 = this.worldServers;
|
||||
int var3 = var2.length;
|
||||
@ -333,11 +316,11 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
|
||||
* "getHostname" is already taken, but both return the hostname.
|
||||
*/
|
||||
public String getServerHostname() {
|
||||
return this.hostname;
|
||||
return "127.1.1.1";
|
||||
}
|
||||
|
||||
public void setHostname(String par1Str) {
|
||||
this.hostname = par1Str;
|
||||
throw new IllegalArgumentException("variable removed");
|
||||
}
|
||||
|
||||
public boolean isServerRunning() {
|
||||
@ -545,14 +528,14 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
|
||||
* Returns the server's hostname.
|
||||
*/
|
||||
public String getHostname() {
|
||||
return this.hostname;
|
||||
return this.getServerHostname();
|
||||
}
|
||||
|
||||
/**
|
||||
* Never used, but "getServerPort" is already taken.
|
||||
*/
|
||||
public int getPort() {
|
||||
return this.serverPort;
|
||||
return this.getServerPort();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -609,7 +592,7 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
|
||||
* Returns true if debugging is enabled, false otherwise.
|
||||
*/
|
||||
public boolean isDebuggingEnabled() {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -629,7 +612,7 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
|
||||
}
|
||||
|
||||
public String getServerModName() {
|
||||
return "vanilla";
|
||||
return "eaglercraft";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -688,7 +671,7 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
|
||||
* Gets the name of this command sender (usually username, but possibly "Rcon")
|
||||
*/
|
||||
public String getCommandSenderName() {
|
||||
return "Server";
|
||||
return "Host";
|
||||
}
|
||||
|
||||
public void sendChatToPlayer(String par1Str) {
|
||||
@ -699,7 +682,7 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
|
||||
* Returns true if the command sender is allowed to use the given command.
|
||||
*/
|
||||
public boolean canCommandSenderUseCommand(int par1, String par2Str) {
|
||||
return true;
|
||||
return par2Str.equals(this.getServerOwner());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -717,11 +700,11 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
|
||||
* Gets serverPort.
|
||||
*/
|
||||
public int getServerPort() {
|
||||
return this.serverPort;
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void setServerPort(int par1) {
|
||||
this.serverPort = par1;
|
||||
throw new IllegalArgumentException("variable removed");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -778,18 +761,18 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
|
||||
* Gets whether this is a demo or not.
|
||||
*/
|
||||
public boolean isDemo() {
|
||||
return this.isDemo;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this is a demo or not.
|
||||
*/
|
||||
public void setDemo(boolean par1) {
|
||||
this.isDemo = par1;
|
||||
throw new IllegalArgumentException("variable removed");
|
||||
}
|
||||
|
||||
public void canCreateBonusChest(boolean par1) {
|
||||
this.enableBonusChest = par1;
|
||||
throw new IllegalArgumentException("variable removed");
|
||||
}
|
||||
|
||||
public ISaveFormat getActiveAnvilConverter() {
|
||||
@ -818,11 +801,11 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
|
||||
}
|
||||
|
||||
public String getTexturePack() {
|
||||
return this.texturePack;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setTexturePack(String par1Str) {
|
||||
this.texturePack = par1Str;
|
||||
throw new IllegalArgumentException("variable removed");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -836,11 +819,11 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
|
||||
public abstract boolean isDedicatedServer();
|
||||
|
||||
public boolean isServerInOnlineMode() {
|
||||
return this.onlineMode;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setOnlineMode(boolean par1) {
|
||||
this.onlineMode = par1;
|
||||
throw new IllegalArgumentException("variable removed");
|
||||
}
|
||||
|
||||
public boolean getCanSpawnAnimals() {
|
||||
@ -889,11 +872,11 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
|
||||
}
|
||||
|
||||
public int getBuildLimit() {
|
||||
return this.buildLimit;
|
||||
return 256;
|
||||
}
|
||||
|
||||
public void setBuildLimit(int par1) {
|
||||
this.buildLimit = par1;
|
||||
throw new IllegalArgumentException("variable removed");
|
||||
}
|
||||
|
||||
public boolean isServerStopped() {
|
||||
@ -948,7 +931,7 @@ public abstract class MinecraftServer implements ICommandSender, Runnable {
|
||||
* Return the spawn protection area's size.
|
||||
*/
|
||||
public int getSpawnProtectionSize() {
|
||||
return 16;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean func_96290_a(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer) {
|
||||
|
@ -10,6 +10,8 @@ import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Collection;
|
||||
|
||||
import com.jcraft.jzlib.GZIPInputStream;
|
||||
import com.jcraft.jzlib.GZIPOutputStream;
|
||||
|
||||
|
@ -3,16 +3,19 @@ package net.minecraft.src;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class EntityList {
|
||||
/** Provides a mapping between entity classes and a string */
|
||||
private static Map stringToClassMapping = new HashMap();
|
||||
private static Map stringToClassReflectMapping = new HashMap();
|
||||
|
||||
/** Provides a mapping between a string and an entity classes */
|
||||
private static Map classToStringMapping = new HashMap();
|
||||
|
||||
/** provides a mapping between an entityID and an Entity Class */
|
||||
private static Map IDtoClassMapping = new HashMap();
|
||||
private static Map IDtoClassReflectMapping = new HashMap();
|
||||
|
||||
/** provides a mapping between an Entity Class and an entity ID */
|
||||
private static Map classToIDMapping = new HashMap();
|
||||
@ -27,10 +30,12 @@ public class EntityList {
|
||||
* adds a mapping between Entity classes and both a string representation and an
|
||||
* ID
|
||||
*/
|
||||
private static void addMapping(Class par0Class, String par1Str, int par2) {
|
||||
stringToClassMapping.put(par1Str, par0Class);
|
||||
private static void addMapping(Class par0Class, Function<World, Entity> constructor, String par1Str, int par2) {
|
||||
stringToClassMapping.put(par1Str, constructor);
|
||||
stringToClassReflectMapping.put(par1Str, par0Class);
|
||||
classToStringMapping.put(par0Class, par1Str);
|
||||
IDtoClassMapping.put(Integer.valueOf(par2), par0Class);
|
||||
IDtoClassMapping.put(Integer.valueOf(par2), constructor);
|
||||
IDtoClassReflectMapping.put(Integer.valueOf(par2), par0Class);
|
||||
classToIDMapping.put(par0Class, Integer.valueOf(par2));
|
||||
stringToIDMapping.put(par1Str, Integer.valueOf(par2));
|
||||
}
|
||||
@ -38,8 +43,8 @@ public class EntityList {
|
||||
/**
|
||||
* Adds a entity mapping with egg info.
|
||||
*/
|
||||
private static void addMapping(Class par0Class, String par1Str, int par2, int par3, int par4) {
|
||||
addMapping(par0Class, par1Str, par2);
|
||||
private static void addMapping(Class par0Class, Function<World, Entity> constructor, String par1Str, int par2, int par3, int par4) {
|
||||
addMapping(par0Class, constructor, par1Str, par2);
|
||||
entityEggs.put(Integer.valueOf(par2), new EntityEggInfo(par2, par3, par4));
|
||||
}
|
||||
|
||||
@ -50,11 +55,10 @@ public class EntityList {
|
||||
Entity var2 = null;
|
||||
|
||||
try {
|
||||
Class var3 = (Class) stringToClassMapping.get(par0Str);
|
||||
Function<World, Entity> var3 = (Function<World, Entity>) stringToClassMapping.get(par0Str);
|
||||
|
||||
if (var3 != null) {
|
||||
var2 = (Entity) var3.getConstructor(new Class[] { World.class })
|
||||
.newInstance(new Object[] { par1World });
|
||||
var2 = var3.apply(par1World);
|
||||
}
|
||||
} catch (Exception var4) {
|
||||
var4.printStackTrace();
|
||||
@ -87,11 +91,10 @@ public class EntityList {
|
||||
}
|
||||
|
||||
try {
|
||||
Class var3 = (Class) stringToClassMapping.get(par0NBTTagCompound.getString("id"));
|
||||
Function<World, Entity> var3 = (Function<World, Entity>) stringToClassMapping.get(par0NBTTagCompound.getString("id"));
|
||||
|
||||
if (var3 != null) {
|
||||
var2 = (Entity) var3.getConstructor(new Class[] { World.class })
|
||||
.newInstance(new Object[] { par1World });
|
||||
var2 = var3.apply(par1World);
|
||||
}
|
||||
} catch (Exception var4) {
|
||||
var4.printStackTrace();
|
||||
@ -113,11 +116,10 @@ public class EntityList {
|
||||
Entity var2 = null;
|
||||
|
||||
try {
|
||||
Class var3 = getClassFromID(par0);
|
||||
Function<World, Entity> var3 = (Function<World, Entity>) IDtoClassMapping.get(par0);
|
||||
|
||||
if (var3 != null) {
|
||||
var2 = (Entity) var3.getConstructor(new Class[] { World.class })
|
||||
.newInstance(new Object[] { par1World });
|
||||
var2 = var3.apply(par1World);
|
||||
}
|
||||
} catch (Exception var4) {
|
||||
var4.printStackTrace();
|
||||
@ -142,7 +144,7 @@ public class EntityList {
|
||||
* Return the class assigned to this entity ID.
|
||||
*/
|
||||
public static Class getClassFromID(int par0) {
|
||||
return (Class) IDtoClassMapping.get(Integer.valueOf(par0));
|
||||
return (Class) IDtoClassReflectMapping.get(Integer.valueOf(par0));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -161,59 +163,59 @@ public class EntityList {
|
||||
}
|
||||
|
||||
static {
|
||||
addMapping(EntityItem.class, "Item", 1);
|
||||
addMapping(EntityXPOrb.class, "XPOrb", 2);
|
||||
addMapping(EntityPainting.class, "Painting", 9);
|
||||
addMapping(EntityArrow.class, "Arrow", 10);
|
||||
addMapping(EntitySnowball.class, "Snowball", 11);
|
||||
addMapping(EntityLargeFireball.class, "Fireball", 12);
|
||||
addMapping(EntitySmallFireball.class, "SmallFireball", 13);
|
||||
addMapping(EntityEnderPearl.class, "ThrownEnderpearl", 14);
|
||||
addMapping(EntityEnderEye.class, "EyeOfEnderSignal", 15);
|
||||
addMapping(EntityPotion.class, "ThrownPotion", 16);
|
||||
addMapping(EntityExpBottle.class, "ThrownExpBottle", 17);
|
||||
addMapping(EntityItemFrame.class, "ItemFrame", 18);
|
||||
addMapping(EntityWitherSkull.class, "WitherSkull", 19);
|
||||
addMapping(EntityTNTPrimed.class, "PrimedTnt", 20);
|
||||
addMapping(EntityFallingSand.class, "FallingSand", 21);
|
||||
addMapping(EntityFireworkRocket.class, "FireworksRocketEntity", 22);
|
||||
addMapping(EntityBoat.class, "Boat", 41);
|
||||
addMapping(EntityMinecartEmpty.class, "MinecartRideable", 42);
|
||||
addMapping(EntityMinecartChest.class, "MinecartChest", 43);
|
||||
addMapping(EntityMinecartFurnace.class, "MinecartFurnace", 44);
|
||||
addMapping(EntityMinecartTNT.class, "MinecartTNT", 45);
|
||||
addMapping(EntityMinecartHopper.class, "MinecartHopper", 46);
|
||||
addMapping(EntityMinecartMobSpawner.class, "MinecartSpawner", 47);
|
||||
addMapping(EntityLiving.class, "Mob", 48);
|
||||
addMapping(EntityMob.class, "Monster", 49);
|
||||
addMapping(EntityCreeper.class, "Creeper", 50, 894731, 0);
|
||||
addMapping(EntitySkeleton.class, "Skeleton", 51, 12698049, 4802889);
|
||||
addMapping(EntitySpider.class, "Spider", 52, 3419431, 11013646);
|
||||
addMapping(EntityGiantZombie.class, "Giant", 53);
|
||||
addMapping(EntityZombie.class, "Zombie", 54, 44975, 7969893);
|
||||
addMapping(EntitySlime.class, "Slime", 55, 5349438, 8306542);
|
||||
addMapping(EntityGhast.class, "Ghast", 56, 16382457, 12369084);
|
||||
addMapping(EntityPigZombie.class, "PigZombie", 57, 15373203, 5009705);
|
||||
addMapping(EntityEnderman.class, "Enderman", 58, 1447446, 0);
|
||||
addMapping(EntityCaveSpider.class, "CaveSpider", 59, 803406, 11013646);
|
||||
addMapping(EntitySilverfish.class, "Silverfish", 60, 7237230, 3158064);
|
||||
addMapping(EntityBlaze.class, "Blaze", 61, 16167425, 16775294);
|
||||
addMapping(EntityMagmaCube.class, "LavaSlime", 62, 3407872, 16579584);
|
||||
addMapping(EntityDragon.class, "EnderDragon", 63);
|
||||
addMapping(EntityWither.class, "WitherBoss", 64);
|
||||
addMapping(EntityBat.class, "Bat", 65, 4996656, 986895);
|
||||
addMapping(EntityWitch.class, "Witch", 66, 3407872, 5349438);
|
||||
addMapping(EntityPig.class, "Pig", 90, 15771042, 14377823);
|
||||
addMapping(EntitySheep.class, "Sheep", 91, 15198183, 16758197);
|
||||
addMapping(EntityCow.class, "Cow", 92, 4470310, 10592673);
|
||||
addMapping(EntityChicken.class, "Chicken", 93, 10592673, 16711680);
|
||||
addMapping(EntitySquid.class, "Squid", 94, 2243405, 7375001);
|
||||
addMapping(EntityWolf.class, "Wolf", 95, 14144467, 13545366);
|
||||
addMapping(EntityMooshroom.class, "MushroomCow", 96, 10489616, 12040119);
|
||||
addMapping(EntitySnowman.class, "SnowMan", 97);
|
||||
addMapping(EntityOcelot.class, "Ozelot", 98, 15720061, 5653556);
|
||||
addMapping(EntityIronGolem.class, "VillagerGolem", 99);
|
||||
addMapping(EntityVillager.class, "Villager", 120, 5651507, 12422002);
|
||||
addMapping(EntityEnderCrystal.class, "EnderCrystal", 200);
|
||||
addMapping(EntityItem.class, (w) -> new EntityItem(w), "Item", 1);
|
||||
addMapping(EntityXPOrb.class, (w) -> new EntityXPOrb(w), "XPOrb", 2);
|
||||
addMapping(EntityPainting.class, (w) -> new EntityPainting(w), "Painting", 9);
|
||||
addMapping(EntityArrow.class, (w) -> new EntityArrow(w), "Arrow", 10);
|
||||
addMapping(EntitySnowball.class, (w) -> new EntitySnowball(w), "Snowball", 11);
|
||||
addMapping(EntityLargeFireball.class, (w) -> new EntityLargeFireball(w), "Fireball", 12);
|
||||
addMapping(EntitySmallFireball.class, (w) -> new EntitySmallFireball(w), "SmallFireball", 13);
|
||||
addMapping(EntityEnderPearl.class, (w) -> new EntityEnderPearl(w), "ThrownEnderpearl", 14);
|
||||
addMapping(EntityEnderEye.class, (w) -> new EntityEnderEye(w), "EyeOfEnderSignal", 15);
|
||||
addMapping(EntityPotion.class, (w) -> new EntityPotion(w), "ThrownPotion", 16);
|
||||
addMapping(EntityExpBottle.class, (w) -> new EntityExpBottle(w), "ThrownExpBottle", 17);
|
||||
addMapping(EntityItemFrame.class, (w) -> new EntityItemFrame(w), "ItemFrame", 18);
|
||||
addMapping(EntityWitherSkull.class, (w) -> new EntityWitherSkull(w), "WitherSkull", 19);
|
||||
addMapping(EntityTNTPrimed.class, (w) -> new EntityTNTPrimed(w), "PrimedTnt", 20);
|
||||
addMapping(EntityFallingSand.class, (w) -> new EntityFallingSand(w), "FallingSand", 21);
|
||||
addMapping(EntityFireworkRocket.class, (w) -> new EntityFireworkRocket(w), "FireworksRocketEntity", 22);
|
||||
addMapping(EntityBoat.class, (w) -> new EntityBoat(w), "Boat", 41);
|
||||
addMapping(EntityMinecartEmpty.class, (w) -> new EntityMinecartEmpty(w), "MinecartRideable", 42);
|
||||
addMapping(EntityMinecartChest.class, (w) -> new EntityMinecartChest(w), "MinecartChest", 43);
|
||||
addMapping(EntityMinecartFurnace.class, (w) -> new EntityMinecartFurnace(w), "MinecartFurnace", 44);
|
||||
addMapping(EntityMinecartTNT.class, (w) -> new EntityMinecartTNT(w), "MinecartTNT", 45);
|
||||
addMapping(EntityMinecartHopper.class, (w) -> new EntityMinecartHopper(w), "MinecartHopper", 46);
|
||||
addMapping(EntityMinecartMobSpawner.class, (w) -> new EntityMinecartMobSpawner(w), "MinecartSpawner", 47);
|
||||
addMapping(EntityLiving.class, null, "Mob", 48);
|
||||
addMapping(EntityMob.class, null, "Monster", 49);
|
||||
addMapping(EntityCreeper.class, (w) -> new EntityCreeper(w), "Creeper", 50, 894731, 0);
|
||||
addMapping(EntitySkeleton.class, (w) -> new EntitySkeleton(w), "Skeleton", 51, 12698049, 4802889);
|
||||
addMapping(EntitySpider.class, (w) -> new EntitySpider(w), "Spider", 52, 3419431, 11013646);
|
||||
addMapping(EntityGiantZombie.class, (w) -> new EntityGiantZombie(w), "Giant", 53);
|
||||
addMapping(EntityZombie.class, (w) -> new EntityZombie(w), "Zombie", 54, 44975, 7969893);
|
||||
addMapping(EntitySlime.class, (w) -> new EntitySlime(w), "Slime", 55, 5349438, 8306542);
|
||||
addMapping(EntityGhast.class, (w) -> new EntityGhast(w), "Ghast", 56, 16382457, 12369084);
|
||||
addMapping(EntityPigZombie.class, (w) -> new EntityPigZombie(w), "PigZombie", 57, 15373203, 5009705);
|
||||
addMapping(EntityEnderman.class, (w) -> new EntityEnderman(w), "Enderman", 58, 1447446, 0);
|
||||
addMapping(EntityCaveSpider.class, (w) -> new EntityCaveSpider(w), "CaveSpider", 59, 803406, 11013646);
|
||||
addMapping(EntitySilverfish.class, (w) -> new EntitySilverfish(w), "Silverfish", 60, 7237230, 3158064);
|
||||
addMapping(EntityBlaze.class, (w) -> new EntityBlaze(w), "Blaze", 61, 16167425, 16775294);
|
||||
addMapping(EntityMagmaCube.class, (w) -> new EntityMagmaCube(w), "LavaSlime", 62, 3407872, 16579584);
|
||||
addMapping(EntityDragon.class, (w) -> new EntityDragon(w), "EnderDragon", 63);
|
||||
addMapping(EntityWither.class, (w) -> new EntityWither(w), "WitherBoss", 64);
|
||||
addMapping(EntityBat.class, (w) -> new EntityBat(w), "Bat", 65, 4996656, 986895);
|
||||
addMapping(EntityWitch.class, (w) -> new EntityWitch(w), "Witch", 66, 3407872, 5349438);
|
||||
addMapping(EntityPig.class, (w) -> new EntityPig(w), "Pig", 90, 15771042, 14377823);
|
||||
addMapping(EntitySheep.class, (w) -> new EntitySheep(w), "Sheep", 91, 15198183, 16758197);
|
||||
addMapping(EntityCow.class, (w) -> new EntityCow(w), "Cow", 92, 4470310, 10592673);
|
||||
addMapping(EntityChicken.class, (w) -> new EntityChicken(w), "Chicken", 93, 10592673, 16711680);
|
||||
addMapping(EntitySquid.class, (w) -> new EntitySquid(w), "Squid", 94, 2243405, 7375001);
|
||||
addMapping(EntityWolf.class, (w) -> new EntityWolf(w), "Wolf", 95, 14144467, 13545366);
|
||||
addMapping(EntityMooshroom.class, (w) -> new EntityMooshroom(w), "MushroomCow", 96, 10489616, 12040119);
|
||||
addMapping(EntitySnowman.class, (w) -> new EntitySnowman(w), "SnowMan", 97);
|
||||
addMapping(EntityOcelot.class, (w) -> new EntityOcelot(w), "Ozelot", 98, 15720061, 5653556);
|
||||
addMapping(EntityIronGolem.class, (w) -> new EntityIronGolem(w), "VillagerGolem", 99);
|
||||
addMapping(EntityVillager.class, (w) -> new EntityVillager(w), "Villager", 120, 5651507, 12422002);
|
||||
addMapping(EntityEnderCrystal.class, (w) -> new EntityEnderCrystal(w), "EnderCrystal", 200);
|
||||
}
|
||||
}
|
||||
|
@ -272,12 +272,14 @@ public class EntityTrackerEntry {
|
||||
|
||||
while (var1.hasNext()) {
|
||||
EntityPlayerMP var2 = (EntityPlayerMP) var1.next();
|
||||
//System.out.println(this.trackedEntity.getEntityName() + ": sendDestroyEntityPacketToTrackedPlayers");
|
||||
var2.destroyedItemsNetCache.add(Integer.valueOf(this.trackedEntity.entityId));
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFromTrackedPlayers(EntityPlayerMP par1EntityPlayerMP) {
|
||||
if (this.trackingPlayers.contains(par1EntityPlayerMP)) {
|
||||
//System.out.println(this.trackedEntity.getEntityName() + ": removeFromTrackedPlayers");
|
||||
par1EntityPlayerMP.destroyedItemsNetCache.add(Integer.valueOf(this.trackedEntity.entityId));
|
||||
this.trackingPlayers.remove(par1EntityPlayerMP);
|
||||
}
|
||||
@ -352,6 +354,7 @@ public class EntityTrackerEntry {
|
||||
}
|
||||
} else if (this.trackingPlayers.contains(par1EntityPlayerMP)) {
|
||||
this.trackingPlayers.remove(par1EntityPlayerMP);
|
||||
//System.out.println(this.trackedEntity.getEntityName() + ": updatePlayerEntity");
|
||||
par1EntityPlayerMP.destroyedItemsNetCache.add(Integer.valueOf(this.trackedEntity.entityId));
|
||||
}
|
||||
}
|
||||
@ -466,6 +469,7 @@ public class EntityTrackerEntry {
|
||||
public void removeTrackedPlayerSymmetric(EntityPlayerMP par1EntityPlayerMP) {
|
||||
if (this.trackingPlayers.contains(par1EntityPlayerMP)) {
|
||||
this.trackingPlayers.remove(par1EntityPlayerMP);
|
||||
System.out.println(this.trackedEntity.getEntityName() + ": removeTrackedPlayerSymmetric");
|
||||
par1EntityPlayerMP.destroyedItemsNetCache.add(Integer.valueOf(this.trackedEntity.entityId));
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package net.minecraft.src;
|
||||
|
||||
import net.lax1dude.eaglercraft.sp.NoCatchParse;
|
||||
|
||||
class GameRuleValue {
|
||||
private String valueString;
|
||||
private boolean valueBoolean;
|
||||
@ -16,17 +18,17 @@ class GameRuleValue {
|
||||
public void setValue(String par1Str) {
|
||||
this.valueString = par1Str;
|
||||
this.valueBoolean = Boolean.parseBoolean(par1Str);
|
||||
|
||||
try {
|
||||
this.valueInteger = Integer.parseInt(par1Str);
|
||||
} catch (NumberFormatException var4) {
|
||||
;
|
||||
|
||||
this.valueInteger = NoCatchParse.parseInt(par1Str);
|
||||
|
||||
if(this.valueInteger == NoCatchParse.INT_EXCEPTION) {
|
||||
this.valueInteger = 0;
|
||||
}
|
||||
|
||||
try {
|
||||
this.valueDouble = Double.parseDouble(par1Str);
|
||||
} catch (NumberFormatException var3) {
|
||||
;
|
||||
|
||||
this.valueDouble = NoCatchParse.parseDouble(par1Str);
|
||||
|
||||
if(this.valueDouble == NoCatchParse.DOUBLE_EXCEPTION) {
|
||||
this.valueDouble = 0.0d;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,13 @@ public abstract class NetHandler {
|
||||
*/
|
||||
public void handleMapChunk(Packet51MapChunk par1Packet51MapChunk) {
|
||||
}
|
||||
|
||||
public void handlePackets() {
|
||||
}
|
||||
|
||||
public boolean shouldBeRemoved() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default handler called for packets that don't have their own handlers in
|
||||
|
@ -27,21 +27,31 @@ public class NetLoginHandler extends NetHandler {
|
||||
private int loginTimer = 0;
|
||||
private String clientUsername = null;
|
||||
private volatile boolean field_72544_i = false;
|
||||
|
||||
|
||||
private boolean field_92079_k = false;
|
||||
|
||||
private int hash = 0;
|
||||
private static int hashBase = 69696969;
|
||||
|
||||
public NetLoginHandler(MinecraftServer par1MinecraftServer, WorkerNetworkManager par2Socket) {
|
||||
this.mcServer = par1MinecraftServer;
|
||||
this.myTCPConnection = par2Socket;
|
||||
hash = ++hashBase;
|
||||
}
|
||||
|
||||
public boolean shouldBeRemoved() {
|
||||
return this.finishedProcessing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the user in if a login packet is found, otherwise keeps processing
|
||||
* network packets unless the timeout has occurred.
|
||||
*/
|
||||
public void tryLogin() {
|
||||
public void handlePackets() {
|
||||
System.out.println("[Server][LOGIN][HANDLE][" + clientUsername + "]");
|
||||
if (this.field_72544_i) {
|
||||
this.initializePlayerConnection();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.loginTimer++ == 600) {
|
||||
@ -50,6 +60,14 @@ public class NetLoginHandler extends NetHandler {
|
||||
this.myTCPConnection.processReadPackets();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return (o instanceof NetLoginHandler) && ((NetLoginHandler)o).hash == hash;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects the user with the given reason.
|
||||
@ -67,6 +85,7 @@ public class NetLoginHandler extends NetHandler {
|
||||
|
||||
public void handleClientProtocol(Packet2ClientProtocol par1Packet2ClientProtocol) {
|
||||
this.clientUsername = par1Packet2ClientProtocol.getUsername();
|
||||
System.out.println("[Server][HANDSHAKE][" + this.clientUsername + "]");
|
||||
|
||||
if (!this.clientUsername.equals(StringUtils.stripControlCodes(this.clientUsername))) {
|
||||
this.kickUser("Invalid username!");
|
||||
@ -77,6 +96,8 @@ public class NetLoginHandler extends NetHandler {
|
||||
} else {
|
||||
this.kickUser("Outdated client!");
|
||||
}
|
||||
}else {
|
||||
this.initializePlayerConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -111,6 +132,8 @@ public class NetLoginHandler extends NetHandler {
|
||||
|
||||
if (var2 != null) {
|
||||
this.mcServer.getConfigurationManager().initializeConnectionToPlayer(this.myTCPConnection, var2);
|
||||
}else {
|
||||
this.kickUser("Could not construct EntityPlayerMP for '" + var1 + "'");
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,7 +192,7 @@ public class NetLoginHandler extends NetHandler {
|
||||
}
|
||||
|
||||
public String getUsernameAndAddress() {
|
||||
return this.clientUsername + " [EAG]";
|
||||
return this.clientUsername + "[EAG]";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,13 +49,24 @@ public class NetServerHandler extends NetHandler {
|
||||
/** is true when the player has moved since his last movement packet */
|
||||
private boolean hasMoved = true;
|
||||
private IntHashMap field_72586_s = new IntHashMap();
|
||||
private int hash = 0;
|
||||
private static int hashCounter = 0;
|
||||
|
||||
public NetServerHandler(MinecraftServer par1, INetworkManager par2, EntityPlayerMP par3) {
|
||||
this.mcServer = par1;
|
||||
this.netManager = par2;
|
||||
par2.setNetHandler(this);
|
||||
this.playerEntity = par3;
|
||||
par3.playerNetServerHandler = this;
|
||||
System.out.println("made nethandlerserver for '" + par3.username + "'");
|
||||
par2.setNetHandler(this);
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
return (o instanceof NetServerHandler) && ((NetServerHandler)o).hash == hash;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,6 +97,10 @@ public class NetServerHandler extends NetHandler {
|
||||
this.mcServer.theProfiler.endStartSection("playerTick");
|
||||
this.mcServer.theProfiler.endSection();
|
||||
}
|
||||
|
||||
public boolean shouldBeRemoved() {
|
||||
return connectionClosed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kick the offending player and give a reason why
|
||||
|
@ -83,9 +83,9 @@ public class ServerConfigurationManager {
|
||||
this.mcServer.getNetworkThread().addPlayer(var7);
|
||||
var7.sendPacket(new Packet4UpdateTime(var5.getTotalWorldTime(), var5.getWorldTime()));
|
||||
|
||||
if (this.mcServer.getTexturePack().length() > 0) {
|
||||
par2EntityPlayerMP.requestTexturePackLoad(this.mcServer.getTexturePack(), this.mcServer.textureSize());
|
||||
}
|
||||
//if (this.mcServer.getTexturePack().length() > 0) {
|
||||
// par2EntityPlayerMP.requestTexturePackLoad(this.mcServer.getTexturePack(), this.mcServer.textureSize());
|
||||
//}
|
||||
|
||||
Iterator var8 = par2EntityPlayerMP.getActivePotionEffects().iterator();
|
||||
|
||||
|
@ -177,15 +177,15 @@ public abstract class World implements IBlockAccess {
|
||||
this.worldInfo.setServerInitialized(true);
|
||||
}
|
||||
|
||||
VillageCollection var7 = (VillageCollection) this.mapStorage.loadData(VillageCollection.class, "villages");
|
||||
//VillageCollection var7 = (VillageCollection) this.mapStorage.loadData(VillageCollection.class, "villages");
|
||||
|
||||
if (var7 == null) {
|
||||
//if (var7 == null) {
|
||||
this.villageCollectionObj = new VillageCollection(this);
|
||||
this.mapStorage.setData("villages", this.villageCollectionObj);
|
||||
} else {
|
||||
this.villageCollectionObj = var7;
|
||||
this.villageCollectionObj.func_82566_a(this);
|
||||
}
|
||||
//} else {
|
||||
// this.villageCollectionObj = var7;
|
||||
// this.villageCollectionObj.func_82566_a(this);
|
||||
//}
|
||||
|
||||
this.calculateInitialSkylight();
|
||||
this.calculateInitialWeather();
|
||||
|
@ -57,6 +57,7 @@ import org.lwjgl.util.glu.GLU;
|
||||
import de.cuina.fireandfuel.CodecJLayerMP3;
|
||||
import net.lax1dude.eaglercraft.AssetRepository;
|
||||
import net.lax1dude.eaglercraft.EarlyLoadScreen;
|
||||
import net.lax1dude.eaglercraft.PKT;
|
||||
import net.lax1dude.eaglercraft.adapter.lwjgl.GameWindowListener;
|
||||
import net.minecraft.src.MathHelper;
|
||||
import paulscode.sound.SoundSystem;
|
||||
@ -1175,4 +1176,36 @@ public class EaglerAdapterImpl2 {
|
||||
return appendbuffer;
|
||||
}
|
||||
|
||||
public static final boolean isIntegratedServerAvailable() {
|
||||
return true; //TODO: change to false
|
||||
}
|
||||
|
||||
public static final void beginLoadingIntegratedServer() {
|
||||
throw new UnsupportedOperationException("Integrated server is not available in LWJGL eagleradapter");
|
||||
}
|
||||
|
||||
public static final boolean isIntegratedServerAlive() {
|
||||
throw new UnsupportedOperationException("Integrated server is not available in LWJGL eagleradapter");
|
||||
}
|
||||
|
||||
public static final void terminateIntegratedServer() {
|
||||
throw new UnsupportedOperationException("Integrated server is not available in LWJGL eagleradapter");
|
||||
}
|
||||
|
||||
public static final void enableChannel(String channel) {
|
||||
throw new UnsupportedOperationException("Integrated server is not available in LWJGL eagleradapter");
|
||||
}
|
||||
|
||||
public static final void disableChannel(String channel) {
|
||||
throw new UnsupportedOperationException("Integrated server is not available in LWJGL eagleradapter");
|
||||
}
|
||||
|
||||
public static final void sendToIntegratedServer(String channel, byte[] pkt) {
|
||||
throw new UnsupportedOperationException("Integrated server is not available in LWJGL eagleradapter");
|
||||
}
|
||||
|
||||
public static final PKT recieveFromIntegratedServer(String channel, byte[] pkt) {
|
||||
throw new UnsupportedOperationException("Integrated server is not available in LWJGL eagleradapter");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,68 @@
|
||||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import net.minecraft.src.GuiButton;
|
||||
import net.minecraft.src.GuiScreen;
|
||||
import net.minecraft.src.StringTranslate;
|
||||
|
||||
public class GuiScreenBackupWorld extends GuiScreen {
|
||||
|
||||
private GuiScreen selectWorld;
|
||||
|
||||
private GuiButton worldRecreate = null;
|
||||
private GuiButton worldDuplicate = null;
|
||||
private GuiButton worldExport = null;
|
||||
private GuiButton worldConvert = null;
|
||||
private long worldSeed;
|
||||
|
||||
private String worldName;
|
||||
|
||||
public GuiScreenBackupWorld(GuiScreen selectWorld, String worldName, long worldSeed) {
|
||||
this.selectWorld = selectWorld;
|
||||
this.worldName = worldName;
|
||||
this.worldSeed = worldSeed;
|
||||
}
|
||||
|
||||
public void initGui() {
|
||||
StringTranslate var1 = StringTranslate.getInstance();
|
||||
this.buttonList.add(worldRecreate = new GuiButton(1, this.width / 2 - 100, this.height / 5 + 40, var1.translateKey("selectWorld.backup.recreate")));
|
||||
this.buttonList.add(worldDuplicate = new GuiButton(2, this.width / 2 - 100, this.height / 5 + 65, var1.translateKey("selectWorld.backup.duplicate")));
|
||||
this.buttonList.add(worldExport = new GuiButton(3, this.width / 2 - 100, this.height / 5 + 115, var1.translateKey("selectWorld.backup.export")));
|
||||
this.buttonList.add(worldConvert = new GuiButton(4, this.width / 2 - 100, this.height / 5 + 140, var1.translateKey("selectWorld.backup.vanilla")));
|
||||
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 160, var1.translateKey("gui.cancel")));
|
||||
}
|
||||
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
StringTranslate var4 = StringTranslate.getInstance();
|
||||
this.drawDefaultBackground();
|
||||
|
||||
this.drawCenteredString(this.fontRenderer, var4.translateKey("selectWorld.backup.title") + " '" + worldName + "'", this.width / 2, this.height / 5, 16777215);
|
||||
this.drawCenteredString(this.fontRenderer, var4.translateKey("selectWorld.backup.seed") + " " + worldSeed, this.width / 2, this.height / 5 + 97, 0xAAAAFF);
|
||||
|
||||
int toolTipColor = 0xDDDDAA;
|
||||
if(worldRecreate.func_82252_a()) {
|
||||
this.drawCenteredString(this.fontRenderer, var4.translateKey("selectWorld.backup.recreate.tooltip"), this.width / 2, this.height / 5 + 20, toolTipColor);
|
||||
}else if(worldDuplicate.func_82252_a()) {
|
||||
this.drawCenteredString(this.fontRenderer, var4.translateKey("selectWorld.backup.duplicate.tooltip"), this.width / 2, this.height / 5 + 20, toolTipColor);
|
||||
}else if(worldExport.func_82252_a()) {
|
||||
this.drawCenteredString(this.fontRenderer, var4.translateKey("selectWorld.backup.export.tooltip"), this.width / 2, this.height / 5 + 20, toolTipColor);
|
||||
}else if(worldConvert.func_82252_a()) {
|
||||
this.drawCenteredString(this.fontRenderer, var4.translateKey("selectWorld.backup.vanilla.tooltip"), this.width / 2, this.height / 5 + 20, toolTipColor);
|
||||
}
|
||||
|
||||
super.drawScreen(par1, par2, par3);
|
||||
}
|
||||
|
||||
protected void actionPerformed(GuiButton par1GuiButton) {
|
||||
if(par1GuiButton.id == 0) {
|
||||
this.mc.displayGuiScreen(selectWorld);
|
||||
}else if(par1GuiButton.id == 1) {
|
||||
this.mc.displayGuiScreen(new GuiScreenSingleplayerNotImplemented(this, "recreate world"));
|
||||
}else if(par1GuiButton.id == 2) {
|
||||
this.mc.displayGuiScreen(new GuiScreenSingleplayerNotImplemented(this, "duplicate world"));
|
||||
}else if(par1GuiButton.id == 3) {
|
||||
this.mc.displayGuiScreen(new GuiScreenSingleplayerNotImplemented(this, "export world"));
|
||||
}else if(par1GuiButton.id == 4) {
|
||||
this.mc.displayGuiScreen(new GuiScreenSingleplayerNotImplemented(this, "export vanilla 1.5.2 world"));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import net.minecraft.src.GuiButton;
|
||||
import net.minecraft.src.GuiCreateWorld;
|
||||
import net.minecraft.src.GuiScreen;
|
||||
import net.minecraft.src.StringTranslate;
|
||||
|
||||
public class GuiScreenCreateWorldSelection extends GuiScreen {
|
||||
|
||||
private GuiScreen mainmenu;
|
||||
private GuiButton worldCreate = null;
|
||||
private GuiButton worldImport = null;
|
||||
private GuiButton worldVanilla = null;
|
||||
|
||||
public GuiScreenCreateWorldSelection(GuiScreen mainmenu) {
|
||||
this.mainmenu = mainmenu;
|
||||
}
|
||||
|
||||
public void initGui() {
|
||||
StringTranslate var1 = StringTranslate.getInstance();
|
||||
this.buttonList.add(worldCreate = new GuiButton(1, this.width / 2 - 100, this.height / 4 + 40, var1.translateKey("selectWorld.create.create")));
|
||||
this.buttonList.add(worldImport = new GuiButton(2, this.width / 2 - 100, this.height / 4 + 65, var1.translateKey("selectWorld.create.import")));
|
||||
this.buttonList.add(worldVanilla = new GuiButton(3, this.width / 2 - 100, this.height / 4 + 90, var1.translateKey("selectWorld.create.vanilla")));
|
||||
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 130, var1.translateKey("gui.cancel")));
|
||||
}
|
||||
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
StringTranslate var4 = StringTranslate.getInstance();
|
||||
this.drawDefaultBackground();
|
||||
|
||||
this.drawCenteredString(this.fontRenderer, var4.translateKey("selectWorld.create.title"), this.width / 2, this.height / 4, 16777215);
|
||||
|
||||
int toolTipColor = 0xDDDDAA;
|
||||
if(worldCreate.func_82252_a()) {
|
||||
this.drawCenteredString(this.fontRenderer, var4.translateKey("selectWorld.create.create.tooltip"), this.width / 2, this.height / 4 + 20, toolTipColor);
|
||||
}else if(worldImport.func_82252_a()) {
|
||||
this.drawCenteredString(this.fontRenderer, var4.translateKey("selectWorld.create.import.tooltip"), this.width / 2, this.height / 4 + 20, toolTipColor);
|
||||
}else if(worldVanilla.func_82252_a()) {
|
||||
this.drawCenteredString(this.fontRenderer, var4.translateKey("selectWorld.create.vanilla.tooltip"), this.width / 2, this.height / 4 + 20, toolTipColor);
|
||||
}
|
||||
|
||||
super.drawScreen(par1, par2, par3);
|
||||
}
|
||||
|
||||
protected void actionPerformed(GuiButton par1GuiButton) {
|
||||
if(par1GuiButton.id == 0) {
|
||||
this.mc.displayGuiScreen(mainmenu);
|
||||
}else if(par1GuiButton.id == 1) {
|
||||
this.mc.displayGuiScreen(new GuiCreateWorld(mainmenu));
|
||||
}else if(par1GuiButton.id == 2) {
|
||||
this.mc.displayGuiScreen(new GuiScreenSingleplayerNotImplemented(this, "load world backup"));
|
||||
}else if(par1GuiButton.id == 3) {
|
||||
this.mc.displayGuiScreen(new GuiScreenSingleplayerNotImplemented(this, "import vanilla world"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.src.GuiButton;
|
||||
import net.minecraft.src.GuiDisconnected;
|
||||
import net.minecraft.src.GuiScreen;
|
||||
import net.minecraft.src.NetClientHandler;
|
||||
import net.minecraft.src.Packet2ClientProtocol;
|
||||
import net.minecraft.src.WorldClient;
|
||||
|
||||
public class GuiScreenSingleplayerConnecting extends GuiScreen {
|
||||
|
||||
private GuiScreen menu;
|
||||
private String message;
|
||||
private GuiButton killTask;
|
||||
private NetClientHandler netHandler = null;
|
||||
|
||||
private long startStartTime;
|
||||
|
||||
public GuiScreenSingleplayerConnecting(GuiScreen menu, String message) {
|
||||
this.menu = menu;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public void initGui() {
|
||||
if(startStartTime == 0) this.startStartTime = System.currentTimeMillis();
|
||||
this.buttonList.add(killTask = new GuiButton(0, this.width / 2 - 100, this.height / 3 + 50, "Kill Task"));
|
||||
killTask.enabled = false;
|
||||
}
|
||||
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
this.drawDefaultBackground();
|
||||
float f = 2.0f;
|
||||
int top = this.height / 3;
|
||||
|
||||
long millis = System.currentTimeMillis();
|
||||
|
||||
long dots = (millis / 500l) % 4l;
|
||||
this.drawString(fontRenderer, message + (dots > 0 ? "." : "") + (dots > 1 ? "." : "") + (dots > 2 ? "." : ""), (this.width - this.fontRenderer.getStringWidth(message)) / 2, top + 10, 0xFFFFFF);
|
||||
|
||||
long elapsed = (millis - startStartTime) / 1000l;
|
||||
if(elapsed > 3) {
|
||||
this.drawCenteredString(fontRenderer, "(" + elapsed + "s)", this.width / 2, top + 25, 0xFFFFFF);
|
||||
}
|
||||
|
||||
super.drawScreen(par1, par2, par3);
|
||||
}
|
||||
|
||||
public boolean doesGuiPauseGame() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void updateScreen() {
|
||||
if(netHandler == null) {
|
||||
try {
|
||||
netHandler = new NetClientHandler(mc, EaglerProfile.username);
|
||||
this.mc.setNetManager(netHandler.getNetManager());
|
||||
netHandler.addToSendQueue(new Packet2ClientProtocol(61, EaglerProfile.username, "127.0.0.1", 0));
|
||||
} catch (IOException e) {
|
||||
this.mc.displayGuiScreen(new GuiDisconnected(this.menu, "connect.failed", "disconnect.genericReason", "could not create nethandler", ""));
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
long millis = System.currentTimeMillis();
|
||||
if(millis - startStartTime > 6000l) {
|
||||
killTask.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected void actionPerformed(GuiButton par1GuiButton) {
|
||||
if(par1GuiButton.id == 0) {
|
||||
IntegratedServer.killWorker();
|
||||
this.mc.loadWorld((WorldClient)null);
|
||||
this.mc.displayGuiScreen(menu);
|
||||
if(netHandler != null) {
|
||||
netHandler.getNetManager().closeConnections();
|
||||
Minecraft.getMinecraft().setNetManager(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.src.GuiButton;
|
||||
import net.minecraft.src.GuiMainMenu;
|
||||
import net.minecraft.src.GuiScreen;
|
||||
|
||||
public class GuiScreenSingleplayerLoading extends GuiScreen {
|
||||
|
||||
private GuiScreen menu;
|
||||
private GuiButton killTask;
|
||||
private String message;
|
||||
private BooleanSupplier checkTaskComplete;
|
||||
private Runnable taskKill;
|
||||
|
||||
private long startStartTime;
|
||||
|
||||
private static final Runnable defaultTerminateAction = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
IntegratedServer.killWorker();
|
||||
Minecraft.getMinecraft().displayGuiScreen(new GuiMainMenu());
|
||||
}
|
||||
};
|
||||
|
||||
public GuiScreenSingleplayerLoading(GuiScreen menu, String message, BooleanSupplier checkTaskComplete) {
|
||||
this(menu, message, checkTaskComplete, defaultTerminateAction);
|
||||
}
|
||||
|
||||
public GuiScreenSingleplayerLoading(GuiScreen menu, String message, BooleanSupplier checkTaskComplete, Runnable onTerminate) {
|
||||
this.menu = menu;
|
||||
this.message = message;
|
||||
this.checkTaskComplete = checkTaskComplete;
|
||||
this.taskKill = onTerminate;
|
||||
}
|
||||
|
||||
public void initGui() {
|
||||
if(startStartTime == 0) this.startStartTime = System.currentTimeMillis();
|
||||
this.buttonList.add(killTask = new GuiButton(0, this.width / 2 - 100, this.height / 3 + 50, "Kill Task"));
|
||||
killTask.enabled = false;
|
||||
}
|
||||
|
||||
public boolean doesGuiPauseGame() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
this.drawDefaultBackground();
|
||||
float f = 2.0f;
|
||||
int top = this.height / 3;
|
||||
|
||||
long millis = System.currentTimeMillis();
|
||||
|
||||
long dots = (millis / 500l) % 4l;
|
||||
this.drawString(fontRenderer, message + (dots > 0 ? "." : "") + (dots > 1 ? "." : "") + (dots > 2 ? "." : ""), (this.width - this.fontRenderer.getStringWidth(message)) / 2, top + 10, 0xFFFFFF);
|
||||
|
||||
long elapsed = (millis - startStartTime) / 1000l;
|
||||
if(elapsed > 3) {
|
||||
this.drawCenteredString(fontRenderer, "(" + elapsed + "s)", this.width / 2, top + 25, 0xFFFFFF);
|
||||
}
|
||||
|
||||
super.drawScreen(par1, par2, par3);
|
||||
}
|
||||
|
||||
public void updateScreen() {
|
||||
long millis = System.currentTimeMillis();
|
||||
if(millis - startStartTime > 6000l) {
|
||||
killTask.enabled = true;
|
||||
}
|
||||
if(checkTaskComplete.getAsBoolean()) {
|
||||
this.mc.displayGuiScreen(menu);
|
||||
}
|
||||
}
|
||||
|
||||
protected void actionPerformed(GuiButton par1GuiButton) {
|
||||
if(par1GuiButton.id == 0) {
|
||||
taskKill.run();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import net.minecraft.src.GuiButton;
|
||||
import net.minecraft.src.GuiScreen;
|
||||
|
||||
public class GuiScreenSingleplayerNotImplemented extends GuiScreen {
|
||||
|
||||
private GuiScreen mainmenu;
|
||||
private String featureName;
|
||||
|
||||
public GuiScreenSingleplayerNotImplemented(GuiScreen mainmenu, String featureName) {
|
||||
this.mainmenu = mainmenu;
|
||||
this.featureName = featureName;
|
||||
}
|
||||
|
||||
public void initGui() {
|
||||
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 3 + 50, "I Understand"));
|
||||
}
|
||||
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
this.drawDefaultBackground();
|
||||
|
||||
this.drawCenteredString(fontRenderer, "the feature '" + featureName + "' is incomplete", this.width / 2, this.height / 3, 0xFFFFFF);
|
||||
this.drawCenteredString(fontRenderer, "it will be added to Eaglercraft in the next update", this.width / 2, this.height / 3 + 20, 0xFFFFFF);
|
||||
|
||||
super.drawScreen(par1, par2, par3);
|
||||
}
|
||||
|
||||
protected void actionPerformed(GuiButton par1GuiButton) {
|
||||
if(par1GuiButton.id == 0) {
|
||||
this.mc.displayGuiScreen(mainmenu);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import net.minecraft.src.EnumChatFormatting;
|
||||
import net.minecraft.src.GuiButton;
|
||||
import net.minecraft.src.GuiScreen;
|
||||
import net.minecraft.src.GuiSelectWorld;
|
||||
|
||||
public class GuiScreenSingleplayerNotice extends GuiScreen {
|
||||
|
||||
private GuiScreen singleplayer;
|
||||
private GuiScreen mainmenu;
|
||||
|
||||
public GuiScreenSingleplayerNotice(GuiScreen singleplayer) {
|
||||
this.singleplayer = singleplayer;
|
||||
public GuiScreenSingleplayerNotice(GuiScreen mainmenu) {
|
||||
this.mainmenu = mainmenu;
|
||||
}
|
||||
|
||||
public void initGui() {
|
||||
@ -39,7 +39,8 @@ public class GuiScreenSingleplayerNotice extends GuiScreen {
|
||||
|
||||
protected void actionPerformed(GuiButton par1GuiButton) {
|
||||
if(par1GuiButton.id == 0) {
|
||||
this.mc.displayGuiScreen(singleplayer);
|
||||
IntegratedServer.begin();
|
||||
this.mc.displayGuiScreen(new GuiScreenSingleplayerLoading(new GuiSelectWorld(mainmenu), "starting up integrated server", () -> IntegratedServer.isReady()));
|
||||
}
|
||||
}
|
||||
|
||||
|
348
src/main/java/net/lax1dude/eaglercraft/IntegratedServer.java
Normal file
348
src/main/java/net/lax1dude/eaglercraft/IntegratedServer.java
Normal file
@ -0,0 +1,348 @@
|
||||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.lax1dude.eaglercraft.sp.ipc.*;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.NetHandler;
|
||||
import net.minecraft.src.WorldSettings;
|
||||
|
||||
public class IntegratedServer {
|
||||
|
||||
public static boolean isWorkerAlive() {
|
||||
return !(statusState < 0 || !EaglerAdapter.isIntegratedServerAlive());
|
||||
}
|
||||
|
||||
public static void killWorker() {
|
||||
openConnections.clear();
|
||||
exceptions.clear();
|
||||
statusState = IntegratedState.WORLD_WORKER_NOT_RUNNING;
|
||||
EaglerAdapter.terminateIntegratedServer();
|
||||
}
|
||||
|
||||
private static String[] loadLocale = null;
|
||||
private static String[] loadStats = null;
|
||||
private static boolean isPaused = false;
|
||||
|
||||
public static void begin() {
|
||||
if(!isWorkerAlive()) {
|
||||
begin(EaglerAdapter.fileContentsLines("lang/en_US.lang"), EaglerAdapter.fileContentsLines("achievement/map.txt"));
|
||||
}
|
||||
}
|
||||
|
||||
public static void begin(String[] locale, String[] stats) {
|
||||
if(!isWorkerAlive()) {
|
||||
openConnections.clear();
|
||||
exceptions.clear();
|
||||
statusState = IntegratedState.WORLD_WORKER_BOOTING;
|
||||
isPaused = false;
|
||||
loadLocale = locale;
|
||||
loadStats = stats;
|
||||
EaglerAdapter.beginLoadingIntegratedServer();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isReady() {
|
||||
return statusState == IntegratedState.WORLD_NONE;
|
||||
}
|
||||
|
||||
public static boolean isWorldRunning() {
|
||||
return statusState == IntegratedState.WORLD_LOADED || statusState == IntegratedState.WORLD_PAUSED;
|
||||
}
|
||||
|
||||
private static void ensureReady() {
|
||||
if(!isReady()) {
|
||||
String msg = "Server is in state " + statusState + " '" + IntegratedState.getStateName(statusState) + "' which is not the 'WORLD_NONE' state for the requested IPC operation";
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ensureWorldReady() {
|
||||
if(!isWorldRunning()) {
|
||||
String msg = "Server is in state " + statusState + " '" + IntegratedState.getStateName(statusState) + "' which is not the 'WORLD_LOADED' state for the requested IPC operation";
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isAlive() {
|
||||
return isWorkerAlive();
|
||||
}
|
||||
|
||||
public static void loadWorld(String name, int difficulty) {
|
||||
loadWorld(name, difficulty, null);
|
||||
}
|
||||
|
||||
public static void loadWorld(String name, int difficulty, WorldSettings gen) {
|
||||
ensureReady();
|
||||
statusState = IntegratedState.WORLD_LOADING;
|
||||
isPaused = false;
|
||||
|
||||
if(gen != null) {
|
||||
sendIPCPacket(new IPCPacket02InitWorld(name, gen.getIPCGamemode(), gen.getTerrainType().getWorldTypeID(),
|
||||
gen.func_82749_j(), gen.getSeed(), gen.areCommandsAllowed(), gen.isMapFeaturesEnabled(), gen.isBonusChestEnabled()));
|
||||
}
|
||||
|
||||
sendIPCPacket(new IPCPacket00StartServer(name, EaglerProfile.username, difficulty));
|
||||
}
|
||||
|
||||
public static void unloadWorld() {
|
||||
ensureWorldReady();
|
||||
statusState = IntegratedState.WORLD_UNLOADING;
|
||||
sendIPCPacket(new IPCPacket01StopServer());
|
||||
}
|
||||
|
||||
public static void autoSave() {
|
||||
if(!isPaused) {
|
||||
statusState = IntegratedState.WORLD_SAVING;
|
||||
sendIPCPacket(new IPCPacket0BPause(false));
|
||||
}
|
||||
}
|
||||
|
||||
public static void setPaused(boolean pause) {
|
||||
if(statusState != IntegratedState.WORLD_LOADED && statusState != IntegratedState.WORLD_PAUSED) {
|
||||
return;
|
||||
}
|
||||
if(isPaused != pause) {
|
||||
if(pause) {
|
||||
statusState = IntegratedState.WORLD_PAUSED;
|
||||
}else {
|
||||
statusState = IntegratedState.WORLD_NONE;
|
||||
}
|
||||
sendIPCPacket(new IPCPacket0BPause(pause));
|
||||
isPaused = pause;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void requestWorldList() {
|
||||
statusState = IntegratedState.WORLD_LISTING;
|
||||
worlds.clear();
|
||||
sendIPCPacket(new IPCPacket0EListWorlds());
|
||||
}
|
||||
|
||||
public static List<NBTTagCompound> getWorldList() {
|
||||
return statusState == IntegratedState.WORLD_LISTING ? null : worlds;
|
||||
}
|
||||
|
||||
public static NBTTagCompound getWorld(String folderName) {
|
||||
for(NBTTagCompound nbt : worlds) {
|
||||
if(folderName.equals(nbt.getString(folderName))) {
|
||||
return nbt;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void deleteWorld(String name) {
|
||||
ensureReady();
|
||||
statusState = IntegratedState.WORLD_DELETING;
|
||||
sendIPCPacket(new IPCPacket03DeleteWorld(name));
|
||||
}
|
||||
|
||||
public static void setWorldName(String name, String displayName) {
|
||||
ensureReady();
|
||||
sendIPCPacket(new IPCPacket06RenameWorldNBT(name, displayName));
|
||||
}
|
||||
|
||||
public static void copyMoveWorld(String oldName, String newName, String newDisplayName, boolean copyFilesNotRename) {
|
||||
ensureReady();
|
||||
statusState = copyFilesNotRename ? IntegratedState.WORLD_DUPLICATING : IntegratedState.WORLD_RENAMING;
|
||||
sendIPCPacket(new IPCPacket04RenameWorld(oldName, newName, newDisplayName, copyFilesNotRename));
|
||||
}
|
||||
|
||||
private static int statusState = IntegratedState.WORLD_WORKER_NOT_RUNNING;
|
||||
private static String worldStatusString = "";
|
||||
private static float worldStatusProgress = 0.0f;
|
||||
|
||||
private static final LinkedList<IPCPacket15ThrowException> exceptions = new LinkedList();
|
||||
|
||||
public static final LinkedList<NBTTagCompound> worlds = new LinkedList();
|
||||
|
||||
public static int statusState() {
|
||||
return statusState;
|
||||
}
|
||||
|
||||
public static String worldStatusString() {
|
||||
return worldStatusString;
|
||||
}
|
||||
|
||||
public static float worldStatusProgress() {
|
||||
return worldStatusProgress;
|
||||
}
|
||||
|
||||
public static IPCPacket15ThrowException worldStatusError() {
|
||||
return exceptions.size() > 0 ? exceptions.remove(0) : null;
|
||||
}
|
||||
|
||||
private static boolean logException = false;
|
||||
|
||||
public static void enableExceptionLog(boolean f) {
|
||||
logException = f;
|
||||
}
|
||||
|
||||
public static void processICP() {
|
||||
|
||||
if(!EaglerAdapter.isIntegratedServerAlive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
PKT pktBytes;
|
||||
while((pktBytes = EaglerAdapter.recieveFromIntegratedServer("IPC")) != null) {
|
||||
|
||||
IPCPacketBase packet;
|
||||
try {
|
||||
packet = IPCPacketManager.IPCDeserialize(pktBytes.data);
|
||||
}catch(IOException e) {
|
||||
System.err.print("Failed to deserialize IPC packet: ");
|
||||
e.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
|
||||
int id = packet.id();
|
||||
|
||||
try {
|
||||
switch(id) {
|
||||
case IPCPacketFFProcessKeepAlive.ID: {
|
||||
IPCPacketFFProcessKeepAlive pkt = (IPCPacketFFProcessKeepAlive)packet;
|
||||
IntegratedState.isACKValidInState(pkt.ack, statusState);
|
||||
switch(pkt.ack) {
|
||||
case 0xFF:
|
||||
System.out.println("Integrated server signaled a successful boot");
|
||||
sendIPCPacket(new IPCPacket14StringList(IPCPacket14StringList.LOCALE, loadLocale));
|
||||
sendIPCPacket(new IPCPacket14StringList(IPCPacket14StringList.STAT_GUID, loadStats));
|
||||
loadLocale = loadStats = null;
|
||||
statusState = IntegratedState.WORLD_NONE;
|
||||
break;
|
||||
case IPCPacket00StartServer.ID:
|
||||
statusState = IntegratedState.WORLD_LOADED;
|
||||
isPaused = false;
|
||||
break;
|
||||
case IPCPacket0BPause.ID:
|
||||
statusState = isPaused ? IntegratedState.WORLD_PAUSED : IntegratedState.WORLD_LOADED;
|
||||
break;
|
||||
case IPCPacket01StopServer.ID:
|
||||
case IPCPacket03DeleteWorld.ID:
|
||||
case IPCPacket04RenameWorld.ID:
|
||||
case IPCPacket07ImportWorld.ID:
|
||||
case IPCPacket12FileWrite.ID:
|
||||
case IPCPacket13FileCopyMove.ID:
|
||||
statusState = IntegratedState.WORLD_NONE;
|
||||
break;
|
||||
default:
|
||||
System.err.println("IPC acknowledge packet type 0x" + Integer.toHexString(id) + " class '" + packet.getClass().getSimpleName() + "' was not handled");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IPCPacket09RequestResponse.ID: {
|
||||
IPCPacket09RequestResponse pkt = (IPCPacket09RequestResponse)packet;
|
||||
|
||||
// import/export/read
|
||||
|
||||
break;
|
||||
}
|
||||
case IPCPacket0DProgressUpdate.ID: {
|
||||
IPCPacket0DProgressUpdate pkt = (IPCPacket0DProgressUpdate)packet;
|
||||
worldStatusString = pkt.updateMessage;
|
||||
worldStatusProgress = pkt.updateProgress;
|
||||
if(logException) {
|
||||
System.out.println("IntegratedServer: task '" + pkt.updateMessage + "' is " + ((int)(pkt.updateProgress * 100.0f)) + "% complete");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IPCPacket14StringList.ID: {
|
||||
IPCPacket14StringList pkt = (IPCPacket14StringList)packet;
|
||||
|
||||
// file path list for file browser
|
||||
|
||||
break;
|
||||
}
|
||||
case IPCPacket15ThrowException.ID: {
|
||||
exceptions.add((IPCPacket15ThrowException)packet);
|
||||
if(logException) {
|
||||
((IPCPacket15ThrowException)packet).log();
|
||||
}
|
||||
if(exceptions.size() > 64) {
|
||||
exceptions.remove(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IPCPacket16NBTList.ID: {
|
||||
IPCPacket16NBTList pkt = (IPCPacket16NBTList)packet;
|
||||
if(pkt.opCode == IPCPacket16NBTList.WORLD_LIST && statusState == IntegratedState.WORLD_LISTING) {
|
||||
statusState = IntegratedState.WORLD_NONE;
|
||||
worlds.clear();
|
||||
worlds.addAll(pkt.nbtTagList);
|
||||
}else {
|
||||
System.err.println("IPC packet type 0x" + Integer.toHexString(id) + " class '" + packet.getClass().getSimpleName() + "' contained invalid opCode " + pkt.opCode + " in state " + statusState + " '" + IntegratedState.getStateName(statusState) + "'");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IPCPacket0CPlayerChannel.ID: {
|
||||
IPCPacket0CPlayerChannel pkt = (IPCPacket0CPlayerChannel)packet;
|
||||
WorkerNetworkManager newConnection = openConnections.get(pkt.channel);
|
||||
if(newConnection == null) {
|
||||
return;
|
||||
}
|
||||
System.out.println("[Client][INIT][CLOSE][" + pkt.channel + "]");
|
||||
newConnection.closeConnections();
|
||||
openConnections.remove(pkt.channel);
|
||||
EaglerAdapter.disableChannel("NET|" + pkt.channel);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
System.err.println("IPC packet type 0x" + Integer.toHexString(id) + " class '" + packet.getClass().getSimpleName() + "' was not handled");
|
||||
break;
|
||||
}
|
||||
}catch(Throwable t) {
|
||||
System.err.println("Failed to process IPC packet type 0x" + Integer.toHexString(id) + " class '" + packet.getClass().getSimpleName() + "'");
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendIPCPacket(IPCPacketBase pkt) {
|
||||
try {
|
||||
byte[] serialized = IPCPacketManager.IPCSerialize(pkt);
|
||||
EaglerAdapter.sendToIntegratedServer("IPC", serialized);
|
||||
} catch (IOException e) {
|
||||
System.err.println("Could not serialize IPC packet 0x" + Integer.toHexString(pkt.id()) + " class '" + pkt.getClass().getSimpleName() + "'");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static final HashMap<String, WorkerNetworkManager> openConnections = new HashMap();
|
||||
|
||||
public static final boolean doesChannelExist(String channel) {
|
||||
return openConnections.containsKey(channel);
|
||||
}
|
||||
|
||||
public static final WorkerNetworkManager openConnection(String channel, NetHandler netHandler) {
|
||||
WorkerNetworkManager newConnection = openConnections.get(channel);
|
||||
if(newConnection != null) {
|
||||
return newConnection;
|
||||
}
|
||||
System.out.println("[Client][INIT][OPEN][" + channel + "]");
|
||||
EaglerAdapter.enableChannel("NET|" + channel);
|
||||
sendIPCPacket(new IPCPacket0CPlayerChannel(channel, true));
|
||||
newConnection = new WorkerNetworkManager(channel, netHandler);
|
||||
openConnections.put(channel, newConnection);
|
||||
return newConnection;
|
||||
}
|
||||
|
||||
public static final void closeChannel(String channel) {
|
||||
WorkerNetworkManager newConnection = openConnections.get(channel);
|
||||
if(newConnection == null) {
|
||||
return;
|
||||
}
|
||||
System.out.println("[Client][INIT][CLOSE][" + channel + "]");
|
||||
newConnection.closeConnections();
|
||||
openConnections.remove(channel);
|
||||
EaglerAdapter.disableChannel("NET|" + channel);
|
||||
sendIPCPacket(new IPCPacket0CPlayerChannel(channel, false));
|
||||
}
|
||||
|
||||
}
|
77
src/main/java/net/lax1dude/eaglercraft/IntegratedState.java
Normal file
77
src/main/java/net/lax1dude/eaglercraft/IntegratedState.java
Normal file
@ -0,0 +1,77 @@
|
||||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import net.lax1dude.eaglercraft.sp.ipc.*;
|
||||
|
||||
public class IntegratedState {
|
||||
|
||||
public static final int WORLD_WORKER_NOT_RUNNING = -2;
|
||||
public static final int WORLD_WORKER_BOOTING = -1;
|
||||
public static final int WORLD_NONE = 0;
|
||||
public static final int WORLD_LOADING = 2;
|
||||
public static final int WORLD_LOADED = 3;
|
||||
public static final int WORLD_UNLOADING = 4;
|
||||
public static final int WORLD_DELETING = 5;
|
||||
public static final int WORLD_RENAMING = 6;
|
||||
public static final int WORLD_DUPLICATING = 7;
|
||||
public static final int WORLD_PAUSED = 9;
|
||||
public static final int WORLD_LISTING = 10;
|
||||
public static final int WORLD_SAVING = 11;
|
||||
public static final int WORLD_IMPORTING = 12;
|
||||
public static final int WORLD_EXPORTING = 13;
|
||||
public static final int WORLD_GET_NBT = 14;
|
||||
|
||||
public static final int WORLD_LIST_FILE = 15;
|
||||
public static final int WORLD_FILE_READ = 16;
|
||||
public static final int WORLD_FILE_WRITE = 17;
|
||||
public static final int WORLD_FILE_MOVE = 18;
|
||||
public static final int WORLD_FILE_COPY = 19;
|
||||
|
||||
public static String getStateName(int i) {
|
||||
switch(i) {
|
||||
case WORLD_WORKER_NOT_RUNNING: return "WORLD_WORKER_NOT_RUNNING";
|
||||
case WORLD_WORKER_BOOTING: return "WORLD_WORKER_BOOTING";
|
||||
case WORLD_NONE: return "WORLD_NONE";
|
||||
case WORLD_LOADING: return "WORLD_LOADING";
|
||||
case WORLD_LOADED: return "WORLD_LOADED";
|
||||
case WORLD_UNLOADING: return "WORLD_UNLOADING";
|
||||
case WORLD_DELETING: return "WORLD_DELETING";
|
||||
case WORLD_RENAMING: return "WORLD_RENAMING";
|
||||
case WORLD_DUPLICATING: return "WORLD_DUPLICATING";
|
||||
case WORLD_PAUSED: return "WORLD_PAUSED";
|
||||
case WORLD_LISTING: return "WORLD_LISTING";
|
||||
case WORLD_SAVING: return "WORLD_SAVING";
|
||||
case WORLD_IMPORTING: return "WORLD_IMPORTING";
|
||||
case WORLD_EXPORTING: return "WORLD_EXPORTING";
|
||||
case WORLD_GET_NBT: return "WORLD_GET_NBT";
|
||||
case WORLD_LIST_FILE: return "WORLD_LIST_FILE";
|
||||
case WORLD_FILE_READ: return "WORLD_FILE_READ";
|
||||
case WORLD_FILE_WRITE: return "WORLD_FILE_WRITE";
|
||||
case WORLD_FILE_MOVE: return "WORLD_FILE_MOVE";
|
||||
case WORLD_FILE_COPY: return "WORLD_FILE_COPY";
|
||||
default: return "INVALID";
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isACKValidInState(int ack, int state) {
|
||||
switch(ack) {
|
||||
case 0xFF: return state == WORLD_WORKER_BOOTING;
|
||||
case IPCPacket00StartServer.ID: return state == WORLD_LOADING;
|
||||
case IPCPacket01StopServer.ID: return state == WORLD_UNLOADING;
|
||||
case IPCPacket03DeleteWorld.ID: return state == WORLD_DELETING;
|
||||
case IPCPacket04RenameWorld.ID: return (state == WORLD_DUPLICATING || state == WORLD_RENAMING);
|
||||
case IPCPacket07ImportWorld.ID: return state == WORLD_IMPORTING;
|
||||
case IPCPacket0BPause.ID: return (state == WORLD_SAVING || state == WORLD_PAUSED);
|
||||
case IPCPacket12FileWrite.ID: return state == WORLD_FILE_WRITE;
|
||||
case IPCPacket13FileCopyMove.ID: return (state == WORLD_FILE_MOVE || state == WORLD_FILE_COPY);
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void assertState(int ack, int state) {
|
||||
if(!isACKValidInState(ack, state)) {
|
||||
String msg = "Recieved ACK " + ack + " '" + getStateName(ack) + "' while the client state was " + state + " '" + getStateName(state) + "'";
|
||||
System.err.println(msg);
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
}
|
||||
}
|
412
src/main/java/net/lax1dude/eaglercraft/NoCatchParse.java
Normal file
412
src/main/java/net/lax1dude/eaglercraft/NoCatchParse.java
Normal file
@ -0,0 +1,412 @@
|
||||
package net.lax1dude.eaglercraft;
|
||||
|
||||
public class NoCatchParse {
|
||||
|
||||
public static final int INT_EXCEPTION = Integer.MIN_VALUE;
|
||||
public static final float FLOAT_EXCEPTION = Float.NaN;
|
||||
public static final double DOUBLE_EXCEPTION = Double.NaN;
|
||||
|
||||
public static int parseInt(String s) {
|
||||
return parseInt(s, 10, false, INT_EXCEPTION);
|
||||
}
|
||||
|
||||
public static int parseInt(String s, int radix) {
|
||||
return parseInt(s, radix, false, INT_EXCEPTION);
|
||||
}
|
||||
|
||||
public static int parseInt(String s, int radix, boolean log) {
|
||||
return parseInt(s, radix, log, INT_EXCEPTION);
|
||||
}
|
||||
|
||||
public static int parseInt(String s, int radix, boolean log, int exceptionResult) {
|
||||
if (s == null) {
|
||||
if (log) {
|
||||
System.err.println("parseInt: string was null");
|
||||
}
|
||||
return exceptionResult;
|
||||
}
|
||||
|
||||
if (s.isEmpty()) {
|
||||
if (log) {
|
||||
System.err.println("parseInt: string was empty");
|
||||
}
|
||||
return exceptionResult;
|
||||
}
|
||||
|
||||
if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) {
|
||||
if (log) {
|
||||
System.err.println("parseInt: invalid radix '" + radix + "'");
|
||||
}
|
||||
return exceptionResult;
|
||||
}
|
||||
|
||||
tryFail: {
|
||||
int result = 0;
|
||||
boolean negative = false;
|
||||
int i = 0, len = s.length();
|
||||
int limit = -Integer.MAX_VALUE;
|
||||
int multmin;
|
||||
int digit;
|
||||
|
||||
if (len > 0) {
|
||||
char firstChar = s.charAt(0);
|
||||
if (firstChar < '0') { // Possible leading "+" or "-"
|
||||
if (firstChar == '-') {
|
||||
negative = true;
|
||||
limit = Integer.MIN_VALUE;
|
||||
} else if (firstChar != '+')
|
||||
break tryFail;
|
||||
|
||||
if (len == 1)
|
||||
break tryFail;
|
||||
i++;
|
||||
}
|
||||
multmin = limit / radix;
|
||||
while (i < len) {
|
||||
// Accumulating negatively avoids surprises near MAX_VALUE
|
||||
digit = Character.digit(s.charAt(i++), radix);
|
||||
if (digit < 0 || result < multmin) {
|
||||
|
||||
break tryFail;
|
||||
}
|
||||
result *= radix;
|
||||
if (result < limit + digit) {
|
||||
break tryFail;
|
||||
}
|
||||
result -= digit;
|
||||
}
|
||||
} else {
|
||||
break tryFail;
|
||||
}
|
||||
int ret = negative ? result : -result;
|
||||
if (ret == exceptionResult) {
|
||||
System.err.println(
|
||||
"parseInt: number '" + s + "' was parsed successfully but it is equal to exceptionResult");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
if (log) {
|
||||
System.err.println("parseInt: cannot parse '" + s + "'");
|
||||
}
|
||||
return exceptionResult;
|
||||
}
|
||||
|
||||
public static double parseDouble(String s) {
|
||||
return parseDouble(s, false, DOUBLE_EXCEPTION);
|
||||
}
|
||||
|
||||
public static double parseDouble(String s, boolean log) {
|
||||
return parseDouble(s, log, DOUBLE_EXCEPTION);
|
||||
}
|
||||
|
||||
public static double parseDouble(String s, boolean log, double exceptionResult) {
|
||||
if (s == null) {
|
||||
if (log) {
|
||||
System.err.println("parseDouble: string was null");
|
||||
}
|
||||
return exceptionResult;
|
||||
}
|
||||
|
||||
if (s.isEmpty()) {
|
||||
if (log) {
|
||||
System.err.println("parseDouble: string was empty");
|
||||
}
|
||||
return exceptionResult;
|
||||
}
|
||||
|
||||
tryFail: {
|
||||
int start = 0;
|
||||
int end = s.length();
|
||||
while (s.charAt(start) <= ' ') {
|
||||
if (++start == end) {
|
||||
break tryFail;
|
||||
}
|
||||
}
|
||||
while (s.charAt(end - 1) <= ' ') {
|
||||
--end;
|
||||
}
|
||||
|
||||
boolean negative = false;
|
||||
int index = start;
|
||||
if (s.charAt(index) == '-') {
|
||||
++index;
|
||||
negative = true;
|
||||
} else if (s.charAt(index) == '+') {
|
||||
++index;
|
||||
}
|
||||
if (index == end) {
|
||||
break tryFail;
|
||||
}
|
||||
char c = s.charAt(index);
|
||||
|
||||
long mantissa = 0;
|
||||
int exp = 0;
|
||||
boolean hasOneDigit = false;
|
||||
if (c != '.') {
|
||||
hasOneDigit = true;
|
||||
if (c < '0' || c > '9') {
|
||||
break tryFail;
|
||||
}
|
||||
while (index < end && s.charAt(index) == '0') {
|
||||
++index;
|
||||
}
|
||||
while (index < end) {
|
||||
c = s.charAt(index);
|
||||
if (c < '0' || c > '9') {
|
||||
break;
|
||||
}
|
||||
if (mantissa < Long.MAX_VALUE / 10 - 9) {
|
||||
mantissa = mantissa * 10 + (c - '0');
|
||||
} else {
|
||||
++exp;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
}
|
||||
if (index < end && s.charAt(index) == '.') {
|
||||
++index;
|
||||
while (index < end) {
|
||||
c = s.charAt(index);
|
||||
if (c < '0' || c > '9') {
|
||||
break;
|
||||
}
|
||||
if (mantissa < Long.MAX_VALUE / 10 - 9) {
|
||||
mantissa = mantissa * 10 + (c - '0');
|
||||
--exp;
|
||||
}
|
||||
++index;
|
||||
hasOneDigit = true;
|
||||
}
|
||||
if (!hasOneDigit) {
|
||||
break tryFail;
|
||||
}
|
||||
}
|
||||
if (index < end) {
|
||||
c = s.charAt(index);
|
||||
if (c != 'e' && c != 'E') {
|
||||
break tryFail;
|
||||
}
|
||||
++index;
|
||||
boolean negativeExp = false;
|
||||
if (index == end) {
|
||||
break tryFail;
|
||||
}
|
||||
if (s.charAt(index) == '-') {
|
||||
++index;
|
||||
negativeExp = true;
|
||||
} else if (s.charAt(index) == '+') {
|
||||
++index;
|
||||
}
|
||||
int numExp = 0;
|
||||
hasOneDigit = false;
|
||||
while (index < end) {
|
||||
c = s.charAt(index);
|
||||
if (c < '0' || c > '9') {
|
||||
break;
|
||||
}
|
||||
numExp = 10 * numExp + (c - '0');
|
||||
hasOneDigit = true;
|
||||
++index;
|
||||
}
|
||||
if (!hasOneDigit) {
|
||||
break tryFail;
|
||||
}
|
||||
if (negativeExp) {
|
||||
numExp = -numExp;
|
||||
}
|
||||
exp += numExp;
|
||||
}
|
||||
if (exp > 308 || exp == 308 && mantissa > 17976931348623157L) {
|
||||
return !negative ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY;
|
||||
}
|
||||
if (negative) {
|
||||
mantissa = -mantissa;
|
||||
}
|
||||
return mantissa * doubleDecimalExponent(exp);
|
||||
}
|
||||
if (log) {
|
||||
System.err.println("parseDouble: cannot parse '" + s + "'");
|
||||
}
|
||||
return exceptionResult;
|
||||
}
|
||||
|
||||
public static double doubleDecimalExponent(int n) {
|
||||
double d;
|
||||
if (n < 0) {
|
||||
d = 0.1;
|
||||
n = -n;
|
||||
} else {
|
||||
d = 10;
|
||||
}
|
||||
double result = 1;
|
||||
while (n != 0) {
|
||||
if (n % 2 != 0) {
|
||||
result *= d;
|
||||
}
|
||||
d *= d;
|
||||
n /= 2;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float parseFloat(String s) {
|
||||
return parseFloat(s, false, FLOAT_EXCEPTION);
|
||||
}
|
||||
|
||||
public static float parseFloat(String s, boolean log) {
|
||||
return parseFloat(s, log, FLOAT_EXCEPTION);
|
||||
}
|
||||
|
||||
public static float parseFloat(String s, boolean log, float exceptionResult) {
|
||||
if (s == null) {
|
||||
if (log) {
|
||||
System.err.println("parseFloat: string was null");
|
||||
}
|
||||
return exceptionResult;
|
||||
}
|
||||
|
||||
if (s.isEmpty()) {
|
||||
if (log) {
|
||||
System.err.println("parseFloat: string was empty");
|
||||
}
|
||||
return exceptionResult;
|
||||
}
|
||||
|
||||
tryFail: {
|
||||
int start = 0;
|
||||
int end = s.length();
|
||||
while (s.charAt(start) <= ' ') {
|
||||
if (++start == end) {
|
||||
break tryFail;
|
||||
}
|
||||
}
|
||||
while (s.charAt(end - 1) <= ' ') {
|
||||
--end;
|
||||
}
|
||||
|
||||
boolean negative = false;
|
||||
int index = start;
|
||||
if (s.charAt(index) == '-') {
|
||||
++index;
|
||||
negative = true;
|
||||
} else if (s.charAt(index) == '+') {
|
||||
++index;
|
||||
}
|
||||
if (index == end) {
|
||||
break tryFail;
|
||||
}
|
||||
char c = s.charAt(index);
|
||||
|
||||
int mantissa = 0;
|
||||
int exp = 0;
|
||||
|
||||
boolean hasOneDigit = false;
|
||||
if (c != '.') {
|
||||
hasOneDigit = true;
|
||||
if (c < '0' || c > '9') {
|
||||
break tryFail;
|
||||
}
|
||||
|
||||
while (index < end && s.charAt(index) == '0') {
|
||||
++index;
|
||||
}
|
||||
while (index < end) {
|
||||
c = s.charAt(index);
|
||||
if (c < '0' || c > '9') {
|
||||
break;
|
||||
}
|
||||
if (mantissa < (Integer.MAX_VALUE / 10) - 9) {
|
||||
mantissa = mantissa * 10 + (c - '0');
|
||||
} else {
|
||||
++exp;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
||||
if (index < end && s.charAt(index) == '.') {
|
||||
++index;
|
||||
while (index < end) {
|
||||
c = s.charAt(index);
|
||||
if (c < '0' || c > '9') {
|
||||
break;
|
||||
}
|
||||
if (mantissa < (Integer.MAX_VALUE / 10) - 9) {
|
||||
mantissa = mantissa * 10 + (c - '0');
|
||||
--exp;
|
||||
}
|
||||
++index;
|
||||
hasOneDigit = true;
|
||||
}
|
||||
if (!hasOneDigit) {
|
||||
break tryFail;
|
||||
}
|
||||
}
|
||||
if (index < end) {
|
||||
c = s.charAt(index);
|
||||
if (c != 'e' && c != 'E') {
|
||||
break tryFail;
|
||||
}
|
||||
++index;
|
||||
boolean negativeExp = false;
|
||||
if (index == end) {
|
||||
break tryFail;
|
||||
}
|
||||
if (s.charAt(index) == '-') {
|
||||
++index;
|
||||
negativeExp = true;
|
||||
} else if (s.charAt(index) == '+') {
|
||||
++index;
|
||||
}
|
||||
int numExp = 0;
|
||||
hasOneDigit = false;
|
||||
while (index < end) {
|
||||
c = s.charAt(index);
|
||||
if (c < '0' || c > '9') {
|
||||
break;
|
||||
}
|
||||
numExp = 10 * numExp + (c - '0');
|
||||
hasOneDigit = true;
|
||||
++index;
|
||||
}
|
||||
if (!hasOneDigit) {
|
||||
break tryFail;
|
||||
}
|
||||
if (negativeExp) {
|
||||
numExp = -numExp;
|
||||
}
|
||||
exp += numExp;
|
||||
}
|
||||
if (exp > 38 || exp == 38 && mantissa > 34028234) {
|
||||
return !negative ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY;
|
||||
}
|
||||
if (negative) {
|
||||
mantissa = -mantissa;
|
||||
}
|
||||
return mantissa * floatDecimalExponent(exp);
|
||||
}
|
||||
if (log) {
|
||||
System.err.println("parseFloat: cannot parse '" + s + "'");
|
||||
}
|
||||
return exceptionResult;
|
||||
}
|
||||
|
||||
private static float floatDecimalExponent(int n) {
|
||||
double d;
|
||||
if (n < 0) {
|
||||
d = 0.1;
|
||||
n = -n;
|
||||
} else {
|
||||
d = 10;
|
||||
}
|
||||
double result = 1;
|
||||
while (n != 0) {
|
||||
if (n % 2 != 0) {
|
||||
result *= d;
|
||||
}
|
||||
d *= d;
|
||||
n /= 2;
|
||||
}
|
||||
return (float) result;
|
||||
}
|
||||
}
|
13
src/main/java/net/lax1dude/eaglercraft/PKT.java
Normal file
13
src/main/java/net/lax1dude/eaglercraft/PKT.java
Normal file
@ -0,0 +1,13 @@
|
||||
package net.lax1dude.eaglercraft;
|
||||
|
||||
public class PKT {
|
||||
|
||||
public final String channel;
|
||||
public final byte[] data;
|
||||
|
||||
public PKT(String channel, byte[] data) {
|
||||
this.channel = channel;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
@ -94,7 +94,6 @@ public class WebsocketNetworkManager implements INetworkManager {
|
||||
stream.mark();
|
||||
try {
|
||||
Packet pkt = Packet.readPacket(packetStream, false);
|
||||
//System.out.println(pkt.toString());
|
||||
pkt.processPacket(this.netHandler);
|
||||
} catch (EOFException e) {
|
||||
stream.reset();
|
||||
|
117
src/main/java/net/lax1dude/eaglercraft/WorkerNetworkManager.java
Normal file
117
src/main/java/net/lax1dude/eaglercraft/WorkerNetworkManager.java
Normal file
@ -0,0 +1,117 @@
|
||||
package net.lax1dude.eaglercraft;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.lax1dude.eaglercraft.sp.ipc.IPCInputStream;
|
||||
import net.lax1dude.eaglercraft.sp.ipc.IPCOutputStream;
|
||||
import net.minecraft.src.INetworkManager;
|
||||
import net.minecraft.src.NetHandler;
|
||||
import net.minecraft.src.Packet;
|
||||
|
||||
public class WorkerNetworkManager implements INetworkManager {
|
||||
|
||||
private NetHandler theNetHandler;
|
||||
private String ipcChannel;
|
||||
private boolean hasClosed;
|
||||
|
||||
public WorkerNetworkManager(String ipcChannel, NetHandler netHandler) {
|
||||
this.ipcChannel = ipcChannel;
|
||||
this.theNetHandler = netHandler;
|
||||
this.hasClosed = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNetHandler(NetHandler var1) {
|
||||
theNetHandler = var1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToSendQueue(Packet var1) {
|
||||
try {
|
||||
ByteArrayOutputStream bao = new ByteArrayOutputStream(var1.getPacketSize() + 1);
|
||||
Packet.writePacket(var1, new DataOutputStream(bao));
|
||||
EaglerAdapter.sendToIntegratedServer("NET|" + ipcChannel, bao.toByteArray());
|
||||
}catch(IOException e) {
|
||||
System.err.println("Failed to serialize minecraft packet '" + var1.getClass().getSimpleName() + "' for IPC channel 'NET|" + ipcChannel + "'");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void wakeThreads() {
|
||||
// no
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processReadPackets() {
|
||||
PKT ipcPacket;
|
||||
while((ipcPacket = EaglerAdapter.recieveFromIntegratedServer("NET|" + ipcChannel)) != null) {
|
||||
byte[] bytes = ipcPacket.data;
|
||||
try {
|
||||
ByteArrayInputStream bai = new ByteArrayInputStream(bytes);
|
||||
int pktId = bai.read();
|
||||
|
||||
if(pktId == -1) {
|
||||
System.err.println("Recieved invalid '-1' packet");
|
||||
continue;
|
||||
}
|
||||
|
||||
Packet pkt = Packet.getNewPacket(pktId);
|
||||
|
||||
if(pkt == null) {
|
||||
System.err.println("Recieved invalid '" + pktId + "' packet");
|
||||
continue;
|
||||
}
|
||||
|
||||
pkt.readPacketData(new DataInputStream(bai));
|
||||
|
||||
//System.out.println("[Client][" + ipcChannel + "]: packet 0x" + Integer.toHexString(pkt.getPacketId()) + " class '" + pkt.getClass().getSimpleName() + "' recieved");
|
||||
|
||||
try {
|
||||
pkt.processPacket(theNetHandler);
|
||||
}catch(Throwable t) {
|
||||
System.err.println("Could not process minecraft packet 0x" + Integer.toHexString(pkt.getPacketId()) + " class '" + pkt.getClass().getSimpleName() + "' on channel 'NET|" + ipcChannel + "'");
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
}catch(IOException ex) {
|
||||
System.err.println("Could not deserialize a " + bytes.length + " byte long minecraft packet of type '" + (bytes.length <= 0 ? -1 : (int)(bytes[0] & 0xFF)) + "' on channel 'NET|" + ipcChannel + "'");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serverShutdown() {
|
||||
if(!hasClosed) {
|
||||
hasClosed = true;
|
||||
IntegratedServer.closeChannel(ipcChannel);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void networkShutdown(String var1, Object... var2) {
|
||||
if(!hasClosed) {
|
||||
hasClosed = true;
|
||||
IntegratedServer.closeChannel(ipcChannel);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int packetSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeConnections() {
|
||||
if(!hasClosed) {
|
||||
hasClosed = true;
|
||||
IntegratedServer.closeChannel(ipcChannel);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -10,7 +10,10 @@ import net.lax1dude.eaglercraft.EaglerAdapter;
|
||||
import net.lax1dude.eaglercraft.EaglerProfile;
|
||||
|
||||
import net.lax1dude.eaglercraft.GuiScreenEditProfile;
|
||||
import net.lax1dude.eaglercraft.GuiScreenSingleplayerConnecting;
|
||||
import net.lax1dude.eaglercraft.GuiScreenSingleplayerLoading;
|
||||
import net.lax1dude.eaglercraft.GuiScreenVoiceChannel;
|
||||
import net.lax1dude.eaglercraft.IntegratedServer;
|
||||
import net.lax1dude.eaglercraft.adapter.Tessellator;
|
||||
import net.lax1dude.eaglercraft.glemu.EffectPipeline;
|
||||
import net.lax1dude.eaglercraft.glemu.FixedFunctionShader;
|
||||
@ -487,6 +490,15 @@ public class Minecraft implements Runnable {
|
||||
: (var0.contains("mac") ? EnumOS.MACOS
|
||||
: (var0.contains("solaris") ? EnumOS.SOLARIS : (var0.contains("sunos") ? EnumOS.SOLARIS : (var0.contains("linux") ? EnumOS.LINUX : (var0.contains("unix") ? EnumOS.LINUX : EnumOS.UNKNOWN)))));
|
||||
}
|
||||
|
||||
public void stopServerAndDisplayGuiScreen(GuiScreen par1GuiScreen) {
|
||||
if(IntegratedServer.isWorldRunning()) {
|
||||
IntegratedServer.unloadWorld();
|
||||
displayGuiScreen(new GuiScreenSingleplayerLoading(par1GuiScreen, "saving world", () -> !IntegratedServer.isWorldRunning()));
|
||||
}else {
|
||||
displayGuiScreen(par1GuiScreen);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the argument GuiScreen as the main (topmost visible) screen.
|
||||
@ -592,7 +604,7 @@ public class Minecraft implements Runnable {
|
||||
this.runGameLoop();
|
||||
} catch (OutOfMemoryError var10) {
|
||||
this.freeMemory();
|
||||
this.displayGuiScreen(new GuiMemoryErrorScreen());
|
||||
this.stopServerAndDisplayGuiScreen(new GuiMemoryErrorScreen());
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
@ -636,6 +648,8 @@ public class Minecraft implements Runnable {
|
||||
for (int var3 = 0; var3 < this.timer.elapsedTicks; ++var3) {
|
||||
this.runTick();
|
||||
}
|
||||
|
||||
IntegratedServer.processICP();
|
||||
|
||||
this.mcProfiler.endStartSection("preRenderErrors");
|
||||
long var7 = System.nanoTime() - var6;
|
||||
@ -712,8 +726,8 @@ public class Minecraft implements Runnable {
|
||||
|
||||
this.checkGLError("Post render");
|
||||
++this.fpsCounter;
|
||||
boolean var5 = this.isGamePaused;
|
||||
this.isGamePaused = false;
|
||||
//boolean var5 = this.isGamePaused;
|
||||
//this.isGamePaused = false;
|
||||
|
||||
if(System.currentTimeMillis() - secondTimer > 1000l) {
|
||||
debugFPS = fpsCounter;
|
||||
@ -955,6 +969,9 @@ public class Minecraft implements Runnable {
|
||||
public void displayInGameMenu() {
|
||||
if (this.currentScreen == null) {
|
||||
this.displayGuiScreen(new GuiIngameMenu());
|
||||
if(IntegratedServer.isWorldRunning() && !this.isSingleplayer()) {
|
||||
IntegratedServer.autoSave();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1074,6 +1091,8 @@ public class Minecraft implements Runnable {
|
||||
this.currentScreen.setWorldAndResolution(this, var4, var5);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean wasPaused = false;
|
||||
|
||||
/**
|
||||
* Runs the current tick.
|
||||
@ -1087,7 +1106,14 @@ public class Minecraft implements Runnable {
|
||||
|
||||
this.mcProfiler.startSection("stats");
|
||||
this.mcProfiler.endStartSection("gui");
|
||||
|
||||
|
||||
this.isGamePaused = this.isSingleplayer() && this.theWorld != null && this.thePlayer != null && this.currentScreen != null && this.currentScreen.doesGuiPauseGame();
|
||||
|
||||
if(wasPaused != isGamePaused) {
|
||||
IntegratedServer.setPaused(this.isGamePaused);
|
||||
wasPaused = isGamePaused;
|
||||
}
|
||||
|
||||
if (!this.isGamePaused) {
|
||||
this.ingameGUI.updateTick();
|
||||
}
|
||||
@ -1460,10 +1486,12 @@ public class Minecraft implements Runnable {
|
||||
if (this.myNetworkManager != null) {
|
||||
this.myNetworkManager.closeConnections();
|
||||
}
|
||||
|
||||
this.myNetworkManager = null;
|
||||
|
||||
}
|
||||
|
||||
this.renderViewEntity = null;
|
||||
this.myNetworkManager = null;
|
||||
|
||||
if (this.loadingScreen != null) {
|
||||
this.loadingScreen.resetProgressAndMessage(par2Str);
|
||||
@ -1520,6 +1548,10 @@ public class Minecraft implements Runnable {
|
||||
this.systemTime = 0L;
|
||||
}
|
||||
|
||||
public void setNetManager(INetworkManager nm) {
|
||||
this.myNetworkManager = nm;
|
||||
}
|
||||
|
||||
/*
|
||||
public void installResource(String par1Str, File par2File) {
|
||||
int var3 = par1Str.indexOf("/");
|
||||
@ -1752,7 +1784,7 @@ public class Minecraft implements Runnable {
|
||||
}
|
||||
|
||||
public boolean isIntegratedServerRunning() {
|
||||
return this.integratedServerIsRunning;
|
||||
return IntegratedServer.isWorldRunning();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1760,7 +1792,7 @@ public class Minecraft implements Runnable {
|
||||
* the integrated one.
|
||||
*/
|
||||
public boolean isSingleplayer() {
|
||||
return false;
|
||||
return isIntegratedServerRunning();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1780,4 +1812,12 @@ public class Minecraft implements Runnable {
|
||||
public static int getGLMaximumTextureSize() {
|
||||
return 8192;
|
||||
}
|
||||
|
||||
public void launchIntegratedServer(String folderName, String trim, WorldSettings var6) {
|
||||
this.loadWorld((WorldClient)null);
|
||||
|
||||
IntegratedServer.loadWorld(folderName, gameSettings.difficulty, var6);
|
||||
|
||||
this.displayGuiScreen(new GuiScreenSingleplayerLoading(new GuiScreenSingleplayerConnecting(new GuiMainMenu(), "Connecting to " + folderName), "Loading world: " + folderName, () -> IntegratedServer.isWorldRunning()));
|
||||
}
|
||||
}
|
||||
|
@ -3,16 +3,19 @@ package net.minecraft.src;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class EntityList {
|
||||
/** Provides a mapping between entity classes and a string */
|
||||
private static Map stringToClassMapping = new HashMap();
|
||||
private static Map stringToClassReflectMapping = new HashMap();
|
||||
|
||||
/** Provides a mapping between a string and an entity classes */
|
||||
private static Map classToStringMapping = new HashMap();
|
||||
|
||||
/** provides a mapping between an entityID and an Entity Class */
|
||||
private static Map IDtoClassMapping = new HashMap();
|
||||
private static Map IDtoClassReflectMapping = new HashMap();
|
||||
|
||||
/** provides a mapping between an Entity Class and an entity ID */
|
||||
private static Map classToIDMapping = new HashMap();
|
||||
@ -27,10 +30,12 @@ public class EntityList {
|
||||
* adds a mapping between Entity classes and both a string representation and an
|
||||
* ID
|
||||
*/
|
||||
private static void addMapping(Class par0Class, String par1Str, int par2) {
|
||||
stringToClassMapping.put(par1Str, par0Class);
|
||||
private static void addMapping(Class par0Class, Supplier<Entity> constructor, String par1Str, int par2) {
|
||||
stringToClassMapping.put(par1Str, constructor);
|
||||
stringToClassReflectMapping.put(par1Str, par0Class);
|
||||
classToStringMapping.put(par0Class, par1Str);
|
||||
IDtoClassMapping.put(Integer.valueOf(par2), par0Class);
|
||||
IDtoClassMapping.put(Integer.valueOf(par2), constructor);
|
||||
IDtoClassReflectMapping.put(Integer.valueOf(par2), par0Class);
|
||||
classToIDMapping.put(par0Class, Integer.valueOf(par2));
|
||||
stringToIDMapping.put(par1Str, Integer.valueOf(par2));
|
||||
}
|
||||
@ -38,8 +43,8 @@ public class EntityList {
|
||||
/**
|
||||
* Adds a entity mapping with egg info.
|
||||
*/
|
||||
private static void addMapping(Class par0Class, String par1Str, int par2, int par3, int par4) {
|
||||
addMapping(par0Class, par1Str, par2);
|
||||
private static void addMapping(Class par0Class, Supplier<Entity> constructor, String par1Str, int par2, int par3, int par4) {
|
||||
addMapping(par0Class, constructor, par1Str, par2);
|
||||
entityEggs.put(Integer.valueOf(par2), new EntityEggInfo(par2, par3, par4));
|
||||
}
|
||||
|
||||
@ -48,18 +53,18 @@ public class EntityList {
|
||||
*/
|
||||
public static Entity createEntityByName(String par0Str, World par1World) {
|
||||
Entity var2 = null;
|
||||
Class var3 = (Class) stringToClassMapping.get(par0Str);
|
||||
|
||||
if (var3 != null) {
|
||||
try {
|
||||
var2 = (Entity) var3.getConstructor(new Class[] { World.class }).newInstance(new Object[] { par1World });
|
||||
} catch (Exception var4) {
|
||||
try {
|
||||
var2 = (Entity) var3.getConstructor(new Class[0]).newInstance(new Object[0]);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
Supplier<Entity> var3 = (Supplier<Entity>) stringToClassMapping.get(par0Str);
|
||||
|
||||
if (var3 != null) {
|
||||
var2 = var3.get();
|
||||
if(par1World != null) {
|
||||
var2.setWorld(par1World);
|
||||
}
|
||||
}
|
||||
} catch (Exception var4) {
|
||||
var4.printStackTrace();
|
||||
}
|
||||
|
||||
return var2;
|
||||
@ -89,10 +94,13 @@ public class EntityList {
|
||||
}
|
||||
|
||||
try {
|
||||
Class var3 = (Class) stringToClassMapping.get(par0NBTTagCompound.getString("id"));
|
||||
Supplier<Entity> var3 = (Supplier<Entity>) stringToClassMapping.get(par0NBTTagCompound.getString("id"));
|
||||
|
||||
if (var3 != null) {
|
||||
var2 = (Entity) var3.getConstructor(new Class[] { World.class }).newInstance(new Object[] { par1World });
|
||||
var2 = var3.get();
|
||||
if(par1World != null) {
|
||||
var2.setWorld(par1World);
|
||||
}
|
||||
}
|
||||
} catch (Exception var4) {
|
||||
var4.printStackTrace();
|
||||
@ -114,10 +122,13 @@ public class EntityList {
|
||||
Entity var2 = null;
|
||||
|
||||
try {
|
||||
Class var3 = getClassFromID(par0);
|
||||
Supplier<Entity> var3 = (Supplier<Entity>) IDtoClassMapping.get(par0);
|
||||
|
||||
if (var3 != null) {
|
||||
var2 = (Entity) var3.newInstance();
|
||||
var2 = var3.get();
|
||||
if(par1World != null) {
|
||||
var2.setWorld(par1World);
|
||||
}
|
||||
}
|
||||
} catch (Exception var4) {
|
||||
var4.printStackTrace();
|
||||
@ -125,8 +136,6 @@ public class EntityList {
|
||||
|
||||
if (var2 == null) {
|
||||
System.err.println("Skipping Entity with id " + par0);
|
||||
}else {
|
||||
var2.setWorld(par1World);
|
||||
}
|
||||
|
||||
return var2;
|
||||
@ -144,7 +153,7 @@ public class EntityList {
|
||||
* Return the class assigned to this entity ID.
|
||||
*/
|
||||
public static Class getClassFromID(int par0) {
|
||||
return (Class) IDtoClassMapping.get(Integer.valueOf(par0));
|
||||
return (Class) IDtoClassReflectMapping.get(Integer.valueOf(par0));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,58 +172,58 @@ public class EntityList {
|
||||
}
|
||||
|
||||
static {
|
||||
addMapping(EntityItem.class, "Item", 1);
|
||||
addMapping(EntityXPOrb.class, "XPOrb", 2);
|
||||
addMapping(EntityPainting.class, "Painting", 9);
|
||||
addMapping(EntityArrow.class, "Arrow", 10);
|
||||
addMapping(EntitySnowball.class, "Snowball", 11);
|
||||
addMapping(EntityLargeFireball.class, "Fireball", 12);
|
||||
addMapping(EntitySmallFireball.class, "SmallFireball", 13);
|
||||
addMapping(EntityEnderPearl.class, "ThrownEnderpearl", 14);
|
||||
addMapping(EntityEnderEye.class, "EyeOfEnderSignal", 15);
|
||||
addMapping(EntityPotion.class, "ThrownPotion", 16);
|
||||
addMapping(EntityExpBottle.class, "ThrownExpBottle", 17);
|
||||
addMapping(EntityItemFrame.class, "ItemFrame", 18);
|
||||
addMapping(EntityWitherSkull.class, "WitherSkull", 19);
|
||||
addMapping(EntityTNTPrimed.class, "PrimedTnt", 20);
|
||||
addMapping(EntityFallingSand.class, "FallingSand", 21);
|
||||
addMapping(EntityFireworkRocket.class, "FireworksRocketEntity", 22);
|
||||
addMapping(EntityBoat.class, "Boat", 41);
|
||||
addMapping(EntityMinecartEmpty.class, "MinecartRideable", 42);
|
||||
addMapping(EntityMinecartChest.class, "MinecartChest", 43);
|
||||
addMapping(EntityMinecartFurnace.class, "MinecartFurnace", 44);
|
||||
addMapping(EntityMinecartTNT.class, "MinecartTNT", 45);
|
||||
addMapping(EntityMinecartHopper.class, "MinecartHopper", 46);
|
||||
addMapping(EntityMinecartMobSpawner.class, "MinecartSpawner", 47);
|
||||
addMapping(EntityLiving.class, "Mob", 48);
|
||||
addMapping(EntityMob.class, "Monster", 49);
|
||||
addMapping(EntityCreeper.class, "Creeper", 50, 894731, 0);
|
||||
addMapping(EntitySkeleton.class, "Skeleton", 51, 12698049, 4802889);
|
||||
addMapping(EntitySpider.class, "Spider", 52, 3419431, 11013646);
|
||||
addMapping(EntityZombie.class, "Zombie", 54, 44975, 7969893);
|
||||
addMapping(EntitySlime.class, "Slime", 55, 5349438, 8306542);
|
||||
addMapping(EntityGhast.class, "Ghast", 56, 16382457, 12369084);
|
||||
addMapping(EntityPigZombie.class, "PigZombie", 57, 15373203, 5009705);
|
||||
addMapping(EntityEnderman.class, "Enderman", 58, 1447446, 0);
|
||||
addMapping(EntityCaveSpider.class, "CaveSpider", 59, 803406, 11013646);
|
||||
addMapping(EntitySilverfish.class, "Silverfish", 60, 7237230, 3158064);
|
||||
addMapping(EntityBlaze.class, "Blaze", 61, 16167425, 16775294);
|
||||
addMapping(EntityMagmaCube.class, "LavaSlime", 62, 3407872, 16579584);
|
||||
addMapping(EntityDragon.class, "EnderDragon", 63);
|
||||
addMapping(EntityWither.class, "WitherBoss", 64);
|
||||
addMapping(EntityBat.class, "Bat", 65, 4996656, 986895);
|
||||
addMapping(EntityWitch.class, "Witch", 66, 3407872, 5349438);
|
||||
addMapping(EntityPig.class, "Pig", 90, 15771042, 14377823);
|
||||
addMapping(EntitySheep.class, "Sheep", 91, 15198183, 16758197);
|
||||
addMapping(EntityCow.class, "Cow", 92, 4470310, 10592673);
|
||||
addMapping(EntityChicken.class, "Chicken", 93, 10592673, 16711680);
|
||||
addMapping(EntitySquid.class, "Squid", 94, 2243405, 7375001);
|
||||
addMapping(EntityWolf.class, "Wolf", 95, 14144467, 13545366);
|
||||
addMapping(EntityMooshroom.class, "MushroomCow", 96, 10489616, 12040119);
|
||||
addMapping(EntitySnowman.class, "SnowMan", 97);
|
||||
addMapping(EntityOcelot.class, "Ozelot", 98, 15720061, 5653556);
|
||||
addMapping(EntityIronGolem.class, "VillagerGolem", 99);
|
||||
addMapping(EntityVillager.class, "Villager", 120, 5651507, 12422002);
|
||||
addMapping(EntityEnderCrystal.class, "EnderCrystal", 200);
|
||||
addMapping(EntityItem.class, () -> new EntityItem(), "Item", 1);
|
||||
addMapping(EntityXPOrb.class, () -> new EntityXPOrb(), "XPOrb", 2);
|
||||
addMapping(EntityPainting.class, () -> new EntityPainting(), "Painting", 9);
|
||||
addMapping(EntityArrow.class, () -> new EntityArrow(), "Arrow", 10);
|
||||
addMapping(EntitySnowball.class, () -> new EntitySnowball(), "Snowball", 11);
|
||||
addMapping(EntityLargeFireball.class, () -> new EntityLargeFireball(), "Fireball", 12);
|
||||
addMapping(EntitySmallFireball.class, () -> new EntitySmallFireball(), "SmallFireball", 13);
|
||||
addMapping(EntityEnderPearl.class, () -> new EntityEnderPearl(), "ThrownEnderpearl", 14);
|
||||
addMapping(EntityEnderEye.class, () -> new EntityEnderEye(), "EyeOfEnderSignal", 15);
|
||||
addMapping(EntityPotion.class, () -> new EntityPotion(), "ThrownPotion", 16);
|
||||
addMapping(EntityExpBottle.class, () -> new EntityExpBottle(), "ThrownExpBottle", 17);
|
||||
addMapping(EntityItemFrame.class, () -> new EntityItemFrame(), "ItemFrame", 18);
|
||||
addMapping(EntityWitherSkull.class, () -> new EntityWitherSkull(), "WitherSkull", 19);
|
||||
addMapping(EntityTNTPrimed.class, () -> new EntityTNTPrimed(), "PrimedTnt", 20);
|
||||
addMapping(EntityFallingSand.class, () -> new EntityFallingSand(), "FallingSand", 21);
|
||||
addMapping(EntityFireworkRocket.class, () -> new EntityFireworkRocket(), "FireworksRocketEntity", 22);
|
||||
addMapping(EntityBoat.class, () -> new EntityBoat(), "Boat", 41);
|
||||
addMapping(EntityMinecartEmpty.class, () -> new EntityMinecartEmpty(), "MinecartRideable", 42);
|
||||
addMapping(EntityMinecartChest.class, () -> new EntityMinecartChest(), "MinecartChest", 43);
|
||||
addMapping(EntityMinecartFurnace.class, () -> new EntityMinecartFurnace(), "MinecartFurnace", 44);
|
||||
addMapping(EntityMinecartTNT.class, () -> new EntityMinecartTNT(), "MinecartTNT", 45);
|
||||
addMapping(EntityMinecartHopper.class, () -> new EntityMinecartHopper(), "MinecartHopper", 46);
|
||||
addMapping(EntityMinecartMobSpawner.class, () -> new EntityMinecartMobSpawner(), "MinecartSpawner", 47);
|
||||
addMapping(EntityLiving.class, null, "Mob", 48);
|
||||
addMapping(EntityMob.class, null, "Monster", 49);
|
||||
addMapping(EntityCreeper.class, () -> new EntityCreeper(), "Creeper", 50, 894731, 0);
|
||||
addMapping(EntitySkeleton.class, () -> new EntitySkeleton(), "Skeleton", 51, 12698049, 4802889);
|
||||
addMapping(EntitySpider.class, () -> new EntitySpider(), "Spider", 52, 3419431, 11013646);
|
||||
addMapping(EntityZombie.class, () -> new EntityZombie(), "Zombie", 54, 44975, 7969893);
|
||||
addMapping(EntitySlime.class, () -> new EntitySlime(), "Slime", 55, 5349438, 8306542);
|
||||
addMapping(EntityGhast.class, () -> new EntityGhast(), "Ghast", 56, 16382457, 12369084);
|
||||
addMapping(EntityPigZombie.class, () -> new EntityPigZombie(), "PigZombie", 57, 15373203, 5009705);
|
||||
addMapping(EntityEnderman.class, () -> new EntityEnderman(), "Enderman", 58, 1447446, 0);
|
||||
addMapping(EntityCaveSpider.class, () -> new EntityCaveSpider(), "CaveSpider", 59, 803406, 11013646);
|
||||
addMapping(EntitySilverfish.class, () -> new EntitySilverfish(), "Silverfish", 60, 7237230, 3158064);
|
||||
addMapping(EntityBlaze.class, () -> new EntityBlaze(), "Blaze", 61, 16167425, 16775294);
|
||||
addMapping(EntityMagmaCube.class, () -> new EntityMagmaCube(), "LavaSlime", 62, 3407872, 16579584);
|
||||
addMapping(EntityDragon.class, () -> new EntityDragon(), "EnderDragon", 63);
|
||||
addMapping(EntityWither.class, () -> new EntityWither(), "WitherBoss", 64);
|
||||
addMapping(EntityBat.class, () -> new EntityBat(), "Bat", 65, 4996656, 986895);
|
||||
addMapping(EntityWitch.class, () -> new EntityWitch(), "Witch", 66, 3407872, 5349438);
|
||||
addMapping(EntityPig.class, () -> new EntityPig(), "Pig", 90, 15771042, 14377823);
|
||||
addMapping(EntitySheep.class, () -> new EntitySheep(), "Sheep", 91, 15198183, 16758197);
|
||||
addMapping(EntityCow.class, () -> new EntityCow(), "Cow", 92, 4470310, 10592673);
|
||||
addMapping(EntityChicken.class, () -> new EntityChicken(), "Chicken", 93, 10592673, 16711680);
|
||||
addMapping(EntitySquid.class, () -> new EntitySquid(), "Squid", 94, 2243405, 7375001);
|
||||
addMapping(EntityWolf.class, () -> new EntityWolf(), "Wolf", 95, 14144467, 13545366);
|
||||
addMapping(EntityMooshroom.class, () -> new EntityMooshroom(), "MushroomCow", 96, 10489616, 12040119);
|
||||
addMapping(EntitySnowman.class, () -> new EntitySnowman(), "SnowMan", 97);
|
||||
addMapping(EntityOcelot.class, () -> new EntityOcelot(), "Ozelot", 98, 15720061, 5653556);
|
||||
addMapping(EntityIronGolem.class, () -> new EntityIronGolem(), "VillagerGolem", 99);
|
||||
addMapping(EntityVillager.class, () -> new EntityVillager(), "Villager", 120, 5651507, 12422002);
|
||||
addMapping(EntityEnderCrystal.class, () -> new EntityEnderCrystal(), "EnderCrystal", 200);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,9 @@ public class EntityMinecartChest extends EntityMinecartContainer {
|
||||
super(par1, par2, par4, par6);
|
||||
}
|
||||
|
||||
public EntityMinecartChest() {
|
||||
}
|
||||
|
||||
public void killMinecart(DamageSource par1DamageSource) {
|
||||
super.killMinecart(par1DamageSource);
|
||||
this.dropItemWithOffset(Block.chest.blockID, 1, 0.0F);
|
||||
|
@ -6,6 +6,9 @@ public class EntityMinecartEmpty extends EntityMinecart {
|
||||
super(par1, par2, par4, par6);
|
||||
}
|
||||
|
||||
public EntityMinecartEmpty() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player interacts with a mob. e.g. gets milk from a cow, gets
|
||||
* into the saddle on a pig.
|
||||
|
@ -9,6 +9,9 @@ public class EntityMinecartFurnace extends EntityMinecart {
|
||||
super(par1World, par2, par4, par6);
|
||||
}
|
||||
|
||||
public EntityMinecartFurnace() {
|
||||
}
|
||||
|
||||
public int getMinecartType() {
|
||||
return 2;
|
||||
}
|
||||
|
@ -11,6 +11,9 @@ public class EntityMinecartHopper extends EntityMinecartContainer implements Hop
|
||||
super(par1World, par2, par4, par6);
|
||||
}
|
||||
|
||||
public EntityMinecartHopper() {
|
||||
}
|
||||
|
||||
public int getMinecartType() {
|
||||
return 5;
|
||||
}
|
||||
|
@ -7,6 +7,9 @@ public class EntityMinecartMobSpawner extends EntityMinecart {
|
||||
super(par1World, par2, par4, par6);
|
||||
}
|
||||
|
||||
public EntityMinecartMobSpawner() {
|
||||
}
|
||||
|
||||
public int getMinecartType() {
|
||||
return 4;
|
||||
}
|
||||
|
@ -9,6 +9,9 @@ public class EntityMinecartTNT extends EntityMinecart {
|
||||
super(par1, par2, par4, par6);
|
||||
}
|
||||
|
||||
public EntityMinecartTNT() {
|
||||
}
|
||||
|
||||
public int getMinecartType() {
|
||||
return 3;
|
||||
}
|
||||
|
@ -45,6 +45,9 @@ public class EntityPainting extends EntityHanging {
|
||||
this.setDirection(par5);
|
||||
}
|
||||
|
||||
public EntityPainting() {
|
||||
}
|
||||
|
||||
/**
|
||||
* (abstract) Protected helper method to write subclass entity data to NBT.
|
||||
*/
|
||||
|
@ -1,5 +1,7 @@
|
||||
package net.minecraft.src;
|
||||
|
||||
import net.lax1dude.eaglercraft.NoCatchParse;
|
||||
|
||||
class GameRuleValue {
|
||||
private String valueString;
|
||||
private boolean valueBoolean;
|
||||
@ -16,17 +18,17 @@ class GameRuleValue {
|
||||
public void setValue(String par1Str) {
|
||||
this.valueString = par1Str;
|
||||
this.valueBoolean = Boolean.parseBoolean(par1Str);
|
||||
|
||||
try {
|
||||
this.valueInteger = Integer.parseInt(par1Str);
|
||||
} catch (NumberFormatException var4) {
|
||||
;
|
||||
|
||||
this.valueInteger = NoCatchParse.parseInt(par1Str);
|
||||
|
||||
if(this.valueInteger == NoCatchParse.INT_EXCEPTION) {
|
||||
this.valueInteger = 0;
|
||||
}
|
||||
|
||||
try {
|
||||
this.valueDouble = Double.parseDouble(par1Str);
|
||||
} catch (NumberFormatException var3) {
|
||||
;
|
||||
|
||||
this.valueDouble = NoCatchParse.parseDouble(par1Str);
|
||||
|
||||
if(this.valueDouble == NoCatchParse.DOUBLE_EXCEPTION) {
|
||||
this.valueDouble = 0.0d;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,8 +110,8 @@ public class GuiConnecting extends GuiScreen {
|
||||
if (this.clientHandler != null) {
|
||||
this.clientHandler.disconnect();
|
||||
}
|
||||
|
||||
this.mc.displayGuiScreen(this.field_98098_c);
|
||||
|
||||
this.mc.stopServerAndDisplayGuiScreen(this.field_98098_c);
|
||||
}
|
||||
}
|
||||
|
||||
@ -132,6 +132,10 @@ public class GuiConnecting extends GuiScreen {
|
||||
|
||||
super.drawScreen(par1, par2, par3);
|
||||
}
|
||||
|
||||
public boolean doesGuiPauseGame() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the NetClientHandler.
|
||||
|
112
src/main/java/net/minecraft/src/GuiCreateFlatWorld.java
Normal file
112
src/main/java/net/minecraft/src/GuiCreateFlatWorld.java
Normal file
@ -0,0 +1,112 @@
|
||||
package net.minecraft.src;
|
||||
|
||||
public class GuiCreateFlatWorld extends GuiScreen {
|
||||
private static RenderItem theRenderItem = new RenderItem();
|
||||
private final GuiCreateWorld createWorldGui;
|
||||
private FlatGeneratorInfo theFlatGeneratorInfo = FlatGeneratorInfo.getDefaultFlatGenerator();
|
||||
private String customizationTitle;
|
||||
private String layerMaterialLabel;
|
||||
private String heightLabel;
|
||||
private GuiCreateFlatWorldListSlot createFlatWorldListSlotGui;
|
||||
private GuiButton buttonAddLayer;
|
||||
private GuiButton buttonEditLayer;
|
||||
private GuiButton buttonRemoveLayer;
|
||||
|
||||
public GuiCreateFlatWorld(GuiCreateWorld par1GuiCreateWorld, String par2Str) {
|
||||
this.createWorldGui = par1GuiCreateWorld;
|
||||
this.setFlatGeneratorInfo(par2Str);
|
||||
}
|
||||
|
||||
public String getFlatGeneratorInfo() {
|
||||
return this.theFlatGeneratorInfo.toString();
|
||||
}
|
||||
|
||||
public void setFlatGeneratorInfo(String par1Str) {
|
||||
this.theFlatGeneratorInfo = FlatGeneratorInfo.createFlatGeneratorFromString(par1Str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the buttons (and other controls) to the screen in question.
|
||||
*/
|
||||
public void initGui() {
|
||||
this.buttonList.clear();
|
||||
this.customizationTitle = StatCollector.translateToLocal("createWorld.customize.flat.title");
|
||||
this.layerMaterialLabel = StatCollector.translateToLocal("createWorld.customize.flat.tile");
|
||||
this.heightLabel = StatCollector.translateToLocal("createWorld.customize.flat.height");
|
||||
this.createFlatWorldListSlotGui = new GuiCreateFlatWorldListSlot(this);
|
||||
this.buttonList.add(this.buttonAddLayer = new GuiButton(2, this.width / 2 - 154, this.height - 52, 100, 20,
|
||||
StatCollector.translateToLocal("createWorld.customize.flat.addLayer") + " (NYI)"));
|
||||
this.buttonList.add(this.buttonEditLayer = new GuiButton(3, this.width / 2 - 50, this.height - 52, 100, 20,
|
||||
StatCollector.translateToLocal("createWorld.customize.flat.editLayer") + " (NYI)"));
|
||||
this.buttonList.add(this.buttonRemoveLayer = new GuiButton(4, this.width / 2 - 155, this.height - 52, 150, 20,
|
||||
StatCollector.translateToLocal("createWorld.customize.flat.removeLayer")));
|
||||
this.buttonList.add(new GuiButton(0, this.width / 2 - 155, this.height - 28, 150, 20,
|
||||
StatCollector.translateToLocal("gui.done")));
|
||||
this.buttonList.add(new GuiButton(5, this.width / 2 + 5, this.height - 52, 150, 20,
|
||||
StatCollector.translateToLocal("createWorld.customize.presets")));
|
||||
this.buttonList.add(new GuiButton(1, this.width / 2 + 5, this.height - 28, 150, 20,
|
||||
StatCollector.translateToLocal("gui.cancel")));
|
||||
this.buttonAddLayer.drawButton = this.buttonEditLayer.drawButton = false;
|
||||
this.theFlatGeneratorInfo.func_82645_d();
|
||||
this.func_82270_g();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a control is clicked. This is the equivalent of
|
||||
* ActionListener.actionPerformed(ActionEvent e).
|
||||
*/
|
||||
protected void actionPerformed(GuiButton par1GuiButton) {
|
||||
int var2 = this.theFlatGeneratorInfo.getFlatLayers().size() - this.createFlatWorldListSlotGui.field_82454_a - 1;
|
||||
|
||||
if (par1GuiButton.id == 1) {
|
||||
this.mc.displayGuiScreen(this.createWorldGui);
|
||||
} else if (par1GuiButton.id == 0) {
|
||||
this.createWorldGui.generatorOptionsToUse = this.getFlatGeneratorInfo();
|
||||
this.mc.displayGuiScreen(this.createWorldGui);
|
||||
} else if (par1GuiButton.id == 5) {
|
||||
this.mc.displayGuiScreen(new GuiFlatPresets(this));
|
||||
} else if (par1GuiButton.id == 4 && this.func_82272_i()) {
|
||||
this.theFlatGeneratorInfo.getFlatLayers().remove(var2);
|
||||
this.createFlatWorldListSlotGui.field_82454_a = Math.min(this.createFlatWorldListSlotGui.field_82454_a,
|
||||
this.theFlatGeneratorInfo.getFlatLayers().size() - 1);
|
||||
}
|
||||
|
||||
this.theFlatGeneratorInfo.func_82645_d();
|
||||
this.func_82270_g();
|
||||
}
|
||||
|
||||
public void func_82270_g() {
|
||||
boolean var1 = this.func_82272_i();
|
||||
this.buttonRemoveLayer.enabled = var1;
|
||||
this.buttonEditLayer.enabled = var1;
|
||||
this.buttonEditLayer.enabled = false;
|
||||
this.buttonAddLayer.enabled = false;
|
||||
}
|
||||
|
||||
private boolean func_82272_i() {
|
||||
return this.createFlatWorldListSlotGui.field_82454_a > -1
|
||||
&& this.createFlatWorldListSlotGui.field_82454_a < this.theFlatGeneratorInfo.getFlatLayers().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the screen and all the components in it.
|
||||
*/
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
this.drawDefaultBackground();
|
||||
this.createFlatWorldListSlotGui.drawScreen(par1, par2, par3);
|
||||
this.drawCenteredString(this.fontRenderer, this.customizationTitle, this.width / 2, 8, 16777215);
|
||||
int var4 = this.width / 2 - 92 - 16;
|
||||
this.drawString(this.fontRenderer, this.layerMaterialLabel, var4, 32, 16777215);
|
||||
this.drawString(this.fontRenderer, this.heightLabel,
|
||||
var4 + 2 + 213 - this.fontRenderer.getStringWidth(this.heightLabel), 32, 16777215);
|
||||
super.drawScreen(par1, par2, par3);
|
||||
}
|
||||
|
||||
static RenderItem getRenderItem() {
|
||||
return theRenderItem;
|
||||
}
|
||||
|
||||
static FlatGeneratorInfo func_82271_a(GuiCreateFlatWorld par0GuiCreateFlatWorld) {
|
||||
return par0GuiCreateFlatWorld.theFlatGeneratorInfo;
|
||||
}
|
||||
}
|
106
src/main/java/net/minecraft/src/GuiCreateFlatWorldListSlot.java
Normal file
106
src/main/java/net/minecraft/src/GuiCreateFlatWorldListSlot.java
Normal file
@ -0,0 +1,106 @@
|
||||
package net.minecraft.src;
|
||||
|
||||
import net.lax1dude.eaglercraft.EaglerAdapter;
|
||||
import net.lax1dude.eaglercraft.adapter.Tessellator;
|
||||
|
||||
class GuiCreateFlatWorldListSlot extends GuiSlot {
|
||||
public int field_82454_a;
|
||||
|
||||
final GuiCreateFlatWorld createFlatWorldGui;
|
||||
|
||||
public GuiCreateFlatWorldListSlot(GuiCreateFlatWorld par1GuiCreateFlatWorld) {
|
||||
super(par1GuiCreateFlatWorld.mc, par1GuiCreateFlatWorld.width, par1GuiCreateFlatWorld.height, 43,
|
||||
par1GuiCreateFlatWorld.height - 60, 24);
|
||||
this.createFlatWorldGui = par1GuiCreateFlatWorld;
|
||||
this.field_82454_a = -1;
|
||||
}
|
||||
|
||||
private void func_82452_a(int par1, int par2, ItemStack par3ItemStack) {
|
||||
this.func_82451_d(par1 + 1, par2 + 1);
|
||||
EaglerAdapter.glEnable(EaglerAdapter.GL_RESCALE_NORMAL);
|
||||
|
||||
if (par3ItemStack != null) {
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
GuiCreateFlatWorld.getRenderItem().renderItemIntoGUI(this.createFlatWorldGui.fontRenderer,
|
||||
this.createFlatWorldGui.mc.renderEngine, par3ItemStack, par1 + 2, par2 + 2);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
}
|
||||
|
||||
EaglerAdapter.glDisable(EaglerAdapter.GL_RESCALE_NORMAL);
|
||||
}
|
||||
|
||||
private void func_82451_d(int par1, int par2) {
|
||||
this.func_82450_b(par1, par2, 0, 0);
|
||||
}
|
||||
|
||||
private void func_82450_b(int par1, int par2, int par3, int par4) {
|
||||
EaglerAdapter.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.createFlatWorldGui.mc.renderEngine.bindTexture("/gui/slot.png");
|
||||
Tessellator var9 = Tessellator.instance;
|
||||
var9.startDrawingQuads();
|
||||
var9.addVertexWithUV((double) (par1 + 0), (double) (par2 + 18), (double) this.createFlatWorldGui.zLevel,
|
||||
(double) ((float) (par3 + 0) * 0.0078125F), (double) ((float) (par4 + 18) * 0.0078125F));
|
||||
var9.addVertexWithUV((double) (par1 + 18), (double) (par2 + 18), (double) this.createFlatWorldGui.zLevel,
|
||||
(double) ((float) (par3 + 18) * 0.0078125F), (double) ((float) (par4 + 18) * 0.0078125F));
|
||||
var9.addVertexWithUV((double) (par1 + 18), (double) (par2 + 0), (double) this.createFlatWorldGui.zLevel,
|
||||
(double) ((float) (par3 + 18) * 0.0078125F), (double) ((float) (par4 + 0) * 0.0078125F));
|
||||
var9.addVertexWithUV((double) (par1 + 0), (double) (par2 + 0), (double) this.createFlatWorldGui.zLevel,
|
||||
(double) ((float) (par3 + 0) * 0.0078125F), (double) ((float) (par4 + 0) * 0.0078125F));
|
||||
var9.draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size of the current slot list.
|
||||
*/
|
||||
protected int getSize() {
|
||||
return GuiCreateFlatWorld.func_82271_a(this.createFlatWorldGui).getFlatLayers().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* the element in the slot that was clicked, boolean for wether it was double
|
||||
* clicked or not
|
||||
*/
|
||||
protected void elementClicked(int par1, boolean par2) {
|
||||
this.field_82454_a = par1;
|
||||
this.createFlatWorldGui.func_82270_g();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns true if the element passed in is currently selected
|
||||
*/
|
||||
protected boolean isSelected(int par1) {
|
||||
return par1 == this.field_82454_a;
|
||||
}
|
||||
|
||||
protected void drawBackground() {
|
||||
}
|
||||
|
||||
protected void drawSlot(int par1, int par2, int par3, int par4, Tessellator par5Tessellator) {
|
||||
FlatLayerInfo var6 = (FlatLayerInfo) GuiCreateFlatWorld.func_82271_a(this.createFlatWorldGui).getFlatLayers()
|
||||
.get(GuiCreateFlatWorld.func_82271_a(this.createFlatWorldGui).getFlatLayers().size() - par1 - 1);
|
||||
ItemStack var7 = var6.getFillBlock() == 0 ? null
|
||||
: new ItemStack(var6.getFillBlock(), 1, var6.getFillBlockMeta());
|
||||
String var8 = var7 == null ? "Air" : Item.itemsList[var6.getFillBlock()].func_77653_i(var7);
|
||||
this.func_82452_a(par2, par3, var7);
|
||||
this.createFlatWorldGui.fontRenderer.drawString(var8, par2 + 18 + 5, par3 + 3, 16777215);
|
||||
String var9;
|
||||
|
||||
if (par1 == 0) {
|
||||
var9 = StatCollector.translateToLocalFormatted("createWorld.customize.flat.layer.top",
|
||||
new Object[] { Integer.valueOf(var6.getLayerCount()) });
|
||||
} else if (par1 == GuiCreateFlatWorld.func_82271_a(this.createFlatWorldGui).getFlatLayers().size() - 1) {
|
||||
var9 = StatCollector.translateToLocalFormatted("createWorld.customize.flat.layer.bottom",
|
||||
new Object[] { Integer.valueOf(var6.getLayerCount()) });
|
||||
} else {
|
||||
var9 = StatCollector.translateToLocalFormatted("createWorld.customize.flat.layer",
|
||||
new Object[] { Integer.valueOf(var6.getLayerCount()) });
|
||||
}
|
||||
|
||||
this.createFlatWorldGui.fontRenderer.drawString(var9,
|
||||
par2 + 2 + 213 - this.createFlatWorldGui.fontRenderer.getStringWidth(var9), par3 + 3, 16777215);
|
||||
}
|
||||
|
||||
protected int getScrollBarX() {
|
||||
return this.createFlatWorldGui.width - 70;
|
||||
}
|
||||
}
|
454
src/main/java/net/minecraft/src/GuiCreateWorld.java
Normal file
454
src/main/java/net/minecraft/src/GuiCreateWorld.java
Normal file
@ -0,0 +1,454 @@
|
||||
package net.minecraft.src;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.lax1dude.eaglercraft.EaglerAdapter;
|
||||
import net.lax1dude.eaglercraft.EaglercraftRandom;
|
||||
import net.lax1dude.eaglercraft.IntegratedServer;
|
||||
|
||||
public class GuiCreateWorld extends GuiScreen {
|
||||
private GuiScreen parentGuiScreen;
|
||||
private GuiTextField textboxWorldName;
|
||||
private GuiTextField textboxSeed;
|
||||
private String folderName;
|
||||
|
||||
/** hardcore', 'creative' or 'survival */
|
||||
private String gameMode = "survival";
|
||||
private boolean generateStructures = true;
|
||||
private boolean commandsAllowed = false;
|
||||
|
||||
/** True iif player has clicked buttonAllowCommands at least once */
|
||||
private boolean commandsToggled = false;
|
||||
|
||||
/** toggles when GUIButton 7 is pressed */
|
||||
private boolean bonusItems = false;
|
||||
|
||||
/** True if and only if gameMode.equals("hardcore") */
|
||||
private boolean isHardcore = false;
|
||||
private boolean createClicked;
|
||||
|
||||
/**
|
||||
* True if the extra options (Seed box, structure toggle button, world type
|
||||
* button, etc.) are being shown
|
||||
*/
|
||||
private boolean moreOptions;
|
||||
|
||||
/** The GUIButton that you click to change game modes. */
|
||||
private GuiButton buttonGameMode;
|
||||
|
||||
/**
|
||||
* The GUIButton that you click to get to options like the seed when creating a
|
||||
* world.
|
||||
*/
|
||||
private GuiButton moreWorldOptions;
|
||||
|
||||
/** The GuiButton in the 'More World Options' screen. Toggles ON/OFF */
|
||||
private GuiButton buttonGenerateStructures;
|
||||
private GuiButton buttonBonusItems;
|
||||
|
||||
/** The GuiButton in the more world options screen. */
|
||||
private GuiButton buttonWorldType;
|
||||
private GuiButton buttonAllowCommands;
|
||||
|
||||
/** GuiButton in the more world options screen. */
|
||||
private GuiButton buttonCustomize;
|
||||
|
||||
/** The first line of text describing the currently selected game mode. */
|
||||
private String gameModeDescriptionLine1;
|
||||
|
||||
/** The second line of text describing the currently selected game mode. */
|
||||
private String gameModeDescriptionLine2;
|
||||
|
||||
/** The current textboxSeed text */
|
||||
private String seed;
|
||||
|
||||
/** E.g. New World, Neue Welt, Nieuwe wereld, Neuvo Mundo */
|
||||
private String localizedNewWorldText;
|
||||
private int worldTypeId = 0;
|
||||
|
||||
/** Generator options to use when creating the world. */
|
||||
public String generatorOptionsToUse = "";
|
||||
|
||||
/**
|
||||
* If the world name is one of these, it'll be surrounded with underscores.
|
||||
*/
|
||||
private static final String[] ILLEGAL_WORLD_NAMES = new String[] { "CON", "COM", "PRN", "AUX", "CLOCK$", "NUL",
|
||||
"COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4",
|
||||
"LPT5", "LPT6", "LPT7", "LPT8", "LPT9" };
|
||||
|
||||
public GuiCreateWorld(GuiScreen par1GuiScreen) {
|
||||
this.parentGuiScreen = par1GuiScreen;
|
||||
this.seed = "";
|
||||
this.localizedNewWorldText = StatCollector.translateToLocal("selectWorld.newWorld");
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from the main game loop to update the screen.
|
||||
*/
|
||||
public void updateScreen() {
|
||||
this.textboxWorldName.updateCursorCounter();
|
||||
this.textboxSeed.updateCursorCounter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the buttons (and other controls) to the screen in question.
|
||||
*/
|
||||
public void initGui() {
|
||||
StringTranslate var1 = StringTranslate.getInstance();
|
||||
EaglerAdapter.enableRepeatEvents(true);
|
||||
this.buttonList.clear();
|
||||
this.buttonList.add(new GuiButton(0, this.width / 2 - 155, this.height - 28, 150, 20,
|
||||
var1.translateKey("selectWorld.create")));
|
||||
this.buttonList
|
||||
.add(new GuiButton(1, this.width / 2 + 5, this.height - 28, 150, 20, var1.translateKey("gui.cancel")));
|
||||
this.buttonList.add(this.buttonGameMode = new GuiButton(2, this.width / 2 - 75, 115, 150, 20,
|
||||
var1.translateKey("selectWorld.gameMode")));
|
||||
this.buttonList.add(this.moreWorldOptions = new GuiButton(3, this.width / 2 - 75, 187, 150, 20,
|
||||
var1.translateKey("selectWorld.moreWorldOptions")));
|
||||
this.buttonList.add(this.buttonGenerateStructures = new GuiButton(4, this.width / 2 - 155, 100, 150, 20,
|
||||
var1.translateKey("selectWorld.mapFeatures")));
|
||||
this.buttonGenerateStructures.drawButton = false;
|
||||
this.buttonList.add(this.buttonBonusItems = new GuiButton(7, this.width / 2 + 5, 151, 150, 20,
|
||||
var1.translateKey("selectWorld.bonusItems")));
|
||||
this.buttonBonusItems.drawButton = false;
|
||||
this.buttonList.add(this.buttonWorldType = new GuiButton(5, this.width / 2 + 5, 100, 150, 20,
|
||||
var1.translateKey("selectWorld.mapType")));
|
||||
this.buttonWorldType.drawButton = false;
|
||||
this.buttonList.add(this.buttonAllowCommands = new GuiButton(6, this.width / 2 - 155, 151, 150, 20,
|
||||
var1.translateKey("selectWorld.allowCommands")));
|
||||
this.buttonAllowCommands.drawButton = false;
|
||||
this.buttonList.add(this.buttonCustomize = new GuiButton(8, this.width / 2 + 5, 120, 150, 20,
|
||||
var1.translateKey("selectWorld.customizeType")));
|
||||
this.buttonCustomize.drawButton = false;
|
||||
this.textboxWorldName = new GuiTextField(this.fontRenderer, this.width / 2 - 100, 60, 200, 20);
|
||||
this.textboxWorldName.setFocused(true);
|
||||
this.textboxWorldName.setText(this.localizedNewWorldText);
|
||||
this.textboxSeed = new GuiTextField(this.fontRenderer, this.width / 2 - 100, 60, 200, 20);
|
||||
this.textboxSeed.setText(this.seed);
|
||||
this.func_82288_a(this.moreOptions);
|
||||
this.makeUseableName();
|
||||
this.updateButtonText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a the name for a world save folder based on your world name, replacing
|
||||
* specific characters for _s and appending -s to the end until a free name is
|
||||
* available.
|
||||
*/
|
||||
private void makeUseableName() {
|
||||
this.folderName = this.textboxWorldName.getText().trim();
|
||||
char[] var1 = ChatAllowedCharacters.allowedCharactersArray;
|
||||
int var2 = var1.length;
|
||||
|
||||
for (int var3 = 0; var3 < var2; ++var3) {
|
||||
char var4 = var1[var3];
|
||||
this.folderName = this.folderName.replace(var4, '_');
|
||||
}
|
||||
|
||||
if (MathHelper.stringNullOrLengthZero(this.folderName)) {
|
||||
this.folderName = "World";
|
||||
}
|
||||
|
||||
this.folderName = func_73913_a(this.folderName);
|
||||
}
|
||||
|
||||
private void updateButtonText() {
|
||||
StringTranslate var1 = StringTranslate.getInstance();
|
||||
this.buttonGameMode.displayString = var1.translateKey("selectWorld.gameMode") + " "
|
||||
+ var1.translateKey("selectWorld.gameMode." + this.gameMode);
|
||||
this.gameModeDescriptionLine1 = var1.translateKey("selectWorld.gameMode." + this.gameMode + ".line1");
|
||||
this.gameModeDescriptionLine2 = var1.translateKey("selectWorld.gameMode." + this.gameMode + ".line2");
|
||||
this.buttonGenerateStructures.displayString = var1.translateKey("selectWorld.mapFeatures") + " ";
|
||||
|
||||
if (this.generateStructures) {
|
||||
this.buttonGenerateStructures.displayString = this.buttonGenerateStructures.displayString
|
||||
+ var1.translateKey("options.on");
|
||||
} else {
|
||||
this.buttonGenerateStructures.displayString = this.buttonGenerateStructures.displayString
|
||||
+ var1.translateKey("options.off");
|
||||
}
|
||||
|
||||
this.buttonBonusItems.displayString = var1.translateKey("selectWorld.bonusItems") + " ";
|
||||
|
||||
if (this.bonusItems && !this.isHardcore) {
|
||||
this.buttonBonusItems.displayString = this.buttonBonusItems.displayString + var1.translateKey("options.on");
|
||||
} else {
|
||||
this.buttonBonusItems.displayString = this.buttonBonusItems.displayString
|
||||
+ var1.translateKey("options.off");
|
||||
}
|
||||
|
||||
this.buttonWorldType.displayString = var1.translateKey("selectWorld.mapType") + " "
|
||||
+ var1.translateKey(WorldType.worldTypes[this.worldTypeId].getTranslateName());
|
||||
this.buttonAllowCommands.displayString = var1.translateKey("selectWorld.allowCommands") + " ";
|
||||
|
||||
if (this.commandsAllowed && !this.isHardcore) {
|
||||
this.buttonAllowCommands.displayString = this.buttonAllowCommands.displayString
|
||||
+ var1.translateKey("options.on");
|
||||
} else {
|
||||
this.buttonAllowCommands.displayString = this.buttonAllowCommands.displayString
|
||||
+ var1.translateKey("options.off");
|
||||
}
|
||||
}
|
||||
|
||||
public static String func_73913_a(String par1Str) {
|
||||
par1Str = par1Str.replaceAll("[\\./\"]", "_");
|
||||
String[] var2 = ILLEGAL_WORLD_NAMES;
|
||||
int var3 = var2.length;
|
||||
|
||||
for (int var4 = 0; var4 < var3; ++var4) {
|
||||
String var5 = var2[var4];
|
||||
|
||||
if (par1Str.equalsIgnoreCase(var5)) {
|
||||
par1Str = "_" + par1Str + "_";
|
||||
}
|
||||
}
|
||||
|
||||
List<NBTTagCompound> l = IntegratedServer.getWorldList();
|
||||
if(l != null) {
|
||||
boolean shit = true;
|
||||
while(shit) {
|
||||
shit = false;
|
||||
for(NBTTagCompound nbt : l) {
|
||||
if(par1Str.equals(nbt.getString("folderName"))) {
|
||||
par1Str = par1Str + "-";
|
||||
shit = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return par1Str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the screen is unloaded. Used to disable keyboard repeat events
|
||||
*/
|
||||
public void onGuiClosed() {
|
||||
EaglerAdapter.enableRepeatEvents(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a control is clicked. This is the equivalent of
|
||||
* ActionListener.actionPerformed(ActionEvent e).
|
||||
*/
|
||||
protected void actionPerformed(GuiButton par1GuiButton) {
|
||||
if (par1GuiButton.enabled) {
|
||||
if (par1GuiButton.id == 1) {
|
||||
this.mc.displayGuiScreen(this.parentGuiScreen);
|
||||
} else if (par1GuiButton.id == 0) {
|
||||
this.mc.displayGuiScreen((GuiScreen) null);
|
||||
|
||||
if (this.createClicked) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.createClicked = true;
|
||||
long var2 = (new EaglercraftRandom()).nextLong();
|
||||
String var4 = this.textboxSeed.getText();
|
||||
|
||||
if (!MathHelper.stringNullOrLengthZero(var4)) {
|
||||
try {
|
||||
long var5 = Long.parseLong(var4);
|
||||
|
||||
if (var5 != 0L) {
|
||||
var2 = var5;
|
||||
}
|
||||
} catch (NumberFormatException var7) {
|
||||
var2 = (long) var4.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
EnumGameType var8 = EnumGameType.getByName(this.gameMode);
|
||||
WorldSettings var6 = new WorldSettings(var2, var8, this.generateStructures, this.isHardcore,
|
||||
WorldType.worldTypes[this.worldTypeId]);
|
||||
var6.func_82750_a(this.generatorOptionsToUse);
|
||||
|
||||
if (this.bonusItems && !this.isHardcore) {
|
||||
var6.enableBonusChest();
|
||||
}
|
||||
|
||||
if (this.commandsAllowed && !this.isHardcore) {
|
||||
var6.enableCommands();
|
||||
}
|
||||
|
||||
this.mc.launchIntegratedServer(this.folderName, this.textboxWorldName.getText().trim(), var6);
|
||||
} else if (par1GuiButton.id == 3) {
|
||||
this.func_82287_i();
|
||||
} else if (par1GuiButton.id == 2) {
|
||||
if (this.gameMode.equals("survival")) {
|
||||
if (!this.commandsToggled) {
|
||||
this.commandsAllowed = false;
|
||||
}
|
||||
|
||||
this.isHardcore = false;
|
||||
this.gameMode = "hardcore";
|
||||
this.isHardcore = true;
|
||||
this.buttonAllowCommands.enabled = false;
|
||||
this.buttonBonusItems.enabled = false;
|
||||
this.updateButtonText();
|
||||
} else if (this.gameMode.equals("hardcore")) {
|
||||
if (!this.commandsToggled) {
|
||||
this.commandsAllowed = true;
|
||||
}
|
||||
|
||||
this.isHardcore = false;
|
||||
this.gameMode = "creative";
|
||||
this.updateButtonText();
|
||||
this.isHardcore = false;
|
||||
this.buttonAllowCommands.enabled = true;
|
||||
this.buttonBonusItems.enabled = true;
|
||||
} else {
|
||||
if (!this.commandsToggled) {
|
||||
this.commandsAllowed = false;
|
||||
}
|
||||
|
||||
this.gameMode = "survival";
|
||||
this.updateButtonText();
|
||||
this.buttonAllowCommands.enabled = true;
|
||||
this.buttonBonusItems.enabled = true;
|
||||
this.isHardcore = false;
|
||||
}
|
||||
|
||||
this.updateButtonText();
|
||||
} else if (par1GuiButton.id == 4) {
|
||||
this.generateStructures = !this.generateStructures;
|
||||
this.updateButtonText();
|
||||
} else if (par1GuiButton.id == 7) {
|
||||
this.bonusItems = !this.bonusItems;
|
||||
this.updateButtonText();
|
||||
} else if (par1GuiButton.id == 5) {
|
||||
++this.worldTypeId;
|
||||
|
||||
if (this.worldTypeId >= WorldType.worldTypes.length) {
|
||||
this.worldTypeId = 0;
|
||||
}
|
||||
|
||||
while (WorldType.worldTypes[this.worldTypeId] == null
|
||||
|| !WorldType.worldTypes[this.worldTypeId].getCanBeCreated()) {
|
||||
++this.worldTypeId;
|
||||
|
||||
if (this.worldTypeId >= WorldType.worldTypes.length) {
|
||||
this.worldTypeId = 0;
|
||||
}
|
||||
}
|
||||
|
||||
this.generatorOptionsToUse = "";
|
||||
this.updateButtonText();
|
||||
this.func_82288_a(this.moreOptions);
|
||||
} else if (par1GuiButton.id == 6) {
|
||||
this.commandsToggled = true;
|
||||
this.commandsAllowed = !this.commandsAllowed;
|
||||
this.updateButtonText();
|
||||
} else if (par1GuiButton.id == 8) {
|
||||
this.mc.displayGuiScreen(new GuiCreateFlatWorld(this, this.generatorOptionsToUse));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void func_82287_i() {
|
||||
this.func_82288_a(!this.moreOptions);
|
||||
}
|
||||
|
||||
private void func_82288_a(boolean par1) {
|
||||
this.moreOptions = par1;
|
||||
this.buttonGameMode.drawButton = !this.moreOptions;
|
||||
this.buttonGenerateStructures.drawButton = this.moreOptions;
|
||||
this.buttonBonusItems.drawButton = this.moreOptions;
|
||||
this.buttonWorldType.drawButton = this.moreOptions;
|
||||
this.buttonAllowCommands.drawButton = this.moreOptions;
|
||||
this.buttonCustomize.drawButton = this.moreOptions && WorldType.worldTypes[this.worldTypeId] == WorldType.FLAT;
|
||||
StringTranslate var2;
|
||||
|
||||
if (this.moreOptions) {
|
||||
var2 = StringTranslate.getInstance();
|
||||
this.moreWorldOptions.displayString = var2.translateKey("gui.done");
|
||||
} else {
|
||||
var2 = StringTranslate.getInstance();
|
||||
this.moreWorldOptions.displayString = var2.translateKey("selectWorld.moreWorldOptions");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a key is typed. This is the equivalent of
|
||||
* KeyListener.keyTyped(KeyEvent e).
|
||||
*/
|
||||
protected void keyTyped(char par1, int par2) {
|
||||
if (this.textboxWorldName.isFocused() && !this.moreOptions) {
|
||||
this.textboxWorldName.textboxKeyTyped(par1, par2);
|
||||
this.localizedNewWorldText = this.textboxWorldName.getText();
|
||||
} else if (this.textboxSeed.isFocused() && this.moreOptions) {
|
||||
this.textboxSeed.textboxKeyTyped(par1, par2);
|
||||
this.seed = this.textboxSeed.getText();
|
||||
}
|
||||
|
||||
if (par1 == 13) {
|
||||
this.actionPerformed((GuiButton) this.buttonList.get(0));
|
||||
}
|
||||
|
||||
((GuiButton) this.buttonList.get(0)).enabled = this.textboxWorldName.getText().length() > 0;
|
||||
this.makeUseableName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the mouse is clicked.
|
||||
*/
|
||||
protected void mouseClicked(int par1, int par2, int par3) {
|
||||
super.mouseClicked(par1, par2, par3);
|
||||
|
||||
if (this.moreOptions) {
|
||||
this.textboxSeed.mouseClicked(par1, par2, par3);
|
||||
} else {
|
||||
this.textboxWorldName.mouseClicked(par1, par2, par3);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the screen and all the components in it.
|
||||
*/
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
StringTranslate var4 = StringTranslate.getInstance();
|
||||
this.drawDefaultBackground();
|
||||
this.drawCenteredString(this.fontRenderer, var4.translateKey("selectWorld.create"), this.width / 2, 20,
|
||||
16777215);
|
||||
|
||||
if (this.moreOptions) {
|
||||
this.drawString(this.fontRenderer, var4.translateKey("selectWorld.enterSeed"), this.width / 2 - 100, 47,
|
||||
10526880);
|
||||
this.drawString(this.fontRenderer, var4.translateKey("selectWorld.seedInfo"), this.width / 2 - 100, 85,
|
||||
10526880);
|
||||
this.drawString(this.fontRenderer, var4.translateKey("selectWorld.mapFeatures.info"), this.width / 2 - 150,
|
||||
122, 10526880);
|
||||
this.drawString(this.fontRenderer, var4.translateKey("selectWorld.allowCommands.info"),
|
||||
this.width / 2 - 150, 172, 10526880);
|
||||
this.textboxSeed.drawTextBox();
|
||||
} else {
|
||||
this.drawString(this.fontRenderer, var4.translateKey("selectWorld.enterName"), this.width / 2 - 100, 47,
|
||||
10526880);
|
||||
this.drawString(this.fontRenderer, var4.translateKey("selectWorld.resultFolder") + " " + this.folderName,
|
||||
this.width / 2 - 100, 85, 10526880);
|
||||
this.textboxWorldName.drawTextBox();
|
||||
this.drawString(this.fontRenderer, this.gameModeDescriptionLine1, this.width / 2 - 100, 137, 10526880);
|
||||
this.drawString(this.fontRenderer, this.gameModeDescriptionLine2, this.width / 2 - 100, 149, 10526880);
|
||||
}
|
||||
|
||||
super.drawScreen(par1, par2, par3);
|
||||
}
|
||||
|
||||
public void func_82286_a(WorldInfo par1WorldInfo) {
|
||||
this.localizedNewWorldText = StatCollector.translateToLocalFormatted("selectWorld.newWorld.copyOf",
|
||||
new Object[] { par1WorldInfo.getWorldName() });
|
||||
this.seed = par1WorldInfo.getSeed() + "";
|
||||
this.worldTypeId = par1WorldInfo.getTerrainType().getWorldTypeID();
|
||||
this.generatorOptionsToUse = par1WorldInfo.getGeneratorOptions();
|
||||
this.generateStructures = par1WorldInfo.isMapFeaturesEnabled();
|
||||
this.commandsAllowed = par1WorldInfo.areCommandsAllowed();
|
||||
|
||||
if (par1WorldInfo.isHardcoreModeEnabled()) {
|
||||
this.gameMode = "hardcore";
|
||||
} else if (par1WorldInfo.getGameType().isSurvivalOrAdventure()) {
|
||||
this.gameMode = "survival";
|
||||
} else if (par1WorldInfo.getGameType().isCreative()) {
|
||||
this.gameMode = "creative";
|
||||
}
|
||||
}
|
||||
}
|
@ -25,6 +25,10 @@ public class GuiDownloadTerrain extends GuiScreen {
|
||||
this.buttonList.clear();
|
||||
}
|
||||
|
||||
public boolean doesGuiPauseGame() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from the main game loop to update the screen.
|
||||
*/
|
||||
|
214
src/main/java/net/minecraft/src/GuiFlatPresets.java
Normal file
214
src/main/java/net/minecraft/src/GuiFlatPresets.java
Normal file
@ -0,0 +1,214 @@
|
||||
package net.minecraft.src;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.lax1dude.eaglercraft.EaglerAdapter;
|
||||
|
||||
public class GuiFlatPresets extends GuiScreen {
|
||||
/** RenderItem instance used to render preset icons. */
|
||||
private static RenderItem presetIconRenderer = new RenderItem();
|
||||
|
||||
/** List of defined flat world presets. */
|
||||
private static final List presets = new ArrayList();
|
||||
private final GuiCreateFlatWorld createFlatWorldGui;
|
||||
private String field_82300_d;
|
||||
private String field_82308_m;
|
||||
private String field_82306_n;
|
||||
private GuiFlatPresetsListSlot theFlatPresetsListSlot;
|
||||
private GuiButton theButton;
|
||||
private GuiTextField theTextField;
|
||||
|
||||
public GuiFlatPresets(GuiCreateFlatWorld par1) {
|
||||
this.createFlatWorldGui = par1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the buttons (and other controls) to the screen in question.
|
||||
*/
|
||||
public void initGui() {
|
||||
this.buttonList.clear();
|
||||
EaglerAdapter.enableRepeatEvents(true);
|
||||
this.field_82300_d = StatCollector.translateToLocal("createWorld.customize.presets.title");
|
||||
this.field_82308_m = StatCollector.translateToLocal("createWorld.customize.presets.share");
|
||||
this.field_82306_n = StatCollector.translateToLocal("createWorld.customize.presets.list");
|
||||
this.theTextField = new GuiTextField(this.fontRenderer, 50, 40, this.width - 100, 20);
|
||||
this.theFlatPresetsListSlot = new GuiFlatPresetsListSlot(this);
|
||||
this.theTextField.setMaxStringLength(1230);
|
||||
this.theTextField.setText(this.createFlatWorldGui.getFlatGeneratorInfo());
|
||||
this.buttonList.add(this.theButton = new GuiButton(0, this.width / 2 - 155, this.height - 28, 150, 20,
|
||||
StatCollector.translateToLocal("createWorld.customize.presets.select")));
|
||||
this.buttonList.add(new GuiButton(1, this.width / 2 + 5, this.height - 28, 150, 20,
|
||||
StatCollector.translateToLocal("gui.cancel")));
|
||||
this.func_82296_g();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the screen is unloaded. Used to disable keyboard repeat events
|
||||
*/
|
||||
public void onGuiClosed() {
|
||||
EaglerAdapter.enableRepeatEvents(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the mouse is clicked.
|
||||
*/
|
||||
protected void mouseClicked(int par1, int par2, int par3) {
|
||||
this.theTextField.mouseClicked(par1, par2, par3);
|
||||
super.mouseClicked(par1, par2, par3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a key is typed. This is the equivalent of
|
||||
* KeyListener.keyTyped(KeyEvent e).
|
||||
*/
|
||||
protected void keyTyped(char par1, int par2) {
|
||||
if (!this.theTextField.textboxKeyTyped(par1, par2)) {
|
||||
super.keyTyped(par1, par2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a control is clicked. This is the equivalent of
|
||||
* ActionListener.actionPerformed(ActionEvent e).
|
||||
*/
|
||||
protected void actionPerformed(GuiButton par1GuiButton) {
|
||||
if (par1GuiButton.id == 0 && this.func_82293_j()) {
|
||||
this.createFlatWorldGui.setFlatGeneratorInfo(this.theTextField.getText());
|
||||
this.mc.displayGuiScreen(this.createFlatWorldGui);
|
||||
} else if (par1GuiButton.id == 1) {
|
||||
this.mc.displayGuiScreen(this.createFlatWorldGui);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the screen and all the components in it.
|
||||
*/
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
this.drawDefaultBackground();
|
||||
this.theFlatPresetsListSlot.drawScreen(par1, par2, par3);
|
||||
this.drawCenteredString(this.fontRenderer, this.field_82300_d, this.width / 2, 8, 16777215);
|
||||
this.drawString(this.fontRenderer, this.field_82308_m, 50, 30, 10526880);
|
||||
this.drawString(this.fontRenderer, this.field_82306_n, 50, 70, 10526880);
|
||||
this.theTextField.drawTextBox();
|
||||
super.drawScreen(par1, par2, par3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from the main game loop to update the screen.
|
||||
*/
|
||||
public void updateScreen() {
|
||||
this.theTextField.updateCursorCounter();
|
||||
super.updateScreen();
|
||||
}
|
||||
|
||||
public void func_82296_g() {
|
||||
boolean var1 = this.func_82293_j();
|
||||
this.theButton.enabled = var1;
|
||||
}
|
||||
|
||||
private boolean func_82293_j() {
|
||||
return this.theFlatPresetsListSlot.field_82459_a > -1
|
||||
&& this.theFlatPresetsListSlot.field_82459_a < presets.size()
|
||||
|| this.theTextField.getText().length() > 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a flat world preset with no world features.
|
||||
*/
|
||||
private static void addPresetNoFeatures(String par0Str, int par1, BiomeGenBase par2BiomeGenBase,
|
||||
FlatLayerInfo... par3ArrayOfFlatLayerInfo) {
|
||||
addPreset(par0Str, par1, par2BiomeGenBase, (List) null, par3ArrayOfFlatLayerInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a flat world preset.
|
||||
*/
|
||||
private static void addPreset(String par0Str, int par1, BiomeGenBase par2BiomeGenBase, List par3List,
|
||||
FlatLayerInfo... par4ArrayOfFlatLayerInfo) {
|
||||
FlatGeneratorInfo var5 = new FlatGeneratorInfo();
|
||||
|
||||
for (int var6 = par4ArrayOfFlatLayerInfo.length - 1; var6 >= 0; --var6) {
|
||||
var5.getFlatLayers().add(par4ArrayOfFlatLayerInfo[var6]);
|
||||
}
|
||||
|
||||
var5.setBiome(par2BiomeGenBase.biomeID);
|
||||
var5.func_82645_d();
|
||||
|
||||
if (par3List != null) {
|
||||
Iterator var8 = par3List.iterator();
|
||||
|
||||
while (var8.hasNext()) {
|
||||
String var7 = (String) var8.next();
|
||||
var5.getWorldFeatures().put(var7, new HashMap());
|
||||
}
|
||||
}
|
||||
|
||||
presets.add(new GuiFlatPresetsItem(par1, par0Str, var5.toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the RenderItem instance used to render preset icons.
|
||||
*/
|
||||
static RenderItem getPresetIconRenderer() {
|
||||
return presetIconRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of defined flat world presets.
|
||||
*/
|
||||
static List getPresets() {
|
||||
return presets;
|
||||
}
|
||||
|
||||
static GuiFlatPresetsListSlot func_82292_a(GuiFlatPresets par0GuiFlatPresets) {
|
||||
return par0GuiFlatPresets.theFlatPresetsListSlot;
|
||||
}
|
||||
|
||||
static GuiTextField func_82298_b(GuiFlatPresets par0GuiFlatPresets) {
|
||||
return par0GuiFlatPresets.theTextField;
|
||||
}
|
||||
|
||||
static {
|
||||
addPreset("Classic Flat", Block.grass.blockID, BiomeGenBase.plains, Arrays.asList(new String[] { "village" }),
|
||||
new FlatLayerInfo[] { new FlatLayerInfo(1, Block.grass.blockID),
|
||||
new FlatLayerInfo(2, Block.dirt.blockID), new FlatLayerInfo(1, Block.bedrock.blockID) });
|
||||
addPreset("Tunnelers\' Dream", Block.stone.blockID, BiomeGenBase.extremeHills,
|
||||
Arrays.asList(new String[] { "biome_1", "dungeon", "decoration", "stronghold", "mineshaft" }),
|
||||
new FlatLayerInfo[] { new FlatLayerInfo(1, Block.grass.blockID),
|
||||
new FlatLayerInfo(5, Block.dirt.blockID), new FlatLayerInfo(230, Block.stone.blockID),
|
||||
new FlatLayerInfo(1, Block.bedrock.blockID) });
|
||||
addPreset("Water World", Block.waterMoving.blockID, BiomeGenBase.plains,
|
||||
Arrays.asList(new String[] { "village", "biome_1" }),
|
||||
new FlatLayerInfo[] { new FlatLayerInfo(90, Block.waterStill.blockID),
|
||||
new FlatLayerInfo(5, Block.sand.blockID), new FlatLayerInfo(5, Block.dirt.blockID),
|
||||
new FlatLayerInfo(5, Block.stone.blockID), new FlatLayerInfo(1, Block.bedrock.blockID) });
|
||||
addPreset("Overworld", Block.tallGrass.blockID, BiomeGenBase.plains,
|
||||
Arrays.asList(new String[] { "village", "biome_1", "decoration", "stronghold", "mineshaft", "dungeon",
|
||||
"lake", "lava_lake" }),
|
||||
new FlatLayerInfo[] { new FlatLayerInfo(1, Block.grass.blockID),
|
||||
new FlatLayerInfo(3, Block.dirt.blockID), new FlatLayerInfo(59, Block.stone.blockID),
|
||||
new FlatLayerInfo(1, Block.bedrock.blockID) });
|
||||
addPreset("Snowy Kingdom", Block.snow.blockID, BiomeGenBase.icePlains,
|
||||
Arrays.asList(new String[] { "village", "biome_1" }),
|
||||
new FlatLayerInfo[] { new FlatLayerInfo(1, Block.snow.blockID),
|
||||
new FlatLayerInfo(1, Block.grass.blockID), new FlatLayerInfo(3, Block.dirt.blockID),
|
||||
new FlatLayerInfo(59, Block.stone.blockID), new FlatLayerInfo(1, Block.bedrock.blockID) });
|
||||
addPreset("Bottomless Pit", Item.feather.itemID, BiomeGenBase.plains,
|
||||
Arrays.asList(new String[] { "village", "biome_1" }),
|
||||
new FlatLayerInfo[] { new FlatLayerInfo(1, Block.grass.blockID),
|
||||
new FlatLayerInfo(3, Block.dirt.blockID), new FlatLayerInfo(2, Block.cobblestone.blockID) });
|
||||
addPreset("Desert", Block.sand.blockID, BiomeGenBase.desert,
|
||||
Arrays.asList(
|
||||
new String[] { "village", "biome_1", "decoration", "stronghold", "mineshaft", "dungeon" }),
|
||||
new FlatLayerInfo[] { new FlatLayerInfo(8, Block.sand.blockID),
|
||||
new FlatLayerInfo(52, Block.sandStone.blockID), new FlatLayerInfo(3, Block.stone.blockID),
|
||||
new FlatLayerInfo(1, Block.bedrock.blockID) });
|
||||
addPresetNoFeatures("Redstone Ready", Item.redstone.itemID, BiomeGenBase.desert,
|
||||
new FlatLayerInfo[] { new FlatLayerInfo(52, Block.sandStone.blockID),
|
||||
new FlatLayerInfo(3, Block.stone.blockID), new FlatLayerInfo(1, Block.bedrock.blockID) });
|
||||
}
|
||||
}
|
18
src/main/java/net/minecraft/src/GuiFlatPresetsItem.java
Normal file
18
src/main/java/net/minecraft/src/GuiFlatPresetsItem.java
Normal file
@ -0,0 +1,18 @@
|
||||
package net.minecraft.src;
|
||||
|
||||
class GuiFlatPresetsItem {
|
||||
/** ID for the item used as icon for this preset. */
|
||||
public int iconId;
|
||||
|
||||
/** Name for this preset. */
|
||||
public String presetName;
|
||||
|
||||
/** Data for this preset. */
|
||||
public String presetData;
|
||||
|
||||
public GuiFlatPresetsItem(int par1, String par2Str, String par3Str) {
|
||||
this.iconId = par1;
|
||||
this.presetName = par2Str;
|
||||
this.presetData = par3Str;
|
||||
}
|
||||
}
|
80
src/main/java/net/minecraft/src/GuiFlatPresetsListSlot.java
Normal file
80
src/main/java/net/minecraft/src/GuiFlatPresetsListSlot.java
Normal file
@ -0,0 +1,80 @@
|
||||
package net.minecraft.src;
|
||||
|
||||
import net.lax1dude.eaglercraft.EaglerAdapter;
|
||||
import net.lax1dude.eaglercraft.adapter.Tessellator;
|
||||
|
||||
class GuiFlatPresetsListSlot extends GuiSlot {
|
||||
public int field_82459_a;
|
||||
|
||||
final GuiFlatPresets flatPresetsGui;
|
||||
|
||||
public GuiFlatPresetsListSlot(GuiFlatPresets par1) {
|
||||
super(par1.mc, par1.width, par1.height, 80, par1.height - 37, 24);
|
||||
this.flatPresetsGui = par1;
|
||||
this.field_82459_a = -1;
|
||||
}
|
||||
|
||||
private void func_82457_a(int par1, int par2, int par3) {
|
||||
this.func_82456_d(par1 + 1, par2 + 1);
|
||||
EaglerAdapter.glEnable(EaglerAdapter.GL_RESCALE_NORMAL);
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
GuiFlatPresets.getPresetIconRenderer().renderItemIntoGUI(this.flatPresetsGui.fontRenderer,
|
||||
this.flatPresetsGui.mc.renderEngine, new ItemStack(par3, 1, 0), par1 + 2, par2 + 2);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
EaglerAdapter.glDisable(EaglerAdapter.GL_RESCALE_NORMAL);
|
||||
}
|
||||
|
||||
private void func_82456_d(int par1, int par2) {
|
||||
this.func_82455_b(par1, par2, 0, 0);
|
||||
}
|
||||
|
||||
private void func_82455_b(int par1, int par2, int par3, int par4) {
|
||||
EaglerAdapter.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.flatPresetsGui.mc.renderEngine.bindTexture("/gui/slot.png");
|
||||
Tessellator var9 = Tessellator.instance;
|
||||
var9.startDrawingQuads();
|
||||
var9.addVertexWithUV((double) (par1 + 0), (double) (par2 + 18), (double) this.flatPresetsGui.zLevel,
|
||||
(double) ((float) (par3 + 0) * 0.0078125F), (double) ((float) (par4 + 18) * 0.0078125F));
|
||||
var9.addVertexWithUV((double) (par1 + 18), (double) (par2 + 18), (double) this.flatPresetsGui.zLevel,
|
||||
(double) ((float) (par3 + 18) * 0.0078125F), (double) ((float) (par4 + 18) * 0.0078125F));
|
||||
var9.addVertexWithUV((double) (par1 + 18), (double) (par2 + 0), (double) this.flatPresetsGui.zLevel,
|
||||
(double) ((float) (par3 + 18) * 0.0078125F), (double) ((float) (par4 + 0) * 0.0078125F));
|
||||
var9.addVertexWithUV((double) (par1 + 0), (double) (par2 + 0), (double) this.flatPresetsGui.zLevel,
|
||||
(double) ((float) (par3 + 0) * 0.0078125F), (double) ((float) (par4 + 0) * 0.0078125F));
|
||||
var9.draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size of the current slot list.
|
||||
*/
|
||||
protected int getSize() {
|
||||
return GuiFlatPresets.getPresets().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* the element in the slot that was clicked, boolean for wether it was double
|
||||
* clicked or not
|
||||
*/
|
||||
protected void elementClicked(int par1, boolean par2) {
|
||||
this.field_82459_a = par1;
|
||||
this.flatPresetsGui.func_82296_g();
|
||||
GuiFlatPresets.func_82298_b(this.flatPresetsGui).setText(((GuiFlatPresetsItem) GuiFlatPresets.getPresets()
|
||||
.get(GuiFlatPresets.func_82292_a(this.flatPresetsGui).field_82459_a)).presetData);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns true if the element passed in is currently selected
|
||||
*/
|
||||
protected boolean isSelected(int par1) {
|
||||
return par1 == this.field_82459_a;
|
||||
}
|
||||
|
||||
protected void drawBackground() {
|
||||
}
|
||||
|
||||
protected void drawSlot(int par1, int par2, int par3, int par4, Tessellator par5Tessellator) {
|
||||
GuiFlatPresetsItem var6 = (GuiFlatPresetsItem) GuiFlatPresets.getPresets().get(par1);
|
||||
this.func_82457_a(par2, par3, var6.iconId);
|
||||
this.flatPresetsGui.fontRenderer.drawString(var6.presetName, par2 + 18 + 5, par3 + 6, 16777215);
|
||||
}
|
||||
}
|
@ -56,7 +56,7 @@ public class GuiGameOver extends GuiScreen {
|
||||
case 2:
|
||||
this.mc.theWorld.sendQuittingDisconnectingPacket();
|
||||
this.mc.loadWorld((WorldClient) null);
|
||||
this.mc.displayGuiScreen(new GuiMainMenu());
|
||||
this.mc.stopServerAndDisplayGuiScreen(new GuiMainMenu());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -467,7 +467,9 @@ public class GuiIngame extends Gui {
|
||||
if (this.recordIsPlaying) {
|
||||
var13 = BiomeGenBase.HSBtoRGB(var33 / 50.0F, 0.7F, 0.6F) & 16777215;
|
||||
}
|
||||
|
||||
|
||||
String str = this.recordPlaying + " (jukebox not enabled)";
|
||||
|
||||
var8.drawString(this.recordPlaying, -var8.getStringWidth(this.recordPlaying) / 2, -4, var13 + (var12 << 24));
|
||||
EaglerAdapter.glDisable(EaglerAdapter.GL_BLEND);
|
||||
EaglerAdapter.glPopMatrix();
|
||||
|
@ -44,7 +44,7 @@ public class GuiIngameMenu extends GuiScreen {
|
||||
par1GuiButton.enabled = false;
|
||||
this.mc.theWorld.sendQuittingDisconnectingPacket();
|
||||
this.mc.loadWorld((WorldClient) null);
|
||||
this.mc.displayGuiScreen(new GuiMainMenu());
|
||||
this.mc.stopServerAndDisplayGuiScreen(new GuiMainMenu());
|
||||
|
||||
case 2:
|
||||
case 3:
|
||||
|
@ -11,7 +11,9 @@ import net.lax1dude.eaglercraft.EaglerImage;
|
||||
|
||||
import net.lax1dude.eaglercraft.GuiScreenEditProfile;
|
||||
import net.lax1dude.eaglercraft.GuiScreenSingleplayerNotice;
|
||||
import net.lax1dude.eaglercraft.GuiScreenSingleplayerLoading;
|
||||
import net.lax1dude.eaglercraft.GuiScreenVoiceChannel;
|
||||
import net.lax1dude.eaglercraft.IntegratedServer;
|
||||
import net.lax1dude.eaglercraft.LocalStorageManager;
|
||||
import net.lax1dude.eaglercraft.TextureLocation;
|
||||
import net.lax1dude.eaglercraft.adapter.Tessellator;
|
||||
@ -236,10 +238,19 @@ public class GuiMainMenu extends GuiScreen {
|
||||
}
|
||||
|
||||
if (par1GuiButton.id == 1) {
|
||||
//if(!hasClickedSingleplayer) {
|
||||
this.mc.displayGuiScreen(new GuiScreenSingleplayerNotice(this));
|
||||
//}
|
||||
//hasClickedSingleplayer = true;
|
||||
if(EaglerAdapter.isIntegratedServerAvailable()) {
|
||||
if(!hasClickedSingleplayer) {
|
||||
this.mc.displayGuiScreen(new GuiScreenSingleplayerNotice(this));
|
||||
}else {
|
||||
if(!IntegratedServer.isAlive()) {
|
||||
IntegratedServer.begin();
|
||||
this.mc.displayGuiScreen(new GuiScreenSingleplayerLoading(new GuiSelectWorld(this), "starting up integrated server", () -> IntegratedServer.isReady()));
|
||||
}else {
|
||||
this.mc.displayGuiScreen(new GuiSelectWorld(this));
|
||||
}
|
||||
}
|
||||
hasClickedSingleplayer = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (par1GuiButton.id == 5) {
|
||||
|
@ -46,7 +46,11 @@ public class GuiProgress extends GuiScreen implements IProgressUpdate {
|
||||
public void onNoMoreProgress() {
|
||||
this.noMoreProgress = true;
|
||||
}
|
||||
|
||||
|
||||
public boolean doesGuiPauseGame() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the screen and all the components in it.
|
||||
*/
|
||||
|
96
src/main/java/net/minecraft/src/GuiRenameWorld.java
Normal file
96
src/main/java/net/minecraft/src/GuiRenameWorld.java
Normal file
@ -0,0 +1,96 @@
|
||||
package net.minecraft.src;
|
||||
|
||||
import net.lax1dude.eaglercraft.EaglerAdapter;
|
||||
|
||||
public class GuiRenameWorld extends GuiScreen {
|
||||
private GuiScreen parentGuiScreen;
|
||||
private GuiTextField theGuiTextField;
|
||||
private final String worldName;
|
||||
|
||||
public GuiRenameWorld(GuiScreen par1GuiScreen, String par2Str) {
|
||||
this.parentGuiScreen = par1GuiScreen;
|
||||
this.worldName = par2Str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from the main game loop to update the screen.
|
||||
*/
|
||||
public void updateScreen() {
|
||||
this.theGuiTextField.updateCursorCounter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the buttons (and other controls) to the screen in question.
|
||||
*/
|
||||
public void initGui() {
|
||||
StringTranslate var1 = StringTranslate.getInstance();
|
||||
EaglerAdapter.enableRepeatEvents(true);
|
||||
this.buttonList.clear();
|
||||
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + 12,
|
||||
var1.translateKey("selectWorld.renameButton")));
|
||||
this.buttonList.add(
|
||||
new GuiButton(1, this.width / 2 - 100, this.height / 4 + 120 + 12, var1.translateKey("gui.cancel")));
|
||||
//ISaveFormat var2 = this.mc.getSaveLoader();
|
||||
//WorldInfo var3 = var2.getWorldInfo(this.worldName);
|
||||
String var4 = worldName; //var3.getWorldName(); //TODO: add rename logic
|
||||
this.theGuiTextField = new GuiTextField(this.fontRenderer, this.width / 2 - 100, this.height / 4 + 3, 200, 20);
|
||||
this.theGuiTextField.setFocused(true);
|
||||
this.theGuiTextField.setText(var4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the screen is unloaded. Used to disable keyboard repeat events
|
||||
*/
|
||||
public void onGuiClosed() {
|
||||
EaglerAdapter.enableRepeatEvents(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a control is clicked. This is the equivalent of
|
||||
* ActionListener.actionPerformed(ActionEvent e).
|
||||
*/
|
||||
protected void actionPerformed(GuiButton par1GuiButton) {
|
||||
if (par1GuiButton.enabled) {
|
||||
if (par1GuiButton.id == 1) {
|
||||
this.mc.displayGuiScreen(this.parentGuiScreen);
|
||||
} else if (par1GuiButton.id == 0) {
|
||||
//ISaveFormat var2 = this.mc.getSaveLoader();
|
||||
//var2.renameWorld(this.worldName, this.theGuiTextField.getText().trim());
|
||||
this.mc.displayGuiScreen(this.parentGuiScreen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a key is typed. This is the equivalent of
|
||||
* KeyListener.keyTyped(KeyEvent e).
|
||||
*/
|
||||
protected void keyTyped(char par1, int par2) {
|
||||
this.theGuiTextField.textboxKeyTyped(par1, par2);
|
||||
((GuiButton) this.buttonList.get(0)).enabled = this.theGuiTextField.getText().trim().length() > 0;
|
||||
|
||||
if (par1 == 13) {
|
||||
this.actionPerformed((GuiButton) this.buttonList.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the mouse is clicked.
|
||||
*/
|
||||
protected void mouseClicked(int par1, int par2, int par3) {
|
||||
super.mouseClicked(par1, par2, par3);
|
||||
this.theGuiTextField.mouseClicked(par1, par2, par3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the screen and all the components in it.
|
||||
*/
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
StringTranslate var4 = StringTranslate.getInstance();
|
||||
this.drawDefaultBackground();
|
||||
this.drawCenteredString(this.fontRenderer, var4.translateKey("selectWorld.renameTitle"), this.width / 2, this.height / 4 - 60 + 20, 16777215);
|
||||
this.drawString(this.fontRenderer, var4.translateKey("selectWorld.enterName"), this.width / 2 - 100, this.height / 4 - 60 + 50, 10526880);
|
||||
this.theGuiTextField.drawTextBox();
|
||||
super.drawScreen(par1, par2, par3);
|
||||
}
|
||||
}
|
@ -2,8 +2,10 @@ package net.minecraft.src;
|
||||
|
||||
public class GuiScreenChatOptions extends GuiScreen {
|
||||
/** An array of all EnumOptions which are to do with chat. */
|
||||
private static final EnumOptions[] allScreenChatOptions = new EnumOptions[] { EnumOptions.CHAT_VISIBILITY, EnumOptions.CHAT_COLOR, EnumOptions.CHAT_LINKS, EnumOptions.CHAT_OPACITY, EnumOptions.CHAT_LINKS_PROMPT, EnumOptions.CHAT_SCALE,
|
||||
EnumOptions.CHAT_HEIGHT_FOCUSED, EnumOptions.CHAT_HEIGHT_UNFOCUSED, EnumOptions.CHAT_WIDTH };
|
||||
private static final EnumOptions[] allScreenChatOptions = new EnumOptions[] { EnumOptions.CHAT_VISIBILITY,
|
||||
EnumOptions.CHAT_COLOR, EnumOptions.CHAT_LINKS, EnumOptions.CHAT_OPACITY, EnumOptions.CHAT_LINKS_PROMPT,
|
||||
EnumOptions.CHAT_SCALE, EnumOptions.CHAT_HEIGHT_FOCUSED, EnumOptions.CHAT_HEIGHT_UNFOCUSED,
|
||||
EnumOptions.CHAT_WIDTH };
|
||||
private static final EnumOptions[] allMultiplayerOptions = new EnumOptions[] { EnumOptions.SHOW_CAPE };
|
||||
|
||||
/** Instance of GuiScreen. */
|
||||
@ -37,9 +39,12 @@ public class GuiScreenChatOptions extends GuiScreen {
|
||||
var6 = var3[var5];
|
||||
|
||||
if (var6.getEnumFloat()) {
|
||||
this.buttonList.add(new GuiSlider(var6.returnEnumOrdinal(), this.width / 2 - 155 + var2 % 2 * 160, this.height / 6 + 24 * (var2 >> 1), var6, this.theSettings.getKeyBinding(var6), this.theSettings.getOptionFloatValue(var6)));
|
||||
this.buttonList.add(new GuiSlider(var6.returnEnumOrdinal(), this.width / 2 - 155 + var2 % 2 * 160,
|
||||
this.height / 6 + 24 * (var2 >> 1), var6, this.theSettings.getKeyBinding(var6),
|
||||
this.theSettings.getOptionFloatValue(var6)));
|
||||
} else {
|
||||
this.buttonList.add(new GuiSmallButton(var6.returnEnumOrdinal(), this.width / 2 - 155 + var2 % 2 * 160, this.height / 6 + 24 * (var2 >> 1), var6, this.theSettings.getKeyBinding(var6)));
|
||||
this.buttonList.add(new GuiSmallButton(var6.returnEnumOrdinal(), this.width / 2 - 155 + var2 % 2 * 160,
|
||||
this.height / 6 + 24 * (var2 >> 1), var6, this.theSettings.getKeyBinding(var6)));
|
||||
}
|
||||
|
||||
++var2;
|
||||
@ -58,15 +63,19 @@ public class GuiScreenChatOptions extends GuiScreen {
|
||||
var6 = var3[var5];
|
||||
|
||||
if (var6.getEnumFloat()) {
|
||||
this.buttonList.add(new GuiSlider(var6.returnEnumOrdinal(), this.width / 2 - 155 + var2 % 2 * 160, this.height / 6 + 24 * (var2 >> 1), var6, this.theSettings.getKeyBinding(var6), this.theSettings.getOptionFloatValue(var6)));
|
||||
this.buttonList.add(new GuiSlider(var6.returnEnumOrdinal(), this.width / 2 - 155 + var2 % 2 * 160,
|
||||
this.height / 6 + 24 * (var2 >> 1), var6, this.theSettings.getKeyBinding(var6),
|
||||
this.theSettings.getOptionFloatValue(var6)));
|
||||
} else {
|
||||
this.buttonList.add(new GuiSmallButton(var6.returnEnumOrdinal(), this.width / 2 - 155 + var2 % 2 * 160, this.height / 6 + 24 * (var2 >> 1), var6, this.theSettings.getKeyBinding(var6)));
|
||||
this.buttonList.add(new GuiSmallButton(var6.returnEnumOrdinal(), this.width / 2 - 155 + var2 % 2 * 160,
|
||||
this.height / 6 + 24 * (var2 >> 1), var6, this.theSettings.getKeyBinding(var6)));
|
||||
}
|
||||
|
||||
++var2;
|
||||
}
|
||||
|
||||
this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height / 6 + 168, var1.translateKey("gui.done")));
|
||||
this.buttonList
|
||||
.add(new GuiButton(200, this.width / 2 - 100, this.height / 6 + 168, var1.translateKey("gui.done")));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,7 +86,8 @@ public class GuiScreenChatOptions extends GuiScreen {
|
||||
if (par1GuiButton.enabled) {
|
||||
if (par1GuiButton.id < 100 && par1GuiButton instanceof GuiSmallButton) {
|
||||
this.theSettings.setOptionValue(((GuiSmallButton) par1GuiButton).returnEnumOptions(), 1);
|
||||
par1GuiButton.displayString = this.theSettings.getKeyBinding(EnumOptions.getEnumOptions(par1GuiButton.id));
|
||||
par1GuiButton.displayString = this.theSettings
|
||||
.getKeyBinding(EnumOptions.getEnumOptions(par1GuiButton.id));
|
||||
}
|
||||
|
||||
if (par1GuiButton.id == 200) {
|
||||
@ -93,7 +103,8 @@ public class GuiScreenChatOptions extends GuiScreen {
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
this.drawDefaultBackground();
|
||||
this.drawCenteredString(this.fontRenderer, this.theChatOptions, this.width / 2, 20, 16777215);
|
||||
this.drawCenteredString(this.fontRenderer, this.field_82268_n, this.width / 2, this.field_82269_o + 7, 16777215);
|
||||
this.drawCenteredString(this.fontRenderer, this.field_82268_n, this.width / 2, this.field_82269_o + 7,
|
||||
16777215);
|
||||
super.drawScreen(par1, par2, par3);
|
||||
}
|
||||
}
|
||||
|
297
src/main/java/net/minecraft/src/GuiSelectWorld.java
Normal file
297
src/main/java/net/minecraft/src/GuiSelectWorld.java
Normal file
@ -0,0 +1,297 @@
|
||||
package net.minecraft.src;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.lax1dude.eaglercraft.GuiScreenBackupWorld;
|
||||
import net.lax1dude.eaglercraft.GuiScreenCreateWorldSelection;
|
||||
import net.lax1dude.eaglercraft.GuiScreenSingleplayerNotImplemented;
|
||||
import net.lax1dude.eaglercraft.IntegratedServer;
|
||||
|
||||
public class GuiSelectWorld extends GuiScreen {
|
||||
/** simple date formater */
|
||||
private final DateFormat dateFormatter = new SimpleDateFormat();
|
||||
|
||||
/**
|
||||
* A reference to the screen object that created this. Used for navigating
|
||||
* between screens.
|
||||
*/
|
||||
protected GuiScreen parentScreen;
|
||||
|
||||
/** The title string that is displayed in the top-center of the screen. */
|
||||
protected String screenTitle = "Select world";
|
||||
|
||||
/** True if a world has been selected. */
|
||||
private boolean selected = false;
|
||||
|
||||
/** the currently selected world */
|
||||
private int selectedWorld;
|
||||
|
||||
/** The save list for the world selection screen */
|
||||
private List<SaveFormatComparator> saveList;
|
||||
private GuiWorldSlot worldSlotContainer;
|
||||
|
||||
/** E.g. World, Welt, Monde, Mundo */
|
||||
private String localizedWorldText;
|
||||
private String localizedMustConvertText;
|
||||
|
||||
/**
|
||||
* The game mode text that is displayed with each world on the world selection
|
||||
* list.
|
||||
*/
|
||||
private String[] localizedGameModeText = new String[3];
|
||||
|
||||
/** set to true if you arein the process of deleteing a world/save */
|
||||
private boolean deleting;
|
||||
|
||||
/** The delete button in the world selection GUI */
|
||||
private GuiButton buttonDelete;
|
||||
|
||||
/** the select button in the world selection gui */
|
||||
private GuiButton buttonSelect;
|
||||
|
||||
/** The rename button in the world selection GUI */
|
||||
private GuiButton buttonRename;
|
||||
private GuiButton buttonBackup;
|
||||
|
||||
private boolean waitingForWorlds = false;
|
||||
|
||||
public GuiSelectWorld(GuiScreen par1GuiScreen) {
|
||||
this.parentScreen = par1GuiScreen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the buttons (and other controls) to the screen in question.
|
||||
*/
|
||||
public void initGui() {
|
||||
StringTranslate var1 = StringTranslate.getInstance();
|
||||
this.screenTitle = var1.translateKey("selectWorld.title");
|
||||
this.saveList = new LinkedList();
|
||||
|
||||
waitingForWorlds = true;
|
||||
IntegratedServer.requestWorldList();
|
||||
|
||||
this.localizedWorldText = var1.translateKey("selectWorld.world");
|
||||
this.localizedMustConvertText = var1.translateKey("selectWorld.conversion");
|
||||
this.localizedGameModeText[EnumGameType.SURVIVAL.getID()] = var1.translateKey("gameMode.survival");
|
||||
this.localizedGameModeText[EnumGameType.CREATIVE.getID()] = var1.translateKey("gameMode.creative");
|
||||
this.localizedGameModeText[EnumGameType.ADVENTURE.getID()] = var1.translateKey("gameMode.adventure");
|
||||
this.worldSlotContainer = new GuiWorldSlot(this);
|
||||
this.worldSlotContainer.registerScrollButtons(this.buttonList, 4, 5);
|
||||
this.initButtons();
|
||||
}
|
||||
|
||||
public void updateScreen() {
|
||||
if(waitingForWorlds && IntegratedServer.getWorldList() != null) {
|
||||
waitingForWorlds = false;
|
||||
this.loadSaves();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* loads the saves
|
||||
*/
|
||||
private void loadSaves() {
|
||||
List<NBTTagCompound> levels = IntegratedServer.getWorldList();
|
||||
for(NBTTagCompound n : levels) {
|
||||
WorldInfo w = new WorldInfo(n.getCompoundTag("Data"));
|
||||
this.saveList.add(new SaveFormatComparator(n.getString("folderName"), w.getWorldName(), w.getLastTimePlayed(),
|
||||
w.getSizeOnDisk(), w.getGameType(), false, w.isHardcoreModeEnabled(), w.areCommandsAllowed(), n));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the file name of the specified save number
|
||||
*/
|
||||
protected String getSaveFileName(int par1) {
|
||||
return ((SaveFormatComparator) this.saveList.get(par1)).getFileName();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the name of the saved game
|
||||
*/
|
||||
protected String getSaveName(int par1) {
|
||||
String var2 = ((SaveFormatComparator) this.saveList.get(par1)).getDisplayName();
|
||||
|
||||
if (var2 == null || MathHelper.stringNullOrLengthZero(var2)) {
|
||||
StringTranslate var3 = StringTranslate.getInstance();
|
||||
var2 = var3.translateKey("selectWorld.world") + " " + (par1 + 1);
|
||||
}
|
||||
|
||||
return var2;
|
||||
}
|
||||
|
||||
/**
|
||||
* intilize the buttons for this GUI
|
||||
*/
|
||||
public void initButtons() {
|
||||
StringTranslate var1 = StringTranslate.getInstance();
|
||||
this.buttonList.add(this.buttonSelect = new GuiButton(1, this.width / 2 - 154, this.height - 52, 150, 20, var1.translateKey("selectWorld.select")));
|
||||
this.buttonList.add(new GuiButton(3, this.width / 2 + 4, this.height - 52, 150, 20, var1.translateKey("selectWorld.create")));
|
||||
this.buttonList.add(this.buttonRename = new GuiButton(6, this.width / 2 - 154, this.height - 28, 72, 20, var1.translateKey("selectWorld.rename")));
|
||||
this.buttonList.add(this.buttonDelete = new GuiButton(2, this.width / 2 - 76, this.height - 28, 72, 20, var1.translateKey("selectWorld.delete")));
|
||||
this.buttonList.add(this.buttonBackup = new GuiButton(7, this.width / 2 + 4, this.height - 28, 72, 20, var1.translateKey("selectWorld.backup")));
|
||||
this.buttonList.add(new GuiButton(0, this.width / 2 + 82, this.height - 28, 72, 20, var1.translateKey("gui.cancel")));
|
||||
this.buttonSelect.enabled = false;
|
||||
this.buttonDelete.enabled = false;
|
||||
this.buttonRename.enabled = false;
|
||||
this.buttonBackup.enabled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a control is clicked. This is the equivalent of
|
||||
* ActionListener.actionPerformed(ActionEvent e).
|
||||
*/
|
||||
protected void actionPerformed(GuiButton par1GuiButton) {
|
||||
if (par1GuiButton.enabled) {
|
||||
if (par1GuiButton.id == 2) {
|
||||
/*
|
||||
String var2 = this.getSaveName(this.selectedWorld);
|
||||
|
||||
if (var2 != null) {
|
||||
this.deleting = true;
|
||||
GuiYesNo var3 = getDeleteWorldScreen(this, var2, this.selectedWorld);
|
||||
this.mc.displayGuiScreen(var3);
|
||||
}
|
||||
*/
|
||||
this.mc.displayGuiScreen(new GuiScreenSingleplayerNotImplemented(this, "delete world"));
|
||||
} else if (par1GuiButton.id == 1) {
|
||||
this.selectWorld(this.selectedWorld);
|
||||
} else if (par1GuiButton.id == 3) {
|
||||
this.mc.displayGuiScreen(new GuiScreenCreateWorldSelection(this));
|
||||
} else if (par1GuiButton.id == 6) {
|
||||
this.mc.displayGuiScreen(new GuiRenameWorld(this, this.getSaveFileName(this.selectedWorld)));
|
||||
} else if (par1GuiButton.id == 0) {
|
||||
this.mc.displayGuiScreen(this.parentScreen);
|
||||
} else if (par1GuiButton.id == 7) {
|
||||
//GuiCreateWorld var5 = new GuiCreateWorld(this);
|
||||
//var5.func_82286_a(new WorldInfo(this.saveList.get(this.selectedWorld).levelDat));
|
||||
//this.mc.displayGuiScreen(var5);
|
||||
this.mc.displayGuiScreen(new GuiScreenBackupWorld(this, this.getSaveFileName(this.selectedWorld), 11111111l));
|
||||
} else {
|
||||
this.worldSlotContainer.actionPerformed(par1GuiButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the selected world.
|
||||
*/
|
||||
public void selectWorld(int par1) {
|
||||
this.mc.displayGuiScreen((GuiScreen) null);
|
||||
|
||||
if (!this.selected) {
|
||||
this.selected = true;
|
||||
String var2 = this.getSaveFileName(par1);
|
||||
|
||||
if (var2 == null) {
|
||||
var2 = "World" + par1;
|
||||
}
|
||||
|
||||
String var3 = this.getSaveName(par1);
|
||||
|
||||
if (var3 == null) {
|
||||
var3 = "World" + par1;
|
||||
}
|
||||
|
||||
this.mc.launchIntegratedServer(var2, var3, (WorldSettings) null);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void confirmClicked(boolean par1, int par2) {
|
||||
if (this.deleting) {
|
||||
this.deleting = false;
|
||||
/*
|
||||
if (par1) {
|
||||
waitingForWorlds = true;
|
||||
IntegratedServer.requestWorldList();
|
||||
}
|
||||
*/
|
||||
this.mc.displayGuiScreen(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the screen and all the components in it.
|
||||
*/
|
||||
public void drawScreen(int par1, int par2, float par3) {
|
||||
this.worldSlotContainer.drawScreen(par1, par2, par3);
|
||||
this.drawCenteredString(this.fontRenderer, this.screenTitle, this.width / 2, 20, 16777215);
|
||||
super.drawScreen(par1, par2, par3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a GuiYesNo screen with the warning, buttons, etc.
|
||||
*/
|
||||
public static GuiYesNo getDeleteWorldScreen(GuiScreen par0GuiScreen, String par1Str, int par2) {
|
||||
StringTranslate var3 = StringTranslate.getInstance();
|
||||
String var4 = var3.translateKey("selectWorld.deleteQuestion");
|
||||
String var5 = "\'" + par1Str + "\' " + var3.translateKey("selectWorld.deleteWarning");
|
||||
String var6 = var3.translateKey("selectWorld.deleteButton");
|
||||
String var7 = var3.translateKey("gui.cancel");
|
||||
GuiYesNo var8 = new GuiYesNo(par0GuiScreen, var4, var5, var6, var7, par2);
|
||||
return var8;
|
||||
}
|
||||
|
||||
static List getSize(GuiSelectWorld par0GuiSelectWorld) {
|
||||
return par0GuiSelectWorld.saveList;
|
||||
}
|
||||
|
||||
/**
|
||||
* called whenever an element in this gui is selected
|
||||
*/
|
||||
static int onElementSelected(GuiSelectWorld par0GuiSelectWorld, int par1) {
|
||||
return par0GuiSelectWorld.selectedWorld = par1;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the world currently selected
|
||||
*/
|
||||
static int getSelectedWorld(GuiSelectWorld par0GuiSelectWorld) {
|
||||
return par0GuiSelectWorld.selectedWorld;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the select button
|
||||
*/
|
||||
static GuiButton getSelectButton(GuiSelectWorld par0GuiSelectWorld) {
|
||||
return par0GuiSelectWorld.buttonSelect;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the rename button
|
||||
*/
|
||||
static GuiButton getRenameButton(GuiSelectWorld par0GuiSelectWorld) {
|
||||
return par0GuiSelectWorld.buttonDelete;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the delete button
|
||||
*/
|
||||
static GuiButton getDeleteButton(GuiSelectWorld par0GuiSelectWorld) {
|
||||
return par0GuiSelectWorld.buttonRename;
|
||||
}
|
||||
|
||||
static GuiButton func_82312_f(GuiSelectWorld par0GuiSelectWorld) {
|
||||
return par0GuiSelectWorld.buttonBackup;
|
||||
}
|
||||
|
||||
static String func_82313_g(GuiSelectWorld par0GuiSelectWorld) {
|
||||
return par0GuiSelectWorld.localizedWorldText;
|
||||
}
|
||||
|
||||
static DateFormat func_82315_h(GuiSelectWorld par0GuiSelectWorld) {
|
||||
return par0GuiSelectWorld.dateFormatter;
|
||||
}
|
||||
|
||||
static String func_82311_i(GuiSelectWorld par0GuiSelectWorld) {
|
||||
return par0GuiSelectWorld.localizedMustConvertText;
|
||||
}
|
||||
|
||||
static String[] func_82314_j(GuiSelectWorld par0GuiSelectWorld) {
|
||||
return par0GuiSelectWorld.localizedGameModeText;
|
||||
}
|
||||
}
|
92
src/main/java/net/minecraft/src/GuiWorldSlot.java
Normal file
92
src/main/java/net/minecraft/src/GuiWorldSlot.java
Normal file
@ -0,0 +1,92 @@
|
||||
package net.minecraft.src;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import net.lax1dude.eaglercraft.adapter.Tessellator;
|
||||
|
||||
class GuiWorldSlot extends GuiSlot {
|
||||
final GuiSelectWorld parentWorldGui;
|
||||
|
||||
public GuiWorldSlot(GuiSelectWorld par1GuiSelectWorld) {
|
||||
super(par1GuiSelectWorld.mc, par1GuiSelectWorld.width, par1GuiSelectWorld.height, 32,
|
||||
par1GuiSelectWorld.height - 64, 36);
|
||||
this.parentWorldGui = par1GuiSelectWorld;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size of the current slot list.
|
||||
*/
|
||||
protected int getSize() {
|
||||
return GuiSelectWorld.getSize(this.parentWorldGui).size();
|
||||
}
|
||||
|
||||
/**
|
||||
* the element in the slot that was clicked, boolean for wether it was double
|
||||
* clicked or not
|
||||
*/
|
||||
protected void elementClicked(int par1, boolean par2) {
|
||||
GuiSelectWorld.onElementSelected(this.parentWorldGui, par1);
|
||||
boolean var3 = GuiSelectWorld.getSelectedWorld(this.parentWorldGui) >= 0
|
||||
&& GuiSelectWorld.getSelectedWorld(this.parentWorldGui) < this.getSize();
|
||||
GuiSelectWorld.getSelectButton(this.parentWorldGui).enabled = var3;
|
||||
GuiSelectWorld.getRenameButton(this.parentWorldGui).enabled = var3;
|
||||
GuiSelectWorld.getDeleteButton(this.parentWorldGui).enabled = var3;
|
||||
GuiSelectWorld.func_82312_f(this.parentWorldGui).enabled = var3;
|
||||
|
||||
if (par2 && var3) {
|
||||
this.parentWorldGui.selectWorld(par1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns true if the element passed in is currently selected
|
||||
*/
|
||||
protected boolean isSelected(int par1) {
|
||||
return par1 == GuiSelectWorld.getSelectedWorld(this.parentWorldGui);
|
||||
}
|
||||
|
||||
/**
|
||||
* return the height of the content being scrolled
|
||||
*/
|
||||
protected int getContentHeight() {
|
||||
return GuiSelectWorld.getSize(this.parentWorldGui).size() * 36;
|
||||
}
|
||||
|
||||
protected void drawBackground() {
|
||||
this.parentWorldGui.drawDefaultBackground();
|
||||
}
|
||||
|
||||
protected void drawSlot(int par1, int par2, int par3, int par4, Tessellator par5Tessellator) {
|
||||
SaveFormatComparator var6 = (SaveFormatComparator) GuiSelectWorld.getSize(this.parentWorldGui).get(par1);
|
||||
String var7 = var6.getDisplayName();
|
||||
|
||||
if (var7 == null || MathHelper.stringNullOrLengthZero(var7)) {
|
||||
var7 = GuiSelectWorld.func_82313_g(this.parentWorldGui) + " " + (par1 + 1);
|
||||
}
|
||||
|
||||
String var8 = var6.getFileName();
|
||||
var8 = var8 + " ("
|
||||
+ GuiSelectWorld.func_82315_h(this.parentWorldGui).format(new Date(var6.getLastTimePlayed()));
|
||||
var8 = var8 + ")";
|
||||
String var9 = "";
|
||||
|
||||
if (var6.requiresConversion()) {
|
||||
var9 = GuiSelectWorld.func_82311_i(this.parentWorldGui) + " " + var9;
|
||||
} else {
|
||||
var9 = GuiSelectWorld.func_82314_j(this.parentWorldGui)[var6.getEnumGameType().getID()];
|
||||
|
||||
if (var6.isHardcoreModeEnabled()) {
|
||||
var9 = EnumChatFormatting.DARK_RED + StatCollector.translateToLocal("gameMode.hardcore")
|
||||
+ EnumChatFormatting.RESET;
|
||||
}
|
||||
|
||||
if (var6.getCheatsEnabled()) {
|
||||
var9 = var9 + ", " + StatCollector.translateToLocal("selectWorld.cheats");
|
||||
}
|
||||
}
|
||||
|
||||
this.parentWorldGui.drawString(this.parentWorldGui.fontRenderer, var7, par2 + 2, par3 + 1, 16777215);
|
||||
this.parentWorldGui.drawString(this.parentWorldGui.fontRenderer, var8, par2 + 2, par3 + 12, 8421504);
|
||||
this.parentWorldGui.drawString(this.parentWorldGui.fontRenderer, var9, par2 + 2, par3 + 12 + 10, 8421504);
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ import java.util.Random;
|
||||
|
||||
import net.lax1dude.eaglercraft.DefaultSkinRenderer;
|
||||
import net.lax1dude.eaglercraft.EaglerAdapter;
|
||||
import net.lax1dude.eaglercraft.IntegratedServer;
|
||||
import net.lax1dude.eaglercraft.WebsocketNetworkManager;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
@ -48,6 +49,11 @@ public class NetClientHandler extends NetHandler {
|
||||
/** RNG. */
|
||||
Random rand = new Random();
|
||||
|
||||
public NetClientHandler(Minecraft par1Minecraft, String channel) throws IOException {
|
||||
this.mc = par1Minecraft;
|
||||
this.netManager = IntegratedServer.openConnection(channel, this);
|
||||
}
|
||||
|
||||
public NetClientHandler(Minecraft par1Minecraft, String par2Str, int par3) throws IOException {
|
||||
this.mc = par1Minecraft;
|
||||
this.netManager = new WebsocketNetworkManager(par2Str, null, this);
|
||||
@ -454,7 +460,7 @@ public class NetClientHandler extends NetHandler {
|
||||
this.disconnected = true;
|
||||
this.mc.loadWorld((WorldClient) null);
|
||||
|
||||
this.mc.displayGuiScreen(new GuiDisconnected(new GuiMultiplayer(new GuiMainMenu()), "disconnect.disconnected", "disconnect.genericReason", new Object[] { par1Packet255KickDisconnect.reason }));
|
||||
this.mc.stopServerAndDisplayGuiScreen(new GuiDisconnected(new GuiMultiplayer(new GuiMainMenu()), "disconnect.disconnected", "disconnect.genericReason", new Object[] { par1Packet255KickDisconnect.reason }));
|
||||
|
||||
}
|
||||
|
||||
@ -463,7 +469,7 @@ public class NetClientHandler extends NetHandler {
|
||||
this.disconnected = true;
|
||||
this.mc.loadWorld((WorldClient) null);
|
||||
|
||||
this.mc.displayGuiScreen(new GuiDisconnected(new GuiMultiplayer(new GuiMainMenu()), "disconnect.lost", par1Str, par2ArrayOfObj));
|
||||
this.mc.stopServerAndDisplayGuiScreen(new GuiDisconnected(new GuiMultiplayer(new GuiMainMenu()), "disconnect.lost", par1Str, par2ArrayOfObj));
|
||||
}
|
||||
}
|
||||
|
||||
|
82
src/main/java/net/minecraft/src/SaveFormatComparator.java
Normal file
82
src/main/java/net/minecraft/src/SaveFormatComparator.java
Normal file
@ -0,0 +1,82 @@
|
||||
package net.minecraft.src;
|
||||
|
||||
public class SaveFormatComparator implements Comparable {
|
||||
/** the file name of this save */
|
||||
private final String fileName;
|
||||
|
||||
/** the displayed name of this save file */
|
||||
private final String displayName;
|
||||
private final long lastTimePlayed;
|
||||
private final long sizeOnDisk;
|
||||
private final boolean requiresConversion;
|
||||
|
||||
/** Instance of EnumGameType. */
|
||||
private final EnumGameType theEnumGameType;
|
||||
private final boolean hardcore;
|
||||
private final boolean cheatsEnabled;
|
||||
|
||||
public final NBTTagCompound levelDat;
|
||||
|
||||
public SaveFormatComparator(String par1Str, String par2Str, long par3, long par5, EnumGameType par7EnumGameType,
|
||||
boolean par8, boolean par9, boolean par10, NBTTagCompound levelDat) {
|
||||
this.fileName = par1Str;
|
||||
this.displayName = par2Str;
|
||||
this.lastTimePlayed = par3;
|
||||
this.sizeOnDisk = par5;
|
||||
this.theEnumGameType = par7EnumGameType;
|
||||
this.requiresConversion = par8;
|
||||
this.hardcore = par9;
|
||||
this.cheatsEnabled = par10;
|
||||
this.levelDat = levelDat;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the file name
|
||||
*/
|
||||
public String getFileName() {
|
||||
return this.fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the display name of the save
|
||||
*/
|
||||
public String getDisplayName() {
|
||||
return this.displayName;
|
||||
}
|
||||
|
||||
public boolean requiresConversion() {
|
||||
return this.requiresConversion;
|
||||
}
|
||||
|
||||
public long getLastTimePlayed() {
|
||||
return this.lastTimePlayed;
|
||||
}
|
||||
|
||||
public int compareTo(SaveFormatComparator par1SaveFormatComparator) {
|
||||
return this.lastTimePlayed < par1SaveFormatComparator.lastTimePlayed ? 1
|
||||
: (this.lastTimePlayed > par1SaveFormatComparator.lastTimePlayed ? -1
|
||||
: this.fileName.compareTo(par1SaveFormatComparator.fileName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the EnumGameType.
|
||||
*/
|
||||
public EnumGameType getEnumGameType() {
|
||||
return this.theEnumGameType;
|
||||
}
|
||||
|
||||
public boolean isHardcoreModeEnabled() {
|
||||
return this.hardcore;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if cheats are enabled for this world
|
||||
*/
|
||||
public boolean getCheatsEnabled() {
|
||||
return this.cheatsEnabled;
|
||||
}
|
||||
|
||||
public int compareTo(Object par1Obj) {
|
||||
return this.compareTo((SaveFormatComparator) par1Obj);
|
||||
}
|
||||
}
|
@ -484,6 +484,13 @@ public class WorldInfo {
|
||||
public void setServerInitialized(boolean par1) {
|
||||
this.initialized = par1;
|
||||
}
|
||||
|
||||
/**
|
||||
* for eaglercraft IPC
|
||||
*/
|
||||
public int getIPCGamemode() {
|
||||
return this.hardcore ? 2 : (this.getGameType().isCreative() ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the GameRules class Instance.
|
||||
|
@ -103,6 +103,13 @@ public final class WorldSettings {
|
||||
public boolean areCommandsAllowed() {
|
||||
return this.commandsAllowed;
|
||||
}
|
||||
|
||||
/**
|
||||
* for eaglercraft IPC
|
||||
*/
|
||||
public int getIPCGamemode() {
|
||||
return this.hardcoreEnabled ? 2 : (this.getGameType().isCreative() ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the GameType by ID
|
||||
|
@ -8,16 +8,18 @@ import java.nio.IntBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.teavm.interop.Async;
|
||||
import org.teavm.interop.AsyncCallback;
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.JSFunctor;
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.ajax.ReadyStateChangeHandler;
|
||||
import org.teavm.jso.ajax.XMLHttpRequest;
|
||||
import org.teavm.jso.browser.TimerHandler;
|
||||
import org.teavm.jso.browser.Window;
|
||||
import org.teavm.jso.core.JSNumber;
|
||||
import org.teavm.jso.dom.events.ErrorEvent;
|
||||
import org.teavm.jso.dom.events.EventListener;
|
||||
import org.teavm.jso.dom.events.KeyboardEvent;
|
||||
import org.teavm.jso.dom.events.MessageEvent;
|
||||
@ -48,11 +50,13 @@ import org.teavm.jso.webgl.WebGLTexture;
|
||||
import org.teavm.jso.webgl.WebGLUniformLocation;
|
||||
import org.teavm.jso.websocket.CloseEvent;
|
||||
import org.teavm.jso.websocket.WebSocket;
|
||||
import org.teavm.jso.workers.Worker;
|
||||
|
||||
import net.lax1dude.eaglercraft.AssetRepository;
|
||||
import net.lax1dude.eaglercraft.Base64;
|
||||
import net.lax1dude.eaglercraft.EarlyLoadScreen;
|
||||
import net.lax1dude.eaglercraft.LocalStorageManager;
|
||||
import net.lax1dude.eaglercraft.PKT;
|
||||
import net.lax1dude.eaglercraft.adapter.teavm.WebGLQuery;
|
||||
import net.lax1dude.eaglercraft.adapter.teavm.WebGLVertexArray;
|
||||
import net.minecraft.src.MathHelper;
|
||||
@ -1567,5 +1571,125 @@ public class EaglerAdapterImpl2 {
|
||||
private static int remapKey(int k) {
|
||||
return (k > LWJGLKeyCodes.length || k < 0) ? -1 : LWJGLKeyCodes[k];
|
||||
}
|
||||
|
||||
|
||||
public static final boolean isIntegratedServerAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@JSFunctor
|
||||
private static interface WorkerBinaryPacketHandler extends JSObject {
|
||||
public void onMessage(String channel, ArrayBuffer buf);
|
||||
}
|
||||
|
||||
private static final HashMap<String,List<PKT>> workerMessageQueue = new HashMap();
|
||||
|
||||
private static Worker server = null;
|
||||
private static boolean serverAlive = false;
|
||||
|
||||
private static class WorkerBinaryPacketHandlerImpl implements WorkerBinaryPacketHandler {
|
||||
|
||||
public void onMessage(String channel, ArrayBuffer buf) {
|
||||
if(channel == null) {
|
||||
System.err.println("Recieved IPC packet with null channel");
|
||||
return;
|
||||
}
|
||||
|
||||
serverAlive = true;
|
||||
synchronized(workerMessageQueue) {
|
||||
List<PKT> existingQueue = workerMessageQueue.get(channel);
|
||||
|
||||
if(existingQueue == null) {
|
||||
System.err.println("Recieved IPC packet with unknown '" + channel + "' channel");
|
||||
return;
|
||||
}
|
||||
|
||||
if(buf == null) {
|
||||
System.err.println("Recieved IPC packet with null buffer");
|
||||
return;
|
||||
}
|
||||
|
||||
Uint8Array a = Uint8Array.create(buf);
|
||||
byte[] pkt = new byte[a.getLength()];
|
||||
for(int i = 0; i < pkt.length; ++i) {
|
||||
pkt[i] = (byte) a.get(i);
|
||||
}
|
||||
|
||||
existingQueue.add(new PKT(channel, pkt));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@JSBody(params = { "w", "wb" }, script = "w.onmessage = function(o) { wb(o.data.ch, o.data.dat); };")
|
||||
private static native void registerPacketHandler(Worker w, WorkerBinaryPacketHandler wb);
|
||||
|
||||
@JSBody(params = { "w", "ch", "dat" }, script = "w.postMessage({ ch: ch, dat : dat });")
|
||||
private static native void sendWorkerPacket(Worker w, String channel, ArrayBuffer arr);
|
||||
|
||||
public static final void beginLoadingIntegratedServer() {
|
||||
if(server != null) {
|
||||
server.terminate();
|
||||
}
|
||||
workerMessageQueue.put("IPC", new LinkedList<PKT>());
|
||||
server = Worker.create("bootstrap.js");
|
||||
server.onError(new EventListener<ErrorEvent>() {
|
||||
@Override
|
||||
public void handleEvent(ErrorEvent evt) {
|
||||
System.err.println("Worker Error: " + evt.getError());
|
||||
}
|
||||
});
|
||||
registerPacketHandler(server, new WorkerBinaryPacketHandlerImpl());
|
||||
}
|
||||
|
||||
public static final boolean isIntegratedServerAlive() {
|
||||
return serverAlive && server != null;
|
||||
}
|
||||
|
||||
public static final void terminateIntegratedServer() {
|
||||
if(server != null) {
|
||||
server.terminate();
|
||||
server = null;
|
||||
serverAlive = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static final void sendToIntegratedServer(String channel, byte[] pkt) {
|
||||
ArrayBuffer arb = ArrayBuffer.create(pkt.length);
|
||||
Uint8Array ar = Uint8Array.create(arb);
|
||||
ar.set(pkt);
|
||||
sendWorkerPacket(server, channel, arb);
|
||||
//System.out.println("[Client][WRITE][" + channel + "]: " + pkt.length);
|
||||
}
|
||||
|
||||
public static final void enableChannel(String channel) {
|
||||
synchronized(workerMessageQueue) {
|
||||
if(workerMessageQueue.containsKey(channel)) {
|
||||
System.err.println("Tried to enable existing channel '" + channel + "' again");
|
||||
}else {
|
||||
System.out.println("[Client][ENABLE][" + channel + "]");
|
||||
workerMessageQueue.put(channel, new LinkedList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final void disableChannel(String channel) {
|
||||
synchronized(workerMessageQueue) {
|
||||
if(workerMessageQueue.remove(channel) == null) {
|
||||
System.err.println("Tried to disable unknown channel '" + channel + "'");
|
||||
}
|
||||
System.out.println("[Client][DISABLE][" + channel + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public static final PKT recieveFromIntegratedServer(String channel) {
|
||||
synchronized(workerMessageQueue) {
|
||||
List<PKT> list = workerMessageQueue.get(channel);
|
||||
if(list == null) {
|
||||
System.err.println("Tried to read from unknown channel '" + channel + "'");
|
||||
return null;
|
||||
}else {
|
||||
return list.size() > 0 ? list.remove(0) : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user