RangedEntity-rangedAttack(LivingEntity target, float charge) dont work
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 12.7k
- Forks
- 3.5k
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 11
Description
Expected behavior
When the method is called, the entity fires an arrow with a loaded crossbow.
Observed/Actual behavior
Nothing happens
Steps/models to reproduce
I created a mobgoal, what makes the entity perform ranged attack
@Override
public void tick() {
LivingEntity target = entity.getTarget();
if (target != null) {
boolean hasSight = entity.hasLineOfSight(target);
boolean var2 = seeTime > 0;
if (hasSight != var2) {
seeTime = 0;
}
if (hasSight) {
++seeTime;
} else {
--seeTime;
}
double distanceSqr = entity.getLocation().distanceSquared(target.getLocation());
boolean canAttack = (distanceSqr > attackRadiusSqr || seeTime > 5) && attackDelay == 0;
entity.lookAt(target,30f,30f);
switch (crossbowState) {
case UNCHARGED -> {
if (canAttack) {
entity.startUsingItem(EquipmentSlot.HAND);
crossbowState = STATE.CHARGING;
}
}
case CHARGING -> {
if (!entity.hasActiveItem()) {
crossbowState = STATE.UNCHARGED;
}
int ticks = entity.getActiveItemUsedTime();
ItemStack item = entity.getEquipment().getItem(EquipmentSlot.HAND);
if (ticks > 25) {
crossbowState = STATE.CHARGED;
attackDelay = 20;
item.editMeta(CrossbowMeta.class, meta -> meta.addChargedProjectile(ARROW));
}
}
case CHARGED -> {
--attackDelay;
if (attackDelay == 0) {
crossbowState = STATE.READY_TO_FIRE;
}
}
case READY_TO_FIRE ->
{
if (hasSight) {
entity.completeUsingActiveItem();
entity.rangedAttack(target, 1.0f);
crossbowState = STATE.UNCHARGED;
}
}
}
}
}
enum STATE {
UNCHARGED,
CHARGING,
CHARGED,
READY_TO_FIRE
}
Plugin and Datapack List
Only my plugin
Paper version
Paper version 1.21.4-227-ver/1.21.4@7675321
Other
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the RangedEntity-rangedAttack(LivingEntity target, float charge) entry point and the crossbow state transitions in the supplied mob-goal code. Check how completeUsingActiveItem(), rangedAttack(), and the charged projectile are expected to interact. Done means a crossbow-equipped entity fires an arrow when the method is called, with the relevant behavior verified against the reported Paper version.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend-api-design, game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100