Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/block action packet #91

Merged
merged 2 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dockyard.version=0.7.14
dockyard.version=0.7.15
kotlin.code.style=official
9 changes: 6 additions & 3 deletions src/main/kotlin/io/github/dockyardmc/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import io.github.dockyardmc.commands.IntArgument
import io.github.dockyardmc.commands.PlayerArgument
import io.github.dockyardmc.commands.simpleSuggestion
import io.github.dockyardmc.datagen.EventsDocumentationGenerator
import io.github.dockyardmc.events.Events
import io.github.dockyardmc.events.PlayerJoinEvent
import io.github.dockyardmc.events.PlayerLeaveEvent
import io.github.dockyardmc.events.*
import io.github.dockyardmc.extentions.broadcastMessage
import io.github.dockyardmc.inventory.give
import io.github.dockyardmc.item.ItemRarity
import io.github.dockyardmc.item.ItemStack
import io.github.dockyardmc.player.Player
import io.github.dockyardmc.player.systems.GameMode
import io.github.dockyardmc.registry.Blocks
import io.github.dockyardmc.registry.Items
Expand Down Expand Up @@ -46,6 +45,10 @@ fun main(args: Array<String>) {
}
}

Events.on<PlayerBlockRightClickEvent> {
it.player.playChestAnimation(it.location, Player.ChestAnimation.OPEN)
}

Events.on<PlayerJoinEvent> {
val player = it.player

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,4 +521,8 @@ fun ByteBuf.readItemHolder(): Item {
} else {
return ItemRegistry.getByProtocolId(type - 1)
}
}

fun ByteBuf.writeByte(byte: Byte) {
this.writeByte(byte.toInt())
}
10 changes: 9 additions & 1 deletion src/main/kotlin/io/github/dockyardmc/player/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ class Player(

fun respawn(isBecauseDeath: Boolean = false) {


sendPacket(ClientboundRespawnPacket(this, ClientboundRespawnPacket.RespawnDataKept.KEEP_ALL))
location = this.world.defaultSpawnLocation

Expand Down Expand Up @@ -476,6 +475,15 @@ class Player(
this.isDigging = false
}

fun playChestAnimation(chestLocation: Location, animation: ChestAnimation) {
sendPacket(ClientboundBlockActionPacket(chestLocation, 1, animation.ordinal.toByte(), Blocks.CHEST))
}

enum class ChestAnimation {
CLOSE,
OPEN
}

override fun dispose() {
decoupledViewSystemScheduler.dispose()
super.dispose()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.github.dockyardmc.protocol.packets.play.clientbound

import io.github.dockyardmc.extentions.writeByte
import io.github.dockyardmc.extentions.writeVarInt
import io.github.dockyardmc.location.Location
import io.github.dockyardmc.location.writeBlockPosition
import io.github.dockyardmc.protocol.packets.ClientboundPacket
import io.github.dockyardmc.registry.registries.RegistryBlock

class ClientboundBlockActionPacket(val location: Location, val blockAction: Byte, val actionParameter: Byte, val blockType: RegistryBlock): ClientboundPacket() {

init {
data.writeBlockPosition(location)
data.writeByte(blockAction)
data.writeByte(actionParameter)
data.writeVarInt(blockType.getProtocolId())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ object ClientPacketRegistry : PacketRegistry() {
addPlay(ClientboundAcknowledgeBlockChangePacket::class)
skipPlay("Block break animation")
skipPlay("Block entity data")
skipPlay("Block action")
addPlay(ClientboundBlockActionPacket::class)
skipPlay("Block change")
addPlay(ClientboundBossbarPacket::class)
addPlay(ClientboundChangeDifficultyPacket::class)
Expand Down
Loading