Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-18 12:30:06 +01:00
SPIGOT-5180: Add Villager#sleep() and #wakeup() methods
Dieser Commit ist enthalten in:
Ursprung
c03b2befb2
Commit
1215188ff7
@ -173,7 +173,8 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean sleep(Location location, boolean force) {
|
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");
|
Preconditions.checkArgument(location.getWorld().equals(getWorld()), "Cannot sleep across worlds");
|
||||||
|
|
||||||
BlockPosition blockposition = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
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.EntityVillager;
|
||||||
import net.minecraft.server.IRegistry;
|
import net.minecraft.server.IRegistry;
|
||||||
import net.minecraft.server.VillagerProfession;
|
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.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.craftbukkit.CraftServer;
|
import org.bukkit.craftbukkit.CraftServer;
|
||||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
@ -78,6 +82,29 @@ public class CraftVillager extends CraftAbstractVillager implements Villager {
|
|||||||
getHandle().setExperience(experience);
|
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) {
|
public static Profession nmsToBukkitProfession(VillagerProfession nms) {
|
||||||
return Profession.valueOf(IRegistry.VILLAGER_PROFESSION.getKey(nms).getKey().toUpperCase(Locale.ROOT));
|
return Profession.valueOf(IRegistry.VILLAGER_PROFESSION.getKey(nms).getKey().toUpperCase(Locale.ROOT));
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren