Delete stuff (maybe the last one)
This commit is contained in:
parent
97644e0dc9
commit
56e6493c27
@ -1,164 +0,0 @@
|
||||
/*
|
||||
#######################################################################
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# Version 2, December 2004 #
|
||||
# #
|
||||
# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> #
|
||||
# #
|
||||
# Everyone is permitted to copy and distribute verbatim or modified #
|
||||
# copies of this license document, and changing it is allowed as long #
|
||||
# as the name is changed. #
|
||||
# #
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION #
|
||||
# #
|
||||
# 0. You just DO WHAT THE FUCK YOU WANT TO. #
|
||||
# #
|
||||
#######################################################################
|
||||
*/
|
||||
|
||||
package morlok8k.MinecraftLandGenerator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jnbt.CompoundTag;
|
||||
import org.jnbt.IntTag;
|
||||
import org.jnbt.LongTag;
|
||||
import org.jnbt.NBTInputStream;
|
||||
import org.jnbt.NBTOutputStream;
|
||||
import org.jnbt.Tag;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author morlok8k
|
||||
*/
|
||||
public class SpawnPoint {
|
||||
|
||||
//TODO: update this
|
||||
/**
|
||||
* @param level
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @author Corrodias
|
||||
*/
|
||||
protected static Vector3i getSpawn(final File level) throws IOException {
|
||||
try {
|
||||
final NBTInputStream input = new NBTInputStream(new FileInputStream(level));
|
||||
final CompoundTag originalTopLevelTag = (CompoundTag) input.readTag();
|
||||
input.close();
|
||||
|
||||
final Map<String, Tag> originalData =
|
||||
((CompoundTag) originalTopLevelTag.getValue().get("Data")).getValue();
|
||||
// This is our map of data. It is an unmodifiable map, for some
|
||||
// reason, so we have to make a copy.
|
||||
final Map<String, Tag> newData = new LinkedHashMap<>(originalData);
|
||||
// .get() a couple of values, just to make sure we're dealing with a
|
||||
// valid level file, here. Good for debugging, too.
|
||||
final IntTag spawnX = (IntTag) newData.get("SpawnX");
|
||||
final IntTag spawnY = (IntTag) newData.get("SpawnY");
|
||||
final IntTag spawnZ = (IntTag) newData.get("SpawnZ");
|
||||
|
||||
final LongTag Seed = (LongTag) newData.get("RandomSeed");
|
||||
var.randomSeed = Seed.getValue();
|
||||
System.out.println("Seed: " + var.randomSeed); // lets output the seed, cause why not?
|
||||
|
||||
final Vector3i ret =
|
||||
new Vector3i(spawnX.getValue(), spawnY.getValue(), spawnZ.getValue());
|
||||
return ret;
|
||||
} catch (final ClassCastException ex) {
|
||||
throw new IOException("Invalid level format.");
|
||||
} catch (final NullPointerException ex) {
|
||||
throw new IOException("Invalid level format.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the spawn point in the given Alpha/Beta level to the given coordinates.<br>
|
||||
* Note that, in Minecraft levels, the Y coordinate is height.<br>
|
||||
* (We picture maps from above, but the game was made from a different perspective)
|
||||
*
|
||||
* @param level
|
||||
* the level file to change the spawn point in
|
||||
* @param xyz
|
||||
* the Coordinates of the spawn point
|
||||
* @throws IOException
|
||||
* if there are any problems reading/writing the file
|
||||
* @author Corrodias
|
||||
*/
|
||||
protected static void setSpawn(final File level, final Vector3i xyz) throws IOException {
|
||||
|
||||
try {
|
||||
final NBTInputStream input = new NBTInputStream(new FileInputStream(level));
|
||||
final CompoundTag originalTopLevelTag = (CompoundTag) input.readTag();
|
||||
input.close();
|
||||
|
||||
//@formatter:off
|
||||
|
||||
//Note: The Following Information is Old (from 2010), compared to the Data inside a current "level.dat".
|
||||
//However, What we look at (SpawnX,Y,Z and RandomSeed) have not changed.
|
||||
|
||||
/* <editor-fold defaultstate="collapsed" desc="structure">
|
||||
* Structure:
|
||||
*
|
||||
*TAG_Compound("Data"): World data.
|
||||
* * TAG_Long("Time"): Stores the current "time of day" in ticks. There are 20 ticks per real-life second, and 24000 ticks per Minecraft day, making the day length 20 minutes. 0 appears to be sunrise, 12000 sunset and 24000 sunrise again.
|
||||
* * TAG_Long("LastPlayed"): Stores the Unix time stamp (in milliseconds) when the player saved the game.
|
||||
* * TAG_Compound("Player"): Player entity information. See Entity Format and Mob Entity Format for details. Has additional elements:
|
||||
* o TAG_List("Inventory"): Each TAG_Compound in this list defines an item the player is carrying, holding, or wearing as armor.
|
||||
* + TAG_Compound: Inventory item data
|
||||
* # TAG_Short("id"): Item or Block ID.
|
||||
* # TAG_Short("Damage"): The amount of wear each item has suffered. 0 means undamaged. When the Damage exceeds the item's durability, it breaks and disappears. Only tools and armor accumulate damage normally.
|
||||
* # TAG_Byte("Count"): Number of items stacked in this inventory slot. Any item can be stacked, including tools, armor, and vehicles. Range is 1-255. Values above 127 are not displayed in-game.
|
||||
* # TAG_Byte("Slot"): Indicates which inventory slot this item is in.
|
||||
* o TAG_Int("Score"): Current score, doesn't appear to be implemented yet. Always 0.
|
||||
* * TAG_Int("SpawnX"): X coordinate of the player's spawn position. Default is 0.
|
||||
* * TAG_Int("SpawnY"): Y coordinate of the player's spawn position. Default is 64.
|
||||
* * TAG_Int("SpawnZ"): Z coordinate of the player's spawn position. Default is 0.
|
||||
* * TAG_Byte("SnowCovered"): 1 enables, 0 disables, see Winter Mode
|
||||
* * TAG_Long("SizeOnDisk"): Estimated size of the entire world in bytes.
|
||||
* * TAG_Long("RandomSeed"): Random number providing the Random Seed for the terrain.
|
||||
* </editor-fold>
|
||||
*/
|
||||
|
||||
//@formatter:on
|
||||
|
||||
final Map<String, Tag> originalData =
|
||||
((CompoundTag) originalTopLevelTag.getValue().get("Data")).getValue();
|
||||
// This is our map of data. It is an unmodifiable map, for some reason, so we have to make a copy.
|
||||
final Map<String, Tag> newData = new LinkedHashMap<>(originalData);
|
||||
|
||||
// .get() a couple of values, just to make sure we're dealing with a valid level file, here. Good for debugging, too.
|
||||
@SuppressWarnings("unused")
|
||||
final IntTag spawnX = (IntTag) newData.get("SpawnX"); // we never use these... Its only here for potential debugging.
|
||||
@SuppressWarnings("unused")
|
||||
final IntTag spawnY = (IntTag) newData.get("SpawnY"); // but whatever... so I (Morlok8k) suppressed these warnings.
|
||||
@SuppressWarnings("unused")
|
||||
final IntTag spawnZ = (IntTag) newData.get("SpawnZ"); // I don't want to remove existing code, either by myself (Morlok8k) or Corrodias
|
||||
|
||||
newData.put("SpawnX", new IntTag("SpawnX", xyz.x)); // pulling the data out of the Coordinates,
|
||||
newData.put("SpawnY", new IntTag("SpawnY", xyz.y)); // and putting it into our IntTag's
|
||||
newData.put("SpawnZ", new IntTag("SpawnZ", xyz.z));
|
||||
|
||||
// Again, we can't modify the data map in the old Tag, so we have to make a new one.
|
||||
final CompoundTag newDataTag = new CompoundTag("Data", newData);
|
||||
final Map<String, Tag> newTopLevelMap = new HashMap<>(1);
|
||||
newTopLevelMap.put("Data", newDataTag);
|
||||
final CompoundTag newTopLevelTag = new CompoundTag("", newTopLevelMap);
|
||||
|
||||
final NBTOutputStream output = new NBTOutputStream(new FileOutputStream(level));
|
||||
output.writeTag(newTopLevelTag);
|
||||
output.close();
|
||||
} catch (final ClassCastException ex) {
|
||||
throw new IOException("Invalid level format.");
|
||||
} catch (final NullPointerException ex) {
|
||||
throw new IOException("Invalid level format.");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,267 +0,0 @@
|
||||
/*
|
||||
#######################################################################
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# Version 2, December 2004 #
|
||||
# #
|
||||
# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> #
|
||||
# #
|
||||
# Everyone is permitted to copy and distribute verbatim or modified #
|
||||
# copies of this license document, and changing it is allowed as long #
|
||||
# as the name is changed. #
|
||||
# #
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION #
|
||||
# #
|
||||
# 0. You just DO WHAT THE FUCK YOU WANT TO. #
|
||||
# #
|
||||
#######################################################################
|
||||
*/
|
||||
|
||||
package morlok8k.MinecraftLandGenerator;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* Program Initialization code. placed here so both CLI and GUI can use it.
|
||||
*
|
||||
* @author morlok8k
|
||||
*
|
||||
*/
|
||||
public class Startup {
|
||||
private static Log log = LogFactory.getLog(Main.class);
|
||||
|
||||
/**
|
||||
*
|
||||
* CLI only: Reads arguments from command line
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean programArguments() {
|
||||
|
||||
// =====================================================================
|
||||
// INSTRUCTIONS
|
||||
// =====================================================================
|
||||
|
||||
// check for -nowait, and remove from arguments if it exists. (we remove it for compatibility reasons with the rest of the existing code.)
|
||||
// (-nowait is the only universal switch - it can be used with anything. its basically for scripting, as it turns off the 10sec wait for human readability)
|
||||
String[] newArgs = new String[var.args.length];
|
||||
newArgs = var.args;
|
||||
newArgs = StringArrayParse.Parse(newArgs, "-n"); //parse out -n
|
||||
newArgs = StringArrayParse.Parse(newArgs, "-nowait"); //parse out -nowait
|
||||
if (!(var.args.equals(newArgs))) { //do the freshly parsed args match the original?
|
||||
var.dontWait = true; //if not, we dont wait for anything!
|
||||
var.args = newArgs; //use the freshly parsed args for everything else now...
|
||||
log.info("Notice: Not waiting for anything...");
|
||||
}
|
||||
|
||||
if (var.args.length == 0) { //we didn't find a an X and Z size, so lets ask for one.
|
||||
log.info("Please Enter the size of world you want. Example: X:1000 Z:1000");
|
||||
log.info(var.MLG + "X:");
|
||||
var.xRange = Input_CLI.getInt("X:");
|
||||
log.info(var.MLG + "Z:");
|
||||
var.zRange = Input_CLI.getInt("Z:");
|
||||
var.args = new String[] { String.valueOf(var.xRange), String.valueOf(var.zRange) };
|
||||
|
||||
}
|
||||
|
||||
if (var.args[0].equalsIgnoreCase("-version") || var.args[0].equalsIgnoreCase("-help")
|
||||
|| var.args[0].equals("/?")) {
|
||||
|
||||
Readme_and_HelpInfo.showHelp(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// =====================================================================
|
||||
// STARTUP AND CONFIG
|
||||
// =====================================================================
|
||||
|
||||
// the arguments are apparently okay so far. parse the conf file.
|
||||
if (var.args[0].equalsIgnoreCase("-conf")) {
|
||||
|
||||
if (var.args.length == 2) {
|
||||
if (var.args[1].equalsIgnoreCase("download")) {
|
||||
final boolean fileSuccess =
|
||||
DownloadFile.downloadFile(var.github_MLG_Conf_URL, var.testing);
|
||||
if (fileSuccess) {
|
||||
log.info(var.MinecraftLandGeneratorConf + " file downloaded.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FileWrite.saveConf(true); //new conf file
|
||||
return true;
|
||||
|
||||
} else if (var.args[0].equalsIgnoreCase("-ps")
|
||||
|| var.args[0].equalsIgnoreCase("-printspawn")) {
|
||||
// okay, sorry, this is an ugly hack, but it's just a last-minute feature.
|
||||
Misc.printSpawn();
|
||||
return true;
|
||||
} else if (var.args[0].equalsIgnoreCase("-build")) {
|
||||
Update.buildID(false);
|
||||
return true;
|
||||
} else if (var.args[0].equalsIgnoreCase("-update")) {
|
||||
Update.updateMLG();
|
||||
return true;
|
||||
} else if (var.args[0].equalsIgnoreCase("-readme")) {
|
||||
|
||||
if (var.args.length == 2) {
|
||||
Readme_and_HelpInfo.readMe(var.args[1]);
|
||||
} else {
|
||||
Readme_and_HelpInfo.readMe(null);
|
||||
}
|
||||
return true;
|
||||
} else if (var.args[0].equalsIgnoreCase("-downloadfile")) {
|
||||
if (var.args.length == 2) {
|
||||
DownloadFile.downloadFile(var.args[1], true);
|
||||
} else {
|
||||
log.info("No File to Download!");
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if (var.args[0].equalsIgnoreCase("-downloadlist")) {
|
||||
|
||||
if (var.args.length == 2) {
|
||||
String origMD5 = "";
|
||||
String recheckMD5 = "";
|
||||
|
||||
try {
|
||||
final File config = new File(var.args[1]);
|
||||
try {
|
||||
origMD5 = MD5.fileMD5(config.toString());
|
||||
} catch (final NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
final BufferedReader in = new BufferedReader(new FileReader(config));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
if (line.contains("###RECHECK###")) {
|
||||
var.recheckFlag = !var.recheckFlag;
|
||||
} else {
|
||||
DownloadFile.downloadFile(line, true);
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
|
||||
if (var.recheckFlag == true) { // the first line is always the location of this file. the second is the recheck flag, if we want to.
|
||||
try {
|
||||
recheckMD5 = MD5.fileMD5(config.toString());
|
||||
} catch (final NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (!origMD5.contentEquals(recheckMD5)) {
|
||||
final BufferedReader in_recheck =
|
||||
new BufferedReader(new FileReader(config));
|
||||
String line_recheck;
|
||||
while ((line_recheck = in_recheck.readLine()) != null) {
|
||||
if (line_recheck.contains("###RECHECK###")) {
|
||||
var.recheckFlag = !var.recheckFlag;
|
||||
} else {
|
||||
DownloadFile.downloadFile(line_recheck, true);
|
||||
}
|
||||
}
|
||||
in_recheck.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (final FileNotFoundException ex) {
|
||||
System.err.println(var.args[1] + " - File not found");
|
||||
return true;
|
||||
} catch (final IOException ex) {
|
||||
System.err.println(var.args[1] + " - Could not read file.");
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
log.info("No File with links!");
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if (var.args.length == 1) {
|
||||
log.info("For help, use java -jar " + var.MLGFileNameShort + " -help");
|
||||
return true;
|
||||
}
|
||||
|
||||
// ARGUMENTS
|
||||
try {
|
||||
var.xRange = Integer.parseInt(var.args[0]);
|
||||
var.zRange = Integer.parseInt(var.args[1]);
|
||||
|
||||
if ((var.xRange < 1000) && (var.xRange != 0)) {
|
||||
var.xRange = 1000; //if less than 1000, (and not 0) set to 1000 (Calculations don't work well on very small maps)
|
||||
log.error("X size too small - Changing X to 1000");
|
||||
}
|
||||
if ((var.zRange < 1000) && (var.zRange != 0)) {
|
||||
var.zRange = 1000;
|
||||
log.error("Z size too small - Changing Z to 1000");
|
||||
}
|
||||
|
||||
} catch (final NumberFormatException ex) {
|
||||
log.error("Invalid X or Z argument.");
|
||||
log.error("Please Enter the size of world you want. Example: X:1000 Z:1000");
|
||||
var.xRange = Input_CLI.getInt("X:");
|
||||
var.zRange = Input_CLI.getInt("Z:");
|
||||
|
||||
//return;
|
||||
}
|
||||
|
||||
// This is embarrassing. Don't look.
|
||||
try {
|
||||
for (int i = 0; i < (var.args.length - 2); i++) {
|
||||
final String nextSwitch = var.args[i + 2].toLowerCase();
|
||||
if (nextSwitch.equals("-verbose") || nextSwitch.equals("-v")) {
|
||||
var.verbose = true;
|
||||
log.info("Notice: Verbose Mode");
|
||||
|
||||
} else if (nextSwitch.startsWith("-i")) {
|
||||
var.increment = Integer.parseInt(var.args[i + 2].substring(2));
|
||||
log.info("Notice: Non-Default Increment: " + var.increment);
|
||||
|
||||
} else if (nextSwitch.startsWith("-w")) {
|
||||
var.ignoreWarnings = true;
|
||||
log.info("Notice: Warnings from Server are Ignored");
|
||||
|
||||
} else if (nextSwitch.equals("-alt") || nextSwitch.equals("-a")) {
|
||||
var.alternate = true;
|
||||
log.info("Notice: Using Alternate Launching");
|
||||
|
||||
} else if (nextSwitch.equals("-chunk") || nextSwitch.equals("-c")) {
|
||||
var.useChunks = true;
|
||||
log.info("Notice: Using Chunks instead of Regions");
|
||||
|
||||
} else if (nextSwitch.startsWith("-x")) {
|
||||
var.xOffset = Integer.valueOf(var.args[i + 2].substring(2));
|
||||
log.info("Notice: X Offset: " + var.xOffset);
|
||||
|
||||
} else if (nextSwitch.startsWith("-y") || nextSwitch.startsWith("-z")) { //NOTE: "-y" is just here for backwards compatibility
|
||||
var.zOffset = Integer.valueOf(var.args[i + 2].substring(2));
|
||||
log.info("Notice: Z Offset: " + var.zOffset);
|
||||
if (nextSwitch.startsWith("-y")) {
|
||||
log.info(
|
||||
"Notice: MLG now uses Z instead of Y. Please use the -z switch instead");
|
||||
}
|
||||
|
||||
} else {
|
||||
var.serverPath = var.args[i + 2];
|
||||
log.info("Notice: Attempting to use Alternate Server:" + var.serverPath);
|
||||
}
|
||||
}
|
||||
} catch (final NumberFormatException ex) {
|
||||
log.error("Invalid switch value.");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false; // success!
|
||||
}
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
#######################################################################
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# Version 2, December 2004 #
|
||||
# #
|
||||
# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> #
|
||||
# #
|
||||
# Everyone is permitted to copy and distribute verbatim or modified #
|
||||
# copies of this license document, and changing it is allowed as long #
|
||||
# as the name is changed. #
|
||||
# #
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION #
|
||||
# #
|
||||
# 0. You just DO WHAT THE FUCK YOU WANT TO. #
|
||||
# #
|
||||
#######################################################################
|
||||
*/
|
||||
|
||||
package morlok8k.MinecraftLandGenerator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author morlok8k
|
||||
*/
|
||||
public class StringArrayParse {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array
|
||||
* @param ParseOut
|
||||
* @return
|
||||
*/
|
||||
public static String[] Parse(final String[] array, final String ParseOut) {
|
||||
|
||||
//There is probably a better way to do this.
|
||||
//We input a String[] array, and a String.
|
||||
//if the String matches one inside the array, it gets "deleted"
|
||||
//(actually a new String[] without it is returned)
|
||||
|
||||
final String[] workingArray = new String[array.length]; //workingArray is our working array. we don't modify the original.
|
||||
|
||||
boolean removed = false;
|
||||
|
||||
try {
|
||||
|
||||
int ii = 0;
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
workingArray[ii] = array[i]; // copy
|
||||
if ((array[i].contains(ParseOut)) && (removed == false)) { // we only remove the first match!
|
||||
workingArray[ii] = null; // we make sure this is set to null (if the last arg is the match it would otherwise be copied... granted it would later be removed... but whatever.)
|
||||
ii = ii - 1; // we just simply move back one
|
||||
removed = true; // set our flag
|
||||
}
|
||||
ii++;
|
||||
}
|
||||
|
||||
} catch (final Exception ex) {
|
||||
System.err.println("Something went wrong! (Parsing Error?)");
|
||||
ex.fillInStackTrace();
|
||||
return array; //we got some error... return the original array, just in case.
|
||||
}
|
||||
|
||||
if (removed) {
|
||||
// at this point, workingArray has null for its last string. we need to remove it.
|
||||
final String[] returnArray = new String[workingArray.length - 1];
|
||||
for (int i = 0; i < returnArray.length; i++) {
|
||||
returnArray[i] = workingArray[i];
|
||||
}
|
||||
|
||||
return returnArray;
|
||||
}
|
||||
return array; //no changes have been done, return the original array
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user