Java Code Examples for net.minecraft.world.World.spawnEntity()

The following are Jave code examples for showing how to use spawnEntity() of the net.minecraft.world.World class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Bewitchment   File: SpellDisarming.java   Source Code and License Vote up 6 votes
@Override
public void performEffect(RayTraceResult rtrace, EntityLivingBase caster, World world) {
	if (rtrace.typeOfHit == Type.ENTITY && rtrace.entityHit instanceof EntityLivingBase) {
		EntityLivingBase entity = (EntityLivingBase) rtrace.entityHit;
		EnumHand hand = null;
		if (!entity.getHeldItemMainhand().isEmpty()) hand = EnumHand.MAIN_HAND;
		else if (!entity.getHeldItemOffhand().isEmpty()) hand = EnumHand.OFF_HAND;
		if (hand != null) {
			ItemStack stack = entity.getHeldItem(hand).copy();
			entity.setHeldItem(hand, ItemStack.EMPTY);
			if (!(entity instanceof EntityPlayer) && stack.isItemStackDamageable() && stack.getItemDamage() == 0) {
				stack.setItemDamage((int) (stack.getMaxDamage() * (0.5D + 0.5D * Math.random())));
			}
			EntityItem ei = new EntityItem(world, entity.posX, entity.posY, entity.posZ, stack);
			ei.setPickupDelay(200);
			ei.setNoDespawn();
			if (!world.isRemote) world.spawnEntity(ei);
		}
	}
}
 
Example 2
Project: Halloween   File: ItemCurseOrb.java   Source Code and License Vote up 6 votes
@Override
	public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
	{
		ItemStack stack = player.getHeldItem(hand);

		if (!player.capabilities.isCreativeMode)
		{
			stack.shrink(1);
		}

		world.playSound((EntityPlayer)null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

		if (!world.isRemote)
		{
			EntityCurseOrb entity = new EntityCurseOrb(world, player);
			entity.setHeadingFromThrower(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F);
			world.spawnEntity(entity);
		}

//		playerIn.addStat(StatList.getObjectUseStats(this));
		return new ActionResult(EnumActionResult.SUCCESS, stack);
	}
 
Example 3
Project: Infernum   File: BlockPedestal.java   Source Code and License Vote up 6 votes
@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 4
Project: genera   File: ItemGlassJar.java   Source Code and License Vote up 6 votes
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    if (!worldIn.isRemote) {
        ItemStack stack = player.getHeldItem(hand);
        if (stack.getMetadata() == 1 && !(worldIn.getTileEntity(pos) instanceof TileFaerieHome)) {
            NBTTagCompound nbt = stack.getTagCompound();
            if (nbt == null) return EnumActionResult.FAIL;
            EntityFaerie faerie = new EntityFaerie(worldIn, nbt.getDouble("max_health"), nbt.getInteger("type"), nbt.getFloat("size"), nbt.getInteger("level"), nbt.getInteger("current_exp"));
            faerie.setPosition((double) pos.getX(), (double) pos.up().getY(), (double) pos.getZ());
            worldIn.spawnEntity(faerie);
            player.setHeldItem(hand, new ItemStack(GeneraItems.ItemGlassJar, 1, 0));
            return EnumActionResult.SUCCESS;
        }
    }
    return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
 
Example 5
Project: genera   File: BlockNightshadeCrop.java   Source Code and License Vote up 6 votes
@Override
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
    super.updateTick(worldIn, pos, state, rand);
    if (!worldIn.isRemote) {
        if (state.getValue(AGE) == 2) {
            EntityFaerie faerie = new EntityFaerie(worldIn, 4.0D, 0, 0.1F, 1);
            faerie.setPosition((double) pos.getX(), (double) pos.up().getY(), (double) pos.getZ());
            worldIn.spawnEntity(faerie);
        }
        if (!(worldIn.getBiome(pos) == Biomes.FOREST ||
                worldIn.getBiome(pos) == Biomes.FOREST_HILLS ||
                worldIn.getBiome(pos) == Biomes.TAIGA ||
                worldIn.getBiome(pos) == Biomes.TAIGA_HILLS) && state.getValue(AGE) >= 1) {
            worldIn.setBlockState(pos, state.withProperty(AGE, 0));
        }
    }

}
 
