Search in sources :

Example 1 with EntityType

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);
}
Also used : EntityType(org.spongepowered.api.entity.EntityType) EntityArchetype(org.spongepowered.api.entity.EntityArchetype) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WeightedSerializableObject(org.spongepowered.api.util.weighted.WeightedSerializableObject)

Example 2 with EntityType

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

Example 3 with EntityType

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

Example 4 with EntityType

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);
}
Also used : EntityType(org.spongepowered.api.entity.EntityType) Entity(org.spongepowered.api.entity.Entity) EntityThrowable(net.minecraft.entity.projectile.EntityThrowable)

Example 5 with EntityType

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);
        }
    }
}
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)

Aggregations

EntityType (org.spongepowered.api.entity.EntityType)33 Vector3d (com.flowpowered.math.vector.Vector3d)7 World (net.minecraft.world.World)6 Entity (org.spongepowered.api.entity.Entity)6 Transform (org.spongepowered.api.entity.Transform)6 ConstructEntityEvent (org.spongepowered.api.event.entity.ConstructEntityEvent)6 SpongeEntityType (org.spongepowered.common.entity.SpongeEntityType)4 Entity (net.minecraft.entity.Entity)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 Player (org.spongepowered.api.entity.living.player.Player)3 CauseStackManager (org.spongepowered.api.event.CauseStackManager)3 World (org.spongepowered.api.world.World)3 Redirect (org.spongepowered.asm.mixin.injection.Redirect)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 NBTTagList (net.minecraft.nbt.NBTTagList)2