Java Code Examples for net.minecraft.entity.item.EntityItem#setDefaultPickupDelay()

The following examples show how to use net.minecraft.entity.item.EntityItem#setDefaultPickupDelay() . 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: BlockNoodle.java    From Sakura_mod with MIT License 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 && !stack.isEmpty() && worldIn.getGameRules().getBoolean("doTileDrops")&& !worldIn.restoringBlockSnapshots) // do not drop items while restoring blockstates, prevents item dupe
    {
        if (captureDrops.get()){
            capturedDrops.get().add(stack);
            return;
        }
        double d0 = worldIn.rand.nextFloat() * 0.5F + 0.25D;
        double d1 = worldIn.rand.nextFloat() * 0.5F + 0.25D;
        double d2 = worldIn.rand.nextFloat() * 0.5F + 0.25D;
        EntityItem entityitem = new EntityItem(worldIn, pos.getX() + d0, pos.getY() + d1, pos.getZ() + d2, stack);
        entityitem.setDefaultPickupDelay();
        worldIn.spawnEntity(entityitem);
    }
}
 
Example 2
Source File: EntityEnderArrow.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void dropAsItem(boolean doDrop)
{
    if (this.canBePickedUp != 1 || doDrop == false)
    {
        return;
    }

    EntityItem entityitem = new EntityItem(this.getEntityWorld(), this.posX, this.posY, this.posZ, this.getArrowStack());
    Random r = new Random();

    entityitem.motionX = 0.01d * r.nextGaussian();
    entityitem.motionY = 0.01d * r.nextGaussian() + 0.05d;
    entityitem.motionZ = 0.01d * r.nextGaussian();
    entityitem.setDefaultPickupDelay();

    this.getEntityWorld().spawnEntity(entityitem);
}
 
Example 3
Source File: EntityEnderPearlReusable.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void dropAsItem()
{
    if (this.isDead)
    {
        return;
    }

    int damage = (this.isElite ? 1 : 0);
    EntityItem entityitem = new EntityItem(this.getEntityWorld(), this.posX, this.posY, this.posZ, new ItemStack(EnderUtilitiesItems.ENDER_PEARL_REUSABLE, 1, damage));

    entityitem.motionX = 0.05d * this.getEntityWorld().rand.nextGaussian();
    entityitem.motionY = 0.05d * this.getEntityWorld().rand.nextGaussian() + 0.2d;
    entityitem.motionZ = 0.05d * this.getEntityWorld().rand.nextGaussian();
    entityitem.setDefaultPickupDelay();

    this.getEntityWorld().spawnEntity(entityitem);
}
 
Example 4
Source File: BlockChestnut.java    From Sakura_mod with MIT License 5 votes vote down vote up
private static void dropItem(ItemStack itemStack, World world, BlockPos pos)
{
  if ((world.restoringBlockSnapshots) || (world.isRemote)) {
    return;
  }
  float f = 0.5F;
  double d0 = world.rand.nextFloat() * f + 0.25D;
  double d1 = world.rand.nextFloat() * f + 0.25D;
  double d2 = world.rand.nextFloat() * f + 0.25D;
  

  EntityItem entityItem = new EntityItem(world, pos.getX() + d0, pos.getY() + d1, pos.getZ() + d2, itemStack);
  entityItem.setDefaultPickupDelay();
  world.spawnEntity(entityItem);
}
 
Example 5
Source File: MetaTileEntityBlockBreaker.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void addToInventoryOrDropItems(List<ItemStack> drops) {
    EnumFacing outputFacing = getOutputFacing();
    double itemSpawnX = getPos().getX() + 0.5 + outputFacing.getFrontOffsetX();
    double itemSpawnY = getPos().getX() + 0.5 + outputFacing.getFrontOffsetX();
    double itemSpawnZ = getPos().getX() + 0.5 + outputFacing.getFrontOffsetX();
    for(ItemStack itemStack : drops) {
        ItemStack remainStack = ItemHandlerHelper.insertItemStacked(exportItems, itemStack, false);
        if(!remainStack.isEmpty()) {
            EntityItem entityitem = new EntityItem(getWorld(), itemSpawnX, itemSpawnY, itemSpawnZ, remainStack);
            entityitem.setDefaultPickupDelay();
            getWorld().spawnEntity(entityitem);
        }
    }
}
 
Example 6
Source File: ToolUtility.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void dropListOfItems(World world, BlockPos pos, List<ItemStack> drops) {
    Random rand = new Random();
    for (ItemStack stack : drops) {
        float f = 0.7F;
        double offX = (rand.nextFloat() * f) + (1.0F - f) * 0.5D;
        double offY = (rand.nextFloat() * f) + (1.0F - f) * 0.5D;
        double offZ = (rand.nextFloat() * f) + (1.0F - f) * 0.5D;
        EntityItem entityItem = new EntityItem(world, pos.getX() + offX, pos.getY() + offY, pos.getZ() + offZ, stack);
        entityItem.setDefaultPickupDelay();
        world.spawnEntity(entityItem);
    }
}
 
Example 7
Source File: BlockDrawingHelper.java    From malmo with MIT License 5 votes vote down vote up
/** Spawn a single item at the specified position.
 * @param item the actual item to be spawned.
 * @param pos the position at which to spawn it.
 * @param world the world in which to spawn the item.
 */
public void placeItem(ItemStack stack, BlockPos pos, World world, boolean centreItem)
{
    EntityItem entityitem = createItem(stack, (double)pos.getX(), (double)pos.getY(), (double)pos.getZ(), world, centreItem);
    // Set the motions to zero to prevent random movement.
    entityitem.motionX = 0;
    entityitem.motionY = 0;
    entityitem.motionZ = 0;
    entityitem.setDefaultPickupDelay();
    world.spawnEntity(entityitem);
}
 
Example 8
Source File: ItemPLTreetap.java    From Production-Line with MIT License 5 votes vote down vote up
private static void ejectResin(World world, BlockPos pos, EnumFacing side, int quantity) {
    double ejectBias = 0.3D;
    double ejectX = (double) pos.getX() + 0.5D + (double) side.getFrontOffsetX() * 0.3D;
    double ejectY = (double) pos.getY() + 0.5D + (double) side.getFrontOffsetY() * 0.3D;
    double ejectZ = (double) pos.getZ() + 0.5D + (double) side.getFrontOffsetZ() * 0.3D;

    for (int i = 0; i < quantity; ++i) {
        EntityItem entityitem = new EntityItem(world, ejectX, ejectY, ejectZ, ItemName.misc_resource.getItemStack(MiscResourceType.resin));
        entityitem.setDefaultPickupDelay();
        world.spawnEntity(entityitem);
    }

}
 
Example 9
Source File: BlockUtils.java    From OpenModsLib with MIT License 5 votes vote down vote up
public static EntityItem dropItemStackInWorld(World worldObj, double x, double y, double z, @Nonnull ItemStack stack) {
	float f = 0.7F;
	float d0 = worldObj.rand.nextFloat() * f + (1.0F - f) * 0.5F;
	float d1 = worldObj.rand.nextFloat() * f + (1.0F - f) * 0.5F;
	float d2 = worldObj.rand.nextFloat() * f + (1.0F - f) * 0.5F;
	EntityItem entityitem = new EntityItem(worldObj, x + d0, y + d1, z + d2, stack);
	entityitem.setDefaultPickupDelay();
	if (stack.hasTagCompound()) {
		entityitem.getItem().setTagCompound(stack.getTagCompound().copy());
	}
	worldObj.spawnEntity(entityitem);
	return entityitem;
}