diff --git a/build.gradle b/build.gradle index c797787..841ac1e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,28 +1,30 @@ plugins { id "scala" - id "nova.gradle" version "0.2.5" + id "nova.gradle" version "0.2.6" id "maven-publish" id "com.jfrog.artifactory" version "3.1.1" } +ext.scala_version = "2.12.3" + build.dependsOn scaladoc apply from: "https://raw.githubusercontent.com/NOVA-Team/NOVA-Gradle/master/shared-scripts/java.gradle" - dependencies { - compile "org.scala-lang:scala-library:2.11.7" - compile "nova.core:NOVA-Core:$novaVersion" - testCompile "nova.core:NOVA-Core:$novaVersion:wrappertests" + compile "org.scala-lang:scala-library:2.12.3" + compile "nova.core:NOVA-Core:$nova_version" + testCompile "nova.core:NOVA-Core:$nova_version:wrappertests" } + nova { wrappers { "17" { - wrapper "nova.core:NOVA-Core-Wrapper-MC1.7:$novaVersion" + wrapper "nova.core:NOVA-Core-Wrapper-MC1.7:$nova_version" } "18" { - wrapper "nova.core:NOVA-Core-Wrapper-MC1.8:$novaVersion" + wrapper "nova.core:NOVA-Core-Wrapper-MC1.8:$nova_version" } } } diff --git a/gradle.properties b/gradle.properties index a19bcb4..ab13bf4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ version = 0.0.1-SNAPSHOT group = nova.scala -novaVersion = 0.1.0-SNAPSHOT +nova_version = 0.1.0-SNAPSHOT packaging = jar info.inceptionYear = 2015 diff --git a/src/main/scala/nova/scala/modcontent/ContentLoader.scala b/src/main/scala/nova/scala/modcontent/ContentLoader.scala index f6dd386..d7be6cc 100644 --- a/src/main/scala/nova/scala/modcontent/ContentLoader.scala +++ b/src/main/scala/nova/scala/modcontent/ContentLoader.scala @@ -20,16 +20,12 @@ package nova.scala.modcontent -import java.util.function.{Function => JFunction} - import nova.core.block.{Block, BlockFactory} import nova.core.entity.{Entity, EntityFactory} import nova.core.item.{Item, ItemFactory} -import nova.core.loader.Loadable import nova.core.render.model.ModelProvider import nova.core.render.texture.{BlockTexture, EntityTexture, ItemTexture} import nova.internal.core.Game -import nova.scala.wrapper.FunctionalWrapper._ /** * Automatic mffs.content registration for all Blocks, Items, Entities and Textures. @@ -38,12 +34,12 @@ import nova.scala.wrapper.FunctionalWrapper._ * * @author Calclavia */ -trait ContentLoader extends Loadable { +trait ContentLoader { self => def id: String - override def preInit() = { + def preInit() = { //Automated handler for registering blocks & items vars for (field <- self.getClass.getDeclaredFields) { //Set it so we can access the field @@ -59,12 +55,11 @@ trait ContentLoader extends Loadable { if (itemWrapper.wrapped.newInstance().isInstanceOf[AutoItemTexture]) { val texture = Game.render.registerTexture(new ItemTexture(id, itemWrapper.getID)) field.set(self, Game.items.register( - texture.getClass.getName, - supplier(() => { + texture.getClass.getName, () => { val wrapped = itemWrapper.wrapped.newInstance() wrapped.asInstanceOf[AutoItemTexture].texture = texture wrapped - }) + } )) } else { @@ -74,12 +69,11 @@ trait ContentLoader extends Loadable { if (itemConstructor.wrapped.apply().isInstanceOf[AutoItemTexture]) { val texture = Game.render.registerTexture(new ItemTexture(id, itemConstructor.wrapped.getID)) field.set(self, Game.items.register( - texture.getClass.getName, - supplier(() => { + texture.getClass.getName, () => { val wrapped = itemConstructor.wrapped.apply() wrapped.asInstanceOf[AutoItemTexture].texture = texture wrapped - }) + } )) } else { @@ -91,12 +85,11 @@ trait ContentLoader extends Loadable { val texture = Game.render.registerTexture(new BlockTexture(id, blockWrapper.getID)) Game.render.registerTexture(new BlockTexture(id, blockWrapper.getID)) field.set(self, Game.blocks.register( - texture.getClass.getName, - supplier(() => { + texture.getClass.getName, () => { val wrapped = blockWrapper.wrapped.newInstance() wrapped.asInstanceOf[AutoBlockTexture].texture = texture wrapped - }) + } )) } else { @@ -107,12 +100,11 @@ trait ContentLoader extends Loadable { val texture = Game.render.registerTexture(new BlockTexture(id, blockConstructor.getID)) Game.render.registerTexture(new BlockTexture(id, blockConstructor.getID)) field.set(self, Game.blocks.register( - texture.getClass.getName, - supplier(() => { + texture.getClass.getName, () => { val wrapped = blockConstructor.wrapped.apply() wrapped.asInstanceOf[AutoBlockTexture].texture = texture wrapped - }) + } )) } else { diff --git a/src/main/scala/nova/scala/wrapper/FunctionalWrapper.scala b/src/main/scala/nova/scala/wrapper/FunctionalWrapper.scala deleted file mode 100644 index b2145e5..0000000 --- a/src/main/scala/nova/scala/wrapper/FunctionalWrapper.scala +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright (c) 2015 NOVA, All rights reserved. - * This library is free software, licensed under GNU Lesser General Public License version 3 - * - * This file is part of NOVA. - * - * NOVA is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * NOVA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with NOVA. If not, see . - */ - -package nova.scala.wrapper - -import java.util.function._ - -import nova.core.event.bus.EventListener - -/** - * Implicitly converts Scala methods to Java methods. - * @author anti344 - */ -object FunctionalWrapper { - - import scala.language.implicitConversions - - implicit def biConsumer[T1, T2](f: (T1, T2) => Any): BiConsumer[T1, T2] = new BiConsumer[T1, T2] { - def accept(t1: T1, t2: T2) = f(t1, t2) - } - - implicit def biFunc[R, T1, T2](f: (T1, T2) => R): BiFunction[T1, T2, R] = new BiFunction[T1, T2, R] { - def apply(t1: T1, t2: T2): R = f(t1, t2) - } - - implicit def biOp[T](f: (T, T) => T): BinaryOperator[T] = new BinaryOperator[T] { - def apply(t1: T, t2: T): T = f(t1, t2) - } - - implicit def biPredicate[T1, T2](f: (T1, T2) => Boolean): BiPredicate[T1, T2] = new BiPredicate[T1, T2] { - def test(t1: T1, t2: T2) = f(t1, t2) - } - - implicit def boolSupplier(f: () => Boolean): BooleanSupplier = new BooleanSupplier { - def getAsBoolean: Boolean = f() - } - - implicit def consumer[T](f: T => Any): Consumer[T] = new Consumer[T] { - def accept(t: T) = f(t) - } - - implicit def doubleBiOp(f: (Double, Double) => Double): DoubleBinaryOperator = new DoubleBinaryOperator { - def applyAsDouble(d1: Double, d2: Double): Double = f(d1, d2) - } - - implicit def doubleConsumer(f: Double => Any): DoubleConsumer = new DoubleConsumer { - def accept(d: Double) = f(d) - } - - implicit def doubleFunc[R](f: Double => R): DoubleFunction[R] = new DoubleFunction[R] { - def apply(d: Double): R = f(d) - } - - implicit def doublePredicate(f: Double => Boolean): DoublePredicate = new DoublePredicate { - def test(d: Double): Boolean = f(d) - } - - implicit def doubleSupplier(f: () => Double): DoubleSupplier = new DoubleSupplier { - def getAsDouble: Double = f() - } - - implicit def doubleToIntFunc(f: Double => Int): DoubleToIntFunction = new DoubleToIntFunction { - def applyAsInt(d: Double): Int = f(d) - } - - implicit def doubleToLongFunc(f: Double => Long): DoubleToLongFunction = new DoubleToLongFunction { - def applyAsLong(d: Double): Long = f(d) - } - - implicit def doubleUnaryOp(f: Double => Double): DoubleUnaryOperator = new DoubleUnaryOperator { - def applyAsDouble(d: Double): Double = f(d) - } - - implicit def func[T, R](f: T => R): Function[T, R] = new Function[T, R] { - def apply(t: T): R = f(t) - } - - implicit def intBiOp(f: (Int, Int) => Int): IntBinaryOperator = new IntBinaryOperator { - def applyAsInt(i1: Int, i2: Int): Int = f(i1, i2) - } - - implicit def intConsumer(f: Int => Any): IntConsumer = new IntConsumer { - def accept(i: Int) = f(i) - } - - implicit def intFunc[R](f: Int => R): IntFunction[R] = new IntFunction[R] { - def apply(i: Int): R = f(i) - } - - implicit def intPredicate(f: Int => Boolean): IntPredicate = new IntPredicate { - def test(i: Int): Boolean = f(i) - } - - implicit def intSupplier(f: () => Int): IntSupplier = new IntSupplier { - def getAsInt: Int = f() - } - - implicit def intToDoubleFunc(f: Int => Double): IntToDoubleFunction = new IntToDoubleFunction { - def applyAsDouble(i: Int): Double = f(i) - } - - implicit def intToLongFunc(f: Int => Long): IntToLongFunction = new IntToLongFunction { - def applyAsLong(i: Int): Long = f(i) - } - - implicit def intUnaryOp(f: Int => Int): IntUnaryOperator = new IntUnaryOperator { - def applyAsInt(i: Int): Int = f(i) - } - - implicit def longBiOp(f: (Long, Long) => Long): LongBinaryOperator = new LongBinaryOperator { - def applyAsLong(i1: Long, i2: Long): Long = f(i1, i2) - } - - implicit def longConsumer(f: Long => Any): LongConsumer = new LongConsumer { - def accept(i: Long) = f(i) - } - - implicit def longFunc[R](f: Long => R): LongFunction[R] = new LongFunction[R] { - def apply(i: Long): R = f(i) - } - - implicit def longPredicate(f: Long => Boolean): LongPredicate = new LongPredicate { - def test(i: Long): Boolean = f(i) - } - - implicit def longSupplier(f: () => Long): LongSupplier = new LongSupplier { - def getAsLong: Long = f() - } - - implicit def longToDoubleFunc(f: Long => Double): LongToDoubleFunction = new LongToDoubleFunction { - def applyAsDouble(i: Long): Double = f(i) - } - - implicit def longToIntFunc(f: Long => Int): LongToIntFunction = new LongToIntFunction { - def applyAsInt(i: Long): Int = f(i) - } - - implicit def longUnaryOp(f: Long => Long): LongUnaryOperator = new LongUnaryOperator { - def applyAsLong(i: Long): Long = f(i) - } - - implicit def objDoubleConsumer[T](f: (T, Double) => Any): ObjDoubleConsumer[T] = new ObjDoubleConsumer[T] { - def accept(t: T, d: Double) = f(t, d) - } - - implicit def objIntConsumer[T](f: (T, Int) => Any): ObjIntConsumer[T] = new ObjIntConsumer[T] { - def accept(t: T, d: Int) = f(t, d) - } - - implicit def objLongConsumer[T](f: (T, Long) => Any): ObjLongConsumer[T] = new ObjLongConsumer[T] { - def accept(t: T, d: Long) = f(t, d) - } - - implicit def predicate[T](f: T => Boolean): Predicate[T] = new Predicate[T] { - def test(t: T): Boolean = f(t) - } - - implicit def supplier[T](f: () => T): Supplier[T] = new Supplier[T] { - def get(): T = f() - } - - implicit def toDoubleBiFunc[T1, T2](f: (T1, T2) => Double): ToDoubleBiFunction[T1, T2] = new ToDoubleBiFunction[T1, T2] { - def applyAsDouble(t1: T1, t2: T2): Double = f(t1, t2) - } - - implicit def toDoubleFun[T](f: T => Double): ToDoubleFunction[T] = new ToDoubleFunction[T] { - def applyAsDouble(d: T): Double = f(d) - } - - implicit def toIntBiFunc[T1, T2](f: (T1, T2) => Int): ToIntBiFunction[T1, T2] = new ToIntBiFunction[T1, T2] { - def applyAsInt(t1: T1, t2: T2): Int = f(t1, t2) - } - - implicit def toIntFun[T](f: T => Int): ToIntFunction[T] = new ToIntFunction[T] { - def applyAsInt(d: T): Int = f(d) - } - - implicit def toLongBiFunc[T1, T2](f: (T1, T2) => Long): ToLongBiFunction[T1, T2] = new ToLongBiFunction[T1, T2] { - def applyAsLong(t1: T1, t2: T2): Long = f(t1, t2) - } - - implicit def toLongFun[T](f: T => Long): ToLongFunction[T] = new ToLongFunction[T] { - def applyAsLong(d: T): Long = f(d) - } - - implicit def unaryOp[T](f: T => T): UnaryOperator[T] = new UnaryOperator[T] { - def apply(t: T): T = f(t) - } - - implicit def inverseSupplier[T](f: Supplier[T]): () => T = () => f.get() - - implicit def runnable(f: () => Unit): Runnable = new Runnable { - override def run(): Unit = f() - } - - //NOVA - implicit def eventListener[T](f: T => Unit): EventListener[T] = new EventListener[T] { - def onEvent(t: T) = f(t) - } -} \ No newline at end of file