This code defines a method called `performRangedAttack` that is likely...

August 31, 2025 at 09:33 PM

@Override public void performRangedAttack(LivingEntity p_34143_, float p_34144_) { if (!this.isDrinkingPotion()) { Vec3 vec3 = p_34143_.getDeltaMovement(); double d0 = p_34143_.getX() + vec3.x - this.getX(); double d1 = p_34143_.getEyeY() - 1.1F - this.getY(); double d2 = p_34143_.getZ() + vec3.z - this.getZ(); double d3 = Math.sqrt(d0 * d0 + d2 * d2); Holder<Potion> holder = Potions.HARMING; if (p_34143_.isInvertedHealAndHarm()) { holder = Potions.HEALING; } if (p_34143_ instanceof Raider) { if (p_34143_.getHealth() <= 4.0F) { holder = Potions.HEALING; } else { holder = Potions.REGENERATION; } this.setTarget(null); } else if (d3 >= 8.0 && !p_34143_.hasEffect(MobEffects.MOVEMENT_SLOWDOWN)) { holder = Potions.SLOWNESS; } else if (p_34143_.getHealth() >= 8.0F && !p_34143_.hasEffect(MobEffects.POISON)) { holder = Potions.POISON; } else if (d3 <= 3.0 && !p_34143_.hasEffect(MobEffects.WEAKNESS) && this.random.nextFloat() < 0.25F) { holder = Potions.WEAKNESS; } if (this.level() instanceof ServerLevel serverlevel) { ItemStack itemstack = PotionContents.createItemStack(Items.SPLASH_POTION, holder); Projectile.spawnProjectileUsingShoot(ThrownPotion::new, serverlevel, itemstack, this, d0, d1 + d3 * 0.2, d2, 0.75F, 8.0F); } if (!this.isSilent()) { this.level() .playSound( null, this.getX(), this.getY(), this.getZ(), SoundEvents.WITCH_THROW, this.getSoundSource(), 1.0F, 0.8F + this.random.nextFloat() * 0.4F ); } } }

This code defines a method called performRangedAttack that is likely implemented in a class representing an entity (possibly a "Witch" in a Minecraft mod or similar system). Here's what the code does:


Purpose:

The method performs a ranged attack on a target (LivingEntity) using a thrown potion. The type of potion used depends on various conditions such as the target's health, distance from the attacker, and existing status effects on the target.


Detailed Breakdown:

  1. Precondition Check:

    • The entity first checks whether it is currently "drinking a potion" (e.g., it’s occupied with another action). If it is, the method does nothing.
  2. Calculate Target's Position and Movement:

    • The target's movement vector (Vec3) is used to determine its current location and velocity.
    • The horizontal (d0, d2) and vertical (d1) distances between the attacker and target are calculated.
    • d3 calculates the 2D horizontal distance between the attacker and target (ignoring height for now).
  3. Choose Potion Type:

    • A "HARMING" potion is chosen by default.
    • Various conditions adjust the potion type:
      • If the target is "inverted to healing and harming" (e.g., undead entities like skeletons or zombies), the potion is set to "HEALING."
      • If the target is a Raider (a specific type of hostile mob in Minecraft):
        • If their health is below 4, it throws a "HEALING" potion.
        • Otherwise, it throws a "REGENERATION" potion.
        • The attacker stops targeting the Raider (this.setTarget(null)).
      • If the target is far away (d3 >= 8.0) and does not have a "SLOWNESS" effect, it throws a "SLOWNESS" potion.
      • If the target has high health (>= 8) and is not poisoned, it throws a "POISON" potion.
      • If the target is very close (d3 <= 3.0), does not have a "WEAKNESS" effect, and a random chance (25%) succeeds, it throws a "WEAKNESS" potion.
  4. Spawn the Potion Projectile:

    • If the current level is a server-level environment (ServerLevel), it creates a splash potion using PotionContents.createItemStack and spawns it as a projectile.
    • Projectile.spawnProjectileUsingShoot is used to precisely control the projectile's trajectory and speed:
      • The computed distances (d0, d1, d2) and modifiers (e.g., d3 * 0.2, speed 0.75F, inaccuracy 8.0F) are used in the calculations for launching the potion.
  5. Play Sound Effect:

    • If the attacker is not silent (i.e., it can make noise), it plays the "WITCH_THROW" sound effect at the attacker's position (this.getX(), this.getY(), this.getZ()) with volume and pitch variations.

Summary of Behavior:

The method simulates a ranged attack by:

  • Determining the optimal potion to throw at the target based on conditions like health, distance, and effects.
  • Spawning a thrown potion projectile (splash potion).
  • Optionally playing a sound effect to signify the action.

This method would likely be part of a modded Minecraft or similar game code where entities like witches implement custom attacking logic with potion effects.

Generate your own explanations
Download our vscode extension
Read other generated explanations

Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node