Java Code Examples for net.minecraft.world.World#spawnEntityInWorld()

The following examples show how to use net.minecraft.world.World#spawnEntityInWorld() . 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
Source Project: Artifacts   File: DispenserBehaviorFireball.java    License: MIT License 6 votes vote down vote up
/**
 * Dispense the specified stack, play the dispense sound and spawn particles.
 */
public ItemStack dispenseStack(IBlockSource par1IBlockSource, ItemStack par2ItemStack)
{
    EnumFacing enumfacing = BlockTrap.getFacing(par1IBlockSource.getBlockMetadata());
    IPosition iposition = BlockTrap.getIPositionFromBlockSource(par1IBlockSource);
    double d0 = iposition.getX() + (double)((float)enumfacing.getFrontOffsetX() * 0.3F);
    double d1 = iposition.getY() + (double)((float)enumfacing.getFrontOffsetX() * 0.3F);
    double d2 = iposition.getZ() + (double)((float)enumfacing.getFrontOffsetZ() * 0.3F);
    World world = par1IBlockSource.getWorld();
    Random random = world.rand;
    double d3 = random.nextGaussian() * 0.05D + (double)enumfacing.getFrontOffsetX();
    double d4 = random.nextGaussian() * 0.05D + (double)enumfacing.getFrontOffsetY();
    double d5 = random.nextGaussian() * 0.05D + (double)enumfacing.getFrontOffsetZ();
    world.spawnEntityInWorld(new EntitySmallFireball(world, d0, d1, d2, d3, d4, d5));
    par2ItemStack.splitStack(1);
    return par2ItemStack;
}
 
Example 2
@Override
protected void dropInventory(World world, int x, int y, int z){
    TileEntity tileEntity = world.getTileEntity(x, y, z);
    if(!(tileEntity instanceof TileEntityAssemblyPlatform)) return;
    TileEntityAssemblyPlatform inventory = (TileEntityAssemblyPlatform)tileEntity;
    Random rand = new Random();
    ItemStack itemStack = inventory.getHeldStack();
    if(itemStack != null && itemStack.stackSize > 0) {
        float dX = rand.nextFloat() * 0.8F + 0.1F;
        float dY = rand.nextFloat() * 0.8F + 0.1F;
        float dZ = rand.nextFloat() * 0.8F + 0.1F;

        EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.getItem(), itemStack.stackSize, itemStack.getItemDamage()));

        if(itemStack.hasTagCompound()) {
            entityItem.getEntityItem().setTagCompound((NBTTagCompound)itemStack.getTagCompound().copy());
        }

        float factor = 0.05F;
        entityItem.motionX = rand.nextGaussian() * factor;
        entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
        entityItem.motionZ = rand.nextGaussian() * factor;
        world.spawnEntityInWorld(entityItem);
        itemStack.stackSize = 0;
    }
}
 
Example 3
Source Project: GardenCollection   File: ItemHeavyChain.java    License: MIT License 6 votes vote down vote up
@Override
public boolean onItemUse (ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    Block block = world.getBlock(x, y, z);
    int meta = world.getBlockMetadata(x, y, z);

    if (block instanceof BlockCauldron && side == 1 && itemStack.getItemDamage() == 0) {
        int waterLevel = BlockCauldron.func_150027_b(meta);
        if (waterLevel == 0)
            return false;

        ItemStack newItem = new ItemStack(ModBlocks.heavyChain, 1, 3);
        itemStack.stackSize--;

        EntityItem itemEntity = new EntityItem(world, x + .5, y + 1.5, z + .5, newItem);
        itemEntity.playSound("random.splash", 0.25F, 1.0F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.4F);

        world.spawnEntityInWorld(itemEntity);
        return true;
    }

    return super.onItemUse(itemStack, player, world, x, y, z, side, hitX, hitY, hitZ);
}
 
