Java Code Examples for net.minecraft.entity.item.EntityItem

The following examples show how to use net.minecraft.entity.item.EntityItem. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
private void outputInChamber(){
    TileEntityPressureChamberValve valve = getCore();
    if(valve != null) {
        for(int i = 0; i < 6; i++) {
            int x = xCoord + Facing.offsetsXForSide[i];
            int y = yCoord + Facing.offsetsYForSide[i];
            int z = zCoord + Facing.offsetsZForSide[i];
            if(valve.isCoordWithinChamber(worldObj, x, y, z)) {
                enoughAir = Math.abs(valve.currentAir) > inventory[0].stackSize * PneumaticValues.USAGE_CHAMBER_INTERFACE;
                if(enoughAir) {
                    valve.addAir((valve.currentAir > 0 ? -1 : 1) * inventory[0].stackSize * PneumaticValues.USAGE_CHAMBER_INTERFACE, ForgeDirection.UNKNOWN);
                    EntityItem item = new EntityItem(worldObj, x + 0.5D, y + 0.5D, z + 0.5D, inventory[0].copy());
                    worldObj.spawnEntityInWorld(item);
                    setInventorySlotContents(0, null);
                    break;
                }
            }
        }
    }
}
 
Example 2
@Override
public void onBlockPreDestroy(World world, int x, int y, int z, int side) {
    TileEntityWrathCage spawner = (TileEntityWrathCage) world.getTileEntity(x, y, z);

    if (spawner != null && spawner.getSpawnerLogic().isMobSet()) {
        float f = world.rand.nextFloat() * 0.8F + 0.1F;
        float f1 = world.rand.nextFloat() * 0.8F + 0.1F;
        float f2 = world.rand.nextFloat() * 0.8F + 0.1F;

        ItemStack crystal = new ItemStack(ForbiddenItems.mobCrystal);
        crystal.setTagCompound(new NBTTagCompound());
        String mob = spawner.getSpawnerLogic().getEntityNameToSpawn();
        crystal.stackTagCompound.setString("mob", mob);

        EntityItem entityitem = new EntityItem(world, (double) ((float) x + f), (double) ((float) y + f1), (double) ((float) z + f2), crystal);

        entityitem.motionX = (double) ((float) world.rand.nextGaussian() * 0.05F);
        entityitem.motionY = (double) ((float) world.rand.nextGaussian() * 0.05F + 0.2F);
        entityitem.motionZ = (double) ((float) world.rand.nextGaussian() * 0.05F);
        world.spawnEntityInWorld(entityitem);

    }

    super.onBlockPreDestroy(world, x, y, z, side);
}
 
