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

The following are top voted examples for showing how to use net.minecraft.entity.item.EntityItem. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: MakeClayValuableAgain   File: ClayProgressionImprovements.java   View source code 6 votes vote down vote up
@SubscribeEvent
public void dropClay(LivingDropsEvent event) {
    EntityLivingBase deadEntity = event.getEntityLiving();
    World world = deadEntity.getEntityWorld();
    BlockPos position = deadEntity.getPosition();
    double x = position.getX();
    double y = position.getY();
    double z = position.getZ();
    if (deadEntity instanceof EntityWitherSkeleton) {
        if (world.rand.nextInt(10) == 5) {
            event.getDrops().add(new EntityItem(world, x, y, z, new ItemStack(Items.CLAY_BALL)));
        }
    } else if (deadEntity instanceof EntityDragon || deadEntity instanceof EntityWither) {
        event.getDrops().add(new EntityItem(world, x, y, z, new ItemStack(Items.CLAY_BALL)));
    }
}
 
Example 2
Project: DecompiledMinecraft   File: BehaviorDefaultDispenseItem.java   View source code 6 votes vote down vote up
public static void doDispense(World worldIn, ItemStack stack, int speed, EnumFacing facing, IPosition position)
{
    double d0 = position.getX();
    double d1 = position.getY();
    double d2 = position.getZ();

    if (facing.getAxis() == EnumFacing.Axis.Y)
    {
        d1 = d1 - 0.125D;
    }
    else
    {
        d1 = d1 - 0.15625D;
    }

    EntityItem entityitem = new EntityItem(worldIn, d0, d1, d2, stack);
    double d3 = worldIn.rand.nextDouble() * 0.1D + 0.2D;
    entityitem.motionX = (double)facing.getFrontOffsetX() * d3;
    entityitem.motionY = 0.20000000298023224D;
    entityitem.motionZ = (double)facing.getFrontOffsetZ() * d3;
    entityitem.motionX += worldIn.rand.nextGaussian() * 0.007499999832361937D * (double)speed;
    entityitem.motionY += worldIn.rand.nextGaussian() * 0.007499999832361937D * (double)speed;
    entityitem.motionZ += worldIn.rand.nextGaussian() * 0.007499999832361937D * (double)speed;
    worldIn.spawnEntityInWorld(entityitem);
}
 
Example 3
Project: pnc-repressurized   File: RenderDroneHeldItem.java   View source code 6 votes vote down vote up
public void render(@Nonnull ItemStack droneHeldItem) {
    EntityItem carriedItem = new EntityItem(world);
    carriedItem.hoverStart = 0.0F;
    carriedItem.setItem(droneHeldItem);

    double scaleFactor = carriedItem.getItem().getItem() instanceof ItemBlock ? 0.7F : 0.5F;

    double yOffset = -0.2F;
    if (carriedItem.getItem().getItem() instanceof ItemTool || carriedItem.getItem().getItem() instanceof ItemSword) {
        // since items are rendered suspended under the drone,
        // holding tools upside down looks more natural - especially if the drone is digging with them
        GlStateManager.rotate(180, 1, 0, 0);
    }
    GlStateManager.translate(0, yOffset, 0);
    GlStateManager.scale(scaleFactor, scaleFactor, scaleFactor);
    customRenderItem.doRender(carriedItem, 0, 0, 0, 0, 0);
}
 
Example 4
Project: DecompiledMinecraft   File: EntityLiving.java   View source code 6 votes vote down vote up
/**
 * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
 * use this to react to sunlight and start to burn.
 */
public void onLivingUpdate()
{
    super.onLivingUpdate();
    this.worldObj.theProfiler.startSection("looting");

    if (!this.worldObj.isRemote && this.canPickUpLoot() && !this.dead && this.worldObj.getGameRules().getBoolean("mobGriefing"))
    {
        for (EntityItem entityitem : this.worldObj.getEntitiesWithinAABB(EntityItem.class, this.getEntityBoundingBox().expand(1.0D, 0.0D, 1.0D)))
        {
            if (!entityitem.isDead && entityitem.getEntityItem() != null && !entityitem.cannotPickup())
            {
                this.updateEquipmentIfNeeded(entityitem);
            }
        }
    }

    this.worldObj.theProfiler.endSection();
}
 
