Skip to content

Commit

Permalink
v0.1.1-alpha
Browse files Browse the repository at this point in the history
- improved DEMagicaModStuff
- corrected version in mod file
- applied kotlin language adapeter
- added Config explosionDoAffectSelf
  • Loading branch information
dedztbh committed Jul 18, 2019
1 parent 10e28b2 commit fca511b
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 24 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Useful Keybindings:
- Z - teleport to y=350 in creative
- B - binocular

Config:
- explosionDoAffectSelf: Explosion Do Affect Creator


Localizations:
- 简体中文
- English
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ allOpen {
annotation("com.dedztbh.demagica.util.Open")
}

version = "0.1-alpha"
version = "0.1.1-alpha"
group = "com.dedztbh.demagica" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "demagica"

Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/com/dedztbh/demagica/DEMagica.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import net.minecraftforge.fml.common.network.NetworkRegistry
import org.apache.logging.log4j.Logger


@Mod(modid = DEMagica.MODID, name = DEMagica.NAME, version = DEMagica.VERSION)
@Mod(modid = DEMagica.MODID, name = DEMagica.NAME, version = DEMagica.VERSION, modLanguageAdapter = "net.shadowfacts.forgelin.KotlinAdapter")
class DEMagica {
companion object {
const val MODID = "demagica"
const val NAME = "DEMagica"
const val VERSION = "1.0"
const val VERSION = "0.1.1-alpha"

@JvmStatic
lateinit var logger: Logger
Expand Down Expand Up @@ -48,7 +48,7 @@ class DEMagica {
@Mod.EventHandler
fun postInit(e: FMLPostInitializationEvent) {
proxy.postInit(e)
logger.debug("Dalao:${Config.dalaofy}")
logger.debug("explosionDoAffectSelf:${Config.explosionDoAffectSelf}")
}

}
4 changes: 2 additions & 2 deletions src/main/kotlin/com/dedztbh/demagica/global/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.apache.logging.log4j.Level

object Config {
// This values below you can access elsewhere in your mod:
var dalaofy = true
var explosionDoAffectSelf = false

private val CATEGORY_GENERAL = "general"
private val CATEGORY_DIMENSIONS = "dimensions"
Expand All @@ -31,7 +31,7 @@ object Config {

private fun initGeneralConfig(cfg: Configuration) {
cfg.addCustomCategoryComment(CATEGORY_GENERAL, "General configuration")
dalaofy = cfg.getBoolean("dalaofy", CATEGORY_GENERAL, dalaofy, "To Dalaofy")
explosionDoAffectSelf = cfg.getBoolean("explosionDoAffectSelf", CATEGORY_GENERAL, explosionDoAffectSelf, "Explosion Do Affect Creator")
}

private fun initDimensionConfig(cfg: Configuration) {
Expand Down
15 changes: 10 additions & 5 deletions src/main/kotlin/com/dedztbh/demagica/global/DEMagicaStuff.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.dedztbh.demagica.util.Open
import net.minecraft.tileentity.TileEntity
import net.minecraftforge.fml.relauncher.Side
import net.minecraftforge.fml.relauncher.SideOnly
import kotlin.reflect.KClass

/**
* Created by DEDZTBH on 2019-07-15.
Expand All @@ -25,20 +26,24 @@ typealias IDEMagicaItem = IDEMagicaStuff
class DEMagicaModStuff {
@Suppress("UNCHECKED_CAST")
fun <T> stuffOf(clazz: Class<T>, vararg otherClazz: Class<out Any>, newInstance: Boolean = false): List<T> =
this::class.java.declaredMethods.filter { func ->
this::class.java.declaredFields.filter { field ->
setOf(clazz, *otherClazz).all {
it.isAssignableFrom(func.returnType)
it.isAssignableFrom(field.type)
}
}.map {
(if (newInstance)
it.returnType.newInstance()
it.type.newInstance()
else
it.invoke(this)) as T
it.get(this)) as T
}

fun <T : Any> stuffOf(clazz: KClass<out T>, vararg otherClazz: KClass<out Any>, newInstance: Boolean = false): List<T> =
stuffOf(clazz.java, *otherClazz.map { it.java }.toTypedArray(), newInstance = newInstance)


@SideOnly(Side.CLIENT)
fun initModels() {
this.stuffOf(IDEMagicaStuff::class.java).forEach {
this.stuffOf(IDEMagicaStuff::class).forEach {
it.initModel()
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/com/dedztbh/demagica/items/ItemMagicStick.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package com.dedztbh.demagica.items

import com.dedztbh.demagica.DEMagica
import com.dedztbh.demagica.blocks.BlockMagic
import com.dedztbh.demagica.global.Config
import com.dedztbh.demagica.global.IDEMagicaItem
import com.dedztbh.demagica.global.ModItems
import com.dedztbh.demagica.global.ServerTickOS
import com.dedztbh.demagica.util.TickTaskManager
import com.dedztbh.demagica.util.isLocal
import com.dedztbh.demagica.util.nextPitch
import com.dedztbh.demagica.util.onlyIfNot
import net.minecraft.client.renderer.block.model.ModelResourceLocation
import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.player.EntityPlayer
Expand Down Expand Up @@ -83,7 +85,7 @@ class ItemMagicStick : ItemSword(ToolMaterial.GOLD), IDEMagicaItem {

taskManager.runTask(20, false) {
target.apply {
world.createExplosion(attacker, posX, posY, posZ, 5f, true)
world.createExplosion(attacker onlyIfNot Config.explosionDoAffectSelf, posX, posY, posZ, 5f, true)
world.playSound(attacker as? EntityPlayer, posX, posY, posZ, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 10f, Random.nextPitch())
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.dedztbh.demagica.projectile

import com.dedztbh.demagica.global.Config
import com.dedztbh.demagica.util.isLocal
import com.dedztbh.demagica.util.onlyIfNot
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.util.math.RayTraceResult
import net.minecraft.world.World
Expand All @@ -11,7 +13,7 @@ import net.minecraft.world.World
* Project DEMagica
*/

open class MagicBallHeavy : MagicBall {
class MagicBallHeavy : MagicBall {

constructor(worldIn: World) : super(worldIn)

Expand All @@ -26,7 +28,7 @@ open class MagicBallHeavy : MagicBall {
override fun onHit(raytraceResultIn: RayTraceResult) {
super.onHit(raytraceResultIn)
if (world.isLocal) {
world.newExplosion(this, posX, posY, posZ, 1f, false, false)
world.newExplosion(thrower onlyIfNot Config.explosionDoAffectSelf, posX, posY, posZ, 1f, false, false)
setDead()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.dedztbh.demagica.projectile

import com.dedztbh.demagica.global.Config
import com.dedztbh.demagica.util.isLocal
import com.dedztbh.demagica.util.onlyIfNot
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.init.SoundEvents
import net.minecraft.util.SoundEvent
Expand All @@ -24,7 +26,7 @@ open class MagicBallKatyusha : MagicBall {

override fun onHit(raytraceResultIn: RayTraceResult) {
if (world.isLocal) {
world.newExplosion(this, posX, posY, posZ, 3f, true, true)
world.newExplosion(thrower onlyIfNot Config.explosionDoAffectSelf, posX, posY, posZ, 3f, true, true)
setDead()
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/com/dedztbh/demagica/projectile/MagicBomb.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.dedztbh.demagica.projectile

import com.dedztbh.demagica.global.Config
import com.dedztbh.demagica.util.isLocal
import com.dedztbh.demagica.util.onlyIfNot
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.util.math.RayTraceResult
import net.minecraft.world.World
Expand All @@ -22,7 +24,7 @@ class MagicBomb : MagicBall {
override fun onHit(raytraceResultIn: RayTraceResult) {
super.onHit(raytraceResultIn)
if (world.isLocal) {
world.newExplosion(this, posX, posY, posZ, 6f, true, true)
world.newExplosion(thrower onlyIfNot Config.explosionDoAffectSelf, posX, posY, posZ, 6f, true, true)
setDead()
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/main/kotlin/com/dedztbh/demagica/proxy/CommonProxy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.dedztbh.demagica.global.IDEMagicaBlock
import com.dedztbh.demagica.global.ModBlocks
import com.dedztbh.demagica.global.ModItems
import com.dedztbh.demagica.projectile.*
import com.dedztbh.demagica.util.Open
import com.dedztbh.demagica.util.then
import net.minecraft.block.Block
import net.minecraft.item.Item
Expand All @@ -25,7 +26,8 @@ import java.io.File


@Mod.EventBusSubscriber
open class CommonProxy {
@Open
class CommonProxy {
companion object {
// Config instance
@JvmStatic
Expand All @@ -34,7 +36,7 @@ open class CommonProxy {
@JvmStatic
@SubscribeEvent
fun registerBlocks(event: RegistryEvent.Register<Block>) {
ModBlocks.stuffOf(Block::class.java, IDEMagicaBlock::class.java, newInstance = true).forEach {
ModBlocks.stuffOf(Block::class, IDEMagicaBlock::class, newInstance = true).forEach {
event.registry.register(it)
it.hasTileEntity(it.defaultState) then {
it as IDEMagicaBlock
Expand All @@ -46,17 +48,17 @@ open class CommonProxy {
@JvmStatic
@SubscribeEvent
fun registerItems(event: RegistryEvent.Register<Item>) {
ModItems.stuffOf(Item::class.java, newInstance = true).forEach {
ModItems.stuffOf(Item::class, newInstance = true).forEach {
event.registry.register(it)
}

ModBlocks.stuffOf(Block::class.java).forEach {
ModBlocks.stuffOf(Block::class).forEach {
event.registry.register(ItemBlock(it).setRegistryName(ModBlocks.blockMagic.registryName))
}
}
}

open fun preInit(e: FMLPreInitializationEvent) {
fun preInit(e: FMLPreInitializationEvent) {
val directory = e.modConfigurationDirectory
config = Configuration(File(directory.path, "demagica.cfg"))
Config.readConfig()
Expand All @@ -72,9 +74,9 @@ open class CommonProxy {
RenderingRegistry.registerEntityRenderingHandler(MagicBallKatyusha::class.java, MagicBallRenderFactory())
}

open fun init(e: FMLInitializationEvent) {}
fun init(e: FMLInitializationEvent) {}

open fun postInit(e: FMLPostInitializationEvent) {
fun postInit(e: FMLPostInitializationEvent) {
if (config.hasChanged()) {
config.save()
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/com/dedztbh/demagica/util/Helper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ fun Int.toBool(): Boolean = this != 0

infix fun <T : Comparable<T>> T.orIfSmaller(b: T) = if (compareTo(b) > 0) b else this

fun <T> nil(): T? = null
fun <T> nil(): T? = null

infix fun <T> T.onlyIf(cond: Boolean): T? = if (cond) this else null
infix fun <T> T.onlyIfNot(cond: Boolean): T? = onlyIf(!cond)

0 comments on commit fca511b

Please sign in to comment.