Skip to content

Commit

Permalink
chore: Update protocolburrito, avoid NMS classes where possible now :)
Browse files Browse the repository at this point in the history
fix: scheduleSyncDelayedTask in a geary listener without saving data first throwing an error
  • Loading branch information
0ffz committed Mar 16, 2024
1 parent 9e8300e commit cc17d11
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ dependencies {

// Other plugins
compileOnly(idofrontLibs.minecraft.plugin.modelengine)
compileOnly(idofrontLibs.minecraft.plugin.protocollib)
compileOnly(idofrontLibs.minecraft.plugin.fawe.core)
compileOnly(idofrontLibs.minecraft.plugin.fawe.bukkit) { isTransitive = false }
compileOnly(idofrontLibs.minecraft.anvilgui)
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
gearyPaper = "0.29.12-dev.6"
guiy="0.9.3"
protocolburrito="0.9.0"
protocolburrito="0.10.0-dev.0"

[libraries]
geary-papermc = { module = "com.mineinabyss:geary-papermc", version.ref = "gearyPaper" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package com.mineinabyss.blocky.helpers

import com.comphenix.protocol.events.PacketContainer
import com.comphenix.protocol.wrappers.BlockPosition
import com.mineinabyss.blocky.api.BlockyFurnitures
import com.mineinabyss.blocky.api.BlockyFurnitures.isBlockyFurniture
import com.mineinabyss.blocky.api.BlockyFurnitures.isModelEngineFurniture
Expand Down Expand Up @@ -56,7 +57,7 @@ object FurniturePacketHelpers {
const val INTERACTION_HEIGHT_ID = 9
const val ITEM_DISPLAY_ITEMSTACK_ID = 23

private val collisionHitboxPosMap = mutableMapOf<FurnitureUUID, MutableSet<BlockPos>>()
private val collisionHitboxPosMap = mutableMapOf<FurnitureUUID, MutableSet<BlockPosition>>()
private val interactionHitboxIdMap = mutableSetOf<FurnitureInteractionHitboxIds>()
private val interactionHitboxPacketMap = mutableMapOf<FurnitureUUID, MutableSet<FurnitureInteractionHitboxPacket>>()
private val hitboxOutlineIdMap = mutableMapOf<FurnitureUUID, IntList>()
Expand All @@ -65,7 +66,7 @@ object FurniturePacketHelpers {
fun getBaseFurnitureFromInteractionEntity(id: Int) =
interactionHitboxIdMap.firstOrNull { id in it.entityIds }?.furniture

fun getBaseFurnitureFromCollisionHitbox(pos: BlockPos) =
fun getBaseFurnitureFromCollisionHitbox(pos: BlockPosition) =
collisionHitboxPosMap.entries.firstOrNull { pos in it.value }?.key?.toEntity() as? ItemDisplay

internal fun registerPacketListeners() {
Expand All @@ -86,7 +87,7 @@ object FurniturePacketHelpers {
// Cancelled so client doesn't remove the "Ghost Block"
onReceive<ServerboundUseItemOnPacketWrap> { wrap ->
Bukkit.getScheduler().callSyncMethod(blocky.plugin) {
getBaseFurnitureFromCollisionHitbox(wrap.blockHit.blockPos)?.let { baseFurniture ->
getBaseFurnitureFromCollisionHitbox(BlockPosition.getConverter().getSpecific(wrap.blockHit.blockPos))?.let { baseFurniture ->
val clickedRelativePosition = Vector(wrap.blockHit.location.x, wrap.blockHit.location.y, wrap.blockHit.location.z)
isCancelled = true

Expand Down Expand Up @@ -221,8 +222,8 @@ object FurniturePacketHelpers {
player.sendMultiBlockChange(positions)
positions.map { it.key.toBlock() }.forEach {
collisionHitboxPosMap.compute(baseEntity.uniqueId) { _, blockPos ->
blockPos?.plus(BlockPos(it.blockX(), it.blockY(), it.blockZ()))?.toMutableSet()
?: mutableSetOf(BlockPos(it.blockX(), it.blockY(), it.blockZ()))
blockPos?.plus(BlockPosition(it.blockX(), it.blockY(), it.blockZ()))?.toMutableSet()
?: mutableSetOf(BlockPosition(it.blockX(), it.blockY(), it.blockZ()))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mineinabyss.blocky.helpers

import com.comphenix.protocol.wrappers.BlockPosition
import com.destroystokyo.paper.MaterialTags
import com.jeff_media.customblockdata.CustomBlockData
import com.mineinabyss.blocky.api.BlockyBlocks
Expand Down Expand Up @@ -70,7 +71,7 @@ const val DEFAULT_FALL_PITCH = 0.75f

val Block.persistentDataContainer get() = customBlockData as PersistentDataContainer
val Block.customBlockData get() = CustomBlockData(this, blocky.plugin)
fun Block.toBlockPos() = BlockPos(this.x, this.y, this.z)
fun Block.toBlockPos() = BlockPosition(this.x, this.y, this.z)

internal infix fun <A, B, C> Pair<A, B>.to(that: C): Triple<A, B, C> = Triple(this.first, this.second, that)
internal inline fun <reified T> ItemStack.decode(): T? = this.itemMeta?.persistentDataContainer?.decode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ fun GearyModule.createFurnitureMEGModelSetter() = listener(
val meg by source.get<BlockyModelEngine>()
}
).exec {
// Save for scheduled task
val display = display
val furniture = furniture
val meg = meg
if (!Plugins.isEnabled("ModelEngine")) return@exec
val activeModel = ModelEngineAPI.createActiveModel(meg.modelId)
Bukkit.getScheduler().scheduleSyncDelayedTask(blocky.plugin, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ fun GearyModule.createFurnitureSeatSetter() = listener(
val seat by source.get<BlockySeat>()
}
).exec {
// Save for scheduled task
val display = display
val furniture = furniture
val seat = seat

val yaw = display.location.yaw
FurnitureHelpers.clearFurnitureSeats(display)
Bukkit.getScheduler().scheduleSyncDelayedTask(blocky.plugin, {
Expand Down

0 comments on commit cc17d11

Please sign in to comment.