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

Compare commits

..

No commits in common. "2cb463f0aa1ac1d81554c9faeb409d235a3e78cf" and "5564fc4a24d7cdc8b91cd3e2712a7c4cc1f0da9f" have entirely different histories.

52 changed files with 319 additions and 287 deletions

View File

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

View File

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

View File

@ -18,65 +18,54 @@ import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.vector.Vector3d
import org.apache.logging.log4j.Logger
inline fun <T : PacketBuffer> T.use(block: T.() -> Unit) {
block()
}
// BlockPos
inline fun ByteBuf.writePos(pos: BlockPos) {
inline fun PacketBuffer.writePos(pos: BlockPos) {
this.writeLong(pos.toLong())
}
inline fun ByteBuf.readPos(): BlockPos {
inline fun PacketBuffer.readPos(): BlockPos {
return Pos(this.readLong())
}
// Vec3d (Full)
fun ByteBuf.writeVec(vec: Vector3d) {
fun PacketBuffer.writeVec(vec: Vector3d) {
this.writeDouble(vec.x)
this.writeDouble(vec.y)
this.writeDouble(vec.z)
}
fun ByteBuf.readVec(): Vector3d {
return Vec(this.readDouble(), this.readDouble(), this.readDouble())
fun PacketBuffer.readVec(): Vector3d {
return Vec(readDouble(), readDouble(), readDouble())
}
// Vec3d (Float)
fun ByteBuf.writeFloatVec(vec: Vector3d) {
fun PacketBuffer.writeFloatVec(vec: Vector3d) {
this.writeFloat(vec.x.toFloat())
this.writeFloat(vec.y.toFloat())
this.writeFloat(vec.z.toFloat())
}
fun ByteBuf.readFloatVec(): Vector3d {
return Vec(this.readFloat().toDouble(), this.readFloat().toDouble(), this.readFloat().toDouble())
fun PacketBuffer.readFloatVec(): Vector3d {
return Vec(readFloat().toDouble(), readFloat().toDouble(), readFloat().toDouble())
}
// Vec3d (Compact)
fun ByteBuf.writeCompactVec(vec: Vector3d) {
fun PacketBuffer.writeCompactVec(vec: Vector3d) {
this.writeInt((vec.x * 8.0).floorToInt())
this.writeInt((vec.y * 8.0).floorToInt())
this.writeInt((vec.z * 8.0).floorToInt())
}
fun ByteBuf.readCompactVec(): Vector3d {
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
fun PacketBuffer.readCompactVec(): Vector3d {
return Vec(readInt() * 0.125, readInt() * 0.125, readInt() * 0.125)
}
// NBT

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,6 +5,7 @@ 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.IShape.Point
import chylex.hee.init.ModEntities
import chylex.hee.util.buffer.use
import chylex.hee.util.math.square
import net.minecraft.entity.EntityType
import net.minecraft.item.ItemStack
@ -32,12 +33,12 @@ class EntityItemFreshlyCooked : EntityItemBase, IEntityAdditionalSpawnData {
)
}
override fun writeSpawnData(buffer: PacketBuffer) {
buffer.writeShort(age)
override fun writeSpawnData(buffer: PacketBuffer) = buffer.use {
writeShort(age)
}
override fun readSpawnData(buffer: PacketBuffer) {
age = buffer.readShort().toInt()
override fun readSpawnData(buffer: PacketBuffer) = buffer.use {
age = readShort().toInt()
}
override fun tick() {

View File

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

View File

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

View File

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

View File

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

View File

@ -47,7 +47,6 @@ class AITargetAttackerFixed(entity: MobEntity, private val callReinforcements: B
private fun alertOthers() {
val maxDistance = targetDistance
val goalOwner = goalOwner
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))

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,7 +9,7 @@ import net.minecraft.item.crafting.SpecialRecipeSerializer
abstract class RecipeBaseDynamic : ICraftingRecipe {
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 isDynamic() = true

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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