net.minecraftforge.event.entity.living.LivingDeathEvent Java Examples

The following examples show how to use net.minecraftforge.event.entity.living.LivingDeathEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EpisodeEventWrapper.java    From malmo with MIT License 6 votes vote down vote up
@SubscribeEvent
public void onPlayerDies(LivingDeathEvent lde)
{
    // Pass the event on to the active episode, if there is one:
    this.stateEpisodeLock.readLock().lock();
    if (this.stateEpisode != null && this.stateEpisode.isLive())
    {
        this.stateEpisode.onPlayerDies(lde);
    }
    this.stateEpisodeLock.readLock().unlock();
}
 
Example #2
Source File: ComponentResurrect.java    From Artifacts with MIT License 6 votes vote down vote up
@Override
public void onDeath(ItemStack itemStack, LivingDeathEvent event, boolean isWornArmor) {
	System.out.println("ABORTING DEATH");
	if(isWornArmor && !event.isCanceled()) {
		EntityPlayer player = (EntityPlayer)event.entity;
		NBTTagCompound data = itemStack.getTagCompound();
		//System.out.println("Cooldown: " + data.getInteger("resCooldown"));
		if(data.getInteger("resCooldown_armor") <= 0) {
			event.setCanceled(true);
			player.setHealth(20);
			data.setInteger("resCooldown_armor", 6000);
			itemStack.damageItem(5, player);
			return;
		}
	}
}
 
Example #3
Source File: ModuleEffectBackup.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public static void onZombieDeath(LivingDeathEvent e) {
	if(e.getEntity() instanceof EntityBackupZombie) {
		if(((EntityBackupZombie)e.getEntity()).getOwner() != null) {
			WizardryWorld world = WizardryWorldCapability.get(e.getEntity().world);

			if(world != null) {
				world.decBackupCount(((EntityBackupZombie)e.getEntity()).getOwner());
			}
		}
	}
}
 
Example #4
Source File: EventHandlerEntity.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void on(LivingDeathEvent event) {
    if (!event.entity.worldObj.isRemote) {
        if(event.entityLiving instanceof EntityPlayer) {
            TCMazeHandler.closeSession((EntityPlayer) event.entityLiving, false);
        }
        if(event.entityLiving instanceof EntityLiving) {
            TileAIShutdown.removeTrackedEntity((EntityLiving) event.entityLiving);
        }
    }
}
 
Example #5
Source File: EntityLivingHandler.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onEntityDeath(LivingDeathEvent event)
{
	EntityLivingBase entity = event.getEntityLiving();

	if(event.getEntity().world.isRemote)
		return;

	if (entity instanceof EntityPlayer)
	{
		//Removed on port
		/*EntityPlayer player = (EntityPlayer) entity;
		SkillStats skills = TFC_Core.getSkillStats(player);
		PlayerInfo pi = PlayerManagerTFC.getInstance().getPlayerInfoFromPlayer(player);
		pi.tempSkills = skills;

		// Save the item in the back slot if keepInventory is set to true.
		if (entityIn.world.getGameRules().getGameRuleBooleanValue("keepInventory") && player.inventory instanceof InventoryPlayerTFC)
		{
			pi.tempEquipment = ((InventoryPlayerTFC) player.inventory).extraEquipInventory.clone();
		}*/
	}

	if(entity.getEntityData().hasKey("TFC2"))
	{
		/*NBTTagCompound nbt = entity.getEntityData().getCompoundTag("TFC2");
		if(nbt.getBoolean("isWild"))
		{
			IslandMap map = Core.getMapForWorld(event.getEntity().getEntityWorld(), event.getEntity().getPosition());
			SpawnEntry entry = map.getIslandData().animalEntries.get(nbt.getString("SpawnGroup"));
			entry.removeAnimal();
		}*/
	}
}
 