Example 3
private void breakTile() {
    if(!isPartOfMultiblock || worldObj.isRemote) return;

    int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
    Block pylon = worldObj.getBlock(xCoord, yCoord, zCoord);
    if(pylon != null) {
        ArrayList<ItemStack> stacks = pylon.getDrops(worldObj, xCoord, yCoord, zCoord, meta, 0);
        for(ItemStack i : stacks) {
            EntityItem item = new EntityItem(worldObj, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, i);
            //ItemUtils.applyRandomDropOffset(item, worldObj.rand);
            worldObj.spawnEntityInWorld(item);
        }
    }
    worldObj.removeTileEntity(xCoord, yCoord, zCoord);
    worldObj.setBlockToAir(xCoord, yCoord, zCoord);
    worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
 
Example 4
@Method(modid = GTValues.MODID_FR)
private boolean processButterflyCatch(ItemStack itemStack, EntityPlayer player, Entity entity) {
    if (entity instanceof IEntityButterfly) {
        if (player.world.isRemote) {
            return true;
        }
        if (player.capabilities.isCreativeMode || GTUtility.doDamageItem(itemStack, this.cost, false)) {
            IEntityButterfly butterfly = (IEntityButterfly) entity;
            IAlleleButterflySpecies species = butterfly.getButterfly().getGenome().getPrimary();
            species.getRoot().getBreedingTracker(entity.world, player.getGameProfile()).registerCatch(butterfly.getButterfly());
            player.world.spawnEntity(new EntityItem(player.world, entity.posX, entity.posY, entity.posZ,
                species.getRoot().getMemberStack(butterfly.getButterfly().copy(), EnumFlutterType.BUTTERFLY)));
            entity.setDead();
        }
        return true;
    }
    return false;
}
 
Example 5
@Override
protected void attackEntity(Entity entity, float f)
{

    if ((f > 2.0F) && (f < 6F) && (rand.nextInt(30) == 0) && onGround)
    {
        double d = entity.posX - posX;
        double d1 = entity.posZ - posZ;
        float f1 = MathHelper.sqrt_double((d * d) + (d1 * d1));
        motionX = ((d / f1) * 0.5D * 0.8D) + (motionX * 0.2D);
        motionZ = ((d1 / f1) * 0.5D * 0.8D) + (motionZ * 0.2D);
        motionY = 0.4D;
    }
    if ((f < 2D) && (entity.boundingBox.maxY > boundingBox.minY) && (entity.boundingBox.minY < boundingBox.maxY))
    {
        attackTime = 20;
        if ((getKittyState() != 18) && (getKittyState() != 10))
        {
            swingArm();
        }
        if (((getKittyState() == 13) && (entity instanceof EntityPlayer)) || ((getKittyState() == 8) && (entity instanceof EntityItem)) || ((getKittyState() == 18) && (entity instanceof MoCEntityKitty)) || (getKittyState() == 10)) { return; }
        //if(worldObj.isRemote) 
        entity.attackEntityFrom(DamageSource.causeMobDamage(this), 1);
    }
}
 
Example 6
@Override
public void executeFullGrownEffect(World world, int x, int y, int z, Random rand){
    if(!world.isRemote) {
        ItemStack seed = new ItemStack(Itemss.plasticPlant, 1, ItemPlasticPlants.REPULSION_PLANT_DAMAGE);
        EntityItem plant = new EntityItem(world, x + 0.5D, y + 0.8D, z + 0.5D, seed);
        plant.motionX = (rand.nextFloat() - 0.5F) / 2;
        plant.motionY = 0.7F;
        plant.motionZ = (rand.nextFloat() - 0.5F) / 2;
        plant.lifespan = 300;
        ItemPlasticPlants.markInactive(plant);
        world.spawnEntityInWorld(plant);
        plant.playSound("mob.newsound.chickenplop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);

        world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) - 2, 3);
    }
}
 
Example 7
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block){
    super.onNeighborBlockChange(world, x, y, z, block);
    TileEntity te = world.getTileEntity(x, y, z);
    if(te instanceof TileEntityElevatorBase) {
        TileEntityElevatorBase thisTe = (TileEntityElevatorBase)te;
        if(thisTe.isCoreElevator()) {
            TileEntityElevatorBase teAbove = getCoreTileEntity(world, x, y, z);
            if(teAbove != null && teAbove != thisTe) {
                for(int i = 0; i < thisTe.getSizeInventory(); i++) {
                    ItemStack item = thisTe.getStackInSlot(i);
                    if(item != null) {
                        ItemStack leftover = TileEntityHopper.func_145889_a(teAbove, item, 0);
                        thisTe.setInventorySlotContents(i, null);
                        if(leftover != null) {
                            EntityItem entity = new EntityItem(world, teAbove.xCoord + 0.5, teAbove.yCoord + 1.5, teAbove.zCoord + 0.5, leftover);
                            world.spawnEntityInWorld(entity);
                        }
                    }
                }
            }
        }
    }
}
 
Example 8
@Override
protected void dropBlockAsItem(World world, int x, int y, int z, ItemStack stack){
    if(!world.isRemote && world.getGameRules().getGameRuleBooleanValue("doTileDrops")) {
        if(captureDrops.get()) {
            capturedDrops.get().add(stack);
            return;
        }
        float f = 0.7F;
        double d0 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
        double d1 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
        double d2 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
        EntityItem entityitem = new EntityItem(world, x + d0, y + d1, z + d2, stack);
        entityitem.delayBeforeCanPickup = 10;
        world.spawnEntityInWorld(entityitem);
        ItemPlasticPlants.markInactive(entityitem);
    }
}
 
