1
0
mirror of https://github.com/chylex/Hardcore-Ender-Expansion-2.git synced 2025-04-11 03:15:44 +02:00

Migrate to 'Kotlin for Forge' and update Kotlin to 1.4.10

This commit is contained in:
chylex 2020-09-25 10:35:20 +02:00
parent 97d7c61ff8
commit fd6a4766c9
21 changed files with 37 additions and 40 deletions

View File

@ -1,5 +1,5 @@
buildscript{
ext.kotlin_version = "1.3.61"
ext.kotlin_version = "1.4.10"
repositories{
jcenter()
@ -20,9 +20,10 @@ buildscript{
}
repositories{
maven{
url = "https://minecraft.curseforge.com/api/maven"
}
maven{
name = "kotlinforforge"
url = "https://thedarkcolour.github.io/KotlinForForge/"
}
}
apply plugin: "net.minecraftforge.gradle"
@ -35,7 +36,7 @@ if (file("run/mods_deobf.gradle").exists()){
def mcversion = "1.15.2"
def forgeversion = "31.2.27"
def kottleversion = "1.5.0"
def kotlinmodversion = "1.6.0"
def prefixName = "displayName = "
def prefixVersion = "version = "
@ -57,13 +58,13 @@ tasks.withType(JavaCompile){
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile){
kotlinOptions{
jvmTarget = "1.8"
apiVersion = "1.3"
languageVersion = "1.3"
apiVersion = "1.4"
languageVersion = "1.4"
freeCompilerArgs = [
"-Xno-call-assertions",
"-Xno-param-assertions",
"-Xno-receiver-assertions",
"-Xjvm-default=enable",
"-Xjvm-default=all",
"-Xuse-experimental=kotlin.ExperimentalUnsignedTypes",
"-Xuse-experimental=kotlin.contracts.ExperimentalContracts",
"-XXLanguage:+InlineClasses"
@ -103,8 +104,9 @@ minecraft{
dependencies{
minecraft "net.minecraftforge:forge:" + mcversion + "-" + forgeversion
implementation "kottle:Kottle:" + kottleversion + ":slim"
implementation "thedarkcolour:kotlinforforge:" + kotlinmodversion
implementation "org.jetbrains.kotlin:kotlin-stdlib"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlin:kotlin-reflect"

View File

@ -70,7 +70,7 @@ class BlockWhitebarkSapling(builder: BlockBuilder, private val generator: Whiteb
override fun grow(world: ServerWorld, rand: Random, pos: BlockPos, state: BlockState){
val stage = state[STAGE]
if (stage < STAGE.allowedValues.max()!!){
if (stage < STAGE.allowedValues.maxOrNull()!!){
pos.setState(world, state.with(STAGE, stage + 1), FLAG_SKIP_RENDER)
}
else{

View File

@ -1,11 +1,10 @@
package chylex.hee.game.block.util
import net.minecraft.block.Block
import net.minecraft.block.Blocks
import net.minecraft.item.DyeColor
import java.util.EnumMap
object ColoredBlocks{
val CARPET = EnumMap<DyeColor, Block>(mapOf(
val CARPET = EnumMap(mapOf(
DyeColor.WHITE to Blocks.WHITE_CARPET,
DyeColor.ORANGE to Blocks.ORANGE_CARPET,
DyeColor.MAGENTA to Blocks.MAGENTA_CARPET,
@ -24,7 +23,7 @@ object ColoredBlocks{
DyeColor.BLACK to Blocks.BLACK_CARPET
))
val WOOL = EnumMap<DyeColor, Block>(mapOf(
val WOOL = EnumMap(mapOf(
DyeColor.WHITE to Blocks.WHITE_WOOL,
DyeColor.ORANGE to Blocks.ORANGE_WOOL,
DyeColor.MAGENTA to Blocks.MAGENTA_WOOL,
@ -43,7 +42,7 @@ object ColoredBlocks{
DyeColor.BLACK to Blocks.BLACK_WOOL
))
val BED = EnumMap<DyeColor, Block>(mapOf(
val BED = EnumMap(mapOf(
DyeColor.WHITE to Blocks.WHITE_BED,
DyeColor.ORANGE to Blocks.ORANGE_BED,
DyeColor.MAGENTA to Blocks.MAGENTA_BED,
@ -62,7 +61,7 @@ object ColoredBlocks{
DyeColor.BLACK to Blocks.BLACK_BED
))
val STAINED_GLASS = EnumMap<DyeColor, Block>(mapOf(
val STAINED_GLASS = EnumMap(mapOf(
DyeColor.WHITE to Blocks.WHITE_STAINED_GLASS,
DyeColor.ORANGE to Blocks.ORANGE_STAINED_GLASS,
DyeColor.MAGENTA to Blocks.MAGENTA_STAINED_GLASS,
@ -81,7 +80,7 @@ object ColoredBlocks{
DyeColor.BLACK to Blocks.BLACK_STAINED_GLASS
))
val WALL_BANNER = EnumMap<DyeColor, Block>(mapOf(
val WALL_BANNER = EnumMap(mapOf(
DyeColor.WHITE to Blocks.WHITE_WALL_BANNER,
DyeColor.ORANGE to Blocks.ORANGE_WALL_BANNER,
DyeColor.MAGENTA to Blocks.MAGENTA_WALL_BANNER,

View File

@ -90,7 +90,7 @@ object CommandDebugStructure : ICommand{ // UPDATE
transformedWorld.apply { piece.generateWithTransformHint(this, transform) }.finalize()
}
x += transforms.map { it(size).x }.max()!! + 2
x += transforms.maxOf { it(size).x } + 2
}
}

View File

@ -13,10 +13,6 @@ import net.minecraft.util.text.TranslationTextComponent
typealias CommandExecutionFunction = Command<CommandSource>
typealias CommandExecutionFunctionCtx<C> = (CommandContext<CommandSource>, C) -> Int
fun <C> ArgumentBuilder<CommandSource, *>.executes(function: (CommandContext<CommandSource>, C) -> Int, extra: C){
this.executes { function(it, extra) }
}
fun <C, T : ArgumentBuilder<CommandSource, T>> ArgumentBuilder<CommandSource, T>.executes(function: (CommandContext<CommandSource>, C) -> Int, extra: C): T{
return this.executes { function(it, extra) }
}

View File

@ -102,7 +102,7 @@ class EntityFallingObsidian : EntityFallingBlockHeavy{
return SUCCESS
}
val relocationPos = pos.allInCenteredBox(1, 0, 1).toList().filter { canFallThrough(world, it) }.minBy { it.distanceSqTo(this) }
val relocationPos = pos.allInCenteredBox(1, 0, 1).toList().filter { canFallThrough(world, it) }.minByOrNull { it.distanceSqTo(this) }
return if (relocationPos != null){
if (super.placeAfterLanding(relocationPos, collidingWith) == SUCCESS){

View File

@ -93,7 +93,7 @@ class EntityMobAngryEnderman(type: EntityType<EntityMobAngryEnderman>, world: Wo
.selectVulnerableEntities
.inRange<EntityPlayer>(posVec, AGGRO_DISTANCE.toDouble())
.filter { predicate.canTarget(this, it) }
.minBy(::getDistanceSq)
.minByOrNull(::getDistanceSq)
if (alternativeTarget != null){
attackTarget = alternativeTarget

View File

@ -283,7 +283,7 @@ class EntityMobBlobby(type: EntityType<out EntityCreature>, world: World) : Enti
blobby.groupId = newId
}
group.maxBy { it.scale }?.setLeaderStatusAndRefresh(isLeader = true)
group.maxByOrNull { it.scale }?.setLeaderStatusAndRefresh(isLeader = true)
}
}

View File

@ -50,6 +50,6 @@ class ItemTableCore(private val tableBlocks: Array<BlockAbstractTableTile<*>>, p
@Sided(Side.CLIENT)
override fun addInformation(stack: ItemStack, world: World?, lines: MutableList<ITextComponent>, flags: ITooltipFlag){
lines.add(TranslationTextComponent("item.tooltip.hee.table_core.tooltip", tableBlocks.map { it.tier }.min()))
lines.add(TranslationTextComponent("item.tooltip.hee.table_core.tooltip", tableBlocks.minOf { it.tier }))
}
}

View File

@ -118,7 +118,7 @@ class DamageProperties{
// Non-lethal damage handling
@SubscribeAllEvents(modid = HEE.ID)
private companion object{
companion object{
@SubscribeEvent(EventPriority.HIGHEST)
fun onLivingDamage(e: LivingDamageEvent){
val source = e.source as? CustomDamageSource ?: return

View File

@ -11,7 +11,7 @@ object VanillaDamageHooks{
@JvmStatic
fun getDamageMultiplier(attacker: EntityLivingBase, target: Entity): Float{
if (target is EntityLivingBase){
val heldItem = attacker.getHeldItem(MAIN_HAND).item;
val heldItem = attacker.getHeldItem(MAIN_HAND).item
if (heldItem is ItemScorchingSword){
return heldItem.handleDamageMultiplier(target)

View File

@ -51,7 +51,7 @@ class PotionTypeInfo(
unrolled /= mp(it)
}
return (0..maxSteps).minBy { abs(getBaseDuration(it) - unrolled) } ?: 0
return (0..maxSteps).minByOrNull { abs(getBaseDuration(it) - unrolled) } ?: 0
}
}

View File

@ -88,7 +88,7 @@ object EnergyShrineGenerator : OverworldFeature(){
findSpawnAtMaybe(world, testChunkX, testChunkZ)?.let(found::add)
}
return found.minBy { it.distanceSqTo(xz) }?.withY(0)
return found.minByOrNull { it.distanceSqTo(xz) }?.withY(0)
}
// Helpers
@ -205,7 +205,7 @@ object EnergyShrineGenerator : OverworldFeature(){
}
val boundingBoxes = build.boundingBoxes
val structureHeight = 1 + boundingBoxes.maxBy { it.max.y }!!.max.y - boundingBoxes.minBy { it.min.y }!!.min.y
val structureHeight = 1 + boundingBoxes.maxOf { it.max.y } - boundingBoxes.minOf { it.min.y }
val topY = getTopSolidNonLeavesBlock(world, xz)
val topOffset = MIN_GROUND_LAYERS + rand.nextInt(0, 2)

View File

@ -44,9 +44,9 @@ import chylex.hee.system.util.facades.Resource
object ObsidianTowerPieces : IStructureDescription{
fun calculateStructureSize(floors: Int) = Size(
PIECES_BASE.map { it.size.x }.max()!!,
PIECES_BASE.maxOf { it.size.x },
PIECES_BASE.sumBy { it.size.y } + ((floors - 2) * PIECE_LEVEL_MIDDLE.size.y),
PIECES_BASE.map { it.size.z }.max()!!
PIECES_BASE.maxOf { it.size.z }
)
// Palette

View File

@ -137,7 +137,7 @@ object StrongholdGenerator : OverworldFeature(){
}
}
return found.minBy { PosXZ(it).distanceSqTo(xz) }
return found.minByOrNull { PosXZ(it).distanceSqTo(xz) }
}
// Helpers

View File

@ -166,7 +166,7 @@ object Generator_LostGarden : ITerritoryGenerator{
val bottom = pos
.allInCenteredBox(2, 0, 2)
.mapNotNull { top -> top.offsetUntil(DOWN, offsetRange){ !world.isAir(it) } }
.minBy { it.y }
.minByOrNull { it.y }
if (bottom != null){
val testPos = Pos(pos.x, bottom.y, pos.z)

View File

@ -41,7 +41,7 @@ object ModNetwork{
it == HEE.version
}
network = NetworkRegistry.newEventChannel(CHANNEL, Supplier { HEE.version }, checkVersion, checkVersion)
network = NetworkRegistry.newEventChannel(CHANNEL, { HEE.version }, checkVersion, checkVersion)
network.registerObject(this)
for((cls, constructor) in PacketConstructors.getAll()){

View File

@ -68,7 +68,7 @@ object ModParticles{
MC.particleManager.registerFactory(type, IParticleMetaFactory {
callback(it)
IParticleFactory<BasicParticleType> { _, world, posX, posY, posZ, motX, motY, motZ ->
IParticleFactory { _, world, posX, posY, posZ, motX, motY, motZ ->
maker.create(world, posX, posY, posZ, motX, motY, motZ, null)
}
})

View File

@ -107,6 +107,6 @@ object ModTileEntities{
}
private inline fun <reified T : TileEntity> build(vararg blocks: Block): TileEntityType<T>{
return TileEntityType.Builder.create<T>(TileEntityConstructors.get(T::class.java), *blocks).build(null) // UPDATE
return TileEntityType.Builder.create(TileEntityConstructors.get(T::class.java), *blocks).build(null) // UPDATE
}
}

View File

@ -163,7 +163,7 @@ fun AITargetAttacker(entity: EntityCreature, callReinforcements: Boolean): AITar
AITargetAttackerFixed(entity, callReinforcements)
inline fun <reified T : EntityLivingBase> AITargetNearby(entity: EntityCreature, chancePerTick: Int, checkSight: Boolean, easilyReachableOnly: Boolean, noinline targetPredicate: ((T) -> Boolean)? = null) =
NearestAttackableTargetGoal(entity, T::class.java, chancePerTick, checkSight, easilyReachableOnly, targetPredicate?.let { p -> Predicate<EntityLivingBase> { p(it as T) } })
NearestAttackableTargetGoal(entity, T::class.java, chancePerTick, checkSight, easilyReachableOnly, targetPredicate?.let { p -> Predicate { p(it as T) } })
inline fun <reified T : EntityLivingBase> AITargetEyeContact(entity: EntityCreature, fieldOfView: Float, headRadius: Float, minStareTicks: Int, easilyReachableOnly: Boolean, noinline targetPredicate: ((T) -> Boolean)? = null) =
AITargetEyeContact(entity, easilyReachableOnly, T::class.java, targetPredicate, fieldOfView, headRadius, minStareTicks)

View File

@ -1,4 +1,4 @@
modLoader = "kotlinfml"
modLoader = "kotlinforforge"
loaderVersion = "[1,)"
authors = "https://hee.chylex.com/authors"