Example 4
public static void dropItemOnGround(ItemStack stack, World world, double x, double y, double z){
    float dX = rand.nextFloat() * 0.8F + 0.1F;
    float dY = rand.nextFloat() * 0.8F + 0.1F;
    float dZ = rand.nextFloat() * 0.8F + 0.1F;

    EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(stack.getItem(), stack.stackSize, stack.getItemDamage()));

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

    float factor = 0.05F;
    entityItem.motionX = rand.nextGaussian() * factor;
    entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
    entityItem.motionZ = rand.nextGaussian() * factor;
    world.spawnEntityInWorld(entityItem);
    stack.stackSize = 0;
}
 
Example 5
@Override
public void executeFullGrownEffect(World world, int x, int y, int z, Random rand){
    if(world.getBlockMetadata(x, y, z) == 14) {
        if(!world.isRemote) {
            world.createExplosion(null, x + 0.5D, y + 0.5D, z + 0.5D, 0.5F, false);
            EntityItem item = new EntityItem(world, x + 0.5D, y + 0.5D, z + 0.5D, new ItemStack(Itemss.plasticPlant, 1, ItemPlasticPlants.CREEPER_PLANT_DAMAGE));
            item.motionX = (rand.nextGaussian() - 0.5D) / 2;
            item.motionY = rand.nextDouble();
            item.motionZ = (rand.nextGaussian() - 0.5D) / 2;
            item.lifespan = 300;
            ItemPlasticPlants.markInactive(item);
            world.spawnEntityInWorld(item);
            world.setBlock(x, y, z, this, world.getBlockMetadata(x, y, z) - 2, 3);
        }
    } else {
        world.setBlockMetadataWithNotify(x, y, z, 14, 3);
        NetworkHandler.sendToAllAround(new PacketPlaySound("creeper.primed", x + 0.5D, y + 0.5D, z + 0.5D, 1.0F, 1.0F, true), world);
        world.scheduleBlockUpdate(x, y, z, this, 60);
    }
}
 
Example 6
@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
    if(!par3EntityPlayer.capabilities.isCreativeMode)
    {
        --par1ItemStack.stackSize;
    }

    if(par2World.isRemote)
        par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

    if(!par2World.isRemote)
    {
        par2World.spawnEntityInWorld(new EntityCloudInABottle(par2World, par3EntityPlayer));
    }

    return par1ItemStack;
}
 
Example 7
@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.HELIUM_PLANT_DAMAGE);
        EntityItem plant = new EntityItem(world, x + 0.5D, y + 0.2D, 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, 4, 3);
    }
}
 