Example 6
Project: MeeCreeps   File: PortalGunItem.java   Source Code and License Vote up 6 votes
private void throwProjectile(EntityPlayer player, EnumHand hand, World world) {
    ItemStack heldItem = player.getHeldItem(hand);

    int charge = getCharge(heldItem);
    if (charge <= 0) {
        MeeCreepsMessages.INSTANCE.sendTo(new PacketShowBalloonToClient("message.meecreeps.gun_no_charge"), (EntityPlayerMP) player);
        return;
    }
    setCharge(heldItem, charge-1);

    List<TeleportDestination> destinations = getDestinations(heldItem);
    int current = getCurrentDestination(heldItem);
    if (current == -1) {
        MeeCreepsMessages.INSTANCE.sendTo(new PacketShowBalloonToClient("message.meecreeps.gun_no_destination"), (EntityPlayerMP) player);
    } else if (destinations.get(current) == null) {
        MeeCreepsMessages.INSTANCE.sendTo(new PacketShowBalloonToClient("message.meecreeps.gun_bad_destination"), (EntityPlayerMP) player);
    } else {
        EntityProjectile projectile = new EntityProjectile(world, player);
        projectile.setDestination(destinations.get(current));
        projectile.setPlayerId(player.getUniqueID());
        projectile.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F);
        world.spawnEntity(projectile);
    }
}
 
Example 7
Project: Bewitchment   File: ItemBrewLinger.java   Source Code and License Vote up 5 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
	ItemStack itemstack = playerIn.getHeldItem(hand);
	ItemStack copy = playerIn.capabilities.isCreativeMode ? itemstack.copy() : itemstack.splitStack(1);
	playerIn.playSound(SoundEvents.ENTITY_LINGERINGPOTION_THROW, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

	if (!worldIn.isRemote) {
		EntityBrew brew = new EntityBrew(worldIn, playerIn, copy, EntityBrew.BrewDispersion.LINGER);

		brew.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, -20.0F, 0.5F, 1.0F);
		worldIn.spawnEntity(brew);
	}

	return ActionResult.newResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(hand));
}
 
Example 8
Project: pnc-repressurized   File: ItemDrone.java   Source Code and License Vote up 5 votes
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (hand != EnumHand.MAIN_HAND) return EnumActionResult.PASS;

    if (!world.isRemote) {
        ItemStack iStack = player.getHeldItemMainhand();
        EntityDrone drone = new EntityDrone(world, player);

        BlockPos placePos = pos.offset(facing);
        drone.setPosition(placePos.getX() + 0.5, placePos.getY() + 0.5, placePos.getZ() + 0.5);
        world.spawnEntity(drone);

        NBTTagCompound stackTag = iStack.getTagCompound();
        NBTTagCompound entityTag = new NBTTagCompound();
        drone.writeEntityToNBT(entityTag);
        if (stackTag != null) {
            entityTag.setTag("widgets", stackTag.getTagList("widgets", 10).copy());
            entityTag.setFloat("currentAir", stackTag.getFloat("currentAir"));
            entityTag.setInteger("color", stackTag.getInteger("color"));
            entityTag.setTag(ChargeableItemHandler.NBT_UPGRADE_TAG, stackTag.getCompoundTag(ChargeableItemHandler.NBT_UPGRADE_TAG));
        }
        drone.readEntityFromNBT(entityTag);
        if (iStack.hasDisplayName()) drone.setCustomNameTag(iStack.getDisplayName());

        drone.naturallySpawned = false;
        //TODO 1.8 check if valid replacement drone.onSpawnWithEgg(null);
        drone.onInitialSpawn(world.getDifficultyForLocation(placePos), null);
        iStack.shrink(1);
    }
    return EnumActionResult.SUCCESS;
}
 
