Search in sources :

Example 1 with SpongeEntityType

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;
}
Also used : SpongeTranslation(org.spongepowered.common.text.translation.SpongeTranslation) SpongeEntityType(org.spongepowered.common.entity.SpongeEntityType) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 2 with SpongeEntityType

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"));
}
Also used : SpongeEntityType(org.spongepowered.common.entity.SpongeEntityType) EntityType(org.spongepowered.api.entity.EntityType) CustomCatalogRegistration(org.spongepowered.api.registry.util.CustomCatalogRegistration)

Example 3 with SpongeEntityType

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);
        }
    }
}
Also used : SpongeEntityType(org.spongepowered.common.entity.SpongeEntityType) EntityType(org.spongepowered.api.entity.EntityType) Entity(org.spongepowered.api.entity.Entity) SpongeEntityType(org.spongepowered.common.entity.SpongeEntityType) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 4 with SpongeEntityType

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);
    }
}
Also used : SpongeEntityType(org.spongepowered.common.entity.SpongeEntityType)

Example 5 with SpongeEntityType

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();
    }
}
Also used : EnumCreatureType(net.minecraft.entity.EnumCreatureType) SpongeEntityType(org.spongepowered.common.entity.SpongeEntityType) SpongeProfileManager(org.spongepowered.common.profile.SpongeProfileManager) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

SpongeEntityType (org.spongepowered.common.entity.SpongeEntityType)7 ItemStack (net.minecraft.item.ItemStack)2 EntityType (org.spongepowered.api.entity.EntityType)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 SpongeTranslation (org.spongepowered.common.text.translation.SpongeTranslation)2 EnumCreatureType (net.minecraft.entity.EnumCreatureType)1 MultiPartEntityPart (net.minecraft.entity.MultiPartEntityPart)1 EntityLightningBolt (net.minecraft.entity.effect.EntityLightningBolt)1 EntityWeatherEffect (net.minecraft.entity.effect.EntityWeatherEffect)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 EntityEgg (net.minecraft.entity.projectile.EntityEgg)1 EntityFishHook (net.minecraft.entity.projectile.EntityFishHook)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 HoverEvent (net.minecraft.util.text.event.HoverEvent)1 Entity (org.spongepowered.api.entity.Entity)1 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)1