Search in sources :

Example 1 with IDefaultSpecies

use of com.lying.variousoddities.api.entity.IDefaultSpecies in project VariousOddities by Lyinginbedmon.

the class TypesManager method getMobTypes.

public List<EnumCreatureType> getMobTypes(ResourceLocation registryName) {
    if (mobTypeCache.containsKey(registryName))
        return mobTypeCache.get(registryName);
    List<EnumCreatureType> types = new ArrayList<>();
    Optional<EntityType<?>> entityType = EntityType.byKey(registryName.toString());
    if (entityType.isPresent() && world != null) {
        Entity object = entityType.get().create(world);
        if (object != null && object instanceof IDefaultSpecies)
            types.addAll(((IDefaultSpecies) object).defaultCreatureTypes());
    }
    if (types.isEmpty())
        for (EnumCreatureType type : typeToMob.keySet()) for (ResourceLocation entry : typeToMob.getOrDefault(type, Collections.emptyList())) if (entry.equals(registryName)) {
            types.add(type);
            break;
        }
    mobTypeCache.put(registryName, types);
    return types;
}
Also used : EntityType(net.minecraft.entity.EntityType) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) IDefaultSpecies(com.lying.variousoddities.api.entity.IDefaultSpecies) EnumCreatureType(com.lying.variousoddities.species.types.EnumCreatureType) ResourceLocation(net.minecraft.util.ResourceLocation) ArrayList(java.util.ArrayList)

Example 2 with IDefaultSpecies

use of com.lying.variousoddities.api.entity.IDefaultSpecies in project VariousOddities by Lyinginbedmon.

the class LivingData method tick.

