fix beer attacking
This commit is contained in:
@@ -20,23 +20,33 @@ public class DrunkEffect extends StatusEffect {
|
|||||||
|
|
||||||
static void tick(MinecraftServer server) {
|
static void tick(MinecraftServer server) {
|
||||||
for (var world : server.getWorlds()) {
|
for (var world : server.getWorlds()) {
|
||||||
// Every 20 ticks = 1 second
|
|
||||||
if (world.getTime() % 20 != 0) continue;
|
if (world.getTime() % 20 != 0) continue;
|
||||||
|
|
||||||
for (ServerPlayerEntity player : world.getPlayers()) {
|
for (ServerPlayerEntity player : world.getPlayers()) {
|
||||||
if (!player.hasStatusEffect(Szar.DRUNK_EFFECT)) continue;
|
if (!player.hasStatusEffect(Szar.DRUNK_EFFECT)) continue;
|
||||||
|
if (world.random.nextInt(5) >= 2) continue; // 2 in 5 chance
|
||||||
|
|
||||||
// 1 in 5 chance
|
double reach = 4.5;
|
||||||
if (world.random.nextInt(5) != 0) continue;
|
net.minecraft.util.math.Vec3d eyePos = player.getEyePos();
|
||||||
|
net.minecraft.util.math.Vec3d lookVec = player.getRotationVector();
|
||||||
|
net.minecraft.util.math.Vec3d endPos = eyePos.add(lookVec.multiply(reach));
|
||||||
|
|
||||||
// Raycast to find what the player is looking at
|
EntityHitResult entityHit = net.minecraft.entity.projectile.ProjectileUtil
|
||||||
HitResult hit = player.raycast(4.5, 0, false);
|
.getEntityCollision(
|
||||||
if (hit.getType() != HitResult.Type.ENTITY) continue;
|
world,
|
||||||
if (!(hit instanceof EntityHitResult entityHit)) continue;
|
player,
|
||||||
|
eyePos,
|
||||||
|
endPos,
|
||||||
|
player.getBoundingBox().stretch(lookVec.multiply(reach)).expand(1.0),
|
||||||
|
e -> e instanceof LivingEntity && e != player && !e.isSpectator()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (entityHit == null) continue;
|
||||||
if (!(entityHit.getEntity() instanceof LivingEntity target)) continue;
|
if (!(entityHit.getEntity() instanceof LivingEntity target)) continue;
|
||||||
|
|
||||||
// Hit the entity as if the player attacked it
|
|
||||||
player.attack(target);
|
player.attack(target);
|
||||||
|
// Swing main hand
|
||||||
|
player.swingHand(net.minecraft.util.Hand.MAIN_HAND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user