rename entity interact packets, fix mapping of abstract c2s packets

This commit is contained in:
Bixilon 2022-01-30 17:45:37 +01:00
parent 5fd9442909
commit b86740b8d0
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
7 changed files with 81 additions and 81 deletions

View File

@ -26,8 +26,8 @@ import de.bixilon.minosoft.gui.rendering.camera.target.targets.BlockTarget
import de.bixilon.minosoft.gui.rendering.camera.target.targets.EntityTarget import de.bixilon.minosoft.gui.rendering.camera.target.targets.EntityTarget
import de.bixilon.minosoft.protocol.packets.c2s.play.PlayerActionC2SP import de.bixilon.minosoft.protocol.packets.c2s.play.PlayerActionC2SP
import de.bixilon.minosoft.protocol.packets.c2s.play.block.BlockInteractC2SP import de.bixilon.minosoft.protocol.packets.c2s.play.block.BlockInteractC2SP
import de.bixilon.minosoft.protocol.packets.c2s.play.entity.interact.EntityInteractAtC2SP import de.bixilon.minosoft.protocol.packets.c2s.play.entity.interact.EntityEmptyInteractC2SP
import de.bixilon.minosoft.protocol.packets.c2s.play.entity.interact.EntityInteractC2SP import de.bixilon.minosoft.protocol.packets.c2s.play.entity.interact.EntityInteractPositionC2SP
import de.bixilon.minosoft.protocol.packets.c2s.play.item.UseItemC2SP import de.bixilon.minosoft.protocol.packets.c2s.play.item.UseItemC2SP
import de.bixilon.minosoft.protocol.packets.c2s.play.move.PositionRotationC2SP import de.bixilon.minosoft.protocol.packets.c2s.play.move.PositionRotationC2SP
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
@ -108,7 +108,7 @@ class InteractInteractionHandler(
fun interactEntityAt(target: EntityTarget, hand: Hands): InteractionResults { fun interactEntityAt(target: EntityTarget, hand: Hands): InteractionResults {
// used in armor stands // used in armor stands
val player = connection.player val player = connection.player
connection.sendPacket(EntityInteractAtC2SP(connection, target.entity, Vec3(target.position), hand, player.isSneaking)) connection.sendPacket(EntityInteractPositionC2SP(connection, target.entity, Vec3(target.position), hand, player.isSneaking))
if (player.gamemode == Gamemodes.SPECTATOR) { if (player.gamemode == Gamemodes.SPECTATOR) {
return InteractionResults.PASS return InteractionResults.PASS
@ -119,7 +119,7 @@ class InteractInteractionHandler(
fun interactEntity(target: EntityTarget, hand: Hands): InteractionResults { fun interactEntity(target: EntityTarget, hand: Hands): InteractionResults {
val player = connection.player val player = connection.player
connection.sendPacket(EntityInteractC2SP(connection, target.entity, hand, player.isSneaking)) connection.sendPacket(EntityEmptyInteractC2SP(connection, target.entity, hand, player.isSneaking))
if (player.gamemode == Gamemodes.SPECTATOR) { if (player.gamemode == Gamemodes.SPECTATOR) {
return InteractionResults.PASS return InteractionResults.PASS

View File

@ -1,45 +0,0 @@
/*
* 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.protocol.packets.c2s.play.entity.interact
import de.bixilon.minosoft.protocol.packets.c2s.PlayC2SPacket
import de.bixilon.minosoft.protocol.protocol.PlayOutByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
abstract class BaseInteractEntityC2SP(
val entityId: Int,
val action: EntityInteractionActions,
) : PlayC2SPacket {
abstract val sneaking: Boolean
override fun write(buffer: PlayOutByteBuffer) {
buffer.writeVarInt(entityId)
val realAction = if (buffer.versionId < ProtocolVersions.V_14W32A && this.action == EntityInteractionActions.INTERACT_AT) {
EntityInteractionActions.INTERACT
} else {
action
}
buffer.writeVarInt(realAction.ordinal)
}
enum class EntityInteractionActions {
INTERACT,
ATTACK,
INTERACT_AT,
}
}

View File

@ -26,7 +26,7 @@ import de.bixilon.minosoft.util.logging.LogMessageType
class EntityAttackC2SP( class EntityAttackC2SP(
entityId: Int, entityId: Int,
override val sneaking: Boolean, override val sneaking: Boolean,
) : BaseInteractEntityC2SP(entityId, EntityInteractionActions.ATTACK) { ) : EntityInteractC2SP(entityId, EntityInteractionActions.ATTACK) {
constructor(connection: PlayConnection, entity: Entity, sneaking: Boolean) : this(connection.world.entities.getId(entity)!!, sneaking) constructor(connection: PlayConnection, entity: Entity, sneaking: Boolean) : this(connection.world.entities.getId(entity)!!, sneaking)

View File

@ -0,0 +1,53 @@
/*
* Minosoft
* Copyright (C) 2020-2022 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.protocol.packets.c2s.play.entity.interact
import de.bixilon.minosoft.data.entities.entities.Entity
import de.bixilon.minosoft.data.player.Hands
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
import de.bixilon.minosoft.protocol.protocol.PlayOutByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
@LoadPacket(parent = true)
class EntityEmptyInteractC2SP(
entityId: Int,
val hand: Hands,
override val sneaking: Boolean,
) : EntityInteractC2SP(entityId, EntityInteractionActions.EMPTY) {
constructor(connection: PlayConnection, entity: Entity, hand: Hands, sneaking: Boolean) : this(connection.world.entities.getId(entity)!!, hand, sneaking)
override fun write(buffer: PlayOutByteBuffer) {
super.write(buffer)
if (buffer.versionId >= ProtocolVersions.V_14W32A) {
if (buffer.versionId >= ProtocolVersions.V_15W31A) {
buffer.writeVarInt(hand.ordinal)
}
if (buffer.versionId >= ProtocolVersions.V_1_16_PRE3) {
buffer.writeBoolean(sneaking)
}
}
}
override fun log(reducedLog: Boolean) {
Log.log(LogMessageType.NETWORK_PACKETS_OUT, LogLevels.VERBOSE) { "Entity interaction (entityId=$entityId, hand=$hand, sneaking=$sneaking)" }
}
}

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger * 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 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.
* *
@ -13,41 +13,33 @@
package de.bixilon.minosoft.protocol.packets.c2s.play.entity.interact package de.bixilon.minosoft.protocol.packets.c2s.play.entity.interact
import de.bixilon.minosoft.data.entities.entities.Entity import de.bixilon.minosoft.protocol.packets.c2s.PlayC2SPacket
import de.bixilon.minosoft.data.player.Hands
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
import de.bixilon.minosoft.protocol.protocol.PlayOutByteBuffer import de.bixilon.minosoft.protocol.protocol.PlayOutByteBuffer
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
@LoadPacket(parent = true) abstract class EntityInteractC2SP(
class EntityInteractC2SP( val entityId: Int,
entityId: Int, val action: EntityInteractionActions,
val hand: Hands, ) : PlayC2SPacket {
override val sneaking: Boolean, abstract val sneaking: Boolean
) : BaseInteractEntityC2SP(entityId, EntityInteractionActions.INTERACT) {
constructor(connection: PlayConnection, entity: Entity, hand: Hands, sneaking: Boolean) : this(connection.world.entities.getId(entity)!!, hand, sneaking)
override fun write(buffer: PlayOutByteBuffer) { override fun write(buffer: PlayOutByteBuffer) {
super.write(buffer) buffer.writeVarInt(entityId)
if (buffer.versionId >= ProtocolVersions.V_14W32A) { val realAction = if (buffer.versionId < ProtocolVersions.V_14W32A && this.action == EntityInteractionActions.POSITION) {
if (buffer.versionId >= ProtocolVersions.V_15W31A) { EntityInteractionActions.EMPTY
buffer.writeVarInt(hand.ordinal) } else {
} action
if (buffer.versionId >= ProtocolVersions.V_1_16_PRE3) {
buffer.writeBoolean(sneaking)
}
} }
buffer.writeVarInt(realAction.ordinal)
} }
override fun log(reducedLog: Boolean) {
Log.log(LogMessageType.NETWORK_PACKETS_OUT, LogLevels.VERBOSE) { "Entity interaction (entityId=$entityId, hand=$hand, sneaking=$sneaking)" } enum class EntityInteractionActions {
EMPTY,
ATTACK,
POSITION,
;
} }
} }

View File

@ -25,12 +25,12 @@ import de.bixilon.minosoft.util.logging.LogMessageType
import glm_.vec3.Vec3 import glm_.vec3.Vec3
@LoadPacket(parent = true) @LoadPacket(parent = true)
class EntityInteractAtC2SP( class EntityInteractPositionC2SP(
entityId: Int, entityId: Int,
val position: Vec3, val position: Vec3,
val hand: Hands, val hand: Hands,
override val sneaking: Boolean, override val sneaking: Boolean,
) : BaseInteractEntityC2SP(entityId, EntityInteractionActions.INTERACT_AT) { ) : EntityInteractC2SP(entityId, EntityInteractionActions.POSITION) {
constructor(connection: PlayConnection, entity: Entity, position: Vec3, hand: Hands, sneaking: Boolean) : this(connection.world.entities.getId(entity)!!, position, hand, sneaking) constructor(connection: PlayConnection, entity: Entity, position: Vec3, hand: Hands, sneaking: Boolean) : this(connection.world.entities.getId(entity)!!, position, hand, sneaking)

View File

@ -153,9 +153,9 @@ object PacketTypeRegistry {
c2sClassMap[c2sClass] = type c2sClassMap[c2sClass] = type
c2sStateMap.synchronizedGetOrPut(annotation.state) { mutableMapOf() }.put(name, type)?.let { throw IllegalStateException("Packet already mapped: $it (name=$name)") } c2sStateMap.synchronizedGetOrPut(annotation.state) { mutableMapOf() }.put(name, type)?.let { throw IllegalStateException("Packet already mapped: $it (name=$name)") }
if (parentClass != null && parentClass != c2sClass) { if (parentClass != null && parentClass != c2sClass) {
val parentType = C2SPacketType(annotation.state, parentClass.unsafeCast(), annotation) val parentType = c2sClassMap.synchronizedGetOrPut(parentClass.unsafeCast()) { C2SPacketType(annotation.state, parentClass.unsafeCast(), annotation) }
c2sClassMap[parentClass.unsafeCast()] = parentType c2sClassMap[parentClass.unsafeCast()] = parentType
c2sStateMap[annotation.state]!!.putIfAbsent(parentClass.getPacketName(null), type) c2sStateMap[annotation.state]!!.putIfAbsent(parentClass.getPacketName(null), parentType)
} }
} }
} }