Example 5
Project: minecraft-quiverbow   File: Endernymous.java   View source code 6 votes vote down vote up
private void dropMagazine(World world, ItemStack stack, Entity entity)
{
	if (!(entity instanceof EntityPlayer)) // For QuiverMobs/Arms Assistants
	{
		this.setCooldown(stack, 60);
		return;
	}

	ItemStack clipStack = Helper.getAmmoStack(EnderQuartzClip.class, stack.getItemDamage());	// Unloading all ammo into that clip

	stack.setItemDamage(this.getMaxDamage());	// Emptying out

	// Creating the clip
	EntityItem entityitem = new EntityItem(world, entity.posX, entity.posY + 1.0d, entity.posZ, clipStack);
	entityitem.delayBeforeCanPickup = 10;

	// And dropping it
	if (entity.captureDrops) { entity.capturedDrops.add(entityitem); }
	else { world.spawnEntityInWorld(entityitem); }

	// SFX
	world.playSoundAtEntity(entity, "random.break", 1.0F, 0.3F);
}
 
Example 6
Project: uniquecrops   File: Dirigible.java   View source code 6 votes vote down vote up
@Override
   public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
	
	if (world.getLightFromNeighbors(pos.up()) >= 9) {
		if ((this.getAge(state) + 1) >= getMaxAge())
		{
			EntityItem ei = new EntityItem(world, pos.getX() + 0.5D, pos.getY(), pos.getZ() + 0.5D, UCItems.generic.createStack(EnumItems.PLUM));
			if (!world.isRemote)
				world.spawnEntityInWorld(ei);
			UCPacketHandler.sendToNearbyPlayers(world, pos, new PacketUCEffect(EnumParticleTypes.EXPLOSION_NORMAL, pos.getX(), pos.getY(), pos.getZ(), 4));
			world.setBlockState(pos, withAge(0), 2);
			return;
		}
	}
	super.updateTick(world, pos, state, rand);
}
 
Example 7
Project: minecraft-quiverbow   File: NetherBellows.java   View source code 6 votes vote down vote up
private void dropMagazine(World world, ItemStack stack, Entity entity)
{
	if (!(entity instanceof EntityPlayer)) // For QuiverMobs/Arms Assistants
	{
		this.setCooldown(stack, 60);
		return;
	}

	ItemStack clipStack = Helper.getAmmoStack(LargeNetherrackMagazine.class, stack.getItemDamage());	// Unloading all ammo into that clip

	stack.setItemDamage(this.getMaxDamage());	// Emptying out

	// Creating the clip
	EntityItem entityitem = new EntityItem(world, entity.posX, entity.posY + 1.0d, entity.posZ, clipStack);
	entityitem.delayBeforeCanPickup = 10;

	// And dropping it
	if (entity.captureDrops) { entity.capturedDrops.add(entityitem); }
	else { world.spawnEntityInWorld(entityitem); }

	// SFX
	world.playSoundAtEntity(entity, "random.break", 1.0F, 0.5F);
}
 
Example 8
Project: uniquecrops   File: EntityEulaBook.java   View source code 6 votes vote down vote up
@Override
  protected void onImpact(RayTraceResult result) {
  	
BlockPos pos = new BlockPos(result.hitVec);
if (result.typeOfHit == RayTraceResult.Type.ENTITY) {
	Entity ent = result.entityHit;
	if (!ent.isDead && ent instanceof EntityPlayerMP && ent.worldObj.isRemote) {
		((EntityPlayerMP)ent).openGui(UniqueCrops.instance, 1, worldObj, (int)ent.posX, (int)ent.posY, (int)ent.posZ);
	}
	this.setDead();
	UCPacketHandler.sendToNearbyPlayers(worldObj, pos, new PacketUCEffect(EnumParticleTypes.CRIT, pos.getX() - 0.5D, pos.getY() - 0.5D, pos.getZ() - 0.5D, 5));
}
else if (result.typeOfHit == RayTraceResult.Type.BLOCK) {
	ItemStack stack = UCItems.generic.createStack(EnumItems.EULA);
	EntityItem eibook = new EntityItem(worldObj, pos.offset(result.sideHit).getX(), pos.offset(result.sideHit).getY(), pos.offset(result.sideHit).getZ(), stack);
	if (!worldObj.isRemote)
		worldObj.spawnEntityInWorld(eibook);
	this.setDead();
}
else
	this.setDead();
  }
 
Example 9
Project: DecompiledMinecraft   File: EntityLivingBase.java   View source code 6 votes vote down vote up
/**
 * Called whenever an item is picked up from walking over it. Args: pickedUpEntity, stackSize
 */
