This is stupid

This commit is contained in:
DBotThePony 2023-07-06 17:07:00 +07:00
parent f9a365b6dc
commit 311af4f8d9
Signed by: DBot
GPG Key ID: DCC23B5715498507
4 changed files with 30 additions and 5 deletions

View File

@ -160,6 +160,7 @@ public final class OverdriveThatMatters {
EVENT_BUS.addListener(EventPriority.NORMAL, MatteryPlayerCapability.Companion::onPlayerTick);
EVENT_BUS.addListener(EventPriority.NORMAL, MatteryPlayerCapability.Companion::isMobEffectApplicable);
EVENT_BUS.addListener(EventPriority.LOW, MatteryPlayerCapability.Companion::onHurtEvent);
EVENT_BUS.addListener(EventPriority.LOW, MatteryPlayerCapability.Companion::onAttackEvent);
EVENT_BUS.addGenericListener(Entity.class, EventPriority.NORMAL, MatteryPlayerCapability.Companion::onAttachCapabilityEvent);
EVENT_BUS.addListener(EventPriority.NORMAL, MatteryPlayerCapability.Companion::onPlayerChangeDimensionEvent);
EVENT_BUS.addListener(EventPriority.LOWEST, MatteryPlayerCapability.Companion::onPlayerDeath);

View File

@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.android
import it.unimi.dsi.fastutil.io.FastByteArrayOutputStream
import net.minecraft.nbt.CompoundTag
import net.minecraftforge.common.util.INBTSerializable
import net.minecraftforge.event.entity.living.LivingAttackEvent
import net.minecraftforge.event.entity.living.LivingHurtEvent
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
import ru.dbotthepony.mc.otm.core.nbt.set
@ -34,6 +35,7 @@ abstract class AndroidFeature(val type: AndroidFeatureType<*>, val android: Matt
open fun removeModifiers() {}
open fun onHurt(event: LivingHurtEvent) {}
open fun onAttack(event: LivingAttackEvent) {}
open fun collectNetworkPayload(): FastByteArrayOutputStream? {
return synchronizer.collectNetworkPayload()

View File

@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.android.feature
import net.minecraft.ChatFormatting
import net.minecraft.resources.ResourceLocation
import net.minecraft.server.level.ServerPlayer
import net.minecraftforge.event.entity.living.LivingAttackEvent
import net.minecraftforge.event.entity.living.LivingHurtEvent
import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.android.AndroidFeature
@ -23,13 +24,10 @@ class FallDampenersFeature(capability: MatteryPlayerCapability) : AndroidFeature
val flat = (AndroidConfig.FALL_DAMAGE_REDUCTION_PER_LEVEL_F * (level + 1)).toFloat().coerceIn(0f, Float.MAX_VALUE)
val old = event.amount
event.amount = ((event.amount - flat) * (1f - reduction)).coerceAtLeast(0f)
if (reduction >= 1f || event.amount <= flat) {
if (event.amount == 0f) {
event.isCanceled = true
event.amount = 0f
} else {
event.amount -= flat
event.amount *= (1f - reduction)
}
if (ply is ServerPlayer && ply.health > event.amount && ply.health <= old) {
@ -37,4 +35,15 @@ class FallDampenersFeature(capability: MatteryPlayerCapability) : AndroidFeature
}
}
}
override fun onAttack(event: LivingAttackEvent) {
if (event.source.isFall) {
val reduction = (AndroidConfig.FALL_DAMAGE_REDUCTION_PER_LEVEL_P * (level + 1)).toFloat().coerceIn(0f, 1f)
val flat = (AndroidConfig.FALL_DAMAGE_REDUCTION_PER_LEVEL_F * (level + 1)).toFloat().coerceIn(0f, Float.MAX_VALUE)
if (reduction >= 1f || event.amount <= flat) {
event.isCanceled = true
}
}
}
}

View File

@ -42,6 +42,7 @@ import net.minecraftforge.event.AttachCapabilitiesEvent
import net.minecraftforge.event.RegisterCommandsEvent
import net.minecraftforge.event.TickEvent
import net.minecraftforge.event.TickEvent.PlayerTickEvent
import net.minecraftforge.event.entity.living.LivingAttackEvent
import net.minecraftforge.event.entity.living.LivingDeathEvent
import net.minecraftforge.event.entity.living.LivingHurtEvent
import net.minecraftforge.event.entity.living.MobEffectEvent
@ -653,6 +654,14 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
}
}
internal fun onAttack(event: LivingAttackEvent) {
if (isAndroid) {
for (feature in featureMap.values) {
feature.onAttack(event)
}
}
}
internal fun <T : AndroidFeature> computeIfAbsent(feature: AndroidFeatureType<T>): T {
return getFeature(feature) ?: addFeature(feature)
}
@ -1307,6 +1316,10 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
event.entity.getCapability(MatteryCapability.MATTERY_PLAYER).ifPresentK { it.onHurt(event) }
}
fun onAttackEvent(event: LivingAttackEvent) {
event.entity.getCapability(MatteryCapability.MATTERY_PLAYER).ifPresentK { it.onAttack(event) }
}
val CAPABILITY_LOCATION = ResourceLocation(OverdriveThatMatters.MOD_ID, "player")
fun onAttachCapabilityEvent(event: AttachCapabilitiesEvent<Entity>) {