mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 09:56:37 -04:00
move raycast method, world triggers events now (when using setBlock, etc)
This commit is contained in:
parent
320abcb306
commit
f62fc6a11e
@ -17,23 +17,27 @@ import de.bixilon.minosoft.data.entities.block.BlockEntity
|
||||
import de.bixilon.minosoft.data.mappings.Dimension
|
||||
import de.bixilon.minosoft.data.mappings.biomes.Biome
|
||||
import de.bixilon.minosoft.data.mappings.blocks.BlockState
|
||||
import de.bixilon.minosoft.data.mappings.tweaker.VersionTweaker
|
||||
import de.bixilon.minosoft.data.world.biome.accessor.BiomeAccessor
|
||||
import de.bixilon.minosoft.data.world.biome.accessor.NullBiomeAccessor
|
||||
import de.bixilon.minosoft.data.world.light.WorldLightAccessor
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.chunkPosition
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.floor
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.getWorldOffset
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.inChunkPosition
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.inChunkSectionPosition
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.sectionHeight
|
||||
import de.bixilon.minosoft.modding.event.events.BlockSetEvent
|
||||
import de.bixilon.minosoft.modding.event.events.ChunkUnloadEvent
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.util.KUtil.synchronizedMapOf
|
||||
import glm_.vec2.Vec2i
|
||||
import glm_.vec3.Vec3
|
||||
import glm_.vec3.Vec3i
|
||||
|
||||
/**
|
||||
* Collection of chunks and more
|
||||
*/
|
||||
class World : BiomeAccessor {
|
||||
class World(
|
||||
val connection: PlayConnection,
|
||||
) : BiomeAccessor {
|
||||
val chunks: MutableMap<Vec2i, Chunk> = synchronizedMapOf()
|
||||
val entities = WorldEntities()
|
||||
var isHardcore = false
|
||||
@ -48,8 +52,7 @@ class World : BiomeAccessor {
|
||||
var age = 0L
|
||||
|
||||
fun getBlockState(blockPosition: Vec3i): BlockState? {
|
||||
val chunkLocation = blockPosition.chunkPosition
|
||||
return chunks[chunkLocation]?.getBlockState(blockPosition.inChunkPosition)
|
||||
return chunks[blockPosition.chunkPosition]?.getBlockState(blockPosition.inChunkPosition)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
@ -62,12 +65,34 @@ class World : BiomeAccessor {
|
||||
return chunks.getOrPut(chunkPosition) { Chunk() }
|
||||
}
|
||||
|
||||
fun setBlock(blockPosition: Vec3i, blockState: BlockState?) {
|
||||
chunks[blockPosition.chunkPosition]?.setBlockState(blockPosition.inChunkPosition, blockState)
|
||||
fun setBlock(blockPosition: Vec3i, blockState: BlockState?, createChunk: Boolean = false) {
|
||||
val chunkPosition = blockPosition.chunkPosition
|
||||
if (createChunk) {
|
||||
// chunks.getOrPut(chunkPosition) { Chunk() }
|
||||
TODO()
|
||||
} else {
|
||||
chunks[chunkPosition]
|
||||
}?.let {
|
||||
val sections = it.sections ?: return
|
||||
|
||||
val transformedBlockState = if (connection.version.isFlattened()) {
|
||||
blockState
|
||||
} else {
|
||||
VersionTweaker.transformBlock(blockState, sections, blockPosition.inChunkSectionPosition, blockPosition.sectionHeight)
|
||||
}
|
||||
it.setBlockState(blockPosition.inChunkPosition, transformedBlockState)
|
||||
connection.fireEvent(BlockSetEvent(
|
||||
connection = connection,
|
||||
blockPosition = blockPosition,
|
||||
blockState = transformedBlockState,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
fun unloadChunk(position: Vec2i) {
|
||||
chunks.remove(position)
|
||||
fun unloadChunk(chunkPosition: Vec2i) {
|
||||
chunks.remove(chunkPosition)?.let {
|
||||
connection.fireEvent(ChunkUnloadEvent(connection, chunkPosition))
|
||||
}
|
||||
}
|
||||
|
||||
fun replaceChunk(position: Vec2i, chunk: Chunk) {
|
||||
@ -114,45 +139,4 @@ class World : BiomeAccessor {
|
||||
|
||||
return blocks.toMap()
|
||||
}
|
||||
|
||||
data class RaycastHit(
|
||||
val position: Vec3,
|
||||
val distance: Float,
|
||||
val blockState: BlockState,
|
||||
val steps: Int,
|
||||
) {
|
||||
val blockPosition = position.floor
|
||||
}
|
||||
|
||||
fun raycast(origin: Vec3, direction: Vec3): RaycastHit? {
|
||||
val currentPosition = Vec3(origin)
|
||||
|
||||
fun getTotalDistance(): Float {
|
||||
return (origin - currentPosition).length()
|
||||
}
|
||||
|
||||
for (i in 0..MAX_STEPS) {
|
||||
val blockPosition = currentPosition.floor
|
||||
val blockState = getBlockState(blockPosition)
|
||||
val distance = blockState?.outlineShape?.let {
|
||||
val aabb = it + blockPosition + blockPosition.getWorldOffset(blockState.block)
|
||||
aabb.raycast(currentPosition, direction)
|
||||
} ?: -1.0f
|
||||
|
||||
if (distance >= 0.0f && blockState != null) {
|
||||
return RaycastHit(
|
||||
currentPosition + direction * distance,
|
||||
getTotalDistance() + distance,
|
||||
blockState = blockState,
|
||||
steps = i,
|
||||
)
|
||||
}
|
||||
currentPosition += direction * (VecUtil.getDistanceToNextIntegerAxis(currentPosition, direction) + 0.001)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val MAX_STEPS = 100
|
||||
}
|
||||
}
|
||||
|
@ -16,13 +16,13 @@ package de.bixilon.minosoft.gui.rendering
|
||||
import de.bixilon.minosoft.config.StaticConfiguration
|
||||
import de.bixilon.minosoft.config.config.game.controls.KeyBindingsNames
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import de.bixilon.minosoft.gui.input.key.RenderWindowInputHandler
|
||||
import de.bixilon.minosoft.gui.rendering.chunk.WorldRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.chunk.block.outline.BlockOutlineRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.font.Font
|
||||
import de.bixilon.minosoft.gui.rendering.hud.HUDRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.hud.atlas.TextureLike
|
||||
import de.bixilon.minosoft.gui.rendering.hud.atlas.TextureLikeTexture
|
||||
import de.bixilon.minosoft.gui.rendering.input.key.RenderWindowInputHandler
|
||||
import de.bixilon.minosoft.gui.rendering.modding.events.RenderingStateChangeEvent
|
||||
import de.bixilon.minosoft.gui.rendering.modding.events.ScreenResizeEvent
|
||||
import de.bixilon.minosoft.gui.rendering.shader.Shader
|
||||
|
@ -25,9 +25,9 @@ import de.bixilon.minosoft.data.world.Chunk
|
||||
import de.bixilon.minosoft.data.world.ChunkSection
|
||||
import de.bixilon.minosoft.data.world.ChunkSection.Companion.indexPosition
|
||||
import de.bixilon.minosoft.data.world.World
|
||||
import de.bixilon.minosoft.gui.input.camera.Frustum
|
||||
import de.bixilon.minosoft.gui.rendering.*
|
||||
import de.bixilon.minosoft.gui.rendering.chunk.models.renderable.BlockLikeRenderContext
|
||||
import de.bixilon.minosoft.gui.rendering.input.camera.Frustum
|
||||
import de.bixilon.minosoft.gui.rendering.modding.events.FrustumChangeEvent
|
||||
import de.bixilon.minosoft.gui.rendering.modding.events.RenderingStateChangeEvent
|
||||
import de.bixilon.minosoft.gui.rendering.shader.Shader
|
||||
@ -150,7 +150,7 @@ class WorldRenderer(
|
||||
prepareChunk(it.chunkPosition)
|
||||
})
|
||||
|
||||
connection.registerEvent(CallbackEventInvoker.of<BlockChangeEvent> {
|
||||
connection.registerEvent(CallbackEventInvoker.of<BlockSetEvent> {
|
||||
prepareChunkSection(it.blockPosition.chunkPosition, it.blockPosition.sectionHeight)
|
||||
})
|
||||
|
||||
@ -158,7 +158,7 @@ class WorldRenderer(
|
||||
clearChunkCache()
|
||||
})
|
||||
|
||||
connection.registerEvent(CallbackEventInvoker.of<MultiBlockChangeEvent> {
|
||||
connection.registerEvent(CallbackEventInvoker.of<MassBlockSetEvent> {
|
||||
val sectionHeights: MutableSet<Int> = synchronizedSetOf()
|
||||
for ((key) in it.blocks) {
|
||||
sectionHeights.add(key.sectionHeight)
|
||||
|
@ -11,14 +11,13 @@
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.gui.input.camera
|
||||
package de.bixilon.minosoft.gui.rendering.input.camera
|
||||
|
||||
import de.bixilon.minosoft.Minosoft
|
||||
import de.bixilon.minosoft.config.config.game.controls.KeyBindingsNames
|
||||
import de.bixilon.minosoft.data.entities.EntityRotation
|
||||
import de.bixilon.minosoft.data.entities.entities.player.PlayerEntity
|
||||
import de.bixilon.minosoft.data.mappings.biomes.Biome
|
||||
import de.bixilon.minosoft.data.world.World
|
||||
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||
import de.bixilon.minosoft.gui.rendering.modding.events.CameraMatrixChangeEvent
|
||||
@ -28,6 +27,8 @@ import de.bixilon.minosoft.gui.rendering.sky.SkyRenderer
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.blockPosition
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.chunkPosition
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.floor
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.getWorldOffset
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.inChunkSectionPosition
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.sectionHeight
|
||||
import de.bixilon.minosoft.modding.event.CallbackEventInvoker
|
||||
@ -303,13 +304,45 @@ class Camera(
|
||||
cameraPosition = getAbsoluteCameraPosition()
|
||||
}
|
||||
|
||||
fun getTargetBlock(): World.RaycastHit? {
|
||||
return connection.world.raycast(cameraPosition, cameraFront)
|
||||
fun getTargetBlock(): RaycastHit? {
|
||||
return raycast(cameraPosition, cameraFront)
|
||||
}
|
||||
|
||||
|
||||
private fun raycast(origin: Vec3, direction: Vec3): RaycastHit? {
|
||||
val currentPosition = Vec3(origin)
|
||||
|
||||
fun getTotalDistance(): Float {
|
||||
return (origin - currentPosition).length()
|
||||
}
|
||||
|
||||
for (i in 0..RAYCAST_MAX_STEPS) {
|
||||
val blockPosition = currentPosition.floor
|
||||
val blockState = connection.world.getBlockState(blockPosition)
|
||||
val distance = blockState?.outlineShape?.let {
|
||||
val aabb = it + blockPosition + blockPosition.getWorldOffset(blockState.block)
|
||||
aabb.raycast(currentPosition, direction)
|
||||
} ?: -1.0f
|
||||
|
||||
if (distance >= 0.0f && blockState != null) {
|
||||
return RaycastHit(
|
||||
currentPosition + direction * distance,
|
||||
getTotalDistance() + distance,
|
||||
blockState = blockState,
|
||||
steps = i,
|
||||
)
|
||||
}
|
||||
currentPosition += direction * (VecUtil.getDistanceToNextIntegerAxis(currentPosition, direction) + 0.001)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
private val CAMERA_UP_VEC3 = Vec3(0.0f, 1.0f, 0.0f)
|
||||
private const val PLAYER_EYE_HEIGHT = 1.3 // player is 1.8 blocks high, the camera is normally at 0.5. 1.8 - 0.5 = 1.13
|
||||
private const val PLAYER_SPRINT_SPEED_MODIFIER = 1.30000001192092896
|
||||
|
||||
private const val RAYCAST_MAX_STEPS = 100
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.gui.input.camera
|
||||
package de.bixilon.minosoft.gui.rendering.input.camera
|
||||
|
||||
|
||||
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 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 distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.gui.rendering.input.camera
|
||||
|
||||
import de.bixilon.minosoft.data.mappings.blocks.BlockState
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.floor
|
||||
import glm_.vec3.Vec3
|
||||
|
||||
data class RaycastHit(
|
||||
val position: Vec3,
|
||||
val distance: Float,
|
||||
val blockState: BlockState,
|
||||
val steps: Int,
|
||||
) {
|
||||
val blockPosition = position.floor
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.gui.input.key
|
||||
package de.bixilon.minosoft.gui.rendering.input.key
|
||||
|
||||
import de.bixilon.minosoft.config.key.KeyBinding
|
||||
|
@ -11,17 +11,17 @@
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.gui.input.key
|
||||
package de.bixilon.minosoft.gui.rendering.input.key
|
||||
|
||||
import de.bixilon.minosoft.Minosoft
|
||||
import de.bixilon.minosoft.config.config.game.controls.KeyBindingsNames
|
||||
import de.bixilon.minosoft.config.key.KeyAction
|
||||
import de.bixilon.minosoft.config.key.KeyCodes
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import de.bixilon.minosoft.gui.input.camera.Camera
|
||||
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||
import de.bixilon.minosoft.gui.rendering.hud.elements.input.KeyConsumer
|
||||
import de.bixilon.minosoft.gui.rendering.input.camera.Camera
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.util.logging.Log
|
||||
import de.bixilon.minosoft.util.logging.LogLevels
|
@ -13,9 +13,9 @@
|
||||
|
||||
package de.bixilon.minosoft.gui.rendering.modding.events
|
||||
|
||||
import de.bixilon.minosoft.gui.input.camera.Frustum
|
||||
import de.bixilon.minosoft.gui.rendering.RenderWindow
|
||||
import de.bixilon.minosoft.gui.rendering.Rendering
|
||||
import de.bixilon.minosoft.gui.rendering.input.camera.Frustum
|
||||
|
||||
class FrustumChangeEvent(
|
||||
renderWindow: RenderWindow = Rendering.currentContext!!,
|
||||
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2021 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 distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.modding.event
|
||||
|
||||
import de.bixilon.minosoft.util.KUtil
|
||||
import de.bixilon.minosoft.util.enum.ValuesEnum
|
||||
|
||||
enum class EventInitiators {
|
||||
CLIENT,
|
||||
SERVER,
|
||||
;
|
||||
|
||||
companion object : ValuesEnum<EventInitiators> {
|
||||
override val VALUES: Array<EventInitiators> = values()
|
||||
override val NAME_MAP: Map<String, EventInitiators> = KUtil.getEnumValues(VALUES)
|
||||
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@
|
||||
package de.bixilon.minosoft.modding.event.events
|
||||
|
||||
import de.bixilon.minosoft.data.mappings.blocks.BlockState
|
||||
import de.bixilon.minosoft.modding.event.EventInitiators
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.play.BlockSetS2CP
|
||||
import glm_.vec3.Vec3i
|
||||
@ -20,11 +21,12 @@ import glm_.vec3.Vec3i
|
||||
/**
|
||||
* Fired when one block is changed
|
||||
*/
|
||||
class BlockChangeEvent(
|
||||
class BlockSetEvent(
|
||||
connection: PlayConnection,
|
||||
val blockPosition: Vec3i,
|
||||
val block: BlockState?,
|
||||
val blockState: BlockState?,
|
||||
val initiator: EventInitiators = EventInitiators.CLIENT,
|
||||
) : PlayConnectionEvent(connection) {
|
||||
|
||||
constructor(connection: PlayConnection, packet: BlockSetS2CP) : this(connection, packet.blockPosition, packet.block)
|
||||
constructor(connection: PlayConnection, packet: BlockSetS2CP) : this(connection, packet.blockPosition, packet.blockState, EventInitiators.SERVER)
|
||||
}
|
@ -13,6 +13,7 @@
|
||||
package de.bixilon.minosoft.modding.event.events
|
||||
|
||||
import de.bixilon.minosoft.data.mappings.blocks.BlockState
|
||||
import de.bixilon.minosoft.modding.event.EventInitiators
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.play.MassBlockSetS2CP
|
||||
import glm_.vec2.Vec2i
|
||||
@ -21,11 +22,13 @@ import glm_.vec3.Vec3i
|
||||
/**
|
||||
* Fired when at least block is changed
|
||||
*/
|
||||
class MultiBlockChangeEvent(
|
||||
class MassBlockSetEvent(
|
||||
connection: PlayConnection,
|
||||
val blocks: Map<Vec3i, BlockState?>,
|
||||
val chunkPosition: Vec2i,
|
||||
val initiator: EventInitiators = EventInitiators.CLIENT,
|
||||
) : PlayConnectionEvent(connection) {
|
||||
|
||||
constructor(connection: PlayConnection, packet: MassBlockSetS2CP) : this(connection, packet.blocks, packet.chunkPosition)
|
||||
constructor(connection: PlayConnection, packet: MassBlockSetS2CP) : this(connection, packet.blocks, packet.chunkPosition, EventInitiators.SERVER)
|
||||
|
||||
}
|
@ -53,7 +53,7 @@ class PlayConnection(
|
||||
val version: Version,
|
||||
) : Connection() {
|
||||
val recipes = Recipes()
|
||||
val world = World()
|
||||
val world = World(this)
|
||||
val tabList = TabList()
|
||||
val scoreboardManager = ScoreboardManager()
|
||||
val mapping = VersionMapping()
|
||||
|
@ -59,7 +59,6 @@ class BlockBreakC2SP(
|
||||
companion object : ValuesEnum<BreakType> {
|
||||
override val VALUES: Array<BreakType> = values()
|
||||
override val NAME_MAP: Map<String, BreakType> = KUtil.getEnumValues(VALUES)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,12 +13,6 @@
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play
|
||||
|
||||
import de.bixilon.minosoft.data.mappings.blocks.BlockState
|
||||
import de.bixilon.minosoft.data.mappings.tweaker.VersionTweaker
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.chunkPosition
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.inChunkSectionPosition
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.sectionHeight
|
||||
|
||||
import de.bixilon.minosoft.modding.event.events.BlockChangeEvent
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||
@ -30,38 +24,23 @@ import glm_.vec3.Vec3i
|
||||
|
||||
class BlockSetS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
||||
val blockPosition: Vec3i
|
||||
val block: BlockState?
|
||||
val blockState: BlockState?
|
||||
|
||||
init {
|
||||
if (buffer.versionId < ProtocolVersions.V_14W03B) {
|
||||
blockPosition = buffer.readByteBlockPosition()
|
||||
block = buffer.connection.mapping.getBlockState(buffer.readVarInt() shl 4 or buffer.readByte().toInt()) // ToDo: When was the meta data "compacted"? (between 1.7.10 - 1.8)
|
||||
blockState = buffer.connection.mapping.getBlockState(buffer.readVarInt() shl 4 or buffer.readByte().toInt()) // ToDo: When was the meta data "compacted"? (between 1.7.10 - 1.8)
|
||||
} else {
|
||||
blockPosition = buffer.readBlockPosition()
|
||||
block = buffer.connection.mapping.getBlockState(buffer.readVarInt())
|
||||
blockState = buffer.connection.mapping.getBlockState(buffer.readVarInt())
|
||||
}
|
||||
}
|
||||
|
||||
override fun handle(connection: PlayConnection) {
|
||||
val chunk = connection.world.getChunk(blockPosition.chunkPosition) ?: return // thanks mojang
|
||||
if (!chunk.isFullyLoaded) {
|
||||
return
|
||||
}
|
||||
val sectionHeight = blockPosition.sectionHeight
|
||||
val inChunkSectionPosition = blockPosition.inChunkSectionPosition
|
||||
val section = chunk.getSectionOrCreate(sectionHeight)
|
||||
|
||||
// tweak
|
||||
if (!connection.version.isFlattened()) {
|
||||
val block = VersionTweaker.transformBlock(block!!, chunk.sections!!, inChunkSectionPosition, sectionHeight)
|
||||
section.setBlockState(inChunkSectionPosition, block)
|
||||
} else {
|
||||
section.setBlockState(inChunkSectionPosition, block)
|
||||
}
|
||||
connection.fireEvent(BlockChangeEvent(connection, this))
|
||||
connection.world.setBlock(blockPosition, blockState)
|
||||
}
|
||||
|
||||
override fun log() {
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Block change (position=${blockPosition}, block=$block)" }
|
||||
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Block change (position=${blockPosition}, block=$blockState)" }
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@
|
||||
*/
|
||||
package de.bixilon.minosoft.protocol.packets.s2c.play
|
||||
|
||||
import de.bixilon.minosoft.modding.event.events.ChunkUnloadEvent
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||
@ -26,7 +25,6 @@ class ChunkUnloadS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
||||
|
||||
override fun handle(connection: PlayConnection) {
|
||||
connection.world.unloadChunk(chunkPosition)
|
||||
connection.fireEvent(ChunkUnloadEvent(connection, chunkPosition))
|
||||
}
|
||||
|
||||
override fun log() {
|
||||
|
@ -17,7 +17,7 @@ import de.bixilon.minosoft.data.mappings.blocks.BlockState
|
||||
import de.bixilon.minosoft.data.mappings.tweaker.VersionTweaker
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.inChunkSectionPosition
|
||||
import de.bixilon.minosoft.gui.rendering.util.VecUtil.sectionHeight
|
||||
import de.bixilon.minosoft.modding.event.events.MultiBlockChangeEvent
|
||||
import de.bixilon.minosoft.modding.event.events.MassBlockSetEvent
|
||||
import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||
@ -96,7 +96,7 @@ class MassBlockSetS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
||||
chunk.setBlockState(key, block)
|
||||
}
|
||||
}
|
||||
connection.fireEvent(MultiBlockChangeEvent(connection, this))
|
||||
connection.fireEvent(MassBlockSetEvent(connection, this))
|
||||
}
|
||||
|
||||
override fun log() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user