Skip to content

Commit

Permalink
fix: climbable being removed in initial packet due to caching emptyCl…
Browse files Browse the repository at this point in the history
…imbableTagMap
  • Loading branch information
Boy0000 committed Jul 29, 2024
1 parent dff3c88 commit cf7ac90
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 26 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group=com.mineinabyss
version=0.23
idofrontVersion=0.24.15
idofrontVersion=0.24.16
14 changes: 3 additions & 11 deletions src/main/kotlin/com/mineinabyss/staminaclimb/StaminaClimbPlugin.kt
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
package com.mineinabyss.staminaclimb

import com.github.shynixn.mccoroutine.bukkit.launch
import com.mineinabyss.geary.autoscan.autoscan
import com.mineinabyss.geary.modules.geary
import com.mineinabyss.idofront.di.DI
import com.mineinabyss.idofront.nms.interceptClientbound
import com.mineinabyss.idofront.plugin.listeners
import com.mineinabyss.idofront.time.ticks
import com.mineinabyss.staminaclimb.climbing.ClimbBehaviour
import com.mineinabyss.staminaclimb.climbing.ClimbBehaviour.stopClimbing
import com.mineinabyss.staminaclimb.modules.StaminaClimbModule
import com.mineinabyss.staminaclimb.modules.StaminaPaperModule
import com.mineinabyss.staminaclimb.modules.stamina
import com.mineinabyss.staminaclimb.nms.Tags
import com.mineinabyss.staminaclimb.nms.Tags.networkPayload
import com.mineinabyss.staminaclimb.nms.Tags.tags
import com.mineinabyss.staminaclimb.stamina.StaminaBar
import com.mineinabyss.staminaclimb.stamina.StaminaBar.registerBar
import com.mineinabyss.staminaclimb.stamina.StaminaTask
import it.unimi.dsi.fastutil.ints.IntList
import net.minecraft.core.registries.Registries
import net.minecraft.network.protocol.Packet
import net.minecraft.network.protocol.common.ClientboundUpdateTagsPacket
import net.minecraft.resources.ResourceLocation
import net.minecraft.tags.BlockTags
import kotlinx.coroutines.delay
import org.bukkit.Bukkit
import org.bukkit.entity.Player
import org.bukkit.plugin.java.JavaPlugin

/** A reference to the StaminaClimb plugin */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ import com.mineinabyss.idofront.messaging.info
import com.mineinabyss.idofront.messaging.success
import com.mineinabyss.staminaclimb.modules.stamina
import com.mineinabyss.staminaclimb.nms.Tags
import net.minecraft.core.Registry
import net.minecraft.core.registries.BuiltInRegistries
import net.minecraft.tags.BlockTags
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.command.TabCompleter
import kotlin.jvm.optionals.getOrNull

class StaminaCommands : IdofrontCommandExecutor(), TabCompleter {
override val commands = commands(stamina.plugin) {
Expand Down
16 changes: 6 additions & 10 deletions src/main/kotlin/com/mineinabyss/staminaclimb/nms/Tags.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.mineinabyss.staminaclimb.nms

import com.mineinabyss.idofront.nms.interceptClientbound
import com.mineinabyss.idofront.nms.networkPayload
import com.mineinabyss.idofront.nms.tags
import com.mineinabyss.staminaclimb.modules.stamina
import it.unimi.dsi.fastutil.ints.IntList
import net.minecraft.core.registries.Registries
Expand Down Expand Up @@ -28,18 +30,17 @@ object Tags {

stamina.initialTags.putAll(packet.tags)
packet.tags.entries.map { registryEntry ->
if (registryEntry.key == Registries.BLOCK) {
registryEntry.key to if (registryEntry.key == Registries.BLOCK) {
val tags = registryEntry.value.tags().map { tag ->
tag.key to when (tag.key) {
BlockTags.CLIMBABLE.location, BlockTags.FALL_DAMAGE_RESETTING.location -> IntList.of()
else -> tag.value
}
}.toMap()
registryEntry.setValue(tags.networkPayload())
}
registryEntry
tags.networkPayload()
} else registryEntry.value
}.forEach {
stamina.disabledClimbingTags[it.key] = it.value
stamina.disabledClimbingTags[it.first] = it.second
}

return@interceptClientbound packet
Expand All @@ -59,9 +60,4 @@ object Tags {
(player as CraftPlayer).handle.connection.send(ClientboundUpdateTagsPacket(stamina.disabledClimbingTags))
}

private val tagsField = NetworkPayload::class.java.getDeclaredField("tags").also { it.isAccessible = true }
private val payloadConstructor = NetworkPayload::class.java.declaredConstructors.first().also { it.isAccessible = true }
fun NetworkPayload.tags() = (tagsField.get(this) as Map<ResourceLocation, IntList>).toMutableMap()
fun Map<ResourceLocation, IntList>.networkPayload() = payloadConstructor.newInstance(this) as NetworkPayload

}

0 comments on commit cf7ac90

Please sign in to comment.