本文整理汇总了Java中org.spongepowered.api.data.type.RabbitType类的典型用法代码示例。如果您正苦于以下问题:Java RabbitType类的具体用法?Java RabbitType怎么用?Java RabbitType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RabbitType类属于org.spongepowered.api.data.type包,在下文中一共展示了RabbitType类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tick
import org.spongepowered.api.data.type.RabbitType; //导入依赖的package包/类
public void tick() {
World w = loc.getExtent();
Optional<Chunk> chunk = w.getChunkAtBlock(loc.getBlockPosition());
if (le == null) {
if (chunk.isPresent() && chunk.get().isLoaded()) {
//first try to link the entity again:
Collection<Entity> ents = chunk.get().getEntities();
for (Entity ent : ents) {
if (( ent.isLoaded() && ent.getType().equals(npcType) && (ent.getUniqueId().equals(lastKnown) ||
( ent.getLocation().getExtent().equals(loc.getExtent()) && ent.getLocation().getPosition().distanceSquared(loc.getPosition())<1.5) ) ) &&
( !VillagerShops.isNPCused(ent) &&
displayName.equals(ent.get(Keys.DISPLAY_NAME).orElse(null))))
{ //check if npc already belongs to a different shop
le = ent; le.setLocationAndRotation(loc, rot); break;
}
}
if (le == null) { //unable to restore
// Optional<Entity> ent = w.createEntity(npcType, loc.getPosition());
Entity shop = w.createEntity(npcType, loc.getPosition());
// if (ent.isPresent()) {
// Entity shop = ent.get();
shop.offer(Keys.AI_ENABLED, false);
shop.offer(Keys.IS_SILENT, true);
//setting variant. super consistent ;D
if (variant != null)
try {
if (npcType.equals(EntityTypes.HORSE)) {
shop.tryOffer(Keys.HORSE_COLOR, (HorseColor)variant);
// ((Horse)shop).variant().set((HorseVariant)variant);
} else if (npcType.equals(EntityTypes.OCELOT)) {
shop.tryOffer(Keys.OCELOT_TYPE, (OcelotType)variant);
} else if (npcType.equals(EntityTypes.VILLAGER)) {
shop.tryOffer(Keys.CAREER, (Career)variant);
} else if (npcType.equals(EntityTypes.LLAMA)) {
shop.tryOffer(Keys.LLAMA_VARIANT, (LlamaVariant)variant);
} else if (npcType.equals(EntityTypes.RABBIT)) {
shop.tryOffer(Keys.RABBIT_TYPE, (RabbitType)variant);
} else if (npcType.equals(EntityTypes.PARROT)) {
shop.tryOffer(Keys.PARROT_VARIANT, (ParrotVariant)variant);
}
} catch (Exception e) { System.err.println("Variant no longer suported! Did the EntityType change?"); }
shop.offer(Keys.DISPLAY_NAME, displayName);
if (w.spawnEntity(shop)) {
lastKnown = shop.getUniqueId();
}
// }
}
}
} else if (le != null) {
if (!le.isLoaded() || !chunk.isPresent() || !chunk.get().isLoaded()) {
le = null; //allowing minecraft to free the resources
} else if (le.isRemoved() || le.get(Keys.HEALTH).orElse(1.0)<=0) {
le = null;
} else {
le.setLocationAndRotation(loc, rot);
if (le instanceof Living) {
if ((++lookAroundTicks>15 && VillagerShops.rng.nextInt(10) == 0) || lookAroundTicks>100) {
Living mo = (Living)le;
lookAroundTicks = 0;
mo.setHeadRotation(new Vector3d(VillagerShops.rng.nextFloat()*30-14, rot.getY()+VillagerShops.rng.nextFloat()*60-30, 0.0));
}
}
}
}
}
示例2: of
import org.spongepowered.api.data.type.RabbitType; //导入依赖的package包/类
public static RabbitType of(Rabbit.Type type) {
return CONVERTER.convert(type);
}