mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-12 09:51:12 +01:00
SPIGOT-4820: Villager Type API
This commit is contained in:
parent
3dcbf6b85b
commit
deeecc7f08
1 changed files with 13 additions and 2 deletions
|
@ -3,9 +3,9 @@ package org.bukkit.craftbukkit.entity;
|
|||
import java.util.Locale;
|
||||
import net.minecraft.server.EntityVillager;
|
||||
import net.minecraft.server.IRegistry;
|
||||
import net.minecraft.server.MinecraftKey;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Villager;
|
||||
|
||||
|
@ -38,6 +38,17 @@ public class CraftVillager extends CraftAbstractVillager implements Villager {
|
|||
@Override
|
||||
public void setProfession(Profession profession) {
|
||||
Validate.notNull(profession);
|
||||
getHandle().setVillagerData(getHandle().getVillagerData().withProfession(IRegistry.VILLAGER_PROFESSION.get(new MinecraftKey(profession.name().toLowerCase(Locale.ROOT)))));
|
||||
getHandle().setVillagerData(getHandle().getVillagerData().withProfession(IRegistry.VILLAGER_PROFESSION.get(CraftNamespacedKey.toMinecraft(profession.getKey()))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getVillagerType() {
|
||||
return Type.valueOf(IRegistry.VILLAGER_TYPE.getKey(getHandle().getVillagerData().getType()).getKey().toUpperCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVillagerType(Type type) {
|
||||
Validate.notNull(type);
|
||||
getHandle().setVillagerData(getHandle().getVillagerData().withType(IRegistry.VILLAGER_TYPE.get(CraftNamespacedKey.toMinecraft(type.getKey()))));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue