Search in sources :

Example 6 with SpongeEntityType

use of org.spongepowered.common.entity.SpongeEntityType in project SpongeCommon by SpongePowered.

the class SpongeHoverAction method getHandle.

public static HoverEvent getHandle(HoverAction<?> action) {
    HoverEvent.Action type = getType(action);
    ITextComponent component;
    switch(type) {
        case SHOW_ENTITY:
            {
                HoverAction.ShowEntity.Ref entity = ((HoverAction.ShowEntity) action).getResult();
                NBTTagCompound nbt = new NBTTagCompound();
                nbt.setString("id", entity.getUniqueId().toString());
                if (entity.getType().isPresent()) {
                    nbt.setString("type", EntityList.getKey(((SpongeEntityType) entity.getType().get()).entityClass).toString());
                }
                nbt.setString("name", entity.getName());
                component = new TextComponentString(nbt.toString());
                break;
            }
        case SHOW_ITEM:
            {
                ItemStack item = (ItemStack) ((ItemStackSnapshot) action.getResult()).createStack();
                NBTTagCompound nbt = new NBTTagCompound();
                item.writeToNBT(nbt);
                component = new TextComponentString(nbt.toString());
                break;
            }
        case SHOW_TEXT:
            component = SpongeTexts.toComponent((Text) action.getResult());
            break;
        default:
            throw new AssertionError();
    }
    HoverEvent event = new HoverEvent(type, component);
    ((IMixinHoverEvent) event).setHandle(action);
    return event;
}
Also used : HoverEvent(net.minecraft.util.text.event.HoverEvent) IMixinHoverEvent(org.spongepowered.common.interfaces.text.IMixinHoverEvent) ITextComponent(net.minecraft.util.text.ITextComponent) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Text(org.spongepowered.api.text.Text) IMixinHoverEvent(org.spongepowered.common.interfaces.text.IMixinHoverEvent) TextComponentString(net.minecraft.util.text.TextComponentString) HoverAction(org.spongepowered.api.text.action.HoverAction) SpongeEntityType(org.spongepowered.common.entity.SpongeEntityType) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) ItemStack(net.minecraft.item.ItemStack)

Example 7 with SpongeEntityType

use of org.spongepowered.common.entity.SpongeEntityType in project SpongeCommon by SpongePowered.

the class EntityActivationRange method initializeEntityActivationState.

/**
 * These entities are excluded from Activation range checks.
 *
 * @param entity Entity to check
 * @return boolean If it should always tick.
 */