public void tick(LivingEntity entity) {
    IDefaultSpecies mobDefaults = entity instanceof IDefaultSpecies ? (IDefaultSpecies) entity : null;
    World world = entity.getEntityWorld();
    if (!this.initialised && (!isPlayer || ((PlayerEntity) entity).getGameProfile() != null)) {
        // TODO Check default home dimension registry for creature before setting to current dim
        if (mobDefaults != null) {
            if (((IDefaultSpecies) entity).defaultHomeDimension() != null)
                setHomeDimension(((IDefaultSpecies) entity).defaultHomeDimension());
        } else
            setHomeDimension(world.getDimensionKey().getLocation());
        if (isPlayer) {
            PlayerEntity player = (PlayerEntity) entity;
            String name = player.getName().getUnformattedComponentText();
            if (CreatureTypeDefaults.isTypedPatron(name)) {
                setCustomTypes(CreatureTypeDefaults.getPatronTypes(name));
                VariousOddities.log.info("Initialised patron " + name + " as " + EnumCreatureType.getTypes(player).toHeader().getString());
            }
        } else {
            if (mobDefaults != null) {
                if (mobDefaults.defaultSpecies() != null) {
                    Species defaultSpecies = SpeciesRegistry.getSpecies(mobDefaults.defaultSpecies());
                    if (defaultSpecies != null)
                        setSpecies(defaultSpecies);
                }
                if (!mobDefaults.defaultTemplates().isEmpty())
                    mobDefaults.defaultTemplates().forEach((temp) -> {
                        Template template = VORegistries.TEMPLATES.getOrDefault(temp, null);
                        if (template != null)
                            addTemplateInitial(template);
                    });
                if (!mobDefaults.defaultCreatureTypes().isEmpty())
                    mobDefaults.defaultCreatureTypes().forEach((type) -> {
                        addCustomType(type);
                    });
                if (!mobDefaults.defaultAbilities().isEmpty())
                    mobDefaults.defaultAbilities().forEach((ability) -> {
                        this.abilities.addCustomAbility(AbilityRegistry.getAbility(ability.writeAtomically(new CompoundNBT())));
                    });
            } else {
                Species guess = SpeciesRegistry.getSpecies(entity.getType().getRegistryName());
                if (guess != null)
                    setSpecies(guess);
            }
            setSelectedSpecies(true);
        }
        this.initialised = true;
        markDirty();
    }
    if (!ConfigVO.MOBS.selectSpeciesOnLogin.get())
        setSelectedSpecies(true);
    handleTypes(entity, world);
    PlayerEntity player = null;
    if (isPlayer)
        player = (PlayerEntity) entity;
    if (isPlayer)
        handleHealth(player);
    ActionSet actions = ActionSet.fromTypes(this.entity, this.prevTypes);
    // Prevent phantoms due to sleeplessness
    if (!actions.sleeps()) {
        if (isPlayer && !world.isRemote) {
            ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
            ServerStatisticsManager statManager = serverPlayer.getStats();
            statManager.setValue(serverPlayer, Stats.CUSTOM.get(Stats.TIME_SINCE_REST), 0);
        }
    }
    handleAir(actions.breathes(), entity);
    if (this.bludgeoning > 0F)
        if (--this.recoveryTimer <= 0)
            setBludgeoning(this.bludgeoning - 1F);
    if (isUnconscious() != isActuallyUnconscious()) {
        if (isPlayer) {
            if (isUnconscious())
                PlayerData.forPlayer((PlayerEntity) entity).setBodyCondition(BodyCondition.UNCONSCIOUS);
            this.isUnconscious = isUnconscious();
        } else {
            if (isUnconscious()) {
                AbstractBody.clearNearbyAttackTargetsOf(entity);
                // Spawn body
                LivingEntity body = EntityBodyUnconscious.createBodyFrom(entity);
                ((AbstractBody) body).setPocketInventory(getPocketInventory());
                if (entity.isAddedToWorld()) {
                    // TODO Play crit attack noise when creature is knocked unconscious
                    if (!world.isRemote) {
                        world.addEntity(body);
                        entity.remove();
                    }
                }
            }
            this.isUnconscious = isUnconscious();
        }
        markDirty();
    }
    abilities.tick();
    handleConditions();
    if (this.dirty) {
        if (this.entity != null && !this.entity.getEntityWorld().isRemote)
            PacketHandler.sendToNearby(entity.getEntityWorld(), entity, new PacketSyncLivingData(entity.getUniqueID(), this));
        this.dirty = false;
    }
    if (world.isRemote && --this.potionSyncTimer <= 0) {
        this.potionSyncTimer = Reference.Values.TICKS_PER_MINUTE;
    // TODO Ping server for visualPotion value
    }
}
Also used : EntityType(net.minecraft.entity.EntityType) BodyCondition(com.lying.variousoddities.capabilities.PlayerData.BodyCondition) AbilityRegistry(com.lying.variousoddities.species.abilities.AbilityRegistry) CapabilityManager(net.minecraftforge.common.capabilities.CapabilityManager) VORegistries(com.lying.variousoddities.init.VORegistries) SpeciesRegistry(com.lying.variousoddities.species.SpeciesRegistry) CompoundNBT(net.minecraft.nbt.CompoundNBT) AbilityGetBreathableFluidEvent(com.lying.variousoddities.api.event.AbilityEvent.AbilityGetBreathableFluidEvent) VOPotions(com.lying.variousoddities.init.VOPotions) Direction(net.minecraft.util.Direction) Map(java.util.Map) NonNullList(net.minecraft.util.NonNullList) TypeBus(com.lying.variousoddities.species.types.TypeBus) VariousOddities(com.lying.variousoddities.VariousOddities) Species(com.lying.variousoddities.species.Species) ListNBT(net.minecraft.nbt.ListNBT) ModifiableAttributeInstance(net.minecraft.entity.ai.attributes.ModifiableAttributeInstance) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) Collection(java.util.Collection) CreatureTypeDefaults(com.lying.variousoddities.species.types.CreatureTypeDefaults) Reference(com.lying.variousoddities.reference.Reference) UUID(java.util.UUID) CapabilityInject(net.minecraftforge.common.capabilities.CapabilityInject) EnchantmentHelper(net.minecraft.enchantment.EnchantmentHelper) Capability(net.minecraftforge.common.capabilities.Capability) PacketSyncBludgeoning(com.lying.variousoddities.network.PacketSyncBludgeoning) ConfigVO(com.lying.variousoddities.config.ConfigVO) SpeciesInstance(com.lying.variousoddities.species.Species.SpeciesInstance) List(java.util.List) Condition(com.lying.variousoddities.condition.Condition) AbstractBody(com.lying.variousoddities.entity.AbstractBody) SpeciesEvent(com.lying.variousoddities.api.event.SpeciesEvent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ServerStatisticsManager(net.minecraft.stats.ServerStatisticsManager) PacketSyncLivingData(com.lying.variousoddities.network.PacketSyncLivingData) PacketSyncAir(com.lying.variousoddities.network.PacketSyncAir) EffectUtils(net.minecraft.potion.EffectUtils) Mark(com.lying.variousoddities.utility.CompanionMarking.Mark) HashMap(java.util.HashMap) Effect(net.minecraft.potion.Effect) ArrayList(java.util.ArrayList) LazyOptional(net.minecraftforge.common.util.LazyOptional) ItemStack(net.minecraft.item.ItemStack) Lists(com.google.common.collect.Lists) Attributes(net.minecraft.entity.ai.attributes.Attributes) DataHelper(com.lying.variousoddities.utility.DataHelper) ConditionInstance(com.lying.variousoddities.condition.ConditionInstance) Stats(net.minecraft.stats.Stats) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) TypeApplyEvent(com.lying.variousoddities.api.event.CreatureTypeEvent.TypeApplyEvent) INBT(net.minecraft.nbt.INBT) TemplateApplied(com.lying.variousoddities.api.event.SpeciesEvent.TemplateApplied) StringNBT(net.minecraft.nbt.StringNBT) Effects(net.minecraft.potion.Effects) Template(com.lying.variousoddities.species.Template) PacketVisualPotion(com.lying.variousoddities.network.PacketVisualPotion) FluidTags(net.minecraft.tags.FluidTags) World(net.minecraft.world.World) ITag(net.minecraft.tags.ITag) BlockPos(net.minecraft.util.math.BlockPos) TypeRemoveEvent(com.lying.variousoddities.api.event.CreatureTypeEvent.TypeRemoveEvent) ActionSet(com.lying.variousoddities.species.types.EnumCreatureType.ActionSet) DamageSource(net.minecraft.util.DamageSource) Pair(com.mojang.datafixers.util.Pair) Blocks(net.minecraft.block.Blocks) PacketHandler(com.lying.variousoddities.network.PacketHandler) EntityBodyUnconscious(com.lying.variousoddities.entity.EntityBodyUnconscious) MinecraftForge(net.minecraftforge.common.MinecraftForge) ICapabilitySerializable(net.minecraftforge.common.capabilities.ICapabilitySerializable) ResourceLocation(net.minecraft.util.ResourceLocation) EnumCreatureType(com.lying.variousoddities.species.types.EnumCreatureType) Fluid(net.minecraft.fluid.Fluid) IDefaultSpecies(com.lying.variousoddities.api.entity.IDefaultSpecies) CompoundNBT(net.minecraft.nbt.CompoundNBT) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) World(net.minecraft.world.World) PacketSyncLivingData(com.lying.variousoddities.network.PacketSyncLivingData) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Template(com.lying.variousoddities.species.Template) ActionSet(com.lying.variousoddities.species.types.EnumCreatureType.ActionSet) LivingEntity(net.minecraft.entity.LivingEntity) IDefaultSpecies(com.lying.variousoddities.api.entity.IDefaultSpecies) ServerStatisticsManager(net.minecraft.stats.ServerStatisticsManager) AbstractBody(com.lying.variousoddities.entity.AbstractBody) Species(com.lying.variousoddities.species.Species) IDefaultSpecies(com.lying.variousoddities.api.entity.IDefaultSpecies)

