Search in sources :

Example 1 with AbstractBody

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

the class ContainerPlayerBody method fromNetwork.

public static ContainerPlayerBody fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
    PlayerEntity player = inv.player;
    double range = player.getAttributeValue(ForgeMod.REACH_DISTANCE.get());
    Vector3d eyeStart = player.getEyePosition(0F);
    Vector3d eyeEnd = eyeStart.add(player.getLook(0F).mul(range, range, range));
    AbstractBody likelyBody = null;
    double minDist = Double.MAX_VALUE;
    for (AbstractBody body : player.getEntityWorld().getEntitiesWithinAABB(AbstractBody.class, player.getBoundingBox().grow(range))) {
        double dist = body.getDistance(player);
        if (body.getBoundingBox().intersects(eyeStart, eyeEnd))
            if (dist < minDist) {
                likelyBody = body;
                minDist = dist;
            }
    }
    if (likelyBody != null && likelyBody.isPlayer() && likelyBody.getSoul() != null)
        return new ContainerPlayerBody(windowId, inv, ((PlayerEntity) likelyBody.getSoul()).inventory, likelyBody);
    return null;
}
Also used : Vector3d(net.minecraft.util.math.vector.Vector3d) AbstractBody(com.lying.variousoddities.entity.AbstractBody) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 2 with AbstractBody

use of com.lying.variousoddities.entity.AbstractBody 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)

Example 3 with AbstractBody

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

the class ContainerBody method fromNetwork.

public static ContainerBody fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
    PlayerEntity player = inv.player;
    double range = player.getAttributeValue(ForgeMod.REACH_DISTANCE.get());
    Vector3d eyeStart = player.getEyePosition(0F);
    Vector3d eyeEnd = eyeStart.add(player.getLook(0F).mul(range, range, range));
    AbstractBody likelyBody = null;
    double minDist = Double.MAX_VALUE;
    for (AbstractBody body : player.getEntityWorld().getEntitiesWithinAABB(AbstractBody.class, player.getBoundingBox().grow(range))) {
        double dist = body.getDistance(player);
        if (body.getBoundingBox().intersects(eyeStart, eyeEnd))
            if (dist < minDist) {
                likelyBody = body;
                minDist = dist;
            }
    }
    if (likelyBody != null)
        return new ContainerBody(windowId, inv, likelyBody.getInventory(), likelyBody);
    return null;
}
Also used : Vector3d(net.minecraft.util.math.vector.Vector3d) AbstractBody(com.lying.variousoddities.entity.AbstractBody) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

AbstractBody (com.lying.variousoddities.entity.AbstractBody)3 PlayerEntity (net.minecraft.entity.player.PlayerEntity)3 Lists (com.google.common.collect.Lists)1 VariousOddities (com.lying.variousoddities.VariousOddities)1 IDefaultSpecies (com.lying.variousoddities.api.entity.IDefaultSpecies)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 EntityBodyUnconscious (com.lying.variousoddities.entity.EntityBodyUnconscious)1 VOPotions (com.lying.variousoddities.init.VOPotions)1 VORegistries (com.lying.variousoddities.init.VORegistries)1 PacketHandler (com.lying.variousoddities.network.PacketHandler)1 PacketSyncAir (com.lying.variousoddities.network.PacketSyncAir)1 PacketSyncBludgeoning (com.lying.variousoddities.network.PacketSyncBludgeoning)1