Search in sources :

Example 1 with EntityBodyCorpse

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

the class VOBusServer method corpseSpawnEvent.

/**
 * Spawn a corpse when a Needled creature dies
 */
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void corpseSpawnEvent(LivingDeathEvent event) {
    LivingEntity victim = event.getEntityLiving();
    World world = victim.getEntityWorld();
    if (event.getSource() == DamageSource.OUT_OF_WORLD || event.isCanceled())
        return;
    if (!(victim instanceof MobEntity || victim instanceof PlayerEntity))
        return;
    boolean spawnCorpse = false;
    switch(ConfigVO.GENERAL.corpseSpawnRule()) {
        case PLAYERS_ONLY:
            spawnCorpse = victim.getType() == EntityType.PLAYER;
            break;
        case NEEDLED_ONLY:
            spawnCorpse = victim.isPotionActive(VOPotions.NEEDLED);
            break;
        case PLAYERS_AND_NEEDLED:
            spawnCorpse = victim.getType() == EntityType.PLAYER || victim.isPotionActive(VOPotions.NEEDLED);
            break;
        case ALWAYS:
            spawnCorpse = true;
            break;
        default:
            spawnCorpse = false;
            break;
    }
    if (spawnCorpse) {
        AbstractBody.clearNearbyAttackTargetsOf(victim);
        victim.removeActivePotionEffect(VOPotions.NEEDLED);
        EntityBodyCorpse corpse = EntityBodyCorpse.createCorpseFrom(victim);
        if (victim.getType() == EntityType.PLAYER) {
            PlayerData playerData = PlayerData.forPlayer((PlayerEntity) victim);
            // If player is already dead, let them die as normal
            if (PlayerData.isPlayerBodyDead((PlayerEntity) victim))
                return;
            else // Otherwise, cancel the event and set them to be dead
            if (playerData.setConditionIsDead(corpse.getUniqueID())) {
                event.setCanceled(true);
                world.getPlayers().forEach((player) -> {
                    player.sendMessage(event.getSource().getDeathMessage(victim), victim.getUniqueID());
                });
                return;
            }
        } else if (corpse != null && !world.isRemote) {
            corpse.setPocketInventory(LivingData.forEntity(victim).getPocketInventory());
            world.addEntity(corpse);
        }
    } else if (!world.isRemote) {
        LivingData livingData = LivingData.forEntity(victim);
        for (ItemStack stack : livingData.getPocketInventory()) if (!stack.isEmpty())
            victim.entityDropItem(stack, victim.getRNG().nextFloat());
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) EntityType(net.minecraft.entity.EntityType) ServerWorld(net.minecraft.world.server.ServerWorld) EntityTravelToDimensionEvent(net.minecraftforge.event.entity.EntityTravelToDimensionEvent) BodyCondition(com.lying.variousoddities.capabilities.PlayerData.BodyCondition) AbilityRegistry(com.lying.variousoddities.species.abilities.AbilityRegistry) VORegistries(com.lying.variousoddities.init.VORegistries) CompoundNBT(net.minecraft.nbt.CompoundNBT) Random(java.util.Random) EntityAIFrightened(com.lying.variousoddities.entity.ai.EntityAIFrightened) VOPotions(com.lying.variousoddities.init.VOPotions) VOEntities(com.lying.variousoddities.init.VOEntities) AbstractGoblinWolf(com.lying.variousoddities.entity.AbstractGoblinWolf) EventPriority(net.minecraftforge.eventbus.api.EventPriority) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) ListNBT(net.minecraft.nbt.ListNBT) PlayerEvent(net.minecraftforge.event.entity.player.PlayerEvent) SoulCondition(com.lying.variousoddities.capabilities.PlayerData.SoulCondition) PlayerEntity(net.minecraft.entity.player.PlayerEntity) AbilitySize(com.lying.variousoddities.species.abilities.AbilitySize) LivingEntity(net.minecraft.entity.LivingEntity) PacketSyncSpecies(com.lying.variousoddities.network.PacketSyncSpecies) Reference(com.lying.variousoddities.reference.Reference) LivingWakeUpEvent(com.lying.variousoddities.api.event.LivingWakeUpEvent) EntityGoblin(com.lying.variousoddities.entity.hostile.EntityGoblin) EntityWorg(com.lying.variousoddities.entity.passive.EntityWorg) PacketSyncBludgeoning(com.lying.variousoddities.network.PacketSyncBludgeoning) ConfigVO(com.lying.variousoddities.config.ConfigVO) PlayerRespawnEvent(net.minecraftforge.event.entity.player.PlayerEvent.PlayerRespawnEvent) List(java.util.List) EntityJoinWorldEvent(net.minecraftforge.event.entity.EntityJoinWorldEvent) EntityRatGiant(com.lying.variousoddities.entity.hostile.EntityRatGiant) PlayerData(com.lying.variousoddities.capabilities.PlayerData) PacketSpeciesOpenScreen(com.lying.variousoddities.network.PacketSpeciesOpenScreen) AbstractBody(com.lying.variousoddities.entity.AbstractBody) PlayerLoggedInEvent(net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent) EntityTeleportEvent(net.minecraftforge.event.entity.living.EntityTeleportEvent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) FireballEntity(net.minecraft.entity.projectile.FireballEntity) FireworkExplosionEvent(com.lying.variousoddities.api.event.FireworkExplosionEvent) PacketSyncLivingData(com.lying.variousoddities.network.PacketSyncLivingData) PacketSyncAir(com.lying.variousoddities.network.PacketSyncAir) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) PotionSleep(com.lying.variousoddities.potion.PotionSleep) GetEntityTypesEvent(com.lying.variousoddities.api.event.CreatureTypeEvent.GetEntityTypesEvent) EntityGhastling(com.lying.variousoddities.entity.passive.EntityGhastling) LivingData(com.lying.variousoddities.capabilities.LivingData) CreatureEntity(net.minecraft.entity.CreatureEntity) ItemStack(net.minecraft.item.ItemStack) EffectInstance(net.minecraft.potion.EffectInstance) EntityBodyCorpse(com.lying.variousoddities.entity.EntityBodyCorpse) NearestAttackableTargetGoal(net.minecraft.entity.ai.goal.NearestAttackableTargetGoal) EntityAISleep(com.lying.variousoddities.entity.ai.EntityAISleep) MobEntity(net.minecraft.entity.MobEntity) Conditions(com.lying.variousoddities.condition.Conditions) PlayerChangeConditionEvent(com.lying.variousoddities.api.event.PlayerChangeConditionEvent) Entity(net.minecraft.entity.Entity) Effects(net.minecraft.potion.Effects) EntityRat(com.lying.variousoddities.entity.passive.EntityRat) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) AbilityAffectEntityEvent(com.lying.variousoddities.api.event.AbilityEvent.AbilityAffectEntityEvent) AttachCapabilitiesEvent(net.minecraftforge.event.AttachCapabilitiesEvent) DamageSource(net.minecraft.util.DamageSource) LivingHurtEvent(net.minecraftforge.event.entity.living.LivingHurtEvent) PacketHandler(com.lying.variousoddities.network.PacketHandler) EntityBodyUnconscious(com.lying.variousoddities.entity.EntityBodyUnconscious) MinecraftForge(net.minecraftforge.common.MinecraftForge) LivingDeathEvent(net.minecraftforge.event.entity.living.LivingDeathEvent) VODamageSource(com.lying.variousoddities.init.VODamageSource) EntityDamageSource(net.minecraft.util.EntityDamageSource) ResourceLocation(net.minecraft.util.ResourceLocation) EnumCreatureType(com.lying.variousoddities.species.types.EnumCreatureType) EntityBodyCorpse(com.lying.variousoddities.entity.EntityBodyCorpse) PacketSyncLivingData(com.lying.variousoddities.network.PacketSyncLivingData) LivingData(com.lying.variousoddities.capabilities.LivingData) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) PlayerData(com.lying.variousoddities.capabilities.PlayerData) MobEntity(net.minecraft.entity.MobEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with EntityBodyCorpse

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

the class VOBusServer method onPlayerConditionChange.

/**
 * Spawns an appropriate body (if any) in response to a player's change in condition.
 * @param event
 */
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void onPlayerConditionChange(PlayerChangeConditionEvent event) {
    if (event.bodyChange()) {
        PlayerEntity player = event.getPlayer();
        PlayerData data = PlayerData.forPlayer(player);
        World world = player.getEntityWorld();
        if (!(event.getNewBody() == BodyCondition.ALIVE && event.getNewSoul() == SoulCondition.ALIVE))
            AbstractBody.clearNearbyAttackTargetsOf(player);
        switch(event.getNewBody()) {
            case DEAD:
                player.removeActivePotionEffect(VOPotions.NEEDLED);
                EntityBodyCorpse corpse = EntityBodyCorpse.createCorpseFrom(player);
                data.setBodyUUID(corpse.getUniqueID());
                player.setHealth(player.getMaxHealth());
                if (!world.isRemote)
                    world.addEntity(corpse);
                break;
            case UNCONSCIOUS:
                LivingEntity body = EntityBodyUnconscious.createBodyFrom(player);
                data.setBodyUUID(body.getUniqueID());
                if (!world.isRemote)
                    world.addEntity(body);
                break;
            case ALIVE:
            default:
                break;
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) EntityBodyCorpse(com.lying.variousoddities.entity.EntityBodyCorpse) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World) PlayerData(com.lying.variousoddities.capabilities.PlayerData) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

PlayerData (com.lying.variousoddities.capabilities.PlayerData)2 EntityBodyCorpse (com.lying.variousoddities.entity.EntityBodyCorpse)2 LivingEntity (net.minecraft.entity.LivingEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 World (net.minecraft.world.World)2 ServerWorld (net.minecraft.world.server.ServerWorld)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 AbilityAffectEntityEvent (com.lying.variousoddities.api.event.AbilityEvent.AbilityAffectEntityEvent)1 GetEntityTypesEvent (com.lying.variousoddities.api.event.CreatureTypeEvent.GetEntityTypesEvent)1 FireworkExplosionEvent (com.lying.variousoddities.api.event.FireworkExplosionEvent)1 LivingWakeUpEvent (com.lying.variousoddities.api.event.LivingWakeUpEvent)1 PlayerChangeConditionEvent (com.lying.variousoddities.api.event.PlayerChangeConditionEvent)1 LivingData (com.lying.variousoddities.capabilities.LivingData)1 BodyCondition (com.lying.variousoddities.capabilities.PlayerData.BodyCondition)1 SoulCondition (com.lying.variousoddities.capabilities.PlayerData.SoulCondition)1 Conditions (com.lying.variousoddities.condition.Conditions)1 ConfigVO (com.lying.variousoddities.config.ConfigVO)1 AbstractBody (com.lying.variousoddities.entity.AbstractBody)1 AbstractGoblinWolf (com.lying.variousoddities.entity.AbstractGoblinWolf)1