public static boolean initializeEntityActivationState(Entity entity) {
    if (((IMixinWorld) entity.world).isFake()) {
        return true;
    }
    // types that should always be active
    if (entity instanceof EntityPlayer && !SpongeImplHooks.isFakePlayer(entity) || entity instanceof EntityThrowable || entity instanceof EntityDragon || entity instanceof MultiPartEntityPart || entity instanceof EntityWither || entity instanceof EntityFireball || entity instanceof EntityWeatherEffect || entity instanceof EntityTNTPrimed || entity instanceof EntityEnderCrystal || entity instanceof EntityFireworkRocket || // Always tick falling blocks
    entity instanceof EntityFallingBlock) {
        return true;
    }
    EntityActivationRangeCategory config = ((IMixinWorldServer) entity.world).getActiveConfig().getConfig().getEntityActivationRange();
    EntityType type = ((org.spongepowered.api.entity.Entity) entity).getType();
    IModData_Activation spongeEntity = (IModData_Activation) entity;
    if (type == EntityTypes.UNKNOWN || !(type instanceof SpongeEntityType)) {
        return false;
    }
    final SpongeEntityType spongeType = (SpongeEntityType) type;
    final byte activationType = spongeEntity.getActivationType();
    if (!spongeType.isActivationRangeInitialized()) {
        addEntityToConfig(entity.world, spongeType, activationType);
        spongeType.setActivationRangeInitialized(true);
    }
    EntityActivationModCategory entityMod = config.getModList().get(spongeType.getModId().toLowerCase());
    int defaultActivationRange = config.getDefaultRanges().get(activationTypeMappings.get(activationType));
    if (entityMod == null) {
        // use default activation range
        spongeEntity.setActivationRange(defaultActivationRange);
        if (defaultActivationRange <= 0) {
            return true;
        }
        return false;
    } else if (!entityMod.isEnabled()) {
        spongeEntity.setActivationRange(defaultActivationRange);
        return true;
    }
    Integer defaultModActivationRange = entityMod.getDefaultRanges().get(activationTypeMappings.get(activationType));
    Integer entityActivationRange = entityMod.getEntityList().get(type.getName().toLowerCase());
    if (defaultModActivationRange != null && entityActivationRange == null) {
        spongeEntity.setActivationRange(defaultModActivationRange);
        if (defaultModActivationRange <= 0) {
            return true;
        }
        return false;
    } else if (entityActivationRange != null) {
        spongeEntity.setActivationRange(entityActivationRange);
        if (entityActivationRange <= 0) {
            return true;
        }
    }
    return false;
}
Also used : EntityThrowable(net.minecraft.entity.projectile.EntityThrowable) EntityDragon(net.minecraft.entity.boss.EntityDragon) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) Entity(net.minecraft.entity.Entity) IModData_Activation(org.spongepowered.common.mixin.plugin.entityactivation.interfaces.IModData_Activation) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) EntityTNTPrimed(net.minecraft.entity.item.EntityTNTPrimed) EntityWeatherEffect(net.minecraft.entity.effect.EntityWeatherEffect) EntityEnderCrystal(net.minecraft.entity.item.EntityEnderCrystal) MultiPartEntityPart(net.minecraft.entity.MultiPartEntityPart) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) SpongeEntityType(org.spongepowered.common.entity.SpongeEntityType) EntityType(org.spongepowered.api.entity.EntityType) IMixinWorld(org.spongepowered.common.interfaces.world.IMixinWorld) EntityFireworkRocket(net.minecraft.entity.item.EntityFireworkRocket) SpongeEntityType(org.spongepowered.common.entity.SpongeEntityType) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityWither(net.minecraft.entity.boss.EntityWither) EntityActivationRangeCategory(org.spongepowered.common.config.category.EntityActivationRangeCategory) EntityActivationModCategory(org.spongepowered.common.config.category.EntityActivationModCategory) EntityFireball(net.minecraft.entity.projectile.EntityFireball)

Example 8 with SpongeEntityType

use of org.spongepowered.common.entity.SpongeEntityType in project SpongeCommon by SpongePowered.

the class EntityTypeRegistryModule method registerDefaults.

