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:
parent
548953bf9a
commit
6791ed30b4
src/main/java/chylex/hee/game/fx
11
src/main/java/chylex/hee/game/fx/FxBlockData.kt
Normal file
11
src/main/java/chylex/hee/game/fx/FxBlockData.kt
Normal 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)
|
||||
}
|
||||
}
|
15
src/main/java/chylex/hee/game/fx/FxBlockHandler.kt
Normal file
15
src/main/java/chylex/hee/game/fx/FxBlockHandler.kt
Normal 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)
|
||||
}
|
10
src/main/java/chylex/hee/game/fx/FxEntityData.kt
Normal file
10
src/main/java/chylex/hee/game/fx/FxEntityData.kt
Normal 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)
|
||||
}
|
||||
}
|
14
src/main/java/chylex/hee/game/fx/FxEntityHandler.kt
Normal file
14
src/main/java/chylex/hee/game/fx/FxEntityHandler.kt
Normal 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)
|
||||
}
|
6
src/main/java/chylex/hee/game/fx/IFxData.kt
Normal file
6
src/main/java/chylex/hee/game/fx/IFxData.kt
Normal file
@ -0,0 +1,6 @@
|
||||
package chylex.hee.game.fx
|
||||
import io.netty.buffer.ByteBuf
|
||||
|
||||
interface IFxData{
|
||||
fun write(buffer: ByteBuf)
|
||||
}
|
9
src/main/java/chylex/hee/game/fx/IFxHandler.kt
Normal file
9
src/main/java/chylex/hee/game/fx/IFxHandler.kt
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user