Initial Commit

This commit is contained in:
IM23a-spirgif
2025-02-26 11:56:39 +01:00
parent a2ffe93ac4
commit e618ae9b19
4 changed files with 96 additions and 7 deletions
@@ -1,11 +1,13 @@
package net.fretux.knockedback;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.network.PacketDistributor;
import java.util.*;
@@ -54,18 +56,27 @@ public class KnockedManager {
Map.Entry<UUID, Integer> entry = it.next();
UUID entityId = entry.getKey();
int timeLeft = entry.getValue();
if (grippedEntities.contains(entityId)) {
continue;
// If the player is not gripped, update the countdown
if (!grippedEntities.contains(entityId)) {
timeLeft--;
if (timeLeft <= 0) {
it.remove();
continue;
} else {
entry.setValue(timeLeft);
}
}
int newTime = timeLeft - 1;
if (newTime <= 0) {
it.remove();
} else {
entry.setValue(newTime);
// Send the updated time to the knocked player
ServerPlayer knockedPlayer = NetworkHandlerHelper.getPlayerByUuid(
net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(), entityId);
if (knockedPlayer != null) {
NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> knockedPlayer),
new net.fretux.knockedback.KnockedTimePacket(timeLeft));
}
}
}
@SubscribeEvent
public static void onLivingHurt(LivingHurtEvent event) {
LivingEntity entity = event.getEntity();