-
Bug
-
Resolution: Unresolved
-
None
-
1.14.4, 1.15, 1.15.2, 20w09a, 20w13b, 20w15a, 20w16a, 20w17a, 20w18a, 20w19a, 20w22a, 1.16.1, 1.16.4, 20w51a, 1.16.5, 21w13a, 21w18a, 1.17, 1.17.1, 21w41a, 1.18.1, 1.18.2, 1.19, 1.19.2, 1.19.3, 1.19.4, 23w18a, 1.20.1, 1.20.2 Pre-release 2, 1.20.2, 23w40a, 23w42a, 23w46a, 1.20.3, 1.20.4 Release Candidate 1, 1.20.4, 24w10a, 1.20.6, 24w19b, 1.21 Release Candidate 1, 1.21, 24w38a, 1.21.3
-
Confirmed
-
Mob behaviour
-
Normal
-
Gameplay
When a villager detects a desired item while sleeping (such as carrots, bread, or beetroot), it will move towards that item before entirely waking up. This causes an incorrect visual for the player where the villager appears to still be asleep (laying down horizontally) while it pathfinds towards any applicable item(s).
Steps to Reproduce:
- Place down one or more beds
- Spawn in one or more villagers
- Drop an item on the ground that entice villagers
/give @p minecraft:carrot 1
Observed Behavior:
The villager will move across the ground as if it is still asleep to pick up items.
Expected Behavior:
The villager should first wake up entirely (standing upright) before walking to the dropped item, or not detect items while asleep in the first place.
Video:
Code Analysis:
Here in the create() method of the GoToWantedItem class (which handles a villagers ai behavior to pathfind to desired items) it checks the following conditions for the villager and/or the desired item:
- The item pickup cooldown is empty
- It can start to pickup the item
- The desired item is close enough to the villager
- The villager and desired item are both within the level's world border
However, it does not check for whether the villager is asleep. The villager waking up is only ever executed from create() in WakeUp.
public static <E extends LivingEntity> BehaviorControl<E> create(Predicate<E> startCondition, float speed, boolean requiresWalkTarget, int radius) { return BehaviorBuilder.create((context) -> { BehaviorBuilder<E, ? extends MemoryAccessor<? extends K1, WalkTarget>> behaviorbuilder = requiresWalkTarget ? context.registered(MemoryModuleType.WALK_TARGET) : context.absent(MemoryModuleType.WALK_TARGET); return context.group(context.registered(MemoryModuleType.LOOK_TARGET), behaviorbuilder, context.present(MemoryModuleType.NEAREST_VISIBLE_WANTED_ITEM), context.registered(MemoryModuleType.ITEM_PICKUP_COOLDOWN_TICKS)).apply(context, (lookTarget, walkTarget, nearestVisibleWantedItem, itemPickupCooldownTicks) -> { return (level, entity, time) -> { ItemEntity itementity = context.get(nearestVisibleWantedItem); if ( context.tryGet(itemPickupCooldownTicks).isEmpty() && startCondition.test(entity) && itementity.closerThan(entity, (double)radius) && entity.level().getWorldBorder().isWithinBounds(itementity.blockPosition()) ) { WalkTarget walktarget = new WalkTarget(new EntityTracker(itementity, false), speed, 0); lookTarget.set(new EntityTracker(itementity, true)); walkTarget.set(walktarget); return true; } else { return false; } }; }); }); } }
Two Possible Solutions:
- If the villager should not be able to pathfind/collect the desired item until it has been woken up via the time turning to day, or being manually woken by a player input on it's bed, a check could be added for whether the villager is currently sleeping. If it is, do not try and pathfind. Like so:
if ( context.tryGet(itemPickupCooldownTicks).isEmpty() && startCondition.test(entity) && itementity.closerThan(entity, (double)radius) && entity.level().getWorldBorder().isWithinBounds(itementity.blockPosition()) //Fix         && !entity.isSleeping() //Fix end )
- If the villager should still be able to wake up as it does currently while sleeping, the villager should first properly and entirely wake up before pathfinding to collect the item. This could be done by adding a check to see if the villager is sleeping. If it is, wake up the villager first before executing the rest of the code.
//Fix if (entity.isSleeping()) { entity.stopSleeping(); } //Fix end WalkTarget walktarget = new WalkTarget(new EntityTracker(itementity, false), speed, 0); lookTarget.set(new EntityTracker(itementity, true)); walkTarget.set(walktarget); return true;
This is how it looks compared with the new behavior in suggestion 2:
2023-07-19_20-02-36.mp4
- is duplicated by
-
MC-156308 Villager leave their bed to pick up the food on the ground when they are sleeping
- Resolved
-
MC-157205 Villagers slide out of bed for a piece of bread
- Resolved
-
MC-157289 Villagers glitch out of beds
- Resolved
-
MC-157510 Villager moves around the bed when you drop items on them
- Resolved
-
MC-158660 Villagers can be push out beds by items
- Resolved
-
MC-160339 Villager seed bug
- Resolved
-
MC-160540 Villagers getting out of bed for food still appear to be in sleeping mode.
- Resolved
-
MC-161421 Villagers Walk While Sleeping To Grab Items!
- Resolved
-
MC-161455 Sleeping Villagers sliding out of beds to gather food
- Resolved
-
MC-164332 Villagers Being Attracted to food when sleeping
- Resolved
-
MC-164340 Sleeping sliding villager
- Resolved
-
MC-164934 Villager wakes up to pick up Wheat Seeds and sleeps in a repeating loop
- Resolved
-
MC-167506 Villagers incorrect in bed when sleeping
- Resolved
-
MC-168718 Villagers are going for food while they're sleeping
- Resolved
-
MC-173942 Giving food to sleeping villagers
- Resolved
-
MC-176781 Villagers Walk and Jump with sleeping position
- Resolved
-
MC-177693 Villager still pathfinds food in bed
- Resolved
-
MC-178532 Villagers sliding off beds
- Resolved
-
MC-189572 Villagers shift in bed when trying to collect thrown down seeds
- Resolved
-
MC-191910 Villagers glide away from bed positioning if bread is thrown
- Resolved
-
MC-197436 Villagers move on beds while sleeping when items thrown
- Resolved
-
MC-211357 Villagers will slide off and move around beds while lying down to take food off the ground
- Resolved
-
MC-222085 Villager walking when sleeping
- Resolved
-
MC-230675 Villagers try to slide while sleeping to get crops.
- Resolved
-
MC-231210 Villagers can take bread while sleeping.
- Resolved
-
MC-234437 The Villager on the bottom Bug
- Resolved
-
MC-237201 Villager sleeping out of the bed
- Resolved
-
MC-239331 villagers is moving (sleeping) on beds which i drop carrot
- Resolved
-
MC-250058 When dropping carrots, potatoes, etc, villagers go out of their bed on the sleeping position
- Resolved
-
MC-255223 villagers try to pick up food and claim workblock while sleeping
- Resolved
-
MC-259169 villagers can do the walk animation and walk when in sleeping animation to!
- Resolved
-
MC-259993 Sleeping villagers lay down when moving to pick up thrown food items.
- Resolved
-
MC-273294 Villagers can pathfind while in beds
- Resolved
-
MC-276862 Minecraft sleepwalker villager
- Resolved
-
MC-278119 Foating villager when a job block is placed
- Resolved
-
MC-278504 Villagers pathing to bread while laying down
- Resolved
- relates to
-
MC-227108 When a villager appears to be moved/fallen out of a bed, you can't kick it out of it ("This bed is occupied")
- Reopened
-
MC-148370 When entering a bed while moving, the player is not placed correctly or can fall out of the bed
- Open
-
MC-145755 Villagers move while in there sleeping position.
- Resolved