Example 9
Source Project: AgriCraft   Source File: ItemClipper.java    License: MIT License 6 votes vote down vote up
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitx, float hity, float hitz) {
    if (world.isRemote) {
        return EnumActionResult.SUCCESS;
    }
    TileEntity te = world.getTileEntity(pos);
    if (te instanceof IAgriCrop) {
        IAgriCrop crop = (IAgriCrop) te;
        if (crop.hasSeed() && crop.getGrowthStage() > 1) {
            crop.setGrowthStage(crop.getGrowthStage() - 1);
            AgriSeed seed = crop.getSeed();
            seed = seed.withStat(seed.getStat());
            world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), ItemClipping.getClipping(seed, 1)));
            return EnumActionResult.SUCCESS;
        }
        return EnumActionResult.FAIL;
    }
    return EnumActionResult.PASS;   //return PASS or else no other use methods will be called (for instance "onBlockActivated" on the crops block)
}
 
Example 10
public EntityItem getClosestEntityItem(Entity entity, double d)
{
	double d1 = -1D;
	EntityItem entityitem = null;
	List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(d, d, d));
	for (int k = 0; k < list.size(); k++)
	{
		Entity entity1 = (Entity) list.get(k);
		if (!(entity1 instanceof EntityItem))
		{
			continue;
		}
		EntityItem entityitem1 = (EntityItem) entity1;
		double d2 = entityitem1.getDistanceSq(entity.posX, entity.posY, entity.posZ);
		if (((d < 0.0D) || (d2 < (d * d))) && ((d1 == -1D) || (d2 < d1)))
		{
			d1 = d2;
			entityitem = entityitem1;
		}
	}

	return entityitem;
}
 
Example 11
@Override
public Collection<ItemStack> collect(){
    List<ItemStack> col = new ArrayList<ItemStack>();
    int[] coords = housing.getCoords();
    int[] area = housing.getArea();
    int[] offset = housing.getOffset();

    AxisAlignedBB harvestBox = AxisAlignedBB.getBoundingBox(coords[0] + offset[0], coords[1] + offset[1], coords[2] + offset[2], coords[0] + offset[0] + area[0], coords[1] + offset[1] + area[1], coords[2] + offset[2] + area[2]);
    List<EntityItem> list = housing.getWorld().getEntitiesWithinAABB(EntityItem.class, harvestBox);

    for(EntityItem item : list) {
        if(!item.isDead) {
            ItemStack contained = item.getEntityItem();
            if(isAcceptedGermling(contained)) {
                col.add(contained.copy());
                item.setDead();
            }
        }
    }
    return col;
}
 
Example 12
@Override
public void executeFullGrownEffect(World world, int x, int y, int z, Random rand){
    if(!world.isRemote) {
        ItemStack seed = new ItemStack(Itemss.plasticPlant, 1, ItemPlasticPlants.BURST_PLANT_DAMAGE);
        EntityItem plant = new EntityItem(world, x + 0.5D, y + 0.8D, z + 0.5D, seed);
        plant.motionX = rand.nextFloat() - 0.5F;
        plant.motionY = 1.0F;
        plant.motionZ = rand.nextFloat() - 0.5F;
        plant.lifespan = 300;
        ItemPlasticPlants.markInactive(plant);
        world.spawnEntityInWorld(plant);
        plant.playSound("mob.newsound.chickenplop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);

        world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) - 2, 3);
    }
}
 
Example 13
Source Project: Kettle   Source File: TrackingRange.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the range an entity should be 'tracked' by players and visible in
 * the client.
 *
 * @param entity
 * @param defaultRange Default range defined by Mojang
 * @return
 */
public static int getEntityTrackingRange(Entity entity, int defaultRange) {
    SpigotWorldConfig config = entity.world.spigotConfig;
    if (entity instanceof EntityPlayer) {
        return config.playerTrackingRange;
    } else if (entity.activationType == 1) {
        return config.monsterTrackingRange;
    } else if (entity instanceof EntityGhast) {
        if (config.monsterTrackingRange > config.monsterActivationRange) {
            return config.monsterTrackingRange;
        } else {
            return config.monsterActivationRange;
        }
    } else if (entity.activationType == 2) {
        return config.animalTrackingRange;
    } else if (entity instanceof EntityItemFrame || entity instanceof EntityPainting || entity instanceof EntityItem || entity instanceof EntityXPOrb) {
        return config.miscTrackingRange;
    } else {
        return config.otherTrackingRange;
    }
}
 
