Player#getTargetEntity returns null for 1.21.10 mannequin
Expected behavior
var result = player.getTargetEntity(100, true);
// Result is null when aiming at mannequin entity
Observed/Actual behavior
It just returns null
Steps/models to reproduce
spawn a mannequin with code (/summon seems to work)
Plugin and Datapack List
Paper version
This server is running Paper version 1.21.10-115-main@af06383 (2025-11-21T23:42:01Z) (Implementing API version 1.21.10-R0.1-SNAPSHOT) You are 2 version(s) behind Download the new version at: https://papermc.io/downloads/paper
Edit: the 2 version updates available did not fix the issue
Other
for some reason, the /summon seems to work but spawned with code does not show, even tho in F3 it says that there is the entity.
Hmm, I cannot replicate this. I just have a blank plugin with only
@EventHandler
public void onTestEvent(ChatEvent event) {
System.out.println(event.getPlayer().getTargetEntity(100, true));
}
and after I summon a mannequin in, and chat while looking at it, it prints out the entity.
This is the method where i spawn the entity, where its not detectable with your test code. It might be because of the setVisibleByDefault() or something else. If you spawn the entity with this code (remove the gameobject and entity component stuff, not relevant for this case), i guess you will be able to reproduce it
private Mannequin spawnNPC(
Location spawnLocation,
EntityComponent entityComponent,
Player viewer,
GameObject gameObject) {
var world = spawnLocation.getWorld();
var entity = (Mannequin) world.spawnEntity(spawnLocation, EntityType.MANNEQUIN);
entity.setCollidable(false);
// Player Visibility Filter
entity.setVisibleByDefault(false);
viewer.showEntity(this.javaPlugin, entity);
// Remove Gravity
entity.setGravity(false);
// Skin
var skinData = entityComponent.skin();
entity.setProfile(
ResolvableProfile.resolvableProfile()
.name("")
.uuid(UUID.randomUUID())
.addProperty(new ProfileProperty("textures", skinData.texture(), skinData.signature()))
.build());
// Apply configured entity settings
entity.setSilent(entityComponent.silent());
entity.setAI(entityComponent.ai());
var pdc = entity.getPersistentDataContainer();
pdc.set(GameConstants.GAME_OBJECT_ID_KEY, PersistentDataType.STRING, gameObject.id());
return entity;
}
It's the entity.setCollidable(false); part. This also controls the "pick-ableness" of an entity, whether a ray trace lookup will interact with it. Like a marker armor stand will have the same behavior, where it doesn't show up.
Ah, makes sense but isn't there any other way to allow the method without making the entity collidable?