Java Code Examples for net.minecraft.world.WorldServer#spawnParticle()

The following examples show how to use net.minecraft.world.WorldServer#spawnParticle() . 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: RecipeLogicSteam.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void tryDoVenting() {
    BlockPos machinePos = metaTileEntity.getPos();
    EnumFacing ventingSide = getVentingSide();
    BlockPos ventingBlockPos = machinePos.offset(ventingSide);
    IBlockState blockOnPos = metaTileEntity.getWorld().getBlockState(ventingBlockPos);
    if (blockOnPos.getCollisionBoundingBox(metaTileEntity.getWorld(), ventingBlockPos) == Block.NULL_AABB) {
        metaTileEntity.getWorld()
            .getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(ventingBlockPos), EntitySelectors.CAN_AI_TARGET)
            .forEach(entity -> entity.attackEntityFrom(DamageSources.getHeatDamage(), 6.0f));
        WorldServer world = (WorldServer) metaTileEntity.getWorld();
        double posX = machinePos.getX() + 0.5 + ventingSide.getFrontOffsetX() * 0.6;
        double posY = machinePos.getY() + 0.5 + ventingSide.getFrontOffsetY() * 0.6;
        double posZ = machinePos.getZ() + 0.5 + ventingSide.getFrontOffsetZ() * 0.6;

        world.spawnParticle(EnumParticleTypes.SMOKE_LARGE, posX, posY, posZ,
            7 + world.rand.nextInt(3),
            ventingSide.getFrontOffsetX() / 2.0,
            ventingSide.getFrontOffsetY() / 2.0,
            ventingSide.getFrontOffsetZ() / 2.0, 0.1);
        world.playSound(null, posX, posY, posZ, SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 1.0f, 1.0f);
        setNeedsVenting(false);
    } else if (!ventingStuck) {
        setVentingStuck(true);
    }
}
 
Example 2
Source File: Nyan.java    From CommunityMod with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void updateNyanEntity(MinecraftServer server, WorldServer world, Entity entity,
		NBTTagCompound data) {
	Entity nyanEntity = null;

	if(data.hasUniqueId(NYAN_ENTITY_UUID_KEY)) {
		nyanEntity = server.getEntityFromUuid(data.getUniqueId(NYAN_ENTITY_UUID_KEY));
	}

	boolean shouldSpawn = false;

	if(nyanEntity == null || nyanEntity.isDead) {
		nyanEntity = newNyanEntity(world);
		nyanEntity.getEntityData().setUniqueId(NYANED_ENTITY_UUID_KEY, entity.getUniqueID());
		data.setUniqueId(NYAN_ENTITY_UUID_KEY, nyanEntity.getUniqueID());
		shouldSpawn = true;
	}

	final BlockPos entityPos = entity.getPosition();
	double entityHeightMultiplier = world.getTotalWorldTime() % 2 == 0 ? 3.5 : 4.0;

	//Account for dab particles
	if(entity instanceof EntityPlayer) {
		entityHeightMultiplier += 2.0;
	}

	//I *could* disable the AI, but this is more fun
	nyanEntity.setPositionAndRotation(
			entityPos.getX(),
			entityPos.getY() + entity.height * entityHeightMultiplier + nyanEntity.height,
			entityPos.getZ(),
			entity.rotationYaw,
			entity.rotationPitch
	);
	nyanEntity.setRotationYawHead(entity.getRotationYawHead());
	nyanEntity.setEntityInvulnerable(true);

	if(shouldSpawn) {
		world.spawnEntity(nyanEntity);
	}

	final BlockPos nyanPos = nyanEntity.getPosition();
	final NyanDirection direction =
			NyanDirection.getDirectionFacing(nyanEntity, Rotation.CLOCKWISE_90);

	world.spawnParticle(
			//Wool
			EnumParticleTypes.REDSTONE,
			//Not long distance
			false,
			nyanPos.getX() + direction.getXDirection() * 12.0,
			nyanPos.getY() - 2.5,
			nyanPos.getZ() + direction.getZDirection() * 12.0,
			//Number of particles
			10,
			direction.getXDirection() * 5.0,
			0.0,
			direction.getZDirection() * 5.0,
			//Speed
			10.0
	);
}