Example #6
Source File: EventHandlerPneumaticCraft.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onEntityDeath(LivingDeathEvent event){
    if(!event.entity.worldObj.isRemote) {
        if(Config.enableSlimeSeedDrop && event.entity instanceof EntitySlime && Math.random() < 0.1D) {
            ItemPlasticPlants.markInactive(event.entity.entityDropItem(new ItemStack(Itemss.plasticPlant, 1, ItemPlasticPlants.SLIME_PLANT_DAMAGE), 0));
        } else if(Config.enableCreeperSeedDrop && event.entity instanceof EntityCreeper && Math.random() < 0.05D) {
            if(Config.enableCreeperDropExplosion) event.entity.worldObj.createExplosion(event.entity, event.entity.posX, event.entity.posY + event.entityLiving.height / 2D, event.entity.posZ, 0.5F, event.entity.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing"));
            int dropAmount = (int)(Math.random() * 3D) + 1;
            for(int i = 0; i < dropAmount; i++)
                ItemPlasticPlants.markInactive(event.entity.entityDropItem(new ItemStack(Itemss.plasticPlant, 1, ItemPlasticPlants.CREEPER_PLANT_DAMAGE), 0));
        } else if(Config.enableSquidSeedDrop && event.entity instanceof EntitySquid && Math.random() < 0.05D) {
            ItemPlasticPlants.markInactive(event.entity.entityDropItem(new ItemStack(Itemss.plasticPlant, 1, ItemPlasticPlants.SQUID_PLANT_DAMAGE), 0));
        }
    }
}
 
Example #7
Source File: PlayerListener.java    From SkyblockAddons with MIT License 4 votes vote down vote up
@SubscribeEvent
    public void onDeath(LivingDeathEvent e) {
        if (e.entity instanceof EntityEnderman) {
            if (countedEndermen.remove(e.entity.getUniqueID())) {
                main.getPersistentValues().addKill();
                EndstoneProtectorManager.onKill();
            } else if (main.getUtils().isOnSkyblock() && main.getConfigValues().isEnabled(Feature.ZEALOT_COUNTER_EXPLOSIVE_BOW_SUPPORT)) {
                if (isZealot(e.entity)) {
                    long now = System.currentTimeMillis();
                    if (recentlyKilledZealots.containsKey(now)) {
                        recentlyKilledZealots.get(now).add(e.entity.getPositionVector());
                    } else {
                        recentlyKilledZealots.put(now, Sets.newHashSet(e.entity.getPositionVector()));
                    }

                    explosiveBowExplosions.keySet().removeIf((explosionTime) -> now - explosionTime > 150);
                    Map.Entry<Long, Vec3> latestExplosion = explosiveBowExplosions.lastEntry();
                    if (latestExplosion == null) return;

                    Vec3 explosionLocation = latestExplosion.getValue();

//                    int possibleZealotsKilled = 1;
//                    System.out.println("This means "+possibleZealotsKilled+" may have been killed...");
//                    int originalPossibleZealotsKilled = possibleZealotsKilled;

                    Vec3 deathLocation = e.entity.getPositionVector();

                    double distance = explosionLocation.distanceTo(deathLocation);
//                    System.out.println("Distance was "+distance+"!");
                    if (explosionLocation.distanceTo(deathLocation) < 4.6) {
//                        possibleZealotsKilled--;

                        main.getPersistentValues().addKill();
                        EndstoneProtectorManager.onKill();
                    }

//                    System.out.println((originalPossibleZealotsKilled-possibleZealotsKilled)+" zealots were actually killed...");
                }
            }
        }
    }
 
Example #8
Source File: EntityEvents.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static boolean onLivingDeath(LivingEntity entity, DamageSource src) {
	return MinecraftForge.EVENT_BUS.post(new LivingDeathEvent(entity, src));
}
 
Example #9
Source File: ItemHeartUpgrade.java    From Cyberware with MIT License 4 votes vote down vote up
@SubscribeEvent
public void handleDeath(LivingDeathEvent event)
{

	EntityLivingBase e = event.getEntityLiving();
	ItemStack test = new ItemStack(this, 1, 0);
	if (CyberwareAPI.isCyberwareInstalled(e, test) && !event.isCanceled())
	{
		ICyberwareUserData cyberware = CyberwareAPI.getCapability(e);
		ItemStack stack = CyberwareAPI.getCyberware(e, test);
		if ((!CyberwareAPI.getCyberwareNBT(stack).hasKey("used")) && cyberware.usePower(test, this.getPowerConsumption(test), false))
		{
			ItemStack[] items = cyberware.getInstalledCyberware(EnumSlot.HEART);
			ItemStack[] itemsNew = items.clone();
			for (int i = 0; i < items.length; i++)
			{
				ItemStack item = items[i];
				if (item != null && item.getItem() == this && item.getItemDamage() == 0)
				{
					itemsNew[i] = null;
					break;
				}
			}
			if (e instanceof EntityPlayer)
			{
				cyberware.setInstalledCyberware(e, EnumSlot.HEART, itemsNew);
				cyberware.updateCapacity();
				if (!e.worldObj.isRemote)
				{
					CyberwareAPI.updateData(e);
				}
			}
			else
			{
				stack = CyberwareAPI.getCyberware(e, test);
				NBTTagCompound com = CyberwareAPI.getCyberwareNBT(stack);
				com.setBoolean("used", true);
				stack.getTagCompound().setTag(CyberwareAPI.DATA_TAG, com);

				CyberwareAPI.updateData(e);
			}
			e.setHealth(e.getMaxHealth() / 3F);
			CyberwarePacketHandler.INSTANCE.sendToAllAround(new ParticlePacket(1, (float) e.posX, (float) e.posY + e.height / 2F, (float) e.posZ), 
					new TargetPoint(e.worldObj.provider.getDimension(), e.posX, e.posY, e.posZ, 20));
			event.setCanceled(true);
		}
	}
}
 
Example #10
Source File: StateEpisode.java    From malmo with MIT License 4 votes vote down vote up
/** Subclass should overrride this to act on player death events.*/
protected void onPlayerDies(LivingDeathEvent event) {}
 
Example #11
Source File: EntityXpHandler.java    From TinkersToolLeveling with MIT License 4 votes vote down vote up
@SubscribeEvent
public void onDeath(LivingDeathEvent event) {
  if(!event.getEntity().getEntityWorld().isRemote && event.getEntity().hasCapability(CapabilityDamageXp.CAPABILITY, null)) {
    event.getEntity().getCapability(CapabilityDamageXp.CAPABILITY, null).distributeXpToTools(event.getEntityLiving());
  }
}
 
Example #12
Source File: ProxyCommon.java    From WearableBackpacks with MIT License 4 votes vote down vote up
@SubscribeEvent
public void onLivingDeath(LivingDeathEvent event) {
	// If an entity wearing a backpack dies, try
	// to place it as a block, or drop the items.

	EntityLivingBase entity = event.getEntityLiving();
	World world = entity.world;
	if (world.isRemote) return;

	BackpackCapability backpack = (BackpackCapability)entity
		.getCapability(IBackpack.CAPABILITY, null);
	if ((backpack == null) || backpack.getStack().isEmpty()) return;

	// If keep inventory (or other item keeping method) is on,
	// keep the backpack capability so we can copy it over to the new player
	// entity in onPlayerClone.
	if (MiscUtils.shouldKeepItem(entity, backpack.getStack())) return;

	// Attempt to place the backpack as a block instead of dropping the items.
	if (WearableBackpacks.CONFIG.dropAsBlockOnDeath.get()) {

		List<BlockCoord> coords = new ArrayList<BlockCoord>();
		for (int x = -2; x <= 2; x++)
			for (int z = -2; z <= 2; z++)
				coords.add(new BlockCoord(entity, x, z));

		// Try to place the backpack on the ground nearby,
		// or look for a ground above or below to place it.

		Collections.sort(coords, new Comparator<BlockCoord>() {
			@Override public int compare(BlockCoord o1, BlockCoord o2) {
				if (o1.distance < o2.distance) return -1;
				else if (o1.distance > o2.distance) return 1;
				else return 0;
			}
		});
		while (!coords.isEmpty()) {
			Iterator<BlockCoord> iter = coords.iterator();
			while (iter.hasNext()) {
				BlockCoord coord = iter.next();
				// Attempt to place and unequip the backpack at
				// this coordinate. If successful, we're done here.
				if (BackpackHelper.placeBackpack(world, coord, backpack.getStack(), entity, true)) {
					// TODO: I'm aware that this is not the cleanest solution.
					((TileEntityBackpack)world.getTileEntity(coord)).setPlacedOnDeath(backpack.mayDespawn);
					return;
				}
				boolean replacable = world.getBlockState(coord).getBlock().isReplaceable(world, coord);
				coord.add(0, (replacable ? -1 : 1), 0);
				coord.moved += (replacable ? 1 : 5);
				if ((coord.getY() <= 0) || (coord.getY() > world.getHeight()) ||
					(coord.moved > 24 - coord.distance * 4)) iter.remove();
			}
		}

	}

	// In the case of regular backpacks, this causes their contents to be dropped.
	backpack.getType().onDeath(entity, backpack);

	// Drop the backpack as an item and remove it from the entity.
	if (!backpack.getStack().isEmpty())
		WorldUtils.dropStackFromEntity(entity, backpack.getStack(), 4.0F);
	BackpackHelper.setEquippedBackpack(entity, ItemStack.EMPTY, null);
}
 
Example #13
Source File: IArtifactComponent.java    From Artifacts with MIT License 2 votes vote down vote up
/**
 * Called from a LivingDeathEvent handler.  Will only fire if the event.entity is of instance EntityPlayer
 * Using these requires an understanding of Shared Monster Attributes and using {@link ArtifactsAPI#OnHurtAttribute}<br/>
 * You will likely want to create unique components for behaviors that use this.
 * @param itemStack is the stack associated with the effect
 * @param event is the LivingDeathEvent
 * @param isWornArmor true if the item is equipped to the player's armor slots
 */
public void onDeath(ItemStack itemStack, LivingDeathEvent event, boolean isWornArmor);
 
Example #14
Source File: BaseComponent.java    From Artifacts with MIT License 2 votes vote down vote up
@Override
public void onDeath(ItemStack itemStack, LivingDeathEvent event, boolean isWornArmor) {
	
}