Example 14
public void renderChopperSeeds(EntityChopperSeeds entity, double x, double y, double z, float var1, float partialTicks){
    float scaleFactor = 0.7F;
    GL11.glPushMatrix(); // start
    GL11.glTranslatef((float)x, (float)y, (float)z); // size
    // GL11.glScalef(1.0F, -1F, -1F);
    GL11.glScalef(scaleFactor, scaleFactor, scaleFactor);
    EntityItem ghostEntityItem = new EntityItem(entity.worldObj);
    ghostEntityItem.hoverStart = 0.0F;
    ghostEntityItem.setEntityItemStack(iStack);
    double radius = 0.25D;
    for(int i = 0; i < 4; i++) {
        GL11.glPushMatrix();
        GL11.glTranslated(Math.sin(0.5D * Math.PI * i + (entity.ticksExisted + partialTicks) * 0.4D) * radius, 0, Math.cos(0.5D * Math.PI * i + (entity.ticksExisted + partialTicks) * 0.4D) * radius);
        itemRenderer.doRender(ghostEntityItem, 0, 0, 0, 0, 0);
        GL11.glPopMatrix();
    }
    GL11.glPopMatrix();
}
 
Example 15
Source Project: TFC2   Source File: BlockLogVertical.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void createFallingEntity(World world, BlockPos pos, IBlockState state)
{
	if(world.rand.nextFloat() < 0.4)
	{
		world.setBlockToAir(pos);
		EntityItem ei = new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.STICK, 1+world.rand.nextInt(3)));
		world.spawnEntity(ei);
	}
	else
	{
		int x = 0;
		int z = 0;
		if(world.rand.nextFloat() < 0.25)
		{
			x = -1 + world.rand.nextInt(3);
			z = -1 + world.rand.nextInt(3);
		}
		world.setBlockToAir(pos);
		EntityFallingBlockTFC entityfallingblock = new EntityFallingBlockTFC(world, pos.getX() + 0.5D + x, pos.getY(), pos.getZ() + 0.5D + z, state);
		world.spawnEntity(entityfallingblock);
	}
}
 
Example 16
Source Project: ExNihiloAdscensio   Source File: ProjectileStone.java    License: MIT License 6 votes vote down vote up
@Override
protected void onImpact(RayTraceResult result)
{
    if (result.entityHit != null)
    {
        result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, getThrower()), (int) (Math.random() * (4.0F / 3.0F)));
    }
    else if (!world.isRemote)
    {
        setDead();
        
        if(stack != null)
        {
            world.spawnEntity(new EntityItem(world, posX, posY, posZ, stack));
        }
    }
    
    for (int j = 0; j < 8; ++j)
    {
        world.spawnParticle(EnumParticleTypes.BLOCK_CRACK, posX, posY, posZ, 0.0D, 0.0D, 0.0D, new int[] { Block.getStateId(Blocks.STONE.getDefaultState()) });
    }
}
 
Example 17
Source Project: SimplyJetpacks   Source File: PlatingReturnHandler.java    License: MIT License 6 votes vote down vote up
@SubscribeEvent
public void onItemCrafted(ItemCraftedEvent evt) {
    if (evt.player.worldObj.isRemote || !(evt.crafting.getItem() instanceof ItemPack)) {
        return;
    }
    
    PackBase outputPack = ((ItemPack) evt.crafting.getItem()).getPack(evt.crafting);
    if (outputPack.isArmored) {
        return;
    }
    
    for (int i = 0; i < evt.craftMatrix.getSizeInventory(); i++) {
        ItemStack input = evt.craftMatrix.getStackInSlot(i);
        if (input == null || !(input.getItem() instanceof ItemPack)) {
            continue;
        }
        PackBase inputPack = ((ItemPack) input.getItem()).getPack(input);
        if (inputPack != null && inputPack.isArmored && inputPack.platingMeta != null) {
            EntityItem item = evt.player.entityDropItem(new ItemStack(ModItems.armorPlatings, 1, inputPack.platingMeta), 0.0F);
            item.delayBeforeCanPickup = 0;
            break;
        }
    }
}
 
