convert to java as per mD

This commit is contained in:
Progwml6 committed 2013-12-05 00:04:18 -05:00
1 parent e4b31e06be
commit 881febd571
22 files changed
+559 -392

No files matched your search

+3 -9
View File
@@ -29,12 +29,8 @@ repositories {
url 'http://s3.amazonaws.com/Minecraft.Download/libraries'
}
}
apply plugin: 'scala'
dependencies {
compile 'org.scala-lang:scala-library:2.10.2'
}
apply plugin: 'forge'
apply plugin: 'forge'
// define the properties file
ext.configFile = file "build.properties"
@@ -74,8 +70,8 @@ sourceSets {
resources {
srcDir 'resources'
}
scala {
srcDirs = ['src']
java {
srcDir 'src'
}
}
}
@@ -84,7 +80,6 @@ processResources
// replace stuff in text files, not binary ones.
from(sourceSets.main.resources.srcDirs) {
include '**/*.info'
include '**/CoreRepo.scala'
// replace version and MCVersion
// forge version is also accessible via project.minecraftforgeVersion
// it contains the full minecraft version, including buildNumber
@@ -94,7 +89,6 @@ processResources
// copy everything else, thats not text
from(sourceSets.main.resources.srcDirs) {
exclude '**/*.info'
exclude '**/CoreRepo.scala'
}
}
+74
View File
@@ -0,0 +1,74 @@
package mantle;
import java.util.logging.Logger;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.Mod.EventHandler;
import net.minecraftforge.common.Configuration;
import mantle.lib.CoreRepo;
import mantle.lib.CoreConfig;
import mantle.internal.EnvironmentChecks;
/**
* Mantle
*
* Central mod object for Mantle
*
* @author Sunstrike <[email protected]>
*/
@Mod(modid = CoreRepo.modId, name = CoreRepo.modName, version = CoreRepo.modVersion)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Mantle {
public static final Logger logger = Logger.getLogger(CoreRepo.modName);
/**
* FML preinitialisation handler
*
* This is where we load our configs and related data, preparing for main load.
*
* @param evt The FMLPreInitializationEvent from FML
*/
@EventHandler
public void preInit (FMLPreInitializationEvent event){
logger.setParent(FMLCommonHandler.instance().getFMLLogger());
CoreConfig.loadConfiguration(new Configuration(event.getSuggestedConfigurationFile()));
logger.info("Mantle (" + CoreRepo.modVersion + ") -- Preparing for launch.");
logger.info("Entering preinitialization phase.");
EnvironmentChecks.verifyEnvironmentSanity();
}
/**
* FML preinitialisation handler
*
* This is where we handle basic loading and populating any missing data in the Repo
*
* @param evt The FMLInitializationEvent from FML
*/
@EventHandler
public void Init (FMLPreInitializationEvent event){
logger.info("Entering initialization phase.");
}
/**
* FML preinitialisation handler
*
* Final chance for cleanup before main game launch
*
* @param evt The FMLPostInitializationEvent from FML
*/
@EventHandler
public void postInit (FMLPreInitializationEvent event){
logger.info("Entering postinitialization phase.");
}
}
-67
View File
@@ -1,67 +0,0 @@
package mantle
import cpw.mods.fml.common.{FMLCommonHandler, Mod}
import cpw.mods.fml.common.network.NetworkMod
import cpw.mods.fml.common.event.{FMLPostInitializationEvent, FMLInitializationEvent, FMLPreInitializationEvent}
import cpw.mods.fml.common.Mod.EventHandler
import net.minecraftforge.common.Configuration
import mantle.lib.CoreRepo._
import mantle.lib.CoreConfig
import mantle.internal.EnvironmentChecks
/**
* Mantle
*
* Central mod object for Mantle
*
* @author Sunstrike <[email protected]>
*/
@Mod(modid = modId, name = modName, version = modVersion, modLanguage = "scala")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
object Mantle {
/**
* FML preinitialisation handler
*
* This is where we load our configs and related data, preparing for main load.
*
* @param evt The FMLPreInitializationEvent from FML
*/
@EventHandler
def preInit(evt:FMLPreInitializationEvent) {
logger.setParent(FMLCommonHandler.instance().getFMLLogger)
CoreConfig.loadConfiguration(new Configuration(evt.getSuggestedConfigurationFile))
logger.info("Mantle (" + modVersion + ") -- Preparing for launch.")
logger.info("Entering preinitialization phase.")
EnvironmentChecks.examineEnvironment()
}
/**
* FML preinitialisation handler
*
* This is where we handle basic loading and populating any missing data in the Repo
*
* @param evt The FMLInitializationEvent from FML
*/
@EventHandler
def init(evt:FMLInitializationEvent) {
logger.info("Entering initialization phase.")
}
/**
* FML preinitialisation handler
*
* Final chance for cleanup before main game launch
*
* @param evt The FMLPostInitializationEvent from FML
*/
@EventHandler
def postInit(evt:FMLPostInitializationEvent) {
logger.info("Entering postinitialization phase.")
}
}
@@ -0,0 +1,93 @@
package mantle.internal;
import java.util.ArrayList;
import java.util.List;
import mantle.Mantle;
import mantle.lib.CoreRepo.*;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.ICrashCallable;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.relauncher.Side;
import mantle.internal.crash.CallableUnsuppConfig;
import mantle.internal.crash.CallableSuppConfig;
/**
* Environment Checks
*
* Checks the runtime environment is safe for use. If not, registers warnings and adds a suitable crash callable.
*
* @author Sunstrike <[email protected]>
*/
public class EnvironmentChecks {
public static boolean hasOptifine = false;
private EnvironmentChecks()
{
} // Singleton
/**
* Checks for conflicting stuff in environment; adds callable to any crash logs if so.
* Note: This code adds additional data to crashlogs. It does not trigger any crashes.
*/
public static void verifyEnvironmentSanity ()
{
List<String> modIds = new ArrayList<String>();
if (Loader.isModLoaded("gregtech_addon"))
{
Mantle.logger.severe("[Environment Checks] Gelatinous iceberg dead ahead! Entering Greggy waters! Abandon hope all ye who enter here! (No, seriously, we don't support GT. Don't report any issues. Thanks.)");
modIds.add("gregtech_addon");
}
if (FMLCommonHandler.instance().getSide() == Side.CLIENT && FMLClientHandler.instance().hasOptifine() || Loader.isModLoaded("optifine"))
{
Mantle.logger.severe("[Environment Checks] Optifine detected. This is a Bad Thing(tm) and can crash Minecraft due to an Optifine bug during TCon armor renders! Capes also disabled.");
modIds.add("optifine");
hasOptifine = true;
}
try
{
Class cl = Class.forName("org.bukkit.Bukkit");
if (cl != null)
{
Mantle.logger.severe("[Environment Checks] Bukkit implementation detected. This may be crashy. Bukkit implementations include Craftbukkit and MCPC+.");
modIds.add("bukkit");
}
}
catch (Exception ex)
{
// No Bukkit in environment.
}
try
{
Class cl = Class.forName("magic.launcher.Launcher");
if (cl != null)
{
Mantle.logger.severe("[Environment Checks] Magic Launcher detected. We recommend using anything else. Vanilla's launcher works fine, as do others.");
modIds.add("magic_launcher");
}
}
catch (Exception ex)
{
// No derpy Magic Launcher in environment.
}
if (modIds.size() == 0)
{
ICrashCallable callable = new CallableSuppConfig();
FMLCommonHandler.instance().registerCrashCallable(callable);
}
else
{
ICrashCallable callable = new CallableUnsuppConfig(modIds);
FMLCommonHandler.instance().registerCrashCallable(callable);
}
}
}
@@ -1,56 +0,0 @@
package mantle.internal
import mantle.lib.CoreRepo._
import scala.collection.mutable.MutableList
import cpw.mods.fml.common.{FMLCommonHandler, Loader}
import mantle.internal.crash.{CallableUnsuppConfig, CallableSuppConfig}
/**
* Environment Checks
*
* Checks the runtime environment is safe for use. If not, registers warnings and adds a suitable crash callable.
*
* @author Sunstrike <[email protected]>
*/
object EnvironmentChecks {
def examineEnvironment() {
logger.info("Beginning environmental inspection...")
var modIds = new MutableList[String]()
if (Loader.isModLoaded("gregtech_addon")) {
logger.warning("[Environment] Found unsupported mod: gregtech_addon.")
modIds += "gregtech_addon"
}
// Removed 'Classic' Optifine check to work around MCP issue with scalac
if (/*FMLCommonHandler.instance.getSide == Side.CLIENT && FMLClientHandler.instance.hasOptifine ||*/ Loader.isModLoaded("optifine")) {
logger.warning("[Environment] Found unsupported mod: optifine")
modIds += "optifine"
}
try {
val cl = Class.forName("org.bukkit.Bukkit")
if (cl != null) {
logger.warning("[Environment] Found unsupported server: bukkit (or derivative thereof)")
modIds += "bukkit"
}
} catch {
case _:Exception => logger.fine("[Environment] Bukkit check failed. This is perfectly normal (good in fact)")
}
if (modIds.size <= 0) {
logger.info("Environmental inspection clean. Continuing.")
FMLCommonHandler.instance().registerCrashCallable(new CallableSuppConfig)
} else {
logger.warning("Non-fatal issues in environment. Continuing but configuration unsupported.")
FMLCommonHandler.instance().registerCrashCallable(new CallableUnsuppConfig(modIds.asInstanceOf[List[String]]))
logger.warning("CallableUnsuppConfig registered. This will mark crash logs as invalid.")
}
}
}
@@ -0,0 +1,25 @@
package mantle.internal.crash;
import cpw.mods.fml.common.ICrashCallable;
/**
* Crash Callable for supported environments.
*
* @author Sunstrike <[email protected]>
*/
public class CallableSuppConfig implements ICrashCallable
{
@Override
public String call () throws Exception
{
return "Environment healthy.";
}
@Override
public String getLabel ()
{
return "Mantle Env";
}
}
@@ -1,16 +0,0 @@
package mantle.internal.crash
import cpw.mods.fml.common.ICrashCallable
/**
* Crash Callable for supported environments.
*
* @author Sunstrike <[email protected]>
*/
class CallableSuppConfig extends ICrashCallable {
def getLabel = "Mantle Env"
def call = "Environment healthy."
}
@@ -0,0 +1,38 @@
package mantle.internal.crash;
import cpw.mods.fml.common.ICrashCallable;
import java.util.List;
// Crash handler for when an unsupported mod is running alongside us
public class CallableUnsuppConfig implements ICrashCallable
{
private List<String> modIds;
public CallableUnsuppConfig(List<String> modIds)
{
this.modIds = modIds;
}
@Override
public String getLabel ()
{
return "Mantle Environment";
}
@Override
public String call () throws Exception
{
String str = "DO NOT REPORT THIS CRASH! Unsupported mods in environment: ";
Boolean firstEntry = true;
for (String id : modIds)
{
str = str + (firstEntry ? id : ", " + id);
firstEntry = false;
}
return str;
}
}
@@ -1,31 +0,0 @@
package mantle.internal.crash
import cpw.mods.fml.common.ICrashCallable
/**
* Crash Callable for unsupported environments.
*
* @param modIds List of unsupported IDs.
*
* @author Sunstrike <[email protected]>
*/
class CallableUnsuppConfig(modIds:List[String]) extends ICrashCallable {
def getLabel = "Mantle Env"
def call = {
val bldr = new StringBuilder
bldr.append("Unsupported environment; found ")
var first = true
for (i <- modIds) {
if (first) {
bldr.append(i)
first = false
} else bldr.append(s", $i")
}
bldr.result()
}
}
@@ -1,8 +1,8 @@
package mantle.lib
package mantle.lib;
import net.minecraftforge.common.Configuration
import mantle.lib.CoreRepo._
import net.minecraftforge.common.Configuration;
import mantle.Mantle;
import mantle.lib.CoreRepo.*;
/**
* Mantle configuration handler
@@ -11,21 +11,21 @@ import mantle.lib.CoreRepo._
*
* @author Sunstrike <[email protected]>
*/
object CoreConfig {
public class CoreConfig {
/**
* Loads state from a Forge configuration object, or saves a new file if it doesn't already exist.
*
* @param config Configuration object (usually from a location given by FML in preinit)
*/
def loadConfiguration(config:Configuration) {
logger.info("Loading configuration from disk.")
config.load()
public static void loadConfiguration(Configuration config) {
Mantle.logger.info("Loading configuration from disk.");
config.load();
// TODO: Config vars get/set here
config.save()
logger.info("Configuration load completed.")
config.save();
Mantle.logger.info("Configuration load completed.");
}
}
+18
View File
@@ -0,0 +1,18 @@
package mantle.lib;
import java.util.logging.Logger;
/**
* Mantle object repository
*
* Storage area for objects accessible throughout Mantle, such as loggers
*
* @author Sunstrike <[email protected]>
*/
public final class CoreRepo {
public static final String modId = "Mantle";
public static final String modName = "Mantle";
public static final String modVersion = "${version}";
}
-20
View File
@@ -1,20 +0,0 @@
package mantle.lib
import java.util.logging.Logger
/**
* Mantle object repository
*
* Storage area for objects accessible throughout Mantle, such as loggers
*
* @author Sunstrike <[email protected]>
*/
object CoreRepo {
final val modId = "Mantle"
final val modName = "Mantle"
final val modVersion = "@VERSION@"
val logger = Logger.getLogger(modName)
}
+81
View File
@@ -0,0 +1,81 @@
package mantle.math;
/**
* Dozenal Converter
*
* Converts decimals into dozenal.
*
* @author mDiyo
*/
import java.util.LinkedList;
public class Dozenal
{
public static String convertToDozenal (byte i)
{
return convertDecimal(i);
}
public static String convertToDozenal (short i)
{
return convertDecimal(i);
}
public static String convertToDozenal (int i)
{
return convertDecimal(i);
}
public static String convertDecimal (int i)
{
int num = i;
LinkedList<Character> list = new LinkedList<Character>();
while (num > 0)
{
list.add(getDozenalCharacter(num % 12));
num /= 12;
}
StringBuilder builder = new StringBuilder();
for (int iter = list.size() - 1; iter > 0; iter--)
{
builder.append(list.get(iter));
}
return builder.toString();
}
public static char getDozenalCharacter (int i)
{
assert i < 12 : "Base 10 number should be less than 12";
switch (i)
{
case 0:
return '0'; //Zero
case 1:
return '1'; //One
case 2:
return '2'; //Two
case 3:
return '3'; //Three
case 4:
return '4'; //Four
case 5:
return '5'; //Five
case 6:
return '6'; //Six
case 7:
return '7'; //Seven
case 8:
return '8'; //Eight
case 9:
return '9'; //Nine
case 10:
return 'X'; //Dec
case 11:
return 'E'; //El
}
return 'Q';
}
}
-63
View File
@@ -1,63 +0,0 @@
package mantle.math
import scala.collection.mutable.MutableList
/**
* Dozenal Converter
*
* Converts decimals into dozenal.
*
* @author mDiyo
* @author Sunstrike <[email protected]>
*/
object Dozenal {
def convertToDozenal(i: Byte): String = {
convertDecimal(i)
}
def convertToDozenal(i: Short): String = {
convertDecimal(i)
}
def convertToDozenal(i: Int): String = {
convertDecimal(i)
}
private def convertDecimal(i: Int): String = {
var num: Int = i
val list: MutableList[Char] = MutableList[Char]()
while (num > 0) {
list += getDozenalCharacter(num % 12)
num /= 12
}
var builder: String = ""
for (entry: Char <- list) {
builder += entry
}
builder
}
private def getDozenalCharacter(i: Int): Char = {
assert(i < 12, "Base 10 number should be less than 12")
i match {
case 0 => '0'
case 1 => '1'
case 2 => '2'
case 3 => '3'
case 4 => '4'
case 5 => '5'
case 6 => '6'
case 7 => '7'
case 8 => '8'
case 9 => '9'
case 10 => 'X'
case 11 => 'E'
case _ => 'Q'
}
}
}
+94
View File
@@ -0,0 +1,94 @@
package mantle.world;
import java.lang.String;
/**
* CoordTuple
*
* @param x The x coordinate
* @param y The y coordinate
* @param z The z coordinate
*
* @author mDiyo
*/
public class CoordTuple implements Comparable
{
public final int x;
public final int y;
public final int z;
public CoordTuple(double posX, double posY, double posZ)
{
x = (int) Math.floor(posX);
y = (int) Math.floor(posY);
z = (int) Math.floor(posZ);
}
public CoordTuple(CoordTuple tuple)
{
x = tuple.x;
y = tuple.y;
z = tuple.z;
}
public boolean equalCoords (int posX, int posY, int posZ)
{
if (this.x == posX && this.y == posY && this.z == posZ)
return true;
else
return false;
}
@Override
public int hashCode ()
{
final int prime = 31;
int result = 1;
result = prime * result + x;
result = prime * result + y;
result = prime * result + z;
return result;
}
public String toString ()
{
return "X: " + x + ", Y: " + y + ", Z: " + z;
}
@Override
public int compareTo (Object o)
{
if (o == null)
throw new NullPointerException("Object cannot be null");
CoordTuple coord = (CoordTuple) o;
if (x < coord.x)
{
return -1;
}
if (x > coord.x)
{
return 1;
}
if (y < coord.y)
{
return -1;
}
if (y > coord.y)
{
return 1;
}
if (z < coord.z)
{
return -1;
}
if (z > coord.z)
{
return 1;
}
return 0;
}
}
-46
View File
@@ -1,46 +0,0 @@
package mantle.world
import java.lang.String
/**
* CoordTuple
*
* @param x The x coordinate
* @param y The y coordinate
* @param z The z coordinate
*
* @author mDiyo
* @author Sunstrike <[email protected]>
*/
class CoordTuple(val x: Int, val y:Int, val z:Int) extends Comparable[CoordTuple] {
def this(posX: Double, posY: Double, posZ: Double) = this(Math.floor(posX).asInstanceOf[Int], Math.floor(posY).asInstanceOf[Int], Math.floor(posZ).asInstanceOf[Int])
def this(tuple: CoordTuple) = this(tuple.x, tuple.y, tuple.z)
def equalCoords(posX: Int, posY: Int, posZ: Int): Boolean = this.x == posX && this.y == posY && this.z == posZ
override def hashCode: Int = {
val prime: Int = 31
var result: Int = 1
result = prime * result + x
result = prime * result + y
result = prime * result + z
result
}
override def toString: String = s"X: $x, Y: $y, Z: $z"
def compareTo(o: CoordTuple): Int = o match {
case null => throw new NullPointerException("Object cannot be null")
case _ if x < o.x => -1
case _ if x > o.x => 1
case _ if y < o.y => -1
case _ if y > o.y => 1
case _ if z < o.z => -1
case _ if z > o.z => 1
case _ => 0
}
}
+27
View File
@@ -0,0 +1,27 @@
package mantle.world;
/**
* CoordTuplePair
*
* @param a The first CoordTuple
* @param b The second CoordTuple
*
* @author mDiyo
*/
public class CoordTuplePair
{
public CoordTuple a;
public CoordTuple b;
public CoordTuplePair(CoordTuple a, CoordTuple b)
{
this.a = a;
this.b = b;
}
public CoordTuplePair(int aX, int aY, int aZ, int bX, int bY, int bZ)
{
this.a = new CoordTuple(aX, aY, aZ);
this.b = new CoordTuple(bX, bY, bZ);
}
}
-16
View File
@@ -1,16 +0,0 @@
package mantle.world
/**
* CoordTuplePair
*
* @param a The first CoordTuple
* @param b The second CoordTuple
*
* @author mDiyo
* @author Sunstrike <[email protected]>
*/
class CoordTuplePair(val a:CoordTuple, val b:CoordTuple) {
def this(aX: Int, aY: Int, aZ: Int, bX: Int, bY: Int, bZ: Int) = this(new CoordTuple(aX, aY, aZ), new CoordTuple(bX, bY, bZ))
}
+31
View File
@@ -0,0 +1,31 @@
package mantle.world;
import java.util.Comparator;
/**
* CoordTupleSort
*
* @author mDiyo
*/
public class CoordTupleSort implements Comparator
{
@Override
public int compare (Object o1, Object o2)
{
CoordTuple c1 = (CoordTuple) o1;
CoordTuple c2 = (CoordTuple) o2;
//Sort by y, then x, then z
if (c1.y != c2.y)
return c1.y - c2.y;
if (c1.x != c2.x)
return c1.x - c2.x;
if (c1.z != c2.z)
return c1.z - c2.z;
return 0;
}
}
-20
View File
@@ -1,20 +0,0 @@
package mantle.world
import java.util.Comparator
/**
* CoordTupleSort
*
* @author mDiyo, Sunstrike
*/
class CoordTupleSort extends Comparator[CoordTuple] {
override def compare(o1: CoordTuple, o2: CoordTuple): Int = {
if (o1.y != o2.y) return o1.y - o2.y
if (o1.x != o2.x) return o1.x - o2.x
if (o1.z != o2.z) return o1.z - o2.z
0
}
}
+65
View File
@@ -0,0 +1,65 @@
package mantle.world;
import java.lang.String;
/**
* DimensionCoordPair
*
* @param dim The dimension ID
* @param x The x coordinate
* @param z The z coordinate
*
* @author mDiyo
*/
public class DimensionCoordPair
{
public final int dim;
public final int x;
public final int z;
public DimensionCoordPair(int worldID, int posX, int posZ)
{
dim = worldID;
x = posX;
z = posZ;
}
public boolean equalCoords (int worldID, int posX, int posZ)
{
if (this.dim == posX && this.x == posX && this.z == posZ)
return true;
else
return false;
}
@Override
public boolean equals (Object obj)
{
if (obj == null)
return false;
if (getClass() == obj.getClass())
{
DimensionCoordPair coord = (DimensionCoordPair) obj;
if (this.dim == coord.dim && this.x == coord.x && this.z == coord.z)
return true;
}
return false;
}
@Override
public int hashCode ()
{
final int prime = 37;
int result = 1;
result = prime * result + dim;
result = prime * result + x;
result = prime * result + z;
return result;
}
public String toString ()
{
return "Dim: " + dim + ", X: " + x + ", Z: " + z;
}
}
-38
View File
@@ -1,38 +0,0 @@
package mantle.world
import java.lang.String
/**
* DimensionCoordPair
*
* @param dim The dimension ID
* @param x The x coordinate
* @param z The z coordinate
*
* @author mDiyo
* @author Sunstrike <[email protected]>
*/
class DimensionCoordPair(val dim: Int, val x:Int, val z:Int) {
def this(tuple: DimensionCoordPair) = this(tuple.dim, tuple.x, tuple.z)
def equalCoords(dim: Int, posX: Int, posZ: Int): Boolean = this.dim == dim && this.x == posX && this.z == posZ
override def hashCode: Int = {
val prime: Int = 31
var result: Int = 1
result = prime * result + dim
result = prime * result + x
result = prime * result + z
result
}
override def equals(obj: scala.Any): Boolean = obj match {
case a:DimensionCoordPair => equalCoords(a.dim, a.x, a.z)
case _ => false
}
override def toString: String = s"Dim: $dim, X: $x, Z: $z"
}