public void onItemPickup(Entity p_71001_1_, int p_71001_2_)
{
    if (!p_71001_1_.isDead && !this.worldObj.isRemote)
    {
        EntityTracker entitytracker = ((WorldServer)this.worldObj).getEntityTracker();

        if (p_71001_1_ instanceof EntityItem)
        {
            entitytracker.sendToAllTrackingEntity(p_71001_1_, new S0DPacketCollectItem(p_71001_1_.getEntityId(), this.getEntityId()));
        }

        if (p_71001_1_ instanceof EntityArrow)
        {
            entitytracker.sendToAllTrackingEntity(p_71001_1_, new S0DPacketCollectItem(p_71001_1_.getEntityId(), this.getEntityId()));
        }

        if (p_71001_1_ instanceof EntityXPOrb)
        {
            entitytracker.sendToAllTrackingEntity(p_71001_1_, new S0DPacketCollectItem(p_71001_1_.getEntityId(), this.getEntityId()));
        }
    }
}
 
Example 10
Project: uniquecrops   File: GrowthSteps.java   View source code 6 votes vote down vote up
@Override
public boolean canAdvance(World world, BlockPos pos, IBlockState state) {

	List<EntityItem> items = world.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(pos, pos.add(1, 1, 1)));
	for (EntityItem item : items) {
		if (!item.isDead && item.getEntityItem() != null) {
			if (item.getEntityItem().getItem() instanceof ItemFood)
			{
				UCPacketHandler.sendToNearbyPlayers(world, pos, new PacketUCEffect(EnumParticleTypes.CLOUD, pos.getX(), pos.getY(), pos.getZ(), 6));
				item.getEntityItem().stackSize--;
				if (item.getEntityItem().stackSize <= 0)
					item.setDead();
				return true;
			}
		}
	}
	return false;
}
 
Example 11
Project: CustomWorldGen   File: Block.java   View source code 6 votes vote down vote up
/**
 * Spawns the given ItemStack as an EntityItem into the World at the given position
 */
public static void spawnAsEntity(World worldIn, BlockPos pos, ItemStack stack)
{
    if (!worldIn.isRemote && worldIn.getGameRules().getBoolean("doTileDrops") && !worldIn.restoringBlockSnapshots) // do not drop items while restoring blockstates, prevents item dupe
    {
        if (captureDrops.get())
        {
            capturedDrops.get().add(stack);
            return;
        }
        float f = 0.5F;
        double d0 = (double)(worldIn.rand.nextFloat() * 0.5F) + 0.25D;
        double d1 = (double)(worldIn.rand.nextFloat() * 0.5F) + 0.25D;
        double d2 = (double)(worldIn.rand.nextFloat() * 0.5F) + 0.25D;
        EntityItem entityitem = new EntityItem(worldIn, (double)pos.getX() + d0, (double)pos.getY() + d1, (double)pos.getZ() + d2, stack);
        entityitem.setDefaultPickupDelay();
        worldIn.spawnEntityInWorld(entityitem);
    }
}
 
Example 12
Project: DecompiledMinecraft   File: EntityWither.java   View source code 6 votes vote down vote up
/**
 * Drop 0-2 items of this living's type
 */
protected void dropFewItems(boolean p_70628_1_, int p_70628_2_)
{
    EntityItem entityitem = this.dropItem(Items.nether_star, 1);

    if (entityitem != null)
    {
        entityitem.setNoDespawn();
    }

    if (!this.worldObj.isRemote)
    {
        for (EntityPlayer entityplayer : this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, this.getEntityBoundingBox().expand(50.0D, 100.0D, 50.0D)))
        {
            entityplayer.triggerAchievement(AchievementList.killWither);
        }
    }
}
 
Example 13
Project: harshencastle   File: BaseItemRenderer.java   View source code 6 votes vote down vote up
@Override
public void render(T te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
	super.render(te, x, y, z, partialTicks, destroyStage, alpha);
	EntityItem item = new EntityItem(Minecraft.getMinecraft().world, 0, 0, 0, te.getItem());
	item.hoverStart = 0.0f;
	int rotateAngle = te.getTimer() * 6;
	GlStateManager.pushMatrix();
	{
		GlStateManager.translate(x, y, z);
		GlStateManager.translate(movePos().x, movePos().y, movePos().z);
		GlStateManager.scale(0.7f, 0.7f, 0.7f);
		GlStateManager.translate(0, Math.sin(rotateAngle) / 20f, 0);
		moveMore(te);
		GlStateManager.rotate(te.getTimer() % 360 * getMovementSpeed(te), 0, 1, 0);
		Minecraft.getMinecraft().getRenderManager().renderEntity(item, 0f, 0f, 0f, 0f, 0f, false);
		
	}
	GlStateManager.popMatrix();
}
 