Example 18
Source Project: SkyblockAddons   Source File: RenderManagerHook.java    License: MIT License 5 votes vote down vote up
public static void shouldRender(Entity entityIn, ReturnValue<Boolean> returnValue) {
    SkyblockAddons main = SkyblockAddons.getInstance();

    if (main.getUtils().isOnSkyblock()) {
        Location currentLocation = main.getUtils().getLocation();

        if (entityIn instanceof EntityItem &&
                entityIn.ridingEntity instanceof EntityArmorStand && entityIn.ridingEntity.isInvisible()) { // Conditions for skeleton helmet flying bones
            if (main.getConfigValues().isEnabled(Feature.HIDE_BONES)) {
                returnValue.cancel();
            }
        }
        if (main.getConfigValues().isEnabled(Feature.HIDE_PLAYERS_NEAR_NPCS)) {
            if (entityIn instanceof EntityOtherPlayerMP && NPCUtils.isNearAnyNPCWithTag(entityIn, Tag.IMPORTANT) && !NPCUtils.isNPC(entityIn)) {
                returnValue.cancel();
            }
        }
        if (main.getConfigValues().isEnabled(Feature.HIDE_PLAYERS_IN_LOBBY)) {
            if (currentLocation == Location.VILLAGE || currentLocation == Location.AUCTION_HOUSE ||
                    currentLocation == Location.BANK) {
                if ((entityIn instanceof EntityOtherPlayerMP || entityIn instanceof EntityFX || entityIn instanceof EntityItemFrame) &&
                        entityIn.getDistanceToEntity(Minecraft.getMinecraft().thePlayer) > 7) {
                    returnValue.cancel();
                }
            }
        }
        if(main.getConfigValues().isEnabled(Feature.HIDE_SVEN_PUP_NAMETAGS)) {
            if (entityIn instanceof EntityArmorStand && entityIn.hasCustomName()) {
                String customNameTag = entityIn.getCustomNameTag();

                if (customNameTag.contains("Sven Pup")) {
                    returnValue.cancel();
                }
            }
        }
    }
}
 
Example 19
private void applyMovementVectors(EntityItem entity) {
    double var3 = (this.xCoord + 0.5D - entity.posX) / 15.0D;
    double var5 = (this.yCoord + 0.5D - entity.posY) / 15.0D;
    double var7 = (this.zCoord + 0.5D - entity.posZ) / 15.0D;
    double var9 = Math.sqrt(var3 * var3 + var5 * var5 + var7 * var7);
    double var11 = 1.0D - var9;
    if (var11 > 0.0D) {
        var11 *= var11;
        entity.motionX += var3 / var9 * var11 * 0.15D;
        entity.motionY += var5 / var9 * var11 * 0.25D;
        entity.motionZ += var7 / var9 * var11 * 0.15D;
    }
}
 
Example 20
Source Project: ToroQuest   Source File: ToroQuestCommand.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void dropItems(EntityPlayer player, List<ItemStack> items) {
	for (ItemStack stack : items) {
		EntityItem dropItem = new EntityItem(player.world, player.posX, player.posY, player.posZ, stack);
		dropItem.setNoPickupDelay();
		player.world.spawnEntity(dropItem);
	}
}
 
Example 21
/**
 * Drops a chest block if the horse is bagged
 */
public void dropBags()
{
    if (!isBagger() || !getChestedHorse() || !MoCreatures.isServer()) { return; }

    EntityItem entityitem = new EntityItem(worldObj, posX, posY, posZ, new ItemStack(Block.chest, 1));
    float f3 = 0.05F;
    entityitem.motionX = (float) worldObj.rand.nextGaussian() * f3;
    entityitem.motionY = ((float) worldObj.rand.nextGaussian() * f3) + 0.2F;
    entityitem.motionZ = (float) worldObj.rand.nextGaussian() * f3;
    worldObj.spawnEntityInWorld(entityitem);
    setChestedHorse(false);
}
 
Example 22
Source Project: Sakura_mod   Source File: BlockShoji.java    License: MIT License 5 votes vote down vote up
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
 ItemStack stack = getDefaultItemStack();
 TileEntityShoji te = (TileEntityShoji) worldIn.getTileEntity(pos);
 if (te != null) {
 	RecipesUtil.getItemTagCompound(stack).setInteger("type", te.getType());
 } else {
 	RecipesUtil.getItemTagCompound(stack).setInteger("type", 0);
 }
    worldIn.spawnEntity(new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack));
    super.breakBlock(worldIn, pos, state);
}
 
Example 23
Source Project: TFC2   Source File: BlockWoodSupport.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void createFallingEntity(World world, BlockPos pos, IBlockState state)
{
	world.setBlockToAir(pos);
	EntityItem ei = new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.STICK, 1+world.rand.nextInt(3)));
	world.spawnEntity(ei);
}
 
