Skip to content

Commit

Permalink
feat: 1.20.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jan 22, 2024
1 parent d8f3e93 commit d18c12a
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 23 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ plugins {
repositories {
maven("https://repo.mineinabyss.com/snapshots")
maven("https://jitpack.io")
mavenLocal()
}

dependencies {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group=com.mineinabyss
version=0.21
idofrontVersion=0.20.6
version=0.22
idofrontVersion=0.21.5
4 changes: 2 additions & 2 deletions gradle/staminaLibs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
geary = "0.27.0"
bonehurtingjuice = "1.10.0"
geary = "0.29.0"
bonehurtingjuice = "1.10.1"

[libraries]
geary-papermc = { module = "com.mineinabyss:geary-papermc", version.ref = "geary" }
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/com/mineinabyss/staminaclimb/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.mineinabyss.staminaclimb.component.StaminaModifier
import com.mineinabyss.staminaclimb.modules.stamina
import com.mineinabyss.staminaclimb.stamina.StaminaBar
import org.bukkit.Material
import org.bukkit.Tag
import org.bukkit.entity.Player
import org.bukkit.inventory.EquipmentSlot
import java.util.*
Expand Down Expand Up @@ -115,3 +116,5 @@ inline fun inCube(
var Player.climbEnabled: Boolean
get() = StaminaBar.climbEnabled(this)
set(enable) = StaminaBar.setClimbEnabled(this, enable)

val Player.isInClimbable get() = location.block.type in Tag.CLIMBABLE.values
12 changes: 12 additions & 0 deletions src/main/kotlin/com/mineinabyss/staminaclimb/StaminaCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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.tags.BlockTags
import org.bukkit.command.Command
import org.bukkit.command.CommandSender
import org.bukkit.command.TabCompleter
Expand All @@ -17,6 +18,7 @@ class StaminaCommands : IdofrontCommandExecutor(), TabCompleter {
playerAction {
player.climbEnabled = !player.climbEnabled
if (player.climbEnabled) Tags.enableClimb(player)
else Tags.disableClimb(player)
player.info("Stamina and climbing system: ${if (player.climbEnabled) "ON" else "OFF"}!")
}
}
Expand All @@ -27,6 +29,16 @@ class StaminaCommands : IdofrontCommandExecutor(), TabCompleter {
sender.success("Config has been reloaded!")
}
}
"tags" {
action {
stamina.emptyClimbableMap.entries.find { it.key == BlockTags.FALL_DAMAGE_RESETTING.location }?.let {
sender.info("Fall damage resetting tag: ${it.value}")
}
stamina.normalClimbableMap.entries.find { it.key == BlockTags.CLIMBABLE.location }?.let {
sender.info("Climbable tag: ${it.value}")
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
package com.mineinabyss.staminaclimb.climbing

import com.mineinabyss.idofront.messaging.broadcast
import com.mineinabyss.staminaclimb.*
import com.mineinabyss.staminaclimb.modules.stamina
import com.mineinabyss.staminaclimb.stamina.StaminaBar
import com.mineinabyss.staminaclimb.stamina.removeProgress
import net.minecraft.world.level.block.LadderBlock
import org.bukkit.GameMode
import org.bukkit.Material
import org.bukkit.Tag
import org.bukkit.block.BlockFace
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.Listener
import org.bukkit.event.block.Action
import org.bukkit.event.block.BlockBreakEvent
import org.bukkit.event.block.BlockPlaceEvent
import org.bukkit.event.entity.EntityDamageEvent
import org.bukkit.event.player.PlayerAnimationEvent
import org.bukkit.event.player.PlayerInteractEvent
import org.bukkit.event.player.PlayerMoveEvent
import org.bukkit.inventory.EquipmentSlot
import org.bukkit.util.Vector
import org.cultofclang.bonehurtingjuice.events.BoneHurtDamageEvent
import org.cultofclang.bonehurtingjuice.hurtBones
import java.util.*
import java.util.concurrent.ConcurrentHashMap

Expand All @@ -35,17 +44,35 @@ object ClimbBehaviour : Listener {
isClimbing.remove(uuid)
}

private val climbableMap = mutableMapOf<UUID, Float>()
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
fun PlayerMoveEvent.onScaleDownClimbable() {
if (!hasExplicitlyChangedBlock() || !player.isInClimbable) return

val block = player.location.block
val increase = if (block.type == Material.SCAFFOLDING || !player.uniqueId.canClimb) 1 else 0
climbableMap.compute(player.uniqueId) { _, v -> (v ?: 0).toFloat() + increase }
if (block.getRelative(BlockFace.DOWN).type in Tag.CLIMBABLE.values) return
player.hurtBones(climbableMap[player.uniqueId] ?: 0f)
climbableMap.remove(player.uniqueId)
}

@EventHandler
fun EntityDamageEvent.onClimbableDamage() {
broadcast(cause.name + ": " + isCancelled)
}

@EventHandler
fun BlockPlaceEvent.onBlockPlace() {
val uuid = player.uniqueId
if (!player.isSneaking && uuid.isClimbing) isCancelled = true
if (cooldown.containsKey(uuid)) uuid.climbCooldown = conf.walljumpCooldown
if (uuid in cooldown) uuid.climbCooldown = conf.walljumpCooldown
}

@EventHandler
fun BlockBreakEvent.onBlockBreak() {
val uuid = player.uniqueId
if (cooldown.containsKey(uuid)) uuid.climbCooldown = conf.walljumpCooldown
if (uuid in cooldown) uuid.climbCooldown = conf.walljumpCooldown
}

@EventHandler
Expand All @@ -54,7 +81,7 @@ object ClimbBehaviour : Listener {
val velocity = player.velocity

//if sneaking, don't climb, but do climb if player is also falling
if (allowClimb(player) && rightClicked() && !isClimbing.containsKey(uuid)) {
if (allowClimb(player) && rightClicked() && uuid !in isClimbing) {
val bossBar = StaminaBar.registeredBars[uuid] ?: return
//remove stamina progress based on how long the player's already fallen
bossBar.removeProgress(player.fallDistance / 15f)
Expand Down Expand Up @@ -85,7 +112,7 @@ object ClimbBehaviour : Listener {
val uuid = player.uniqueId
//when isClimbing is false, it means player can still do the jump, once it's actually removed from the hashmap, that's when we can't climb
//don't even ask ok
if (allowClimb(player) && isClimbing.containsKey(uuid)) {
if (allowClimb(player) && uuid in isClimbing) {
//set a cooldown for player not to be able to wall jump right away
uuid.climbCooldown = conf.walljumpCooldown
val bossBar = StaminaBar.registeredBars[uuid] ?: return
Expand Down
31 changes: 21 additions & 10 deletions src/main/kotlin/com/mineinabyss/staminaclimb/nms/Tags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import it.unimi.dsi.fastutil.ints.IntList
import net.minecraft.core.registries.BuiltInRegistries
import net.minecraft.core.registries.Registries
import net.minecraft.network.protocol.common.ClientboundUpdateTagsPacket
import net.minecraft.network.protocol.game.ServerboundEntityTagQuery
import net.minecraft.resources.ResourceLocation
import net.minecraft.tags.BlockTags
import net.minecraft.tags.TagNetworkSerialization.NetworkPayload
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer
import org.bukkit.entity.Player

object Tags {
Expand All @@ -23,18 +24,27 @@ object Tags {
fun enableClimb(player: Player) {
if (player !in disabledPlayers) return
disabledPlayers.remove(player)
val packet =
ClientboundUpdateTagsPacket(mapOf(Registries.BLOCK to createPayload(stamina.normalClimbableMap)))
(player as CraftPlayer).handle.connection.send(packet)
(player as CraftPlayer).handle.connection.send(updateTagPacket(true))
}

fun disableClimb(player: Player) {
if (player in disabledPlayers) return
disabledPlayers.add(player)

val packet =
ClientboundUpdateTagsPacket(mapOf(Registries.BLOCK to createPayload(stamina.emptyClimbableMap)))
(player as CraftPlayer).handle.connection.send(packet)
(player as CraftPlayer).handle.connection.send(updateTagPacket(false))
}

private fun updateTagPacket(enable: Boolean): ClientboundUpdateTagsPacket {
return ClientboundUpdateTagsPacket(
mapOf(
Registries.BLOCK to createPayload(
when (enable) {
true -> stamina.normalClimbableMap
false -> stamina.emptyClimbableMap
}
)
)
)
}

fun emptyFallDamageResetTag(player: Player): Map<ResourceLocation, IntArrayList> {
Expand All @@ -60,9 +70,10 @@ object Tags {
return BuiltInRegistries.BLOCK.tags.map { pair ->
pair.first.location to IntArrayList(pair.second.size()).apply {
// If the tag is CLIMBABLE, don't add any blocks to the list
if (pair.first.location == BlockTags.CLIMBABLE.location) return@apply
if (pair.first.location == BlockTags.FALL_DAMAGE_RESETTING.location) return@apply
pair.second.forEach { add(BuiltInRegistries.BLOCK.getId(it.value())) }
when (pair.first.location) {
BlockTags.CLIMBABLE.location, BlockTags.FALL_DAMAGE_RESETTING.location -> return@apply
else -> pair.second.forEach { add(BuiltInRegistries.BLOCK.getId(it.value())) }
}
}
}.toList().toMap()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.bukkit.Bukkit
import org.bukkit.GameMode.ADVENTURE
import org.bukkit.GameMode.SURVIVAL
import org.bukkit.Location
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class StaminaTask : BukkitRunnable() {

StaminaBar.forEachBar { player, uuid, bar ->
val progress = bar.progress()
val onClimbable: Boolean = Tag.CLIMBABLE.isTagged(player.location.block.type)

if (player.gameMode == GameMode.CREATIVE || player.gameMode == GameMode.SPECTATOR) {
StaminaBar.unregisterBar(uuid)
Expand All @@ -45,7 +44,7 @@ class StaminaTask : BukkitRunnable() {
bar.addProgress(
if (player.location.apply { y -= 0.0625 }.block.isSolid)
conf.staminaRegen
else if (!onClimbable) conf.staminaRegenInAir else 0f
else if (!player.isInClimbable) conf.staminaRegenInAir else 0f
)

if (progress <= conf.barRed) { //Changing bar colors and effects on player depending on its progress
Expand All @@ -62,7 +61,7 @@ class StaminaTask : BukkitRunnable() {
)
} else if (progress < 1 && !uuid.canClimb) {
bar.color(BossBar.Color.RED) //Keep Stamina Bar red even in yellow zone while it's regenerating
} else if ((uuid.isClimbing || onClimbable) && progress <= conf.barBlink2) {
} else if ((uuid.isClimbing || player.isInClimbable) && progress <= conf.barBlink2) {
val deltaTime = System.currentTimeMillis() - lastTime
lastTime = System.currentTimeMillis()
if (timeSinceLastColorFlip < conf.barBlinkSpeed2)
Expand All @@ -71,7 +70,7 @@ class StaminaTask : BukkitRunnable() {
flipColor(bar)
timeSinceLastColorFlip = 0
}
} else if ((uuid.isClimbing || onClimbable) && progress <= conf.barBlink1) {
} else if ((uuid.isClimbing || player.isInClimbable) && progress <= conf.barBlink1) {
val deltaTime = System.currentTimeMillis() - lastTime
lastTime = System.currentTimeMillis()
if (timeSinceLastColorFlip < conf.barBlinkSpeed1)
Expand Down

0 comments on commit d18c12a

Please sign in to comment.