Example 9
Project: pnc-repressurized   File: ItemLogisticsDrone.java   Source Code and License Vote up 5 votes
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack iStack = player.getHeldItem(hand);
    if (!world.isRemote) {
        EntityDrone drone = new EntityLogisticsDrone(world, player);

        BlockPos placePos = pos.offset(facing);
        drone.setPosition(placePos.getX() + 0.5, placePos.getY() + 0.5, placePos.getZ() + 0.5);
        world.spawnEntity(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"));
            entityTag.setTag(ChargeableItemHandler.NBT_UPGRADE_TAG, stackTag.getCompoundTag(ChargeableItemHandler.NBT_UPGRADE_TAG));
        }
        drone.readEntityFromNBT(entityTag);
        addLogisticsProgram(pos, drone.progWidgets);
        if (iStack.hasDisplayName()) drone.setCustomNameTag(iStack.getDisplayName());

        drone.naturallySpawned = false;
        //TODO 1.8 check if valid replacement drone.onSpawnWithEgg(null);
        drone.onInitialSpawn(world.getDifficultyForLocation(placePos), null);
        iStack.shrink(1);
    }
    return EnumActionResult.SUCCESS;
}
 
Example 10
Project: Bewitchment   File: GrassGrowBrew.java   Source Code and License Vote up 5 votes
@Override
public void apply(World world, BlockPos pos, EntityLivingBase entity, int amplifier, int tick) {
	if (entity instanceof EntityMooshroom) {
		EntityCow cow = new EntityCow(world);
		cow.setPosition(pos.getX(), pos.getY(), pos.getZ());
		entity.setDead();
		world.spawnEntity(cow);
	}
}
 
Example 11
Project: ChopDown   File: ChopDown.java   Source Code and License Vote up 5 votes
private static void drop(World world, BlockPos pos, BlockPos newPos) {
    EntityFallingBlock fallingBlock = new EntityFallingBlock(world, newPos.getX(), newPos.getY(), newPos.getZ(), world.getBlockState(pos));
    fallingBlock.setEntityBoundingBox(new AxisAlignedBB(newPos.add(0, 0, 0), newPos.add(1, 1, 1)));
    fallingBlock.fallTime = 1;
    world.spawnEntity(fallingBlock);
    world.setBlockState(pos, Blocks.AIR.getDefaultState());
}
 
Example 12
Project: harshencastle   File: HarshenTemplate.java   Source Code and License Vote up 5 votes
private void addEntitiesToWorld(World worldIn, BlockPos pos, Mirror mirrorIn, Rotation rotationIn, @Nullable StructureBoundingBox aabb)
{
    for (Template.EntityInfo template$entityinfo : this.entities)
    {
        BlockPos blockpos = transformedBlockPos(template$entityinfo.blockPos, mirrorIn, rotationIn).add(pos);

        if (aabb == null || aabb.isVecInside(blockpos))
        {
            NBTTagCompound nbttagcompound = template$entityinfo.entityData;
            Vec3d vec3d = transformedVec3d(template$entityinfo.pos, mirrorIn, rotationIn);
            Vec3d vec3d1 = vec3d.addVector((double)pos.getX(), (double)pos.getY(), (double)pos.getZ());
            NBTTagList nbttaglist = new NBTTagList();
            nbttaglist.appendTag(new NBTTagDouble(vec3d1.x));
            nbttaglist.appendTag(new NBTTagDouble(vec3d1.y));
            nbttaglist.appendTag(new NBTTagDouble(vec3d1.z));
            nbttagcompound.setTag("Pos", nbttaglist);
            nbttagcompound.setUniqueId("UUID", UUID.randomUUID());
            Entity entity;

            try
            {
                entity = EntityList.createEntityFromNBT(nbttagcompound, worldIn);
            }
            catch (Exception var15)
            {
                entity = null;
            }

            if (entity != null)
            {
                float f = entity.getMirroredYaw(mirrorIn);
                f = f + (entity.rotationYaw - entity.getRotatedYaw(rotationIn));
                entity.setLocationAndAngles(vec3d1.x, vec3d1.y, vec3d1.z, f, entity.rotationPitch);
                worldIn.spawnEntity(entity);
            }
        }
    }
}
 
