Fix some small issues
This commit is contained in:
@@ -16,30 +16,19 @@ public class IntelligencePotionEvents {
|
|||||||
public static void onBeneficialEffectAdded(MobEffectEvent.Added event) {
|
public static void onBeneficialEffectAdded(MobEffectEvent.Added event) {
|
||||||
if (!(event.getEntity() instanceof Player player)) return;
|
if (!(event.getEntity() instanceof Player player)) return;
|
||||||
if (player.level().isClientSide) return;
|
if (player.level().isClientSide) return;
|
||||||
|
|
||||||
MobEffectInstance inst = event.getEffectInstance();
|
MobEffectInstance inst = event.getEffectInstance();
|
||||||
if (inst == null) return;
|
if (inst == null) return;
|
||||||
if (inst.getEffect().getCategory() != MobEffectCategory.BENEFICIAL) return;
|
if (inst.getEffect().getCategory() != MobEffectCategory.BENEFICIAL) return;
|
||||||
|
|
||||||
// Avoid re-scaling already huge/custom durations.
|
|
||||||
if (inst.getDuration() > 12000) return;
|
if (inst.getDuration() > 12000) return;
|
||||||
|
|
||||||
player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
|
player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
|
||||||
int intel = stats.getAttributeLevel("intelligence");
|
int intel = stats.getAttributeLevel("intelligence");
|
||||||
if (intel <= 0) return;
|
if (intel <= 0) return;
|
||||||
|
|
||||||
int baseDuration = inst.getDuration();
|
int baseDuration = inst.getDuration();
|
||||||
|
|
||||||
// +0.5% duration per INT, up to +50%
|
|
||||||
double durPerPoint = 0.005d;
|
double durPerPoint = 0.005d;
|
||||||
double durMax = 0.5d;
|
double durMax = 0.5d;
|
||||||
double durBonus = Math.min(intel * durPerPoint, durMax);
|
double durBonus = Math.min(intel * durPerPoint, durMax);
|
||||||
int newDuration = (int) (baseDuration * (1.0d + durBonus));
|
int newDuration = (int) (baseDuration * (1.0d + durBonus));
|
||||||
|
if (newDuration <= baseDuration) return;
|
||||||
if (newDuration <= baseDuration) return; // nothing to do
|
|
||||||
|
|
||||||
// Replace effect: remove original, add scaled.
|
|
||||||
// This will fire another Added event, but newDuration > 12000 guard prevents loops.
|
|
||||||
player.removeEffect(inst.getEffect());
|
player.removeEffect(inst.getEffect());
|
||||||
player.addEffect(new MobEffectInstance(
|
player.addEffect(new MobEffectInstance(
|
||||||
inst.getEffect(),
|
inst.getEffect(),
|
||||||
|
|||||||
@@ -26,11 +26,15 @@ public class PlayerEvents {
|
|||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onPlayerClone(PlayerEvent.Clone event) {
|
public static void onPlayerClone(PlayerEvent.Clone event) {
|
||||||
|
if (!event.isWasDeath()) return;
|
||||||
event.getOriginal().reviveCaps();
|
event.getOriginal().reviveCaps();
|
||||||
event.getOriginal().getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(oldStats ->
|
event.getOriginal().getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(oldStats ->
|
||||||
event.getEntity().getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(newStats -> {
|
event.getEntity().getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(newStats -> {
|
||||||
newStats.deserializeNBT(oldStats.serializeNBT());
|
newStats.deserializeNBT(oldStats.serializeNBT());
|
||||||
StatEffects.applyAll(event.getEntity());
|
StatEffects.applyAll(event.getEntity());
|
||||||
|
if (!event.getEntity().level().isClientSide) {
|
||||||
|
PlayerStatsProvider.sync(event.getEntity());
|
||||||
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,9 @@ public class ServerboundSpendPointPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void handle(Supplier<NetworkEvent.Context> ctx) {
|
public void handle(Supplier<NetworkEvent.Context> ctx) {
|
||||||
ctx.get().enqueueWork(() -> {
|
NetworkEvent.Context context = ctx.get();
|
||||||
ServerPlayer player = ctx.get().getSender();
|
context.enqueueWork(() -> {
|
||||||
|
ServerPlayer player = context.getSender();
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
|
||||||
System.out.println("[Ascend] Received spend packet '" + attribute + "' from " + player.getGameProfile().getName());
|
System.out.println("[Ascend] Received spend packet '" + attribute + "' from " + player.getGameProfile().getName());
|
||||||
@@ -36,34 +37,13 @@ public class ServerboundSpendPointPacket {
|
|||||||
player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
|
player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
|
||||||
boolean success = stats.spendPoints(attribute);
|
boolean success = stats.spendPoints(attribute);
|
||||||
if (success) {
|
if (success) {
|
||||||
player.sendSystemMessage(Component.literal("You increased " + attribute + "!"));
|
StatEffects.applyAll(player);
|
||||||
CompoundTag data = stats.serializeNBT();
|
CompoundTag data = stats.serializeNBT();
|
||||||
PacketHandler.INSTANCE.send(
|
PacketHandler.INSTANCE.send(
|
||||||
PacketDistributor.PLAYER.with(() -> player),
|
PacketDistributor.PLAYER.with(() -> player),
|
||||||
new ClientboundSyncStatsPacket(data)
|
new ClientboundSyncStatsPacket(data)
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
int level = stats.getAttributeLevel(attribute);
|
|
||||||
int cost = stats.getCostToUpgrade(attribute);
|
|
||||||
int have = stats.getUnspentPoints();
|
|
||||||
player.sendSystemMessage(Component.literal(
|
|
||||||
"Not enough points (" + have + "/" + cost + ") to increase " + attribute + " (lvl " + level + ")."
|
|
||||||
));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
|
|
||||||
boolean success = stats.spendPoints(attribute);
|
|
||||||
if (success) {
|
|
||||||
if ("strength".equals(attribute)) {
|
|
||||||
StatEffects.applyStrength(player, stats.getAttributeLevel("strength"));
|
|
||||||
}
|
|
||||||
|
|
||||||
player.sendSystemMessage(Component.literal("You increased " + attribute + "!"));
|
player.sendSystemMessage(Component.literal("You increased " + attribute + "!"));
|
||||||
CompoundTag data = stats.serializeNBT();
|
|
||||||
PacketHandler.INSTANCE.send(
|
|
||||||
PacketDistributor.PLAYER.with(() -> player),
|
|
||||||
new ClientboundSyncStatsPacket(data)
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
int level = stats.getAttributeLevel(attribute);
|
int level = stats.getAttributeLevel(attribute);
|
||||||
int cost = stats.getCostToUpgrade(attribute);
|
int cost = stats.getCostToUpgrade(attribute);
|
||||||
@@ -74,6 +54,6 @@ public class ServerboundSpendPointPacket {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
ctx.get().setPacketHandled(true);
|
context.setPacketHandled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user