Implement strength and agility scaling
This commit is contained in:
@@ -16,6 +16,8 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.event.level.BlockEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDamageEvent;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = AscendMod.MODID)
|
||||
public class ActivityEvents {
|
||||
@@ -54,7 +56,7 @@ public class ActivityEvents {
|
||||
public static void onPlayerDamaged(LivingHurtEvent event) {
|
||||
if (event.getEntity() instanceof Player player && !player.level().isClientSide) {
|
||||
player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
|
||||
int gain = Math.min((int) event.getAmount() * 2, 10);
|
||||
int gain = Math.min((int) event.getAmount() / 2, 10);
|
||||
stats.addAscendXP(gain);
|
||||
PlayerStatsProvider.sync(player);
|
||||
});
|
||||
@@ -203,4 +205,22 @@ public class ActivityEvents {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerDealsDamage(LivingDamageEvent event) {
|
||||
if (!(event.getSource().getEntity() instanceof Player player)) return;
|
||||
if (player.level().isClientSide) return;
|
||||
LivingEntity target = event.getEntity();
|
||||
player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
|
||||
int strength = stats.getAttributeLevel("strength");
|
||||
if (strength <= 0) return;
|
||||
float bypassFraction = Math.min(strength * 0.001f, 0.30f);
|
||||
int armor = target.getArmorValue();
|
||||
if (armor <= 0 || bypassFraction <= 0f) return;
|
||||
float baseDamage = event.getAmount();
|
||||
float armorFactor = (float) armor / (armor + 100.0f);
|
||||
float bonus = baseDamage * armorFactor * bypassFraction;
|
||||
event.setAmount(baseDamage + bonus);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package net.fretux.ascend.event;
|
||||
|
||||
import net.fretux.ascend.AscendMod;
|
||||
import net.fretux.ascend.player.PlayerStatsProvider;
|
||||
import net.fretux.ascend.player.StatEffects;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
@@ -27,15 +28,19 @@ public class PlayerEvents {
|
||||
public static void onPlayerClone(PlayerEvent.Clone event) {
|
||||
event.getOriginal().reviveCaps();
|
||||
event.getOriginal().getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(oldStats ->
|
||||
event.getEntity().getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(newStats ->
|
||||
newStats.deserializeNBT(oldStats.serializeNBT())));
|
||||
event.getEntity().getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(newStats -> {
|
||||
newStats.deserializeNBT(oldStats.serializeNBT());
|
||||
StatEffects.applyAll(event.getEntity());
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// Optional but very helpful: sync on login so client sees initial 15 points
|
||||
@SubscribeEvent
|
||||
public static void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
if (!event.getEntity().level().isClientSide) {
|
||||
PlayerStatsProvider.sync(event.getEntity());
|
||||
StatEffects.applyAll(event.getEntity());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user