use of org.spongepowered.api.entity.EntityType in project SpongeCommon by SpongePowered.
the class SpawnerUtils method getNextEntity.
public static WeightedSerializableObject<EntityArchetype> getNextEntity(MobSpawnerBaseLogic logic) {
int weight = logic.spawnData.itemWeight;
EntityType type = EntityUtil.fromNameToType(logic.spawnData.getNbt().getString("id")).orElse(EntityTypes.PIG);
NBTTagCompound data = logic.spawnData.getNbt();
EntityArchetype archetype = EntityArchetype.builder().type(type).entityData(NbtTranslator.getInstance().translateFrom(data)).build();
return new WeightedSerializableObject<>(archetype, weight);
}
use of org.spongepowered.api.entity.EntityType in project SpongeCommon by SpongePowered.
the class EntityTypeRegistryModule method getForClass.
@Override
public EntityType getForClass(Class<? extends Entity> clazz) {
EntityType type = this.entityClassToTypeMappings.get(clazz);
if (type == null) {
SpongeImpl.getLogger().warn(String.format("No entity type is registered for class %s", clazz.getName()));
type = EntityTypes.UNKNOWN;
this.entityClassToTypeMappings.put(clazz, type);
}
return type;
}
use of org.spongepowered.api.entity.EntityType in project SpongeCommon by SpongePowered.
the class EntityTypeRegistryModule method registerCatalogs.
@CustomCatalogRegistration
public void registerCatalogs() {
registerDefaults();
RegistryHelper.mapFields(EntityTypes.class, fieldName -> {
if (fieldName.equals("UNKNOWN")) {
return SpongeEntityType.UNKNOWN;
}
EntityType entityType = this.entityTypeMappings.get(fieldName.toLowerCase(Locale.ENGLISH));
this.entityClassToTypeMappings.put(((SpongeEntityType) entityType).entityClass, entityType);
// remove old mapping
this.entityTypeMappings.remove(fieldName.toLowerCase(Locale.ENGLISH));
// add new mapping with minecraft id
this.entityTypeMappings.put(entityType.getId(), entityType);
return entityType;
});
this.entityTypeMappings.put("minecraft:ozelot", this.entityTypeMappings.get("minecraft:ocelot"));
}
use of org.spongepowered.api.entity.EntityType in project SpongeCommon by SpongePowered.
the class ProjectileLauncher method defaultLaunch.
@SuppressWarnings("unchecked")
static <P extends Projectile> Optional<P> defaultLaunch(ProjectileSource source, Class<P> projectileClass, Location<?> loc) {
Optional<EntityType> opType = EntityTypeRegistryModule.getInstance().getEntity(projectileClass);
if (!opType.isPresent()) {
return Optional.empty();
}
Entity projectile = loc.getExtent().createEntity(opType.get(), loc.getPosition());
if (projectile instanceof EntityThrowable) {
configureThrowable((EntityThrowable) projectile);
}
return doLaunch(loc.getExtent(), (P) projectile);
}
use of org.spongepowered.api.entity.EntityType in project SpongeCommon by SpongePowered.
the class MixinEntity_Collisions method onEntityConstruction.
@Inject(method = "<init>", at = @At("RETURN"))
public void onEntityConstruction(World world, CallbackInfo ci) {
if (world != null && ((IMixinWorldInfo) world.getWorldInfo()).isValid()) {
EntityType entityType = ((Entity) this).getType();
if (entityType == EntityTypes.UNKNOWN || !(entityType instanceof SpongeEntityType)) {
return;
}
this.spongeEntityType = (SpongeEntityType) entityType;
if ((Object) this instanceof EntityItem) {
EntityItem item = (EntityItem) (Object) this;
ItemStack itemstack = item.getItem();
if (!itemstack.isEmpty()) {
this.entityName = itemstack.getUnlocalizedName().replace("item.", "");
}
} else {
this.entityName = this.spongeEntityType.getName();
}
this.entityModId = this.spongeEntityType.getModId();
if (!this.world.isRemote) {
initializeCollisionState(this.world);
}
}
}
Aggregations