Made it so neutral mobs can kill you and fixed gravity when knocked.
This commit is contained in:
+1
-1
@@ -48,7 +48,7 @@ mod_name=Knockedback
|
|||||||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||||
mod_license=MIT
|
mod_license=MIT
|
||||||
# The mod version. See https://semver.org/
|
# The mod version. See https://semver.org/
|
||||||
mod_version=1.1.0
|
mod_version=1.2.0
|
||||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||||
# This should match the base package used for the mod sources.
|
# This should match the base package used for the mod sources.
|
||||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import net.minecraft.world.damagesource.DamageSource;
|
|||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.Items;
|
import net.minecraft.world.item.Items;
|
||||||
|
import net.minecraftforge.event.TickEvent;
|
||||||
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
@@ -28,6 +29,20 @@ public class KnockedManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
|
||||||
|
if (!(event.player instanceof ServerPlayer sp)) return;
|
||||||
|
if (KnockedManager.isKnocked(sp)) {
|
||||||
|
boolean grounded = sp.onGround() || sp.isInWater();
|
||||||
|
sp.setNoGravity(false); // Always allow gravity
|
||||||
|
if (!grounded) {
|
||||||
|
sp.setDeltaMovement(0, sp.getDeltaMovement().y() - 0.08, 0); // Gravity acceleration
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean isKnocked(LivingEntity entity) {
|
public static boolean isKnocked(LivingEntity entity) {
|
||||||
return knockedEntities.containsKey(entity.getUUID());
|
return knockedEntities.containsKey(entity.getUUID());
|
||||||
|
|||||||
@@ -144,17 +144,25 @@ public class MobKillHandler {
|
|||||||
p.getX() + r, p.getY() + r, p.getZ() + r
|
p.getX() + r, p.getY() + r, p.getZ() + r
|
||||||
);
|
);
|
||||||
return world.getEntitiesOfClass(Mob.class, box).stream()
|
return world.getEntitiesOfClass(Mob.class, box).stream()
|
||||||
.filter(m -> isHostile(m) || isAggressiveNeutral(m))
|
.filter(m -> isHostile(m) || isAggressiveNeutral(m, p))
|
||||||
.findAny().orElse(null);
|
.findAny().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean isHostile(Mob m) {
|
private boolean isHostile(Mob m) {
|
||||||
return m instanceof net.minecraft.world.entity.monster.Monster;
|
return m instanceof net.minecraft.world.entity.monster.Monster;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isAggressiveNeutral(Mob m) {
|
private boolean isAggressiveNeutral(Mob mob, Player target) {
|
||||||
if (m instanceof net.minecraft.world.entity.animal.Wolf w) return w.isAngry();
|
if (mob instanceof net.minecraft.world.entity.animal.Wolf wolf) {
|
||||||
if (m instanceof net.minecraft.world.entity.monster.EnderMan e) return e.isCreepy();
|
return wolf.isAngry() && wolf.getTarget() == target;
|
||||||
|
}
|
||||||
|
if (mob instanceof net.minecraft.world.entity.monster.EnderMan enderman) {
|
||||||
|
return enderman.isCreepy() && enderman.getTarget() == target;
|
||||||
|
}
|
||||||
|
if (mob instanceof net.minecraft.world.entity.animal.IronGolem golem) {
|
||||||
|
return golem.getTarget() == target;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ public class KnockedEffect {
|
|||||||
public static void onPlayerTick(LivingEvent.LivingTickEvent event) {
|
public static void onPlayerTick(LivingEvent.LivingTickEvent event) {
|
||||||
if (!(event.getEntity() instanceof Player player)) return;
|
if (!(event.getEntity() instanceof Player player)) return;
|
||||||
if (KnockedManager.isKnocked(player)) {
|
if (KnockedManager.isKnocked(player)) {
|
||||||
player.setDeltaMovement(0, 0, 0);
|
|
||||||
player.setSprinting(false);
|
player.setSprinting(false);
|
||||||
player.hurtMarked = true;
|
player.hurtMarked = true;
|
||||||
player.setNoGravity(false);
|
player.setNoGravity(false);
|
||||||
|
player.setDeltaMovement(0, player.getDeltaMovement().y(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user