use of org.spongepowered.common.entity.SpongeEntityType in project SpongeCommon by SpongePowered.
the class EntityTypeRegistryModule method newEntityTypeFromName.
private SpongeEntityType newEntityTypeFromName(String spongeName, String mcName) {
ResourceLocation resourceLoc = new ResourceLocation(mcName);
Class<? extends Entity> cls = SpongeImplHooks.getEntityClass(resourceLoc);
if (cls == null) {
throw new IllegalArgumentException("No class mapping for entity name " + mcName);
}
final SpongeEntityType entityType = new SpongeEntityType(SpongeImplHooks.getEntityId(cls), spongeName, cls, new SpongeTranslation("entity." + SpongeImplHooks.getEntityTranslation(resourceLoc) + ".name"));
KeyRegistryModule.getInstance().registerForEntityClass(cls);
return entityType;
}
use of org.spongepowered.common.entity.SpongeEntityType 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.common.entity.SpongeEntityType 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);
}
}
}
use of org.spongepowered.common.entity.SpongeEntityType in project SpongeForge by SpongePowered.
the class StaticMixinForgeHelper method registerCustomEntity.
public static void registerCustomEntity(Class<? extends Entity> entityClass, String entityName, int id, ModContainer modContainer) {
// fix bad entity name registrations from mods
final String[] parts = entityName.split(":");
if (parts.length > 1) {
entityName = parts[1];
}
if (entityName.contains(".")) {
if ((entityName.indexOf(".") + 1) < entityName.length()) {
entityName = entityName.substring(entityName.indexOf(".") + 1, entityName.length());
}
}
entityName = entityName.replace("entity", "");
if (entityName.startsWith("ent")) {
entityName = entityName.replace("ent", "");
}
entityName = entityName.replaceAll("[^A-Za-z0-9]", "");
String modId = "unknown";
if (modContainer != null) {
modId = modContainer.getModId();
}
if (!modContainer.equals(SpongeMod.instance)) {
SpongeEntityType entityType = new SpongeEntityType(id, entityName, modId, entityClass, null);
EntityTypeRegistryModule.getInstance().registerAdditionalCatalog(entityType);
}
}
use of org.spongepowered.common.entity.SpongeEntityType in project SpongeCommon by SpongePowered.
the class MixinEntity method onConstruction.
@Inject(method = "<init>", at = @At("RETURN"))
public void onConstruction(net.minecraft.world.World worldIn, CallbackInfo ci) {
if (this.entityType instanceof SpongeEntityType) {
SpongeEntityType spongeEntityType = (SpongeEntityType) this.entityType;
if (spongeEntityType.getEnumCreatureType() == null) {
for (EnumCreatureType type : EnumCreatureType.values()) {
if (SpongeImplHooks.isCreatureOfType((net.minecraft.entity.Entity) (Object) this, type)) {
spongeEntityType.setEnumCreatureType(type);
break;
}
}
}
}
if (worldIn != null && !worldIn.isRemote) {
this.spongeProfileManager = ((SpongeProfileManager) Sponge.getServer().getGameProfileManager());
this.userStorageService = SpongeImpl.getGame().getServiceManager().provide(UserStorageService.class).get();
}
}
Aggregations