Search in sources :

Example 1 with PacketSyncLivingData

use of com.lying.variousoddities.network.PacketSyncLivingData in project VariousOddities by Lyinginbedmon.

the class VOBusServer method onPlayerLogInEvent.

@SubscribeEvent
public static void onPlayerLogInEvent(PlayerLoggedInEvent event) {
    PlayerEntity player = event.getPlayer();
    PacketHandler.sendTo((ServerPlayerEntity) player, new PacketSyncSpecies(VORegistries.SPECIES));
    LivingData data = LivingData.forEntity(player);
    if (data != null) {
        PacketHandler.sendToAll((ServerWorld) player.getEntityWorld(), new PacketSyncLivingData(player.getUniqueID(), data));
        data.getAbilities().markDirty();
        if (!data.hasSelectedSpecies() && ConfigVO.MOBS.selectSpeciesOnLogin.get()) {
            if (!player.getEntityWorld().isRemote)
                PacketHandler.sendTo((ServerPlayerEntity) player, new PacketSpeciesOpenScreen());
            player.addPotionEffect(new EffectInstance(Effects.RESISTANCE, Reference.Values.TICKS_PER_MINUTE * 15, 15, true, false));
        }
    }
}
Also used : PacketSpeciesOpenScreen(com.lying.variousoddities.network.PacketSpeciesOpenScreen) PacketSyncLivingData(com.lying.variousoddities.network.PacketSyncLivingData) LivingData(com.lying.variousoddities.capabilities.LivingData) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) PacketSyncSpecies(com.lying.variousoddities.network.PacketSyncSpecies) PacketSyncLivingData(com.lying.variousoddities.network.PacketSyncLivingData) EffectInstance(net.minecraft.potion.EffectInstance) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with PacketSyncLivingData

use of com.lying.variousoddities.network.PacketSyncLivingData in project VariousOddities by Lyinginbedmon.

the class VOBusServer method addEntityBehaviours.

@SubscribeEvent
public static void addEntityBehaviours(EntityJoinWorldEvent event) {
    Entity theEntity = event.getEntity();
    if (theEntity instanceof LivingEntity && !theEntity.getEntityWorld().isRemote) {
        LivingData data = LivingData.forEntity((LivingEntity) theEntity);
        if (data != null && !theEntity.getEntityWorld().isRemote)
            PacketHandler.sendToAll((ServerWorld) theEntity.getEntityWorld(), new PacketSyncLivingData(theEntity.getUniqueID(), data));
    }
    if (theEntity.getType() == EntityType.CAT || theEntity.getType() == EntityType.OCELOT) {
        MobEntity feline = (MobEntity) theEntity;
        if (ConfigVO.MOBS.aiSettings.isOddityAIEnabled(VOEntities.RAT))
            feline.targetSelector.addGoal(1, new NearestAttackableTargetGoal<EntityRat>(feline, EntityRat.class, true));
        if (ConfigVO.MOBS.aiSettings.isOddityAIEnabled(VOEntities.RAT_GIANT))
            feline.targetSelector.addGoal(1, new NearestAttackableTargetGoal<EntityRatGiant>(feline, EntityRatGiant.class, true));
    }
    // Add sleep AI to mobs
    if (theEntity instanceof MobEntity) {
        MobEntity living = (MobEntity) theEntity;
        living.goalSelector.addGoal(1, new EntityAISleep(living));
        if (living instanceof CreatureEntity)
            living.goalSelector.addGoal(1, new EntityAIFrightened((CreatureEntity) living));
    }
    // Spook worgs
    if (event.getEntity().getType() == EntityType.LIGHTNING_BOLT) {
        BlockPos pos = event.getEntity().getPosition();
        AxisAlignedBB bounds = new AxisAlignedBB(0, 0, 0, 1, 256, 1).offset(pos.getX(), 0, pos.getZ()).grow(128, 0, 128);
        for (EntityWorg worg : event.getEntity().getEntityWorld().getEntitiesWithinAABB(EntityWorg.class, bounds)) worg.spook();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) FireballEntity(net.minecraft.entity.projectile.FireballEntity) CreatureEntity(net.minecraft.entity.CreatureEntity) MobEntity(net.minecraft.entity.MobEntity) Entity(net.minecraft.entity.Entity) PacketSyncLivingData(com.lying.variousoddities.network.PacketSyncLivingData) LivingData(com.lying.variousoddities.capabilities.LivingData) NearestAttackableTargetGoal(net.minecraft.entity.ai.goal.NearestAttackableTargetGoal) PacketSyncLivingData(com.lying.variousoddities.network.PacketSyncLivingData) CreatureEntity(net.minecraft.entity.CreatureEntity) EntityAISleep(com.lying.variousoddities.entity.ai.EntityAISleep) LivingEntity(net.minecraft.entity.LivingEntity) ServerWorld(net.minecraft.world.server.ServerWorld) EntityAIFrightened(com.lying.variousoddities.entity.ai.EntityAIFrightened) BlockPos(net.minecraft.util.math.BlockPos) MobEntity(net.minecraft.entity.MobEntity) EntityWorg(com.lying.variousoddities.entity.passive.EntityWorg) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 3 with PacketSyncLivingData

use of com.lying.variousoddities.network.PacketSyncLivingData 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

PacketSyncLivingData (com.lying.variousoddities.network.PacketSyncLivingData)3 PlayerEntity (net.minecraft.entity.player.PlayerEntity)3 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)3 LivingData (com.lying.variousoddities.capabilities.LivingData)2 LivingEntity (net.minecraft.entity.LivingEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 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 AbstractBody (com.lying.variousoddities.entity.AbstractBody)1 EntityBodyUnconscious (com.lying.variousoddities.entity.EntityBodyUnconscious)1