use of net.minecraft.server.v1_16_R3.EntityTypes in project Citizens2 by CitizensDev.
the class NMSImpl method registerEntityClass.
@Override
public void registerEntityClass(Class<?> clazz) {
if (ENTITY_REGISTRY == null)
return;
Class<?> search = clazz;
while ((search = search.getSuperclass()) != null && Entity.class.isAssignableFrom(search)) {
EntityTypes<?> type = ENTITY_REGISTRY.findType(search);
MinecraftKey key = ENTITY_REGISTRY.getKey(type);
if (key == null || type == null)
continue;
CITIZENS_ENTITY_TYPES.put(clazz, type);
int code = ENTITY_REGISTRY.a(type);
ENTITY_REGISTRY.put(code, key, type);
return;
}
throw new IllegalArgumentException("unable to find valid entity superclass for class " + clazz.toString());
}
use of net.minecraft.server.v1_16_R3.EntityTypes in project RoseStacker by Rosewood-Development.
the class NMSHandlerImpl method createNewEntityUnspawned.
@Override
public LivingEntity createNewEntityUnspawned(EntityType entityType, Location location, SpawnReason spawnReason) {
World world = location.getWorld();
if (world == null)
return null;
Class<? extends org.bukkit.entity.Entity> entityClass = entityType.getEntityClass();
if (entityClass == null || !LivingEntity.class.isAssignableFrom(entityClass))
throw new IllegalArgumentException("EntityType must be of a LivingEntity");
EntityTypes<? extends Entity> nmsEntityType = IRegistry.ENTITY_TYPE.get(CraftNamespacedKey.toMinecraft(entityType.getKey()));
Entity nmsEntity = this.createCreature(nmsEntityType, ((CraftWorld) world).getHandle(), null, null, null, new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()), this.toNmsSpawnReason(spawnReason));
return nmsEntity == null ? null : (LivingEntity) nmsEntity.getBukkitEntity();
}
use of net.minecraft.server.v1_16_R3.EntityTypes in project RoseStacker by Rosewood-Development.
the class NMSHandlerImpl method createEntityFromNBT.
@Override
public LivingEntity createEntityFromNBT(StackedEntityDataEntry<?> serialized, Location location, boolean addToWorld, EntityType entityType) {
try {
NBTTagCompound nbt = (NBTTagCompound) serialized.get();
NBTTagList positionTagList = nbt.getList("Pos", 6);
if (positionTagList == null)
positionTagList = new NBTTagList();
this.setTag(positionTagList, 0, NBTTagDouble.a(location.getX()));
this.setTag(positionTagList, 1, NBTTagDouble.a(location.getY()));
this.setTag(positionTagList, 2, NBTTagDouble.a(location.getZ()));
nbt.set("Pos", positionTagList);
NBTTagList rotationTagList = nbt.getList("Rotation", 5);
if (rotationTagList == null)
rotationTagList = new NBTTagList();
this.setTag(rotationTagList, 0, NBTTagFloat.a(location.getYaw()));
this.setTag(rotationTagList, 1, NBTTagFloat.a(location.getPitch()));
nbt.set("Rotation", rotationTagList);
// Reset the UUID to resolve possible duplicates
nbt.a("UUID", UUID.randomUUID());
Optional<EntityTypes<?>> optionalEntity = EntityTypes.a(entityType.getKey().getKey());
if (optionalEntity.isPresent()) {
WorldServer world = ((CraftWorld) location.getWorld()).getHandle();
Entity entity = this.createCreature(optionalEntity.get(), world, nbt, null, null, new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()), EnumMobSpawn.COMMAND);
if (entity == null)
throw new NullPointerException("Unable to create entity from NBT");
// Load NBT
entity.load(nbt);
if (addToWorld) {
IChunkAccess ichunkaccess = world.getChunkAt(MathHelper.floor(entity.locX() / 16.0D), MathHelper.floor(entity.locZ() / 16.0D), ChunkStatus.FULL, true);
if (!(ichunkaccess instanceof Chunk))
throw new NullPointerException("Unable to spawn entity from NBT, couldn't get chunk");
ichunkaccess.a(entity);
method_WorldServer_registerEntity.invoke(world, entity);
entity.noDamageTicks = 0;
}
return (LivingEntity) entity.getBukkitEntity();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of net.minecraft.server.v1_16_R3.EntityTypes in project RoseStacker by Rosewood-Development.
the class NMSHandlerImpl method createEntityFromNBT.
@Override
public LivingEntity createEntityFromNBT(StackedEntityDataEntry<?> serialized, Location location, boolean addToWorld, EntityType entityType) {
try {
NBTTagCompound nbt = (NBTTagCompound) serialized.get();
NBTTagList positionTagList = nbt.getList("Pos", 6);
if (positionTagList == null)
positionTagList = new NBTTagList();
this.setTag(positionTagList, 0, NBTTagDouble.a(location.getX()));
this.setTag(positionTagList, 1, NBTTagDouble.a(location.getY()));
this.setTag(positionTagList, 2, NBTTagDouble.a(location.getZ()));
nbt.set("Pos", positionTagList);
NBTTagList rotationTagList = nbt.getList("Rotation", 5);
if (rotationTagList == null)
rotationTagList = new NBTTagList();
this.setTag(rotationTagList, 0, NBTTagFloat.a(location.getYaw()));
this.setTag(rotationTagList, 1, NBTTagFloat.a(location.getPitch()));
nbt.set("Rotation", rotationTagList);
// Reset the UUID to resolve possible duplicates
nbt.a("UUID", UUID.randomUUID());
Optional<EntityTypes<?>> optionalEntity = EntityTypes.a(entityType.getKey().getKey());
if (optionalEntity.isPresent()) {
WorldServer world = ((CraftWorld) location.getWorld()).getHandle();
Entity entity = this.createCreature(optionalEntity.get(), world, nbt, null, null, new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()), EnumMobSpawn.COMMAND);
if (entity == null)
throw new NullPointerException("Unable to create entity from NBT");
// Load NBT
entity.load(nbt);
if (addToWorld) {
IChunkAccess ichunkaccess = world.getChunkAt(MathHelper.floor(entity.locX() / 16.0D), MathHelper.floor(entity.locZ() / 16.0D), ChunkStatus.FULL, true);
if (!(ichunkaccess instanceof Chunk))
throw new NullPointerException("Unable to spawn entity from NBT, couldn't get chunk");
ichunkaccess.a(entity);
method_WorldServer_registerEntity.invoke(world, entity);
entity.noDamageTicks = 0;
}
return (LivingEntity) entity.getBukkitEntity();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of net.minecraft.server.v1_16_R3.EntityTypes in project MyPet by xXKeyleXx.
the class EntityRegistry method registerEntityType.
@SuppressWarnings("unchecked")
protected void registerEntityType(MyPetType petType, String key, RegistryBlocks<EntityTypes<?>> entityRegistry) {
EntitySize size = entityRegistry.get(new MinecraftKey(key.toLowerCase())).l();
entityTypes.put(petType, IRegistry.a(entityRegistry, "mypet_" + key.toLowerCase(), EntityTypes.Builder.a(EnumCreatureType.CREATURE).b().a().a(size.width, size.height).a(key)));
registerDefaultAttributes(entityTypes.get(petType), (EntityTypes<? extends EntityLiving>) ReflectionUtil.getFieldValue(EntityTypes.class, null, ("" + petType.getTypeID()).toUpperCase()));
overwriteEntityID(entityTypes.get(petType), getEntityTypeId(petType, entityRegistry), entityRegistry);
}
Aggregations