Example 14
Project: Adventurers-Toolbox   File: EntityRock.java   View source code 6 votes vote down vote up
@Override
protected void onImpact(RayTraceResult result) {
	//System.out.println(MathHelper.sqrt((MathHelper.abs((float) this.motionX) + MathHelper.abs((float) this.motionY) + MathHelper.abs((float) this.motionZ))));
	if (result.entityHit != null) {
		float f = MathHelper.sqrt((MathHelper.abs((float) this.motionX) + MathHelper.abs((float) this.motionY) + MathHelper.abs((float) this.motionZ)));
		result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 4F * f);
	}

	if (!this.world.isRemote) {
		if (this.rand.nextFloat() < 0.5F) {
			EntityItem rock = new EntityItem(world, posX, posY, posZ, new ItemStack(ModItems.rock));
			world.spawnEntity(rock);
		} else {
			this.world.setEntityState(this, (byte) 3);
		}
		this.setDead();
	}
}
 
Example 15
Project: Infernum   File: BlockPedestal.java   View source code 6 votes vote down vote up
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand,
		EnumFacing side, float hitX, float hitY, float hitZ) {

	if (!world.isRemote && world.getTileEntity(pos) instanceof TilePedestal) {
		TilePedestal pedestal = (TilePedestal) world.getTileEntity(pos);
		if (pedestal.getStack().func_190926_b()) {
			if (!player.getHeldItem(hand).func_190926_b()) {
				pedestal.setStack(player.getHeldItem(hand));
				player.inventory.setInventorySlotContents(player.inventory.currentItem, ItemStack.field_190927_a);
				player.openContainer.detectAndSendChanges();
			}
		} else {
			ItemStack stack = pedestal.getStack();
			pedestal.setStack(ItemStack.field_190927_a);
			if (!player.inventory.addItemStackToInventory(stack)) {
				EntityItem entityItem = new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), stack);
				world.spawnEntity(entityItem);
			} else {
				player.openContainer.detectAndSendChanges();
			}
		}
	}

	return true;
}
 
Example 16
Project: DecompiledMinecraft   File: EntityLiving.java   View source code 6 votes vote down vote up
/**
 * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
 * use this to react to sunlight and start to burn.
 */
public void onLivingUpdate()
{
    super.onLivingUpdate();
    this.worldObj.theProfiler.startSection("looting");

    if (!this.worldObj.isRemote && this.canPickUpLoot() && !this.dead && this.worldObj.getGameRules().getBoolean("mobGriefing"))
    {
        for (EntityItem entityitem : this.worldObj.getEntitiesWithinAABB(EntityItem.class, this.getEntityBoundingBox().expand(1.0D, 0.0D, 1.0D)))
        {
            if (!entityitem.isDead && entityitem.getEntityItem() != null && !entityitem.cannotPickup())
            {
                this.updateEquipmentIfNeeded(entityitem);
            }
        }
    }

    this.worldObj.theProfiler.endSection();
}
 
Example 17
Project: CustomWorldGen   File: EntityLiving.java   View source code 6 votes vote down vote up
/**
 * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
 * use this to react to sunlight and start to burn.
 */
public void onLivingUpdate()
{
    super.onLivingUpdate();
    this.worldObj.theProfiler.startSection("looting");

    if (!this.worldObj.isRemote && this.canPickUpLoot() && !this.dead && this.worldObj.getGameRules().getBoolean("mobGriefing"))
    {
        for (EntityItem entityitem : this.worldObj.getEntitiesWithinAABB(EntityItem.class, this.getEntityBoundingBox().expand(1.0D, 0.0D, 1.0D)))
        {
            if (!entityitem.isDead && entityitem.getEntityItem() != null && !entityitem.cannotPickup())
            {
                this.updateEquipmentIfNeeded(entityitem);
            }
        }
    }

    this.worldObj.theProfiler.endSection();
}
 
Example 18
Project: MeeCreeps   File: DigTunnelActionWorker.java   View source code 6 votes vote down vote up
private void buildSupport(BlockPos pos, EntityItem entityItem) {
    ItemStack blockStack = entityItem.getItem();
    ItemStack actual = blockStack.splitStack(1);
    if (blockStack.isEmpty()) {
        entityItem.setDead();
    }
    if (actual.isEmpty()) {
        return;
    }
    Item item = actual.getItem();
    if (!(item instanceof ItemBlock)) {
        // Safety
        return;
    }

    IMeeCreep entity = helper.getMeeCreep();
    World world = entity.getWorld();
    Block block = ((ItemBlock) item).getBlock();
    IBlockState stateForPlacement = block.getStateForPlacement(world, pos, EnumFacing.UP, 0, 0, 0, item.getMetadata(actual), GeneralTools.getHarvester(), EnumHand.MAIN_HAND);
    world.setBlockState(pos, stateForPlacement, 3);
    SoundTools.playSound(world, block.getSoundType().getPlaceSound(), pos.getX(), pos.getY(), pos.getZ(), 1.0f, 1.0f);
}
 