Example 13
Project: Bewitchment   File: RitualConjurationWitch.java   Source Code and License Vote up 5 votes
@Override
public void onFinish(EntityPlayer player, IRitualHandler tile, World world, BlockPos pos, NBTTagCompound data) {
	if (!world.isRemote) {
		EntityWitch witch = new EntityWitch(world);
		witch.setLocationAndAngles(pos.getX(), pos.getY(), pos.getZ(), (float) (Math.random() * 360), 0);
		witch.onInitialSpawn(world.getDifficultyForLocation(new BlockPos(witch)), (IEntityLivingData) null);
		world.spawnEntity(witch);
		if (Math.random() < 0.1)
			witch.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 6000, 2, false, false));
	}
}
 
Example 14
Project: WirelessRedstone   File: RedstoneEtherClientAddons.java   Source Code and License Vote up 5 votes
public void throwREP(ItemStack itemstack, World world, EntityPlayer player) {
    if (REPThrowTimeout > 0) {
        return;
    }

    if (!player.capabilities.isCreativeMode) {
        itemstack.shrink(1);
    }
    world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL,  0.5F, 0.4F / (world.rand.nextFloat() * 0.4F + 0.8F));
    activeREP = new EntityREP(world, player);
    world.spawnEntity(activeREP);
    REPThrowTimeout = 40;
}
 
Example 15
Project: Infernum   File: SpellWitheringBolt.java   Source Code and License Vote up 5 votes
@Override
public void onCastFinish(World world, EntityPlayer player, ItemStack stack) {
	if (!world.isRemote && consumePower(player)) {
		Vec3d lookVec = player.getLookVec();
		double x = player.posX + lookVec.xCoord;
		double y = player.posY + lookVec.yCoord + player.eyeHeight;
		double z = player.posZ + lookVec.zCoord;
		EntityWitheringBolt bolt = new EntityWitheringBolt(world, player, 1, x, y, z);
		bolt.setAim(player, player.rotationPitch, player.rotationYaw, 0.75F, 0.08F);
		world.spawnEntity(bolt);
	}
}
 
Example 16
Project: pnc-repressurized   File: SemiBlockManager.java   Source Code and License Vote up 5 votes
public void breakSemiBlock(ISemiBlock semiBlock, EntityPlayer player) {
    if (!semiBlock.isInvalid()) {
        World world = semiBlock.getWorld();
        BlockPos pos = semiBlock.getPos();
        NonNullList<ItemStack> drops = NonNullList.create();
        semiBlock.addDrops(drops);
        for (ItemStack stack : drops) {
            EntityItem item = new EntityItem(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, stack);
            world.spawnEntity(item);
            if (player != null) item.onCollideWithPlayer(player);
        }
        removeSemiBlock(semiBlock);
    }
}
 
Example 17
Project: BetterBeginningsReborn   File: ItemKnife.java   Source Code and License Vote up 5 votes
@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft)
{
    if(entityLiving instanceof EntityPlayer)
    {
        setThrown(stack, true);
    }
    if(!worldIn.isRemote)
    {
        EntityThrownKnife knife = new EntityThrownKnife(worldIn, entityLiving, stack);
        knife.setForce((float) Math.min((this.getMaxItemUseDuration(stack) - timeLeft), ItemKnife.DRAW_TIME) / ItemKnife.DRAW_TIME);
        knife.setHeadingFromThrower(entityLiving, entityLiving.rotationPitch, entityLiving.rotationYaw, 0.0F, 1.5F, 1.0F);
        worldIn.spawnEntity(knife);
    }
}
 
