1
0
mirror of https://github.com/chylex/Hardcore-Ender-Expansion-2.git synced 2024-11-25 13:42:44 +01:00

Compare commits

..

4 Commits

52 changed files with 287 additions and 319 deletions

View File

@ -16,7 +16,7 @@ buildscript {
ext { ext {
forge_gradle_version = "4.1.+" forge_gradle_version = "4.1.+"
mixin_gradle_version = "0.7-SNAPSHOT" mixin_gradle_version = "0.7-SNAPSHOT"
kotlin_version = "1.5.20" kotlin_version = "1.7.0"
} }
repositories { repositories {
@ -83,16 +83,13 @@ allprojects {
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) { tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
kotlinOptions { kotlinOptions {
jvmTarget = "1.8" jvmTarget = "1.8"
apiVersion = "1.5" apiVersion = "1.7"
languageVersion = "1.5" languageVersion = "1.7"
useIR = true
freeCompilerArgs = [ freeCompilerArgs = [
"-Xno-call-assertions", "-Xno-call-assertions",
"-Xno-param-assertions", "-Xno-param-assertions",
"-Xno-receiver-assertions", "-Xno-receiver-assertions",
"-Xjvm-default=all", "-XXLanguage:+InlineClasses",
"-Xuse-experimental=kotlin.contracts.ExperimentalContracts",
"-XXLanguage:+InlineClasses"
] ]
} }
} }

View File

@ -1,8 +1,6 @@
package chylex.hee.game.world.generation.noise package chylex.hee.game.world.generation.noise
import chylex.hee.util.math.FloatRange import chylex.hee.util.math.remap
import chylex.hee.util.math.range
import chylex.hee.util.math.remapRange
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.pow import kotlin.math.pow
import kotlin.math.roundToInt import kotlin.math.roundToInt
@ -28,12 +26,12 @@ class NoiseValue(var value: Double) {
it.coerceIn(minimum, maximum) it.coerceIn(minimum, maximum)
} }
fun remap(oldRange: FloatRange, newRange: FloatRange) = then { fun remap(fromMin: Double, fromMax: Double, toMin: Double, toMax: Double) = then {
remapRange(it, oldRange, newRange) it.remap(fromMin, fromMax, toMin, toMax)
} }
fun remap(newRange: FloatRange) = then { fun remap(toMin: Double, toMax: Double) = then {
remapRange(it, range(0F, 1F), newRange) it.remap(fromMin = 0.0, fromMax = 1.0, toMin, toMax)
} }
inline fun ifNonZero(block: NoiseValue.() -> Unit) { inline fun ifNonZero(block: NoiseValue.() -> Unit) {

View File

@ -18,54 +18,65 @@ import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.vector.Vector3d import net.minecraft.util.math.vector.Vector3d
import org.apache.logging.log4j.Logger import org.apache.logging.log4j.Logger
inline fun <T : PacketBuffer> T.use(block: T.() -> Unit) {
block()
}
// BlockPos // BlockPos
inline fun PacketBuffer.writePos(pos: BlockPos) { inline fun ByteBuf.writePos(pos: BlockPos) {
this.writeLong(pos.toLong()) this.writeLong(pos.toLong())
} }
inline fun PacketBuffer.readPos(): BlockPos { inline fun ByteBuf.readPos(): BlockPos {
return Pos(this.readLong()) return Pos(this.readLong())
} }
// Vec3d (Full) // Vec3d (Full)
fun PacketBuffer.writeVec(vec: Vector3d) { fun ByteBuf.writeVec(vec: Vector3d) {
this.writeDouble(vec.x) this.writeDouble(vec.x)
this.writeDouble(vec.y) this.writeDouble(vec.y)
this.writeDouble(vec.z) this.writeDouble(vec.z)
} }
fun PacketBuffer.readVec(): Vector3d { fun ByteBuf.readVec(): Vector3d {
return Vec(readDouble(), readDouble(), readDouble()) return Vec(this.readDouble(), this.readDouble(), this.readDouble())
} }
// Vec3d (Float) // Vec3d (Float)
fun PacketBuffer.writeFloatVec(vec: Vector3d) { fun ByteBuf.writeFloatVec(vec: Vector3d) {
this.writeFloat(vec.x.toFloat()) this.writeFloat(vec.x.toFloat())
this.writeFloat(vec.y.toFloat()) this.writeFloat(vec.y.toFloat())
this.writeFloat(vec.z.toFloat()) this.writeFloat(vec.z.toFloat())
} }
fun PacketBuffer.readFloatVec(): Vector3d { fun ByteBuf.readFloatVec(): Vector3d {
return Vec(readFloat().toDouble(), readFloat().toDouble(), readFloat().toDouble()) return Vec(this.readFloat().toDouble(), this.readFloat().toDouble(), this.readFloat().toDouble())
} }
// Vec3d (Compact) // Vec3d (Compact)
fun PacketBuffer.writeCompactVec(vec: Vector3d) { fun ByteBuf.writeCompactVec(vec: Vector3d) {
this.writeInt((vec.x * 8.0).floorToInt()) this.writeInt((vec.x * 8.0).floorToInt())
this.writeInt((vec.y * 8.0).floorToInt()) this.writeInt((vec.y * 8.0).floorToInt())
this.writeInt((vec.z * 8.0).floorToInt()) this.writeInt((vec.z * 8.0).floorToInt())
} }
fun PacketBuffer.readCompactVec(): Vector3d { fun ByteBuf.readCompactVec(): Vector3d {
return Vec(readInt() * 0.125, readInt() * 0.125, readInt() * 0.125) return Vec(this.readInt() * 0.125, this.readInt() * 0.125, this.readInt() * 0.125)
}
// Enum
fun <T : Enum<T>> PacketBuffer.writeEnum(value: T?) {
this.writeVarInt(value?.ordinal ?: -1)
}
inline fun <reified T : Enum<T>> PacketBuffer.readEnum(): T? {
val ordinal = this.readVarInt()
return if (ordinal >= 0)
T::class.java.enumConstants.getOrNull(ordinal)
else
null
} }
// NBT // NBT

View File

@ -46,17 +46,17 @@ fun lerp(from: Double, to: Double, progress: Double): Double {
} }
/** /**
* Maps a range of values in [from] range to values in [to] range using linear interpolation. * Remaps a value from the range [[fromMin], [fromMax]] to a value in the range [[toMin], [toMax]] using linear interpolation.
*/ */
fun remapRange(value: Float, from: FloatRange, to: FloatRange): Float { fun Float.remap(fromMin: Float, fromMax: Float, toMin: Float, toMax: Float): Float {
val remappedBetween0And1 = (value - from.start) / (from.end - from.start) val remappedBetween0And1 = (this - fromMin) / (fromMax - fromMin)
return to.start + remappedBetween0And1 * (to.end - to.start) return toMin + remappedBetween0And1 * (toMax - toMin)
} }
/** /**
* Maps a range of values in [from] range to values in [to] range using linear interpolation. * Remaps a value from the range [[fromMin], [fromMax]] to a value in the range [[toMin], [toMax]] using linear interpolation.
*/ */
fun remapRange(value: Double, from: FloatRange, to: FloatRange): Double { fun Double.remap(fromMin: Double, fromMax: Double, toMin: Double, toMax: Double): Double {
val remappedBetween0And1 = (value - from.start) / (from.end - from.start) val remappedBetween0And1 = (this - fromMin) / (fromMax - fromMin)
return to.start + remappedBetween0And1 * (to.end - to.start) return toMin + remappedBetween0And1 * (toMax - toMin)
} }

View File

@ -1,14 +0,0 @@
package chylex.hee.util.math
@JvmInline
value class FloatRange(private val combined: Long) {
constructor(start: Float, end: Float) : this((start.toRawBits() shlong 32) or (end.toRawBits().toLong() and 0xFFFF_FFFFL))
val start
get() = Float.fromBits((combined ushr 32).toInt())
val end
get() = Float.fromBits((combined and 0xFFFF_FFFFL).toInt())
}
fun range(start: Float, end: Float) = FloatRange(start, end)

View File

@ -15,6 +15,7 @@ import net.minecraftforge.common.util.Constants.NBT
import org.apache.logging.log4j.Logger import org.apache.logging.log4j.Logger
import java.util.Locale import java.util.Locale
import java.util.UUID import java.util.UUID
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract import kotlin.contracts.contract
typealias NBTBase = net.minecraft.nbt.INBT typealias NBTBase = net.minecraft.nbt.INBT
@ -54,12 +55,14 @@ inline fun TagCompound.hasKey(key: String, type: Int): Boolean {
return this.contains(key, type) return this.contains(key, type)
} }
@OptIn(ExperimentalContracts::class)
@JvmName("isNotNullAndHasKey") @JvmName("isNotNullAndHasKey")
inline fun TagCompound?.hasKey(key: String): Boolean { inline fun TagCompound?.hasKey(key: String): Boolean {
contract { returns(true) implies (this@hasKey != null) } contract { returns(true) implies (this@hasKey != null) }
return this != null && this.hasKey(key) return this != null && this.hasKey(key)
} }
@OptIn(ExperimentalContracts::class)
@JvmName("isNotNullAndHasKey") @JvmName("isNotNullAndHasKey")
inline fun TagCompound?.hasKey(key: String, type: Int): Boolean { inline fun TagCompound?.hasKey(key: String, type: Int): Boolean {
contract { returns(true) implies (this@hasKey != null) } contract { returns(true) implies (this@hasKey != null) }

View File

@ -1,7 +1,6 @@
package chylex.hee.util.random package chylex.hee.util.random
import chylex.hee.util.math.range import chylex.hee.util.math.remap
import chylex.hee.util.math.remapRange
import java.util.Random import java.util.Random
import kotlin.math.pow import kotlin.math.pow
@ -30,7 +29,7 @@ abstract class RandomDouble private constructor(val min: Double, val max: Double
fun Exp(min: Double, max: Double, exp: Double) = object : RandomDouble(min, max) { fun Exp(min: Double, max: Double, exp: Double) = object : RandomDouble(min, max) {
override fun invoke(rand: Random): Double { override fun invoke(rand: Random): Double {
return remapRange(rand.nextDouble().pow(exp), range(0F, 1F), range(min.toFloat(), max.toFloat())) return rand.nextDouble().pow(exp).remap(fromMin = 0.0, fromMax = 1.0, toMin = min, toMax = max)
} }
} }
} }

View File

@ -1,3 +1,5 @@
rootProject.name = "HEE"
include ":util" include ":util"
include ":system" include ":system"
include ":debug" include ":debug"

View File

@ -25,8 +25,7 @@ import chylex.hee.util.forge.SubscribeAllEvents
import chylex.hee.util.forge.SubscribeEvent import chylex.hee.util.forge.SubscribeEvent
import chylex.hee.util.math.LerpedFloat import chylex.hee.util.math.LerpedFloat
import chylex.hee.util.math.floorToInt import chylex.hee.util.math.floorToInt
import chylex.hee.util.math.range import chylex.hee.util.math.remap
import chylex.hee.util.math.remapRange
import chylex.hee.util.math.scale import chylex.hee.util.math.scale
import com.mojang.blaze3d.matrix.MatrixStack import com.mojang.blaze3d.matrix.MatrixStack
import com.mojang.blaze3d.platform.GlStateManager.FogMode.EXP2 import com.mojang.blaze3d.platform.GlStateManager.FogMode.EXP2
@ -118,7 +117,7 @@ object TerritoryRenderer {
// Fog rendering // Fog rendering
private val currentFogDensityMp private val currentFogDensityMp
get() = 1F + (9F * remapRange(currentVoidFactor, range(-0.5F, 1F), range(0F, 1F)).coerceIn(0F, 1F).pow(1.5F)) get() = 1F + (9F * currentVoidFactor.remap(fromMin = -0.5F, fromMax = 1F, toMin = 0F, toMax = 1F).coerceIn(0F, 1F).pow(1.5F))
private val currentRenderDistanceMp private val currentRenderDistanceMp
get() = MC.settings.renderDistanceChunks.let { if (it > 12) 0F else (1F - (it / 16.5F)).pow((it - 1) * 0.25F) } get() = MC.settings.renderDistanceChunks.let { if (it > 12) 0F else (1F - (it / 16.5F)).pow((it - 1) * 0.25F) }
@ -148,7 +147,7 @@ object TerritoryRenderer {
get() = Void.voidFactor.get(MC.partialTicks) get() = Void.voidFactor.get(MC.partialTicks)
val currentSkyAlpha val currentSkyAlpha
get() = remapRange(currentVoidFactor, range(-1F, 0.5F), range(1F, 0F)).coerceIn(0F, 1F) get() = currentVoidFactor.remap(fromMin = -1F, fromMax = 0.5F, toMin = 1F, toMax = 0F).coerceIn(0F, 1F)
private object Void { private object Void {
private val VOID_PARTICLE = ParticleSpawnerCustom( private val VOID_PARTICLE = ParticleSpawnerCustom(

View File

@ -49,13 +49,13 @@ class RenderEntityTokenHolder(manager: EntityRendererManager) : EntityRenderer<E
matrix.rotateX(55F) matrix.rotateX(55F)
matrix.rotateZ(55F) matrix.rotateZ(55F)
ModelEntityTokenHolder.render(matrix, buffer.getBuffer(RenderType.getEntityTranslucent(getEntityTexture(entity) ?: textures.getValue(NORMAL))), combinedLight, OverlayTexture.NO_OVERLAY, 1F, 1F, 1F, alpha) ModelEntityTokenHolder.render(matrix, buffer.getBuffer(RenderType.getEntityTranslucent(getEntityTexture(entity))), combinedLight, OverlayTexture.NO_OVERLAY, 1F, 1F, 1F, alpha)
matrix.pop() matrix.pop()
matrix.pop() matrix.pop()
} }
override fun getEntityTexture(entity: EntityTokenHolder): ResourceLocation? { override fun getEntityTexture(entity: EntityTokenHolder): ResourceLocation {
return textures[entity.tokenType] return textures.getValue(entity.tokenType)
} }
} }

View File

@ -32,7 +32,6 @@ import chylex.hee.game.world.util.setState
import chylex.hee.init.ModSounds import chylex.hee.init.ModSounds
import chylex.hee.network.client.PacketClientFX import chylex.hee.network.client.PacketClientFX
import chylex.hee.util.buffer.readPos import chylex.hee.util.buffer.readPos
import chylex.hee.util.buffer.use
import chylex.hee.util.buffer.writePos import chylex.hee.util.buffer.writePos
import chylex.hee.util.math.center import chylex.hee.util.math.center
import chylex.hee.util.nbt.TagCompound import chylex.hee.util.nbt.TagCompound
@ -174,9 +173,9 @@ interface IBlockDeathFlowerDecaying {
private val PARTICLE_MOT = Gaussian(0.02F) private val PARTICLE_MOT = Gaussian(0.02F)
class FxHealData(private val pos: BlockPos, private val newLevel: Int) : IFxData { class FxHealData(private val pos: BlockPos, private val newLevel: Int) : IFxData {
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writePos(pos) buffer.writePos(pos)
writeByte(newLevel) buffer.writeByte(newLevel)
} }
} }

View File

@ -27,7 +27,6 @@ import chylex.hee.init.ModSounds
import chylex.hee.init.ModTileEntities import chylex.hee.init.ModTileEntities
import chylex.hee.network.client.PacketClientFX import chylex.hee.network.client.PacketClientFX
import chylex.hee.util.buffer.readCompactVec import chylex.hee.util.buffer.readCompactVec
import chylex.hee.util.buffer.use
import chylex.hee.util.buffer.writeCompactVec import chylex.hee.util.buffer.writeCompactVec
import chylex.hee.util.collection.mutableWeightedListOf import chylex.hee.util.collection.mutableWeightedListOf
import chylex.hee.util.collection.weightedListOf import chylex.hee.util.collection.weightedListOf
@ -119,17 +118,17 @@ class TileEntityMinersBurialAltar(type: TileEntityType<TileEntityMinersBurialAlt
) )
class FxSpawnData(private val pos: Vector3d, private val type: Byte) : IFxData { class FxSpawnData(private val pos: Vector3d, private val type: Byte) : IFxData {
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writeCompactVec(pos) buffer.writeCompactVec(pos)
writeByte(type.toInt()) buffer.writeByte(type.toInt())
} }
} }
val FX_SPAWN = object : IFxHandler<FxSpawnData> { val FX_SPAWN = object : IFxHandler<FxSpawnData> {
override fun handle(buffer: PacketBuffer, world: World, rand: Random) = buffer.use { override fun handle(buffer: PacketBuffer, world: World, rand: Random) {
val pos = readCompactVec() val pos = buffer.readCompactVec()
when (readByte()) { when (buffer.readByte()) {
REDEEM_TYPE_TOKEN -> { REDEEM_TYPE_TOKEN -> {
PARTICLE_SPAWN.spawn(Point(pos, 9), rand) PARTICLE_SPAWN.spawn(Point(pos, 9), rand)
} }

View File

@ -36,6 +36,7 @@ abstract class TileEntityBasePortalController(type: TileEntityType<out TileEntit
when (clientRenderState) { when (clientRenderState) {
Invisible -> clientAnimationProgress.update(max(0F, clientAnimationProgress - clientAnimationFadeOutSpeed)) Invisible -> clientAnimationProgress.update(max(0F, clientAnimationProgress - clientAnimationFadeOutSpeed))
is Animating -> clientAnimationProgress.update(min(1F, clientAnimationProgress + clientAnimationFadeInSpeed)) is Animating -> clientAnimationProgress.update(min(1F, clientAnimationProgress + clientAnimationFadeInSpeed))
else -> {}
} }
} }

View File

@ -23,8 +23,9 @@ import chylex.hee.network.client.PacketClientMoveYourAss
import chylex.hee.network.client.PacketClientRotateInstantly import chylex.hee.network.client.PacketClientRotateInstantly
import chylex.hee.network.client.PacketClientTeleportInstantly import chylex.hee.network.client.PacketClientTeleportInstantly
import chylex.hee.util.buffer.readCompactVec import chylex.hee.util.buffer.readCompactVec
import chylex.hee.util.buffer.use import chylex.hee.util.buffer.readEnum
import chylex.hee.util.buffer.writeCompactVec import chylex.hee.util.buffer.writeCompactVec
import chylex.hee.util.buffer.writeEnum
import chylex.hee.util.math.Pos import chylex.hee.util.math.Pos
import chylex.hee.util.math.Vec import chylex.hee.util.math.Vec
import chylex.hee.util.math.addY import chylex.hee.util.math.addY
@ -78,16 +79,16 @@ class Teleporter(
private val soundVolume: Float, private val soundVolume: Float,
private val extraRange: Float = 0F, private val extraRange: Float = 0F,
) : IFxData { ) : IFxData {
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writeCompactVec(startPoint) buffer.writeCompactVec(startPoint)
writeCompactVec(endPoint) buffer.writeCompactVec(endPoint)
writeByte((width * 10F).floorToInt().coerceIn(0, 100)) buffer.writeByte((width * 10F).floorToInt().coerceIn(0, 100))
writeByte((height * 10F).floorToInt().coerceIn(0, 100)) buffer.writeByte((height * 10F).floorToInt().coerceIn(0, 100))
writeRegistryId(soundEvent) buffer.writeRegistryId(soundEvent)
writeEnumValue(soundCategory) buffer.writeEnum(soundCategory)
writeByte((soundVolume * 10F).floorToInt().coerceIn(0, 250)) buffer.writeByte((soundVolume * 10F).floorToInt().coerceIn(0, 250))
writeByte(extraRange.floorToInt().coerceIn(0, 255)) buffer.writeByte(extraRange.floorToInt().coerceIn(0, 255))
} }
fun send(world: World) { fun send(world: World) {
@ -99,20 +100,20 @@ class Teleporter(
} }
val FX_TELEPORT = object : IFxHandler<FxTeleportData> { val FX_TELEPORT = object : IFxHandler<FxTeleportData> {
override fun handle(buffer: PacketBuffer, world: World, rand: Random) = buffer.use { override fun handle(buffer: PacketBuffer, world: World, rand: Random) {
val player = MC.player ?: return val player = MC.player ?: return
val playerPos = player.posVec val playerPos = player.posVec
val startPoint = readCompactVec() val startPoint = buffer.readCompactVec()
val endPoint = readCompactVec() val endPoint = buffer.readCompactVec()
val halfWidth = (readByte() / 10F) * 0.5F val halfWidth = (buffer.readByte() / 10F) * 0.5F
val halfHeight = (readByte() / 10F) * 0.5F val halfHeight = (buffer.readByte() / 10F) * 0.5F
val soundEvent = readRegistryIdSafe(SoundEvent::class.java) val soundEvent = buffer.readRegistryIdSafe(SoundEvent::class.java)
val soundCategory = readEnumValue(SoundCategory::class.java) val soundCategory = buffer.readEnum() ?: SoundCategory.NEUTRAL
val soundVolume = readByte() / 10F val soundVolume = buffer.readByte() / 10F
val soundRange = 16F + readByte() val soundRange = 16F + buffer.readByte()
val soundPosition = if (playerPos.squareDistanceTo(startPoint) < playerPos.squareDistanceTo(endPoint)) val soundPosition = if (playerPos.squareDistanceTo(startPoint) < playerPos.squareDistanceTo(endPoint))
startPoint startPoint

View File

@ -16,7 +16,6 @@ import chylex.hee.game.world.util.getTile
import chylex.hee.game.world.util.removeBlock import chylex.hee.game.world.util.removeBlock
import chylex.hee.game.world.util.setState import chylex.hee.game.world.util.setState
import chylex.hee.init.ModEntities import chylex.hee.init.ModEntities
import chylex.hee.util.buffer.use
import chylex.hee.util.math.Pos import chylex.hee.util.math.Pos
import chylex.hee.util.math.Vec3 import chylex.hee.util.math.Vec3
import chylex.hee.util.math.subtractY import chylex.hee.util.math.subtractY
@ -86,12 +85,12 @@ open class EntityFallingBlockHeavy(type: EntityType<out EntityFallingBlockHeavy>
return NetworkHooks.getEntitySpawningPacket(this) return NetworkHooks.getEntitySpawningPacket(this)
} }
override fun writeSpawnData(buffer: PacketBuffer) = buffer.use { override fun writeSpawnData(buffer: PacketBuffer) {
writeInt(fallTile?.let(Block::getStateId) ?: 0) buffer.writeInt(fallTile?.let(Block::getStateId) ?: 0)
} }
override fun readSpawnData(buffer: PacketBuffer) = buffer.use { override fun readSpawnData(buffer: PacketBuffer) {
fallTile = Block.getStateById(readInt()) fallTile = Block.getStateById(buffer.readInt())
} }
override fun tick() { override fun tick() {

View File

@ -18,7 +18,6 @@ import chylex.hee.init.ModEntities
import chylex.hee.init.ModSounds import chylex.hee.init.ModSounds
import chylex.hee.network.client.PacketClientFX import chylex.hee.network.client.PacketClientFX
import chylex.hee.util.buffer.readPos import chylex.hee.util.buffer.readPos
import chylex.hee.util.buffer.use
import chylex.hee.util.buffer.writePos import chylex.hee.util.buffer.writePos
import chylex.hee.util.math.Pos import chylex.hee.util.math.Pos
import chylex.hee.util.random.nextFloat import chylex.hee.util.random.nextFloat
@ -45,16 +44,16 @@ class EntityFallingObsidian : EntityFallingBlockHeavy {
private val DAMAGE = Damage(PEACEFUL_EXCLUSION, ARMOR_PROTECTION(false), ENCHANTMENT_PROTECTION) private val DAMAGE = Damage(PEACEFUL_EXCLUSION, ARMOR_PROTECTION(false), ENCHANTMENT_PROTECTION)
class FxFallData(private val pos: BlockPos, private val volume: Float) : IFxData { class FxFallData(private val pos: BlockPos, private val volume: Float) : IFxData {
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writePos(pos) buffer.writePos(pos)
writeFloat(volume) buffer.writeFloat(volume)
} }
} }
val FX_FALL = object : IFxHandler<FxFallData> { val FX_FALL = object : IFxHandler<FxFallData> {
override fun handle(buffer: PacketBuffer, world: World, rand: Random) = buffer.use { override fun handle(buffer: PacketBuffer, world: World, rand: Random) {
val pos = readPos() val pos = buffer.readPos()
val volume = readFloat() val volume = buffer.readFloat()
repeat(2) { repeat(2) {
ModSounds.BLOCK_OBSIDIAN_LAND.playClient(pos, SoundCategory.BLOCKS, volume = volume, pitch = rand.nextFloat(0.8F, 1.2F)) ModSounds.BLOCK_OBSIDIAN_LAND.playClient(pos, SoundCategory.BLOCKS, volume = volume, pitch = rand.nextFloat(0.8F, 1.2F))

View File

@ -24,8 +24,7 @@ import chylex.hee.init.ModEntities
import chylex.hee.system.heeTag import chylex.hee.system.heeTag
import chylex.hee.util.math.Vec import chylex.hee.util.math.Vec
import chylex.hee.util.math.center import chylex.hee.util.math.center
import chylex.hee.util.math.range import chylex.hee.util.math.remap
import chylex.hee.util.math.remapRange
import chylex.hee.util.nbt.TagCompound import chylex.hee.util.nbt.TagCompound
import chylex.hee.util.nbt.use import chylex.hee.util.nbt.use
import chylex.hee.util.random.nextFloat import chylex.hee.util.random.nextFloat
@ -269,9 +268,9 @@ class EntityInfusedTNT : TNTEntity {
val waterRatio = foundWaterBlocks.size.toFloat() / totalCountedBlocks val waterRatio = foundWaterBlocks.size.toFloat() / totalCountedBlocks
val dropAmount = when { val dropAmount = when {
waterRatio < 0.1 -> remapRange(waterRatio, range(0.0F, 0.1F), range(1.0F, 1.6F)) waterRatio < 0.1 -> waterRatio.remap(fromMin = 0.0F, fromMax = 0.1F, toMin = 1.0F, toMax = 1.6F)
waterRatio < 0.4 -> remapRange(waterRatio, range(0.1F, 0.4F), range(1.6F, 4.0F)) waterRatio < 0.4 -> waterRatio.remap(fromMin = 0.1F, fromMax = 0.4F, toMin = 1.6F, toMax = 4.0F)
else -> remapRange(waterRatio, range(0.4F, 1.0F), range(4.0F, 5.8F)) else -> waterRatio.remap(fromMin = 0.4F, fromMax = 1.0F, toMin = 4.0F, toMax = 5.8F)
} }
val lootTable = Environment.getLootTable(LootTables.GAMEPLAY_FISHING) val lootTable = Environment.getLootTable(LootTables.GAMEPLAY_FISHING)

View File

@ -5,7 +5,6 @@ import chylex.hee.game.particle.spawner.properties.IOffset.Constant
import chylex.hee.game.particle.spawner.properties.IOffset.InBox import chylex.hee.game.particle.spawner.properties.IOffset.InBox
import chylex.hee.game.particle.spawner.properties.IShape.Point import chylex.hee.game.particle.spawner.properties.IShape.Point
import chylex.hee.init.ModEntities import chylex.hee.init.ModEntities
import chylex.hee.util.buffer.use
import chylex.hee.util.math.square import chylex.hee.util.math.square
import net.minecraft.entity.EntityType import net.minecraft.entity.EntityType
import net.minecraft.item.ItemStack import net.minecraft.item.ItemStack
@ -33,12 +32,12 @@ class EntityItemFreshlyCooked : EntityItemBase, IEntityAdditionalSpawnData {
) )
} }
override fun writeSpawnData(buffer: PacketBuffer) = buffer.use { override fun writeSpawnData(buffer: PacketBuffer) {
writeShort(age) buffer.writeShort(age)
} }
override fun readSpawnData(buffer: PacketBuffer) = buffer.use { override fun readSpawnData(buffer: PacketBuffer) {
age = readShort().toInt() age = buffer.readShort().toInt()
} }
override fun tick() { override fun tick() {

View File

@ -18,7 +18,6 @@ import chylex.hee.init.ModEntities
import chylex.hee.init.ModSounds import chylex.hee.init.ModSounds
import chylex.hee.network.client.PacketClientFX import chylex.hee.network.client.PacketClientFX
import chylex.hee.util.buffer.readPos import chylex.hee.util.buffer.readPos
import chylex.hee.util.buffer.use
import chylex.hee.util.buffer.writePos import chylex.hee.util.buffer.writePos
import chylex.hee.util.math.Pos import chylex.hee.util.math.Pos
import chylex.hee.util.math.center import chylex.hee.util.math.center
@ -46,16 +45,16 @@ class EntityItemRevitalizationSubstance : EntityItemBase {
private const val MAX_RADIUS = 8.5F private const val MAX_RADIUS = 8.5F
class FxRevitalizeGooData(private val center: BlockPos, private val radius: Float) : IFxData { class FxRevitalizeGooData(private val center: BlockPos, private val radius: Float) : IFxData {
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writePos(center) buffer.writePos(center)
writeFloat(radius) buffer.writeFloat(radius)
} }
} }
val FX_REVITALIZE_GOO = object : IFxHandler<FxRevitalizeGooData> { val FX_REVITALIZE_GOO = object : IFxHandler<FxRevitalizeGooData> {
override fun handle(buffer: PacketBuffer, world: World, rand: Random) = buffer.use { override fun handle(buffer: PacketBuffer, world: World, rand: Random) {
val center = readPos() val center = buffer.readPos()
val radius = readFloat() val radius = buffer.readFloat()
forEachGoo(world, center, radius) { pos, _ -> forEachGoo(world, center, radius) { pos, _ ->
BlockEnderGooPurified.FX_PLACE.let { BlockEnderGooPurified.FX_PLACE.let {

View File

@ -22,7 +22,8 @@ import chylex.hee.init.ModSounds
import chylex.hee.network.client.PacketClientFX import chylex.hee.network.client.PacketClientFX
import chylex.hee.network.client.PacketClientLaunchInstantly import chylex.hee.network.client.PacketClientLaunchInstantly
import chylex.hee.system.heeTag import chylex.hee.system.heeTag
import chylex.hee.util.buffer.use import chylex.hee.util.buffer.readEnum
import chylex.hee.util.buffer.writeEnum
import chylex.hee.util.forge.Side import chylex.hee.util.forge.Side
import chylex.hee.util.forge.Sided import chylex.hee.util.forge.Sided
import chylex.hee.util.math.LerpedFloat import chylex.hee.util.math.LerpedFloat
@ -114,16 +115,16 @@ class EntityTokenHolder(type: EntityType<EntityTokenHolder>, world: World) : Ent
dataManager.register(DATA_CHARGE, 1F) dataManager.register(DATA_CHARGE, 1F)
} }
override fun writeSpawnData(buffer: PacketBuffer) = buffer.use { override fun writeSpawnData(buffer: PacketBuffer) {
writeByte(tokenType.ordinal) buffer.writeEnum(tokenType)
writeShort(territoryType?.ordinal ?: -1) buffer.writeEnum(territoryType)
writeFloat(currentCharge) buffer.writeFloat(currentCharge)
} }
override fun readSpawnData(buffer: PacketBuffer) = buffer.use { override fun readSpawnData(buffer: PacketBuffer) {
tokenType = TokenType.values().getOrElse(readByte().toInt()) { TokenType.NORMAL } tokenType = buffer.readEnum<TokenType>() ?: TokenType.NORMAL
territoryType = TerritoryType.values().getOrNull(readShort().toInt()) territoryType = buffer.readEnum<TerritoryType>()
renderCharge.updateImmediately(readFloat()) renderCharge.updateImmediately(buffer.readFloat())
} }
override fun tick() { override fun tick() {

View File

@ -128,6 +128,6 @@ abstract class EntityMobAbstractEnderman(type: EntityType<out EntityMobAbstractE
override fun isDamageAbsolute() = source.isDamageAbsolute override fun isDamageAbsolute() = source.isDamageAbsolute
override fun canHarmInCreative() = source.canHarmInCreative() override fun canHarmInCreative() = source.canHarmInCreative()
override fun getDeathMessage(victim: LivingEntity): ITextComponent? = source.getDeathMessage(victim) override fun getDeathMessage(victim: LivingEntity): ITextComponent = source.getDeathMessage(victim)
} }
} }

View File

@ -38,7 +38,6 @@ import chylex.hee.init.ModSounds
import chylex.hee.network.client.PacketClientFX import chylex.hee.network.client.PacketClientFX
import chylex.hee.system.heeTag import chylex.hee.system.heeTag
import chylex.hee.util.buffer.readTag import chylex.hee.util.buffer.readTag
import chylex.hee.util.buffer.use
import chylex.hee.util.buffer.writeTag import chylex.hee.util.buffer.writeTag
import chylex.hee.util.color.IColorGenerator import chylex.hee.util.color.IColorGenerator
import chylex.hee.util.color.RGB import chylex.hee.util.color.RGB
@ -159,12 +158,12 @@ class EntityMobUndread(type: EntityType<EntityMobUndread>, world: World) : Monst
return NetworkHooks.getEntitySpawningPacket(this) return NetworkHooks.getEntitySpawningPacket(this)
} }
override fun writeSpawnData(buffer: PacketBuffer) = buffer.use { override fun writeSpawnData(buffer: PacketBuffer) {
writeTag(TagCompound().apply { putList(DUSTS_TAG, dustEffects.serializeNBT()) }) buffer.writeTag(TagCompound().apply { putList(DUSTS_TAG, dustEffects.serializeNBT()) })
} }
override fun readSpawnData(buffer: PacketBuffer) = buffer.use { override fun readSpawnData(buffer: PacketBuffer) {
dustEffects = UndreadDustEffects.fromNBT(readTag().getListOfStrings(DUSTS_TAG)) dustEffects = UndreadDustEffects.fromNBT(buffer.readTag().getListOfStrings(DUSTS_TAG))
} }
override fun tick() { override fun tick() {

View File

@ -20,7 +20,6 @@ import chylex.hee.init.ModEntities
import chylex.hee.init.ModSounds import chylex.hee.init.ModSounds
import chylex.hee.system.heeTag import chylex.hee.system.heeTag
import chylex.hee.util.buffer.readDecoded import chylex.hee.util.buffer.readDecoded
import chylex.hee.util.buffer.use
import chylex.hee.util.buffer.writeEncoded import chylex.hee.util.buffer.writeEncoded
import chylex.hee.util.color.RGB import chylex.hee.util.color.RGB
import chylex.hee.util.nbt.TagCompound import chylex.hee.util.nbt.TagCompound
@ -120,22 +119,22 @@ class EntityMobVillagerDying(type: EntityType<EntityMobVillagerDying>, world: Wo
return NetworkHooks.getEntitySpawningPacket(this) return NetworkHooks.getEntitySpawningPacket(this)
} }
override fun writeSpawnData(buffer: PacketBuffer) = buffer.use { override fun writeSpawnData(buffer: PacketBuffer) {
writeEncoded(villager, VillagerData.CODEC, HEE.log) buffer.writeEncoded(villager, VillagerData.CODEC, HEE.log)
writeVarInt(deathTime) buffer.writeVarInt(deathTime)
writeFloat(renderYawOffset) buffer.writeFloat(renderYawOffset)
writeFloat(rotationYawHead) buffer.writeFloat(rotationYawHead)
writeFloat(limbSwing) buffer.writeFloat(limbSwing)
} }
override fun readSpawnData(buffer: PacketBuffer) = buffer.use { override fun readSpawnData(buffer: PacketBuffer) {
villager = readDecoded(VillagerData.CODEC, HEE.log) villager = buffer.readDecoded(VillagerData.CODEC, HEE.log)
deathTime = readVarInt() deathTime = buffer.readVarInt()
renderYawOffset = readFloat() renderYawOffset = buffer.readFloat()
rotationYawHead = readFloat() rotationYawHead = buffer.readFloat()
limbSwing = readFloat() limbSwing = buffer.readFloat()
prevRenderYawOffset = renderYawOffset prevRenderYawOffset = renderYawOffset
prevRotationYawHead = rotationYawHead prevRotationYawHead = rotationYawHead

View File

@ -47,6 +47,7 @@ class AITargetAttackerFixed(entity: MobEntity, private val callReinforcements: B
private fun alertOthers() { private fun alertOthers() {
val maxDistance = targetDistance val maxDistance = targetDistance
val goalOwner = goalOwner
val (x, y, z) = goalOwner.posVec val (x, y, z) = goalOwner.posVec
val friendlies = goalOwner.world.getLoadedEntitiesWithinAABB(goalOwner.javaClass, AxisAlignedBB(x, y, z, x + 1.0, y + 1.0, z + 1.0).grow(maxDistance, 10.0, maxDistance)) val friendlies = goalOwner.world.getLoadedEntitiesWithinAABB(goalOwner.javaClass, AxisAlignedBB(x, y, z, x + 1.0, y + 1.0, z + 1.0).grow(maxDistance, 10.0, maxDistance))

View File

@ -21,7 +21,6 @@ import chylex.hee.game.world.util.getBlocksInside
import chylex.hee.game.world.util.isAir import chylex.hee.game.world.util.isAir
import chylex.hee.init.ModEntities import chylex.hee.init.ModEntities
import chylex.hee.system.heeTag import chylex.hee.system.heeTag
import chylex.hee.util.buffer.use
import chylex.hee.util.forge.EventPriority import chylex.hee.util.forge.EventPriority
import chylex.hee.util.forge.SubscribeAllEvents import chylex.hee.util.forge.SubscribeAllEvents
import chylex.hee.util.forge.SubscribeEvent import chylex.hee.util.forge.SubscribeEvent
@ -130,19 +129,19 @@ class EntityProjectileEnderPearl(type: EntityType<EntityProjectileEnderPearl>, w
return NetworkHooks.getEntitySpawningPacket(this) return NetworkHooks.getEntitySpawningPacket(this)
} }
override fun writeSpawnData(buffer: PacketBuffer) = buffer.use { override fun writeSpawnData(buffer: PacketBuffer) {
writeBoolean(infusions.has(HARMLESS)) buffer.writeBoolean(infusions.has(HARMLESS))
writeBoolean(infusions.has(SLOW)) buffer.writeBoolean(infusions.has(SLOW))
} }
override fun readSpawnData(buffer: PacketBuffer) = buffer.use { override fun readSpawnData(buffer: PacketBuffer) {
var list = InfusionList.EMPTY var list = InfusionList.EMPTY
if (readBoolean()) { if (buffer.readBoolean()) {
list = list.with(HARMLESS) list = list.with(HARMLESS)
} }
if (readBoolean()) { if (buffer.readBoolean()) {
list = list.with(SLOW) list = list.with(SLOW)
} }

View File

@ -21,7 +21,6 @@ import chylex.hee.game.world.util.offsetUntil
import chylex.hee.init.ModEntities import chylex.hee.init.ModEntities
import chylex.hee.system.heeTag import chylex.hee.system.heeTag
import chylex.hee.util.buffer.readPos import chylex.hee.util.buffer.readPos
import chylex.hee.util.buffer.use
import chylex.hee.util.buffer.writePos import chylex.hee.util.buffer.writePos
import chylex.hee.util.color.IColorGenerator import chylex.hee.util.color.IColorGenerator
import chylex.hee.util.color.IntColor import chylex.hee.util.color.IntColor
@ -172,13 +171,13 @@ class EntityProjectileEyeOfEnder(type: EntityType<EntityProjectileEyeOfEnder>, w
return NetworkHooks.getEntitySpawningPacket(this) return NetworkHooks.getEntitySpawningPacket(this)
} }
override fun writeSpawnData(buffer: PacketBuffer) = buffer.use { override fun writeSpawnData(buffer: PacketBuffer) {
writePos(targetPos ?: BlockPos.ZERO) buffer.writePos(targetPos ?: BlockPos.ZERO)
writeShort(timer) buffer.writeShort(timer)
writeFloat(speed) buffer.writeFloat(speed)
} }
override fun readSpawnData(buffer: PacketBuffer) = buffer.use { override fun readSpawnData(buffer: PacketBuffer) {
targetPos = buffer.readPos().takeIf { it != BlockPos.ZERO } targetPos = buffer.readPos().takeIf { it != BlockPos.ZERO }
timer = buffer.readShort().toInt() timer = buffer.readShort().toInt()
speed = buffer.readFloat() speed = buffer.readFloat()

View File

@ -26,7 +26,6 @@ import chylex.hee.init.ModSounds
import chylex.hee.network.client.PacketClientFX import chylex.hee.network.client.PacketClientFX
import chylex.hee.system.heeTag import chylex.hee.system.heeTag
import chylex.hee.util.buffer.readCompactVec import chylex.hee.util.buffer.readCompactVec
import chylex.hee.util.buffer.use
import chylex.hee.util.buffer.writeCompactVec import chylex.hee.util.buffer.writeCompactVec
import chylex.hee.util.color.IColorGenerator import chylex.hee.util.color.IColorGenerator
import chylex.hee.util.color.RGB import chylex.hee.util.color.RGB
@ -119,19 +118,19 @@ class EntityProjectileSpatialDash(type: EntityType<EntityProjectileSpatialDash>,
) )
class FxExpireData(private val point: Vector3d, private val ownerEntity: Entity?) : IFxData { class FxExpireData(private val point: Vector3d, private val ownerEntity: Entity?) : IFxData {
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writeCompactVec(point) buffer.writeCompactVec(point)
writeInt(ownerEntity?.entityId ?: -1) buffer.writeInt(ownerEntity?.entityId ?: -1)
} }
} }
val FX_EXPIRE = object : IFxHandler<FxExpireData> { val FX_EXPIRE = object : IFxHandler<FxExpireData> {
override fun handle(buffer: PacketBuffer, world: World, rand: Random) = buffer.use { override fun handle(buffer: PacketBuffer, world: World, rand: Random) {
val player = MC.player ?: return val player = MC.player ?: return
val playerPos = player.posVec val playerPos = player.posVec
val point = readCompactVec() val point = buffer.readCompactVec()
val forceAudible = readInt() == player.entityId val forceAudible = buffer.readInt() == player.entityId
val soundPoint = if (forceAudible) { val soundPoint = if (forceAudible) {
val distance = playerPos.distanceTo(point) val distance = playerPos.distanceTo(point)

View File

@ -29,7 +29,6 @@ import chylex.hee.init.ModSounds
import chylex.hee.network.client.PacketClientFX import chylex.hee.network.client.PacketClientFX
import chylex.hee.system.heeTag import chylex.hee.system.heeTag
import chylex.hee.util.buffer.readPos import chylex.hee.util.buffer.readPos
import chylex.hee.util.buffer.use
import chylex.hee.util.buffer.writePos import chylex.hee.util.buffer.writePos
import chylex.hee.util.math.Pos import chylex.hee.util.math.Pos
import chylex.hee.util.math.Vec3 import chylex.hee.util.math.Vec3
@ -161,14 +160,14 @@ class EntityTechnicalIgneousPlateLogic(type: EntityType<EntityTechnicalIgneousPl
) )
class FxCoolingData(private val pos: BlockPos, private val amount: Float) : IFxData { class FxCoolingData(private val pos: BlockPos, private val amount: Float) : IFxData {
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writePos(pos) buffer.writePos(pos)
writeFloat(amount) buffer.writeFloat(amount)
} }
} }
val FX_COOLING = object : IFxHandler<FxCoolingData> { val FX_COOLING = object : IFxHandler<FxCoolingData> {
override fun handle(buffer: PacketBuffer, world: World, rand: Random) = buffer.use { override fun handle(buffer: PacketBuffer, world: World, rand: Random) {
val pos = buffer.readPos() val pos = buffer.readPos()
val amount = buffer.readFloat() val amount = buffer.readFloat()

View File

@ -14,7 +14,6 @@ import chylex.hee.game.world.generation.feature.tombdungeon.piece.TombDungeonRoo
import chylex.hee.game.world.generation.feature.tombdungeon.piece.TombDungeonRoom_Tomb import chylex.hee.game.world.generation.feature.tombdungeon.piece.TombDungeonRoom_Tomb
import chylex.hee.init.ModEntities import chylex.hee.init.ModEntities
import chylex.hee.system.heeTag import chylex.hee.system.heeTag
import chylex.hee.util.buffer.use
import chylex.hee.util.delegate.NotifyOnChange import chylex.hee.util.delegate.NotifyOnChange
import chylex.hee.util.nbt.TagCompound import chylex.hee.util.nbt.TagCompound
import chylex.hee.util.nbt.getEnum import chylex.hee.util.nbt.getEnum
@ -93,12 +92,12 @@ class EntityTechnicalTrigger(type: EntityType<EntityTechnicalTrigger>, world: Wo
override fun registerData() {} override fun registerData() {}
override fun writeSpawnData(buffer: PacketBuffer) = buffer.use { override fun writeSpawnData(buffer: PacketBuffer) {
writeInt(type.ordinal) buffer.writeInt(type.ordinal)
} }
override fun readSpawnData(buffer: PacketBuffer) = buffer.use { override fun readSpawnData(buffer: PacketBuffer) {
type = Types.values().getOrNull(readInt()) ?: INVALID type = Types.values().getOrNull(buffer.readInt()) ?: INVALID
} }
override fun tick() { override fun tick() {

View File

@ -27,7 +27,6 @@ import chylex.hee.network.client.PacketClientFX
import chylex.hee.system.heeTag import chylex.hee.system.heeTag
import chylex.hee.system.heeTagOrNull import chylex.hee.system.heeTagOrNull
import chylex.hee.util.buffer.readPos import chylex.hee.util.buffer.readPos
import chylex.hee.util.buffer.use
import chylex.hee.util.buffer.writePos import chylex.hee.util.buffer.writePos
import chylex.hee.util.math.ceilToInt import chylex.hee.util.math.ceilToInt
import chylex.hee.util.math.floorToInt import chylex.hee.util.math.floorToInt
@ -68,9 +67,9 @@ class ItemAbstractEnergyUser(private val impl: IEnergyItem) : HeeItemBuilder() {
} }
class FxChargeData(private val cluster: TileEntityEnergyCluster, private val player: PlayerEntity) : IFxData { class FxChargeData(private val cluster: TileEntityEnergyCluster, private val player: PlayerEntity) : IFxData {
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writePos(cluster.pos) buffer.writePos(cluster.pos)
writeInt(player.entityId) buffer.writeInt(player.entityId)
} }
} }
@ -86,9 +85,9 @@ class ItemAbstractEnergyUser(private val impl: IEnergyItem) : HeeItemBuilder() {
} }
} }
override fun handle(buffer: PacketBuffer, world: World, rand: Random) = buffer.use { override fun handle(buffer: PacketBuffer, world: World, rand: Random) {
val cluster = readPos().getTile<TileEntityEnergyCluster>(world) ?: return val cluster = buffer.readPos().getTile<TileEntityEnergyCluster>(world) ?: return
val player = world.getEntityByID(readInt()) as? PlayerEntity ?: return val player = world.getEntityByID(buffer.readInt()) as? PlayerEntity ?: return
ParticleSpawnerCustom( ParticleSpawnerCustom(
type = ParticleEnergyTransferToPlayer, type = ParticleEnergyTransferToPlayer,

View File

@ -19,8 +19,9 @@ import chylex.hee.game.particle.spawner.properties.IShape.Line
import chylex.hee.game.world.util.getTile import chylex.hee.game.world.util.getTile
import chylex.hee.init.ModSounds import chylex.hee.init.ModSounds
import chylex.hee.network.client.PacketClientFX import chylex.hee.network.client.PacketClientFX
import chylex.hee.util.buffer.readEnum
import chylex.hee.util.buffer.readPos import chylex.hee.util.buffer.readPos
import chylex.hee.util.buffer.use import chylex.hee.util.buffer.writeEnum
import chylex.hee.util.buffer.writePos import chylex.hee.util.buffer.writePos
import chylex.hee.util.math.center import chylex.hee.util.math.center
import chylex.hee.util.math.directionTowards import chylex.hee.util.math.directionTowards
@ -74,19 +75,19 @@ object ItemRevitalizationSubstance : HeeItemBuilder() {
) )
class FxUseData(private val pos: BlockPos, private val player: PlayerEntity, private val hand: Hand) : IFxData { class FxUseData(private val pos: BlockPos, private val player: PlayerEntity, private val hand: Hand) : IFxData {
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writePos(pos) buffer.writePos(pos)
writeInt(player.entityId) buffer.writeInt(player.entityId)
writeByte(hand.ordinal) buffer.writeEnum(hand)
} }
} }
val FX_FAIL = object : IFxHandler<FxUseData> { val FX_FAIL = object : IFxHandler<FxUseData> {
override fun handle(buffer: PacketBuffer, world: World, rand: Random) = buffer.use { override fun handle(buffer: PacketBuffer, world: World, rand: Random) {
val blockPos = readPos().center val blockPos = buffer.readPos().center
val player = world.getEntityByID(readInt()) as? PlayerEntity ?: return val player = world.getEntityByID(buffer.readInt()) as? PlayerEntity ?: return
val hand = Hand.values().getOrNull(readByte().toInt()) ?: return val hand = buffer.readEnum<Hand>() ?: return
val handPos = ModelHelper.getHandPosition(player, hand) val handPos = ModelHelper.getHandPosition(player, hand)
val startPoint = handPos.add(handPos.directionTowards(blockPos).scale(0.2)) val startPoint = handPos.add(handPos.directionTowards(blockPos).scale(0.2))

View File

@ -25,8 +25,9 @@ import chylex.hee.init.ModSounds
import chylex.hee.network.client.PacketClientFX import chylex.hee.network.client.PacketClientFX
import chylex.hee.system.heeTag import chylex.hee.system.heeTag
import chylex.hee.system.heeTagOrNull import chylex.hee.system.heeTagOrNull
import chylex.hee.util.buffer.readEnum
import chylex.hee.util.buffer.readPos import chylex.hee.util.buffer.readPos
import chylex.hee.util.buffer.use import chylex.hee.util.buffer.writeEnum
import chylex.hee.util.buffer.writePos import chylex.hee.util.buffer.writePos
import chylex.hee.util.nbt.getPos import chylex.hee.util.nbt.getPos
import chylex.hee.util.nbt.hasKey import chylex.hee.util.nbt.hasKey
@ -145,17 +146,17 @@ object ItemTableLink : HeeItemBuilder() {
} }
class FxUseData(private val pos: BlockPos, private val type: SoundType) : IFxData { class FxUseData(private val pos: BlockPos, private val type: SoundType) : IFxData {
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writePos(pos) buffer.writePos(pos)
writeByte(type.ordinal) buffer.writeEnum(type)
} }
} }
val FX_USE = object : IFxHandler<FxUseData> { val FX_USE = object : IFxHandler<FxUseData> {
override fun handle(buffer: PacketBuffer, world: World, rand: Random) = buffer.use { override fun handle(buffer: PacketBuffer, world: World, rand: Random) {
val pos = readPos() val pos = buffer.readPos()
when (SoundType.values().getOrNull(readByte().toInt())) { when (buffer.readEnum<SoundType>()) {
LINK_SUCCESS -> ModSounds.ITEM_TABLE_LINK_USE_SUCCESS.playClient(pos, SoundCategory.PLAYERS, pitch = rand.nextFloat(0.49F, 0.51F)) LINK_SUCCESS -> ModSounds.ITEM_TABLE_LINK_USE_SUCCESS.playClient(pos, SoundCategory.PLAYERS, pitch = rand.nextFloat(0.49F, 0.51F))
LINK_RESTART -> ModSounds.ITEM_TABLE_LINK_USE_SPECIAL.playClient(pos, SoundCategory.PLAYERS, pitch = rand.nextFloat(0.69F, 0.71F)) LINK_RESTART -> ModSounds.ITEM_TABLE_LINK_USE_SPECIAL.playClient(pos, SoundCategory.PLAYERS, pitch = rand.nextFloat(0.69F, 0.71F))
LINK_OUTPUT -> ModSounds.ITEM_TABLE_LINK_USE_SPECIAL.playClient(pos, SoundCategory.PLAYERS, volume = 0.9F, pitch = 0.63F) LINK_OUTPUT -> ModSounds.ITEM_TABLE_LINK_USE_SPECIAL.playClient(pos, SoundCategory.PLAYERS, volume = 0.9F, pitch = 0.63F)

View File

@ -3,8 +3,7 @@ package chylex.hee.game.mechanics.instability.dimension
import chylex.hee.game.mechanics.instability.dimension.components.EndermiteSpawnLogic import chylex.hee.game.mechanics.instability.dimension.components.EndermiteSpawnLogic
import chylex.hee.util.math.ceilToInt import chylex.hee.util.math.ceilToInt
import chylex.hee.util.math.floorToInt import chylex.hee.util.math.floorToInt
import chylex.hee.util.math.range import chylex.hee.util.math.remap
import chylex.hee.util.math.remapRange
import chylex.hee.util.nbt.TagCompound import chylex.hee.util.nbt.TagCompound
import chylex.hee.util.nbt.use import chylex.hee.util.nbt.use
import net.minecraft.util.math.BlockPos import net.minecraft.util.math.BlockPos
@ -27,7 +26,7 @@ open class DimensionInstabilityGlobal(private val world: World, private val ende
private fun calculateActionMultiplier(ticksSinceEndermiteSpawn: Long): Float { private fun calculateActionMultiplier(ticksSinceEndermiteSpawn: Long): Float {
return if (ticksSinceEndermiteSpawn < 300L) return if (ticksSinceEndermiteSpawn < 300L)
remapRange(ticksSinceEndermiteSpawn.toFloat(), range(0F, 300F), range(0.2F, 1F)) ticksSinceEndermiteSpawn.toFloat().remap(fromMin = 0F, fromMax = 300F, toMin = 0.2F, toMax = 1F)
else else
1F 1F
} }

View File

@ -5,7 +5,8 @@ import chylex.hee.game.mechanics.instability.region.IRegionEntryConstructor
import chylex.hee.util.math.shlong import chylex.hee.util.math.shlong
import net.minecraft.util.math.BlockPos import net.minecraft.util.math.BlockPos
inline class Entry5x5(override val compacted: Long) : IRegionEntry { @JvmInline
value class Entry5x5(override val compacted: Long) : IRegionEntry {
private companion object { private companion object {
private const val MASK_X = 0x00000_FFFFFL private const val MASK_X = 0x00000_FFFFFL
private const val MASK_Z = 0xFFFFF_00000L private const val MASK_Z = 0xFFFFF_00000L

View File

@ -17,7 +17,6 @@ import chylex.hee.game.world.util.getTile
import chylex.hee.init.ModBlocks import chylex.hee.init.ModBlocks
import chylex.hee.network.client.PacketClientFX import chylex.hee.network.client.PacketClientFX
import chylex.hee.util.buffer.readPos import chylex.hee.util.buffer.readPos
import chylex.hee.util.buffer.use
import chylex.hee.util.buffer.writePos import chylex.hee.util.buffer.writePos
import chylex.hee.util.math.center import chylex.hee.util.math.center
import chylex.hee.util.math.directionTowards import chylex.hee.util.math.directionTowards
@ -45,24 +44,24 @@ class TableParticleHandler(private val table: TileEntityBaseTable) {
private val PARTICLE_CLUSTER_MOT = InBox(0.004F) private val PARTICLE_CLUSTER_MOT = InBox(0.004F)
class FxProcessPedestalsData(private val table: TileEntityBaseTable, private val targetPositions: List<BlockPos>, private val travelTime: Int) : IFxData { class FxProcessPedestalsData(private val table: TileEntityBaseTable, private val targetPositions: List<BlockPos>, private val travelTime: Int) : IFxData {
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writePos(table.pos) buffer.writePos(table.pos)
writeByte(travelTime) buffer.writeByte(travelTime)
writeByte(targetPositions.size) buffer.writeByte(targetPositions.size)
for (pos in targetPositions) { for (pos in targetPositions) {
writeLong(pos.toLong()) buffer.writeLong(pos.toLong())
} }
} }
} }
val FX_PROCESS_PEDESTALS = object : IFxHandler<FxProcessPedestalsData> { val FX_PROCESS_PEDESTALS = object : IFxHandler<FxProcessPedestalsData> {
override fun handle(buffer: PacketBuffer, world: World, rand: Random) = buffer.use { override fun handle(buffer: PacketBuffer, world: World, rand: Random) {
val table = readPos().getTile<TileEntityBaseTable>(world) ?: return val table = buffer.readPos().getTile<TileEntityBaseTable>(world) ?: return
val travelTime = readByte().toInt() val travelTime = buffer.readByte().toInt()
repeat(readByte().toInt()) { repeat(buffer.readByte().toInt()) {
val targetPos = readPos() val targetPos = buffer.readPos()
if (targetPos.getBlock(world) === ModBlocks.TABLE_PEDESTAL) { if (targetPos.getBlock(world) === ModBlocks.TABLE_PEDESTAL) {
ParticleSpawnerCustom( ParticleSpawnerCustom(
@ -77,16 +76,16 @@ class TableParticleHandler(private val table: TileEntityBaseTable) {
} }
class FxDrainClusterData(private val table: TileEntityBaseTable, private val clusterPos: BlockPos) : IFxData { class FxDrainClusterData(private val table: TileEntityBaseTable, private val clusterPos: BlockPos) : IFxData {
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writePos(clusterPos) buffer.writePos(clusterPos)
writePos(table.pos) buffer.writePos(table.pos)
} }
} }
val FX_DRAIN_CLUSTER = object : IFxHandler<FxDrainClusterData> { val FX_DRAIN_CLUSTER = object : IFxHandler<FxDrainClusterData> {
override fun handle(buffer: PacketBuffer, world: World, rand: Random) = buffer.use { override fun handle(buffer: PacketBuffer, world: World, rand: Random) {
val cluster = readPos().getTile<TileEntityEnergyCluster>(world) ?: return val cluster = buffer.readPos().getTile<TileEntityEnergyCluster>(world) ?: return
val table = readPos().getTile<TileEntityBaseTable>(world) ?: return val table = buffer.readPos().getTile<TileEntityBaseTable>(world) ?: return
val clusterPos = cluster.pos.center val clusterPos = cluster.pos.center
val tablePos = table.pos.center val tablePos = table.pos.center

View File

@ -9,7 +9,7 @@ import net.minecraft.item.crafting.SpecialRecipeSerializer
abstract class RecipeBaseDynamic : ICraftingRecipe { abstract class RecipeBaseDynamic : ICraftingRecipe {
private val serializer = SpecialRecipeSerializer { this } private val serializer = SpecialRecipeSerializer { this }
final override fun getId() = serializer.registryName final override fun getId() = serializer.registryName!!
final override fun getSerializer() = serializer final override fun getSerializer() = serializer
final override fun isDynamic() = true final override fun isDynamic() = true

View File

@ -27,8 +27,7 @@ import chylex.hee.util.math.Pos
import chylex.hee.util.math.ceilToInt import chylex.hee.util.math.ceilToInt
import chylex.hee.util.math.directionTowards import chylex.hee.util.math.directionTowards
import chylex.hee.util.math.floorToInt import chylex.hee.util.math.floorToInt
import chylex.hee.util.math.range import chylex.hee.util.math.remap
import chylex.hee.util.math.remapRange
import chylex.hee.util.math.square import chylex.hee.util.math.square
import chylex.hee.util.random.nextFloat import chylex.hee.util.random.nextFloat
import net.minecraft.entity.Entity import net.minecraft.entity.Entity
@ -129,7 +128,6 @@ object TerritoryVoid {
private const val PLAYER_NEXT_DAMAGE_TIME_TAG = "VoidNextDamageTime" private const val PLAYER_NEXT_DAMAGE_TIME_TAG = "VoidNextDamageTime"
private val FACTOR_DAMAGE_REMAP_FROM = range(0.5F, 3F)
private val DAMAGE = Damage(DEAL_CREATIVE, IGNORE_INVINCIBILITY()) private val DAMAGE = Damage(DEAL_CREATIVE, IGNORE_INVINCIBILITY())
fun onWorldTick(world: ServerWorld) { fun onWorldTick(world: ServerWorld) {
@ -158,10 +156,10 @@ object TerritoryVoid {
val nextDamageTime = getLong(PLAYER_NEXT_DAMAGE_TIME_TAG) val nextDamageTime = getLong(PLAYER_NEXT_DAMAGE_TIME_TAG)
if (currentTime >= nextDamageTime) { if (currentTime >= nextDamageTime) {
val amount = remapRange(factor, FACTOR_DAMAGE_REMAP_FROM, range(2F, 6F)).ceilToInt().toFloat() val amount = factor.remap(fromMin = 0.5F, fromMax = 3F, toMin = 2F, toMax = 6F).ceilToInt().toFloat()
if (DAMAGE.dealTo(amount, entity, TITLE_WITHER)) { if (DAMAGE.dealTo(amount, entity, TITLE_WITHER)) {
val cooldown = min(30, remapRange(factor, FACTOR_DAMAGE_REMAP_FROM, range(30F, 6F)).floorToInt()) val cooldown = min(30, factor.remap(fromMin = 0.5F, fromMax = 3F, toMin = 30F, toMax = 6F).floorToInt())
putLong(PLAYER_NEXT_DAMAGE_TIME_TAG, currentTime + cooldown) putLong(PLAYER_NEXT_DAMAGE_TIME_TAG, currentTime + cooldown)
} }
} }

View File

@ -30,8 +30,7 @@ import chylex.hee.util.math.Size
import chylex.hee.util.math.component1 import chylex.hee.util.math.component1
import chylex.hee.util.math.component2 import chylex.hee.util.math.component2
import chylex.hee.util.math.component3 import chylex.hee.util.math.component3
import chylex.hee.util.math.range import chylex.hee.util.math.remap
import chylex.hee.util.math.remapRange
import chylex.hee.util.math.square import chylex.hee.util.math.square
import chylex.hee.util.math.xz import chylex.hee.util.math.xz
import chylex.hee.util.random.RandomInt.Companion.Biased import chylex.hee.util.random.RandomInt.Companion.Biased
@ -122,9 +121,9 @@ object Generator_ForgottenTombs : ITerritoryGenerator {
val noiseY = NoiseGenerator.OldPerlinNormalized(rand, scale = 48.0, octaves = 2) val noiseY = NoiseGenerator.OldPerlinNormalized(rand, scale = 48.0, octaves = 2)
for ((x, y, z) in BlockPos.ZERO.allInCenteredBoxMutable(RADIUS_XZ, RADIUS_Y, RADIUS_XZ)) { for ((x, y, z) in BlockPos.ZERO.allInCenteredBoxMutable(RADIUS_XZ, RADIUS_Y, RADIUS_XZ)) {
val normalizedY = remapRange(y.toFloat(), range(-radY, radY), range(0F, 1F)) val normalizedY = y.toFloat().remap(fromMin = -radY, fromMax = radY, toMin = 0F, toMax = 1F)
val powerY = remapRange(sqrt(normalizedY), range(0F, 1F), range(4.8F, 1.6F)) val powerY = sqrt(normalizedY).remap(fromMin = 0F, fromMax = 1F, toMin = 4.8F, toMax = 1.6F)
val powerXZ = powerY * 0.8F val powerXZ = powerY * 0.8F
val corner = 1 + ((abs(x) + abs(z)) / (3F * radXZ)).pow(2F) val corner = 1 + ((abs(x) + abs(z)) / (3F * radXZ)).pow(2F)

View File

@ -48,8 +48,7 @@ import chylex.hee.util.math.addY
import chylex.hee.util.math.ceilToInt import chylex.hee.util.math.ceilToInt
import chylex.hee.util.math.center import chylex.hee.util.math.center
import chylex.hee.util.math.floorToInt import chylex.hee.util.math.floorToInt
import chylex.hee.util.math.range import chylex.hee.util.math.remap
import chylex.hee.util.math.remapRange
import chylex.hee.util.math.scale import chylex.hee.util.math.scale
import chylex.hee.util.math.scaleY import chylex.hee.util.math.scaleY
import chylex.hee.util.math.square import chylex.hee.util.math.square
@ -208,7 +207,7 @@ object Generator_LostGarden : ITerritoryGenerator {
} }
val edgeMpXZ = if (distRatioXZ > 0.86) val edgeMpXZ = if (distRatioXZ > 0.86)
remapRange(distRatioXZ.coerceAtMost(1.0), range(0.86F, 1F), range(1F, 0.86F * noiseXZ.getRawValue(-x * 3, -z * 3).toFloat())) distRatioXZ.coerceAtMost(1.0).remap(fromMin = 0.86, fromMax = 1.0, toMin = 1.0, toMax = 0.86 * noiseXZ.getRawValue(-x * 3, -z * 3))
else else
1.0 1.0
@ -218,10 +217,10 @@ object Generator_LostGarden : ITerritoryGenerator {
} }
val valueValley = 1.0 - noiseValley.getValue(x, z) { val valueValley = 1.0 - noiseValley.getValue(x, z) {
remap(range(0.5F, 1F), range(0F, 1F)) remap(fromMin = 0.5, fromMax = 1.0, toMin = 0.0, toMax = 1.0)
coerce() coerce()
redistribute(0.5) redistribute(0.5)
remap(range(0F, 0.75F)) remap(0.0, 0.75)
if (valueXZ < 0.6) { if (valueXZ < 0.6) {
multiply(valueXZ / 0.6) multiply(valueXZ / 0.6)
@ -229,7 +228,7 @@ object Generator_LostGarden : ITerritoryGenerator {
} }
val valueThreshold = noiseThreshold.getValue(x, z) { val valueThreshold = noiseThreshold.getValue(x, z) {
remap(range(0.14F, 0.29F)) remap(0.14, 0.29)
} }
val valueTotalXZ = valueXZ * valueValley val valueTotalXZ = valueXZ * valueValley
@ -237,7 +236,7 @@ object Generator_LostGarden : ITerritoryGenerator {
val edgeMpY = (0.5 - (1.0 - edgeMpXZ)) val edgeMpY = (0.5 - (1.0 - edgeMpXZ))
val endersolY = -0.125 + (0.575 * noiseEndersol.getValue(x, z) { val endersolY = -0.125 + (0.575 * noiseEndersol.getValue(x, z) {
if (value > 0.6) { if (value > 0.6) {
remap(range(0.6F, 1F), range(0.6F, 5F)) remap(fromMin = 0.6, fromMax = 1.0, toMin = 0.6, toMax = 5.0)
} }
}) })
@ -277,20 +276,20 @@ object Generator_LostGarden : ITerritoryGenerator {
private fun NoiseValue.distanceReshapeXZ(distance: Double) { private fun NoiseValue.distanceReshapeXZ(distance: Double) {
value = when (distance) { value = when (distance) {
in (0.00)..(0.40) -> value * remapRange(distance, range(0F, 0.4F), range(0.8F, 1F)) in (0.00)..(0.40) -> value * distance.remap(fromMin = 0.0, fromMax = 0.4, toMin = 0.8, toMax = 1.0)
in (0.40)..(0.85) -> value in (0.40)..(0.85) -> value
in (0.85)..(1.00) -> value * remapRange(distance, range(0.85F, 1F), range(1F, 0F)) in (0.85)..(1.00) -> value * distance.remap(fromMin = 0.85, fromMax = 1.0, toMin = 1.0, toMax = 0.0)
else -> 0.0 else -> 0.0
} }
} }
private fun NoiseValue.distanceReshapeY(distance: Double) { private fun NoiseValue.distanceReshapeY(distance: Double) {
value = when (distance) { value = when (distance) {
in (-1.0)..(-0.6) -> value * square(remapRange(distance, range(-1F, -0.5F), range(0F, 1F))) in (-1.0)..(-0.6) -> value * square(distance.remap(fromMin = -1.0, fromMax = -0.5, toMin = 0.0, toMax = 1.0))
in (-0.6)..( 0.5) -> value in (-0.6)..( 0.5) -> value
in ( 0.5)..( 0.8) -> value * remapRange(distance, range(0.5F, 0.8F), range(1F, 0.5F)) in ( 0.5)..( 0.8) -> value * distance.remap(fromMin = 0.5, fromMax = 0.8, toMin = 1.0, toMax = 0.5)
in ( 0.8)..( 1.4) -> value * 0.5 in ( 0.8)..( 1.4) -> value * 0.5
in ( 1.4)..( 2.0) -> value * remapRange(distance, range(1.4F, 2F), range(0.5F, 0.1F)) in ( 1.4)..( 2.0) -> value * distance.remap(fromMin = 1.4, fromMax = 2.0, toMin = 0.5, toMax = 0.1)
else -> 0.0 else -> 0.0
} }
} }

View File

@ -46,8 +46,7 @@ import chylex.hee.util.math.Vec
import chylex.hee.util.math.ceilToInt import chylex.hee.util.math.ceilToInt
import chylex.hee.util.math.center import chylex.hee.util.math.center
import chylex.hee.util.math.directionTowards import chylex.hee.util.math.directionTowards
import chylex.hee.util.math.range import chylex.hee.util.math.remap
import chylex.hee.util.math.remapRange
import chylex.hee.util.math.square import chylex.hee.util.math.square
import chylex.hee.util.math.toRadians import chylex.hee.util.math.toRadians
import chylex.hee.util.random.RandomInt.Companion.Constant import chylex.hee.util.random.RandomInt.Companion.Constant
@ -338,7 +337,7 @@ object Generator_ObsidianTowers : ITerritoryGenerator {
private fun generate(world: SegmentedWorld, rand: Random, island: Island, builder: ObsidianTowerBuilder) { private fun generate(world: SegmentedWorld, rand: Random, island: Island, builder: ObsidianTowerBuilder) {
island.generateBase(world, rand) island.generateBase(world, rand)
island.generatePillars(world, rand, amount = (1 + island.radius).ceilToInt(), exclusionRadius = 8.0) island.generatePillars(world, rand, amount = (1 + island.radius).ceilToInt(), exclusionRadius = 8.0)
builder.build(rand)?.generate(OffsetStructureWorld(world, island.center.subtract(ObsidianTowerPieces.STRUCTURE_SIZE.getPos(CENTER, MIN, CENTER)))) builder.build(rand).generate(OffsetStructureWorld(world, island.center.subtract(ObsidianTowerPieces.STRUCTURE_SIZE.getPos(CENTER, MIN, CENTER))))
} }
} }
@ -415,7 +414,7 @@ object Generator_ObsidianTowers : ITerritoryGenerator {
ENDIUM_ORES { ENDIUM_ORES {
override fun beforePillars(world: SegmentedWorld, rand: Random, island: Island) { override fun beforePillars(world: SegmentedWorld, rand: Random, island: Island) {
val piles = if (island.radius >= 5.0) val piles = if (island.radius >= 5.0)
rand.nextRounded(remapRange(island.radius, range(5F, 7F), range(2F, 4F)).toFloat()) rand.nextRounded(island.radius.toFloat().remap(fromMin = 5F, fromMax = 7F, toMin = 2F, toMax = 4F))
else else
1 1

View File

@ -43,8 +43,7 @@ import chylex.hee.util.math.addY
import chylex.hee.util.math.ceilToInt import chylex.hee.util.math.ceilToInt
import chylex.hee.util.math.center import chylex.hee.util.math.center
import chylex.hee.util.math.floorToInt import chylex.hee.util.math.floorToInt
import chylex.hee.util.math.range import chylex.hee.util.math.remap
import chylex.hee.util.math.remapRange
import chylex.hee.util.math.scale import chylex.hee.util.math.scale
import chylex.hee.util.math.scaleY import chylex.hee.util.math.scaleY
import chylex.hee.util.math.square import chylex.hee.util.math.square
@ -129,7 +128,7 @@ object Generator_TheHub : ITerritoryGenerator {
redistribute(0.4) redistribute(0.4)
ifNonZero { ifNonZero {
remap(range(0.2F, 1F)) remap(0.2, 1.0)
multiply(ELEVATION_BOTTOM) multiply(ELEVATION_BOTTOM)
} }
} }
@ -155,7 +154,7 @@ object Generator_TheHub : ITerritoryGenerator {
private fun NoiseValue.distanceReshape(distance: Double) { private fun NoiseValue.distanceReshape(distance: Double) {
value = when (distance) { value = when (distance) {
in (0.00)..(0.85) -> value in (0.00)..(0.85) -> value
in (0.85)..(1.00) -> value * remapRange(distance, range(0.85F, 1F), range(1F, 0F)) in (0.85)..(1.00) -> value * distance.remap(fromMin = 0.85, fromMax = 1.0, toMin = 1.0, toMax = 0.0)
else -> 0.0 else -> 0.0
} }
} }

View File

@ -2,7 +2,6 @@ package chylex.hee.network.client
import chylex.hee.network.BaseClientPacket import chylex.hee.network.BaseClientPacket
import chylex.hee.util.buffer.readFloatVec import chylex.hee.util.buffer.readFloatVec
import chylex.hee.util.buffer.use
import chylex.hee.util.buffer.writeFloatVec import chylex.hee.util.buffer.writeFloatVec
import chylex.hee.util.forge.Side import chylex.hee.util.forge.Side
import chylex.hee.util.forge.Sided import chylex.hee.util.forge.Sided
@ -20,14 +19,14 @@ class PacketClientLaunchInstantly() : BaseClientPacket() {
private var entityId: Int? = null private var entityId: Int? = null
private lateinit var motion: Vector3d private lateinit var motion: Vector3d
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writeInt(entityId!!) buffer.writeInt(entityId!!)
writeFloatVec(motion) buffer.writeFloatVec(motion)
} }
override fun read(buffer: PacketBuffer) = buffer.use { override fun read(buffer: PacketBuffer) {
entityId = readInt() entityId = buffer.readInt()
motion = readFloatVec() motion = buffer.readFloatVec()
} }
@Sided(Side.CLIENT) @Sided(Side.CLIENT)

View File

@ -2,7 +2,6 @@ package chylex.hee.network.client
import chylex.hee.network.BaseClientPacket import chylex.hee.network.BaseClientPacket
import chylex.hee.util.buffer.readVec import chylex.hee.util.buffer.readVec
import chylex.hee.util.buffer.use
import chylex.hee.util.buffer.writeVec import chylex.hee.util.buffer.writeVec
import chylex.hee.util.forge.Side import chylex.hee.util.forge.Side
import chylex.hee.util.forge.Sided import chylex.hee.util.forge.Sided
@ -17,12 +16,12 @@ class PacketClientMoveYourAss() : BaseClientPacket() {
private lateinit var position: Vector3d private lateinit var position: Vector3d
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writeVec(position) buffer.writeVec(position)
} }
override fun read(buffer: PacketBuffer) = buffer.use { override fun read(buffer: PacketBuffer) {
position = readVec() position = buffer.readVec()
} }
@Sided(Side.CLIENT) @Sided(Side.CLIENT)

View File

@ -1,7 +1,6 @@
package chylex.hee.network.client package chylex.hee.network.client
import chylex.hee.network.BaseClientPacket import chylex.hee.network.BaseClientPacket
import chylex.hee.util.buffer.use
import chylex.hee.util.forge.Side import chylex.hee.util.forge.Side
import chylex.hee.util.forge.Sided import chylex.hee.util.forge.Sided
import net.minecraft.client.entity.player.ClientPlayerEntity import net.minecraft.client.entity.player.ClientPlayerEntity
@ -17,14 +16,14 @@ class PacketClientPotionDuration() : BaseClientPacket() {
private var effect: Effect? = null private var effect: Effect? = null
private var newDuration: Int? = null private var newDuration: Int? = null
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writeRegistryId(effect!!) buffer.writeRegistryId(effect!!)
writeInt(newDuration!!) buffer.writeInt(newDuration!!)
} }
override fun read(buffer: PacketBuffer) = buffer.use { override fun read(buffer: PacketBuffer) {
effect = readRegistryIdSafe(Effect::class.java) effect = buffer.readRegistryIdSafe(Effect::class.java)
newDuration = readInt() newDuration = buffer.readInt()
} }
@Sided(Side.CLIENT) @Sided(Side.CLIENT)

View File

@ -1,7 +1,6 @@
package chylex.hee.network.client package chylex.hee.network.client
import chylex.hee.network.BaseClientPacket import chylex.hee.network.BaseClientPacket
import chylex.hee.util.buffer.use
import chylex.hee.util.forge.Side import chylex.hee.util.forge.Side
import chylex.hee.util.forge.Sided import chylex.hee.util.forge.Sided
import net.minecraft.client.entity.player.ClientPlayerEntity import net.minecraft.client.entity.player.ClientPlayerEntity
@ -20,16 +19,16 @@ class PacketClientRotateInstantly() : BaseClientPacket() {
private var yaw: Float? = null private var yaw: Float? = null
private var pitch: Float? = null private var pitch: Float? = null
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writeInt(entityId!!) buffer.writeInt(entityId!!)
writeFloat(yaw!!) buffer.writeFloat(yaw!!)
writeFloat(pitch!!) buffer.writeFloat(pitch!!)
} }
override fun read(buffer: PacketBuffer) = buffer.use { override fun read(buffer: PacketBuffer) {
entityId = readInt() entityId = buffer.readInt()
yaw = readFloat() yaw = buffer.readFloat()
pitch = readFloat() pitch = buffer.readFloat()
} }
@Sided(Side.CLIENT) @Sided(Side.CLIENT)

View File

@ -2,7 +2,6 @@ package chylex.hee.network.client
import chylex.hee.network.BaseClientPacket import chylex.hee.network.BaseClientPacket
import chylex.hee.util.buffer.readVec import chylex.hee.util.buffer.readVec
import chylex.hee.util.buffer.use
import chylex.hee.util.buffer.writeVec import chylex.hee.util.buffer.writeVec
import chylex.hee.util.forge.Side import chylex.hee.util.forge.Side
import chylex.hee.util.forge.Sided import chylex.hee.util.forge.Sided
@ -20,14 +19,14 @@ class PacketClientTeleportInstantly() : BaseClientPacket() {
private var entityId: Int? = null private var entityId: Int? = null
private lateinit var position: Vector3d private lateinit var position: Vector3d
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writeInt(entityId!!) buffer.writeInt(entityId!!)
writeVec(position) buffer.writeVec(position)
} }
override fun read(buffer: PacketBuffer) = buffer.use { override fun read(buffer: PacketBuffer) {
entityId = readInt() entityId = buffer.readInt()
position = readVec() position = buffer.readVec()
} }
@Sided(Side.CLIENT) @Sided(Side.CLIENT)

View File

@ -5,7 +5,6 @@ import chylex.hee.game.territory.storage.VoidData
import chylex.hee.game.territory.system.storage.TerritoryEntry import chylex.hee.game.territory.system.storage.TerritoryEntry
import chylex.hee.network.BaseClientPacket import chylex.hee.network.BaseClientPacket
import chylex.hee.util.buffer.readTag import chylex.hee.util.buffer.readTag
import chylex.hee.util.buffer.use
import chylex.hee.util.buffer.writeTag import chylex.hee.util.buffer.writeTag
import chylex.hee.util.forge.Side import chylex.hee.util.forge.Side
import chylex.hee.util.forge.Sided import chylex.hee.util.forge.Sided
@ -20,12 +19,12 @@ class PacketClientTerritoryEnvironment() : BaseClientPacket() {
private var void: TagCompound? = null private var void: TagCompound? = null
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writeOptionalTag(void) buffer.writeOptionalTag(void)
} }
override fun read(buffer: PacketBuffer) = buffer.use { override fun read(buffer: PacketBuffer) {
void = readOptionalTag() void = buffer.readOptionalTag()
} }
@Sided(Side.CLIENT) @Sided(Side.CLIENT)

View File

@ -4,7 +4,6 @@ import chylex.hee.client.util.MC
import chylex.hee.game.item.interfaces.getHeeInterface import chylex.hee.game.item.interfaces.getHeeInterface
import chylex.hee.game.mechanics.trinket.ITrinketItem import chylex.hee.game.mechanics.trinket.ITrinketItem
import chylex.hee.network.BaseClientPacket import chylex.hee.network.BaseClientPacket
import chylex.hee.util.buffer.use
import chylex.hee.util.forge.Side import chylex.hee.util.forge.Side
import chylex.hee.util.forge.Sided import chylex.hee.util.forge.Sided
import net.minecraft.client.entity.player.ClientPlayerEntity import net.minecraft.client.entity.player.ClientPlayerEntity
@ -22,14 +21,14 @@ class PacketClientTrinketBreak() : BaseClientPacket() {
private var entityId: Int? = null private var entityId: Int? = null
private lateinit var item: Item private lateinit var item: Item
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writeInt(entityId!!) buffer.writeInt(entityId!!)
writeInt(Item.getIdFromItem(item)) buffer.writeInt(Item.getIdFromItem(item))
} }
override fun read(buffer: PacketBuffer) = buffer.use { override fun read(buffer: PacketBuffer) {
entityId = readInt() entityId = buffer.readInt()
item = Item.getItemById(readInt()) item = Item.getItemById(buffer.readInt())
} }
@Sided(Side.CLIENT) @Sided(Side.CLIENT)

View File

@ -1,7 +1,6 @@
package chylex.hee.network.client package chylex.hee.network.client
import chylex.hee.network.BaseClientPacket import chylex.hee.network.BaseClientPacket
import chylex.hee.util.buffer.use
import chylex.hee.util.forge.Side import chylex.hee.util.forge.Side
import chylex.hee.util.forge.Sided import chylex.hee.util.forge.Sided
import net.minecraft.client.entity.player.ClientPlayerEntity import net.minecraft.client.entity.player.ClientPlayerEntity
@ -14,12 +13,12 @@ class PacketClientUpdateExperience() : BaseClientPacket() {
private var experience: Float? = null private var experience: Float? = null
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writeFloat(experience!!) buffer.writeFloat(experience!!)
} }
override fun read(buffer: PacketBuffer) = buffer.use { override fun read(buffer: PacketBuffer) {
experience = readFloat() experience = buffer.readFloat()
} }
@Sided(Side.CLIENT) @Sided(Side.CLIENT)

View File

@ -2,7 +2,6 @@ package chylex.hee.network.server
import chylex.hee.HEE import chylex.hee.HEE
import chylex.hee.network.BaseServerPacket import chylex.hee.network.BaseServerPacket
import chylex.hee.util.buffer.use
import net.minecraft.entity.player.ServerPlayerEntity import net.minecraft.entity.player.ServerPlayerEntity
import net.minecraft.network.PacketBuffer import net.minecraft.network.PacketBuffer
@ -19,12 +18,12 @@ class PacketServerContainerEvent() : BaseServerPacket() {
private var eventId: Byte? = null private var eventId: Byte? = null
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writeByte(eventId!!.toInt()) buffer.writeByte(eventId!!.toInt())
} }
override fun read(buffer: PacketBuffer) = buffer.use { override fun read(buffer: PacketBuffer) {
eventId = readByte() eventId = buffer.readByte()
} }
override fun handle(player: ServerPlayerEntity) { override fun handle(player: ServerPlayerEntity) {

View File

@ -7,7 +7,6 @@ import chylex.hee.game.item.interfaces.getHeeInterface
import chylex.hee.game.mechanics.trinket.TrinketHandler import chylex.hee.game.mechanics.trinket.TrinketHandler
import chylex.hee.init.ModContainers import chylex.hee.init.ModContainers
import chylex.hee.network.BaseServerPacket import chylex.hee.network.BaseServerPacket
import chylex.hee.util.buffer.use
import net.minecraft.entity.player.ServerPlayerEntity import net.minecraft.entity.player.ServerPlayerEntity
import net.minecraft.network.PacketBuffer import net.minecraft.network.PacketBuffer
@ -18,12 +17,12 @@ class PacketServerOpenInventoryItem() : BaseServerPacket() {
private var slot: Int? = null private var slot: Int? = null
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writeVarInt(slot!!) buffer.writeVarInt(slot!!)
} }
override fun read(buffer: PacketBuffer) = buffer.use { override fun read(buffer: PacketBuffer) {
slot = readVarInt() slot = buffer.readVarInt()
} }
override fun handle(player: ServerPlayerEntity) { override fun handle(player: ServerPlayerEntity) {

View File

@ -2,7 +2,6 @@ package chylex.hee.network.server
import chylex.hee.game.container.slot.SlotTrinketItemInventory import chylex.hee.game.container.slot.SlotTrinketItemInventory
import chylex.hee.network.BaseServerPacket import chylex.hee.network.BaseServerPacket
import chylex.hee.util.buffer.use
import net.minecraft.entity.player.ServerPlayerEntity import net.minecraft.entity.player.ServerPlayerEntity
import net.minecraft.item.ItemStack import net.minecraft.item.ItemStack
import net.minecraft.network.PacketBuffer import net.minecraft.network.PacketBuffer
@ -14,12 +13,12 @@ class PacketServerShiftClickTrinket() : BaseServerPacket() {
private var sourceSlot: Int? = null private var sourceSlot: Int? = null
override fun write(buffer: PacketBuffer) = buffer.use { override fun write(buffer: PacketBuffer) {
writeInt(sourceSlot!!) buffer.writeInt(sourceSlot!!)
} }
override fun read(buffer: PacketBuffer) = buffer.use { override fun read(buffer: PacketBuffer) {
sourceSlot = readInt() sourceSlot = buffer.readInt()
} }
override fun handle(player: ServerPlayerEntity) { override fun handle(player: ServerPlayerEntity) {