Example 8
/**
 * 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 9
Source Project: bartworks   File: BW_TileEntityContainer.java    License: MIT License 5 votes vote down vote up
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
    TileEntity t = world.getTileEntity(x, y, z);
    if (t instanceof ITileDropsContent) {
        int[] dropSlots = ((ITileDropsContent) t).getDropSlots();
        for (int dropSlot : dropSlots) {
            if (((ITileDropsContent) t).getStackInSlot(dropSlot) != null)
                world.spawnEntityInWorld(new EntityItem(world, x, y, z, ((BW_TileEntity_HeatedWaterPump) t).getStackInSlot(dropSlot)));
        }
    }
    super.breakBlock(world, x, y, z, block, meta);
}
 
Example 10
private void dropItems(World pWorld, int pX, int pY, int pZ)
{
    Random tRand = new Random();

    TileEntity tTileEntity = pWorld.getTileEntity(pX, pY, pZ);
    if (!(tTileEntity instanceof IInventory))
    {
        return;
    }
    
    IInventory tInventory = (IInventory) tTileEntity;

    for (int i = 0; i < tInventory.getSizeInventory(); i++)
    {
        ItemStack tItem = tInventory.getStackInSlot(i);

        if (tItem != null && tItem.stackSize > 0) 
        {
            float tx = tRand.nextFloat() * 0.8F + 0.1F;
            float ty = tRand.nextFloat() * 0.8F + 0.1F;
            float tz = tRand.nextFloat() * 0.8F + 0.1F;

            EntityItem tEntityItem = new EntityItem(pWorld, pX + tx, pY + ty, pZ + tz, new ItemStack(tItem.getItem(), tItem.stackSize, tItem.getItemDamage()));

            if (tItem.hasTagCompound()) {
                tEntityItem.getEntityItem().setTagCompound((NBTTagCompound) tItem.getTagCompound().copy());
            }

            float tFactor = 0.05F;
            tEntityItem.motionX = tRand.nextGaussian() * tFactor;
            tEntityItem.motionY = tRand.nextGaussian() * tFactor + 0.2F;
            tEntityItem.motionZ = tRand.nextGaussian() * tFactor;
            pWorld.spawnEntityInWorld(tEntityItem);
            tItem.stackSize = 0;
        }
    }
}
 
Example 11
@Override
//Overriden here because the IOUnit isn't implementing IInventory (intentionally).
protected void dropInventory(World world, int x, int y, int z){

    TileEntity tileEntity = world.getTileEntity(x, y, z);

    if(!(tileEntity instanceof TileEntityAssemblyIOUnit)) return;

    TileEntityAssemblyIOUnit inventory = (TileEntityAssemblyIOUnit)tileEntity;
    Random rand = new Random();

    ItemStack itemStack = inventory.inventory[0];

    if(itemStack != null && itemStack.stackSize > 0) {
        float dX = rand.nextFloat() * 0.8F + 0.1F;
        float dY = rand.nextFloat() * 0.8F + 0.1F;
        float dZ = rand.nextFloat() * 0.8F + 0.1F;

        EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.getItem(), itemStack.stackSize, itemStack.getItemDamage()));

        if(itemStack.hasTagCompound()) {
            entityItem.getEntityItem().setTagCompound((NBTTagCompound)itemStack.getTagCompound().copy());
        }

        float factor = 0.05F;
        entityItem.motionX = rand.nextGaussian() * factor;
        entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
        entityItem.motionZ = rand.nextGaussian() * factor;
        world.spawnEntityInWorld(entityItem);
        itemStack.stackSize = 0;
    }
}
 
Example 12
public void throwREP(ItemStack itemstack, World world, EntityPlayer player) {
    if (REPThrowTimeout > 0) {
        return;
    }

    if (!player.capabilities.isCreativeMode) {
        itemstack.stackSize--;
    }
    world.playSoundAtEntity(player, "random.bow", 0.5F, 0.4F / (world.rand.nextFloat() * 0.4F + 0.8F));
    activeREP = new EntityREP(world, player);
    world.spawnEntityInWorld(activeREP);
    REPThrowTimeout = 40;
}
 
Example 13
Source Project: Artifacts   File: BlockPedestal.java    License: MIT License 5 votes vote down vote up
private void dropItems(World world, int x, int y, int z){
	Random rand = new Random();

	TileEntity tileEntity = world.getTileEntity(x, y, z);
	if (!(tileEntity instanceof IInventory)) {
		return;
	}
	IInventory inventory = (IInventory) tileEntity;

	for (int i = 0; i < inventory.getSizeInventory(); i++) {
		ItemStack item = inventory.getStackInSlot(i);

		if (item != null && item.stackSize > 0) {
			float rx = rand.nextFloat() * 0.8F + 0.1F;
			float ry = rand.nextFloat() * 0.8F + 0.1F;
			float rz = rand.nextFloat() * 0.8F + 0.1F;

			EntityItem entityItem = new EntityItem(world,
					x + rx, y + ry, z + rz,
					new ItemStack(item.getItem(), item.stackSize, item.getItemDamage()));

			if (item.hasTagCompound()) {
				entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy());
			}

			float factor = 0.05F;
			entityItem.motionX = rand.nextGaussian() * factor;
			entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
			entityItem.motionZ = rand.nextGaussian() * factor;
			world.spawnEntityInWorld(entityItem);
			item.stackSize = 0;
		}
	}
}
 
Example 14
@Override
public ItemStack onFocusRightClick(ItemStack itemstack, World world, EntityPlayer player, MovingObjectPosition movingobjectposition) {
    ItemWandCasting wand = (ItemWandCasting) itemstack.getItem();
    if (wand.consumeAllVis(itemstack, player, getVisCost(), true, true)) {
        if (!world.isRemote) {
            EntityLaser laser;
            laser = new EntityLaser(world, player, 2);
            world.spawnEntityInWorld(laser);
        }
    }
    return itemstack;
}
 
Example 15
protected void dropInventory(World world, int x, int y, int z){

        TileEntity tileEntity = world.getTileEntity(x, y, z);

        if(!(tileEntity instanceof IInventory)) return;

        IInventory inventory = (IInventory)tileEntity;
        Random rand = new Random();
        for(int i = getInventoryDropStartSlot(inventory); i < getInventoryDropEndSlot(inventory); i++) {

            ItemStack itemStack = inventory.getStackInSlot(i);

            if(itemStack != null && itemStack.stackSize > 0) {
                float dX = rand.nextFloat() * 0.8F + 0.1F;
                float dY = rand.nextFloat() * 0.8F + 0.1F;
                float dZ = rand.nextFloat() * 0.8F + 0.1F;

                EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.getItem(), itemStack.stackSize, itemStack.getItemDamage()));

                if(itemStack.hasTagCompound()) {
                    entityItem.getEntityItem().setTagCompound((NBTTagCompound)itemStack.getTagCompound().copy());
                }

                float factor = 0.05F;
                entityItem.motionX = rand.nextGaussian() * factor;
                entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
                entityItem.motionZ = rand.nextGaussian() * factor;
                world.spawnEntityInWorld(entityItem);
                itemStack.stackSize = 0;
            }
        }
    }
 
Example 16
@Override
public boolean onItemUse(ItemStack iStack, EntityPlayer player, World world, int x, int y, int z, int side, float vecX, float vecY, float vecZ){
    if(!world.isRemote) {
        EntityDrone drone = new EntityLogisticsDrone(world, player);
        ForgeDirection dir = ForgeDirection.getOrientation(side);
        drone.setPosition(x + 0.5 + dir.offsetX, y + 0.5 + dir.offsetY, z + 0.5 + dir.offsetZ);
        world.spawnEntityInWorld(drone);

        NBTTagCompound stackTag = iStack.getTagCompound();
        NBTTagCompound entityTag = new NBTTagCompound();
        drone.writeEntityToNBT(entityTag);
        if(stackTag != null) {
            entityTag.setFloat("currentAir", stackTag.getFloat("currentAir"));
            entityTag.setInteger("color", stackTag.getInteger("color"));
            NBTTagCompound invTag = stackTag.getCompoundTag("UpgradeInventory");
            if(invTag != null) entityTag.setTag("Inventory", invTag.copy());
        }
        drone.readEntityFromNBT(entityTag);
        addLogisticsProgram(x, y, z, drone.progWidgets);
        if(iStack.hasDisplayName()) drone.setCustomNameTag(iStack.getDisplayName());

        drone.naturallySpawned = false;
        drone.onSpawnWithEgg(null);
        iStack.stackSize--;
    }
    return true;
}
 
Example 17
@Override
public void executeFullGrownEffect(World world, int x, int y, int z, Random rand){
    if(!world.isRemote && world.isRaining()) {
        ItemStack seed = new ItemStack(Itemss.plasticPlant, 1, ItemPlasticPlants.RAIN_PLANT_DAMAGE);
        EntityItem plant = new EntityItem(world, x + rand.nextInt(16) - 8, 128, z + rand.nextInt(16) - 8, seed);
        plant.lifespan = 300;
        ItemPlasticPlants.markInactive(plant);
        world.spawnEntityInWorld(plant);
        world.setBlockMetadataWithNotify(x, y, z, world.getBlockMetadata(x, y, z) - 2, 3);
    }
}
 
Example 18
@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
	if (!par3EntityPlayer.capabilities.isCreativeMode) {
		--par1ItemStack.stackSize;
	}

	if (par2World.isRemote)
		par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

	if (!par2World.isRemote) {
		par2World.spawnEntityInWorld(new EntityBallOMoss(par2World, par3EntityPlayer));
	}

	return par1ItemStack;
}
 
Example 19
public static EntityCreature retrieveFluidAmazonStyle(World world, int x, int y, int z, FluidStack queriedFluid){
    if(world.isRemote) return null;
    if(queriedFluid == null) throw new IllegalArgumentException("Can't query a null FluidStack");
    if(queriedFluid.amount <= 0) throw new IllegalArgumentException("Can't query a FluidStack with an amount of <= 0");

    EntityDrone drone = getChargedDispenserUpgradeDrone(world);

    //Program the drone
    int startY = world.getHeightValue(x + 30, z) + 30;
    drone.setPosition(x + 30, startY, z);
    List<IProgWidget> widgets = drone.progWidgets;

    ProgWidgetStart start = new ProgWidgetStart();
    start.setX(92);
    start.setY(41);
    widgets.add(start);

    int yBase = 52;

    ProgWidgetLiquidImport im = new ProgWidgetLiquidImport();
    im.setX(92);
    im.setY(yBase);
    im.setCount(queriedFluid.amount);
    im.setUseCount(true);
    widgets.add(im);

    ProgWidgetArea area = new ProgWidgetArea();
    area.setX(107);
    area.setY(yBase);
    area.x1 = x;
    area.y1 = y;
    area.z1 = z;
    widgets.add(area);

    ProgWidgetLiquidFilter filter = new ProgWidgetLiquidFilter();
    filter.setX(107);
    filter.setY(yBase + 11);
    filter.setFluid(queriedFluid.getFluid());
    widgets.add(filter);

    yBase += 22;

    ProgWidgetGoToLocation gotoPiece = new ProgWidgetGoToLocation();
    gotoPiece.setX(92);
    gotoPiece.setY(yBase);
    widgets.add(gotoPiece);

    area = new ProgWidgetArea();
    area.setX(107);
    area.setY(yBase);
    area.x1 = x + 30;
    area.y1 = startY;
    area.z1 = z;
    widgets.add(area);

    ProgWidgetSuicide suicide = new ProgWidgetSuicide();
    suicide.setX(92);
    suicide.setY(yBase + 11);
    widgets.add(suicide);

    TileEntityProgrammer.updatePuzzleConnections(widgets);

    world.spawnEntityInWorld(drone);
    return drone;
}
 
Example 20
@Override
public EnumActionResult onItemUse(final ItemStack item, final EntityPlayer player, final World w,
								  final BlockPos coord, EnumHand hand, final EnumFacing facing,
								  final float partialX, final float partialY, final float partialZ) {
	if(facing != EnumFacing.UP) return EnumActionResult.PASS;
	List<EntityItem> entities = w.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(
			coord.getX(),coord.getY()+1,coord.getZ(),
			coord.getX()+1,coord.getY()+2,coord.getZ()+1));
	boolean success = false;
	for(EntityItem target : entities){
			ItemStack targetItem = ((net.minecraft.entity.item.EntityItem)target).getEntityItem();
			if(targetItem != null ){
				ICrusherRecipe recipe = CrusherRecipeRegistry.getInstance().getRecipeForInputItem(targetItem);
				if(recipe != null){
					// hardness check
					if(BaseMetals.enforceHardness){
						if(targetItem.getItem() instanceof ItemBlock){
							Block b = ((ItemBlock)targetItem.getItem()).getBlock();
							if(!this.canHarvestBlock(b.getStateFromMeta(targetItem.getMetadata()))){
								// cannot harvest the block, no crush for you!
								return EnumActionResult.PASS;
							}
						}
					}
					// crush the item (server side only)
                       if(!w.isRemote) {
                           ItemStack output = recipe.getOutput().copy();
                           int count = output.stackSize;
                           output.stackSize = 1;
                           double x = target.posX;
                           double y = target.posY;
                           double z = target.posZ;

                           targetItem.stackSize--;
                           if (targetItem.stackSize <= 0) {
                               w.removeEntity(target);
                           }
                           for (int i = 0; i < count; i++) {
                               w.spawnEntityInWorld(new EntityItem(w, x, y, z, output.copy()));
                           }
                           item.damageItem(1, player);
                       }
					success = true;
					break;
				}
			}
	}
	if(success){
           w.playSound(player, coord, SoundEvents.BLOCK_GRAVEL_BREAK, SoundCategory.BLOCKS, 0.5F, 0.5F + (itemRand.nextFloat() * 0.3F));
	}
	return success ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
}