Example 19
Project: DecompiledMinecraft   File: EntityLivingBase.java   View source code 6 votes vote down vote up
/**
 * Called whenever an item is picked up from walking over it. Args: pickedUpEntity, stackSize
 */
public void onItemPickup(Entity p_71001_1_, int p_71001_2_)
{
    if (!p_71001_1_.isDead && !this.worldObj.isRemote)
    {
        EntityTracker entitytracker = ((WorldServer)this.worldObj).getEntityTracker();

        if (p_71001_1_ instanceof EntityItem)
        {
            entitytracker.sendToAllTrackingEntity(p_71001_1_, new S0DPacketCollectItem(p_71001_1_.getEntityId(), this.getEntityId()));
        }

        if (p_71001_1_ instanceof EntityArrow)
        {
            entitytracker.sendToAllTrackingEntity(p_71001_1_, new S0DPacketCollectItem(p_71001_1_.getEntityId(), this.getEntityId()));
        }

        if (p_71001_1_ instanceof EntityXPOrb)
        {
            entitytracker.sendToAllTrackingEntity(p_71001_1_, new S0DPacketCollectItem(p_71001_1_.getEntityId(), this.getEntityId()));
        }
    }
}
 
Example 20
Project: MeeCreeps   File: DigdownStairsActionWorker.java   View source code 6 votes vote down vote up
private void collectCobble(EntityItem entityItem) {
    ItemStack blockStack = entityItem.getItem();
    ItemStack actual = blockStack.splitStack(6);
    if (blockStack.isEmpty()) {
        entityItem.setDead();
    }
    if (actual.isEmpty()) {
        return;
    }
    Item item = actual.getItem();
    if (!(item instanceof ItemBlock)) {
        // Safety
        return;
    }
    numCobble += actual.getCount();
}
 
Example 21
Project: BaseClient   File: EntityWither.java   View source code 6 votes vote down vote up
/**
 * Drop 0-2 items of this living's type
 */
protected void dropFewItems(boolean p_70628_1_, int p_70628_2_)
{
    EntityItem entityitem = this.dropItem(Items.nether_star, 1);

    if (entityitem != null)
    {
        entityitem.setNoDespawn();
    }

    if (!this.worldObj.isRemote)
    {
        for (EntityPlayer entityplayer : this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, this.getEntityBoundingBox().expand(50.0D, 100.0D, 50.0D)))
        {
            entityplayer.triggerAchievement(AchievementList.killWither);
        }
    }
}
 
Example 22
Project: pnc-repressurized   File: ModelChargingStation.java   View source code 5 votes vote down vote up
public void renderModel(float scale, boolean renderChargePad, EntityItem ghostEntityItem) {
    if (renderChargePad) {
        shape3.render(scale);
        shape4.render(scale);
        shape5.render(scale);
        shape6.render(scale);
        shape7.render(scale);
        shape8.render(scale);
        shape9.render(scale);
        shape10.render(scale);
        shape11.render(scale);
        shape12.render(scale);
        shape13.render(scale);
        shape14.render(scale);
        shape15.render(scale);
        shape16.render(scale);
    }
    if (ghostEntityItem != null) {
        if (customRenderItem == null) {
            customRenderItem = new AbstractModelRenderer.NoBobItemRenderer();
        }
        GlStateManager.translate(0, 1.25f, 0);
        GlStateManager.scale(1.0F, -1F, -1F);

        RenderManager renderManager = Minecraft.getMinecraft().getRenderManager();
        boolean fancySetting = renderManager.options.fancyGraphics;
        renderManager.options.fancyGraphics = true;
        customRenderItem.doRender(ghostEntityItem, 0, 0, 0, 0, 0);
        renderManager.options.fancyGraphics = fancySetting;
    }
}
 
Example 23
Project: Thermionics   File: BlockScaffold.java   View source code 5 votes vote down vote up
@Override
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) {
	if (entity instanceof EntityItem) return;
	
	if (entity.isCollidedHorizontally) {
		entity.motionY = 0.35;
	} else if (entity.isSneaking()) {
		entity.motionY = 0.08; //Stop, but also counteract EntityLivingBase-applied microgravity
	} else if (entity.motionY<-0.20) {
		entity.motionY = -0.20;
	}
	entity.fallDistance = 0.0f;
}
 
