mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 20:05:02 -04:00
rename entity interact packets, fix mapping of abstract c2s packets
This commit is contained in:
parent
5fd9442909
commit
b86740b8d0
@ -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.protocol.packets.c2s.play.PlayerActionC2SP
|
||||
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.EntityInteractC2SP
|
||||
import de.bixilon.minosoft.protocol.packets.c2s.play.entity.interact.EntityEmptyInteractC2SP
|
||||
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.move.PositionRotationC2SP
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
@ -108,7 +108,7 @@ class InteractInteractionHandler(
|
||||
fun interactEntityAt(target: EntityTarget, hand: Hands): InteractionResults {
|
||||
// used in armor stands
|
||||
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) {
|
||||
return InteractionResults.PASS
|
||||
@ -119,7 +119,7 @@ class InteractInteractionHandler(
|
||||
|
||||
fun interactEntity(target: EntityTarget, hand: Hands): InteractionResults {
|
||||
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) {
|
||||
return InteractionResults.PASS
|
||||
|
@ -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,
|
||||
|
||||
}
|
||||
}
|
@ -26,7 +26,7 @@ import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
class EntityAttackC2SP(
|
||||
entityId: Int,
|
||||
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)
|
||||
|
||||
|
@ -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)" }
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
@ -13,41 +13,33 @@
|
||||
|
||||
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.packets.c2s.PlayC2SPacket
|
||||
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 EntityInteractC2SP(
|
||||
entityId: Int,
|
||||
val hand: Hands,
|
||||
override val sneaking: Boolean,
|
||||
) : BaseInteractEntityC2SP(entityId, EntityInteractionActions.INTERACT) {
|
||||
|
||||
constructor(connection: PlayConnection, entity: Entity, hand: Hands, sneaking: Boolean) : this(connection.world.entities.getId(entity)!!, hand, sneaking)
|
||||
abstract class EntityInteractC2SP(
|
||||
val entityId: Int,
|
||||
val action: EntityInteractionActions,
|
||||
) : PlayC2SPacket {
|
||||
abstract val sneaking: Boolean
|
||||
|
||||
override fun write(buffer: PlayOutByteBuffer) {
|
||||
super.write(buffer)
|
||||
buffer.writeVarInt(entityId)
|
||||
|
||||
if (buffer.versionId >= ProtocolVersions.V_14W32A) {
|
||||
if (buffer.versionId >= ProtocolVersions.V_15W31A) {
|
||||
buffer.writeVarInt(hand.ordinal)
|
||||
val realAction = if (buffer.versionId < ProtocolVersions.V_14W32A && this.action == EntityInteractionActions.POSITION) {
|
||||
EntityInteractionActions.EMPTY
|
||||
} 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,
|
||||
;
|
||||
}
|
||||
}
|
||||
|
@ -25,12 +25,12 @@ import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
import glm_.vec3.Vec3
|
||||
|
||||
@LoadPacket(parent = true)
|
||||
class EntityInteractAtC2SP(
|
||||
class EntityInteractPositionC2SP(
|
||||
entityId: Int,
|
||||
val position: Vec3,
|
||||
val hand: Hands,
|
||||
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)
|
||||
|
@ -153,9 +153,9 @@ object PacketTypeRegistry {
|
||||
c2sClassMap[c2sClass] = type
|
||||
c2sStateMap.synchronizedGetOrPut(annotation.state) { mutableMapOf() }.put(name, type)?.let { throw IllegalStateException("Packet already mapped: $it (name=$name)") }
|
||||
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
|
||||
c2sStateMap[annotation.state]!!.putIfAbsent(parentClass.getPacketName(null), type)
|
||||
c2sStateMap[annotation.state]!!.putIfAbsent(parentClass.getPacketName(null), parentType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user