Step assist is now switchable

This commit is contained in:
DBotThePony 2022-09-25 15:42:43 +07:00
parent b89d59358c
commit 25a1c90012
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 36 additions and 2 deletions

View File

@ -468,6 +468,7 @@ private fun androidFeatures(provider: MatteryLanguageProvider) {
add(AndroidFeatures.NIGHT_VISION, "Night Vision")
add(AndroidFeatures.NANOBOTS_ARMOR, "Nanobots Armor")
add(AndroidFeatures.ITEM_MAGNET, "Item Magnet")
add(AndroidFeatures.STEP_ASSIST, "Step Assist")
}
}

View File

@ -1,15 +1,18 @@
package ru.dbotthepony.mc.otm.android.feature
import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.world.entity.ai.attributes.AttributeModifier
import net.minecraftforge.common.ForgeMod
import ru.dbotthepony.mc.otm.android.AndroidFeature
import ru.dbotthepony.mc.otm.android.AndroidSwitchableFeature
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.client.render.ResearchIcons
import ru.dbotthepony.mc.otm.registry.AndroidFeatures
import java.util.*
class StepAssistFeature(android: MatteryPlayerCapability) : AndroidFeature(AndroidFeatures.EXTENDED_REACH, android) {
class StepAssistFeature(android: MatteryPlayerCapability) : AndroidSwitchableFeature(AndroidFeatures.STEP_ASSIST, android) {
override fun applyModifiers() {
if (!ForgeMod.STEP_HEIGHT_ADDITION.isPresent)
if (!ForgeMod.STEP_HEIGHT_ADDITION.isPresent || !isActive)
return
val reach = ply.getAttribute(ForgeMod.STEP_HEIGHT_ADDITION.get()) ?: return
@ -25,6 +28,36 @@ class StepAssistFeature(android: MatteryPlayerCapability) : AndroidFeature(Andro
ply.getAttribute(ForgeMod.STEP_HEIGHT_ADDITION.get())?.removePermanentModifier(MODIFIER_ID)
}
private var isSteppingCarefully = false
private fun sharedTick() {
if (isActive) {
if (isSteppingCarefully != ply.isSteppingCarefully) {
isSteppingCarefully = ply.isSteppingCarefully
if (isSteppingCarefully) {
removeModifiers()
} else {
applyModifiers()
}
}
}
}
override fun tickClient() {
super.tickClient()
sharedTick()
}
override fun tickServer() {
super.tickServer()
sharedTick()
}
override fun renderIcon(stack: PoseStack, x: Float, y: Float, width: Float, height: Float) {
ResearchIcons.ICON_STEP_ASSIST.render(stack, x, y, width, height)
}
companion object {
private val MODIFIER_ID = UUID.fromString("4a3fae46-47a8-a03f-857d-f5c2b2c8f2f4")
}