Initial Commit
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user