Skip to content

Commit

Permalink
refactor: remove methods to send hitbox-updates to all players
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jan 30, 2024
1 parent 91f2e93 commit a4260e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,6 @@ object BlockyFurnitures {
return true
}

/**
* Updates the hitbox & light packets of a furniture entity.
*/
fun updateFurniturePackets(furniture: ItemDisplay) {
FurniturePacketHelpers.sendInteractionEntityPacket(furniture)
FurniturePacketHelpers.sendCollisionHitboxPacket(furniture)
FurniturePacketHelpers.sendLightPacket(furniture)
}

/**
* Updates the hitbox & light packets of a furniture entity for a given player.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ object FurniturePacketHelpers {
const val INTERACTION_HEIGHT_ID = 9
const val ITEM_DISPLAY_ITEMSTACK_ID = 23

val collisionHitboxPosMap = mutableMapOf<FurnitureUUID, MutableSet<BlockPos>>()
val interactionHitboxIdMap = mutableSetOf<FurnitureInteractionHitboxIds>()
val interactionHitboxPacketMap = mutableMapOf<FurnitureUUID, MutableSet<FurnitureInteractionHitboxPacket>>()
val hitboxOutlineIdMap = mutableMapOf<FurnitureUUID, IntList>()
private val collisionHitboxPosMap = mutableMapOf<FurnitureUUID, MutableSet<BlockPos>>()
private val interactionHitboxIdMap = mutableSetOf<FurnitureInteractionHitboxIds>()
private val interactionHitboxPacketMap = mutableMapOf<FurnitureUUID, MutableSet<FurnitureInteractionHitboxPacket>>()
private val hitboxOutlineIdMap = mutableMapOf<FurnitureUUID, IntList>()
private val outlinePlayerMap = mutableMapOf<UUID, UUID>()

fun getBaseFurnitureFromInteractionEntity(id: Int) =
interactionHitboxIdMap.firstOrNull { id in it.entityIds }?.furniture
Expand Down Expand Up @@ -95,22 +96,6 @@ object FurniturePacketHelpers {
}
}

/**
* Sends a packet to show the interaction hitbox of the given furniture to all players in the world.
* @param furniture The furniture to show the interaction hitbox of.
*/
fun sendInteractionEntityPacket(furniture: ItemDisplay) {
// Don't send interactionEntity packet if modelengine furniture with hitbox
if (furniture.isModelEngineFurniture) {
val modelId = furniture.toGeary().get<BlockyModelEngine>()?.modelId ?: return
val blueprint = ModelEngineAPI.getBlueprint(modelId) ?: return
if (blueprint.mainHitbox != null || blueprint.subHitboxes.isNotEmpty()) return
}
furniture.world.players.forEach {
sendInteractionEntityPacket(furniture, it)
}
}

/**
* Sends a packet to show the interaction hitbox of the given furniture to the given player.
* @param furniture The furniture to show the interaction hitbox of.
Expand Down Expand Up @@ -176,14 +161,6 @@ object FurniturePacketHelpers {
PacketContainer.fromPacket(ClientboundRemoveEntitiesPacket(*entityIds.toIntArray())).sendTo(player)
}

fun sendHitboxOutlinePacket(furniture: ItemDisplay) {
furniture.world.players.forEach {
sendHitboxOutlinePacket(furniture, it)
}
}

val outlinePlayerMap = mutableMapOf<UUID, UUID>()

fun sendHitboxOutlinePacket(furniture: ItemDisplay, player: Player) {
if (outlinePlayerMap[player.uniqueId] == furniture.uniqueId) return
removeHitboxOutlinePacket(player)
Expand Down Expand Up @@ -232,15 +209,6 @@ object FurniturePacketHelpers {
outlinePlayerMap.remove(player.uniqueId)
}

/**
* Sends a packet to show the collision hitbox of the given furniture to all players in the world.
* @param baseEntity The furniture to show the collision hitbox of.
*/
fun sendCollisionHitboxPacket(baseEntity: ItemDisplay) {
baseEntity.world.players.forEach {
sendCollisionHitboxPacket(baseEntity, it)
}
}

/**
* Sends a packet to show the collision hitbox of the given furniture to the given player.
Expand Down Expand Up @@ -281,16 +249,6 @@ object FurniturePacketHelpers {
player.sendMultiBlockChange(positions)
}

/**
* Sends the light packets for this furniture to all players in the world
* @param baseEntity The furniture to send the light packets for
*/
fun sendLightPacket(baseEntity: ItemDisplay) {
baseEntity.world.players.forEach {
sendLightPacket(baseEntity, it)
}
}

/**
* Sends the light packets for this furniture to a specific player
* @param baseEntity The furniture to send the light packets for
Expand Down

0 comments on commit a4260e4

Please sign in to comment.