Example 18
Project: BetterBeginningsReborn   File: TileEntityInfusionRepair.java   Source Code and License Vote up 4 votes
public void activate(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
   {
if(player.isSneaking())
{
    if(Prep1_11.isEmpty(heldItem))
    {
	if(hasEnchItem())
	{
	    if(!world.isRemote)
	    {
		world.spawnEntity(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), mainHandler.getStackInSlot(SLOT_ENCH_ITEM)));
	    }
	    mainHandler.setStackInSlot(SLOT_ENCH_ITEM, null);
	    mode = Mode.NONE;
	    pendingIngredients.clear();
	    markDirty();
	    world.notifyBlockUpdate(pos, state, state, 8);
	}
	else if(world.isRemote)
	{
	    ITextComponent link1 = new TextComponentString("Infusion Repair");
	    link1.setStyle(new Style().setBold(true).setUnderlined(true).setClickEvent(new ClickEvent(Action.OPEN_URL, "https://github.com/einsteinsci/betterbeginnings/wiki/Infusion-Repair")));
	    ITextComponent link2 = new TextComponentString("Enchantment Diffusion");
	    link2.setStyle(new Style().setBold(true).setUnderlined(true).setClickEvent(new ClickEvent(Action.OPEN_URL, "https://github.com/einsteinsci/betterbeginnings/wiki/Enchantment-Diffusion")));
	    ITextComponent message = new TextComponentString("See the BB wiki articles on ");
	    message.appendSibling(link1);
	    player.sendMessage(message);
	    player.sendMessage(new TextComponentString("and ").appendSibling(link2));
	}
    }
}
else
{
    if(Prep1_11.isEmpty(heldItem) || hasEnchItem() || mode != Mode.NONE) return;
    if(heldItem.getItem() == RegisterItems.cloth)
    {
	mode = Mode.DIFFUSION;
    }
    else if(heldItem.isItemEnchanted())
    {
	if(heldItem.getEnchantmentTagList().tagCount() > 8)
	{
	    player.sendMessage(new TextComponentTranslation("diffusion.toomanyenchants"));
	    mode = Mode.NONE;
	    return;
	}
	mode = Mode.REPAIR;
	pendingIngredients.clear();
	pendingIngredients.addAll(InfusionRepairUtil.getRequiredStacks(heldItem));
	xpLevelsNeeded = InfusionRepairUtil.getTakenLevels(heldItem);
	markDirty();
    }
    else
	return;
    ItemStack newStack = heldItem.copy();
    newStack.setCount(1);
    mainHandler.setStackInSlot(heldItem.isItemEnchanted() ? SLOT_ENCH_ITEM : 1, newStack);
    heldItem.shrink(1);
}
   }
 
Example 19
Project: ExPetrum   File: BlockBerryBush.java   Source Code and License Vote up 4 votes
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    if (this.getState() == EnumShrubState.BLOOMING)
    {
        if (!worldIn.isRemote)
        {
            ItemStack held = playerIn.getHeldItem(hand);
            int allowHarvest;
            if (!held.isEmpty() && held.getItem() == ExPItems.basket)
            {
                held.damageItem(1, playerIn);
                allowHarvest = 2;
            }
            else
            {
                allowHarvest = worldIn.rand.nextFloat() < 0.1F ? 1 : 0;
                if (allowHarvest == 0)
                {
                    worldIn.playSound(null, pos, SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.BLOCKS, 1, 1);
                }
            }

            if (allowHarvest > 0)
            {
                worldIn.setBlockState(pos, ExPBlocks.berryBushes[EnumShrubState.NORMAL.ordinal()].getDefaultState().withProperty(ExPBlockProperties.BERRY_BUSH_TYPE, state.getValue(ExPBlockProperties.BERRY_BUSH_TYPE)));
                if (allowHarvest == 2 || worldIn.rand.nextFloat() <= 0.75F)
                {
                    float amt = 50 + worldIn.rand.nextFloat() * 250;
                    ItemStack food = new ItemStack(ExPItems.food, 1, EnumCrop.values().length + state.getValue(ExPBlockProperties.BERRY_BUSH_TYPE).ordinal() + 1);
                    ItemFood item = (ItemFood) food.getItem();
                    item.setLastTickTime(food, IExPWorld.of(worldIn).today());
                    item.setTotalWeight(food, amt);
                    EntityItem drop = new EntityItem(worldIn, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, food.copy());
                    worldIn.spawnEntity(drop);
                }
            }
        }

        return true;
    }

    return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
 
Example 20
Project: Industrial-Foregoing   File: EssenceStrawHandler.java   Source Code and License Vote up 4 votes
@Override
public void onDrink(World world, BlockPos pos, FluidStack stack, EntityPlayer player, boolean fromFluidContainer) {
    world.spawnEntity(new EntityXPOrb(world, player.posX, player.posY, player.posZ, world.rand.nextInt(10) + 8));
}