Aggregations

IDefaultSpecies (com.lying.variousoddities.api.entity.IDefaultSpecies)2 EnumCreatureType (com.lying.variousoddities.species.types.EnumCreatureType)2 ArrayList (java.util.ArrayList)2 EntityType (net.minecraft.entity.EntityType)2 LivingEntity (net.minecraft.entity.LivingEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 Lists (com.google.common.collect.Lists)1 VariousOddities (com.lying.variousoddities.VariousOddities)1 AbilityGetBreathableFluidEvent (com.lying.variousoddities.api.event.AbilityEvent.AbilityGetBreathableFluidEvent)1 TypeApplyEvent (com.lying.variousoddities.api.event.CreatureTypeEvent.TypeApplyEvent)1 TypeRemoveEvent (com.lying.variousoddities.api.event.CreatureTypeEvent.TypeRemoveEvent)1 SpeciesEvent (com.lying.variousoddities.api.event.SpeciesEvent)1 TemplateApplied (com.lying.variousoddities.api.event.SpeciesEvent.TemplateApplied)1 BodyCondition (com.lying.variousoddities.capabilities.PlayerData.BodyCondition)1 Condition (com.lying.variousoddities.condition.Condition)1 ConditionInstance (com.lying.variousoddities.condition.ConditionInstance)1 ConfigVO (com.lying.variousoddities.config.ConfigVO)1 AbstractBody (com.lying.variousoddities.entity.AbstractBody)1