move/extract some constants

This commit is contained in:
Bixilon 2023-01-04 20:19:43 +01:00
parent 4026ee53f5
commit 050eeda712
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
22 changed files with 69 additions and 88 deletions

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger * Copyright (C) 2020-2023 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -16,6 +16,7 @@ package de.bixilon.minosoft.assets.util
import com.github.luben.zstd.ZstdInputStream import com.github.luben.zstd.ZstdInputStream
import com.github.luben.zstd.ZstdOutputStream import com.github.luben.zstd.ZstdOutputStream
import de.bixilon.kutil.array.ByteArrayUtil.toHex import de.bixilon.kutil.array.ByteArrayUtil.toHex
import de.bixilon.kutil.buffer.BufferDefinition
import de.bixilon.kutil.enums.EnumUtil import de.bixilon.kutil.enums.EnumUtil
import de.bixilon.kutil.enums.ValuesEnum import de.bixilon.kutil.enums.ValuesEnum
import de.bixilon.kutil.hex.HexUtil.isHexString import de.bixilon.kutil.hex.HexUtil.isHexString
@ -23,7 +24,6 @@ import de.bixilon.kutil.random.RandomStringUtil.randomString
import de.bixilon.minosoft.assets.AssetsManager import de.bixilon.minosoft.assets.AssetsManager
import de.bixilon.minosoft.assets.util.FileAssetsUtil.HashTypes.Companion.hashType import de.bixilon.minosoft.assets.util.FileAssetsUtil.HashTypes.Companion.hashType
import de.bixilon.minosoft.data.registries.ResourceLocation import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.terminal.RunConfiguration import de.bixilon.minosoft.terminal.RunConfiguration
import de.bixilon.minosoft.util.KUtil import de.bixilon.minosoft.util.KUtil
import java.io.* import java.io.*
@ -75,7 +75,7 @@ object FileAssetsUtil {
output = ZstdOutputStream(output, 5) output = ZstdOutputStream(output, 5)
} }
val buffer = ByteArray(ProtocolDefinition.DEFAULT_BUFFER_SIZE) val buffer = ByteArray(BufferDefinition.DEFAULT_BUFFER_SIZE)
var length: Int var length: Int
while (true) { while (true) {
length = stream.read(buffer, 0, buffer.size) length = stream.read(buffer, 0, buffer.size)
@ -149,7 +149,7 @@ object FileAssetsUtil {
val input = openStream(file, compress) val input = openStream(file, compress)
val buffer = ByteArray(ProtocolDefinition.DEFAULT_BUFFER_SIZE) val buffer = ByteArray(BufferDefinition.DEFAULT_BUFFER_SIZE)
var length: Int var length: Int
while (true) { while (true) {
length = input.read(buffer, 0, buffer.size) length = input.read(buffer, 0, buffer.size)
@ -200,7 +200,7 @@ object FileAssetsUtil {
val input = openStream(file, compress) val input = openStream(file, compress)
val output = ByteArrayOutputStream(if (compress) input.available() else maxOf(1000, input.available())) val output = ByteArrayOutputStream(if (compress) input.available() else maxOf(1000, input.available()))
val buffer = ByteArray(ProtocolDefinition.DEFAULT_BUFFER_SIZE) val buffer = ByteArray(BufferDefinition.DEFAULT_BUFFER_SIZE)
var length: Int var length: Int
while (true) { while (true) {
length = input.read(buffer, 0, buffer.size) length = input.read(buffer, 0, buffer.size)

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2021 Moritz Zwerger * Copyright (C) 2020-2023 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -15,9 +15,9 @@ package de.bixilon.minosoft.assets.util
import com.fasterxml.jackson.module.kotlin.readValue import com.fasterxml.jackson.module.kotlin.readValue
import com.github.luben.zstd.ZstdInputStream import com.github.luben.zstd.ZstdInputStream
import de.bixilon.kutil.buffer.BufferDefinition
import de.bixilon.kutil.cast.CastUtil.unsafeCast import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.mbf.MBFBinaryReader import de.bixilon.mbf.MBFBinaryReader
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.json.Jackson import de.bixilon.minosoft.util.json.Jackson
import de.matthiasmann.twl.utils.PNGDecoder import de.matthiasmann.twl.utils.PNGDecoder
import org.kamranzafar.jtar.TarInputStream import org.kamranzafar.jtar.TarInputStream
@ -56,7 +56,7 @@ object FileUtil {
fun InputStream.readAsString(close: Boolean = true): String { fun InputStream.readAsString(close: Boolean = true): String {
val builder = StringBuilder() val builder = StringBuilder()
val buffer = ByteArray(ProtocolDefinition.DEFAULT_BUFFER_SIZE) val buffer = ByteArray(BufferDefinition.DEFAULT_BUFFER_SIZE)
var length: Int var length: Int
while (true) { while (true) {

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger * Copyright (C) 2020-2023 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -21,7 +21,7 @@ import de.bixilon.minosoft.config.profile.delegate.types.StringDelegate
import de.bixilon.minosoft.config.profile.profiles.Profile import de.bixilon.minosoft.config.profile.profiles.Profile
import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfileManager.latestVersion import de.bixilon.minosoft.config.profile.profiles.particle.ParticleProfileManager.latestVersion
import de.bixilon.minosoft.config.profile.profiles.particle.types.TypesC import de.bixilon.minosoft.config.profile.profiles.particle.types.TypesC
import de.bixilon.minosoft.gui.rendering.RenderConstants import de.bixilon.minosoft.gui.rendering.particle.ParticleRenderer
/** /**
* Profile for particle * Profile for particle
@ -61,9 +61,9 @@ class ParticleProfile(
* Limits the number of particles. * Limits the number of particles.
* Particles that exceed that count will be ignored * Particles that exceed that count will be ignored
* Must not be negative or exceed $RenderConstants.MAXIMUM_PARTICLE_AMOUNT * Must not be negative or exceed $RenderConstants.MAXIMUM_PARTICLE_AMOUNT
* @see RenderConstants.MAXIMUM_PARTICLE_AMOUNT * @see ParticleRenderer.MAXIMUM_AMOUNT
*/ */
var maxAmount by IntDelegate(this, RenderConstants.MAXIMUM_PARTICLE_AMOUNT, "", arrayOf(0..RenderConstants.MAXIMUM_PARTICLE_AMOUNT)) var maxAmount by IntDelegate(this, ParticleRenderer.MAXIMUM_AMOUNT, "", arrayOf(0..ParticleRenderer.MAXIMUM_AMOUNT))
val types = TypesC(this) val types = TypesC(this)
override fun toString(): String { override fun toString(): String {

View File

@ -27,13 +27,13 @@ import de.bixilon.minosoft.data.container.slots.DefaultSlotType
import de.bixilon.minosoft.data.container.slots.SlotType import de.bixilon.minosoft.data.container.slots.SlotType
import de.bixilon.minosoft.data.container.stack.ItemStack import de.bixilon.minosoft.data.container.stack.ItemStack
import de.bixilon.minosoft.data.container.stack.property.HolderProperty import de.bixilon.minosoft.data.container.stack.property.HolderProperty
import de.bixilon.minosoft.data.container.types.PlayerInventory
import de.bixilon.minosoft.data.registries.ResourceLocation import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.containers.ContainerFactory import de.bixilon.minosoft.data.registries.containers.ContainerFactory
import de.bixilon.minosoft.data.registries.containers.ContainerType import de.bixilon.minosoft.data.registries.containers.ContainerType
import de.bixilon.minosoft.data.text.ChatComponent import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.packets.c2s.play.container.CloseContainerC2SP import de.bixilon.minosoft.protocol.packets.c2s.play.container.CloseContainerC2SP
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.KUtil.toResourceLocation import de.bixilon.minosoft.util.KUtil.toResourceLocation
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
@ -219,7 +219,7 @@ open class Container(
floatingItem = null // ToDo: Does not seem correct floatingItem = null // ToDo: Does not seem correct
val id = id ?: return val id = id ?: return
if (id != ProtocolDefinition.PLAYER_CONTAINER_ID) { if (id != PlayerInventory.CONTAINER_ID) {
connection.player.containers -= id connection.player.containers -= id
} }
// minecraft behavior, when opening the inventory an open packet is never sent, but a close is // minecraft behavior, when opening the inventory an open packet is never sent, but a close is

View File

@ -149,6 +149,7 @@ class PlayerInventory(connection: PlayConnection) : Container(connection = conne
} }
companion object : ContainerFactory<PlayerInventory> { companion object : ContainerFactory<PlayerInventory> {
const val CONTAINER_ID = 0
override val identifier: ResourceLocation = "minecraft:player_inventory".toResourceLocation() override val identifier: ResourceLocation = "minecraft:player_inventory".toResourceLocation()
val TYPE = ContainerType( val TYPE = ContainerType(
identifier = identifier, identifier = identifier,

View File

@ -25,14 +25,13 @@ import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.blocks.BlockState import de.bixilon.minosoft.data.registries.blocks.BlockState
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
import de.bixilon.minosoft.data.registries.blocks.types.entity.CampfireBlock import de.bixilon.minosoft.data.registries.blocks.types.entity.CampfireBlock
import de.bixilon.minosoft.gui.rendering.RenderConstants
import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.fire.SmokeParticle import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.fire.SmokeParticle
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.util.nbt.tag.NBTUtil.listCast import de.bixilon.minosoft.util.nbt.tag.NBTUtil.listCast
import java.util.* import java.util.*
class CampfireBlockEntity(connection: PlayConnection) : BlockEntity(connection) { class CampfireBlockEntity(connection: PlayConnection) : BlockEntity(connection) {
val items: Array<ItemStack?> = arrayOfNulls(RenderConstants.CAMPFIRE_ITEMS) val items: Array<ItemStack?> = arrayOfNulls(CampfireBlock.MAX_ITEMS)
override fun updateNBT(nbt: Map<String, Any>) { override fun updateNBT(nbt: Map<String, Any>) {

View File

@ -95,7 +95,7 @@ class LocalPlayerEntity(
val inventory = PlayerInventory(connection) val inventory = PlayerInventory(connection)
val incompleteContainers: SynchronizedMap<Int, IncompleteContainer> = synchronizedMapOf() val incompleteContainers: SynchronizedMap<Int, IncompleteContainer> = synchronizedMapOf()
val containers: SynchronizedBiMap<Int, Container> = synchronizedBiMapOf( val containers: SynchronizedBiMap<Int, Container> = synchronizedBiMapOf(
ProtocolDefinition.PLAYER_CONTAINER_ID to inventory, PlayerInventory.CONTAINER_ID to inventory,
) )
var selectedHotbarSlot: Int by observed(0) var selectedHotbarSlot: Int by observed(0)

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger * Copyright (C) 2020-2023 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -48,8 +48,9 @@ import de.bixilon.minosoft.data.registries.blocks.types.water.KelpPlantBlock
import de.bixilon.minosoft.data.registries.blocks.types.water.SeagrassBlock import de.bixilon.minosoft.data.registries.blocks.types.water.SeagrassBlock
import de.bixilon.minosoft.data.registries.factory.clazz.DefaultClassFactory import de.bixilon.minosoft.data.registries.factory.clazz.DefaultClassFactory
@Suppress("DEPRECATION_ERROR")
object BlockFactories : DefaultClassFactory<BlockFactory<*>>( object BlockFactories : DefaultClassFactory<BlockFactory<*>>(
AirBlock, de.bixilon.minosoft.data.registries.blocks.types.AirBlock,
Block, Block,
FluidBlock, FluidBlock,
DoorBlock, DoorBlock,

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger * Copyright (C) 2020-2023 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -17,9 +17,10 @@ import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.blocks.BlockFactory import de.bixilon.minosoft.data.registries.blocks.BlockFactory
import de.bixilon.minosoft.data.registries.registries.Registries import de.bixilon.minosoft.data.registries.registries.Registries
@Deprecated("Air is always null!") @Deprecated("Air == null!", level = DeprecationLevel.HIDDEN)
open class AirBlock(resourceLocation: ResourceLocation, registries: Registries, data: Map<String, Any>) : Block(resourceLocation, registries, data) { open class AirBlock(resourceLocation: ResourceLocation, registries: Registries, data: Map<String, Any>) : Block(resourceLocation, registries, data) {
@Suppress("DEPRECATION_ERROR")
companion object : BlockFactory<AirBlock> { companion object : BlockFactory<AirBlock> {
override fun build(resourceLocation: ResourceLocation, registries: Registries, data: Map<String, Any>): AirBlock { override fun build(resourceLocation: ResourceLocation, registries: Registries, data: Map<String, Any>): AirBlock {

View File

@ -105,6 +105,7 @@ open class CampfireBlock(resourceLocation: ResourceLocation, registries: Registr
companion object : BlockFactory<CampfireBlock> { companion object : BlockFactory<CampfireBlock> {
private val CAMPFIRE_CRACKLE_SOUND = "minecraft:block.campfire.crackle".toResourceLocation() private val CAMPFIRE_CRACKLE_SOUND = "minecraft:block.campfire.crackle".toResourceLocation()
const val MAX_ITEMS = 4
override fun build(resourceLocation: ResourceLocation, registries: Registries, data: Map<String, Any>): CampfireBlock { override fun build(resourceLocation: ResourceLocation, registries: Registries, data: Map<String, Any>): CampfireBlock {
return CampfireBlock(resourceLocation, registries, data) return CampfireBlock(resourceLocation, registries, data)

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger * Copyright (C) 2020-2023 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -17,7 +17,6 @@ import de.bixilon.kutil.exception.Broken
import de.bixilon.kutil.json.JsonObject import de.bixilon.kutil.json.JsonObject
import de.bixilon.minosoft.data.registries.ResourceLocation import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.registries.blocks.BlockState import de.bixilon.minosoft.data.registries.blocks.BlockState
import de.bixilon.minosoft.data.registries.blocks.types.AirBlock
import de.bixilon.minosoft.data.registries.registries.Registries import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
@ -69,12 +68,13 @@ class BlockStateRegistry(var flattened: Boolean) : AbstractRegistry<BlockState?>
return getOrNull(id) return getOrNull(id)
} }
@Suppress("DEPRECATION_ERROR")
override fun getOrNull(id: Int): BlockState? { override fun getOrNull(id: Int): BlockState? {
if (id == ProtocolDefinition.AIR_BLOCK_ID) { if (id == ProtocolDefinition.AIR_BLOCK_ID) {
return null return null
} }
val state = forceGet(id) ?: return null val state = forceGet(id) ?: return null
if (state.block is AirBlock) { if (state.block is de.bixilon.minosoft.data.registries.blocks.types.AirBlock) {
return null return null
} }
return state return state

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger * Copyright (C) 2020-2023 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -18,11 +18,6 @@ import de.bixilon.minosoft.data.text.formatting.color.RGBColor
import de.bixilon.minosoft.data.text.formatting.color.RGBColor.Companion.asColor import de.bixilon.minosoft.data.text.formatting.color.RGBColor.Companion.asColor
object RenderConstants { object RenderConstants {
val BLACK_COLOR = "#000000".asColor()
val GRASS_FAILOVER_COLOR = "#48B518".asColor()
val EXPERIENCE_BAR_LEVEL_COLOR = "#80ff20".asColor() val EXPERIENCE_BAR_LEVEL_COLOR = "#80ff20".asColor()
const val COLORMAP_SIZE = 255 const val COLORMAP_SIZE = 255
@ -42,13 +37,9 @@ object RenderConstants {
val DEBUG_TEXTURE_RESOURCE_LOCATION = ResourceLocation("minosoft:textures/debug.png") val DEBUG_TEXTURE_RESOURCE_LOCATION = ResourceLocation("minosoft:textures/debug.png")
const val CAMPFIRE_ITEMS = 4
const val DOUBLE_PRESS_KEY_PRESS_MAX_DELAY = 300 const val DOUBLE_PRESS_KEY_PRESS_MAX_DELAY = 300
const val DOUBLE_PRESS_DELAY_BETWEEN_PRESSED = 500 const val DOUBLE_PRESS_DELAY_BETWEEN_PRESSED = 500
const val MAXIMUM_PARTICLE_AMOUNT = 50000
const val DEFAULT_LINE_WIDTH = 1.0f / 128.0f const val DEFAULT_LINE_WIDTH = 1.0f / 128.0f

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger * Copyright (C) 2020-2023 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -33,7 +33,6 @@ import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextElement
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3iUtil.EMPTY import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3iUtil.EMPTY
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.KUtil import de.bixilon.minosoft.util.KUtil
class RawItemElement( class RawItemElement(
@ -101,14 +100,15 @@ class RawItemElement(
} }
override fun forceSilentApply() { override fun forceSilentApply() {
val count = _stack?.item?.count val item = _stack?.item
val count = item?.count
countText.text = when { countText.text = when {
count == null || count == 1 -> ChatComponent.EMPTY count == null || count == 1 -> ChatComponent.EMPTY
count < -99 -> NEGATIVE_INFINITE_TEXT count < -99 -> NEGATIVE_INFINITE_TEXT
count < 0 -> TextComponent(count, color = ChatColors.RED) // No clue why I do this... count < 0 -> TextComponent(count, color = ChatColors.RED) // No clue why I do this...
count == 0 -> ZERO_TEXT count == 0 -> ZERO_TEXT
count > 99 -> INFINITE_TEXT count > 99 -> INFINITE_TEXT
count > ProtocolDefinition.ITEM_STACK_MAX_SIZE -> TextComponent(count, color = ChatColors.RED) count > item.item.maxStackSize -> TextComponent(count, color = ChatColors.RED)
else -> TextComponent(count) else -> TextComponent(count)
} }

View File

@ -22,7 +22,6 @@ import de.bixilon.kutil.observer.DataObserver.Companion.observe
import de.bixilon.kutil.time.TimeUtil.millis import de.bixilon.kutil.time.TimeUtil.millis
import de.bixilon.minosoft.data.registries.ResourceLocation import de.bixilon.minosoft.data.registries.ResourceLocation
import de.bixilon.minosoft.data.world.particle.AbstractParticleRenderer import de.bixilon.minosoft.data.world.particle.AbstractParticleRenderer
import de.bixilon.minosoft.gui.rendering.RenderConstants
import de.bixilon.minosoft.gui.rendering.RenderContext import de.bixilon.minosoft.gui.rendering.RenderContext
import de.bixilon.minosoft.gui.rendering.events.CameraMatrixChangeEvent import de.bixilon.minosoft.gui.rendering.events.CameraMatrixChangeEvent
import de.bixilon.minosoft.gui.rendering.particle.types.Particle import de.bixilon.minosoft.gui.rendering.particle.types.Particle
@ -52,8 +51,8 @@ class ParticleRenderer(
private val translucentShader = renderSystem.createShader(minosoft("particle")) { ParticleShader(it, false) } private val translucentShader = renderSystem.createShader(minosoft("particle")) { ParticleShader(it, false) }
// There is no opaque mesh because it is simply not needed (every particle has transparency) // There is no opaque mesh because it is simply not needed (every particle has transparency)
private var transparentMesh = ParticleMesh(context, BufferedArrayFloatList(RenderConstants.MAXIMUM_PARTICLE_AMOUNT * ParticleMesh.ParticleMeshStruct.FLOATS_PER_VERTEX)) private var transparentMesh = ParticleMesh(context, BufferedArrayFloatList(MAXIMUM_AMOUNT * ParticleMesh.ParticleMeshStruct.FLOATS_PER_VERTEX))
private var translucentMesh = ParticleMesh(context, BufferedArrayFloatList(RenderConstants.MAXIMUM_PARTICLE_AMOUNT * ParticleMesh.ParticleMeshStruct.FLOATS_PER_VERTEX)) private var translucentMesh = ParticleMesh(context, BufferedArrayFloatList(MAXIMUM_AMOUNT * ParticleMesh.ParticleMeshStruct.FLOATS_PER_VERTEX))
private val particlesLock = SimpleLock() private val particlesLock = SimpleLock()
private var particles: MutableList<Particle> = mutableListOf() private var particles: MutableList<Particle> = mutableListOf()
@ -81,7 +80,7 @@ class ParticleRenderer(
} }
field = value field = value
} }
private var maxAmount = RenderConstants.MAXIMUM_PARTICLE_AMOUNT private var maxAmount = MAXIMUM_AMOUNT
set(value) { set(value) {
check(value > 1) { "Can not have negative particle max amount" } check(value > 1) { "Can not have negative particle max amount" }
particlesLock.lock() particlesLock.lock()
@ -102,7 +101,7 @@ class ParticleRenderer(
get() = particles.size get() = particles.size
override fun init(latch: CountUpAndDownLatch) { override fun init(latch: CountUpAndDownLatch) {
profile::maxAmount.observe(this, true) { maxAmount = minOf(it, RenderConstants.MAXIMUM_PARTICLE_AMOUNT) } profile::maxAmount.observe(this, true) { maxAmount = minOf(it, MAXIMUM_AMOUNT) }
profile::enabled.observe(this, true) { enabled = it } profile::enabled.observe(this, true) { enabled = it }
connection.events.listen<CameraMatrixChangeEvent> { connection.events.listen<CameraMatrixChangeEvent> {
@ -263,6 +262,7 @@ class ParticleRenderer(
companion object : RendererBuilder<ParticleRenderer> { companion object : RendererBuilder<ParticleRenderer> {
override val identifier = ResourceLocation("minosoft:particle") override val identifier = ResourceLocation("minosoft:particle")
const val MAXIMUM_AMOUNT = 50000
override fun build(connection: PlayConnection, context: RenderContext): ParticleRenderer? { override fun build(connection: PlayConnection, context: RenderContext): ParticleRenderer? {
if (connection.profiles.particle.skipLoading) { if (connection.profiles.particle.skipLoading) {

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger * Copyright (C) 2020-2023 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -59,7 +59,7 @@ object Vec3iUtil {
fun Any?.toVec3iN(): Vec3i? { fun Any?.toVec3iN(): Vec3i? {
return when (this) { return when (this) {
is List<*> -> Vec3i(this[0].toInt(), this[1].toInt(), this[2].toInt()) is List<*> -> Vec3i(this[0].toInt(), this[1].toInt(), this[2].toInt())
is Map<*, *> -> Vec3i(this["x"]?.toInt() ?: 0.0f, this["y"]?.toInt() ?: 0.0f, this["z"]?.toInt() ?: 0.0f) is Map<*, *> -> Vec3i(this["x"]?.toInt() ?: 0, this["y"]?.toInt() ?: 0, this["z"]?.toInt() ?: 0)
is IntArray -> Vec3i(this[0], this[1], this[2]) is IntArray -> Vec3i(this[0], this[1], this[2])
is Number -> Vec3i(this.toInt()) is Number -> Vec3i(this.toInt())
else -> null else -> null

View File

@ -22,9 +22,10 @@ import de.bixilon.minosoft.protocol.network.connection.play.channel.play.PlayCha
import de.bixilon.minosoft.protocol.packets.c2s.play.ChannelC2SP import de.bixilon.minosoft.protocol.packets.c2s.play.ChannelC2SP
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.PlayOutByteBuffer import de.bixilon.minosoft.protocol.protocol.PlayOutByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
object BrandHandler { object BrandHandler {
const val VANILLA = "vanilla"
const val MINOSOFT = "minosoft"
fun register(connection: PlayConnection) { fun register(connection: PlayConnection) {
connection.channels.play[connection.getBrandChannel()] = BrandChannelHandler(connection) connection.channels.play[connection.getBrandChannel()] = BrandChannelHandler(connection)
@ -41,7 +42,7 @@ object BrandHandler {
} }
fun PlayConnection.sendBrand() { fun PlayConnection.sendBrand() {
sendBrand(getBrandChannel(), if (profiles.connection.fakeBrand) ProtocolDefinition.VANILLA_BRAND else ProtocolDefinition.MINOSOFT_BRAND) sendBrand(getBrandChannel(), if (profiles.connection.fakeBrand) VANILLA else MINOSOFT)
} }

View File

@ -32,6 +32,7 @@ import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_14W26A import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_14W26A
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_14W28A import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_14W28A
@ -107,21 +108,16 @@ class ChunkS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
// block entities // block entities
when { when {
buffer.versionId < V_1_9_4 -> { buffer.versionId < V_1_9_4 -> Unit
}
buffer.versionId < V_21W37A -> { buffer.versionId < V_21W37A -> {
val blockEntities: MutableMap<Vec3i, BlockEntity> = mutableMapOf() val blockEntities: MutableMap<Vec3i, BlockEntity> = mutableMapOf()
val positionOffset = Vec3i.of(position, dimension.minSection, Vec3i.EMPTY) val positionOffset = Vec3i.of(position, dimension.minSection, Vec3i.EMPTY)
for (i in 0 until buffer.readVarInt()) { for (i in 0 until buffer.readVarInt()) {
val nbt = buffer.readNBT().asJsonObject() val nbt = buffer.readNBT().asJsonObject()
val position = Vec3i(nbt["x"]?.toInt() ?: continue, nbt["y"]?.toInt() ?: continue, nbt["z"]?.toInt() ?: continue) - positionOffset val position = Vec3i(nbt["x"]?.toInt() ?: continue, nbt["y"]?.toInt() ?: continue, nbt["z"]?.toInt() ?: continue) - positionOffset
val resourceLocation = (nbt["id"]?.toResourceLocation() ?: continue).fix() val id = (nbt["id"]?.toResourceLocation() ?: continue).fix()
val type = buffer.connection.registries.blockEntityType[resourceLocation] val type = buffer.connection.registries.blockEntityType[id] ?: continue
if (type == null) {
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.WARN) { "Unknown block entity: $resourceLocation" }
continue
}
val entity = type.build(buffer.connection) val entity = type.build(buffer.connection)
entity.updateNBT(nbt) entity.updateNBT(nbt)
blockEntities[position] = entity blockEntities[position] = entity
@ -162,7 +158,7 @@ class ChunkS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
fun PlayInByteBuffer.readBiomeArray(): Array<Biome> { fun PlayInByteBuffer.readBiomeArray(): Array<Biome> {
val length = when { val length = when {
versionId >= ProtocolVersions.V_20W28A -> readVarInt() versionId >= ProtocolVersions.V_20W28A -> readVarInt()
versionId >= ProtocolVersions.V_19W36A -> 1024 versionId >= ProtocolVersions.V_19W36A -> ProtocolDefinition.BLOCKS_PER_SECTION / 4 // 1024, 4x4 blocks
else -> 0 else -> 0
} }

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.protocol.packets.s2c.play.container package de.bixilon.minosoft.protocol.packets.s2c.play.container
import de.bixilon.minosoft.data.container.DefaultInventoryTypes import de.bixilon.minosoft.data.container.DefaultInventoryTypes
import de.bixilon.minosoft.data.container.types.PlayerInventory
import de.bixilon.minosoft.data.registries.containers.ContainerType import de.bixilon.minosoft.data.registries.containers.ContainerType
import de.bixilon.minosoft.data.text.ChatComponent import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.modding.event.events.container.ContainerOpenEvent import de.bixilon.minosoft.modding.event.events.container.ContainerOpenEvent
@ -20,7 +21,6 @@ import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_14W03B import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_14W03B
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_19W11A import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_19W11A
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_1_14 import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_1_14
@ -66,7 +66,7 @@ class OpenContainerS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
} }
override fun handle(connection: PlayConnection) { override fun handle(connection: PlayConnection) {
if (containerId == ProtocolDefinition.PLAYER_CONTAINER_ID) { if (containerId == PlayerInventory.CONTAINER_ID) {
return return
} }
val title = if (hasTitle) title else null val title = if (hasTitle) title else null

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger * Copyright (C) 2020-2023 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -29,6 +29,10 @@ import java.net.*
import java.nio.charset.StandardCharsets import java.nio.charset.StandardCharsets
object LANServerListener { object LANServerListener {
const val BROADCAST_PORT = 4445
const val BROADCAST_ADDRESS = "224.0.2.60"
const val MAXIMUM_SERVERS = 100 // maximum number of lan servers, set because otherwise dos attacks would be easy
val SERVERS: HashBiMap<InetAddress, AbstractServer> = HashBiMap.create() val SERVERS: HashBiMap<InetAddress, AbstractServer> = HashBiMap.create()
private const val MOTD_START_STRING = "[MOTD]" private const val MOTD_START_STRING = "[MOTD]"
private const val MOTD_END_STRING = "[/MOTD]" private const val MOTD_END_STRING = "[/MOTD]"
@ -66,9 +70,9 @@ object LANServerListener {
stop = false stop = false
val thread = Thread({ val thread = Thread({
try { try {
val socket = MulticastSocket(ProtocolDefinition.LAN_SERVER_BROADCAST_PORT) val socket = MulticastSocket(BROADCAST_PORT)
val inetAddress = InetAddress.getByName(ProtocolDefinition.LAN_SERVER_BROADCAST_ADDRESS) val inetAddress = InetAddress.getByName(BROADCAST_ADDRESS)
socket.joinGroup(InetSocketAddress(inetAddress, ProtocolDefinition.LAN_SERVER_BROADCAST_PORT), NetworkInterface.getByInetAddress(inetAddress)) socket.joinGroup(InetSocketAddress(inetAddress, BROADCAST_PORT), NetworkInterface.getByInetAddress(inetAddress))
val buffer = ByteArray(256) // this should be enough, if the packet is longer, it is probably invalid val buffer = ByteArray(256) // this should be enough, if the packet is longer, it is probably invalid
Log.log(LogMessageType.NETWORK_STATUS, LogLevels.VERBOSE) { "Listening for LAN servers..." } Log.log(LogMessageType.NETWORK_STATUS, LogLevels.VERBOSE) { "Listening for LAN servers..." }
latch?.dec() latch?.dec()
@ -87,7 +91,7 @@ object LANServerListener {
if (SERVERS.containsValue(server)) { if (SERVERS.containsValue(server)) {
continue continue
} }
if (SERVERS.size > ProtocolDefinition.LAN_SERVER_MAXIMUM_SERVERS) { if (SERVERS.size > MAXIMUM_SERVERS) {
continue continue
} }
Log.log(LogMessageType.NETWORK_STATUS, LogLevels.INFO) { "Discovered LAN servers: ${server.address}" } Log.log(LogMessageType.NETWORK_STATUS, LogLevels.INFO) { "Discovered LAN servers: ${server.address}" }

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger * Copyright (C) 2020-2023 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -27,22 +27,14 @@ public final class ProtocolDefinition {
public static final float ROTATION_ANGLE_DIVIDER = 360.0F / 256.0F; public static final float ROTATION_ANGLE_DIVIDER = 360.0F / 256.0F;
public static final float SOUND_PITCH_DIVIDER = 100.0F / 63.0F; public static final float SOUND_PITCH_DIVIDER = 100.0F / 63.0F;
public static final int PLAYER_CONTAINER_ID = 0;
public static final int FLATTING_VERSION_ID = ProtocolVersions.V_17W47A;
public static final int PRE_FLATTENING_VERSION_ID = ProtocolVersions.V_17W46A;
public static final int QUERY_PROTOCOL_VERSION_ID = -1; public static final int QUERY_PROTOCOL_VERSION_ID = -1;
public static final int LAN_SERVER_BROADCAST_PORT = 4445; public static final String MINECRAFT_NAMESPACE = "minecraft";
public static final String LAN_SERVER_BROADCAST_ADDRESS = "224.0.2.60";
public static final int LAN_SERVER_MAXIMUM_SERVERS = 100; // maximum number of lan servers, set because otherwise dos attacks would be easy
public static final String DEFAULT_NAMESPACE = "minecraft";
public static final String MINOSOFT_NAMESPACE = "minosoft"; public static final String MINOSOFT_NAMESPACE = "minosoft";
public static final char TEXT_COMPONENT_SPECIAL_PREFIX_CHAR = '\u00A7'; public static final String DEFAULT_NAMESPACE = MINECRAFT_NAMESPACE;
public static final int DEFAULT_BUFFER_SIZE = 4096; public static final char TEXT_COMPONENT_SPECIAL_PREFIX_CHAR = '§';
public static final int AIR_BLOCK_ID = 0; public static final int AIR_BLOCK_ID = 0;
@ -65,8 +57,8 @@ public final class ProtocolDefinition {
public static final int CHUNK_MAX_SECTION = CHUNK_MAX_Y / SECTION_HEIGHT_Y; public static final int CHUNK_MAX_SECTION = CHUNK_MAX_Y / SECTION_HEIGHT_Y;
public static final int CHUNK_MAX_HEIGHT = CHUNK_MAX_Y - CHUNK_MIN_Y; public static final int CHUNK_MAX_HEIGHT = CHUNK_MAX_Y - CHUNK_MIN_Y;
public static final int CHUNK_MAX_SECTIONS = CHUNK_MAX_HEIGHT / SECTION_HEIGHT_Y; public static final int CHUNK_MAX_SECTIONS = CHUNK_MAX_HEIGHT / SECTION_HEIGHT_Y;
public static final int ITEM_STACK_MAX_SIZE = 64;
@Deprecated
public static final char[] OBFUSCATED_CHARS = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~".toCharArray(); public static final char[] OBFUSCATED_CHARS = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~".toCharArray();
@ -89,8 +81,4 @@ public final class ProtocolDefinition {
public static final byte LIGHT_LEVELS = 16; public static final byte LIGHT_LEVELS = 16;
public static final byte MAX_LIGHT_LEVEL = LIGHT_LEVELS - 1; public static final byte MAX_LIGHT_LEVEL = LIGHT_LEVELS - 1;
public static final int MAX_LIGHT_LEVEL_I = MAX_LIGHT_LEVEL; public static final int MAX_LIGHT_LEVEL_I = MAX_LIGHT_LEVEL;
public static final String VANILLA_BRAND = "vanilla";
public static final String MINOSOFT_BRAND = "minosoft";
} }

View File

@ -21,7 +21,6 @@ import de.bixilon.minosoft.data.registries.registries.Registries
import de.bixilon.minosoft.data.registries.registries.RegistriesLoader import de.bixilon.minosoft.data.registries.registries.RegistriesLoader
import de.bixilon.minosoft.protocol.packets.factory.C2SPacketType import de.bixilon.minosoft.protocol.packets.factory.C2SPacketType
import de.bixilon.minosoft.protocol.packets.factory.S2CPacketType import de.bixilon.minosoft.protocol.packets.factory.S2CPacketType
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.protocol.protocol.ProtocolStates import de.bixilon.minosoft.protocol.protocol.ProtocolStates
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_15W31A import de.bixilon.minosoft.protocol.protocol.ProtocolVersions.V_15W31A
@ -49,7 +48,7 @@ class Version(
return this.versionId.compareTo(versionId) return this.versionId.compareTo(versionId)
} }
val flattened: Boolean get() = versionId >= ProtocolDefinition.FLATTING_VERSION_ID val flattened: Boolean get() = versionId >= ProtocolVersions.V_17W47A
val hasOffhand: Boolean get() = versionId >= V_15W31A val hasOffhand: Boolean get() = versionId >= V_15W31A
val maxPacketLength get() = if (versionId < ProtocolVersions.V_1_17_1_RC2) 1 shl 21 else 1 shl 23 val maxPacketLength get() = if (versionId < ProtocolVersions.V_1_17_1_RC2) 1 shl 21 else 1 shl 23
val maxChatMessageSize get() = if (versionId < ProtocolVersions.V_16W38A) 100 else 256 val maxChatMessageSize get() = if (versionId < ProtocolVersions.V_16W38A) 100 else 256

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger * Copyright (C) 2020-2023 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -50,11 +50,10 @@ object Jackson {
.registerModule(Vec3Serializer) .registerModule(Vec3Serializer)
.registerModule(Vec4Serializer) .registerModule(Vec4Serializer)
.setDefaultMergeable(true) .setDefaultMergeable(true)
.apply {
propertyNamingStrategy = PropertyNamingStrategies.SNAKE_CASE
}
val JSON_MAP_TYPE: MapType = MAPPER.typeFactory.constructMapType(HashMap::class.java, Any::class.java, Any::class.java) val JSON_MAP_TYPE: MapType = MAPPER.typeFactory.constructMapType(HashMap::class.java, Any::class.java, Any::class.java)
init {
MAPPER.propertyNamingStrategy = PropertyNamingStrategies.SNAKE_CASE
}
} }