Example 24
Project: Backmemed   File: EntityPlayer.java   View source code 5 votes vote down vote up
@Nullable

    /**
     * Drop one item out of the currently selected stack if {@code dropAll} is false. If {@code dropItem} is true the
     * entire stack is dropped.
     */
    public EntityItem dropItem(boolean dropAll)
    {
        return this.dropItem(this.inventory.decrStackSize(this.inventory.currentItem, dropAll && !this.inventory.getCurrentItem().func_190926_b() ? this.inventory.getCurrentItem().func_190916_E() : 1), false, true);
    }
 
Example 25
Project: pnc-repressurized   File: PneumaticCraftUtils.java   View source code 5 votes vote down vote up
public static void dropItemOnGroundPrecisely(ItemStack stack, World world, double x, double y, double z) {
    EntityItem entityItem = new EntityItem(world, x, y, z, new ItemStack(stack.getItem(), stack.getCount(), stack.getItemDamage()));

    if (stack.hasTagCompound()) {
        entityItem.getItem().setTagCompound(stack.getTagCompound().copy());
    }

    world.spawnEntity(entityItem);
    stack.setCount(0);
}
 
Example 26
Project: CustomWorldGen   File: TileEntityHopper.java   View source code 5 votes vote down vote up
/**
 * Attempts to place the passed EntityItem's stack into the inventory using as many slots as possible. Returns false
 * if the stackSize of the drop was not depleted.
 */
public static boolean putDropInInventoryAllSlots(IInventory p_145898_0_, EntityItem itemIn)
{
    boolean flag = false;

    if (itemIn == null)
    {
        return false;
    }
    else
    {
        ItemStack itemstack = itemIn.getEntityItem().copy();
        ItemStack itemstack1 = putStackInInventoryAllSlots(p_145898_0_, itemstack, (EnumFacing)null);

        if (itemstack1 != null && itemstack1.stackSize != 0)
        {
            itemIn.setEntityItemStack(itemstack1);
        }
        else
        {
            flag = true;
            itemIn.setDead();
        }

        return flag;
    }
}
 
Example 27
Project: EndermanEvolution   File: EntityFrienderman.java   View source code 5 votes vote down vote up
@Override
public boolean shouldExecute() {
	//EntityLivingBase entitylivingbase = thePet.getOwner();
	itemsNear = thePet.getEntityWorld().getEntitiesWithinAABB(EntityItem.class, thePet.getEntityBoundingBox().expand(0.0D, -1.0D, 0.0D).expand(6.0D, 2.0D, 6.0D));
	if (!thePet.isTamed() || itemsNear.size() <= 0 || !thePet.isHoldingChest()) {
		return false;
	}
	return true;
}
 
Example 28
Project: pnc-repressurized   File: TileEntityPressureChamberValve.java   View source code 5 votes vote down vote up
private void captureEntityItemsInChamber(){
    AxisAlignedBB bbBox = getChamberAABB();
    List<EntityItem> items = getWorld().getEntitiesWithinAABB(EntityItem.class, bbBox);
    for(EntityItem item : items){
        if(!item.isDead){
            ItemStack stack = item.getItem();
            ItemStack leftover = ItemHandlerHelper.insertItem(itemsInChamber, stack, false);
            if(leftover.isEmpty()) item.setDead();
            else item.setItem(stack);
        }
    }
}
 
Example 29
Project: BaseClient   File: RenderEntityItem.java   View source code 5 votes vote down vote up
private int func_177077_a(EntityItem itemIn, double p_177077_2_, double p_177077_4_, double p_177077_6_, float p_177077_8_, IBakedModel p_177077_9_)
{
    ItemStack itemstack = itemIn.getEntityItem();
    Item item = itemstack.getItem();

    if (item == null)
    {
        return 0;
    }
    else
    {
        boolean flag = p_177077_9_.isGui3d();
        int i = this.func_177078_a(itemstack);
        float f = 0.25F;
        float f1 = MathHelper.sin(((float)itemIn.getAge() + p_177077_8_) / 10.0F + itemIn.hoverStart) * 0.1F + 0.1F;
        float f2 = p_177077_9_.getItemCameraTransforms().getTransform(ItemCameraTransforms.TransformType.GROUND).scale.y;
        GlStateManager.translate((float)p_177077_2_, (float)p_177077_4_ + f1 + 0.25F * f2, (float)p_177077_6_);

        if (flag || this.renderManager.options != null)
        {
            float f3 = (((float)itemIn.getAge() + p_177077_8_) / 20.0F + itemIn.hoverStart) * (180F / (float)Math.PI);
            GlStateManager.rotate(f3, 0.0F, 1.0F, 0.0F);
        }

        if (!flag)
        {
            float f6 = -0.0F * (float)(i - 1) * 0.5F;
            float f4 = -0.0F * (float)(i - 1) * 0.5F;
            float f5 = -0.046875F * (float)(i - 1) * 0.5F;
            GlStateManager.translate(f6, f4, f5);
        }

        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        return i;
    }
}
 
