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

Create reusable FX data and handler classes w/ common parameters

This commit is contained in:
chylex 2019-01-18 05:00:35 +01:00
parent 548953bf9a
commit 6791ed30b4
6 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,11 @@
package chylex.hee.game.fx
import chylex.hee.system.util.use
import chylex.hee.system.util.writePos
import io.netty.buffer.ByteBuf
import net.minecraft.util.math.BlockPos
class FxBlockData(private val pos: BlockPos) : IFxData{
override fun write(buffer: ByteBuf) = buffer.use {
writePos(pos)
}
}

View File

@ -0,0 +1,15 @@
package chylex.hee.game.fx
import chylex.hee.system.util.readPos
import chylex.hee.system.util.use
import io.netty.buffer.ByteBuf
import net.minecraft.util.math.BlockPos
import net.minecraft.world.World
import java.util.Random
abstract class FxBlockHandler : IFxHandler<FxBlockData>{
final override fun handle(buffer: ByteBuf, world: World, rand: Random) = buffer.use {
handle(readPos(), world, rand)
}
abstract fun handle(pos: BlockPos, world: World, rand: Random)
}

View File

@ -0,0 +1,10 @@
package chylex.hee.game.fx
import chylex.hee.system.util.use
import io.netty.buffer.ByteBuf
import net.minecraft.entity.Entity
class FxEntityData(private val entity: Entity) : IFxData{
override fun write(buffer: ByteBuf) = buffer.use {
writeInt(entity.entityId)
}
}

View File

@ -0,0 +1,14 @@
package chylex.hee.game.fx
import chylex.hee.system.util.use
import io.netty.buffer.ByteBuf
import net.minecraft.entity.Entity
import net.minecraft.world.World
import java.util.Random
abstract class FxEntityHandler : IFxHandler<FxEntityData>{
final override fun handle(buffer: ByteBuf, world: World, rand: Random) = buffer.use {
world.getEntityByID(readInt())?.let { handle(it, rand) }
}
abstract fun handle(entity: Entity, rand: Random)
}

View File

@ -0,0 +1,6 @@
package chylex.hee.game.fx
import io.netty.buffer.ByteBuf
interface IFxData{
fun write(buffer: ByteBuf)
}

View File

@ -0,0 +1,9 @@
package chylex.hee.game.fx
import io.netty.buffer.ByteBuf
import net.minecraft.world.World
import java.util.Random
@Suppress("unused")
interface IFxHandler<T : IFxData>{
fun handle(buffer: ByteBuf, world: World, rand: Random)
}