rename BlockBreak packet

This commit is contained in:
Bixilon 2021-10-31 10:10:03 +01:00
parent a3468c084d
commit e23b4a9312
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
9 changed files with 41 additions and 34 deletions

View File

@ -29,7 +29,7 @@ import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.modding.event.events.BlockBreakAckEvent
import de.bixilon.minosoft.modding.event.invoker.CallbackEventInvoker
import de.bixilon.minosoft.protocol.packets.c2s.play.ArmSwingC2SP
import de.bixilon.minosoft.protocol.packets.c2s.play.BlockBreakC2SP
import de.bixilon.minosoft.protocol.packets.c2s.play.PlayerActionC2SP
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.KUtil.synchronizedMapOf
import de.bixilon.minosoft.util.KUtil.toResourceLocation
@ -74,7 +74,7 @@ class LeftClickHandler(
private fun cancelDigging() {
breakPosition?.let {
connection.sendPacket(BlockBreakC2SP(BlockBreakC2SP.BreakType.CANCELLED_DIGGING, breakPosition, Directions.UP)) // ToDo: Direction?
connection.sendPacket(PlayerActionC2SP(PlayerActionC2SP.Actions.CANCELLED_DIGGING, breakPosition, Directions.UP)) // ToDo: Direction?
clearDigging()
}
}
@ -123,7 +123,7 @@ class LeftClickHandler(
if (breakPosition != null) {
return
}
connection.sendPacket(BlockBreakC2SP(BlockBreakC2SP.BreakType.START_DIGGING, raycastHit.blockPosition, raycastHit.hitDirection))
connection.sendPacket(PlayerActionC2SP(PlayerActionC2SP.Actions.START_DIGGING, raycastHit.blockPosition, raycastHit.hitDirection))
breakPosition = raycastHit.blockPosition
breakBlockState = raycastHit.blockState
@ -134,7 +134,7 @@ class LeftClickHandler(
}
fun finishDigging() {
connection.sendPacket(BlockBreakC2SP(BlockBreakC2SP.BreakType.FINISHED_DIGGING, raycastHit.blockPosition, raycastHit.hitDirection))
connection.sendPacket(PlayerActionC2SP(PlayerActionC2SP.Actions.FINISHED_DIGGING, raycastHit.blockPosition, raycastHit.hitDirection))
clearDigging()
connection.world.setBlockState(raycastHit.blockPosition, null)
@ -254,8 +254,8 @@ class LeftClickHandler(
))
connection.registerEvent(CallbackEventInvoker.of<BlockBreakAckEvent> {
when (it.breakType) {
BlockBreakC2SP.BreakType.START_DIGGING -> {
when (it.actions) {
PlayerActionC2SP.Actions.START_DIGGING -> {
if (it.successful) {
acknowledgedBreakStarts[it.blockPosition] = it.blockState
} else {
@ -265,7 +265,7 @@ class LeftClickHandler(
breakProgress = Double.NEGATIVE_INFINITY
}
}
BlockBreakC2SP.BreakType.FINISHED_DIGGING -> {
PlayerActionC2SP.Actions.FINISHED_DIGGING -> {
if (acknowledgedBreakStarts[it.blockPosition] == null) {
// start was not acknowledged, undoing
connection.world[it.blockPosition] = it.blockState

View File

@ -39,7 +39,7 @@ import de.bixilon.minosoft.gui.rendering.util.VecUtil.floor
import de.bixilon.minosoft.gui.rendering.util.VecUtil.getWorldOffset
import de.bixilon.minosoft.modding.event.invoker.CallbackEventInvoker
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.packets.c2s.play.BlockBreakC2SP
import de.bixilon.minosoft.protocol.packets.c2s.play.PlayerActionC2SP
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.util.KUtil.decide
import de.bixilon.minosoft.util.KUtil.toResourceLocation
@ -223,14 +223,14 @@ class Camera(
}
val type = if (stack) {
connection.player.inventory.getHotbarSlot()?.count = 0
BlockBreakC2SP.BreakType.DROP_ITEM_STACK
PlayerActionC2SP.Actions.DROP_ITEM_STACK
} else {
connection.player.inventory.getHotbarSlot()?.let {
it.count--
}
BlockBreakC2SP.BreakType.DROP_ITEM
PlayerActionC2SP.Actions.DROP_ITEM
}
connection.sendPacket(BlockBreakC2SP(type, connection.player.positionInfo.blockPosition))
connection.sendPacket(PlayerActionC2SP(type, connection.player.positionInfo.blockPosition))
lastDropPacketSent = time
}

View File

@ -15,7 +15,7 @@ package de.bixilon.minosoft.modding.event.events
import de.bixilon.minosoft.data.registries.blocks.BlockState
import de.bixilon.minosoft.modding.event.events.connection.play.PlayConnectionEvent
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.packets.c2s.play.BlockBreakC2SP
import de.bixilon.minosoft.protocol.packets.c2s.play.PlayerActionC2SP
import de.bixilon.minosoft.protocol.packets.s2c.play.BlockBreakAckS2CP
import glm_.vec3.Vec3i
@ -23,10 +23,10 @@ class BlockBreakAckEvent(
connection: PlayConnection,
val blockPosition: Vec3i,
val blockState: BlockState?,
val breakType: BlockBreakC2SP.BreakType,
val actions: PlayerActionC2SP.Actions,
val successful: Boolean,
) : PlayConnectionEvent(connection) {
constructor(connection: PlayConnection, packet: BlockBreakAckS2CP) : this(connection, packet.blockPosition, packet.blockState, packet.breakType, packet.successful)
constructor(connection: PlayConnection, packet: BlockBreakAckS2CP) : this(connection, packet.blockPosition, packet.blockState, packet.actions, packet.successful)
}

View File

@ -21,10 +21,10 @@ import glm_.vec3.Vec3i
class BlockBreakAnimationEvent(
connection: PlayConnection,
initiator: EventInitiators,
val animationId: Int,
val entityId: Int,
val blockPosition: Vec3i,
val stage: Int,
) : PlayConnectionEvent(connection, initiator), CancelableEvent {
constructor(connection: PlayConnection, packet: BlockBreakAnimationS2CP) : this(connection, EventInitiators.SERVER, packet.animationId, packet.blockPosition, packet.stage)
constructor(connection: PlayConnection, packet: BlockBreakAnimationS2CP) : this(connection, EventInitiators.SERVER, packet.entityId, packet.blockPosition, packet.stage)
}

View File

@ -23,17 +23,17 @@ import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
import glm_.vec3.Vec3i
class BlockBreakC2SP(
val type: BreakType,
class PlayerActionC2SP(
val action: Actions,
val position: Vec3i?,
val direction: Directions? = null,
) : PlayC2SPacket {
override fun write(buffer: PlayOutByteBuffer) {
if (buffer.versionId < ProtocolVersions.V_15W31A) { // ToDo
buffer.writeByte(type.ordinal)
buffer.writeByte(action.ordinal)
} else {
buffer.writeVarInt(type.ordinal)
buffer.writeVarInt(action.ordinal)
}
if (buffer.versionId < ProtocolVersions.V_14W04A) {
buffer.writeByteBlockPosition(position)
@ -44,22 +44,26 @@ class BlockBreakC2SP(
}
override fun log() {
Log.log(LogMessageType.NETWORK_PACKETS_OUT, LogLevels.VERBOSE) { "Block break (type=$type, position=$position, direction=$direction)" }
Log.log(LogMessageType.NETWORK_PACKETS_OUT, LogLevels.VERBOSE) { "Player action (action=$action, position=$position, direction=$direction)" }
}
enum class BreakType {
enum class Actions {
START_DIGGING,
CANCELLED_DIGGING,
FINISHED_DIGGING,
DROP_ITEM_STACK,
DROP_ITEM,
SHOOT_ARROW_FINISH_EATING,
/**
* e.g. use a shield and then not use it anymore (or eat, shoot arrow, etc)
*/
RELEASE_ITEM,
SWAP_ITEMS_IN_HAND,
;
companion object : ValuesEnum<BreakType> {
override val VALUES: Array<BreakType> = values()
override val NAME_MAP: Map<String, BreakType> = KUtil.getEnumValues(VALUES)
companion object : ValuesEnum<Actions> {
override val VALUES: Array<Actions> = values()
override val NAME_MAP: Map<String, Actions> = KUtil.getEnumValues(VALUES)
}
}
}

View File

@ -15,7 +15,7 @@ package de.bixilon.minosoft.protocol.packets.s2c.play
import de.bixilon.minosoft.data.registries.blocks.BlockState
import de.bixilon.minosoft.modding.event.events.BlockBreakAckEvent
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.packets.c2s.play.BlockBreakC2SP.BreakType
import de.bixilon.minosoft.protocol.packets.c2s.play.PlayerActionC2SP.Actions
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.util.logging.Log
@ -26,11 +26,11 @@ import glm_.vec3.Vec3i
class BlockBreakAckS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
val blockPosition: Vec3i = buffer.readBlockPosition()
val blockState: BlockState? = buffer.connection.registries.blockStateRegistry[buffer.readVarInt()]
val breakType: BreakType = BreakType[buffer.readVarInt()]
val actions: Actions = Actions[buffer.readVarInt()]
val successful: Boolean = buffer.readBoolean()
override fun handle(connection: PlayConnection) {
if (breakType == BreakType.FINISHED_DIGGING && !successful) {
if (actions == Actions.FINISHED_DIGGING && !successful) {
// never happens?
connection.world[blockPosition] = blockState
}
@ -38,6 +38,6 @@ class BlockBreakAckS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
}
override fun log() {
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Block break acknowledge (blockPosition=$blockPosition, blockState=$blockState, breakType=$breakType, successful=$successful)" }
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Block break acknowledge (blockPosition=$blockPosition, blockState=$blockState, actions=$actions, successful=$successful)" }
}
}

View File

@ -23,7 +23,10 @@ import de.bixilon.minosoft.util.logging.LogMessageType
import glm_.vec3.Vec3i
class BlockBreakAnimationS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
val animationId: Int = buffer.readVarInt()
/**
* Entity id of the entity who is breaking the block
*/
val entityId: Int = buffer.readVarInt()
var blockPosition: Vec3i = if (buffer.versionId < ProtocolVersions.V_14W03B) {
buffer.readIntBlockPosition()
} else {
@ -46,6 +49,6 @@ class BlockBreakAnimationS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
}
override fun log() {
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Block break animation (animationId=$animationId, blockPosition=$blockPosition, stage=$stage" }
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Block break animation (entityId=$entityId, blockPosition=$blockPosition, stage=$stage)" }
}
}

View File

@ -84,7 +84,7 @@ class PacketTypes {
PLAY_PICK_ITEM,
PLAY_CRAFTING_RECIPE_REQUEST(CraftingRecipeRequestC2SP::class.java),
PLAY_FLY_TOGGLE(FlyToggleC2SP::class.java),
PLAY_PLAYER_DIGGING(BlockBreakC2SP::class.java),
PLAY_PLAYER_ACTION(PlayerActionC2SP::class.java),
PLAY_ENTITY_ACTION(EntityActionC2SP::class.java),
PLAY_VEHICLE_STEER(VehicleSteerC2SP::class.java),
PLAY_RECIPE_BOOK_STATE(RecipeBookStateC2SP::class.java),

File diff suppressed because one or more lines are too long