Example 30
Project: BetterBeginningsReborn   File: TileEntityInfusionRepair.java   View source code 5 votes vote down vote up
private void absorbItems()
   {
List<EntityItem> items = world.getEntitiesWithinAABB(EntityItem.class, searchBox);
IBlockState state = world.getBlockState(pos);
for (EntityItem entityItem : items)
{
    if(tryAbsorbDroppedItem(entityItem, state))
    {
	markDirty();
	world.notifyBlockUpdate(pos, state, state, 8);
    }
    if(entityItem.getItem().getCount() == 0)
	entityItem.setDead();
}
   }
 
Example 31
Project: uniquecrops   File: BlockHourglass.java   View source code 5 votes vote down vote up
@Override
public Entity createEntity(World world, Entity location, ItemStack stack) {
	
	if (location instanceof EntityItem) {
		EntityItemHourglass hourglass = new EntityItemHourglass(world, (EntityItem)location, stack);
		return hourglass;
	}
	return null;
}
 
Example 32
Project: Uranium   File: TrackingRange.java   View source code 5 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.worldObj.getSpigotConfig(); // Cauldron
    int range = defaultRange;
    if ( entity instanceof EntityPlayerMP )
    {
        range = config.playerTrackingRange;
    } else if ( entity.defaultActivationState || entity instanceof EntityGhast )
    {
        range = defaultRange;
    } else if ( entity.activationType == 1 )
    {
        range = config.monsterTrackingRange;
    } else if ( entity.activationType == 2 )
    {
        range = config.animalTrackingRange;
    } else if ( entity instanceof EntityItemFrame || entity instanceof EntityPainting || entity instanceof EntityItem || entity instanceof EntityXPOrb )
    {
        range = config.miscTrackingRange;
    }
    // Cauldron start - allow for 0 to disable tracking ranges
    if (range == 0)
    {
        return defaultRange;
    }
    // Cauldron end

    return Math.min( config.maxTrackingRange, range );
}
 
Example 33
Project: Uranium   File: ItemSnapshot.java   View source code 5 votes vote down vote up
/**
 * 将物品放到玩家身上
 * 
 * @return 如果背包满,将生成物品在地上并返回false
 */
public boolean apply(){
    if(!this.mApply){
        this.mApply=true;

        if(!this.mPlayer.inventory.addItemStackToInventory(this.mItem)){
            this.mPlayer.worldObj.spawnEntityInWorld(
                    new EntityItem(this.mPlayer.worldObj,this.mPlayer.posX,this.mPlayer.posY,this.mPlayer.posZ,this.mItem));
            return false;
        }
    }
    return true;
}
 
Example 34
Project: JustJunk   File: PotionSick.java   View source code 5 votes vote down vote up
@Override
public void performEffect(EntityLivingBase entityLivingBaseIn, int p_76394_2_){
    if (!entityLivingBaseIn.world.isRemote){
        EntityItem item = new EntityItem(entityLivingBaseIn.world, entityLivingBaseIn.posX + (entityLivingBaseIn.getLookVec().xCoord * 0.2F), entityLivingBaseIn.posY + entityLivingBaseIn.getEyeHeight() - 0.7F, entityLivingBaseIn.posZ + (entityLivingBaseIn.getLookVec().zCoord), new ItemStack(loot_table[(int) (Math.random() * loot_table.length)], 1));
        item.setPickupDelay(15);
        entityLivingBaseIn.world.spawnEntity(item);
    }
}
 
Example 35
Project: ExPetrum   File: BlockLog.java   View source code 5 votes vote down vote up
@Override
public void dropLogItem(World w, IBlockState state, Vec3d at)
{
	state = state.withProperty(AXIS, Axis.Y);
	EntityItem item = new EntityItem(w, at.x, at.y, at.z, new ItemStack(ExPBlocks.logsDeco[this.logIndex], 1, this.getMetaFromState(state)));
	if (!w.isRemote)
	{
		w.spawnEntity(item);
	}
}
 
Example 36
Project: BaseClient   File: EntityPlayerSP.java   View source code 5 votes vote down vote up
/**
 * Called when player presses the drop item key
 */
