net.minecraftforge.event.entity.living.LivingDropsEvent Java Examples
The following examples show how to use
net.minecraftforge.event.entity.living.LivingDropsEvent.
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: StringEventHandling.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 6 votes |
@SubscribeEvent public void entityDrops(LivingDropsEvent ev) { if (!ConfigManager.SERVER.dropStringFromSheep.get()) return; Entity entity = ev.getEntity(); if (!(entity instanceof SheepEntity)) return; Collection<ItemEntity> drops = ev.getDrops(); if (drops instanceof ImmutableList) { SurvivalistMod.LOGGER.warn("WARNING: Some mod is returning an ImmutableList, replacing drops will NOT be possible."); return; } if (rnd.nextFloat() < 0.25f) drops.add(new ItemEntity(entity.getEntityWorld(), entity.getPosX(), entity.getPosY(), entity.getPosZ(), new ItemStack(Items.STRING))); }
Example #2
Source File: ServerEventHandler.java From Et-Futurum with The Unlicense | 6 votes |
@SubscribeEvent(priority = EventPriority.HIGHEST) public void dropEvent(LivingDropsEvent event) { if (event.entityLiving.worldObj.isRemote) return; if (EtFuturum.enableSkullDrop) dropHead(event.entityLiving, event.source, event.lootingLevel, event.drops); Random rand = event.entityLiving.worldObj.rand; if (EtFuturum.enableMutton && event.entityLiving instanceof EntitySheep) { int amount = rand.nextInt(3) + 1 + rand.nextInt(1 + event.lootingLevel); for (int i = 0; i < amount; i++) if (event.entityLiving.isBurning()) addDrop(new ItemStack(ModItems.cooked_mutton), event.entityLiving, event.drops); else addDrop(new ItemStack(ModItems.raw_mutton), event.entityLiving, event.drops); } }
Example #3
Source File: AliquoEvents.java From Ex-Aliquo with MIT License | 6 votes |
@ForgeSubscribe public void onLivingDrops(LivingDropsEvent event) { if (event.entityLiving == null) { return; } if (event.entityLiving instanceof EntityDragon) { if (event.source.getEntity() != null && event.source.getEntity() instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) event.source.getEntity(); if (!player.worldObj.isRemote) { EntityItem item = new EntityItem(player.worldObj, player.posX + 0.5D, player.posY + 0.5D, player.posZ + 0.5D, new ItemStack(Registries.dragonEgg, 1, 0)); player.worldObj.spawnEntityInWorld(item); if (!(player instanceof FakePlayer)) { item.onCollideWithPlayer(player); } } } } }
Example #4
Source File: LivingDropsEventHandler.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
@SubscribeEvent public void onLivingDrops(LivingDropsEvent event) { DamageSource source = event.getSource(); if (source != null && source.damageType != null && source.damageType.equals("player") && source.getImmediateSource() instanceof EntityPlayer) { ItemStack stack = ((EntityPlayer) source.getImmediateSource()).getHeldItemMainhand(); if (stack.isEmpty() == false && stack.getItem() == EnderUtilitiesItems.ENDER_SWORD) { ((ItemEnderSword) stack.getItem()).handleLivingDropsEvent(stack, event); } } }
Example #5
Source File: EventHandlerEMT.java From Electro-Magic-Tools with GNU General Public License v3.0 | 6 votes |
@SubscribeEvent public void onEntityLivingDrops(LivingDropsEvent event) { if (event.source.getEntity() != null && event.source.getEntity() instanceof EntityPlayer) { if (event.entityLiving instanceof EntityCreeper) { EntityCreeper creeper = (EntityCreeper) event.entityLiving; if (creeper.getPowered()) { event.drops.add(new EntityItem(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, new ItemStack(IC2ItemRegistry.itemEMTItems, 1, 6))); } } if (event.entityLiving instanceof EntityTaintChicken) { event.drops.add(new EntityItem(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, new ItemStack(IC2ItemRegistry.itemEMTItems, 1, 14))); } } if (event.entityLiving instanceof EntityCreeper) { event.entityLiving.entityDropItem(new ItemStack(IC2ItemRegistry.itemEMTItems, 6), 1); } if (event.entityLiving instanceof EntityTaintChicken) { event.entityLiving.entityDropItem(new ItemStack(IC2ItemRegistry.itemEMTItems, 14), 1); } }
Example #6
Source File: MixinLivingEntity.java From patchwork-api with GNU Lesser General Public License v2.1 | 5 votes |
@Inject(method = "drop", at = @At("TAIL")) private void hookDropForDropsEvent(DamageSource src, CallbackInfo info) { LivingEntity entity = (LivingEntity) (Object) this; IForgeEntity forgeEntity = (IForgeEntity) this; Collection<ItemEntity> drops = forgeEntity.captureDrops(null); if (!MinecraftForge.EVENT_BUS.post(new LivingDropsEvent(entity, src, drops, dropLootingLevel.get(), playerHitTimer > 0))) { for (ItemEntity item : drops) { forgeEntity.getEntity().world.spawnEntity(item); } } dropLootingLevel.remove(); }
Example #7
Source File: AdvancedModEventHandler.java From AdvancedMod with GNU General Public License v3.0 | 5 votes |
/** * Using the LivingDropsEvent. Note that this is from net.minecraftforge.event, so to make this method be called, this class needs to be registered at MinecraftForge.EVENT_BUS.register(new AdvancedModEventHandler()). * @param event */ @SubscribeEvent public void addPigDrops(LivingDropsEvent event){ if(event.entityLiving instanceof EntityPig && event.entityLiving.getRNG().nextInt(3) == 0) { ItemStack stack = new ItemStack(ModBlocks.dutchFlag); event.drops.add(new EntityItem(event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, stack)); } }
Example #8
Source File: EntityEventHandler.java From Electro-Magic-Tools with GNU General Public License v3.0 | 5 votes |
@SubscribeEvent public void onEntityLivingDrops(LivingDropsEvent event) { if (event.source.getEntity() != null && event.source.getEntity() instanceof EntityPlayer) { if (event.entityLiving instanceof EntityCreeper) { EntityCreeper creeper = (EntityCreeper) event.entityLiving; if (creeper.getPowered()) { event.entityLiving.entityDropItem(new ItemStack(IC2ItemRegistry.itemEMTItems, 1, 6), 1); } } if (event.entityLiving instanceof EntityTaintChicken) { event.entityLiving.entityDropItem(new ItemStack(IC2ItemRegistry.itemEMTItems, 1, 14), 1); } } }
Example #9
Source File: CyberwareDataHandler.java From Cyberware with MIT License | 4 votes |
@SubscribeEvent public void handleCyberzombieDrops(LivingDropsEvent event) { EntityLivingBase e = event.getEntityLiving(); if (e instanceof EntityPlayer && !e.worldObj.isRemote) { EntityPlayer p = (EntityPlayer) e; if ((p.worldObj.getWorldInfo().getGameRulesInstance().getBoolean(DROP_WARE_GAMERULE) && !p.worldObj.getWorldInfo().getGameRulesInstance().getBoolean(KEEP_WARE_GAMERULE)) || (p.worldObj.getWorldInfo().getGameRulesInstance().getBoolean(KEEP_WARE_GAMERULE) && shouldDropWare(event.getSource()))) { if (CyberwareAPI.hasCapability(p)) { ICyberwareUserData data = CyberwareAPI.getCapability(p); for (EnumSlot slot : EnumSlot.values()) { ItemStack[] stacks = data.getInstalledCyberware(slot); ItemStack[] defaults = CyberwareConfig.getStartingItems(EnumSlot.values()[slot.ordinal()]).clone(); for (ItemStack stack : stacks) { if (stack != null) { ItemStack toDrop = stack.copy(); boolean found = false; for (ItemStack def : defaults) { if (CyberwareAPI.areCyberwareStacksEqual(def, toDrop)) { if (toDrop.stackSize > def.stackSize) { toDrop.stackSize -= def.stackSize; } else { found = true; } } } if (!found && p.worldObj.rand.nextFloat() < CyberwareConfig.DROP_CHANCE / 100F) { EntityItem item = new EntityItem(p.worldObj, p.posX, p.posY, p.posZ, toDrop); p.worldObj.spawnEntityInWorld(item); } } } } data.resetWare(p); } } } if (!CyberwareConfig.NO_ZOMBIES && e instanceof EntityCyberZombie && ((EntityCyberZombie) e).hasWare && !e.worldObj.isRemote) { } }
Example #10
Source File: SkullFireSwordDropFix.java From NewHorizonsCoreMod with GNU General Public License v3.0 | 4 votes |
private void dropWitherHeadsInWorld( LivingDropsEvent event, ItemStack drop ) { EntityItem entityitem = new EntityItem( event.entityLiving.worldObj, event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, drop ); entityitem.delayBeforeCanPickup = 10; event.entityLiving.worldObj.spawnEntityInWorld( entityitem ); }
Example #11
Source File: SkullFireSwordDropFix.java From NewHorizonsCoreMod with GNU General Public License v3.0 | 4 votes |
@SubscribeEvent( priority = EventPriority.LOWEST ) public void onLivingDrops( LivingDropsEvent event ) { try { if( mSkullFireSword == null ) { return; } // MainRegistry.Logger.info( "SkullFireSwordDropFix::onLivingDrops" ); if( event.recentlyHit && isValidSkeletonEntity( event.entityLiving ) && event.source.getEntity() instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) event.source.getEntity(); if( player.getHeldItem() != null && player.getHeldItem().getItem() == mSkullFireSword.getItem()) { // MainRegistry.Logger.info( "SkullFireSwordDropFix::Perform DropAction" ); if( event.drops.isEmpty() ) { dropWitherHeadsInWorld(event, new ItemStack(Items.skull, 1, 1)); } else { int skulls = 0; for( int i = 0; i < event.drops.size(); i++ ) { EntityItem drop = event.drops.get( i ); ItemStack stack = drop.getEntityItem(); if( stack.getItem() == Items.skull ) { if( stack.getItemDamage() == 1 ) { dropWitherHeadsInWorld(event, new ItemStack(Items.skull, skulls + 1, 1)); } else if( stack.getItemDamage() == 0 ) { dropWitherHeadsInWorld(event, new ItemStack(Items.skull, 1, 1)); } } } if( skulls == 0 ) { dropWitherHeadsInWorld(event, new ItemStack(Items.skull, 1, 1)); } } } } } catch( Exception e ) { e.printStackTrace(); } }