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());
}
}
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;
}
}
}
Aggregations