@Override
public void registerDefaults() {
    this.entityTypeMappings.put("item", newEntityTypeFromName("Item"));
    this.entityTypeMappings.put("experience_orb", newEntityTypeFromName("xp_orb"));
    this.entityTypeMappings.put("area_effect_cloud", newEntityTypeFromName("area_effect_cloud"));
    this.entityTypeMappings.put("dragon_fireball", newEntityTypeFromName("dragon_fireball"));
    this.entityTypeMappings.put("leash_hitch", newEntityTypeFromName("leash_knot"));
    this.entityTypeMappings.put("painting", newEntityTypeFromName("painting"));
    this.entityTypeMappings.put("tipped_arrow", newEntityTypeFromName("arrow"));
    this.entityTypeMappings.put("snowball", newEntityTypeFromName("snowball"));
    this.entityTypeMappings.put("fireball", newEntityTypeFromName("LargeFireball", "fireball"));
    this.entityTypeMappings.put("small_fireball", newEntityTypeFromName("small_fireball"));
    this.entityTypeMappings.put("ender_pearl", newEntityTypeFromName("ender_pearl"));
    this.entityTypeMappings.put("eye_of_ender", newEntityTypeFromName("eye_of_ender_signal"));
    this.entityTypeMappings.put("splash_potion", newEntityTypeFromName("potion"));
    this.entityTypeMappings.put("thrown_exp_bottle", newEntityTypeFromName("xp_bottle"));
    this.entityTypeMappings.put("item_frame", newEntityTypeFromName("item_frame"));
    this.entityTypeMappings.put("wither_skull", newEntityTypeFromName("wither_skull"));
    this.entityTypeMappings.put("primed_tnt", newEntityTypeFromName("tnt"));
    this.entityTypeMappings.put("falling_block", newEntityTypeFromName("falling_block"));
    this.entityTypeMappings.put("firework", newEntityTypeFromName("fireworks_rocket"));
    this.entityTypeMappings.put("armor_stand", newEntityTypeFromName("armor_stand"));
    this.entityTypeMappings.put("boat", newEntityTypeFromName("boat"));
    this.entityTypeMappings.put("rideable_minecart", newEntityTypeFromName("minecart"));
    this.entityTypeMappings.put("chested_minecart", newEntityTypeFromName("chest_minecart"));
    this.entityTypeMappings.put("furnace_minecart", newEntityTypeFromName("furnace_minecart"));
    this.entityTypeMappings.put("tnt_minecart", newEntityTypeFromName("tnt_minecart"));
    this.entityTypeMappings.put("hopper_minecart", newEntityTypeFromName("hopper_minecart"));
    this.entityTypeMappings.put("mob_spawner_minecart", newEntityTypeFromName("spawner_minecart"));
    this.entityTypeMappings.put("commandblock_minecart", newEntityTypeFromName("commandblock_minecart"));
    this.entityTypeMappings.put("evocation_fangs", newEntityTypeFromName("evocation_fangs"));
    this.entityTypeMappings.put("evocation_illager", newEntityTypeFromName("evocation_illager"));
    this.entityTypeMappings.put("vex", newEntityTypeFromName("vex"));
    this.entityTypeMappings.put("vindication_illager", newEntityTypeFromName("vindication_illager"));
    this.entityTypeMappings.put("creeper", newEntityTypeFromName("creeper"));
    this.entityTypeMappings.put("skeleton", newEntityTypeFromName("skeleton"));
    this.entityTypeMappings.put("stray", newEntityTypeFromName("stray"));
    this.entityTypeMappings.put("wither_skeleton", newEntityTypeFromName("wither_skeleton"));
    this.entityTypeMappings.put("spider", newEntityTypeFromName("spider"));
    this.entityTypeMappings.put("giant", newEntityTypeFromName("giant"));
    this.entityTypeMappings.put("zombie", newEntityTypeFromName("zombie"));
    this.entityTypeMappings.put("husk", newEntityTypeFromName("husk"));
    this.entityTypeMappings.put("slime", newEntityTypeFromName("slime"));
    this.entityTypeMappings.put("ghast", newEntityTypeFromName("ghast"));
    this.entityTypeMappings.put("pig_zombie", newEntityTypeFromName("zombie_pigman"));
    this.entityTypeMappings.put("enderman", newEntityTypeFromName("enderman"));
    this.entityTypeMappings.put("cave_spider", newEntityTypeFromName("cave_spider"));
    this.entityTypeMappings.put("silverfish", newEntityTypeFromName("silverfish"));
    this.entityTypeMappings.put("blaze", newEntityTypeFromName("blaze"));
    this.entityTypeMappings.put("magma_cube", newEntityTypeFromName("magma_cube"));
    this.entityTypeMappings.put("ender_dragon", newEntityTypeFromName("ender_dragon"));
    this.entityTypeMappings.put("wither", newEntityTypeFromName("wither"));
    this.entityTypeMappings.put("bat", newEntityTypeFromName("bat"));
    this.entityTypeMappings.put("witch", newEntityTypeFromName("witch"));
    this.entityTypeMappings.put("endermite", newEntityTypeFromName("endermite"));
    this.entityTypeMappings.put("guardian", newEntityTypeFromName("guardian"));
    this.entityTypeMappings.put("elder_guardian", newEntityTypeFromName("elder_guardian"));
    this.entityTypeMappings.put("pig", newEntityTypeFromName("pig"));
    this.entityTypeMappings.put("sheep", newEntityTypeFromName("sheep"));
    this.entityTypeMappings.put("cow", newEntityTypeFromName("cow"));
    this.entityTypeMappings.put("chicken", newEntityTypeFromName("chicken"));
    this.entityTypeMappings.put("squid", newEntityTypeFromName("squid"));
    this.entityTypeMappings.put("wolf", newEntityTypeFromName("wolf"));
    this.entityTypeMappings.put("mushroom_cow", newEntityTypeFromName("mooshroom"));
    this.entityTypeMappings.put("snowman", newEntityTypeFromName("snowman"));
    this.entityTypeMappings.put("ocelot", newEntityTypeFromName("Ocelot"));
    this.entityTypeMappings.put("iron_golem", newEntityTypeFromName("villager_golem"));
    this.entityTypeMappings.put("horse", newEntityTypeFromName("horse"));
    this.entityTypeMappings.put("skeleton_horse", newEntityTypeFromName("skeleton_horse"));
    this.entityTypeMappings.put("zombie_horse", newEntityTypeFromName("zombie_horse"));
    this.entityTypeMappings.put("donkey", newEntityTypeFromName("donkey"));
    this.entityTypeMappings.put("mule", newEntityTypeFromName("mule"));
    this.entityTypeMappings.put("llama", newEntityTypeFromName("llama"));
    this.entityTypeMappings.put("llama_spit", newEntityTypeFromName("llama_spit"));
    this.entityTypeMappings.put("rabbit", newEntityTypeFromName("rabbit"));
    this.entityTypeMappings.put("villager", newEntityTypeFromName("villager"));
    this.entityTypeMappings.put("zombie_villager", newEntityTypeFromName("zombie_villager"));
    this.entityTypeMappings.put("ender_crystal", newEntityTypeFromName("ender_crystal"));
    this.entityTypeMappings.put("shulker", newEntityTypeFromName("shulker"));
    this.entityTypeMappings.put("shulker_bullet", newEntityTypeFromName("shulker_bullet"));
    this.entityTypeMappings.put("spectral_arrow", newEntityTypeFromName("spectral_arrow"));
    this.entityTypeMappings.put("polar_bear", newEntityTypeFromName("polar_bear"));
    this.entityTypeMappings.put("egg", new SpongeEntityType(-1, "egg", EntityEgg.class, new SpongeTranslation("item.egg.name")));
    this.entityTypeMappings.put("fishing_hook", new SpongeEntityType(-2, "FishingHook", EntityFishHook.class, new SpongeTranslation("item.fishingRod.name")));
    this.entityTypeMappings.put("lightning", new SpongeEntityType(-3, "lightning", EntityLightningBolt.class, null));
    this.entityTypeMappings.put("weather", new SpongeEntityType(-4, "Weather", EntityWeatherEffect.class, new SpongeTranslation("soundCategory.weather")));
    this.entityTypeMappings.put("player", new SpongeEntityType(-5, "Player", EntityPlayerMP.class, new SpongeTranslation("soundCategory.player")));
    this.entityTypeMappings.put("complex_part", new SpongeEntityType(-6, "ComplexPart", MultiPartEntityPart.class, null));
    // TODO: Figure out what id to use, as negative ids no longer work
    this.entityTypeMappings.put("human", registerCustomEntity(EntityHuman.class, "human", "Human", 300, null));
    // this.entityClassToTypeMappings.put("human", new SpongeEntityType(-6))
    this.entityTypeMappings.put("parrot", newEntityTypeFromName("parrot"));
    this.entityTypeMappings.put("illusion_illager", newEntityTypeFromName("illusion_illager"));
}
Also used : EntityHuman(org.spongepowered.common.entity.living.human.EntityHuman) SpongeTranslation(org.spongepowered.common.text.translation.SpongeTranslation) SpongeEntityType(org.spongepowered.common.entity.SpongeEntityType) EntityFishHook(net.minecraft.entity.projectile.EntityFishHook) EntityWeatherEffect(net.minecraft.entity.effect.EntityWeatherEffect) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) MultiPartEntityPart(net.minecraft.entity.MultiPartEntityPart) EntityLightningBolt(net.minecraft.entity.effect.EntityLightningBolt) EntityEgg(net.minecraft.entity.projectile.EntityEgg)

Aggregations

SpongeEntityType (org.spongepowered.common.entity.SpongeEntityType)8 EntityType (org.spongepowered.api.entity.EntityType)3 MultiPartEntityPart (net.minecraft.entity.MultiPartEntityPart)2 EntityWeatherEffect (net.minecraft.entity.effect.EntityWeatherEffect)2 ItemStack (net.minecraft.item.ItemStack)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 SpongeTranslation (org.spongepowered.common.text.translation.SpongeTranslation)2 Entity (net.minecraft.entity.Entity)1 EnumCreatureType (net.minecraft.entity.EnumCreatureType)1 EntityDragon (net.minecraft.entity.boss.EntityDragon)1 EntityWither (net.minecraft.entity.boss.EntityWither)1 EntityLightningBolt (net.minecraft.entity.effect.EntityLightningBolt)1 EntityEnderCrystal (net.minecraft.entity.item.EntityEnderCrystal)1 EntityFallingBlock (net.minecraft.entity.item.EntityFallingBlock)1 EntityFireworkRocket (net.minecraft.entity.item.EntityFireworkRocket)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityTNTPrimed (net.minecraft.entity.item.EntityTNTPrimed)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 EntityEgg (net.minecraft.entity.projectile.EntityEgg)1