public EntityItem dropOneItem(boolean dropAll)
{
    C07PacketPlayerDigging.Action c07packetplayerdigging$action = dropAll ? C07PacketPlayerDigging.Action.DROP_ALL_ITEMS : C07PacketPlayerDigging.Action.DROP_ITEM;
    this.sendQueue.addToSendQueue(new C07PacketPlayerDigging(c07packetplayerdigging$action, BlockPos.ORIGIN, EnumFacing.DOWN));
    return null;
}
 
Example 37
Project: Thermionics   File: BlockScaffoldCable.java   View source code 5 votes vote down vote up
@Override
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) {
	if (entity instanceof EntityItem) return;
	if (entity.isCollidedHorizontally) {
		entity.motionY = 0.35;
	} else if (entity.isSneaking()) {
		entity.motionY = 0.08; //Stop, but also counteract EntityLivingBase-applied microgravity
	} else if (entity.motionY<-0.20) {
		entity.motionY = -0.20;
	}
	entity.fallDistance = 0.0f;
}
 
Example 38
Project: Bewitchment   File: SpellMagnet.java   View source code 5 votes vote down vote up
@Override
public void performEffect(RayTraceResult rtrace, EntityLivingBase caster, World world) {
	if (rtrace.typeOfHit == Type.BLOCK && caster != null) {
		world.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(rtrace.hitVec, rtrace.hitVec.addVector(1, 1, 1)).grow(2)).forEach(ei -> {
			ei.setNoPickupDelay();
			if (caster instanceof EntityPlayer) {
				ei.onCollideWithPlayer((EntityPlayer) caster);
			} else {
				ei.setPositionAndUpdate(caster.posX, caster.posY, caster.posZ);
			}
		});
	}
}
 
Example 39
Project: DecompiledMinecraft   File: EntitySheep.java   View source code 5 votes vote down vote up
/**
 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
 */
public boolean interact(EntityPlayer player)
{
    ItemStack itemstack = player.inventory.getCurrentItem();

    if (itemstack != null && itemstack.getItem() == Items.shears && !this.getSheared() && !this.isChild())
    {
        if (!this.worldObj.isRemote)
        {
            this.setSheared(true);
            int i = 1 + this.rand.nextInt(3);

            for (int j = 0; j < i; ++j)
            {
                EntityItem entityitem = this.entityDropItem(new ItemStack(Item.getItemFromBlock(Blocks.wool), 1, this.getFleeceColor().getMetadata()), 1.0F);
                entityitem.motionY += (double)(this.rand.nextFloat() * 0.05F);
                entityitem.motionX += (double)((this.rand.nextFloat() - this.rand.nextFloat()) * 0.1F);
                entityitem.motionZ += (double)((this.rand.nextFloat() - this.rand.nextFloat()) * 0.1F);
            }
        }

        itemstack.damageItem(1, player);
        this.playSound("mob.sheep.shear", 1.0F, 1.0F);
    }

    return super.interact(player);
}
 
Example 40
Project: uniquecrops   File: Feroxia.java   View source code 5 votes vote down vote up
@Override
   public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
	
	if (this.getAge(state) >= getMaxAge() || world.isRemote)
		return;
	
	if (!this.canBlockStay(world, pos, state)) {
		EntityItem ei = new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.1, pos.getZ() + 0.5, new ItemStack(this.getSeed()));
		world.spawnEntityInWorld(ei);
		world.setBlockToAir(pos);
		return;
	}
	TileEntity tile = world.getTileEntity(pos);
	if (tile == null || (tile != null && !(tile instanceof TileFeroxia)))
		return;
	
	TileFeroxia te = (TileFeroxia)tile;
	if (te.getOwner() == null || (te.getOwner() != null && UCUtils.getPlayerFromUUID(te.getOwner().toString()) == null))
		return;
	
	NBTTagList taglist = UCUtils.getServerTaglist(UCUtils.getPlayerFromUUID(te.getOwner().toString()).getEntityId());
	if (taglist == null)
		return;
	NBTTagCompound tag = taglist.getCompoundTagAt(this.getAge(state));
	int stage = tag.getInteger("stage" + this.getAge(state));
	
	if (!steps.get(stage).getCondition().canAdvance(world, pos, state)) {
		return;
	}
       int i = this.getAge(state);

       if (i < this.getMaxAge()) {
           float f = getGrowthChance(this, world, pos);
           if (rand.nextInt((int)(25.0F / f) + 1) == 0)
           	world.setBlockState(pos, this.withAge(i + 1), 2);
       }
}