mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-25 12:05:53 +01:00
SPIGOT-5180: Add Villager#sleep() and #wakeup() methods
This commit is contained in:
parent
c03b2befb2
commit
1215188ff7
@ -173,7 +173,8 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
|
||||
@Override
|
||||
public boolean sleep(Location location, boolean force) {
|
||||
Preconditions.checkArgument(location != null, "Location == null");
|
||||
Preconditions.checkArgument(location != null, "Location cannot be null");
|
||||
Preconditions.checkArgument(location.getWorld() != null, "Location needs to be in a world");
|
||||
Preconditions.checkArgument(location.getWorld().equals(getWorld()), "Cannot sleep across worlds");
|
||||
|
||||
BlockPosition blockposition = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
|
@ -5,7 +5,11 @@ import java.util.Locale;
|
||||
import net.minecraft.server.EntityVillager;
|
||||
import net.minecraft.server.IRegistry;
|
||||
import net.minecraft.server.VillagerProfession;
|
||||
import net.minecraft.server.IBlockData;
|
||||
import net.minecraft.server.BlockPosition;
|
||||
import net.minecraft.server.BlockBed;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@ -78,6 +82,29 @@ public class CraftVillager extends CraftAbstractVillager implements Villager {
|
||||
getHandle().setExperience(experience);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sleep(Location location) {
|
||||
Preconditions.checkArgument(location != null, "Location cannot be null");
|
||||
Preconditions.checkArgument(location.getWorld() != null, "Location needs to be in a world");
|
||||
Preconditions.checkArgument(location.getWorld().equals(getWorld()), "Cannot sleep across worlds");
|
||||
|
||||
BlockPosition position = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
IBlockData iblockdata = getHandle().world.getType(position);
|
||||
if (!(iblockdata.getBlock() instanceof BlockBed)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
getHandle().e(position); // PAIL rename sleep
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void wakeup() {
|
||||
Preconditions.checkState(isSleeping(), "Cannot wakeup if not sleeping");
|
||||
|
||||
getHandle().dy(); // PAIL rename wakeup
|
||||
}
|
||||
|
||||
public static Profession nmsToBukkitProfession(VillagerProfession nms) {
|
||||
return Profession.valueOf(IRegistry.VILLAGER_PROFESSION.getKey(nms).getKey().toUpperCase(Locale.ROOT));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user