Enhance intelligence, willpower, and charisma bonuses
This commit is contained in:
@@ -14,6 +14,8 @@ import net.minecraft.world.entity.npc.Villager;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.LightLayer;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.entity.TamableAnimal;
|
||||
import net.minecraft.world.entity.animal.horse.AbstractHorse;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
||||
@@ -24,8 +26,14 @@ 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;
|
||||
import net.minecraft.world.entity.animal.IronGolem;
|
||||
import net.minecraft.world.entity.animal.SnowGolem;
|
||||
import net.minecraft.world.entity.npc.GossipType;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = AscendMod.MODID)
|
||||
public class ActivityEvents {
|
||||
@@ -33,6 +41,7 @@ public class ActivityEvents {
|
||||
private static int agilityTickCounter = 0;
|
||||
private static int fortitudeTickCounter = 0;
|
||||
private static int willpowerTickCounter = 0;
|
||||
private static int charismaTickCounter = 0;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onMobKilled(LivingDeathEvent event) {
|
||||
@@ -41,7 +50,7 @@ public class ActivityEvents {
|
||||
stats.addAscendXP((int) (AscendConfig.COMMON.xpPerMobKill.get() * AscendConfig.COMMON.xpMultiplier.get()));
|
||||
LivingEntity mob = event.getEntity();
|
||||
if (mob.getMaxHealth() > 100f || mob.getType().toString().toLowerCase().contains("boss")) {
|
||||
stats.addKnowledge(2);
|
||||
stats.addKnowledgeScaled(2);
|
||||
}
|
||||
PlayerStatsProvider.sync(player);
|
||||
});
|
||||
@@ -134,8 +143,15 @@ public class ActivityEvents {
|
||||
Player player = event.player;
|
||||
if (player.level().isClientSide || event.phase != TickEvent.Phase.END) return;
|
||||
willpowerTickCounter++;
|
||||
if (willpowerTickCounter % 200 != 0) return;
|
||||
player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
|
||||
int willpower = stats.getAttributeLevel("willpower");
|
||||
if (willpower > 0 && willpowerTickCounter % 80 == 0) {
|
||||
float regen = StatEffects.getWillpowerHealthRegen(willpower);
|
||||
if (regen > 0.0f && player.getHealth() < player.getMaxHealth()) {
|
||||
player.heal(regen);
|
||||
}
|
||||
}
|
||||
if (willpowerTickCounter % 200 != 0) return;
|
||||
boolean hasNegativeEffect = player.getActiveEffects().stream()
|
||||
.anyMatch(e -> e.getEffect().getCategory() == MobEffectCategory.HARMFUL);
|
||||
boolean lowHealth = player.getHealth() <= player.getMaxHealth() * 0.25f;
|
||||
@@ -151,12 +167,48 @@ public class ActivityEvents {
|
||||
});
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onPlayerTickCharisma(TickEvent.PlayerTickEvent event) {
|
||||
Player player = event.player;
|
||||
if (player.level().isClientSide || event.phase != TickEvent.Phase.END) return;
|
||||
charismaTickCounter++;
|
||||
if (charismaTickCounter % 40 != 0) return;
|
||||
player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
|
||||
int charisma = stats.getAttributeLevel("charisma");
|
||||
if (charisma <= 0) return;
|
||||
double radius = 16.0d;
|
||||
AABB range = player.getBoundingBox().inflate(radius);
|
||||
for (LivingEntity entity : player.level().getEntitiesOfClass(LivingEntity.class, range,
|
||||
candidate -> isCharismaAlly(player, candidate))) {
|
||||
StatEffects.applyCharismaAllyBuff(entity, charisma);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onCharismaAllyTick(LivingEvent.LivingTickEvent event) {
|
||||
LivingEntity entity = event.getEntity();
|
||||
if (entity.level().isClientSide) return;
|
||||
if (!isCharismaAllyCandidate(entity)) return;
|
||||
if (entity.tickCount % 40 != 0) return;
|
||||
double radius = 16.0d;
|
||||
if (hasNearbyCharismaSource(entity, radius)) return;
|
||||
StatEffects.clearCharismaAllyBuff(entity);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onVillagerTrade(PlayerInteractEvent.EntityInteract event) {
|
||||
if (!(event.getTarget() instanceof Villager)) return;
|
||||
Player player = event.getEntity();
|
||||
if (player.level().isClientSide) return;
|
||||
player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
|
||||
int charisma = stats.getAttributeLevel("charisma");
|
||||
if (charisma > 0) {
|
||||
int reputationBonus = StatEffects.getCharismaVillagerReputationBonus(charisma);
|
||||
if (reputationBonus > 0 && event.getTarget() instanceof Villager villager) {
|
||||
villager.getGossips().add(player.getUUID(), GossipType.MINOR_POSITIVE, reputationBonus);
|
||||
}
|
||||
}
|
||||
stats.addAscendXP((int) (AscendConfig.COMMON.xpPerTrade.get() * AscendConfig.COMMON.xpMultiplier.get()));
|
||||
PlayerStatsProvider.sync(player);
|
||||
});
|
||||
@@ -271,4 +323,64 @@ public class ActivityEvents {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isCharismaAlly(Player player, LivingEntity entity) {
|
||||
if (entity instanceof TamableAnimal tame) {
|
||||
return tame.isTame() && tame.isOwnedBy(player);
|
||||
}
|
||||
if (entity instanceof AbstractHorse horse) {
|
||||
return horse.isTamed() && player.getUUID().equals(horse.getOwnerUUID());
|
||||
}
|
||||
if (entity instanceof IronGolem) {
|
||||
return true;
|
||||
}
|
||||
if (entity instanceof SnowGolem) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isCharismaAllyCandidate(LivingEntity entity) {
|
||||
if (entity instanceof TamableAnimal tame) {
|
||||
return tame.isTame();
|
||||
}
|
||||
if (entity instanceof AbstractHorse horse) {
|
||||
return horse.isTamed();
|
||||
}
|
||||
if (entity instanceof IronGolem) {
|
||||
return true;
|
||||
}
|
||||
if (entity instanceof SnowGolem) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean hasNearbyCharismaSource(LivingEntity entity, double radius) {
|
||||
if (entity instanceof TamableAnimal tame) {
|
||||
Player owner = tame.getOwner() instanceof Player player ? player : null;
|
||||
return owner != null && owner.distanceToSqr(entity) <= radius * radius && hasCharisma(owner);
|
||||
}
|
||||
if (entity instanceof AbstractHorse horse) {
|
||||
UUID ownerId = horse.getOwnerUUID();
|
||||
if (ownerId == null) return false;
|
||||
Player owner = entity.level().getPlayerByUUID(ownerId);
|
||||
return owner != null && owner.distanceToSqr(entity) <= radius * radius && hasCharisma(owner);
|
||||
}
|
||||
if (entity instanceof IronGolem || entity instanceof SnowGolem) {
|
||||
AABB range = entity.getBoundingBox().inflate(radius);
|
||||
for (Player player : entity.level().getEntitiesOfClass(Player.class, range)) {
|
||||
if (hasCharisma(player)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean hasCharisma(Player player) {
|
||||
return player.getCapability(PlayerStatsProvider.PLAYER_STATS)
|
||||
.map(stats -> stats.getAttributeLevel("charisma") > 0)
|
||||
.orElse(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user