Example 24
@Override
public void invalidate(){
    super.invalidate();
    for(ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
        TileEntity te = worldObj.getTileEntity(xCoord + d.offsetX, yCoord + d.offsetY, zCoord + d.offsetZ);
        if(te instanceof TileEntityModularStorage) {
            ((TileEntityModularStorage)te).master = null;
            ((TileEntityModularStorage)te).initializeMultiblockIfNecessary();
        }
    }
    for(ItemStack stack : inventory) {
        if(stack != null) worldObj.spawnEntityInWorld(new EntityItem(worldObj, xCoord, yCoord, zCoord, stack));
    }
}
 
Example 25
@Override
protected void onHit(RayTraceResult raytraceResultIn) {
    if (this.world.isRemote)
        return;
    this.setDead();
    EntityChicken chicken = new EntityChicken(world);
    Vec3d hit = raytraceResultIn.hitVec;
    chicken.setPosition(hit.x, hit.y, hit.z);
    world.spawnEntity(chicken);
    world.spawnEntity(new EntityItem(world, hit.x, hit.y, hit.z, new ItemStack(Items.EGG)));
}
 
Example 26
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
	TileEntity tileEntity = world.getTileEntity(pos);
	if (tileEntity instanceof TileEntityAltar) {
		ItemStack stack = ((TileEntityAltar) tileEntity).getStack();
		if (!stack.isEmpty()) {
			EntityItem drop = new EntityItem(world, pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, stack);
			world.spawnEntity(drop);
		}
	}
	super.breakBlock(world, pos, state);
}
 
Example 27
/**
 * Spawns an itemstack in the world at a location
 */
public static void dropItem(ItemStack stack, World world, Vector3 dropLocation) {
    EntityItem item = new EntityItem(world, dropLocation.x, dropLocation.y, dropLocation.z, stack);
    item.motionX = world.rand.nextGaussian() * 0.05;
    item.motionY = world.rand.nextGaussian() * 0.05 + 0.2F;
    item.motionZ = world.rand.nextGaussian() * 0.05;
    world.spawnEntityInWorld(item);
}
 
Example 28
Source Project: EmergingTechnology   Source File: HarvesterTileEntity.java    License: MIT License 5 votes vote down vote up
private boolean pullItems(EnumFacing facing) {

        if (getTargetBlockState(facing) == null) {
            return false;
        }

        // Includes target and directly above target
        AxisAlignedBB collectionArea = new AxisAlignedBB(getTarget(facing)).expand(0, 1, 0);

        List<EntityItem> entityItems = world.getEntitiesWithinAABB(EntityItem.class, collectionArea);
        insertItems(entityItems);

        return true;
    }
 
Example 29
Source Project: Cyberware   Source File: ItemBrainUpgrade.java    License: MIT License 5 votes vote down vote up
@SubscribeEvent
public void handleClone(PlayerEvent.Clone event)
{
	if (event.isWasDeath())
	{
		EntityPlayer p = event.getOriginal();
		
		if (CyberwareAPI.isCyberwareInstalled(p, new ItemStack(this, 1, 0)) && !p.worldObj.getGameRules().getBoolean("keepInventory"))
		{
			/*float range = 5F;
			List<EntityXPOrb> orbs = p.worldObj.getEntitiesWithinAABB(EntityXPOrb.class, new AxisAlignedBB(p.posX - range, p.posY - range, p.posZ - range, p.posX + p.width + range, p.posY + p.height + range, p.posZ + p.width + range));
			for (EntityXPOrb orb : orbs)
			{
				orb.setDead();
			}*/

			if (!p.worldObj.isRemote)
			{
				ItemStack stack = new ItemStack(CyberwareContent.expCapsule);
				NBTTagCompound c = new NBTTagCompound();
				c.setInteger("xp", p.experienceTotal);
				stack.setTagCompound(c);
				EntityItem item = new EntityItem(p.worldObj, p.posX, p.posY, p.posZ, stack);
				p.worldObj.spawnEntityInWorld(item);
			}
		}
		else if (CyberwareAPI.isCyberwareInstalled(p, new ItemStack(this, 1, 2)) && !p.worldObj.getGameRules().getBoolean("keepInventory"))
		{
			event.getEntityPlayer().addExperience((int) (Math.min(100, p.experienceLevel * 7) * .9F));
		}
	}
}
 
Example 30
/**
 * 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));
    }
}